const reqInterface = require("../../../api/models"); const reg = require("../../../utils/regHelper"); const {matchValue, imagePrefix} = require("../../../utils/dataHelper"); Page({ /** * 页面的初始数据 */ data: { api: '', id: '', info: { // 基本信息 name: '', gender: '', pid: '', birthday: '', phone: '', degree: '', homeAddress: '', workName: '', workAddress: '', // 银行 bankNumber: '', bankName: '', bankBranch: '', carAmount: '', socialAmount: '', workAmount: '', askType: '', // 照片 pidPath: '', bookletPath: '', personPath: '', bankPath: '', insuredPath: '', jobPath: '', // 签名 signPath: '', status: 0 }, showInfo: { gender: '', degree: '', askType: '', pidFrontPhoto: '', pidLaterPhoto: '', bookletPhoto: '', personPathPhoto: '', bankPhoto: '', insuredPhoto: '', jobPhoto: [], pidFrontPath: '', pidLaterPath: '', retire_age_man: 0, retire_age_women: 0 }, steps: [{ text: '填写资料一' }, { text: '填写资料二' }, { text: '补充资料' }, { text: '签名' } ], active: 0, curActive: 0, }, onLoad(opt) { if (opt.id) { this.setData({ id: opt.id }) } if (opt.id || wx.getStorageSync('id')) { this.getDetail() } }, /** * 生命周期函数--监听页面显示 */ onShow() { let self = this; self.setData({ api: imagePrefix() }) // 获取退休年龄 reqInterface.GetBladeSystemDictDictionary({ code: 'retire_age' }).then(res => { self.setData({ 'showInfo.retire_age_man': res[0].dictKey, 'showInfo.retire_age_women': res[1].dictKey }) }) }, getDetail() { let self = this; reqInterface.GetConsumerinfoCheckDetail({ consumerInfoId: self.data.id ? self.data.id : wx.getStorageSync('id') }).then(res => { self.data.showInfo.jobPhoto = res.jobPath.split(",") for (let i = 0; i < self.data.showInfo.jobPhoto.length; i++) { self.data.showInfo.jobPhoto[i] = self.data.api + self.data.showInfo.jobPhoto[i]; } self.setData({ info: res, 'info.status': 0, 'showInfo.pidFrontPhoto': res.pidPath ? self.data.api + res.pidPath.split(',')[0] : '', 'showInfo.pidLaterPhoto': res.pidPath ? self.data.api + res.pidPath.split(',')[1] : '', 'showInfo.bookletPhoto': res.bookletPath ? self.data.api + res.bookletPath : '', 'showInfo.personPathPhoto': res.personPath ? self.data.api + res.personPath : '', 'showInfo.bankPhoto': res.bankPath ? self.data.api + res.bankPath : '', 'showInfo.insuredPhoto': res.insuredPath ? self.data.api + res.insuredPath : '', 'showInfo.jobPhoto': self.data.showInfo.jobPhoto, }) }) }, errorCheck() { return new Promise((resolve, reject) => { let self = this; switch (self.data.curActive) { case 0: if (!self.data.showInfo.pidFrontPhoto) { self.errorInfo('请上传身份证人像面'); reject(false) return false; } if (!self.data.showInfo.pidLaterPhoto) { self.errorInfo('请上传身份证国徽面'); reject(false) return false; } if (!self.data.info.name) { self.errorInfo('请填写姓名'); reject(false) return false; } if (!self.data.info.gender) { self.errorInfo('请选择性别'); reject(false) return false; } if (!self.data.info.pid) { self.errorInfo('请填写身份证号'); reject(false) return false; } if (!self.data.info.phone) { self.errorInfo('请填写联系电话'); reject(false) return false; } if (!self.data.info.degree) { self.errorInfo('请选择文化程度'); reject(false) return false; } if (!self.data.info.homeAddress) { self.errorInfo('请填写家庭住址'); reject(false) return false; } if (!self.data.info.workName) { self.errorInfo('请填写务工单位'); reject(false) return false; } if (!self.data.info.workAddress) { self.errorInfo('请填写单位地址'); reject(false) return false; } break; case 1: if (!self.data.showInfo.bankPhoto) { self.errorInfo('请上传银行卡照片'); reject(false) return false; } if (!self.data.info.bankNumber) { self.errorInfo('请填写银行卡号'); reject(false) return false; } if (!self.data.info.bankName) { self.errorInfo('请填写开户银行'); reject(false) return false; } if (self.data.info.carAmount === '') { self.errorInfo('请选择一次性交通补贴'); reject(false) return false; } if (self.data.info.socialAmount === '') { self.errorInfo('请选择个人社保补贴'); reject(false) return false; } if (self.data.info.workAmount === '') { self.errorInfo('请选择就业补贴'); reject(false) return false; } if (!self.data.info.askType) { self.errorInfo('请选择补贴对象'); reject(false) return false; } break; case 2: if (!self.data.showInfo.bookletPhoto) { self.errorInfo('请上传户口本户主页'); reject(false) return false; } if (!self.data.showInfo.personPathPhoto) { self.errorInfo('请上传户口本本人页'); reject(false) return false; } if (!self.data.showInfo.insuredPhoto) { self.errorInfo('请上传参保证明'); reject(false) return false; } if (!self.data.showInfo.jobPhoto) { self.errorInfo('请上传工作证明'); reject(false) return false; } break; } resolve(true) }) }, errorInfo(val) { wx.showToast({ title: val, icon: 'none' }) }, toNext(e) { let self = this; self.errorCheck().then(() => { switch (self.data.curActive) { case 0: reqInterface.PostConsumerinfoSubmit(self.data.info).then(res => { if (!self.data.id) { wx.setStorageSync('id', res.id) } self.setData({ 'info.id': res.id, id: res.id, active: 1, curActive: 1, }) }) break; case 1: reqInterface.PostConsumerinfoSubmit(self.data.info).then(res => { self.setData({ 'info.id': res.id, id: res.id, active: 2, curActive: 2, }) }) break; case 2: reqInterface.PostConsumerinfoSubmit(self.data.info).then(res => { self.setData({ 'info.id': res.id, id: res.id, active: 3, curActive: 3, }) }) break; } }) }, toFront() { let self = this; // self.getDetail() if (self.data.active == 1) { self.setData({ active: 0, curActive: 0, }) } if (self.data.active == 2) { self.setData({ active: 1, curActive: 1, }) } if (self.data.active == 3) { self.setData({ active: 2, curActive: 2, }) } }, async ocrCheckIdCardFront(e) { let self = this; // 计算年纪 const startdate = new Date(e.detail.birth.text); const now = new Date(); const year = now.getFullYear(); const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始,所以加1,并补零 const day = String(now.getDate()).padStart(2, '0'); // 补零 const enddate = new Date(`${year}-${month}-${day}`); const timeDifference = enddate.getTime() - startdate.getTime(); const age = Math.floor(timeDifference / (1000 * 60 * 60 * 24 * 365)); // 判断是否满足申请年龄 if (e.detail.gender.text == '男' && age > self.data.showInfo.retire_age_man) { wx.showModal({ title: '无法申请', content: '已超出申请年龄,无法申请', confirmText: '退出申请', showCancel: false, success(res1) { if (res1.confirm) { wx.reLaunch({ url: '/pages/my/index/index', }) } } }) } else if (e.detail.gender.text == '女' && age > self.data.showInfo.retire_age_women) { wx.showModal({ title: '无法申请', content: '已超出申请年龄,无法申请', confirmText: '退出申请', showCancel: false, success(res1) { if (res1.confirm) { wx.reLaunch({ url: '/pages/my/index/index', }) } } }) } else { try { self.setData({ 'info.name': e.detail.name.text, 'info.gender': e.detail.gender.text == '男' ? 1 : 2, 'showInfo.gender': e.detail.gender.text, 'info.pid': e.detail.id.text, 'info.birthday': e.detail.birth.text, 'info.homeAddress': e.detail.address.text, }) let res = await reqInterface.PostImageUpload(e.detail.image_path); self.setData({ 'showInfo.pidFrontPhoto': res.data.url, 'showInfo.pidFrontPath': res.data.path }) if (self.data.showInfo.pidFrontPath) { self.setData({ 'info.pidPath': self.data.showInfo.pidFrontPath + ',' + self.data.showInfo.pidLaterPath }) } } catch { } } }, async ocrCheckIdCardLater(e) { try { let self = this; let res = await reqInterface.PostImageUpload(e.detail.image_path); self.setData({ 'showInfo.pidLaterPhoto': res.data.url, 'showInfo.pidLaterPath': res.data.path }) if (self.data.showInfo.pidLaterPath) { self.setData({ 'info.pidPath': self.data.showInfo.pidFrontPath + ',' + self.data.showInfo.pidLaterPath }) } } catch { } }, nameValue(e) { let self = this; if (!e.detail.val) { self.errorInfo('请填写姓名'); return false; } self.setData({ 'info.name': e.detail.val }) }, genderValue(e) { let self = this; self.setData({ 'info.gender': e.detail.val }) }, idNumberValue(e) { let self = this; console.log(e.detail.val) reg.IDCard(e.detail.val).then(res => { if (res) { self.setData({ 'info.pid': e.detail.val }) } }).catch(() => { self.setData({ 'info.pid': '' }) }) }, // 联系电话 phoneValue(e) { let self = this; reg.phone(e.detail.val).then(res => { if (res) { self.setData({ 'info.phone': e.detail.val }) } }).catch(err => { self.setData({ 'info.phone': '' }) }) }, // 文化程度 degreeValue(e) { let self = this; self.setData({ 'info.degree': e.detail.val }) }, // 家庭住址 homeAddressValue(e) { let self = this; if (!e.detail.val) { self.errorInfo('请填写家庭住址'); return false; } self.setData({ 'info.homeAddress': e.detail.val }) }, // 务工单位 workNameValue(e) { let self = this; if (!e.detail.val) { self.errorInfo('请填写务工单位'); return false; } self.setData({ 'info.workName': e.detail.val }) }, // 单位地址 workAddressValue(e) { let self = this; if (!e.detail.val) { self.errorInfo('请填写单位地址'); return false; } self.setData({ 'info.workAddress': e.detail.val }) }, // 银行卡识别 async ocrCheckBankCard(e) { let self = this; self.setData({ 'info.bankNumber': e.detail.number.text, }) let res = await reqInterface.PostImageUpload(e.detail.image_path); self.setData({ 'showInfo.bankPhoto': res.data.url, 'info.bankPath': res.data.path }) }, // 银行卡号 bankNumberValue(e) { let self = this; if (!e.detail.val) { self.errorInfo('请填写银行卡号'); return false; } self.setData({ 'info.bankNumber': e.detail.val }) }, // 开户银行 bankNameValue(e) { let self = this; if (!e.detail.val) { self.errorInfo('请填写开户银行'); return false; } self.setData({ 'info.bankName': e.detail.val }) }, // 支行名称 bankBranchValue(e) { let self = this; self.setData({ 'info.bankBranch': e.detail.val }) }, // 一次性交通补贴 carAmountValue(e) { let self = this; self.setData({ 'info.carAmount': e.detail.val }) }, // 个人社保补贴 socialAmountValue(e) { let self = this; self.setData({ 'info.socialAmount': e.detail.val }) }, // 就业补贴 workAmountValue(e) { let self = this; self.setData({ 'info.workAmount': e.detail.val }) }, // 性质 askTypeValue(e) { let self = this; self.setData({ 'info.askType': e.detail.val }) }, // 户口本 bookletPhotoValue(data) { let self = this; self.setData({ 'showInfo.bookletPhoto': data.detail.url, 'info.bookletPath': data.detail.path }) }, // 户口本本人 personPathValue(data) { let self = this; self.setData({ 'showInfo.personPathPhoto': data.detail.url, 'info.personPath': data.detail.path }) }, // 参保证明 insuredPhotoValue(data) { let self = this; self.setData({ 'showInfo.insuredPhoto': data.detail.url, 'info.insuredPath': data.detail.path }) }, // 工作证明 jobPhotoValue(data) { let self = this; console.log(data) self.data.info.jobPath = data.detail.imagesPath.join(",") self.setData({ 'showInfo.jobPhoto': data.detail.images, 'info.jobPath': self.data.info.jobPath }) }, toSign(e) { console.log(e) wx.navigateTo({ url: '/pages/info/sign/index?id=' + e.currentTarget.dataset.id, }) }, imageError(e) { this.setData({ [e.currentTarget.dataset.imgkey]: e.currentTarget.dataset.errimage, }) }, })