Kaynağa Gözat

bugfix 页面重构

谢杰标 2 yıl önce
ebeveyn
işleme
763a701928
2 değiştirilmiş dosya ile 237 ekleme ve 127 silme
  1. 67 0
      common/methodTool.js
  2. 170 127
      pages2/verify/input.vue

+ 67 - 0
common/methodTool.js

@@ -660,4 +660,71 @@ export default {
       return false;
     }
   },
+  imageToBase64(url, quality = 0.8) {
+    return new Promise((resolve, reject) => {
+      url = this.splitImgHost(url);
+      // #ifdef MP-WEIXI
+      let that = this;
+      uni.downloadFile({
+        url,
+        success: (res) => {
+          if (res.statusCode === 200) {
+            that.fileToBase64(res.tempFilePath).then((res) => {
+              console.log(res);
+              resolve(res);
+            });
+          }
+        },
+      });
+      // #endif
+      // #ifdef H5
+      let image = new Image();
+      console.log(1);
+      image.onload = function () {
+        let canvas = document.createElement("canvas");
+        canvas.width = image.width;
+        canvas.height = image.height;
+        let context = canvas.getContext("2d");
+        context.drawImage(image, 0, 0, image.width, image.height);
+        let base64 = canvas.toDataURL("image/jpeg", quality); //将图片格式转为base64
+        resolve(base64);
+      };
+      image.setAttribute("crossOrigin", "Anonymous");
+      image.src = url + "?time=" + Date.now();
+      image.onerror = () => {
+        reject(new Error("urlToBase64 error"));
+      };
+      // #endif
+    });
+  },
+  fileToBase64(url) {
+    return new Promise((resolve, reject) => {
+      // #ifdef MP-WEIXI
+      let fileSystem = uni.getFileSystemManager();
+      fileSystem.readFile({
+        filePath: url,
+        encoding: "base64",
+        position: 0,
+        success: (res) => {
+          resolve("data:image/jpg;base64," + res.data);
+        },
+        fail(err) {
+          console.error(err, "err");
+        },
+      });
+      // #endif
+      // #ifdef H5
+      let reader = new FileReader();
+      reader.readAsDataURL(url);
+      reader.onload = (e) => {
+        resolve(e.target.result);
+      };
+      // #endif
+    });
+  },
+  isBase64(str) {
+    var reg =
+      /^\s*data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s]*?)\s*$/i;
+    return reg.test(str);
+  },
 };

+ 170 - 127
pages2/verify/input.vue

@@ -522,7 +522,7 @@ export default {
       isUploading: false,
       form: {
         name: "",
-        sex: "",
+        sex: "",
         idcard: "",
         telphone: "",
         education: "",
@@ -534,9 +534,9 @@ export default {
         apply_post: "",
         major: "",
         working_years: "",
-        recent_photos: "",
-        idcard_face_photo: "",
-        idcard_national_photo: "",
+        recent_photos: "oss/images/avatar/131/1686271592764_1781951949",
+        idcard_face_photo: "oss/images/IDCard/131/1686271688971.jpg",
+        idcard_national_photo: "oss/images/IDCard/131/1686271714573.jpg",
         commitment_electr_signature: "",
         commitment_seal: "",
       },
@@ -722,8 +722,6 @@ export default {
       apply_post_disabled: false,
       isRequired: false,
       orderGoodsId: 0,
-      veryIdCard: "",
-      veryIdName: "",
       disName: false, // 姓名是否禁止输入
       disCard: false, // 身份证是否禁止输入
       auto: "180rpx",
@@ -1014,12 +1012,146 @@ export default {
     },
 
     async uploadDatas(data) {
-      // console.log('sfsfg---data', data)
+      console.log("sfsfg---data", data);
+      if (this.form.recent_photos && this.form.idcard_face_photo) {
+        let base64 = await this.$method.imageToBase64(
+          this.form.idcard_face_photo
+        );
+        let resData = await this.faceCertificationIDCardOCR(1, base64);
+        if (!resData.data) {
+          uni.showModal({
+            title: "提示",
+            content: "身份证人像面照片异常,请重新上传",
+            showCancel: false,
+          });
+          this.isUploading = false;
+          return;
+        }
+        base64 = await this.$method.imageToBase64(this.form.recent_photos);
+        this.$api
+          .faceCertificationIdCardCompareFace({
+            urlA: this.form.idcard_face_photo,
+            oneInchPhotos: base64,
+          })
+          .then((res1) => {
+            if (res1.data.data >= 70) {
+              var self = this;
+              if (self.remarkStatus) {
+                var arsty = {};
+                for (let k in data) {
+                  for (let j in self.copyData) {
+                    if (k === j) {
+                      if (self.copyData[j].value === data[k]) {
+                        arsty[k] = {
+                          fieldKey: k,
+                          value: data[k],
+                          fieldName: (function () {
+                            for (let i = 0; i < self.listData.length; i++) {
+                              if (self.listData[i].fieldKey == k) {
+                                return self.listData[i].fieldName;
+                              }
+                            }
+                          })(),
+                          status: 0,
+                        };
+                      } else {
+                        arsty[k] = {
+                          fieldKey: k,
+                          value: data[k],
+                          fieldName: (function () {
+                            for (let i = 0; i < self.listData.length; i++) {
+                              if (self.listData[i].fieldKey == k) {
+                                return self.listData[i].fieldName;
+                              }
+                            }
+                          })(),
+                          status: 1,
+                        };
+                      }
+                    }
+                  }
+                }
+                var datas = {
+                  id: this.id,
+                  goodsId: this.goodsId,
+                  orderGoodsId: this.orderGoodsId,
+                  keyValue: JSON.stringify(arsty),
+                };
+                console.log(datas, "datas0");
+                // this.isUploading = false;
+                // return;
+                this.$api.editbaseprofiletp(datas).then((res) => {
+                  this.isUploading = false;
+                  if (res.data.code === 200) {
+                    this.$method.showToast("提交成功");
+                    this.getUserInfo();
+                    setTimeout(() => {
+                      console.log("延迟");
+                      uni.navigateBack();
+                    }, 1500);
+                  } else {
+                    this.$method.showToast(res.data.msg);
+                    this.isUploading = false;
+                  }
+                });
+              } else {
+                var objs = {};
+                for (let k in data) {
+                  objs[k] = {
+                    fieldKey: k,
+                    value: data[k],
+                    fieldName: (function () {
+                      for (let i = 0; i < self.listData.length; i++) {
+                        if (self.listData[i].fieldKey == k) {
+                          return self.listData[i].fieldName;
+                        }
+                      }
+                    })(),
+                    status: 0,
+                  };
+                }
+                var datas = {
+                  goodsId: this.goodsId,
+                  profileTpId: this.goodsId,
+                  orderGoodsId: this.orderGoodsId,
+                  keyValue: JSON.stringify(objs),
+                };
+
+                console.log(data, "datas");
+                // this.isUploading = false;
+                // return;
+                this.$api.addbaseprofiletp(datas).then((res) => {
+                  this.isUploading = false;
+                  if (res.data.code === 200) {
+                    this.$method.showToast("提交成功");
+                    this.getUserInfo();
+                    setTimeout(() => {
+                      console.log("延迟");
+                      uni.navigateBack();
+                    }, 1500);
+                  } else {
+                    this.$method.showToast(res.data.msg);
+                    this.isUploading = false;
+                  }
+                });
+              }
+            } else {
+              this.isUploading = false;
+              uni.showModal({
+                title: "提示",
+                content: "个人近照和身份证人像面照片不匹配",
+                showCancel: false,
+              });
+            }
+          });
+        return  
+      }
+      return;
       if (this.form.recent_photos && this.form.idcard_face_photo) {
         uni.downloadFile({
           url: this.$method.splitImgHost(this.form.idcard_face_photo),
           success: async (res) => {
-            console.log(res, 999);
+            console.log(res, 8585858);
             if (res.statusCode === 200) {
               let resData = await this.faceCertificationIDCardOCR(
                 1,
@@ -1034,21 +1166,6 @@ export default {
                 this.isUploading = false;
                 return;
               }
-              this.veryIdCard = resData.data.data.IdNum;
-              this.veryIdName = resData.data.data.IdName;
-
-              // if(this.form.idcard) {
-              // 	if(this.form.idcard != this.veryIdCard) {
-              // 		uni.showModal({
-              // 			title:'提示',
-              // 			content:'输入的身份证号和身份证人像面照片身份证号不匹配',
-              // 			showCancel:false,
-              // 		})
-              // 		this.isUploading = false;
-              // 		return;
-              // 	}
-              // }
-
               uni.downloadFile({
                 url: this.$method.splitImgHost(this.form.recent_photos),
                 success: (res) => {
@@ -1272,7 +1389,7 @@ export default {
 
         console.log(datas, "datas1");
 
-        // return;
+        return;
         this.$api.editbaseprofiletp(datas).then((res) => {
           this.isUploading = false;
           if (res.data.code === 200) {
@@ -1332,7 +1449,7 @@ export default {
           .catch((err) => {});
       }
     },
-    
+
     clearWord() {
       this.$set(this.form, "commitment_seal", "");
       this.titleName = "";
@@ -1357,7 +1474,6 @@ export default {
         );
       }
       if (data["idcard_face_photo"]) {
-        console.log("idcard_face_photo");
         data.idcard_face_photo = await this.$method.uploadFile(
           data.idcard_face_photo,
           0
@@ -1381,7 +1497,6 @@ export default {
           0
         );
       }
-      console.log(data,789)
       this.uploadDatas(data);
     },
     //验证表单
@@ -1428,50 +1543,16 @@ export default {
       this.openVerify = true;
       this.resultForm(1);
     },
-    faceCertificationIDCardOCR(cardSide, url) {
-      return new Promise((resolve) => {
-        let fileSystem = uni.getFileSystemManager();
-        fileSystem.readFile({
-          filePath: url,
-          encoding: "base64",
-          position: 0,
-          success: (res) => {
-            let base64 = "data:image/jpg;base64," + res.data;
-            this.$api
-              .faceCertificationIDCardOCR({
-                cardSide: cardSide, //1人像  2 国徽
-                cardImageBase64: base64,
-                gradeId: this.gradeId,
-              })
-              .then((res) => {
-                resolve(res);
-              });
-          },
-          fail(err) {
-            console.error(err, "err");
-          },
-        });
-      });
-    },
-    h5FaceCertificationIDCardOCR(cardSide, file) {
-      return new Promise((resolve) => {
-        var reader = new FileReader();
-        // 将文件加载进入
-        reader.readAsDataURL(file);
-        reader.onload = (e) => {
-          // 转换完成输出该文件base64编码
-          let base64 = e.target.result;
-          this.$api
-            .faceCertificationIDCardOCR({
-              cardSide: cardSide, //1人像  2 国徽
-              cardImageBase64: base64,
-              gradeId: this.gradeId,
-            })
-            .then((res) => {
-              resolve(res);
-            });
-        };
+    async faceCertificationIDCardOCR(cardSide, base64) {
+      if (!this.$method.isBase64(base64)) {
+        base64 = await this.$method.fileToBase64(base64);
+      }
+      let res = await this.$api.faceCertificationIDCardOCR({
+        cardSide: cardSide, //1人像  2 国徽
+        cardImageBase64: base64,
+        gradeId: this.gradeId,
       });
+      return Promise.resolve(res.data);
     },
     async changePhotoListHeader(lists, key) {
       const map = {
@@ -1506,6 +1587,7 @@ export default {
               url = await this.$method.uploadFile(url, 0);
               // #endif
               this.$set(this.form, "recent_photos", url);
+              console.log(url, 789);
             } else {
               // #ifdef MP-WEIXIN
               let url = lists[0].url;
@@ -1617,38 +1699,6 @@ export default {
               }
             );
           }
-
-          // uni.compressImage({
-          //   src: url,
-          //   quality: 75,
-          //   width: "50%",
-          //   height: "50%",
-          //   success: async (rest) => {
-          //     let res = await this.faceCertificationIDCardOCR(
-          //       1,
-          //       rest.tempFilePath
-          //     );
-
-          //     if (res.data.code == 500) {
-          //       uni.showToast({
-          //         icon: "none",
-          //         title: "请上传正确清晰的身份证人像面照片",
-          //       });
-          //       return;
-          //     }
-          //     this.$refs.idcard_face_photo[0].lists = [
-          //       {
-          //         url: this.$method.splitImgHost(res.data.data.IdImgPath),
-          //       },
-          //     ];
-          //     this.$set(
-          //       this.form,
-          //       "idcard_face_photo",
-          //       res.data.data.IdImgPath
-          //     );
-          //     console.log(this.form, "idcard_face_photo");
-          //   },
-          // });
         }
       } else {
         this.fileList2 = [];
@@ -1721,21 +1771,15 @@ export default {
       });
     },
     async checkIdCard(cardSide, url, titleMsg, paramType) {
-      // #ifdef MP-WEIXIN
       let res = await this.faceCertificationIDCardOCR(cardSide, url);
-      // #endif
-      // #ifdef H5
-      let res = await this.h5FaceCertificationIDCardOCR(cardSide, url);
-      // #endif
-
-      if (res.data.code == 500) {
+      if (res.code == 500) {
         uni.showToast({
           icon: "none",
           title: titleMsg,
         });
         return;
       }
-      let { IdName, IdNum } = res.data.data;
+      let { IdName, IdNum } = res.data;
       if (IdName != this.form.name || IdNum != this.form.idcard) {
         // uni.showModal({
         //   content:
@@ -1753,11 +1797,10 @@ export default {
       }
       this.$refs[paramType][0].lists = [
         {
-          url: this.$method.splitImgHost(res.data.data.IdImgPath),
+          url: this.$method.splitImgHost(res.data.IdImgPath),
         },
       ];
-      this.$set(this.form, paramType, res.data.data.IdImgPath);
-      // console.log(this.form[paramType], '《===',paramType);
+      this.$set(this.form, paramType, res.data.IdImgPath);
     },
     getTimes(key) {
       if (this.form[key]) {
@@ -2010,20 +2053,20 @@ export default {
                   (result.data.data.status === 1 ||
                     result.data.data.status === 2)
                 ) {
-                  uni.showModal({
-                    showCancel: false,
-                    content:
-                      result.data.data.status === 1
-                        ? "该商品审核资料已通过,不可重复提交资料"
-                        : result.data.data.status === 2
-                        ? "该商品审核资料处于待审核状态,不可重复提交资料"
-                        : "请联系管理员",
-                    success: function (k) {
-                      if (k.confirm) {
-                        uni.navigateBack();
-                      }
-                    },
-                  });
+                  // uni.showModal({
+                  //   showCancel: false,
+                  //   content:
+                  //     result.data.data.status === 1
+                  //       ? "该商品审核资料已通过,不可重复提交资料"
+                  //       : result.data.data.status === 2
+                  //       ? "该商品审核资料处于待审核状态,不可重复提交资料"
+                  //       : "请联系管理员",
+                  //   success: function (k) {
+                  //     if (k.confirm) {
+                  //       uni.navigateBack();
+                  //     }
+                  //   },
+                  // });
                 }
               }
             });