Browse Source

针对新数据格式对数据统一存取操作

zhangyu 5 years ago
parent
commit
6f30b64178

+ 2 - 2
src/utils/handsontable/mainText.js

@@ -7,9 +7,9 @@ const text = {
         if (value instanceof Array && value.length > 0) {
             let i = 0
             value.map(item => {
-                if (item.type == "image" || item.type == "video") {
+                // if (item.type == "image" || item.type == "video") {
                     i++
-                }
+                // }
             })
             td.innerHTML = "已上传:" + i;
         } else {

+ 31 - 0
src/utils/scan/tools.js

@@ -494,6 +494,37 @@ tools.isObjectValueEqual = function (a, b) {//判断两个对象的可枚举属
 
 }
 
+tools.dataForKey = function (data, key) {
+    let arr = key.split(".")
+    if (arr && arr[0]) {
+      for (let i = 0; i < arr.length; i++) {
+        if (arr[i] && data[arr[i]]) {
+            data = data[arr[i]]
+        } else {
+            return ''
+        }
+      }
+      return data
+    }
+}
+
+tools.setDataForKey = function (data, key, value) {
+    let arr = key.split(".")
+    if (arr && arr[0]) {
+      for (let i = 0; i < arr.length; i++) {
+        if (!(arr[i] && data[arr[i]])) {
+            data[arr[i]] = {}
+        }
+        if (value !== undefined) {
+            if (i == arr.length - 1) {
+                data[arr[i]] = value
+            }
+        }
+        data = data[arr[i]]
+      }
+    }
+}
+
 function dateToDate(date) {
     var sDate = new Date();
     if (typeof date == 'object' && typeof new Date().getMonth == "function") {

+ 44 - 37
src/views/ledger/facility/partsmanage/addparts/index.vue

@@ -393,11 +393,11 @@ export default {
     },
     //上传文件弹窗触发事件
     fileChange(keys) {
-      this.setDataToMain(keys, this.messKey.split(".")[1], this.row);
+      this.setDataToMain(keys, this.messKey, this.row);
     },
     //上传图片弹窗触发事件
     imgChange(keys) {
-      this.setDataToMain(keys, this.messKey.split(".")[1], this.row);
+      this.setDataToMain(keys, this.messKey, this.row);
     },
     //维修商变更
     changeMaintainer(data) {
@@ -419,7 +419,7 @@ export default {
     },
     //设备图片弹窗改变事件
     changePics(keys) {
-      this.setDataToMain(keys, this.messKey.split(".")[1], this.row);
+      this.setDataToMain(keys, this.messKey, this.row);
     },
     setGraphyId(graphyId, assetGroupList) {
       this.graphyId = graphyId;
@@ -506,10 +506,9 @@ export default {
       //供应合同编号
       if (val == "LedgerParam.SupplyPurchase.SupplierContractID") {
         let falg = null;
-        if (!!this.tableData[row.row].infos) {
-          if (!!this.tableData[row.row].infos) {
-            falg = this.tableData[row.row].infos.DPSupplierID.split("-")[0];
-          }
+        let data = tools.dataForKey(this.tableData[row.row], val)
+        if (data) {
+          falg = data.split("-")[0];
         }
         if (!!falg) {
           this.id = falg;
@@ -522,10 +521,9 @@ export default {
       if (val == "LedgerParam.InsuranceDoc.InsuranceNum") {
         //选择保单
         let falg = null;
-        if (!!this.tableData[row.row].infos) {
-          if (!!this.tableData[row.row].infos) {
-            falg = this.tableData[row.row].infos.DPInsurerID.split("-")[0];
-          }
+        let data = tools.dataForKey(this.tableData[row.row], val)
+        if (data) {
+          falg = data.split("-")[0];
         }
         if (!!falg) {
           this.id = falg;
@@ -539,11 +537,13 @@ export default {
         val == "LedgerParam.InsuranceDoc.InsuranceFile" ||
         val == "LedgerParam.PhotoDoc.Archive"
       ) {
-        this.filesArr = this.tableData[row.row].infos
-          ? this.tableData[row.row].infos[val.split(".")[1]]
-            ? [this.tableData[row.row].infos[val.split(".")[1]]]
-            : []
-          : [];
+        let data = tools.dataForKey(this.tableData[row.row], val)
+        this.filesArr = data? data: []
+        // this.filesArr = this.tableData[row.row].infos
+        //   ? this.tableData[row.row].infos[val.split(".")[1]]
+        //     ? [this.tableData[row.row].infos[val.split(".")[1]]]
+        //     : []
+        //   : [];
         this.myDialog.uploadFiles = true;
       }
       //安装照片--安装图纸--设备铭牌照片--设备图纸
@@ -553,28 +553,32 @@ export default {
         val == "LedgerParam.PhotoDoc.Nameplate" ||
         val == "LedgerParam.PhotoDoc.Drawing"
       ) {
-        if (val == "LedgerParam.PhotoDoc.Nameplate") {
-          this.imgsArr = this.tableData[row.row].infos
-            ? this.tableData[row.row].infos[val.split(".")[1]]
-              ? [this.tableData[row.row].infos[val.split(".")[1]].key]
-              : []
-            : [];
-        } else {
-          this.imgsArr = this.tableData[row.row].infos
-            ? this.tableData[row.row].infos[val.split(".")[1]]
-              ? [this.tableData[row.row].infos[val.split(".")[1]]]
-              : []
-            : [];
-        }
+        let data = tools.dataForKey(this.tableData[row.row], val)
+        this.filesArr = data? data: []
+        // if (val == "LedgerParam.PhotoDoc.Nameplate") {
+        //   this.imgsArr = this.tableData[row.row].infos
+        //     ? this.tableData[row.row].infos[val.split(".")[1]]
+        //       ? [this.tableData[row.row].infos[val.split(".")[1]].key]
+        //       : []
+        //     : [];
+        // } else {
+        //   this.imgsArr = this.tableData[row.row].infos
+        //     ? this.tableData[row.row].infos[val.split(".")[1]]
+        //       ? [this.tableData[row.row].infos[val.split(".")[1]]]
+        //       : []
+        //     : [];
+        // }
         this.myDialog.uploadImgs = true;
       }
       //设备照片
       if (val == "LedgerParam.PhotoDoc.Pic") {
-        this.picsArr = this.tableData[row.row].infos
-          ? this.tableData[row.row].infos[val.split(".")[1]]
-            ? this.tableData[row.row].infos[val.split(".")[1]]
-            : []
-          : [];
+        let data = tools.dataForKey(this.tableData[row.row], val)
+        this.picsArr = data? data: []
+        // this.picsArr = this.tableData[row.row].infos
+        //   ? this.tableData[row.row].infos[val.split(".")[1]]
+        //     ? this.tableData[row.row].infos[val.split(".")[1]]
+        //     : []
+        //   : [];
         this.myDialog.pic = true;
       }
       this.row = row.row;
@@ -599,17 +603,20 @@ export default {
     },
     //判断是否有值,有值赋值
     setDataToMain(data, key, row) {
+      console.log("start+++++++++++++++++",this.tableData[row])
       if (!!data && data != "--") {
         if (!!this.tableData[row]) {
           //铭牌照片特殊处理
-          this.tableData[row][key] = data;
+          tools.setDataForKey(this.tableData[row], key, data)
+          // this.tableData[row][key] = data;
         } else {
           this.tableData[row] = {};
-          this.tableData[row][key] = data;
+          tools.setDataForKey(this.tableData[row], key, data)
         }
       } else {
-        this.tableData[row][key] = "";
+        tools.setDataForKey(this.tableData[row], key, "")
       }
+      console.log("end+++++++++++++++++",this.tableData[row])
     }
   }
 };