import { reactive } from "vue"; import { requestNew } from "@/utils/network/request"; import { Index, handleDataList } from "@/components/form-builder/tools"; import { etcCarOcrCard, fileUpload } from "@/utils/network/api.js"; import { useQdOrderStore } from "@/stores/qdOrder.js"; // 配合formBuilderVue3模板使用 export default function () { const ocrDataFu = [ { title: "准牵引总质量(kg)", key: "towing", isNumbers: true, sendKey: "permittedTowWeight" }, { title: "核定载人数", key: "apc", isNumbers: true, sendKey: "approvedCount" }, { title: "核定载质量(kg)", isNumbers: true, key: "alc", sendKey: "permittedWeight" }, { title: "总质量(kg)", isNumbers: true, key: "gross", sendKey: "totalMass" }, { title: "整备质量(kg)", isNumbers: true, key: "unladen", sendKey: "maintenaceMass" }, { title: "外廓尺寸", key: "overall", // substring: 2, //截取最后两位 sendKey: "vehicleDimensions" } ]; let submitQuery = reactive({ orderId: "", //订单ID man: "", //所有人 character: "", //使用性质 register: "", //注册日期 customerId: "", //用户编号 vehicleId: "", vehicleIdNum: "", //车牌编号 issueDate: "", //发证日期 vehPosImgUrl: "", //行驶证正面 vehNegImgUrl: "", //行驶证证反面 type: "0", //0,客车 1.货车 useUserType: 0, //车辆用户类型 useUserTypeName: "普通车", vehicleSign: 2, //前/后装标识 vin: "", //车辆识别代号 engineNum: "", //发动机号码 vehicleType: "", //车辆类型 vehicleModel: "", //行驶证品牌型号 approvedCount: "", //核定人数 totalMass: "", //总质量 maintenaceMass: "", //整备质量 permittedWeight: "", //核定载质量 vehicleDimensions: "", //车辆尺寸 permittedTowWeight: "", //准牵引总质量 axleCount: "", //车轴数 ownerName: "", //车主姓名 ownerIdType: "", //车主证件类型 ownerIdNum: "", //车主证件号码 ownPosImgUrl: "", //车主证件正面图片 ownNegImgUrl: "", //车主证件反面图片 agreementId: "", //签约编号 channelId: "5201018892300000001", //编号渠道 scenePayType: "", // transportIdNum: "", //道路运输证编号 licenseIdNum: "", //经营许可证编号 vehBodyUrl: "",//车身照片 proxyUrl: "", agentIdType: "", userIdType: "", // 企业相关字段 companyName: "", // 公司名称 socialCreditCode: "", // 社会信用代码 companyAddress: "", // 公司地址 businessLicenseUrl: "", // 营业执照图片URL }); const qdOrderStore = useQdOrderStore(); let registerQuery = reactive({}); let ocrDatas = {}; let vehicChargeVal = {}; let ocrFu = false;//标志副业是否ocr识别过 let ocrZm = false;//标志主页是否ocr识别过 // 行驶证主业或副业处理 const cardImageOcr = (fileList, item, formData) => { let imageType: string; if (item.title == "行驶证主页") { imageType = "3"; } else if (item.title == "行驶证副页") { imageType = "4"; } const params = { type: imageType, // imagePath: fileList.url.split('default-bucket/')[1], imagePath: fileList.url, }; requestNew("/iaw/api/ocr/do", { data: params }).then(async res => { if (res.code !== 0) return; let data: any = res.data; const itemData = formData.value[Index(item.title, formData.value)]; // itemData[itemData.value] = fileList.pathDomain.split('default-bucket/')[1]; itemData[itemData.value] = fileList.url; if (data.man != null) { submitQuery.man = data.man } if (imageType === "3") { const ocrData = [ { title: "车牌号", key: "plate_a" }, { title: "车辆类型", key: "vehicle" }, { title: "使用性质", key: "character" }, { title: "发动机号码", key: "engine" }, { title: "品牌型号", key: "model" }, { title: "车辆识别代码", key: "vin" }, { title: "所有人", key: "man" }, { title: "发证日期", key: "issue" }, { title: "注册日期", key: "register" } ]; // 处理数据展示 handleDataList(ocrData, data, formData); ocrZm = true; if(ocrFu){ handleVehicUsePropert(formData); } ocrDatas = data; } else { handleDataList(ocrDataFu, data, formData); ocrFu = true;//声明副业ocr已经识别 // 在处理完副页OCR数据后调用handleVehicCharge // handleVehicCharge(formData); if(ocrZm){ handleVehicUsePropert(formData); } const permittedWeight = formData.value[Index("核定载质量(kg)", formData.value)]; console.log(permittedWeight[permittedWeight.value], "permittedWeight"); const permittedTowWeight = formData.value[Index("准牵引总质量(kg)", formData.value)]; console.log(permittedTowWeight[permittedTowWeight.value], "permittedTowWeight"); // 如果核定载质量为undefined,则设置show为true if (permittedWeight && permittedWeight[permittedWeight.value]) { permittedWeight.show = false; }else{ permittedWeight.show = true; } if (permittedTowWeight && permittedTowWeight[permittedTowWeight.value]) { permittedTowWeight.show = false; }else{ permittedTowWeight.show = true; } } }); }; // 收费车型 const handleVehicCharge = formData => { console.log(formData.value, "收费车型formData"); console.log(qdOrderStore.qdOrderVal, "qdOrderStore.qdOrderVal"); const axleCountVal = formData.value[Index("车轴数", formData.value)]; const approvedCount = formData.value[Index("核定载人数", formData.value)]; const totalMass = formData.value[Index("总质量(kg)", formData.value)]; const vehicleDimensions = formData.value[Index("外廓尺寸", formData.value)]; console.log(axleCountVal, "axleCountVal"); if ( !axleCountVal[axleCountVal.value] ) { return; }else{ let data = { approvedCount: approvedCount[approvedCount.value], axleCount: Number(axleCountVal[axleCountVal.value]), totalMass: totalMass[totalMass.value], vanType: qdOrderStore.qdOrderVal.vanType, vehicleDimensions: vehicleDimensions[vehicleDimensions.value] } let options = { data: data, method: "POST", showLoading: true }; return requestNew("/iaw/h5/order/web/vehicCharge", options).then(res => { console.log(res, "res vehicCharge"); if (res.code !== 0) return; const itemData = formData.value[Index("收费车型", formData.value)]; console.log(itemData, "itemData"); console.log("feeVehicleType value:", res.data.feeVehicleType, "type:", typeof res.data.feeVehicleType); // 直接设置值,不需要设置 itemData.itemData const feeVehicleType = Number(res.data.feeVehicleType); itemData.feeVehicleType = feeVehicleType; // 直接设置到对象属性上 submitQuery.feeVehicleType = feeVehicleType; vehicChargeVal = res.data.feeVehicleTypeStr; console.log("After set itemData:", itemData); handleVehicUsePropert(formData); }); } }; // 车辆使用性质 const handleVehicUsePropert = formData => { console.log(formData,'使用性质formData') console.log(vehicChargeVal,vehicChargeVal,'vehicChargeVal') const vehicleType = formData.value[Index("车辆类型", formData.value)]; const useCharacter = formData.value[Index("使用性质", formData.value)]; const approvedCount = formData.value[Index("核定载人数", formData.value)]; const totalMass = formData.value[Index("总质量(kg)", formData.value)]; const vehicleDimensions = formData.value[Index("外廓尺寸", formData.value)]; const permittedWeight = formData.value[Index("核定载质量(kg)", formData.value)]; const permittedTowWeight = formData.value[Index("准牵引总质量(kg)", formData.value)]; const axleCount = formData.value[Index("车轴数", formData.value)]; const vanType = formData.value[Index("收费车型", formData.value)]; const plateNum = formData.value[Index("车牌号", formData.value)]; console.log(ocrDatas,'ocrDatas') // if (!vehicChargeVal || !ocrDatas.character) { // console.log('没有收费车型或使用性质') // return; // } // itemData[itemData.value] = data.imageUrl let data = { approvedCount: approvedCount[approvedCount.value], axleCount: axleCount[axleCount.value], plateNum: plateNum[plateNum.value], totalMass: totalMass[totalMass.value], vanType: qdOrderStore.qdOrderVal.vanType, vehicleDimensions: vehicleDimensions[vehicleDimensions.value], // permittedWeight: permittedWeight[permittedWeight.value], // permittedTowWeight: permittedTowWeight[permittedTowWeight.value], // feeVehicleTypeStr: vehicChargeVal, vehicleTypeName: vehicleType[vehicleType.value], vehicleUsePropertName: useCharacter[useCharacter.value] }; let options = { data: data, method: "POST", showLoading: true }; console.log(options, "options"); return requestNew("/iaw/h5/order/web/vehicUsePropert", options) .then(res => { console.log(res, "res"); if (res.code !== 0) return; const itemData = formData.value[Index("使用性质", formData.value)]; itemData[itemData.value] = res.data.vehicUse || ""; const itemData1 = formData.value[Index("收费车型", formData.value)]; const feeVehicleType = Number(res.data.feeVehicleType); itemData1.feeVehicleType = feeVehicleType; // 直接设置到对象属性上 submitQuery.feeVehicleType = feeVehicleType; vehicChargeVal = res.data.feeVehicleTypeStr; }) .finally(() => { }); }; // 身份证类别识别 function idCardOcr(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 => { if (res.code !== 0) return let data: any = res.data; console.log(res.data, 'res.datares.datares.datares.data'); let ocrData = [ ]; const itemData = formData.value[Index(item.title, formData.value)] // itemData[itemData.value] = fileList.pathDomain itemData[itemData.value] = fileList.url console.log(data, 'dataocr'); if (data.idno != null) { submitQuery.idno = data.idno } if (data.name != null) { submitQuery.idName = data.name submitQuery.ownerPosImgUrl = data.imageUrl } else { submitQuery.ownerNegImgUrl = data.imageUrl } if (data.address != null) { submitQuery.ownerIdAddress = data.address } if (data.mobile != null) { submitQuery.ownerTel = data.mobile } if (imageType == "1") { // 人像面 if (!data.name || !data.idno) { uni.showModal({ title: "提示", content: "很抱歉,我们无法识别您的证件,请按规范上传正反面,确保图片清晰、背景简洁(如白墙或桌面),减少证件反光和阴影", success: function (res) { } }); return; } ocrData = ocrData.concat([ { title: "姓名", key: "name" }, { title: "证件号码", key: "idno" }, { title: "住址", key: "address" } ]); submitQuery.userIdType = 101; //身份证 registerQuery.gender = data.gender == '男' ? 'MALE' : 'FEMALE' //用户性别 } else { if (!data.enddate) { uni.showModal({ title: "提示", content: "很抱歉,我们无法识别您的证件,请按规范上传正反面,确保图片清晰、背景简洁(如白墙或桌面),减少证件反光和阴影", success: function (res) { } }); return; } if (item.title == "经办人证件国徽面") { submitQuery.agentIdVld = data.enddate; //经办人证件有效期 } else { submitQuery.customerIdVld = data.enddate; //证件有效期 } } // 处理数据展示 handleDataList(ocrData, data, formData); console.log(data, 'data'); console.log(formData, 'formData'); }).finally(() => { uni.hideLoading(); }); } // 营业执照OCR识别 - 参考UserInfoUploading的实现 function cardImageOcrYY(fileList, item, formData) { submitQuery.userIdType = "203"; //203 公司信用代码 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 = res.data; console.log(data, '营业执照OCR识别结果'); // 定义OCR数据映射 - 使用UserInfoUploading中的字段名 let ocrData = [ { title: "公司名称", key: "unitName" }, { title: "社会信用代码", key: "screditCode" }, { title: "住址", key: "adress" // 注意:原代码中使用的是adress而不是address } ]; // 保存营业执照图片地址到submitQuery const itemData = formData.value[Index(item.title, formData.value)]; // itemData[itemData.value] = fileList.pathDomain.split('default-bucket/')[1]; // submitQuery.businessLicenseUrl = fileList.pathDomain.split('default-bucket/')[1]; itemData[itemData.value] = fileList.url; submitQuery.businessLicenseUrl = fileList.url; // 使用handleDataList函数处理数据展示 - 这是关键方法 handleDataList(ocrData, data, formData); // 同时保存到submitQuery中供后续提交使用 if (data.unitName) submitQuery.companyName = data.unitName; if (data.screditCode) submitQuery.socialCreditCode = data.screditCode; if (data.adress) submitQuery.companyAddress = data.adress; console.log("营业执照OCR识别完成,保存的数据:", { unitName: data.unitName, screditCode: data.screditCode, adress: data.adress, submitQuery: submitQuery }); }).catch(error => { console.error('营业执照OCR识别失败:', error); }).finally(() => { uni.hideLoading(); }); } //身份证上传 function uploadImgHandleId(fileList, item, formData) { if ( ["人像面", "国徽面", "经办人证件人像面", "经办人证件国徽面"].includes( item.title ) ) { idCardOcr(fileList, item, formData); } else if (item.title == "营业执照") { cardImageOcrYY(fileList, item, formData); } else if (item.title == "委托书") { proxyFileImageUpdate(fileList, item, formData); } else if (item.title == "车身照") { // 明确指定车身照类型 cardFileImageUpdate(fileList, item, formData); } } // 车身照上传 const cardFileImageUpdate = (fileList, item, formData) => { const dataItem = formData.value[Index(item.title, formData.value)]; // dataItem[dataItem.value] = fileList.pathDomain.split('default-bucket/')[1]; // submitQuery.vehBodyUrl = fileList.pathDomain.split('default-bucket/')[1]; dataItem[dataItem.value] = fileList.url; submitQuery.vehBodyUrl = fileList.url; }; // 委托书上传 const proxyFileImageUpdate = (fileList, item, formData) => { const dataItem = formData.value[Index(item.title, formData.value)]; // dataItem[dataItem.value] = fileList.pathDomain.split('default-bucket/')[1]; // submitQuery.proxyUrl = fileList.pathDomain.split('default-bucket/')[1]; dataItem[dataItem.value] = fileList.url; submitQuery.proxyUrl = fileList.url; }; //图像文件上传 const uploadImgHandle = (fileList, item, formData) => { if (item.title == "行驶证主页" || item.title == "行驶证副页") { cardImageOcr(fileList, item, formData); } else if (item.title == "车身照") { // 明确指定车身照类型 cardFileImageUpdate(fileList, item, formData); } }; return { uploadImgHandle, submitQuery, ocrDataFu, handleVehicCharge, handleVehicUsePropert, uploadImgHandleId, }; }