const util = require('../../utils/util.js'); const api = require('../../config/api.js'); // 使用引入的模块进行相关操作 Page({ data: { width:380,//宽度 height: 250,//高度 max_width:400, max_height:500, showCropper: false, croppedImageSrc: '', orgImageSrc: '', orgImageName: '', isalert: false, isalert1: false, isShowBankManual: false, ifchild: false, showbanktype: false, tipsdialog: false, refname: null, refidcard: null, refbankcard: null, refbankcardname: null, refbanktype: null, refbanktypeinfo: null, refbankmanual: null, reftel: null, imageUrlIdcard: '', // 用于存储上传的图片路径 resIdcardImgUrl: '', imageUrlBankcard: '', // 用于存储上传的图片路径 resBankcardImgUrl: '', imageUrlChildId: '', // 用于存储上传的图片路径 resChildIdImgUrl: '', bankType: [ { name: '中国银行', value: 0 ,msg:"请输入中国银行卡号"}, { name: '中国工商银行', value: 1 ,msg:'请输入中国工商银行卡号'}, { name: '中国建设银行', value: 2 ,msg:'请输入中国建设银行卡号'}, { name: '中国农业银行', value: 3 ,msg:'请输入中国农业银行卡号'}, { name: '中国邮政储蓄银行', value: 4 ,msg:'请输入中国邮政储蓄银行卡号'}, { name: '新疆农村信用社', value: 5 ,msg:'请输入新疆农村信用社卡号'}, { name: '新疆昆仑银行', value: 6 ,msg:'请输入新疆昆仑银行卡号'}, { name: '其他(手工填写)', value: 7 ,msg:'其他(手工填写)'}, ], }, onLoad: function (options) { console.log('onload'); }, onReady: function() { console.log('onReady'); this.onShowTips(); }, //裁剪图片开始 preventDefault() { // 阻止默认点击事件 }, // 裁剪器加载完成 onCropperLoad() { console.log('裁剪器加载完成'); }, OnCropperloadimage(e){ wx.hideLoading(); console.log("图片加载完成",e.detail); //图片重置一下 this.selectComponent("#image-cropper").imgReset(); }, // 触发裁剪操作 triggerCut() { const cropper = this.selectComponent("#image-cropper") console.log(cropper, 'triggerCut被点击'); if (cropper) { // 模拟触发裁剪事件 cropper.triggerEvent('tapcut'); } }, // 确认裁剪 onCropperConfirm(e) { console.log('裁剪按钮被点击'); let that = this; const cropper = this.selectComponent("#image-cropper") cropper.getImg((obj) => { //app.globalData.imgSrc = obj.url; console.log('裁剪后的图片路径1:', obj.url); that.setData({ showCropper: false }); if(this.data.orgImageName == 'idcard'){ that.uploadImageIdcard(obj.url); // 上传图片 } else if(this.data.orgImageName == 'bankcard'){ that.uploadImageBankcard(obj.url); // 上传图片 }else if(this.data.orgImageName == 'childcard'){ that.uploadImageChildId(obj.url); // 上传图片 } }); }, // 取消裁剪 onCropperCancel() { this.setData({ showCropper: false }); }, rotate() { //在用户旋转的基础上旋转90° const cropper = this.selectComponent("#image-cropper") cropper.setAngle(cropper.data.angle += 90); }, end(e) { clearInterval(this.data[e.currentTarget.dataset.type]); }, //裁剪图片结束 handleSubmit:function(){ var that = this; console.log(this.data.refname, "refname"); console.log(this.data.refidcard, "refidcard"); console.log(this.data.refbankcard, "refbankcard"); console.log(this.data.refbankcardname, "refbankcardname"); console.log(this.data.refbanktypeinfo, "refbanktypeinfo"); console.log(this.data.refbanktype, "refbanktype"); console.log(this.data.refbankmanual, "refbankmanual"); console.log(this.data.reftel, "reftel"); console.log(this.data.resIdcardImgUrl, "resIdcardImgUrl"); console.log(this.data.resBankcardImgUrl, "resBankcardImgUrl"); console.log(this.data.resChildIdImgUrl, "resChildIdImgUrl"); util.requestPost(api.createRefund, { refname: that.data.refname, refidcard: that.data.refidcard, refbankcard: that.data.refbankcard, refbankcardname: that.data.refbankcardname, refbanktype: that.data.refbanktype, reftel: that.data.reftel, zidcardimg: that.data.resIdcardImgUrl, zbankcardimg: that.data.resBankcardImgUrl, childidcardimg: that.data.resChildIdImgUrl, }) .then(function(res) { if (res.code === 0) { console.log("createRefund res:"); console.log(res); console.log("createRefund resdata:"); console.log(res.data); wx.showToast({ title: '申请上传成功', icon: 'success', }); setTimeout(() => { // 使用 wx.switchTab 切换到带有 tabBar 的首页 wx.switchTab({ url: '/pages/index/index', }) }, 1000); }else if (res.code == 1002025012){ that.setData({ isalert1: true }) }else{ wx.showToast({ title: '申请上传失败', icon: 'success', }); } }); }, handleReset:function(){ this.setData({ refname: '', refidcard: '', refbankcard: '', refbankcardname: '', refbanktype: '', refbanktypeinfo: '', refbankmanual: '', reftel: '', imageUrlIdcard: '', // 用于存储上传的图片路径 resIdcardImgUrl: '', imageUrlBankcard: '', // 用于存储上传的图片路径 resBankcardImgUrl: '', imageUrlChildId: '', // 用于存储上传的图片路径 resChildIdImgUrl: '', }) }, onConfirmTips: function(){ this.setData({ tipsdialog: false }) }, onShowTips: function(){ this.setData({ tipsdialog: true }) }, onhandleSubmit: function(){ this.setData({ isalert: true }) }, onConfirmAlert1: function(){ this.setData({ isalert1: false }) }, onConfirmAlert: function(){ this.setData({ isalert: false }) console.log(this.data.refname, "refname"); console.log(this.data.refidcard, "refidcard"); console.log(this.data.refbankcard, "refbankcard"); console.log(this.data.refbankcardname, "refbankcardname"); console.log(this.data.refbanktypeinfo, "refbanktypeinfo"); console.log(this.data.refbanktype, "refbanktype"); console.log(this.data.refbankmanual, "refbankmanual"); console.log(this.data.reftel, "reftel"); console.log(this.data.resIdcardImgUrl, "resIdcardImgUrl"); console.log(this.data.resBankcardImgUrl, "resBankcardImgUrl"); console.log(this.data.resChildIdImgUrl, "resChildIdImgUrl"); if(this.data.refname =='' || this.data.refname == null){ wx.showModal({ content: '就诊卡登记姓名不能为空', showCancel: false, }) } else if(this.data.refidcard =='' || this.data.refidcard == null){ wx.showModal({ content: '身份证号不能为空', showCancel: false, }) } else if(this.data.refbankcard =='' || this.data.refbankcard == null){ wx.showModal({ content: '银行卡号不能为空', showCancel: false, }) } else if(this.data.refbankcardname =='' || this.data.refbankcardname == null){ wx.showModal({ content: '银行卡持卡人姓名不能为空', showCancel: false, }) } else if(this.data.reftel =='' || this.data.reftel == null){ wx.showModal({ content: '手机号码不能为空', showCancel: false, }) } else if(this.data.resIdcardImgUrl =='' || this.data.resIdcardImgUrl == null){ wx.showModal({ content: '身份证正面不能为空', showCancel: false, }) } else if(this.data.resBankcardImgUrl =='' || this.data.resBankcardImgUrl == null){ wx.showModal({ content: '银行卡正面不能为空', showCancel: false, }) } else if((this.data.resChildIdImgUrl =='' || this.data.resChildIdImgUrl == null)&& (this.data.ifchild == true)){ wx.showModal({ content: '儿童证件不能为空', showCancel: false, }) } else{ this.handleSubmit(); } }, onCancelAlert: function(){ this.setData({ isalert: false }) }, showPopBankType(){ this.setData({ showbanktype: true }); }, onCloseBankType() { this.setData({ showbanktype: false, }); }, confirmBankType(e){ console.log(e.currentTarget.dataset.item) let item = e.currentTarget.dataset.item this.setData({ showbanktype: false, refbanktype: item.name, refbanktypeinfo: item.name }) if(item.value == 7){ this.setData({ isShowBankManual: true }) }else{ this.setData({ isShowBankManual: false }) } }, onChangeBankType: function(e){ this.setData({ refbanktype: e.detail }) }, onChangeRefname: function(e){ this.setData({ refname: e.detail }) }, onChangeRefbankcard: function(e){ this.setData({ refbankcard: e.detail }) }, onChangeRefbankcardname: function(e){ this.setData({ refbankcardname: e.detail }) }, onChangeReftel: function(e){ this.setData({ reftel: e.detail }) }, // 从身份证号码中提取生日信息(格式为YYYYMMDD) getBirthdayFromIdCard: function(idCard){ return idCard.substring(6, 14); // 这里假设身份证号码长度为18位并按照标准格式存放 }, // 将字符串类型的生日转换成Date对象 convertToDateObject: function(birthdayString){ const year = birthdayString.substr(0, 4); const month = birthdayString.substr(4, 2); const day = birthdayString.substr(6, 2); return new Date(`${year}-${month}-${day}`); }, // 计算年龄函数 calculateAge: function(idCard){ console.log(idCard); // 获取当前日期 const currentDate = new Date(); const birthdate = this.convertToDateObject(this.getBirthdayFromIdCard(idCard)); let age; if (currentDate >= birthdate && !isNaN(currentDate)) { age = Math.floor((currentDate - birthdate) / (365 * 24 * 60 * 60 * 1000)); console.log(age, "age0"); } else { console.error('无效的身份证号码或者未知错误'); } return age || ''; }, isValidID:function (id) { if (!/^\d{17}(\d|X)$/.test(id)) return false; // 检查格式是否正确 // 计算第18位校验码 const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; const checkCode = '10X98765432'; let sum = 0; for (let i = 0; i < id.length - 1; i++) { sum += parseInt(id[i], 10) * weights[i]; } sum = sum % 11; // 验证第18位校验码是否正确 return checkCode[sum] === id[17].toUpperCase(); }, onChangeIdcard(e) { this.data.refidcard = e.detail; console.log(this.data.refidcard, "idcard"); if(this.isValidID(this.data.refidcard) == false) return; let age = this.calculateAge(this.data.refidcard); console.log(age, "age"); if(age <= 15){ this.setData({ ifchild: true, }); console.log(this.data.ifchild, "child"); } }, // 选择银行卡图片 chooseImageBankcard() { let that = this; wx.showActionSheet({ itemList: ['拍照', '从相册选择'], success: (res) => { const sourceType = res.tapIndex === 0 ? ['camera'] : ['album']; // 0: 拍照, 1: 相册 // wx.chooseImage({ wx.chooseImage({ count: 1, // 只能选择一张图片 sizeType: ['compressed'], // 压缩图片 sourceType: sourceType, // 调用相机或相册 success: (res) => { wx.showLoading({ title: '加载中', }) const tempFilePaths = res.tempFilePaths; // this.setData({ // imageUrlBankcard: tempFilePaths[0], // 更新图片路径 // }); that.setData({ showCropper: true}, () => { // setData 的回调函数,确保页面已经重新渲染 const cropperInstance1 = this.selectComponent("#image-cropper"); if (cropperInstance1) { // 调用组件的方法 console.log('找到组件实例'); } else { console.log('未找到组件实例'); } }); that.setData({ orgImageSrc: tempFilePaths[0], // 更新图片路径 orgImageName: 'bankcard' }); //this.uploadImageBankcard(tempFilePaths[0]); // 上传图片 }, fail: (err) => { console.error('选择银行卡图片失败', err); wx.showToast({ title: '选择银行卡图片失败', icon: 'none', }); }, }); }, fail: (err) => { console.error('打开选择器失败', err); }, }); }, // 选择身份证图片 chooseImageChildId() { let that = this; wx.showActionSheet({ itemList: ['拍照', '从相册选择'], success: (res) => { const sourceType = res.tapIndex === 0 ? ['camera'] : ['album']; // 0: 拍照, 1: 相册 // wx.chooseImage({ wx.chooseImage({ count: 1, // 只能选择一张图片 sizeType: ['compressed'], // 压缩图片 sourceType: sourceType, // 调用相机或相册 success: (res) => { wx.showLoading({ title: '加载中', }) const tempFilePaths = res.tempFilePaths; // this.setData({ // imageUrlChildId: tempFilePaths[0], // 更新图片路径 // }); that.setData({ showCropper: true}, () => { // setData 的回调函数,确保页面已经重新渲染 const cropperInstance1 = this.selectComponent("#image-cropper"); if (cropperInstance1) { // 调用组件的方法 console.log('找到组件实例'); } else { console.log('未找到组件实例'); } }); that.setData({ orgImageSrc: tempFilePaths[0], // 更新图片路径 orgImageName: 'childcard' }); //this.uploadImageChildId(tempFilePaths[0]); // 上传图片 }, fail: (err) => { console.error('选择儿童证件图片失败', err); wx.showToast({ title: '选择儿童证件图片失败', icon: 'none', }); }, }); }, fail: (err) => { console.error('打开选择器失败', err); }, }); }, // 选择身份证图片 chooseImageIdcard() { let that = this; wx.showActionSheet({ itemList: ['拍照', '从相册选择'], success: (res) => { const sourceType = res.tapIndex === 0 ? ['camera'] : ['album']; // 0: 拍照, 1: 相册 wx.chooseImage({ count: 1, // 只能选择一张图片 sizeType: ['compressed'], // 压缩图片 sourceType: sourceType, // 调用相机或相册 success: (res) => { wx.showLoading({ title: '加载中', }) const tempFilePaths = res.tempFilePaths; console.log(tempFilePaths, "tempFilePaths"); that.setData({ showCropper: true}, () => { // setData 的回调函数,确保页面已经重新渲染 const cropperInstance1 = this.selectComponent("#image-cropper"); if (cropperInstance1) { // 调用组件的方法 console.log('找到组件实例'); } else { console.log('未找到组件实例'); } }); that.setData({ orgImageSrc: tempFilePaths[0], // 更新图片路径 orgImageName: 'idcard' }); //this.uploadImageIdcard(tempFilePaths[0]); // 上传图片 }, fail: (err) => { console.error('选择身份证图片失败', err); wx.showToast({ title: '选择身份证图片失败', icon: 'none', }); }, }); }, fail: (err) => { console.error('打开选择器失败', err); }, }); }, // 上传图片 uploadImageIdcard(filePath) { wx.showLoading({ title: '图片上传中', }) wx.uploadFile({ url: 'https://xytj.btlsoln.com/app-api/member/dept-info/upload', // url: 'http://192.168.10.172:58080/app-api/member/dept-info/upload', filePath: filePath, // 图片路径 name: 'file', // 文件对应的 key // 设置请求头 header: { 'tenant-id':'1', // 示例:设置授权信息 'Content-Type': 'multipart/form-data' // 可以根据需要修改 }, formData: { type: 'id_card_front', // 上传文件类型 }, success: (res) => { wx.hideLoading(); try{ const data = JSON.parse(res.data); // 解析服务器返回的数据 console.log('上传成功', data.data); wx.showToast({ title: '上传成功', icon: 'success', }); this.setData({ imageUrlIdcard: filePath }); this.setData({ resIdcardImgUrl: data.data, // 更新后端图片路径,用于请求 }); }catch(error){ // 解析失败,捕获错误信息 console.log('JSON 解析出错:', error); wx.showToast({ title: '上传失败', icon: 'none', }); } }, fail: (err) => { console.error('上传失败', err); wx.showToast({ title: '上传失败', icon: 'none', }); }, }); }, // 上传图片 uploadImageBankcard(filePath) { wx.showLoading({ title: '图片上传中', }) wx.uploadFile({ url: 'https://xytj.btlsoln.com/app-api/member/dept-info/upload', // url: 'http://192.168.10.172:58080/app-api/member/dept-info/upload', filePath: filePath, // 图片路径 name: 'file', // 文件对应的 key // 设置请求头 header: { 'tenant-id':'1', // 示例:设置授权信息 'Content-Type': 'multipart/form-data' // 可以根据需要修改 }, formData: { type: 'id_card_front', // 上传文件类型 }, success: (res) => { wx.hideLoading(); try { const data = JSON.parse(res.data); // 解析服务器返回的数据 console.log('上传成功', data.data); wx.showToast({ title: '上传成功', icon: 'success', }); this.setData({ imageUrlBankcard: filePath }); this.setData({ resBankcardImgUrl: data.data, // 更新后端图片路径,用于请求 }); }catch(error){ // 解析失败,捕获错误信息 console.log('JSON 解析出错:', error); wx.showToast({ title: '上传失败', icon: 'none', }); } }, fail: (err) => { console.error('上传失败', err); wx.showToast({ title: '上传失败', icon: 'none', }); }, }); }, // 上传图片 uploadImageChildId(filePath) { wx.showLoading({ title: '图片上传中', }) wx.uploadFile({ url: 'https://xytj.btlsoln.com/app-api/member/dept-info/upload', // url: 'http://192.168.10.172:58080/app-api/member/dept-info/upload', filePath: filePath, // 图片路径 name: 'file', // 文件对应的 key // 设置请求头 header: { 'tenant-id':'1', // 示例:设置授权信息 'Content-Type': 'multipart/form-data' // 可以根据需要修改 }, formData: { type: 'id_card_front', // 上传文件类型 }, success: (res) => { wx.hideLoading(); try { const data = JSON.parse(res.data); // 解析服务器返回的数据 console.log('上传成功', data.data); wx.showToast({ title: '上传成功', icon: 'success', }); this.setData({ imageUrlChildId: filePath }); this.setData({ resChildIdImgUrl: data.data, // 更新后端图片路径,用于请求 }); }catch(error){ // 解析失败,捕获错误信息 console.log('JSON 解析出错:', error); wx.showToast({ title: '上传失败', icon: 'none', }); } }, fail: (err) => { console.error('上传失败', err); wx.showToast({ title: '上传失败', icon: 'none', }); }, }); }, });