@dongkboy преди 3 години
родител
ревизия
afee1b6cde
променени са 2 файла, в които са добавени 20 реда и са изтрити 6 реда
  1. 14 0
      src/utils/validate.js
  2. 6 6
      src/views/Letter/Letter.vue

+ 14 - 0
src/utils/validate.js

@@ -157,6 +157,20 @@ export function searchkey(cityName){
       matchedKeys.push(key)
       matchedKeys.push(key)
     }
     }
   }
   }
+
+  return matchedKeys
+}
+//身份证地址识别
+export function addressCode(address){
+  let rule=/.+?(省|市|自治区|自治州|县|区|城|旗|域|岛|院|划|街道)/g;
+  const targetValues=address.match(rule)
+  const matchedKeys = [];
+  for (const key in codeToText) {
+    const value = codeToText[key];
+    if (targetValues.includes(value)) {
+      matchedKeys.push(key)
+    }
+  }
   const cityValues = [];
   const cityValues = [];
   if(matchedKeys.length<3){
   if(matchedKeys.length<3){
     let unknown=matchedKeys[1].length==6?'true' : "false";
     let unknown=matchedKeys[1].length==6?'true' : "false";

+ 6 - 6
src/views/Letter/Letter.vue

@@ -1639,7 +1639,7 @@
 import QRCode from "qrcodejs2";
 import QRCode from "qrcodejs2";
 import Cookies from "js-cookie";
 import Cookies from "js-cookie";
 import CommonUtil from "@/utils/comutil.js";
 import CommonUtil from "@/utils/comutil.js";
-import { getAgeByIdCard, searchkey } from "@/utils/validate.js";
+import { getAgeByIdCard, searchkey,addressCode } from "@/utils/validate.js";
 import { regionData, codeToText } from "element-china-area-data";
 import { regionData, codeToText } from "element-china-area-data";
 export default {
 export default {
   inject: ["reload"],
   inject: ["reload"],
@@ -2742,6 +2742,7 @@ export default {
       import("element-ui/packages/image/src/image-viewer")
       import("element-ui/packages/image/src/image-viewer")
   },
   },
   created() {
   created() {
+    console.log(addressCode('山西省静乐县王村镇三山村71号1户'))
     this.getDicType("vehicleType");//车辆种类
     this.getDicType("vehicleType");//车辆种类
     this.getDicType("trafficManagementVehicleType");//车辆类型
     this.getDicType("trafficManagementVehicleType");//车辆类型
     this.getDicType("energyType");//能源种类
     this.getDicType("energyType");//能源种类
@@ -5141,7 +5142,7 @@ export default {
               this.ownerInfoform.identifyValidEndDate = '9999-12-31';
               this.ownerInfoform.identifyValidEndDate = '9999-12-31';
             }
             }
           }
           }
-         let values=searchkey(this.ownerInfoform.addr.match(this.regular));
+         let values=addressCode(this.ownerInfoform.addr);
           this.ownerInfoform.province=codeToText[values[0]]
           this.ownerInfoform.province=codeToText[values[0]]
           this.ownerInfoform.city=codeToText[values[1]]
           this.ownerInfoform.city=codeToText[values[1]]
           this.ownerInfoform.county=codeToText[values[2]]
           this.ownerInfoform.county=codeToText[values[2]]
@@ -5152,18 +5153,17 @@ export default {
       //传参
       //传参
       switch (this.userIndex) {
       switch (this.userIndex) {
         case 2:
         case 2:
-          this.selectedOptions1=searchkey(this.ownerInfoform.addr.match(this.regular));
-          console.log(this.ownerInfoform)
+          this.selectedOptions1=addressCode(this.ownerInfoform.addr);
           this.ownerInfo = JSON.parse(JSON.stringify(this.ownerInfoform));
           this.ownerInfo = JSON.parse(JSON.stringify(this.ownerInfoform));
           break;
           break;
         case 3:
         case 3:
-        this.selectedOptions2=searchkey(this.ownerInfoform.addr.match(this.regular));
+        this.selectedOptions2=addressCode(this.ownerInfoform.addr);
           this.policyHolderInfo = JSON.parse(
           this.policyHolderInfo = JSON.parse(
             JSON.stringify(this.ownerInfoform)
             JSON.stringify(this.ownerInfoform)
           );
           );
           break;
           break;
         case 4:
         case 4:
-        this.selectedOptions3=searchkey(this.ownerInfoform.addr.match(this.regular));
+        this.selectedOptions3=addressCode(this.ownerInfoform.addr);
           this.insuredPersonInfo = JSON.parse(
           this.insuredPersonInfo = JSON.parse(
             JSON.stringify(this.ownerInfoform)
             JSON.stringify(this.ownerInfoform)
           );
           );