// pages/perfectInformation/index.js const $$ = require('../../utils/util'); // 保存信息 function setUserInfoApi(submitData) { return $$.request({ url: 'paUser/perfectInfo', type: 'post', submitData, service: 'cust' }); } Page({ /** * 页面的初始数据 */ copySubmitData: {}, // 数据复制 isCheck: false, data: { submitData: { trueName: '', mobile: '', sex: '09_00003-1', sexName: '男', idcardType: '09_00015-1', idcardTypeName: '身份证', idcard: '', city: '', cityName: '', area: '', areaName: '', road: '', roadName: '', village: '', villageName: '', addr: '', }, popup: {}, // 下拉弹出框数据 isCheck: false, // 是否只是查看 isImproveData: false, // 是否是完善资料进入,则不显示身份证的修改 }, // 展示弹出层 handleShowPopup(e) { this.setData({ popup: e.detail }); }, // 关闭弹出层 handleClosePopup() { this.data.popup.visible = false; this.setData({ popup: this.data.popup }); }, // 下拉框确认选择 handleConfirmPicker({ detail }) { let type = this.data.popup.type; let value = detail.detail.value; let arr = []; this.data.popup.visible = false; 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 || ''; }); } else { if (type === 'cardType') { arr = ['idcardType', 'idcardTypeName']; } else if (type === 'sex') { arr = ['sex', 'sexName']; } arr.forEach((x, t) => { this.data.submitData[x] = value[t === 0 ? 'value' : 'label']; }); } this.setData({ submitData: this.data.submitData, popup: this.data.popup }); }, // form的change handleChange(e) { const { key, value } = e.detail; this.data.submitData[key] = value; this.setData({ submitData: this.data.submitData }); }, // 修改picker的列时触发 handleChangeColumns(e) { if (this.data.popup.type === 'location') { let selectData = $$.changeLocation(e, this.selectComponent('#personal-data-dom').location, this.data.popup.selectData); this.setData({ popup: { ...this.data.popup, selectData } }); } }, // 验证 checkSubmitData() { if (this.data.submitData.mobile && !$$.mobileRegExp(this.data.submitData.mobile)) { $$.showToast({ title: '请输入正确的手机号码' }); return false; } let userInfo = wx.getStorageSync('userInfo'); let that = this; if (userInfo.realStatus === '1' && this.data.submitData.trueName !== this.copySubmitData.trueName) { $$.showModal({ content: '您修改了姓名,修改后需重新实名认证,是否继续操作?', success: (res) => { if (res.confirm) { userInfo.realStatus = '99'; wx.setStorageSync('userInfo', userInfo); that.handleSave(); } }, }); return false; } if (userInfo.realStatus === '1' && this.data.submitData.idcard !== this.copySubmitData.idcard) { $$.showModal({ content: '您修改了身份证号码,修改后需重新实名认证,是否继续操作?', success: (res) => { if (res.confirm) { userInfo.realStatus = '99'; wx.setStorageSync('userInfo', userInfo); that.handleSave(); } }, }); return false; } that.handleSave(); }, // 保存 async handleSave() { $$.showLoading(); const res = await setUserInfoApi(this.data.submitData); $$.hideLoading(); if (res.type) { $$.showToast({ title: '操作成功', icon: 'success' }); await $$.sleep(); wx.navigateBack({ delta: 1, }); } }, // 获取个人信息 getUserInfo(e) { let data = e.detail || {}; let keys = Object.keys(this.data.submitData); keys.forEach((x) => { if (data[x]) { this.data.submitData[x] = data[x]; } }); if (this.isCheck && this.data.submitData.idcardType === '09_00015-1') { this.data.submitData.idcard = `${this.data.submitData.idcard?.substring(0, 6)}********${this.data.submitData.idcard?.substring(14)}`; } this.setData({ submitData: this.data.submitData }); this.copySubmitData = Object.assign({}, this.data.submitData); }, // 获取手机号码 async handleGetPhoneNumber(e) { let phone = await this.selectComponent('#common-page').handleGetPhoneNumber(e.detail); this.data.submitData.mobile = phone; this.setData({ submitData: this.data.submitData }); }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ isCheck: !!options.isCheck, isImproveData: !!options.type }); this.isCheck = !!options.isCheck; }, });