hldy_xcx/unpackage/dist/dev/mp-weixin/pages/addoldman/oldIDcard.js

580 lines
21 KiB
JavaScript
Raw Normal View History

2025-09-19 17:12:59 +08:00
"use strict";
const common_vendor = require("../../common/vendor.js");
const request_index = require("../../request/index.js");
const compontent_public_long = require("../../compontent/public/long.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) {
(model + _easycom_u_action_sheet)();
}
const model = () => "../../compontent/public/model.js";
const _sfc_main = {
__name: "oldIDcard",
setup(__props) {
const show = common_vendor.ref(false);
const content = common_vendor.ref("");
const bottomshow = common_vendor.ref(false);
const bottomlist = [{
text: "拍摄图片",
fontSize: 40
}, {
text: "图片预览",
fontSize: 40
}];
const nameArray = ["姓名", "性别", "身份证号码", "民族", "出生日期", "住址", "签发机关", "有效期限"];
const textArray = common_vendor.reactive(["", "", "", "", "", "", "", ""]);
2025-09-23 17:15:17 +08:00
common_vendor.reactive(["", "", "", "", ""]);
2025-09-19 17:12:59 +08:00
const guanxi = common_vendor.ref("");
2025-09-23 17:15:17 +08:00
const form = common_vendor.reactive({
name: "",
idCard: "",
tel: "",
homeAddress: "",
workUnit: ""
});
2025-09-19 17:12:59 +08:00
const fontphoto = common_vendor.ref("");
const endphoto = common_vendor.ref("");
common_vendor.ref(0);
const photoclick = (element) => {
if (element) {
common_vendor.index.previewImage({
2025-10-29 17:28:17 +08:00
urls: [headImge.value, backImge.value, specialImgeshow.value],
2025-09-19 17:12:59 +08:00
// 必填,所有要预览的图片地址数组
2025-10-29 17:28:17 +08:00
current: targetphoto.value ? targetphoto.value == 1 ? backImge.value : specialImgeshow.value : headImge.value,
2025-09-19 17:12:59 +08:00
// 可选,当前显示图片的地址,默认是 urls[0]
indicator: "default",
// 可选指示器样式H5/App 有效,值为 'default'(圆点)或 'number'(数字)
longPressActions: {
// 可选,仅 App 支持,长按图片时弹出的操作项
itemList: ["保存图片到相册"]
}
});
} else {
getMessage();
}
};
const tempImagePath = common_vendor.ref("");
const targetphoto = common_vendor.ref(0);
2025-10-29 17:28:17 +08:00
const isspecial = common_vendor.ref(false);
2025-09-19 17:12:59 +08:00
const selectphoto = (number) => {
if (!uping.value) {
return;
}
2025-10-29 17:28:17 +08:00
targetphoto.value = number;
if (!number) {
if (headImge.value) {
bottomshow.value = true;
} else {
getMessage();
}
} else if (number == 1) {
if (backImge.value) {
bottomshow.value = true;
} else {
getMessage();
}
} else if (number == 2) {
if (specialImge.value) {
bottomshow.value = true;
} else {
isspecial.value = true;
getMessage();
}
2025-09-19 17:12:59 +08:00
}
};
function getMessage() {
common_vendor.index.chooseImage({
count: 1,
sourceType: ["album", "camera"],
success: (chooseRes) => {
tempImagePath.value = chooseRes.tempFilePaths[0];
common_vendor.index.navigateTo({
url: `/compontent/public/camera?url=${chooseRes.tempFilePaths[0]}&type=0`
});
},
fail: (err) => {
2025-11-25 11:25:32 +08:00
common_vendor.index.__f__("error", "at pages/addoldman/oldIDcard.vue:279", "拍照失败:", err);
2025-09-19 17:12:59 +08:00
}
});
}
2025-10-29 17:28:17 +08:00
const specialImge = common_vendor.ref("");
const specialImgeshow = common_vendor.ref("");
2025-09-19 17:12:59 +08:00
const headImge = common_vendor.ref("");
const backImge = common_vendor.ref("");
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;
}
2025-10-29 17:28:17 +08:00
if (isspecial.value || targetphoto.value == 2) {
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, 2);
}
isspecial.value = false;
2025-09-19 17:12:59 +08:00
} else {
2025-10-29 17:28:17 +08:00
if (JSON.parse(JSON.parse(uploadRes.data).result.data).data.face) {
let father = JSON.parse(JSON.parse(uploadRes.data).result.data).data.face.data;
textArray[0] = father.name;
textArray[1] = father.sex;
textArray[2] = father.idNumber;
textArray[3] = father.ethnicity;
textArray[4] = father.birthDate;
textArray[5] = father.address;
headImge.value = filePath;
savephoto(filePath, 0);
} else if (JSON.parse(JSON.parse(uploadRes.data).result.data).data.back) {
let father = JSON.parse(JSON.parse(uploadRes.data).result.data).data.back.data;
textArray[6] = father.issueAuthority;
textArray[7] = father.validPeriod;
backImge.value = filePath;
savephoto(filePath, 1);
} else {
common_vendor.index.hideLoading();
common_vendor.index.showToast({
title: "识别失败",
icon: "error",
duration: 2e3
});
uping.value = true;
}
2025-09-19 17:12:59 +08:00
}
},
fail: (err) => {
common_vendor.index.showToast({
title: "上传出错",
icon: "error"
});
common_vendor.index.hideLoading();
}
});
}
const uping = common_vendor.ref(true);
const savephoto = (filePath, type) => {
2025-11-25 11:25:32 +08:00
const now = /* @__PURE__ */ new Date();
const yyyy = now.getFullYear();
const mm = String(now.getMonth() + 1).padStart(2, "0");
let path = "";
switch ("zz") {
case "jg":
path = `${yyyy}/${mm}/jgxx/jg`;
break;
case "yg":
path = `${yyyy}/${mm}/ygxx/yg`;
break;
case "zz":
path = `${yyyy}/${mm}/zzxx/zz`;
break;
case "jhr":
path = `${yyyy}/${mm}/zzxx/jhr`;
break;
default:
path = `${yyyy}/${mm}/temp`;
}
2025-09-19 17:12:59 +08:00
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: {
2025-11-25 11:25:32 +08:00
biz: path
2025-09-19 17:12:59 +08:00
},
success: (uploadRes) => {
if (!type) {
fontphoto.value = JSON.parse(uploadRes.data).message;
2025-10-29 17:28:17 +08:00
} else if (type == 1) {
2025-09-19 17:12:59 +08:00
endphoto.value = JSON.parse(uploadRes.data).message;
2025-10-29 17:28:17 +08:00
} else if (type == 2) {
specialImge.value = JSON.parse(uploadRes.data).message;
2025-09-19 17:12:59 +08:00
}
common_vendor.index.hideLoading();
if (JSON.parse(uploadRes.data).code == 401) {
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: {
2025-11-25 11:25:32 +08:00
biz: path
2025-09-19 17:12:59 +08:00
},
success: (uploadRes2) => {
if (!type) {
fontphoto.value = JSON.parse(uploadRes2.data).message;
2025-10-29 17:28:17 +08:00
} else if (type == 1) {
2025-09-19 17:12:59 +08:00
endphoto.value = JSON.parse(uploadRes2.data).message;
2025-10-29 17:28:17 +08:00
} else if (type == 2) {
specialImge.value = JSON.parse(uploadRes2.data).message;
2025-09-19 17:12:59 +08:00
}
uping.value = true;
},
fail: (err) => {
common_vendor.index.showToast({
title: "上传出错",
icon: "error"
});
common_vendor.index.hideLoading();
}
});
}
uping.value = true;
},
fail: (err) => {
common_vendor.index.showToast({
title: "上传出错",
icon: "error"
});
common_vendor.index.hideLoading();
}
});
};
function isAtLeastEightChars(str) {
return typeof str === "string" && str.length >= 12;
}
const openLook = (res) => {
if (isAtLeastEightChars(res)) {
content.value = res;
show.value = true;
}
};
2025-09-23 17:15:17 +08:00
function isValid11DigitNumber(val) {
2025-10-29 17:28:17 +08:00
return /^1[3-9]\d{9}$/.test(val);
2025-09-23 17:15:17 +08:00
}
function isValid18DigitNumber(val) {
return /^(\d{18})$/.test(val);
}
const ukey = common_vendor.ref(
`${common_vendor.index.getStorageSync("openid") || ""}lrbg${String(Date.now()).slice(-5)}${String(Math.floor(Math.random() * 900) + 100)}`
);
2025-09-19 17:12:59 +08:00
const next = () => {
2025-10-29 17:28:17 +08:00
if (!specialImge.value) {
common_vendor.index.showToast({
title: "请上传监护人身份证正面",
icon: "none"
});
return;
}
2025-09-19 17:12:59 +08:00
if (!fontphoto.value) {
common_vendor.index.showToast({
title: "请上传身份证正面",
icon: "none"
});
return;
} else if (!endphoto.value) {
common_vendor.index.showToast({
title: "请上传身份证背面",
icon: "none"
});
return;
2025-09-28 10:58:31 +08:00
}
if (canshow.value) {
2025-10-29 17:28:17 +08:00
if (!form.name) {
2025-09-28 10:58:31 +08:00
common_vendor.index.showToast({
title: "请填写监护人姓名",
icon: "none"
});
return;
} else if (!form.tel) {
common_vendor.index.showToast({
title: "请填写监护人电话",
icon: "none"
});
return;
} else if (!isValid11DigitNumber(form.tel)) {
common_vendor.index.showToast({
title: "监护人电话格式错误",
icon: "none"
});
return;
} else if (!form.idCard) {
common_vendor.index.showToast({
title: "请填写身份证号",
icon: "none"
});
return;
} else if (!isValid18DigitNumber(form.idCard)) {
common_vendor.index.showToast({
title: "身份证号格式错误",
icon: "none"
});
return;
} else if (!form.homeAddress) {
common_vendor.index.showToast({
title: "请填写家庭住址",
icon: "none"
});
return;
} else if (!form.workUnit) {
common_vendor.index.showToast({
title: "请填写工作单位",
icon: "none"
});
return;
}
2025-09-19 17:12:59 +08:00
}
const allNonEmpty = textArray.every((item) => {
return item !== "";
});
if (!uping.value) {
return;
}
if (allNonEmpty) {
const range = textArray[7];
const [start, end] = range.split("-");
let data = {};
data.openId = common_vendor.index.getStorageSync("openid");
data.nuId = common_vendor.index.getStorageSync("oldman").nuId;
data.idCardPositive = fontphoto.value;
data.idCardNegative = endphoto.value;
2025-10-29 17:28:17 +08:00
data.guardianIdCardPositive = specialImge.value;
2025-09-19 17:12:59 +08:00
data.name = textArray[0];
data.sex = textArray[1];
data.idCard = textArray[2];
data.national = textArray[3];
data.dateOfBirth = textArray[4];
data.houseAddress = textArray[5];
data.issuingAuthority = textArray[6];
data.startTime = start;
2025-10-15 15:56:44 +08:00
data.endTime = end;
2025-10-14 15:46:44 +08:00
if (data.endTime == "长期") {
data.endTime = compontent_public_long.swapLongTerm(end);
}
2025-09-19 17:12:59 +08:00
data.sysOrgCode = common_vendor.index.getStorageSync("oldman").orgCode;
2025-09-23 17:15:17 +08:00
let res = form;
2025-09-19 17:12:59 +08:00
data.guardianName = res.name;
data.relationship = guanxi.value;
data.guardianIdCard = res.idCard;
data.guardianPhone = res.tel;
data.guardianHomeAddress = res.homeAddress;
data.guardianWorkUnit = res.workUnit;
data.guardianOpenId = common_vendor.index.getStorageSync("openid");
2025-09-23 17:15:17 +08:00
data.guardianId = common_vendor.index.getStorageSync("allinfo").id;
2025-09-26 16:46:17 +08:00
data.modifyType = "zz";
2025-09-19 17:12:59 +08:00
if (id.value) {
data.id = id.value;
const urlpost = `${payurl.value}/api/elderInfo/updateElderInfo?ukey=${ukey.value}`;
2025-09-19 17:12:59 +08:00
common_vendor.index.request({
url: urlpost,
method: "POST",
header: {
"Content-Type": "application/json",
"X-Access-Token": common_vendor.index.getStorageSync("token") || ""
},
data,
success: (res2) => {
if (res2.data.result == "重复提交") {
common_vendor.index.showToast({
title: `重复提交`,
icon: "error"
});
return;
}
if (res2.data.result == "未做变更") {
common_vendor.index.showToast({
2025-10-17 10:51:10 +08:00
title: `当前无变更,无需提交`,
2025-10-17 13:18:01 +08:00
icon: "none"
});
return;
}
2025-09-19 17:12:59 +08:00
common_vendor.index.reLaunch({
url: "/pages/oldmanindex/oldmansuccess?type=1"
});
},
fail: (e) => {
2025-11-25 11:25:32 +08:00
common_vendor.index.__f__("log", "at pages/addoldman/oldIDcard.vue:653", "????", e);
2025-09-19 17:12:59 +08:00
}
});
} else {
const urlpost = `${payurl.value}/api/elderInfo/addElder?ukey=${ukey.value}`;
2025-09-19 17:12:59 +08:00
common_vendor.index.request({
url: urlpost,
method: "POST",
header: {
"Content-Type": "application/json",
"X-Access-Token": common_vendor.index.getStorageSync("token") || ""
},
data,
success: (r) => {
if (r.data.result == "重复提交") {
return;
}
2025-09-23 17:15:17 +08:00
if (r.data.code != 200) {
common_vendor.index.showToast({
title: r.data.message,
icon: "none",
// 'success' 成功图标,'none' 无图标
duration: 2e3
// 显示时长 ms
});
return;
}
2025-09-19 17:12:59 +08:00
const connectinon = {
nuId: data.nuId,
openId: common_vendor.index.getStorageSync("openid"),
elderId: r.data.result,
sysOrgCode: data.sysOrgCode
};
const urlpost2 = `${payurl.value}/api/nuBaseInfo/bindNu`;
common_vendor.index.request({
url: urlpost2,
method: "POST",
header: {
"Content-Type": "application/json",
"X-Access-Token": common_vendor.index.getStorageSync("token") || ""
},
data: connectinon,
success: (r2) => {
common_vendor.index.reLaunch({
url: "/pages/oldmanindex/oldmansuccess"
});
},
fail: (e) => {
}
});
},
fail: (e) => {
}
});
}
} else {
common_vendor.index.showToast({
title: "请上传清晰的身份证",
icon: "error"
});
}
};
const goBack = () => {
if (!uping.value) {
return;
}
common_vendor.index.navigateBack();
};
const payurl = common_vendor.ref("");
const id = common_vendor.ref("");
2025-09-25 17:30:11 +08:00
const canshow = common_vendor.ref(true);
2025-09-19 17:12:59 +08:00
common_vendor.onLoad(() => {
payurl.value = request_index.base_url;
2025-09-23 17:15:17 +08:00
common_vendor.index.getStorageSync("allinfo");
2025-09-19 17:12:59 +08:00
if (common_vendor.index.getStorageSync("specicalid")) {
let data = common_vendor.index.getStorageSync("baddata");
2025-09-25 17:30:11 +08:00
canshow.value = false;
2025-09-19 17:12:59 +08:00
fontphoto.value = data.idCardPositive;
endphoto.value = data.idCardNegative;
2025-10-29 17:28:17 +08:00
specialImge.value = data.guardianIdCardPositive;
2025-09-19 17:12:59 +08:00
textArray[0] = data.name;
textArray[1] = data.sex;
textArray[2] = data.idCard;
textArray[3] = data.national;
2025-09-29 10:40:43 +08:00
textArray[4] = data.dateOfBirth;
2025-09-19 17:12:59 +08:00
textArray[5] = data.houseAddress;
textArray[6] = data.issuingAuthority;
guanxi.value = data.relationship;
data.startTime = data.startTime;
data.endTime = data.endTime;
id.value = data.id;
textArray[7] = `${data.startTime}-${compontent_public_long.swapLongTerm(data.endTime)}`;
2025-10-29 17:28:17 +08:00
} else {
form.tel = common_vendor.index.getStorageSync("tel");
2025-09-19 17:12:59 +08:00
}
});
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(($event) => show.value = false),
b: common_vendor.p({
show: show.value,
content: content.value
}),
c: common_vendor.o(goBack),
2025-10-20 09:29:15 +08:00
d: `${common_vendor.index.getStorageSync("moveHeight") + 40}px`,
2025-10-13 14:58:45 +08:00
e: `${common_vendor.index.getStorageSync("moveHeight") + 30}px`,
f: canshow.value
2025-10-29 17:28:17 +08:00
}, canshow.value ? common_vendor.e({
g: specialImge.value ? `${common_vendor.unref(request_index.media_base_url)}${specialImge.value}` : `https://www.focusnu.com/media/directive/index/IDfront.png`,
h: specialImge.value ? `` : `https://www.focusnu.com/media/directive/index/bian.png`,
i: !specialImge.value
}, !specialImge.value ? {} : {}, {
j: common_vendor.o(($event) => selectphoto(2)),
k: form.name,
l: common_vendor.o(($event) => form.name = $event.detail.value),
m: form.tel,
n: common_vendor.o(($event) => form.tel = $event.detail.value),
o: form.idCard,
p: common_vendor.o(($event) => form.idCard = $event.detail.value),
q: form.homeAddress,
r: common_vendor.o(($event) => form.homeAddress = $event.detail.value),
s: form.workUnit,
t: common_vendor.o(($event) => form.workUnit = $event.detail.value)
}) : {}, {
v: fontphoto.value ? `${common_vendor.unref(request_index.media_base_url)}${fontphoto.value}` : `https://www.focusnu.com/media/directive/index/IDfront.png`,
w: fontphoto.value ? `` : `https://www.focusnu.com/media/directive/index/bian.png`,
x: !fontphoto.value
2025-09-19 17:12:59 +08:00
}, !fontphoto.value ? {} : {}, {
2025-10-29 17:28:17 +08:00
y: common_vendor.o(($event) => selectphoto(0)),
z: endphoto.value ? `${common_vendor.unref(request_index.media_base_url)}${endphoto.value}` : `https://www.focusnu.com/media/directive/index/IDend.png`,
A: endphoto.value ? `` : `https://www.focusnu.com/media/directive/index/bian.png`,
B: !endphoto.value
2025-09-19 17:12:59 +08:00
}, !endphoto.value ? {} : {}, {
2025-10-29 17:28:17 +08:00
C: common_vendor.o(($event) => selectphoto(1)),
D: common_vendor.f(nameArray, (item, index, i0) => {
2025-09-19 17:12:59 +08:00
return {
a: common_vendor.t(item),
b: common_vendor.t(textArray[index] ? textArray[index] : "自动获取"),
c: index,
d: common_vendor.o(($event) => openLook(textArray[index]), index)
};
}),
2025-10-29 17:28:17 +08:00
E: common_vendor.o(next),
F: common_vendor.o(photoclick),
G: common_vendor.o(($event) => bottomshow.value = $event),
H: common_vendor.p({
2025-09-19 17:12:59 +08:00
list: bottomlist,
modelValue: bottomshow.value
})
});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-70d4a10f"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/addoldman/oldIDcard.js.map