Ver Fonte

编辑页面选择框绑定值

XuZinan há 3 anos atrás
pai
commit
a01ee66ba4
1 ficheiros alterados com 39 adições e 6 exclusões
  1. 39 6
      pages/Project/add.vue

+ 39 - 6
pages/Project/add.vue

@@ -20,6 +20,10 @@
           @change="selectChangeType"
           :range="typeList"
           :range-key="'name'"
+          :value="
+            formData.type &&
+            typeList.findIndex((item) => item.id == formData.type.id)
+          "
         >
           <view class="select">
             {{
@@ -47,6 +51,10 @@
           @change="selectChangeIndustry"
           :range="industryList"
           :range-key="'name'"
+          :value="
+            formData.industry &&
+            typeList.findIndex((item) => item.id == formData.industry.id)
+          "
         >
           <view class="select">
             {{
@@ -68,6 +76,7 @@
           @change="selectChangeLocation"
           :range="locationList"
           :range-key="'name'"
+          :value="locationIndex"
         >
           <view class="select">
             {{
@@ -97,7 +106,11 @@
         v-show="!formData.type || (formData.type && formData.type.id != 7)"
         required
       >
-        <picker @change="selectChangeVersion" :range="versionList">
+        <picker
+          @change="selectChangeVersion"
+          :range="versionList"
+          :value="formData.version && formData.version - 1"
+        >
           <view class="select">
             {{ versionList[this.formData.version - 1] }}
           </view>
@@ -218,6 +231,7 @@ export default {
       versionList,
       provinces,
       locationList: [provinces, []],
+      locationIndex: [0, 0],
     };
   },
   computed: {
@@ -277,6 +291,22 @@ export default {
           code.location = form.location.code;
           code.name = form.name;
           code.version = form.version;
+
+          const searchLocation = (list, name) => {
+            for (let i = 0; i < list.length; ++i) {
+              if (list[i].children) {
+                let childrenIndex = searchLocation(list[i].children, name);
+                if (childrenIndex[0] != -1) return [i, childrenIndex[0]];
+              } else {
+                if (list[i].name == name) return [i, 0];
+              }
+            }
+            return [-1, -1];
+          };
+
+          this.locationIndex = searchLocation(this.provinces, current.location);
+          if (this.provinces[this.locationIndex[0]].children)
+            this.locationList[1] = this.provinces[this.locationIndex[0]].children;
         }
       }
     },
@@ -318,16 +348,19 @@ export default {
       this.binddata("version", e.target.value);
     },
     bindChangeLocationColumn(e) {
-      e.target.column == 0 &&
-        (this.locationList[1] = this.provinces[e.target.value].children || []);
+      if (e.target.column == 0) {
+        this.locationList[1] = this.provinces[e.target.value].children || [];
+        this.locationIndex = [e.target.value, 0];
+      }
     },
     selectChangeLocation(e) {
       let multiIndex = e.target.value;
+      this.locationIndex = multiIndex;
       // let location = this.formData.location;
       // let locationCode = this.formData.code.location;
-      let location = provinces[multiIndex[0]].children
-        ? provinces[multiIndex[0]].children[multiIndex[1]]
-        : provinces[multiIndex[0]];
+      let location = this.provinces[multiIndex[0]].children
+        ? this.provinces[multiIndex[0]].children[multiIndex[1]]
+        : this.provinces[multiIndex[0]];
       location.code =
         location.code.length == 4 ? location.code.substr(1) : location.code;
       this.formData.location = location;