Browse Source

省市选择bug修改

zhuxinbo 5 years ago
parent
commit
2359df9a1b
1 changed files with 31 additions and 6 deletions
  1. 31 6
      src/views/template/userorientation/modules/transferCity.vue

+ 31 - 6
src/views/template/userorientation/modules/transferCity.vue

@@ -241,17 +241,41 @@ export default {
       this.$emit('update:checkData', this.checkData)
     },
     checkOne(item, index) {
+      if (this.checkMatched.length == this.province.length) {
+        this.checkAll = true
+      } else {
+        this.checkAll = false
+      }
       if (this.checkMatched.indexOf(item.value) == -1) {
-        var index = this.checkData.findIndex(v => v.value === item.value)
-        this.checkData.splice(index, 1)
+        var index1 = this.checkData.findIndex(v => v.value === item.value)
+        var index2 = this.checkMatched.findIndex(v => v === item.value)
+        this.checkData.splice(index1, 1)
+        this.checkMatched.splice(index2, 1)
         if (this.nowProvince) {
           if (this.nowProvince.value == item.value) {
             this.checkMatchedCity = []
           }
         }
-        this.checkAll = false
       } else {
         this.checkData.push(item)
+        var data = []
+        getProvince(this.CityData, { parentCode: item.value }).then(res => {
+          if (res.code == '0') {
+            data = res.result.records.map(item => {
+              return {
+                label: item.name,
+                value: item.id
+              }
+            })
+            for (var i = 0; i < this.checkData.length; i++) {
+              for (let j = 0; j < data.length; j++) {
+                if (this.checkData[i].value == data[j].value) {
+                  this.checkData.splice(i, 1)
+                }
+              }
+            }
+          }
+        })
         if (this.nowProvince) {
           if (item.value == this.nowProvince.value) {
             this.checkMatchedCity = this.city.map(item => {
@@ -260,9 +284,7 @@ export default {
           }
         }
       }
-      if (this.checkData.length == this.province.length) {
-        this.checkAll = true
-      }
+
       this.$emit('update:checkData', this.checkData)
     },
     checkAllBoxCity() {
@@ -306,17 +328,20 @@ export default {
         if (allCity.length != this.city.length) {
           this.checkData.push(item)
         }
+        this.checkAll = true
       } else {
         if (this.checkMatched.indexOf(this.nowProvince.value) != -1) {
           var index1 = this.checkData.findIndex(v => v.value === this.nowProvince.value)
           var index2 = this.checkMatched.findIndex(v => v === this.nowProvince.value)
           this.checkData.splice(index1, 1)
           this.checkMatched.splice(index2, 1)
+          this.checkAll = false
           var data = this.city.filter(v => {
             return v.value != item.value
           })
           this.checkData.push(...data)
         } else {
+          this.checkAll = true
           var index1 = this.checkData.findIndex(v => v.value === item.value)
           this.checkData.splice(index1, 1)
         }