ソースを参照

省市区优化

@dongkboy 3 年 前
親
コミット
af42f02111
2 ファイル変更、20 行追加、7 行削除
  1. 15 1
      src/utils/validate.js
  2. 5 6
      src/views/Letter/Letter.vue

+ 15 - 1
src/utils/validate.js

@@ -157,8 +157,22 @@ export function searchkey(cityName){
       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 = [];
-  if(matchedKeys.length<3){
+  if(matchedKeys.length<3 && matchedKeys.length!=0){
     let unknown=matchedKeys[1].length==6?'true' : "false";
     if(unknown){
       let city=matchedKeys[1].substring(0,4)

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

@@ -1639,7 +1639,7 @@
 import QRCode from "qrcodejs2";
 import Cookies from "js-cookie";
 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";
 export default {
   inject: ["reload"],
@@ -5141,7 +5141,7 @@ export default {
               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.city=codeToText[values[1]]
           this.ownerInfoform.county=codeToText[values[2]]
@@ -5152,18 +5152,17 @@ export default {
       //传参
       switch (this.userIndex) {
         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));
           break;
         case 3:
-        this.selectedOptions2=searchkey(this.ownerInfoform.addr.match(this.regular));
+        this.selectedOptions2=addressCode(this.ownerInfoform.addr);
           this.policyHolderInfo = JSON.parse(
             JSON.stringify(this.ownerInfoform)
           );
           break;
         case 4:
-        this.selectedOptions3=searchkey(this.ownerInfoform.addr.match(this.regular));
+        this.selectedOptions3=addressCode(this.ownerInfoform.addr);
           this.insuredPersonInfo = JSON.parse(
             JSON.stringify(this.ownerInfoform)
           );