瀏覽代碼

修改点击工料机后载入数据

olym 7 年之前
父節點
當前提交
2e11959c2a

+ 25 - 16
modules/glj/models/glj_list_model.js

@@ -91,14 +91,8 @@ class GLJListModel extends BaseModel {
 
             // 整理获取工料机ID list
             let gljIdList = [];
-            // 整理获取有组成物的项目工料机编码
-            let projectGLJCode = [];
             for(let tmp of gljData) {
                 gljIdList.push(tmp.id);
-                // 有组成物的类型才入数组
-                if (this.ownCompositionTypes.indexOf(tmp.type)) {
-                    projectGLJCode.push(tmp.code);
-                }
             }
             // 从定额工料机库中获取消耗量
             condition = {
@@ -116,9 +110,15 @@ class GLJListModel extends BaseModel {
                 } else {
                     quantityList[tmp.projectGLJID] += tmp.quantity * tmpNum;
                 }
-
             }
-
+            // 整理获取有组成物的项目工料机编码
+            let projectGLJCode = [];
+            for(let tmp of gljData) {
+                // 有组成物的类型且消耗量大于0才查找
+                if (quantityList[tmp.id] !== undefined) {
+                    projectGLJCode.push(tmp.code);
+                }
+            }
             // 查找组成物的消耗量
             let totalComposition = {};
             let mixRatioData = {};
@@ -145,8 +145,7 @@ class GLJListModel extends BaseModel {
                 }
             }
             // 组合单价数据
-            this.combineData(gljData, unitPriceList, quantityList, mixRatioData, totalComposition);
-
+            gljData = this.combineData(gljData, unitPriceList, quantityList, mixRatioData, totalComposition);
             // 排序
             gljData.sort(function (a, b) {
                 a.unit_price = a.unit_price === null ? 0 : a.unit_price;
@@ -170,7 +169,7 @@ class GLJListModel extends BaseModel {
      * @param {object} quantityList
      * @param {object} mixRatioData 组合物明细数据
      * @param {object} totalComposition 组合物父工料机统计数据
-     * @return {void}
+     * @return {Array}
      */
     combineData(gljList, unitPriceList, quantityList = {}, mixRatioData = {}, totalComposition = {}) {
         // 整理组成物消耗量(只有在总列表显示的时候才需用到,获取单项项目工料机内容则忽略)
@@ -184,8 +183,10 @@ class GLJListModel extends BaseModel {
 
             }
         }
+        let result = [];
         // 循环组合数据
-        for(let glj of gljList) {
+        for(let index in gljList) {
+            let glj = gljList[index];
             if (glj.code === undefined) {
                 continue;
             }
@@ -196,13 +197,20 @@ class GLJListModel extends BaseModel {
             }
 
             let gljId = glj.glj_id + '';
+            let projectGljId = glj.id + '';
+
             // 消耗量赋值
-            glj.quantity = quantityList[glj.id] !== undefined ? quantityList[glj.id] : 0;
+            glj.quantity = quantityList[projectGljId] !== undefined ? quantityList[projectGljId] : 0;
             glj.quantity = totalComposition[glj.code] !== undefined ? totalComposition[glj.code] : glj.quantity;
             glj.quantity = compositionConsumption[gljId] !== undefined ?  glj.quantity + compositionConsumption[gljId] : glj.quantity;
 
+            // 消耗值为0的数据不显示
+            if (glj.quantity === 0) {
+                delete gljList[index];
+                continue;
+            }
             // 组成物数据
-            glj.ratio_data = mixRatioData[gljId] !== undefined ? mixRatioData[gljId] : [];
+            gljList[index].ratio_data = mixRatioData[gljId] !== undefined ? mixRatioData[gljId] : [];
 
             // 计算调整基价
             switch (glj.unit_price.type + '') {
@@ -218,8 +226,9 @@ class GLJListModel extends BaseModel {
                 default:
                     glj.adjust_price = glj.unit_price.base_price;
             }
-
+            result.push(glj);
         }
+        return result;
     }
 
     /**
@@ -540,7 +549,7 @@ class GLJListModel extends BaseModel {
                 unitPriceData[tmp.code + tmp.name] = tmp;
             }
 
-            this.combineData(gljData, unitPriceData, [], mixRatioData);
+            gljData = this.combineData(gljData, unitPriceData, [], mixRatioData);
 
             // 排序
             gljData.sort(function (a, b) {

+ 23 - 21
web/building_saas/glj/js/project_glj.js

@@ -199,32 +199,34 @@ $(document).ready(function () {
  * @return {void|boolean}
  */
 function init() {
-    // 加载工料机数据
-    let data = projectObj.project.projectGLJ === null ? null : projectObj.project.projectGLJ.datas;
-    if (data === null) {
-        return false;
-    }
-    // 赋值
-    jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
-    mixRatioConnectData = data.mixRatioConnectData !== undefined ? data.mixRatioConnectData : mixRatioConnectData;
+    projectObj.project.projectGLJ.loadData(function(data) {
+        if (jsonData.length <= 0) {
+            // 赋值
+            jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
+            mixRatioConnectData = data.mixRatioConnectData !== undefined ? data.mixRatioConnectData : mixRatioConnectData;
+
+            host = data.constData.hostname !== undefined ? data.constData.hostname : '';
+            materialIdList = data.constData.materialIdList !== undefined ? data.constData.materialIdList : materialIdList;
+            roomId = data.constData.roomId !== undefined ? data.constData.roomId : roomId;
+            canNotChangeTypeId = data.constData.ownCompositionTypes !== undefined ?
+                data.constData.ownCompositionTypes : canNotChangeTypeId;
+            GLJTypeConst = data.constData.GLJTypeConst !== undefined ? JSON.parse(data.constData.GLJTypeConst) : GLJTypeConst;
 
-    host = data.constData.hostname !== undefined ? data.constData.hostname : '';
-    materialIdList = data.constData.materialIdList !== undefined ? data.constData.materialIdList : materialIdList;
-    roomId = data.constData.roomId !== undefined ? data.constData.roomId : roomId;
-    canNotChangeTypeId = data.constData.ownCompositionTypes !== undefined ?
-        data.constData.ownCompositionTypes : canNotChangeTypeId;
-    GLJTypeConst = data.constData.GLJTypeConst !== undefined ? JSON.parse(data.constData.GLJTypeConst) : GLJTypeConst;
+            let usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];
+            usedUnitPriceInfo = data.constData.usedUnitPriceInfo !== undefined ?
+                data.constData.usedUnitPriceInfo : {};
 
-    let usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];
-    usedUnitPriceInfo = data.constData.usedUnitPriceInfo !== undefined ?
-        data.constData.usedUnitPriceInfo : {};
+            // 连接socket服务器
+            socketInit();
 
-    // 连接socket服务器
-    socketInit();
+            unitPriceFileInit(usedUnitPriceInfo.name, usedTenderList);
 
-    unitPriceFileInit(usedUnitPriceInfo.name, usedTenderList);
+            setTimeout(spreadInit, 1);
+        } else {
+            projectObj.project.projectGLJ.loadCacheData();
+        }
 
-    setTimeout(spreadInit, 1);
+    });
 }
 
 /**

+ 1 - 1
web/building_saas/glj/js/project_glj_spread.js

@@ -106,7 +106,7 @@ ProjectGLJSpread.prototype.init = function () {
     this.sheetObj.setColumnEditable(marketPriceColumn);
     this.sheetObj.setColumnEditable(isEvaluateColumn);
     this.sheetObj.setColumnEditable(isAdjustPriceColumn);
-    this.sheetObj.setColumnEditable(11);
+    this.sheetObj.setColumnEditable(supplyColumn);
     this.sheetObj.setData(sourceData);
     // 取消正在加载字符提示
     $("#project-glj > p").hide();