import { reactive, ref } from "vue"; import { request, requestNew } from "@/utils/network/request"; import { Index, handleDataList } from "@/components/form-builder/tools"; import { etcOcrCard, ocrAllQuery, fileUpload } from "@/utils/network/api.js"; import { useQdOrderStore } from "@/stores/qdOrder.js"; // 配合formBuilderVue3模板使用 export default function () { let submitQuery = ref({}); let registerQuery = reactive({}); const qdOrderStore = useQdOrderStore(); // 社会信用代码ocr识别 function cardImageOcrYY(fileList, item, formData) { submitQuery.value.userIdType = "203"; //203 公司信用代码 // 将图片上传 //识别营业执照 // return const data = { type:'5', // imagePath: fileList.url.split('default-bucket/')[1], imagePath: fileList.url, }; uni.showLoading({ title: '正在识别图片...', mask: true }); requestNew('/iaw/api/ocr/do', { data: data }).then(res => { if (res.code !== 0) return let data : any = res.data; let ocrData = [ { title: "公司名称", key: "unitName" }, { title: "社会信用代码", key: "screditCode" }, { title: "住址", key: "adress" } ]; // const itemData = formData.value[Index(item.title, formData.value)] // itemData[itemData.value] = fileList.pathDomain // 保存营业执照图片地址到submitQuery // submitQuery.value.userIdPoImageUrl = fileList.pathDomain.split('default-bucket/')[1]; submitQuery.value.userIdPoImageUrl = fileList.url; // 处理数据展示 handleDataList(ocrData, data, formData); }).finally(()=>{ uni.hideLoading(); }); } // 委托书 function cardFileImageUpdate(fileList, item, formData) { console.log(fileList, item, formData,'fileList, item, formData'); const dataItem = formData.value[Index(item.title, formData.value)]; dataItem[dataItem.value] = fileList.url; // submitQuery.value.proxyUrl = fileList.pathDomain.split('default-bucket/')[1]; // dataItem[dataItem.value] = fileList.pathDomain; } // 身份证类别识别 function idCardOcr(fileList, item, formData) { console.log(fileList, item, formData,'fileList, item, formData'); let imageType; if (item.title == "人像面" || item.title == "经办人证件人像面") { imageType = "1"; } else if (item.title == "国徽面" || item.title == "经办人证件国徽面") { imageType = "2"; } const data = { // source: "1", type:imageType, // imagePath: fileList.url.split('default-bucket/')[1], imagePath: fileList.url, }; uni.showLoading({ title: '正在识别图片...', mask: true }); requestNew('/iaw/api/ocr/do', { data: data }).then(res => { console.log('OCR接口返回:', res); // 添加接口返回日志 if (res.code !== 0) { console.log('OCR接口返回错误码:', res.code); // 添加错误码日志 return; } let data : any = res.data; console.log('OCR识别数据:', data); // 添加识别数据日志 let ocrData = []; const itemData = formData.value[Index(item.title, formData.value)] // itemData[itemData.value] = fileList.pathDomain.split('default-bucket/')[1] itemData[itemData.value] = fileList.url if (imageType == "1") { // 人像面 if (!data.name || !data.idno) { console.log('缺少必要的身份信息:', {name: data.name, idno: data.idno}); // 添加数据缺失日志 uni.showModal({ title: "提示", content: "很抱歉,我们无法识别您的证件,请按规范上传正反面,确保图片清晰、背景简洁(如白墙或桌面),减少证件反光和阴影", success: function (res) { } }); return; } if (item.title == "经办人证件人像面") { ocrData = ocrData.concat([ { title: "经办人姓名", key: "name" }, { title: "经办人证件号码", key: "idno" } ]); submitQuery.value.agentIdType = 101; //身份证类型 submitQuery.value.agentAddress = data.address; //经办人住址 } else { console.log('设置个人信息数据'); // 添加个人信息设置日志 ocrData = ocrData.concat([ { title: "姓名", key: "name" }, { title: "证件号码", key: "idno" }, { title: "住址", key: "address" } ]); console.log('准备处理数据展示,ocrData:', ocrData); // 添加数据处理前日志 submitQuery.value.userIdType = 101; //身份证 registerQuery.gender = data.gender == '男' ? 'MALE' : 'FEMALE' //用户性别 } console.log('准备处理数据展示,ocrData:', ocrData); // 添加数据处理前日志 // 处理数据展示 handleDataList(ocrData, data, formData); console.log('数据处理完成'); // 添加数据处理完成日志 } else { if (!data.enddate) { console.log('缺少有效期信息'); // 添加有效期缺失日志 uni.showModal({ title: "提示", content: "很抱歉,我们无法识别您的证件,请按规范上传正反面,确保图片清晰、背景简洁(如白墙或桌面),减少证件反光和阴影", success: function (res) { } }); return; } if (item.title == "经办人证件国徽面") { submitQuery.value.agentIdVld = data.enddate; //经办人证件有效期 } else { submitQuery.value.customerIdVld = data.enddate; //证件有效期 } } }).catch(error => { console.error('OCR接口调用失败:', error); // 添加错误捕获日志 }).finally(()=>{ uni.hideLoading(); }); } //图像文件上传 function uploadImgHandle(fileList, item, formData) { if ( ["人像面", "国徽面", "经办人证件人像面", "经办人证件国徽面"].includes( item.title ) ) { idCardOcr(fileList, item, formData); } else if (item.title == "营业执照") { console.log("dsdsad",formData) cardImageOcrYY(fileList, item, formData); } else { cardFileImageUpdate(fileList, item, formData); } } return { uploadImgHandle, submitQuery }; }