123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464 |
- 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<any>({
- 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:"",
- });
- const qdOrderStore = useQdOrderStore();
- let registerQuery = reactive<any>({});
- let ocrDatas = {};
- let vehicChargeVal = {};
- // 行驶证主业或副业处理
- const cardImageOcr = (fileList, item, formData) => {
- let imageType: string;
- if (item.title == "行驶证主页") {
- imageType = "1";
- } else if (item.title == "行驶证副页") {
- imageType = "2";
- }
- const params = {
- source: "1",
- agencyId: qdOrderStore.qdOrderVal.agencyId,
- imageType: imageType,
- fileName: fileList.fileName,
- // imageBase64: fileList.path
- imageUrl: fileList.url
- };
- console.log("请求中etcCarOcrCard", params);
- requestNew("/iaw/ocr/vehicleLicenseOcr", {
- data: params
- // showLoading: true
- }).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] = data.imageUrl
- itemData[itemData.value] = fileList.pathDomain;
- console.log(data, "ocr返回数据");
- if(data.man != null){
- submitQuery.man = data.man
- }
- // item[item.value] = data.imageUrl
- if (imageType === "1") {
- // 需要处理展示的页面
- // 正面
- if (!data.plate_a || !data.engine) {
- uni.showModal({
- title: "提示",
- content: "识别错误,请上传正确的图片",
- success: function(res) {}
- });
- return;
- }
- 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);
- ocrDatas = data
- } else {
- if (!data.gross || !data.apc) {
- uni.showModal({
- title: "提示",
- content: "识别错误,请上传正确的图片",
- success: function(res) {}
- });
- return;
- }
- // 处理数据展示
- handleDataList(ocrDataFu, data, formData);
- console.log(formData, "formData");
- }
-
-
- await handleVehicCharge(formData);
- handleVehicUsePropert(formData);
- });
- };
- // 收费车型
- const handleVehicCharge = formData => {
- const approvedCountVal =
- formData.value[Index("核定载人数", formData.value)];
- const axleCountVal = formData.value[Index("车轴数", formData.value)];
- const vehicleDimensionsVal =
- formData.value[Index("外廓尺寸", formData.value)];
- const totalMassVal = formData.value[Index("总质量(kg)", formData.value)];
- if (
- !axleCountVal[axleCountVal.value] ||
- !vehicleDimensionsVal[vehicleDimensionsVal.value]
- ) {
- return;
- }
- let data = {
- agentId: qdOrderStore.qdOrderVal.agencyId,
- approvedCount: approvedCountVal[approvedCountVal.value],
- axleCount: axleCountVal[axleCountVal.value],
- channelId: qdOrderStore.qdOrderVal.channelId, //网点编号
- channelType: qdOrderStore.qdOrderVal.promotionModes,
- openId: "",
- totalMass: totalMassVal[totalMassVal.value],
- vanType: qdOrderStore.qdOrderVal.vanType,
- vehicleDimensions: vehicleDimensionsVal[vehicleDimensionsVal.value]
- .replace("mm", "")
- .trim()
- };
- if (qdOrderStore.qdOrderVal.promotionModes === 2) {
- data.openId = qdOrderStore.qdOrderVal.staffId; //操作人id
- } else if (qdOrderStore.qdOrderVal.promotionModes === 1) {
- data.openId = qdOrderStore.qdOrderVal.userId; //操作人id
- }
- let options = {
- data: data,
- method: "POST",
- showLoading: true
- };
- console.log(options, "options");
- 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)];
- itemData[itemData.value] = res.data.code;
- vehicChargeVal = res.data;
- console.log(itemData);
- });
- };
- // 车辆使用性质
- const handleVehicUsePropert = formData => {
- console.log(vehicChargeVal,'vehicChargeVal',ocrDatas)
- if (!vehicChargeVal.value || !ocrDatas.character) {
- return;
- }
- // itemData[itemData.value] = data.imageUrl
- let data = {
- agentId: qdOrderStore.qdOrderVal.agencyId,
- channelId: qdOrderStore.qdOrderVal.channelId, //网点编号
- channelType: qdOrderStore.qdOrderVal.promotionModes,
- openId: "",
- plateNum: qdOrderStore.qdOrderVal.vehiclePlate,
- vehicChargeName: vehicChargeVal.value,
- vehicleTypeName: ocrDatas.vehicle,
- vehicleUsePropertName: ocrDatas.character
- };
- if (qdOrderStore.qdOrderVal.promotionModes === 2) {
- data.openId = qdOrderStore.qdOrderVal.staffId; //操作人id
- } else if (qdOrderStore.qdOrderVal.promotionModes === 1) {
- data.openId = qdOrderStore.qdOrderVal.userId; //操作人id
- }
- 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 || "";
- })
- .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",
- agencyId: qdOrderStore.qdOrderVal.agencyId,
- imageType: imageType,
- fileName: fileList.fileName,
- // imageBase64: fileList.path,
- url: fileList.url,
- };
- uni.showLoading({
- title: '正在识别图片...',
- mask: true
- });
- requestNew('/iaw/ocr/idCardOcr', {
- 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
- 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.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;
- }
- if (item.title == "经办人证件人像面") {
- ocrData = ocrData.concat([
- {
- title: "经办人姓名",
- key: "name"
- },
- {
- title: "经办人证件号码",
- key: "idno"
- }
- ]);
- submitQuery.agentIdType = 101; //身份证类型
- submitQuery.agentAddress = data.address; //经办人住址
- // registerQuery.agentGender = data.gender == '男' ? 'MALE' : 'FEMALE' //经办人性别
- } else {
- 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识别
- function cardImageOcrYY(fileList, item, formData) {
- const params = {
- type: "business_license",
- url: fileList.url,
- };
- submitQuery.userIdType = "203"; //203 公司信用代码
- // 将图片上传
- cardFileImageUpdate(fileList, item, formData);
- //暂不识别营业执照
- return
- // request(ocrAllQuery, {
- // data: params
- // }).then(res => {
- // let data : any = JSON.parse(res.bizContent);
- // console.log(data, '公司ocr', '请求参数', params)
- // if (data.result) {
- // submitQuery.value.userIdType = "203"; //203 公司信用代码
- // const corporateName = formData.value[Index("公司名称", formData.value)];
- // const businessLicense = JSON.parse(data.result.businessLicense)
- // corporateName[corporateName.value] = businessLicense["名称"] || '';
- // submitQuery.value.address = businessLicense[
- // "住所"
- // ] || ''; //公司地址ocr获取不到,手动填写
- // const creditNum = formData.value[Index("社会信用代码", formData.value)];
- // creditNum[creditNum.value] = businessLicense[
- // "统一社会信用代码"
- // ];
- // // 将图片上传
- // cardFileImageUpdate(fileList, item, formData);
- // }
- // });
- }
-
- //身份证上传
- function uploadImgHandleId(fileList, item, formData) {
- if (
- ["人像面", "国徽面", "经办人证件人像面", "经办人证件国徽面"].includes(
- item.title
- )
- ) {
- idCardOcr(fileList, item, formData);
- } else if (item.title == "营业执照") {
- cardImageOcrYY(fileList, item, formData);
- } else {
- cardFileImageUpdate(fileList, item, formData);
- }
- }
- // 车身照上传
- const cardFileImageUpdate = (fileList, item, formData) => {
- const dataItem = formData.value[Index(item.title, formData.value)];
- dataItem[dataItem.value] = fileList.pathDomain;
- };
-
- //图像文件上传
- const uploadImgHandle = (fileList, item, formData) => {
- if (item.title == "行驶证主页" || item.title == "行驶证副页") {
- cardImageOcr(fileList, item, formData);
- } else {
- cardFileImageUpdate(fileList, item, formData);
- }
- };
-
- return {
- uploadImgHandle,
- submitQuery,
- ocrDataFu,
- handleVehicCharge,
- handleVehicUsePropert,
- uploadImgHandleId,
- };
- }
|