"use strict"; const common_vendor = require("../../common/vendor.js"); const request_index = require("../../request/index.js"); const api_loginApi = require("../../api/loginApi.js"); if (!Array) { const _easycom_u_action_sheet2 = common_vendor.resolveComponent("u-action-sheet"); _easycom_u_action_sheet2(); } const _easycom_u_action_sheet = () => "../../uni_modules/vk-uview-ui/components/u-action-sheet/u-action-sheet.js"; if (!Math) { _easycom_u_action_sheet(); } const _sfc_main = { __name: "IDcard", setup(__props) { const bottomshow = common_vendor.ref(false); const form = common_vendor.reactive({ name: "", tel: "", advisoryType: 1, status: 2, idCard: "", homeAddress: "", workUnit: "", izJs: 1, openId: common_vendor.index.getStorageSync("openid"), relationship: "" }); const bottomlist = [{ text: "拍摄图片", fontSize: 40 }, { text: "图片预览", fontSize: 40 }]; function isValid11DigitNumber(val) { return /^1[3-9]\d{9}$/.test(val); } function isValid18DigitNumber(val) { return /^(\d{18})$/.test(val); } const photoclick = (element) => { if (element) { common_vendor.index.previewImage({ urls: [specialImgeshow.value], // 必填,所有要预览的图片地址数组 current: specialImgeshow.value, // 可选,当前显示图片的地址,默认是 urls[0] indicator: "default", // 可选,指示器样式,H5/App 有效,值为 'default'(圆点)或 'number'(数字) longPressActions: { // 可选,仅 App 支持,长按图片时弹出的操作项 itemList: ["保存图片到相册"] } }); } else { angetMessage(); } }; const specialImge = common_vendor.ref(""); const uping = common_vendor.ref(true); const selectphoto = () => { if (!uping.value) { return; } if (specialImge.value) { bottomshow.value = true; } else { angetMessage(); } }; function angetMessage() { common_vendor.index.chooseImage({ count: 1, sourceType: ["album", "camera"], success: (chooseRes) => { common_vendor.index.navigateTo({ url: `/compontent/public/camera?url=${chooseRes.tempFilePaths[0]}&type=0` }); }, fail: (err) => { common_vendor.index.__f__("error", "at pages/addoldman/IDcard.vue:174", "拍照失败:", err); } }); } const ukey = common_vendor.ref( `${common_vendor.index.getStorageSync("openid") || ""}jhbg${String(Date.now()).slice(-5)}${String(Math.floor(Math.random() * 900) + 100)}` ); const next = () => { if (!form.name) { common_vendor.index.showToast({ title: "请填写姓名", icon: "error" }); } else if (!form.tel) { common_vendor.index.showToast({ title: "请填写电话", icon: "error" }); } else if (!isValid11DigitNumber(form.tel)) { common_vendor.index.showToast({ title: "电话格式错误", icon: "none" }); return; } else if (!form.idCard) { common_vendor.index.showToast({ title: "请填写身份证号", icon: "error" }); } else if (!isValid18DigitNumber(form.idCard)) { common_vendor.index.showToast({ title: "身份证号格式错误", icon: "none" }); return; } else if (!form.homeAddress) { common_vendor.index.showToast({ title: "请填写家庭住址", icon: "error" }); } else if (!form.workUnit) { common_vendor.index.showToast({ title: "请填写工作单位", icon: "error" }); } else { if (common_vendor.index.getStorageSync("allinfo").name) { let data = common_vendor.index.getStorageSync("allinfo"); data.guardianName = form.name; data.guardianPhone = form.tel; data.guardianIdCard = form.idCard; data.guardianHomeAddress = form.homeAddress; data.guardianWorkUnit = form.workUnit; data.relationship = form.relationship; data.guardianIdCardPositive = specialImge.value; data.modifyType = "jhr"; const urlpost = `${request_index.base_url}/api/elderInfo/updateElderInfo?ukey=${ukey.value}`; common_vendor.index.request({ url: urlpost, method: "POST", header: { "Content-Type": "application/json", "X-Access-Token": common_vendor.index.getStorageSync("token") || "" }, data, success: (res) => { if (res.data.result == "重复提交") { common_vendor.index.showToast({ title: `重复提交`, icon: "error" }); return; } if (res.data.result == "未做变更") { common_vendor.index.showToast({ title: `当前无变更,无需提交`, icon: "none" }); return; } if (res.data.success) { api_loginApi.getMessage(common_vendor.index.getStorageSync("openid")).then((res2) => { common_vendor.index.setStorageSync("allinfo", res2.result); common_vendor.index.reLaunch({ url: "/pages/oldmanindex/oldmansuccess?type=1&jianhu=1" }); }); } }, fail: (e) => { common_vendor.index.__f__("log", "at pages/addoldman/IDcard.vue:271", "????", e); } }); } else { let data = {}; data.guardianName = form.name; data.guardianPhone = form.tel; data.guardianIdCard = form.idCard; data.guardianHomeAddress = form.homeAddress; data.guardianWorkUnit = form.workUnit; data.relationship = form.relationship; data.guardianIdCardPositive = specialImge.value; const urlpost = `${request_index.base_url}/api/elderInfo/addElder?ukey=${ukey.value}`; common_vendor.index.request({ url: urlpost, method: "POST", header: { "Content-Type": "application/json", "X-Access-Token": common_vendor.index.getStorageSync("token") || "" }, data, success: (res) => { if (res.data.result == "重复提交") { common_vendor.index.showToast({ title: `重复提交`, icon: "error" }); return; } if (res.data.result == "未做变更") { common_vendor.index.showToast({ title: `当前无变更,无需提交`, icon: "none" }); return; } if (res.data.code != 200) { common_vendor.index.showToast({ title: res.data.message, icon: "none", // 'success' 成功图标,'none' 无图标 duration: 2e3 // 显示时长 ms }); return; } else { common_vendor.index.reLaunch({ url: "/pages/oldmanindex/oldmansuccess?type=1&jianhu=1" }); } }, fail: (e) => { } }); } } }; const goBack = () => { common_vendor.index.navigateBack(); }; const specialImgeshow = common_vendor.ref(""); common_vendor.onLoad(() => { if (common_vendor.index.getStorageSync("allinfo").name) { let data = common_vendor.index.getStorageSync("allinfo"); const keys = [ "openId", "name", "tel", "advisoryType", "status", "idCard", "homeAddress", "workUnit", "izJs", "relationship" ]; keys.forEach((key) => { form[key] = data[key] || ""; }); specialImge.value = data.guardianIdCardPositive; specialImgeshow.value = request_index.media_base_url + data.guardianIdCardPositive; common_vendor.index.__f__("log", "at pages/addoldman/IDcard.vue:406", "????", common_vendor.index.getStorageSync("allinfo")); } }); function uploadImage(filePath) { uping.value = false; common_vendor.index.showLoading(); common_vendor.index.uploadFile({ url: `${request_index.base_url}/api/ocr/idCard`, // 替换为您的POST接口地址 filePath, name: "file", // 后端接收时的字段名 header: { "X-Access-Token": common_vendor.index.getStorageSync("token") || "" }, formData: {}, success: (uploadRes) => { if (!JSON.parse(uploadRes.data).success) { common_vendor.index.hideLoading(); common_vendor.index.showToast({ title: "识别失败", icon: "error", duration: 2e3 }); uping.value = true; return; } if (JSON.parse(JSON.parse(uploadRes.data).result.data).data.face) { let father = JSON.parse(JSON.parse(uploadRes.data).result.data).data.face.data; specialImgeshow.value = filePath; form.name = father.name; form.idCard = father.idNumber; form.homeAddress = father.address; savephoto(filePath); } }, fail: (err) => { common_vendor.index.showToast({ title: "上传出错", icon: "error" }); common_vendor.index.hideLoading(); } }); } const savephoto = (filePath, type) => { common_vendor.index.uploadFile({ url: `${request_index.base_url}/sys/common/upload`, // 替换为您的POST接口地址 filePath, name: "file", // 后端接收时的字段名 header: { "X-Access-Token": common_vendor.index.getStorageSync("token") || "" }, formData: { biz: `temp` }, success: (uploadRes) => { specialImge.value = JSON.parse(uploadRes.data).message; common_vendor.index.hideLoading(); uping.value = true; }, fail: (err) => { common_vendor.index.showToast({ title: "上传出错", icon: "error" }); common_vendor.index.hideLoading(); } }); }; common_vendor.onShow(() => { const img = common_vendor.index.getStorageSync("imgkey0"); if (img) { uploadImage(img); common_vendor.index.removeStorageSync("imgkey0"); } }); return (_ctx, _cache) => { return common_vendor.e({ a: common_vendor.o(goBack), b: `${common_vendor.index.getStorageSync("moveHeight") + 40}px`, c: `${common_vendor.index.getStorageSync("moveHeight") + 40}px`, d: specialImge.value ? `${common_vendor.unref(request_index.media_base_url)}${specialImge.value}` : `https://www.focusnu.com/media/directive/index/IDfront.png`, e: specialImge.value ? `` : `https://www.focusnu.com/media/directive/index/bian.png`, f: !specialImge.value }, !specialImge.value ? {} : {}, { g: common_vendor.o(($event) => selectphoto()), h: form.name, i: common_vendor.o(($event) => form.name = $event.detail.value), j: form.tel, k: common_vendor.o(($event) => form.tel = $event.detail.value), l: form.idCard, m: common_vendor.o(($event) => form.idCard = $event.detail.value), n: form.homeAddress, o: common_vendor.o(($event) => form.homeAddress = $event.detail.value), p: form.workUnit, q: common_vendor.o(($event) => form.workUnit = $event.detail.value), r: common_vendor.o(next), s: common_vendor.o(photoclick), t: common_vendor.o(($event) => bottomshow.value = $event), v: common_vendor.p({ list: bottomlist, modelValue: bottomshow.value }) }); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-5fcb8e22"]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/addoldman/IDcard.js.map