Преглед изворни кода

人材机选择页面,搜索分页

zhongzewei пре 6 година
родитељ
комит
4d17a98303
2 измењених фајлова са 57 додато и 29 уклоњено
  1. 29 13
      web/building_saas/main/js/models/ration_glj.js
  2. 28 16
      web/building_saas/main/js/views/glj_view.js

+ 29 - 13
web/building_saas/main/js/models/ration_glj.js

@@ -499,16 +499,17 @@ let ration_glj = {
         };
         ration_glj.prototype.getGLJDataPaging = function (condition, cb) {
             gljOprObj.loadingPagination = true;
-            let property = projectObj.project.projectInfo.property;
-            let engineerID = property.engineering_id;
+            const property = projectObj.project.projectInfo.property;
+            const engineerID = property.engineering_id;
             CommonAjax.post('/rationGlj/getGLJDataPaging', {engineerID, condition}, function (data) {
                 gljOprObj.curPageTotal = data.total;
                 data.complementaryGLJs.forEach(glj => {
                     glj.isComplementary = true;
                 });
-                let gljType = condition.type === gljOprObj.pagingType.stdGLJ
+                const gljType = condition.type === gljOprObj.pagingType.stdGLJ
                     ? 'stdGLJ'
                     : 'complementaryGLJs';
+                const newData = data[gljType];
                 if (condition.init) {
                     gljOprObj.treeData = data.treeData;
                     gljOprObj.distTypeTree = gljOprObj.getComboData(data.distTypeTree);
@@ -516,19 +517,26 @@ let ration_glj = {
                     gljOprObj.complementaryGLJs = data.complementaryGLJs;
                     gljOprObj.AllRecode = [...gljOprObj.stdGLJ, ...gljOprObj.complementaryGLJs];*/
                 }
+                // 获取的数据从0开始,说明需要重置当前页面数据(点击了分类树、搜索等等)
                 if (condition.index === 0) {
                     gljOprObj.stdGLJ = data.stdGLJ;
                     gljOprObj.complementaryGLJs = data.complementaryGLJs;
                     gljOprObj.AllRecode = [...gljOprObj.stdGLJ, ...gljOprObj.complementaryGLJs];
                     gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
                 } else {
-                    gljOprObj[gljType].splice(condition.index, 0, ...data[gljType]);
-                    gljOprObj.AllRecode.splice(condition.index, 0, ...data[gljType]);
+                    gljOprObj[gljType].splice(condition.index, 0, ...newData);
+                    gljOprObj.AllRecode.splice(condition.index, 0, ...newData);
                 }
-                let tReg = /^[+\d]{1,}(?:\.{0}\d{2}|\d+)/
-                console.log(gljOprObj.AllRecode);
+                // 根据缓存选中数据,设置人材机是否选中
+                newData.forEach(item => {
+                    const connectKey = gljOprObj.getIndex(item, gljLibKeyArray);
+                    const cacheItem = gljOprObj.selectedList.find(selItem => selItem.connectKey === connectKey);
+                    if (cacheItem) {
+                        item.select = 1;
+                    }
+                });
                 // 设置人材机类型名称
-                gljOprObj.setTypeName(gljOprObj.distTypeTree.comboDatas, data[gljType]);
+                gljOprObj.setTypeName(gljOprObj.distTypeTree.comboDatas, newData);
                 if (data.priceProperties && data.priceProperties.length > 0) {
                     let tmp = _.find(data.priceProperties, {region: property.region, taxModel: parseInt(property.taxType)});
                     if (tmp) {
@@ -712,19 +720,27 @@ let ration_glj = {
 
 
         ration_glj.prototype.addGLJByLib = function (GLJSelection, ration, callback) {
-            let me=this,gljList = [];
-            let allGLJ = gljOprObj.AllRecode;
+            const me = this,
+                  gljList = [],
+                  allGLJ = gljOprObj.selectedList;
             GLJSelection.sort();
-            _.forEach(GLJSelection, function (g) {
+            GLJSelection.forEach(selKey => {
+                const glj = allGLJ.find(item => item.connectKey === selKey);
+                if (glj) {
+                    const rationGLJ = me.getAddDataByStd(glj, ration.ID, ration.billsItemID, ration.projectID);
+                    gljList.push(rationGLJ);
+                }
+            });
+            /*_.forEach(GLJSelection, function (g) {
                 let glj = _.find(allGLJ, function (item) {
                     let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
                     return i_key == g;
                 });
                 let ration_glj = me.getAddDataByStd(glj,ration.ID,ration.billsItemID,ration.projectID);
                 gljList.push(ration_glj);
-            });
+            });*/
             $.bootstrapLoading.start();
-            CommonAjax.post("/rationGlj/addGLJ", gljList, callback, function () {
+            CommonAjax.post('/rationGlj/addGLJ', gljList, callback, function () {
                 $.bootstrapLoading.end();
             });
         };

+ 28 - 16
web/building_saas/main/js/views/glj_view.js

@@ -14,6 +14,17 @@ var gljOprObj = {
     detailSheet: null,
     detailData: [],
     GLJSelection: [],
+    // 由于分页需求,重新点击分类树等,会重新获取数据,因此需要一个缓存,来解决一次性添加多个分类树人材机的问题
+    // 人材机选择页面,当前选中人材机的缓存
+    selectedList: [],
+    pagingType: {
+        stdGLJ: 1,
+        complementaryGLJs: 2
+    },
+    // 是否正在分页
+    loadingPagination: false,
+    // 当前筛选条件下总数据数,用于判断是否需要继续分页
+    curPageTotal: 0,
     selectedGLJClass: null,
     parentNodeIds: {},
     preActiveTab: '', //提升焦点变换性能 2019年4月12日
@@ -102,13 +113,6 @@ var gljOprObj = {
         }
     },
     gljLibSheet: null,
-    pagingType: {
-        stdGLJ: 1,
-        complementaryGLJs: 2
-    },
-    loadingPagination: false,
-    // 当前筛选数据下总数据数
-    curPageTotal: 0,
     scopeSetting:{},
     scopeSpread:null,
     scopeSheet:null,
@@ -1106,14 +1110,17 @@ var gljOprObj = {
         }
     },
     addGLJsSelection: function (args, newVal) {
-        var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
+        const curGLJ = this.gljLibSheetData[args.row];
+        const con_key = this.getIndex(curGLJ, gljLibKeyArray);
+        curGLJ.connectKey = con_key;
         if (newVal == 1) {
             this.GLJSelection.push(con_key);
-            console.log(this.gljLibSheetData);
-            this.gljLibSheetData[args.row].select = 1;
+            this.selectedList.push(curGLJ);
+            //curGLJ.select = 1;
         } else if (newVal == 0) {
             _.pull(this.GLJSelection, con_key);
-            this.gljLibSheetData[args.row].select = 0;
+            _.remove(this.selectedList, glj => glj.connectKey === con_key);
+            //curGLJ.select = 0;
         }
     },
     replaceGLJSelection: function (args, newVal) {
@@ -1582,6 +1589,10 @@ var gljOprObj = {
 }
 
 $(function () {
+    $('#glj_tree_div').on('hidden.bs.modal', function () {
+        // 清除选中人材机缓存数据
+        gljOprObj.selectedList = [];
+    });
     $('#glj_tree_div').on('shown.bs.modal', function (e) {
         if (gljOprObj.gljLibSpresd == undefined) {
             gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
@@ -1686,11 +1697,12 @@ $(function () {
             return false;
         }
     });*/
-    $('#gljSearchKeyword').bind('keyup', function (e) {
-        gljOprObj.filterLibGLJSheetData();
-        gljOprObj.showLibGLJSheetData();
-        gljOprObj.initSelection({row: 0});
-    });
+    $('#gljSearchKeyword').bind('keyup', _.debounce(function() {
+        gljOprObj.loadPageData(gljOprObj.gljLibSheet, 0);
+        /*gljOprObj.filterLibGLJSheetData();
+         gljOprObj.showLibGLJSheetData();
+         gljOprObj.initSelection({row: 0});*/
+    }, 500));
 
     $('#glj_selected_conf').click(function () {
         if (gljOprObj.GLJSelection.length < 1) {