123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- 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<any>({});
- let registerQuery = reactive<any>({});
- const qdOrderStore = useQdOrderStore();
- // 社会信用代码ocr识别
- function cardImageOcrYY(fileList, item, formData) {
- const params = {
- type: "business_license",
- url: fileList.url,
- };
- submitQuery.value.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 cardFileImageUpdate(fileList, item, formData) {
- const dataItem = formData.value[Index(item.title, formData.value)];
- dataItem[dataItem.value] = fileList.pathDomain;
- }
-
- // 身份证类别识别
- 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;
-
- let ocrData = [
-
- ];
-
- const itemData = formData.value[Index(item.title, formData.value)]
- itemData[itemData.value] = fileList.pathDomain
- console.log(data, 'dataocr');
- 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.value.agentIdType = 101; //身份证类型
- submitQuery.value.agentAddress = data.address; //经办人住址
- // registerQuery.agentGender = data.gender == '男' ? 'MALE' : 'FEMALE' //经办人性别
- } else {
- ocrData = ocrData.concat([
- {
- title: "姓名",
- key: "name"
- },
- {
- title: "证件号码",
- key: "idno"
- },
- {
- title: "住址",
- key: "address"
- }
- ]);
- submitQuery.value.userIdType = 101; //身份证
- registerQuery.gender = data.gender == '男' ? 'MALE' : 'FEMALE' //用户性别
- }
- } else {
- if (!data.enddate) {
- uni.showModal({
- title: "提示",
- content: "很抱歉,我们无法识别您的证件,请按规范上传正反面,确保图片清晰、背景简洁(如白墙或桌面),减少证件反光和阴影",
- success: function (res) { }
- });
- return;
- }
- if (item.title == "经办人证件国徽面") {
- submitQuery.value.agentIdVld = data.enddate; //经办人证件有效期
- } else {
- submitQuery.value.customerIdVld = data.enddate; //证件有效期
- }
- }
- // 处理数据展示
- handleDataList(ocrData, data, formData);
- console.log(formData, 'formData');
- }).finally(()=>{
- uni.hideLoading();
- });
- }
- //图像文件上传
- function uploadImgHandle(fileList, item, formData) {
- if (
- ["人像面", "国徽面", "经办人证件人像面", "经办人证件国徽面"].includes(
- item.title
- )
- ) {
- idCardOcr(fileList, item, formData);
- } else if (item.title == "营业执照") {
- cardImageOcrYY(fileList, item, formData);
- } else {
- cardFileImageUpdate(fileList, item, formData);
- }
- }
- return {
- uploadImgHandle,
- submitQuery
- };
- }
|