// pages/register/index.js const $$ = require('../../utils/util'); const app = getApp(); import Toast from '../../components/vant/toast/toast'; // 获取个人信息 function getUserInfoApi() { return $$.request({ url: 'paUser/getUserInfo', type: 'get', service: 'cust' }); } function caseRegisterSaveApi(submitData) { return $$.request({ url: 'caseInfo/caseRegister', type: 'post', submitData, service: 'mediate' }); } Page({ /** * 页面的初始数据 */ userInfo: {}, location: [], // 省市区等地理资源 select: {}, // 下拉框数据 goToMaterialSave: false, // 避免跳转到材料上传页面重复保存草稿 agreementMsg: '', // 服务协议 data: { stepText: 5, //用户须知倒计时5秒 timer: null, // 用于存储定时器的引用 popupVisibleText: false, //是否滚动到底部 imgUrl: $$.url.img, steps: [{ title: '填写人员', number: '1', activeIcon: 'steps-register-1-active.png' }, { title: '描述纠纷', number: '2', activeIcon: 'steps-register-2-active.png' }, { title: '提交申请', number: '3', activeIcon: 'steps-register-3-active.png' }, ], saveStatus: false, //未提交,已提交 oneList: [], titleShow: { '09_01001-1': ['自然人', '姓名', '真实姓名'], '09_01001-2': ['法人', '企业名称', '企业全名', '法定代表人姓名'], '09_01001-3': ['机构代表人', '机构名称', '机构全名', '机构代表人姓名'], }, // 用于判断显示的输入框标题 stepsActive: 0, // 步骤条当前下标 submitData: { occurTime: new Date().getTime(), occurTimeName: $$.moment(new Date().getTime()).format('YYYY-MM-DD'), caseType: '', caseTypeName: '', addr: '', lat: '', lng: '', peopleNum: '', amount: '', caseDes: '', caseClaim: '', plaintiffList: [], defendantList: [], }, // 表单数据 addPersonData: {}, //添加的当事人 materialNum: 0, // 纠纷材料总数量 userInfoVisible: false, // 是否采用个人信息更新申请人信息 timePicker: false, //时间选择展示 maxDate: new Date().getTime(), popup: { formtype: '', // 控制在纠纷信息 or 申请人信息 or 被申请人添加数据 index: 0, // 如为申请人信息 or 被申请人确认下拉选择此参数为下标 }, // 下拉弹出框数据 changeVisible: false, // 是否是修改 recordingVisible: false, // 录音界面是否显示 popupMsg: { show: false, title: '', type: 1, editType: 'add', buttonText: '' }, // 弹窗, type: 1'恢复草稿',2'申请人',3'被申请人', editType: 'add'新增,'edit'修改 tipData: { caseList: [].join("\n"), guideList: [], }, caseText: '', caseTitle: '', similarity: '', showCase: false, popupSelect: { show: false, data: [], activeIndex: null }, // 选择人员 threeAvtice: '1', caseDesNum: 0, //事项概况字数 caseClaimNum: 0, //事项申请字数 }, // 获取服务协议 async getAgreement() { var that = this; const res = await $$.commonRequest({ url: `${$$.url.txt}agree.txt`, type: 'get' }); if (res) { that.data.popupVisible = true; that.setData({ popupVisible: true, }); this.startCountdown(); // 启动倒计时 } }, //须知弹窗倒计时 startCountdown: function () { let that = this; that.setData({ timer: setInterval(function () { if (that.data.stepText > 0) { that.data.stepText--; that.setData({ stepText: that.data.stepText }); } else { clearInterval(that.data.timer); // 倒计时结束,清除定时器 // 在这里执行销毁操作,比如隐藏或删除倒计时组件 } }, 1000) }) }, // 表单修改 handleChange(e) { let key = e.currentTarget.dataset.key, value = e.detail; this.data.submitData[key] = value; this.setData({ submitData: this.data.submitData }); if (key === 'caseDes' || key === 'caseClaim') { this.setData({ [key + 'Num']: value.length }); } }, threeTagChange(e) { value = e.detail; this.setData({ threeAvtice: value }); }, // 下拉框选择确认 handleConfirmPicker({ detail }) { let type = this.data.popup.type, value = detail.detail.value, arr = []; this.data.popup.visible = false; if (type === 'caseCause') { arr = ['caseType', 'caseTypeName']; arr.forEach((x, t) => { this.data.submitData[x] = value[0][t === 0 ? 'value' : 'label']; }); } else if (type === 'location') { arr = [ ['city', 'cityName'], ['area', 'areaName'], ['road', 'roadName'] ]; arr.forEach((x, t) => { this.data.submitData[x[0]] = value[t]?.value || ''; this.data.submitData[x[1]] = value[t]?.label || ''; }); } this.setData({ popup: this.data.popup, submitData: this.data.submitData }); }, // 下拉框选择开启 handleShowPopup(e) { let type = e.currentTarget.dataset.type; let selectData = []; if (type === 'location') { if (this.location.length === 0) { return false; } let selectOption = JSON.parse(JSON.stringify(this.location)); let arr = $$.getLocationIndex(this.location, this.data.submitData); // 计算默认的市区县下标 selectData = [{ values: selectOption, defaultIndex: arr[0] }, { values: selectOption[arr[0]].children, defaultIndex: arr[1] }, { values: selectOption[arr[0]].children[arr[1]].children || [], defaultIndex: arr[2] }, ]; selectData.forEach((x) => { x.values.forEach((y) => { delete y.children; }); }); } else if (type === 'occurTime') { this.setData({ timePicker: true }) return; } else { let selectOption = this.select[type]; selectData = [{ values: selectOption, defaultIndex: 0 }]; } this.setData({ popup: { formtype: e.currentTarget.dataset.formtype, index: e.currentTarget.dataset.index, visible: true, title: e.currentTarget.dataset.title, type: type, selectData: selectData, }, }); }, // 关闭下拉框选择 handleClosePopup() { this.data.popup.visible = false; this.setData({ popup: this.data.popup }); }, // 滚动到底部事件 handlescrolltolower() { this.setData({ popupVisibleText: true }) }, // 用户须知 handleAgree(e) { let type = e.currentTarget.dataset.type; if (!this.data.popupVisibleText) { Toast('请阅读完整的用户须知'); return; } if (type === 'agree') { // 同意协议之后退出登录后不重复弹出 wx.setStorage({ key: 'agreement', data: 1 }); } this.setData({ popupVisible: false }); }, // 下一步 or 上一步 handleNext(e) { let type = e.currentTarget.dataset.type; if (type === 'next' && this.data.stepsActive === 0) { this.setData({ stepsActive: 1 }); return; } if (type === 'back' && this.data.stepsActive === 1) { this.setData({ stepsActive: 0 }); return; } if (type === 'next' && this.data.stepsActive === 1) { this.setData({ stepsActive: 2 }); return; } if (type === 'back' && this.data.stepsActive === 2) { this.setData({ stepsActive: 1 }); return; } // 申请提交 if (type === 'next' && this.data.stepsActive === 2) { let data = this.data.submitData; let list = this.data.oneList; let personList = []; //"15_020008-1" 申请方当事人 ,"15_020008-2" 被申请方当事人 let agentList = []; //"24_00006-1" 申请方代理人 ,"24_00006-2" 被申请方代理人 personList = list.filter(item => item.perType === '15_020008-1' || item.perType === '15_020008-2'); agentList = list.filter(item => item.perType === '24_00006-1' || item.perType === '24_00006-2'); this.caseRegisterSave({ ...data, personList, agentList }); } }, async caseRegisterSave(params) { $$.showLoading(); const res = await caseRegisterSaveApi(params); $$.hideLoading(); if (res.type) { Toast('提交成功'); } }, //选择纠纷类型 、跳转事项概况语音描述,跳转事项申请语音描述 caseTypeGoPage(e) { let url = e.currentTarget.dataset.url; wx.navigateTo({ url: url, }); }, //选择地址 openmap: function (e) { var that = this; console.log('latitude') wx.getLocation({ type: 'gcj02', //返回可以用于wx.openLocation的经纬度 success: function (res) { wx.chooseLocation({ success: function (res) { that.setData({ submitData: { ...that.data.submitData, addr: res.address, lng: res.longitude, lat: res.latitude, } }) }, fail: function (res) { }, }) } }) }, delAddress() { this.setData({ submitData: { ...this.data.submitData, addr: '', lng: '', lat: '' } }) }, // 获取省市区等地理资源 async getLocationData() { $$.showLoading(); const res = await $$.commonRequest({ url: `${$$.url.assets}locationSelect.json`, type: 'get' }); $$.hideLoading(); if (res) { let location = []; $$.province.forEach((x) => { location.push(res[x][0]); }); this.location = location; } }, // 请求下拉框资源 async getSelectOptionData() { const res = await $$.commonRequest({ url: `${$$.url.assets}selectOption.json`, type: 'get' }); if (res) { this.select.cardType = res.data.cardType || []; this.select.caseCause = this.data.caseCause || []; this.select.personClass = res.data.personClass || []; } }, // 获取个人信息 async getUserInfo() { $$.showLoading(); const res = await getUserInfoApi(); $$.hideLoading(); if (res.type) { let data = res.data || {} this.setData({ oneList: [{ ...data, perType: '15_020008-1', perTypeName: '申请方当事人', perClass: '09_01001-1', perClassName: '自然人', certiNo: data.idcard || '' }] }) }; }, // 自动添加申请人提醒 oneAddMe(e) { let formtype = e.currentTarget.dataset.formtype; if (formtype === 'yes') { this.getUserInfo() } this.setData({ addMePlaintiff: false }) }, // 填写人员 oneDelPerson(e) { console.log('e', e); let index = e.currentTarget.dataset.index; let item = e.currentTarget.dataset.item; $$.showModal({ title: '删除人员确认', content: '确定删除当事人' + item.trueName + '吗?', cancelText: '我再想想', confirmText: '确定删除', success: (res) => { if (res.confirm) { this.setData({ oneList: this.data.oneList.filter((i, idx) => idx !== index) }) } }, }); }, // 添加当事人 oneAddPerson(e) { let perType = e.currentTarget.dataset.pertype; let perTypeName = e.currentTarget.dataset.pertypename; if (!perType) { this.setData({ addPerson: true }) } else { this.setData({ addPerson: false }) wx.navigateTo({ url: `../../pages/addPerson/index?perType=${perType}&perTypeName=${perTypeName}`, }); } }, // 修改当事人 oneEditPerson(e) { let item = e.currentTarget.dataset.item; let index = e.currentTarget.dataset.index; wx.navigateTo({ url: `../../pages/addPerson/index?data=${JSON.stringify(item)}&index=${index}`, }); }, // 关闭自定义弹窗 addClosePopup(e) { let key = e.currentTarget.dataset.key; this.setData({ [key]: false }) }, // 选择发生事件确定 onInput(e) { let key = e.currentTarget.dataset.key; let value = e.detail; this.setData({ [key]: false, submitData: { ...this.data.submitData, occurTime: value, occurTimeName: $$.moment(value).format('YYYY-MM-DD'), } }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function () { this.getLocationData(); let agreement = wx.getStorageSync('agreement'); if (!agreement) { this.getAgreement(); } else { if (this.data.oneList?.length === 0) { this.setData({ addMePlaintiff: true }) } } }, /** * 生命周期函数--监听页面显示 */ onShow: function () { if (this.data.oneData?.trueName) { let list = this.data.oneList; console.log('list', list); console.log('this.data.editIndex', this.data.editIndex); console.log('this.data.oneData', this.data.oneData); if (this.data.editIndex) { list[this.data.editIndex] = this.data.oneData; } else { list = list.concat(this.data.oneData) } this.setData({ oneList: list, oneData: {}, editIndex: false, }) } if (this.data.twoData?.title) { this.setData({ submitData: { ...this.data.submitData, caseType: this.data.twoData.value, caseTypeName: this.data.twoData.title, }, twoData: {} }) } if (this.data.twoValue) { console.log('this.data.twoValue', this.data.twoValue); console.log('this.data.twoKey', this.data.twoKey); this.setData({ submitData: { ...this.data.submitData, [this.data.twoKey]: this.data.twoValue }, twoValue: '', twoKey: '' }) } }, onHide: function () { // this.handleCheckSave(); }, onUnload: function () { // this.handleCheckSave(); }, });