// pages/addPerson/index.js const $$ = require('../../utils/util'); const app = getApp(); import Toast from '../../components/vant/toast/toast'; Page({ /** * 页面的初始数据 */ select: {}, // 下拉框数据 data: { imgUrl: $$.url.img, popup: { formtype: '', index: 0, }, personTypes: [{ title: '自然人', imgUrl: $$.url.img + 'person-types_1.png', imgUrlActive: $$.url.img + 'person-types_1_active.png', }, { title: '法人', imgUrl: $$.url.img + 'person-types_2.png', imgUrlActive: $$.url.img + 'person-types_2_active.png', }, { title: '非法人组织', imgUrl: $$.url.img + 'person-types_3.png', imgUrlActive: $$.url.img + 'person-types_3_active.png', }], personTypesActive: 0, // 人员类型切换 perType: '', formData: { trueName: '', mobile: '', certiType: '09_00015-1', certiTypeName: '身份证', certiNo: '', addr: '', placeAddr: '', workUnit: '', nation: '', nationName: '', sex: '09_00003-1', sexName: '男', }, //表单存储对象 frData: {}, ffrData: {} }, // 保存 handleNext(e) { let personTypesActive = this.data.personTypesActive; let data = { ...this.data.formData, perType: this.data.perType, agentCode: this.data.radio, perTypeName: this.data.perTypeName, perClass: personTypesActive === 0 ? '09_01001-1' : personTypesActive === 1 ? '09_01001-2' : personTypesActive === 2 ? '09_01001-3' : "", perClassName: personTypesActive === 0 ? '自然人' : personTypesActive === 1 ? '法人' : personTypesActive === 2 ? '非法人组织' : "", } // 获取当前页面栈 var pages = getCurrentPages(); // 上一个页面 var prevPage = pages[pages.length - 2]; // 直接设置数据对象到上一页面的data中 prevPage.setData({ oneData: data, editIndex: this.data.editIndex || false, }); wx.navigateBack({ delta: 1, }) }, // 选择法人或非法人组织 selectUnit(e) { let type = e.currentTarget.dataset.type; // 法人信息 非法人组织 if (type === 'person' || type === 'units') { wx.navigateTo({ url: '../../pages/addUnit/index?type=' + type, }); } }, // 获取手机号码 async _handleGetPhoneNumber(e) { let that = this; let phone = await that.selectComponent('#common-page').handleGetPhoneNumber(e.detail.code); that.data.formData.mobile = phone; that.setData({ formData: that.data.formData }); }, // 身份证ocr handleOCR(e) { 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/wecatRecognition`, 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; } that.data.formData.certiNo = data?.ocrResult.certiNo; that.data.formData.certiType = data?.ocrResult.certiType; that.data.formData.certiTypeName = data?.ocrResult.certiTypeName; that.data.formData.trueName = data?.ocrResult.trueName; that.data.formData.placeAddr = data?.ocrResult.placeAddr; that.data.formData.sex = data?.ocrResult.sex; that.data.formData.sexName = data?.ocrResult.sexName; that.data.formData.nation = data?.ocrResult.nation; that.data.formData.nationName = data?.ocrResult.nationName; that.setData({ formData: that.data.formData }); } }, }); }, }); }, // 表单修改 handleChange(e) { let key = e.currentTarget.dataset.key, value = e.detail; if (key === 'sex') { this.data.formData[key] = value; this.data.formData[key + 'Name'] = value === '09_00003-2' ? '女' : value === '09_00003-1' ? '男' : ''; } else { this.data.formData[key] = value; } this.setData({ formData: this.data.formData }); }, // 人员类型切换 _handleSelectData(e) { let index = e.currentTarget.dataset.index; this.setData({ personTypesActive: index }) if (index === 1) { this.setData({ ffrData: {}, formData: { trueName: '', mobile: '', certiType: '09_00015-1', certiTypeName: '身份证', certiNo: '', addr: '', placeAddr: '', workUnit: '', nation: '', nationName: '', sex: '09_00003-1', sexName: '男', } }) } if (index === 2) { this.setData({ frData: {}, formData: { trueName: '', mobile: '', certiType: '09_00015-1', certiTypeName: '身份证', certiNo: '', addr: '', placeAddr: '', workUnit: '', nation: '', nationName: '', sex: '09_00003-1', sexName: '男', } }) } }, // 下拉框选择开启 handleShowPopup(e) { let type = e.currentTarget.dataset.type; let selectData = []; let selectOption = this.select[type]; selectData = [{ values: selectOption, defaultIndex: 0 }]; this.setData({ popup: { formtype: e.currentTarget.dataset.key, 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 }); }, // 下拉框选择确认 handleConfirmPicker({ detail }) { let formtype = this.data.popup.formtype; let value = detail.detail.value, arr = []; this.data.popup.visible = false; this.data.formData[formtype] = value[0].value; this.data.formData[formtype + 'Name'] = value[0].label; this.setData({ popup: this.data.popup, formData: this.data.formData }); }, // 请求下拉框资源 async getSelectOptionData() { const res = await $$.commonRequest({ url: `${$$.url.assets}selectOption.json`, type: 'get' }); if (res) { this.select.cardType = res.data.cardType || []; this.select.nation = res.data.nation || []; } }, onChange(event) { console.log('event.detail', event.detail); this.setData({ radio: event.detail, }); }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let { perType, perTypeName, data, index, objs, } = options; let selectList = JSON.parse(objs) console.log('selectList', selectList); if (data) { data = JSON.parse(data); wx.setNavigationBarTitle({ title: "修改" + data.perTypeName }) this.setData({ selectList, editIndex: index, radio: data.agentCode, formData: data, perType: data.perType, perTypeName: data.perTypeName, personTypesActive: data.perClass === '09_01001-1' ? 0 : data.perClass === '09_01001-2' ? 1 : data.perClass === '09_01001-3' ? 2 : 0, }) } else { wx.setNavigationBarTitle({ title: "添加" + perTypeName }) this.setData({ selectList, radio: selectList[0]?.agentCode, perType, perTypeName }) } this.getSelectOptionData(); }, /** * 生命周期函数--监听页面显示 */ onShow() { }, })