Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ocrHandle.ts 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. import { reactive } from "vue";
  2. import { requestNew } from "@/utils/network/request";
  3. import { Index, handleDataList } from "@/components/form-builder/tools";
  4. import { etcCarOcrCard, fileUpload } from "@/utils/network/api.js";
  5. import { useQdOrderStore } from "@/stores/qdOrder.js";
  6. // 配合formBuilderVue3模板使用
  7. export default function () {
  8. const ocrDataFu = [
  9. {
  10. title: "准牵引总质量(kg)",
  11. key: "towing",
  12. isNumbers: true,
  13. sendKey: "permittedTowWeight"
  14. },
  15. {
  16. title: "核定载人数",
  17. key: "apc",
  18. isNumbers: true,
  19. sendKey: "approvedCount"
  20. },
  21. {
  22. title: "核定载质量(kg)",
  23. isNumbers: true,
  24. key: "alc",
  25. sendKey: "permittedWeight"
  26. },
  27. {
  28. title: "总质量(kg)",
  29. isNumbers: true,
  30. key: "gross",
  31. sendKey: "totalMass"
  32. },
  33. {
  34. title: "整备质量(kg)",
  35. isNumbers: true,
  36. key: "unladen",
  37. sendKey: "maintenaceMass"
  38. },
  39. {
  40. title: "外廓尺寸",
  41. key: "overall",
  42. // substring: 2, //截取最后两位
  43. sendKey: "vehicleDimensions"
  44. }
  45. ];
  46. let submitQuery = reactive<any>({
  47. orderId: "", //订单ID
  48. man: "", //所有人
  49. character: "", //使用性质
  50. register: "", //注册日期
  51. customerId: "", //用户编号
  52. vehicleId: "",
  53. vehicleIdNum: "", //车牌编号
  54. issueDate: "", //发证日期
  55. vehPosImgUrl: "", //行驶证正面
  56. vehNegImgUrl: "", //行驶证证反面
  57. type: "0", //0,客车 1.货车
  58. useUserType: 0, //车辆用户类型
  59. useUserTypeName: "普通车",
  60. vehicleSign: 2, //前/后装标识
  61. vin: "", //车辆识别代号
  62. engineNum: "", //发动机号码
  63. vehicleType: "", //车辆类型
  64. vehicleModel: "", //行驶证品牌型号
  65. approvedCount: "", //核定人数
  66. totalMass: "", //总质量
  67. maintenaceMass: "", //整备质量
  68. permittedWeight: "", //核定载质量
  69. vehicleDimensions: "", //车辆尺寸
  70. permittedTowWeight: "", //准牵引总质量
  71. axleCount: "", //车轴数
  72. ownerName: "", //车主姓名
  73. ownerIdType: "", //车主证件类型
  74. ownerIdNum: "", //车主证件号码
  75. ownPosImgUrl: "", //车主证件正面图片
  76. ownNegImgUrl: "", //车主证件反面图片
  77. agreementId: "", //签约编号
  78. channelId: "5201018892300000001", //编号渠道
  79. scenePayType: "", //
  80. transportIdNum: "", //道路运输证编号
  81. licenseIdNum: "", //经营许可证编号
  82. vehBodyUrl: "",//车身照片
  83. proxyUrl: "",
  84. agentIdType: "",
  85. userIdType: "",
  86. // 企业相关字段
  87. companyName: "", // 公司名称
  88. socialCreditCode: "", // 社会信用代码
  89. companyAddress: "", // 公司地址
  90. businessLicenseUrl: "", // 营业执照图片URL
  91. });
  92. const qdOrderStore = useQdOrderStore();
  93. let registerQuery = reactive<any>({});
  94. let ocrDatas = {};
  95. let vehicChargeVal = {};
  96. let ocrFu = false;//标志副业是否ocr识别过
  97. let ocrZm = false;//标志主页是否ocr识别过
  98. // 行驶证主业或副业处理
  99. const cardImageOcr = (fileList, item, formData) => {
  100. let imageType: string;
  101. if (item.title == "行驶证主页") {
  102. imageType = "3";
  103. } else if (item.title == "行驶证副页") {
  104. imageType = "4";
  105. }
  106. const params = {
  107. type: imageType,
  108. // imagePath: fileList.url.split('default-bucket/')[1],
  109. imagePath: fileList.url,
  110. };
  111. requestNew("/iaw/api/ocr/do", {
  112. data: params
  113. }).then(async res => {
  114. if (res.code !== 0) return;
  115. let data: any = res.data;
  116. const itemData = formData.value[Index(item.title, formData.value)];
  117. // itemData[itemData.value] = fileList.pathDomain.split('default-bucket/')[1];
  118. itemData[itemData.value] = fileList.url;
  119. if (data.man != null) {
  120. submitQuery.man = data.man
  121. }
  122. if (imageType === "3") {
  123. const ocrData = [
  124. {
  125. title: "车牌号",
  126. key: "plate_a"
  127. },
  128. {
  129. title: "车辆类型",
  130. key: "vehicle"
  131. },
  132. {
  133. title: "使用性质",
  134. key: "character"
  135. },
  136. {
  137. title: "发动机号码",
  138. key: "engine"
  139. },
  140. {
  141. title: "品牌型号",
  142. key: "model"
  143. },
  144. {
  145. title: "车辆识别代码",
  146. key: "vin"
  147. },
  148. {
  149. title: "所有人",
  150. key: "man"
  151. },
  152. {
  153. title: "发证日期",
  154. key: "issue"
  155. },
  156. {
  157. title: "注册日期",
  158. key: "register"
  159. }
  160. ];
  161. // 处理数据展示
  162. handleDataList(ocrData, data, formData);
  163. ocrZm = true;
  164. if(ocrFu){
  165. handleVehicUsePropert(formData);
  166. }
  167. ocrDatas = data;
  168. } else {
  169. handleDataList(ocrDataFu, data, formData);
  170. ocrFu = true;//声明副业ocr已经识别
  171. // 在处理完副页OCR数据后调用handleVehicCharge
  172. // handleVehicCharge(formData);
  173. if(ocrZm){
  174. handleVehicUsePropert(formData);
  175. }
  176. const permittedWeight = formData.value[Index("核定载质量(kg)", formData.value)];
  177. console.log(permittedWeight[permittedWeight.value], "permittedWeight");
  178. const permittedTowWeight = formData.value[Index("准牵引总质量(kg)", formData.value)];
  179. console.log(permittedTowWeight[permittedTowWeight.value], "permittedTowWeight");
  180. // 如果核定载质量为undefined,则设置show为true
  181. if (permittedWeight && permittedWeight[permittedWeight.value]) {
  182. permittedWeight.show = false;
  183. }else{
  184. permittedWeight.show = true;
  185. }
  186. if (permittedTowWeight && permittedTowWeight[permittedTowWeight.value]) {
  187. permittedTowWeight.show = false;
  188. }else{
  189. permittedTowWeight.show = true;
  190. }
  191. }
  192. });
  193. };
  194. // 收费车型
  195. const handleVehicCharge = formData => {
  196. console.log(formData.value, "收费车型formData");
  197. console.log(qdOrderStore.qdOrderVal, "qdOrderStore.qdOrderVal");
  198. const axleCountVal = formData.value[Index("车轴数", formData.value)];
  199. const approvedCount = formData.value[Index("核定载人数", formData.value)];
  200. const totalMass = formData.value[Index("总质量(kg)", formData.value)];
  201. const vehicleDimensions = formData.value[Index("外廓尺寸", formData.value)];
  202. console.log(axleCountVal, "axleCountVal");
  203. if (
  204. !axleCountVal[axleCountVal.value]
  205. ) {
  206. return;
  207. }else{
  208. let data = {
  209. approvedCount: approvedCount[approvedCount.value],
  210. axleCount: Number(axleCountVal[axleCountVal.value]),
  211. totalMass: totalMass[totalMass.value],
  212. vanType: qdOrderStore.qdOrderVal.vanType,
  213. vehicleDimensions: vehicleDimensions[vehicleDimensions.value]
  214. }
  215. let options = {
  216. data: data,
  217. method: "POST",
  218. showLoading: true
  219. };
  220. return requestNew("/iaw/h5/order/web/vehicCharge", options).then(res => {
  221. console.log(res, "res vehicCharge");
  222. if (res.code !== 0) return;
  223. const itemData = formData.value[Index("收费车型", formData.value)];
  224. console.log(itemData, "itemData");
  225. console.log("feeVehicleType value:", res.data.feeVehicleType, "type:", typeof res.data.feeVehicleType);
  226. // 直接设置值,不需要设置 itemData.itemData
  227. const feeVehicleType = Number(res.data.feeVehicleType);
  228. itemData.feeVehicleType = feeVehicleType; // 直接设置到对象属性上
  229. submitQuery.feeVehicleType = feeVehicleType;
  230. vehicChargeVal = res.data.feeVehicleTypeStr;
  231. console.log("After set itemData:", itemData);
  232. handleVehicUsePropert(formData);
  233. });
  234. }
  235. };
  236. // 车辆使用性质
  237. const handleVehicUsePropert = formData => {
  238. console.log(formData,'使用性质formData')
  239. console.log(vehicChargeVal,vehicChargeVal,'vehicChargeVal')
  240. const vehicleType = formData.value[Index("车辆类型", formData.value)];
  241. const useCharacter = formData.value[Index("使用性质", formData.value)];
  242. const approvedCount = formData.value[Index("核定载人数", formData.value)];
  243. const totalMass = formData.value[Index("总质量(kg)", formData.value)];
  244. const vehicleDimensions = formData.value[Index("外廓尺寸", formData.value)];
  245. const permittedWeight = formData.value[Index("核定载质量(kg)", formData.value)];
  246. const permittedTowWeight = formData.value[Index("准牵引总质量(kg)", formData.value)];
  247. const axleCount = formData.value[Index("车轴数", formData.value)];
  248. const vanType = formData.value[Index("收费车型", formData.value)];
  249. const plateNum = formData.value[Index("车牌号", formData.value)];
  250. console.log(ocrDatas,'ocrDatas')
  251. // if (!vehicChargeVal || !ocrDatas.character) {
  252. // console.log('没有收费车型或使用性质')
  253. // return;
  254. // }
  255. // itemData[itemData.value] = data.imageUrl
  256. let data = {
  257. approvedCount: approvedCount[approvedCount.value],
  258. axleCount: axleCount[axleCount.value],
  259. plateNum: plateNum[plateNum.value],
  260. totalMass: totalMass[totalMass.value],
  261. vanType: qdOrderStore.qdOrderVal.vanType,
  262. vehicleDimensions: vehicleDimensions[vehicleDimensions.value],
  263. // permittedWeight: permittedWeight[permittedWeight.value],
  264. // permittedTowWeight: permittedTowWeight[permittedTowWeight.value],
  265. // feeVehicleTypeStr: vehicChargeVal,
  266. vehicleTypeName: vehicleType[vehicleType.value],
  267. vehicleUsePropertName: useCharacter[useCharacter.value]
  268. };
  269. let options = {
  270. data: data,
  271. method: "POST",
  272. showLoading: true
  273. };
  274. console.log(options, "options");
  275. return requestNew("/iaw/h5/order/web/vehicUsePropert", options)
  276. .then(res => {
  277. console.log(res, "res");
  278. if (res.code !== 0) return;
  279. const itemData = formData.value[Index("使用性质", formData.value)];
  280. itemData[itemData.value] = res.data.vehicUse || "";
  281. const itemData1 = formData.value[Index("收费车型", formData.value)];
  282. const feeVehicleType = Number(res.data.feeVehicleType);
  283. itemData1.feeVehicleType = feeVehicleType; // 直接设置到对象属性上
  284. submitQuery.feeVehicleType = feeVehicleType;
  285. vehicChargeVal = res.data.feeVehicleTypeStr;
  286. })
  287. .finally(() => { });
  288. };
  289. // 身份证类别识别
  290. function idCardOcr(fileList, item, formData) {
  291. let imageType;
  292. if (item.title == "人像面" || item.title == "经办人证件人像面") {
  293. imageType = "1";
  294. } else if (item.title == "国徽面" || item.title == "经办人证件国徽面") {
  295. imageType = "2";
  296. }
  297. const data = {
  298. // source: "1",
  299. type:imageType,
  300. // imagePath: fileList.url.split('default-bucket/')[1],
  301. imagePath: fileList.url,
  302. };
  303. uni.showLoading({
  304. title: '正在识别图片...',
  305. mask: true
  306. });
  307. requestNew('/iaw/api/ocr/do', {
  308. data: data
  309. }).then(res => {
  310. if (res.code !== 0) return
  311. let data: any = res.data;
  312. console.log(res.data, 'res.datares.datares.datares.data');
  313. let ocrData = [
  314. ];
  315. const itemData = formData.value[Index(item.title, formData.value)]
  316. // itemData[itemData.value] = fileList.pathDomain
  317. itemData[itemData.value] = fileList.url
  318. console.log(data, 'dataocr');
  319. if (data.idno != null) {
  320. submitQuery.idno = data.idno
  321. }
  322. if (data.name != null) {
  323. submitQuery.idName = data.name
  324. submitQuery.ownerPosImgUrl = data.imageUrl
  325. } else {
  326. submitQuery.ownerNegImgUrl = data.imageUrl
  327. }
  328. if (data.address != null) {
  329. submitQuery.ownerIdAddress = data.address
  330. }
  331. if (data.mobile != null) {
  332. submitQuery.ownerTel = data.mobile
  333. }
  334. if (imageType == "1") {
  335. // 人像面
  336. if (!data.name || !data.idno) {
  337. uni.showModal({
  338. title: "提示",
  339. content: "很抱歉,我们无法识别您的证件,请按规范上传正反面,确保图片清晰、背景简洁(如白墙或桌面),减少证件反光和阴影",
  340. success: function (res) { }
  341. });
  342. return;
  343. }
  344. ocrData = ocrData.concat([
  345. {
  346. title: "姓名",
  347. key: "name"
  348. },
  349. {
  350. title: "证件号码",
  351. key: "idno"
  352. },
  353. {
  354. title: "住址",
  355. key: "address"
  356. }
  357. ]);
  358. submitQuery.userIdType = 101; //身份证
  359. registerQuery.gender = data.gender == '男' ? 'MALE' : 'FEMALE' //用户性别
  360. } else {
  361. if (!data.enddate) {
  362. uni.showModal({
  363. title: "提示",
  364. content: "很抱歉,我们无法识别您的证件,请按规范上传正反面,确保图片清晰、背景简洁(如白墙或桌面),减少证件反光和阴影",
  365. success: function (res) { }
  366. });
  367. return;
  368. }
  369. if (item.title == "经办人证件国徽面") {
  370. submitQuery.agentIdVld = data.enddate; //经办人证件有效期
  371. } else {
  372. submitQuery.customerIdVld = data.enddate; //证件有效期
  373. }
  374. }
  375. // 处理数据展示
  376. handleDataList(ocrData, data, formData);
  377. console.log(data, 'data');
  378. console.log(formData, 'formData');
  379. }).finally(() => {
  380. uni.hideLoading();
  381. });
  382. }
  383. // 营业执照OCR识别 - 参考UserInfoUploading的实现
  384. function cardImageOcrYY(fileList, item, formData) {
  385. submitQuery.userIdType = "203"; //203 公司信用代码
  386. const data = {
  387. type: '5',
  388. // imagePath: fileList.url.split('default-bucket/')[1],
  389. imagePath: fileList.url,
  390. };
  391. uni.showLoading({
  392. title: '正在识别图片...',
  393. mask: true
  394. });
  395. requestNew('/iaw/api/ocr/do', {
  396. data: data
  397. }).then(res => {
  398. if (res.code !== 0) return;
  399. let data = res.data;
  400. console.log(data, '营业执照OCR识别结果');
  401. // 定义OCR数据映射 - 使用UserInfoUploading中的字段名
  402. let ocrData = [
  403. {
  404. title: "公司名称",
  405. key: "unitName"
  406. },
  407. {
  408. title: "社会信用代码",
  409. key: "screditCode"
  410. },
  411. {
  412. title: "住址",
  413. key: "adress" // 注意:原代码中使用的是adress而不是address
  414. }
  415. ];
  416. // 保存营业执照图片地址到submitQuery
  417. const itemData = formData.value[Index(item.title, formData.value)];
  418. // itemData[itemData.value] = fileList.pathDomain.split('default-bucket/')[1];
  419. // submitQuery.businessLicenseUrl = fileList.pathDomain.split('default-bucket/')[1];
  420. itemData[itemData.value] = fileList.url;
  421. submitQuery.businessLicenseUrl = fileList.url;
  422. // 使用handleDataList函数处理数据展示 - 这是关键方法
  423. handleDataList(ocrData, data, formData);
  424. // 同时保存到submitQuery中供后续提交使用
  425. if (data.unitName) submitQuery.companyName = data.unitName;
  426. if (data.screditCode) submitQuery.socialCreditCode = data.screditCode;
  427. if (data.adress) submitQuery.companyAddress = data.adress;
  428. console.log("营业执照OCR识别完成,保存的数据:", {
  429. unitName: data.unitName,
  430. screditCode: data.screditCode,
  431. adress: data.adress,
  432. submitQuery: submitQuery
  433. });
  434. }).catch(error => {
  435. console.error('营业执照OCR识别失败:', error);
  436. }).finally(() => {
  437. uni.hideLoading();
  438. });
  439. }
  440. //身份证上传
  441. function uploadImgHandleId(fileList, item, formData) {
  442. if (
  443. ["人像面", "国徽面", "经办人证件人像面", "经办人证件国徽面"].includes(
  444. item.title
  445. )
  446. ) {
  447. idCardOcr(fileList, item, formData);
  448. } else if (item.title == "营业执照") {
  449. cardImageOcrYY(fileList, item, formData);
  450. } else if (item.title == "委托书") {
  451. proxyFileImageUpdate(fileList, item, formData);
  452. } else if (item.title == "车身照") { // 明确指定车身照类型
  453. cardFileImageUpdate(fileList, item, formData);
  454. }
  455. }
  456. // 车身照上传
  457. const cardFileImageUpdate = (fileList, item, formData) => {
  458. const dataItem = formData.value[Index(item.title, formData.value)];
  459. // dataItem[dataItem.value] = fileList.pathDomain.split('default-bucket/')[1];
  460. // submitQuery.vehBodyUrl = fileList.pathDomain.split('default-bucket/')[1];
  461. dataItem[dataItem.value] = fileList.url;
  462. submitQuery.vehBodyUrl = fileList.url;
  463. };
  464. // 委托书上传
  465. const proxyFileImageUpdate = (fileList, item, formData) => {
  466. const dataItem = formData.value[Index(item.title, formData.value)];
  467. // dataItem[dataItem.value] = fileList.pathDomain.split('default-bucket/')[1];
  468. // submitQuery.proxyUrl = fileList.pathDomain.split('default-bucket/')[1];
  469. dataItem[dataItem.value] = fileList.url;
  470. submitQuery.proxyUrl = fileList.url;
  471. };
  472. //图像文件上传
  473. const uploadImgHandle = (fileList, item, formData) => {
  474. if (item.title == "行驶证主页" || item.title == "行驶证副页") {
  475. cardImageOcr(fileList, item, formData);
  476. } else if (item.title == "车身照") { // 明确指定车身照类型
  477. cardFileImageUpdate(fileList, item, formData);
  478. }
  479. };
  480. return {
  481. uploadImgHandle,
  482. submitQuery,
  483. ocrDataFu,
  484. handleVehicCharge,
  485. handleVehicUsePropert,
  486. uploadImgHandleId,
  487. };
  488. }