// 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' }); } // 附件上传的id function getByIdApi(param) { return $$.request({ url: 'caseUtils/getNewTimeCaseId', type: 'get', submitData: param || {}, service: 'utils' }); } // 删除附件 function delfileApi(id) { return $$.request({ url: 'fileInfo/deleteFileById?id=' + id, type: 'get', service: 'sys', }); } function getawApi(submitData) { return $$.request({ url: 'case-law/get-clain-rise-case', type: 'post', ai: true, submitData, service: 'mediate', }); } // 获取案例 function getCaseApi(submitData) { return $$.request({ url: 'case-law/get-case', type: 'post', ai: true, submitData, service: 'mediate', }); } function caseRegisterSaveApi(submitData) { return $$.request({ url: 'caseInfo/caseRegister', type: 'post', submitData, service: 'mediate' }); } // 限制选择地图位置在白云区内 function checkRegisterAreaApi(submitData) { return $$.request({ url: 'syRegion/checkRegisterArea', type: 'get', submitData, service: 'sys' }); } Page({ /** * 页面的初始数据 */ userInfo: {}, location: [], // 省市区等地理资源 select: {}, // 下拉框数据 goToMaterialSave: false, // 避免跳转到材料上传页面重复保存草稿 agreementMsg: '', // 服务协议 ownerId: '', //附件上传id 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: '', }, // 表单数据 fileList: [], //表单附件 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 }); if (this.data.oneList?.length === 0) { this.setData({ addMePlaintiff: true }) } }, // 下一步 or 上一步 handleNext(e) { let type = e.currentTarget.dataset.type; if (type === 'next' && this.data.stepsActive === 0) { if (this.data.oneList?.length <= 0) { $$.showToast({ title: '请至少添加一名当事人', duration: 500 }); } else { this.setData({ stepsActive: 1 }); this.getById(); } return; } if (type === 'back' && this.data.stepsActive === 1) { this.setData({ stepsActive: 0 }); return; } if (type === 'next' && this.data.stepsActive === 1) { let newData = this.data.submitData; if (!newData.caseType) { $$.showToast({ title: '请选择纠纷类型', duration: 500 }); return; } if (!newData.occurTime) { $$.showToast({ title: '请选择纠纷发生时间', duration: 500 }); return; } if (!newData.addr) { $$.showToast({ title: '请选择纠纷发生地', duration: 500 }); return; } if (!newData.caseDes) { $$.showToast({ title: '请填写事项概况', duration: 500 }); return; } if (!newData.caseClaim) { $$.showToast({ title: '请填写事项申请', duration: 500 }); return; } // 提交AI接口 // this.getaw(newData); if (this.data.fileList?.length <= 0) { // 附件上传提示 this.setData({ showFileTip: true }) return; } 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, id: this.data.ownerId, }); } }, async getaw(data) { let newData = { caseDes: data.caseDes, caseClaim: data.caseClaim, caseId: this.data.ownerId, } const res = await getawApi(newData); if (res.type) { this.setData({ AIData: res.data || {} }) } }, async getById() { $$.showLoading(); const res = await getByIdApi(); $$.hideLoading(); if (res.type) { this.setData({ ownerId: res.data || '' }) } }, async caseRegisterSave(params) { $$.showLoading(); const res = await caseRegisterSaveApi(params); $$.hideLoading(); if (res.type) { // Toast('提交成功'); this.setData({ saveStatus: true }) } const res1 = await getCaseApi({ caseDes: params.caseDes, caseClaim: params.caseClaim, caseId: params.id, }); if (res1.type) { wx.setStorage({ key: 'AICase', data: { caseDes: params.caseDes, caseClaim: params.caseClaim, caseId: params.id, } }); } }, //选择纠纷类型 、跳转事项概况语音描述,跳转事项申请语音描述 caseTypeGoPage(e) { let url = e.currentTarget.dataset.url; let type = e.currentTarget.dataset.type; let value = e.currentTarget.dataset.value; wx.navigateTo({ url: url + '?type=' + type + '&value=' + value, }); }, // 图片识别 ocrClick(e) { let key = e.currentTarget.dataset.key; let keyNum = e.currentTarget.dataset.keynum; let that = this; wx.chooseMedia({ count: 1, mediaType: ['image'], success(res2) { const tempFiles = res2.tempFiles[0]; $$.showLoading(); wx.uploadFile({ url: `${$$.baseUrl}${$$.url.sys}/api/wechat/fileInfo/recognitionText`, filePath: tempFiles.tempFilePath, name: 'file', header: { Authorization: app.globalData.token }, complete(res3) { $$.hideLoading(); if (res3.errMsg === 'uploadFile:ok') { let { code, data } = JSON.parse(res3.data); if (code == -1) { $$.errorModal({ content: '识别失败' }); return; } let wordsResult = data?.ocrResult?.wordsResult.join(''); let wordsResultNum = data?.ocrResult?.wordsResultNum; that.setData({ submitData: { ...that.data.submitData, [key]: that.data.submitData[key] + wordsResult }, [keyNum]: (that.data.submitData[keyNum] + wordsResult).length }); } }, }); }, }); }, //选择地址 async openmap(e) { var that = this; console.log('latitude') wx.getLocation({ type: 'gcj02', //返回可以用于wx.openLocation的经纬度 success: function (res) { wx.chooseLocation({ success: function (res) { that.checkRegisterArea(res) }, }) } }) }, async checkRegisterArea(item) { $$.showLoading(); const res = await checkRegisterAreaApi({ lng: item.longitude, lat: item.latitude }); $$.hideLoading(); if (res.type) { console.log('res', res); if (res.data) { this.setData({ submitData: { ...this.data.submitData, addr: item.address, lng: item.longitude, lat: item.latitude, } }) } else { $$.errorModal({ title: '提示信息', content: res.msg, success: () => { }, }); } } }, delAddress() { this.setData({ submitData: { ...this.data.submitData, addr: '', lng: '', lat: '' } }) }, // 上传文件图片 async handleUploadFile(e) { let id = e.currentTarget.dataset.id; let type = e.currentTarget.dataset.type; let key = e.currentTarget.dataset.key; if (key) { this.setData({ showFileTip: false }) } let that = this; this.filesArr = []; wx.chooseMedia({ mediaType: ['image'], success(res2) { const tempFiles = res2.tempFiles; // 多个文件逐一上传 tempFiles.forEach((x, t) => { $$.showLoading('上传中...'); wx.uploadFile({ url: `${$$.baseUrl}${$$.url.sys}/api/wechat/fileInfo/upload?mainId=${id}&ownerId=${id}&ownerType=${type}`, filePath: x.tempFilePath, name: 'file', header: { Authorization: app.globalData.token }, complete(res) { $$.hideLoading(); if (res.errMsg === 'uploadFile:ok') { const getData = JSON.parse(res.data) const file = { ...getData.data[0], wxurl: x.tempFilePath }; that.setData({ fileList: that.data.fileList.concat(file) }) $$.showToast({ icon: 'success', title: '上传成功', duration: 500 }); } else { $$.showToast({ title: '上传失败', duration: 500 }); } }, }); }); }, }); }, // 弹窗取消上传附件 noUploadNext() { this.setData({ stepsActive: 2, showFileTip: false }); }, // 预览图片 handlePreviewImage(e) { let item = e.currentTarget.dataset.item; console.log('item', item); let index = e.currentTarget.dataset.index; wx.previewImage({ current: item.wxurl, urls: [item.wxurl] // 需要预览的图片http链接列表 }); }, // 删除图片 async handleDelImage(e) { let item = e.currentTarget.dataset.item; let index = e.currentTarget.dataset.index; let id = e.currentTarget.dataset.id; let type = e.currentTarget.dataset.type; $$.showModal({ title: '删除材料确认', content: '确定删除材料' + item.name + '吗?', cancelText: '我再想想', confirmText: '确定删除', success: async (res) => { if (res.confirm) { $$.showLoading(); const res = await delfileApi(id); if (res.type) { $$.showToast({ icon: 'success', title: '删除成功', duration: 500 }); let list = this.data.fileList.filter((i, idx) => idx !== index); console.log('list', list); this.setData({ fileList: list }) } } }, }); }, // 请求下拉框资源 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 || '', certiType: data.certiType || '09_00015-1', certiTypeName: data.certiTypeName || '身份证', agentCode: 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; let oneList = this.data.oneList; if (!perType) { this.setData({ addPerson: true }) } else { this.setData({ addPerson: false }) if (perTypeName === '申请方代理人') { // 申请方 或 被申请方 let newList = oneList.filter(item => item.perType === "15_020008-1"); let objs = newList.map(i => ({ trueName: i.trueName, agentCode: i.agentCode, })); wx.navigateTo({ url: `../../pages/addAgent/index?perType=${perType}&perTypeName=${perTypeName}&objs=${JSON.stringify(objs)}`, }); } else if (perTypeName === '被申请方代理人') { // 申请方 或 被申请方 let newList = oneList.filter(item => item.perType === "15_020008-2"); let objs = newList.map(i => ({ trueName: i.trueName, agentCode: i.agentCode, })); wx.navigateTo({ url: `../../pages/addAgent/index?perType=${perType}&perTypeName=${perTypeName}&objs=${JSON.stringify(objs)}`, }); } else { wx.navigateTo({ url: `../../pages/addPerson/index?perType=${perType}&perTypeName=${perTypeName}`, }); } } }, // 修改当事人 oneEditPerson(e) { let item = e.currentTarget.dataset.item; let index = e.currentTarget.dataset.index; let oneList = this.data.oneList; if (item.perType === '24_00006-1') { let newList = oneList.filter(item => item.perType === "15_020008-1"); let objs = newList.map(i => ({ trueName: i.trueName, agentCode: i.agentCode, })); wx.navigateTo({ url: `../../pages/addAgent/index?data=${JSON.stringify(item)}&index=${index}&objs=${JSON.stringify(objs)}`, }); } else if (item.perType === '24_00006-2') { let newList = oneList.filter(item => item.perType === "15_020008-2"); let objs = newList.map(i => ({ trueName: i.trueName, agentCode: i.agentCode, })); wx.navigateTo({ url: `../../pages/addAgent/index?data=${JSON.stringify(item)}&index=${index}&objs=${JSON.stringify(objs)}`, }); } else { 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 () { 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; if (this.data.editIndex) { list[this.data.editIndex] = this.data.oneData; } else { list = list.concat(this.data.oneData) } console.log('list', list); this.setData({ oneList: list, oneData: {}, editIndex: false, }) } if (this.data.twoData?.label) { this.setData({ submitData: { ...this.data.submitData, caseType: this.data.twoData.value, caseTypeName: this.data.twoData.label, }, 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.submitData[this.data.twoKey] + this.data.twoValue, }, [this.data.twoKey + 'Num']: (this.data.submitData[this.data.twoKey] + this.data.twoValue).length, twoValue: '', twoKey: '' }) } }, onHide: function () { // this.handleCheckSave(); }, onUnload: function () { // this.handleCheckSave(); }, });