浏览代码

定额下附注条件增删改操作改了好多Bug。

Chenshilong 8 年之前
父节点
当前提交
24a4edae5f

+ 2 - 0
modules/ration_repository/controllers/coe_controller.js

@@ -21,7 +21,9 @@ module.exports ={
     },
 
     getCoeItemsByIDs: function(req,res){
+        console.log('传入: '+JSON.stringify(JSON.parse(req.body.data)));
         coeList.getCoeItemsByIDs(JSON.parse(req.body.data), function(err,data){
+            console.log('返回: '+JSON.stringify(data));
             callback(req, res, err, 'Get coe', data);
         });
     }

+ 21 - 22
web/maintain/ration_repository/dinge.html

@@ -77,31 +77,24 @@
                                   <!-- 标签 -->
                                   <ul class="nav nav-tabs" role="tablist">
                                       <li class="nav-item">
-                                          <a class="nav-link active" id="linkGLJ" data-toggle="tab" href="#bglj" role="tab">工料机</a>
+                                          <a class="nav-link active" id="linkGLJ" data-toggle="tab" href="#rDetail" role="tab">工料机</a>
                                       </li>
                                       <li class="nav-item">
-                                          <a class="nav-link" data-toggle="tab" href="#bfzd" role="tab">辅助定额调整</a>
+                                          <a class="nav-link" id="linkFZDE" data-toggle="tab" href="#rDetail" role="tab">辅助定额调整</a>
                                       </li>
                                       <li class="nav-item">
-                                          <a class="nav-link" id="linkFZTJ" data-toggle="tab" href="#bfzt" role="tab">附注条件调整</a>
+                                          <a class="nav-link" id="linkFZTJ" data-toggle="tab" href="#rDetail" role="tab">附注条件调整</a>
                                       </li>
                                       <li class="nav-item">
-                                          <a class="nav-link" data-toggle="tab" href="#baz" role="tab">安装增加费</a>
-                                      </li>
-                                      <li class="nav-item">
-                                          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button id="btnGLJ">工料机</button>
-                                      </li>
-                                      <li class="nav-item">
-                                          &nbsp;<button id="btnFZTJ">附注条件</button>
+                                          <a class="nav-link" id="linkAZZJ" data-toggle="tab" href="#rDetail" role="tab">安装增加费</a>
                                       </li>
                                   </ul>
                                   <!-- 内容 -->
                                   <div class="tab-content">
-                                      <!--工料机-->
-                                      <div class="tab-pane active" id="bglj" role="tabpanel">
-                                          <div id="rationGLJSheet" class="main-data-bottom"></div>
+                                      <div class="tab-pane active" id="rDetail" role="tabpanel">
+                                          <div id="rdSpread" class="main-data-bottom"></div>
                                       </div>
-                                      <!--辅助定额调整-->
+<!--                                      &lt;!&ndash;辅助定额调整&ndash;&gt;
                                       <div class="tab-pane" id="bfzd" role="tabpanel">
                                           <div class="main-data-bottom">
                                               <table class="table table-sm table-bordered m-0">
@@ -124,11 +117,11 @@
                                               </table>
                                           </div>
                                       </div>
-                                      <!--附注条件调整-->
+                                      &lt;!&ndash;附注条件调整&ndash;&gt;
 
                                       <div class="tab-pane" id="bfzt" role="tabpanel">
                                           <div id="rationCoeSpread" class="main-data-bottom"></div>
-                                          <!--<div class="main-data-bottom">
+                                          &lt;!&ndash;<div class="main-data-bottom">
                                               <table class="table table-sm table-bordered m-0">
                                                   <thead><tr><th width="30"></th><th width="40">编号</th><th width="120">本分项全部适用</th><th>调整顺序</th><th>名称</th><th>内容</th></tr></thead>
                                                   <tbody>
@@ -146,14 +139,14 @@
                                                   </tr>
                                                   </tbody>
                                               </table>
-                                          </div>-->
+                                          </div>&ndash;&gt;
                                       </div>
-                                      <!--安装增加费-->
+                                      &lt;!&ndash;安装增加费&ndash;&gt;
                                       <div class="tab-pane" id="baz" role="tabpanel">
                                           <div class="main-data-bottom">
                                               安装增加费
                                           </div>
-                                      </div>
+                                      </div>-->
 
                                   </div>
                               </div>
@@ -565,19 +558,25 @@
                 sheetCommonObj.shieldAllCells(rationOprObj.workBook.getSheet(0), rationOprObj.setting);
 
                // tabPanel 下有多个Spread时,相互之间不能正确显示。改成一个Spread下多个Sheet。
-                var rdSpread = sheetCommonObj.createSpread($("#rationGLJSheet")[0], 3);
+                var rdSpread = sheetCommonObj.createSpread($("#rdSpread")[0], 3);
                 rationGLJOprObj.buildSheet(rdSpread.getSheet(0));
                 sheetCommonObj.shieldAllCells(rdSpread.getSheet(0), rationGLJOprObj.setting);
                 rationCoeOprObj.buildSheet(rdSpread.getSheet(1));
                 sheetCommonObj.shieldAllCells(rdSpread.getSheet(1), rationCoeOprObj.setting);
 
-                $("#btnGLJ").click(function(){
+                $("#linkGLJ").click(function(){
                     rdSpread.setActiveSheetIndex(0);
                 });
 
-                $("#btnFZTJ").click(function(){
+                $("#linkFZDE").click(function(){
+                    rdSpread.setActiveSheetIndex(2);
+                    rdSpread.getSheet(2).setText(0,0,"开发中...");
+                });
+
+                $("#linkFZTJ").click(function(){
                     rdSpread.setActiveSheetIndex(1);
                 });
+
             });
         </script>
     </div>

+ 0 - 1
web/maintain/ration_repository/js/ration.js

@@ -59,7 +59,6 @@ var rationOprObj = {
             sheetCommonObj.shieldAllCells(sheetCoe);
             var cacheSection = me.getCache();
             if (cacheSection && args.row < cacheSection.length) {
-                //alert('0001'+JSON.stringify(cacheSection[args.row]));
                 rationGLJOprObj.getGljItems(cacheSection[args.row]);
                 rationCoeOprObj.getCoeItems(cacheSection[args.row]);
             }

+ 107 - 99
web/maintain/ration_repository/js/ration_coe.js

@@ -3,12 +3,12 @@
  */
 var rationCoeOprObj = {
     sheet: null,
-    libID: -1,
-    currentRationItem: null,
+    libID: null,
+    curRation: null,
     cache: {},
     setting: {
         header:[
-            {headerName:"编",headerWidth:120,dataCode:"ID", dataType: "Number"},
+            {headerName:"编",headerWidth:120,dataCode:"ID", dataType: "Number"},
             {headerName:"名称",headerWidth:400,dataCode:"name", dataType: "String"},
             {headerName:"内容",headerWidth:300,dataCode:"content", dataType: "String"}
         ],
@@ -20,9 +20,9 @@ var rationCoeOprObj = {
     buildSheet: function(sheet) {
         var me = this;
         me.sheet = sheet;
-        //alert('0020 libID:' + JSON.stringify(me.libID));
-        me.libID = storageUtil.getSessionCache("RationGrp","repositoryID");
-        //alert('0021 libID:' + JSON.stringify(me.libID));
+        me.libID = storageUtil.getSessionCache("RationGrp","repositoryID"); // 不可靠,有时取不到
+        if (me.libID == undefined){me.libID = getQueryString('repository')};
+        //alert('0000 初始化libID: ' + JSON.stringify(me.libID));
         sheetCommonObj.initSheet(me.sheet, me.setting, 30);
         me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
         me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
@@ -33,63 +33,68 @@ var rationCoeOprObj = {
         if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
             var me = rationCoeOprObj, updateArr = [], removeArr = [];
             if (args.col == 0) {
-                if (me.cache["_Coe_" + me.currentRationItem.ID]) {
-                    var cacheArr = me.cache["_Coe_" + me.currentRationItem.ID];
+                var curCache = me.cache["_Coe_" + me.curRation.ID];
+                if (curCache) {
                     for (var i = args.rowCount - 1; i >= 0; i--) {
-                        if (args.row + i < cacheArr.length) {
-                            cacheArr.splice(args.row + i, 1);
-                        }
-                    }
-                    me.updateRationItem();
+                        if (args.row + i < curCache.length) {
+                            curCache.splice(args.row + i, 1);
+                        };
+                    };
+                    me.updateCurRation();
                     sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
-                    me.showCoeItems(me.currentRationItem.ID);
-                }
-            }
-
-        }
+                    me.showCoeItems(me.curRation.ID);
+                };
+            };
+        };
     },
-/*    onClipboardPasting: function(sender, args) {
+
+    onClipboardPasting: function(sender, args) {
         var me = rationCoeOprObj;
-        if (args.cellRange.colCount != 1 || args.cellRange.col != 0 || !(me.currentRationItem)) {
+        if (args.cellRange.colCount != 1 || args.cellRange.col != 0 || !(me.curRation)) {
             args.cancel = true;
         }
     },
+
     onClipboardPasted: function(e, info) {
         var me = rationCoeOprObj;
         if (me.libID) {
+            // 修改第一列(编号)
             if (info.cellRange.col == 0) {
-                var tmpCoeIDs = sheetCommonObj.analyzePasteData({header:[{dataCode: "ID"}] }, info);
-                var IDs = [];
-                for (var i = 0; i < tmpCoeIDs.length; i++) {
-                    IDs.push(tmpCoeIDs[i]);
-                }
-                me.addCoeItems(IDs);
+                var coeIDs = [];
+                var temp = sheetCommonObj.analyzePasteData({header:[{dataCode: "ID"}] }, info);
+                for (let obj of temp) {
+                    coeIDs.push(obj.ID);
+                };
+                //alert('0009 ' + JSON.stringify(IDs));
+                me.addCoeItems(coeIDs);
             } else {
                 //修改用量
             }
         }
-    },*/
+    },
     onCellEditEnd: function(sender, args){
         var me = rationCoeOprObj;
         if (args.col == 0) {   // 编号列
-            if (args.editingText == null || args.editingText.trim() == "") {  //delete
-                var cacheArr = me.cache["_Coe_" + me.currentRationItem.ID];
-                if (cacheArr) {
-                    if (args.row < cacheArr.length) {
-                        cacheArr.splice(args.row, 1);
-                        me.updateRationItem();
+            //delete
+            if (args.editingText == null || args.editingText.trim() == "") {
+                var curCache = me.cache["_Coe_" + me.curRation.ID];
+                if (curCache) {
+                    if (args.row < curCache.length) {
+                        curCache.splice(args.row, 1);
+                        me.updateCurRation();
                         sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
-                        me.showCoeItems(me.currentRationItem.ID);
+                        me.showCoeItems(me.curRation.ID);
                     }
                 }
             } else {
                 if (me.libID) {
-                    var coeIDs = [];
-                    coeIDs.push(args.editingText.trim());
-                    me.addCoeItems(coeIDs, me.libID);
-                }
-            }
-        }
+                    var ID = args.editingText.trim();
+                    if (!isNaN(ID)) {
+                        me.addCoeItems([ID]);
+                    };
+                };
+            };
+        };
     },
 
     addCoeItems: function(coeIDs) {
@@ -105,36 +110,38 @@ var rationCoeOprObj = {
                 sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
                 if (result) {
                     var rstArr = [], newAddArr = [];
-                    for (var i = 0; i < result.data.length; i++) {
-                        rstArr.push(result.data[i]);
-                    };
-                    if (me.cache["_Coe_" + me.currentRationItem.ID]) {
-                        var cacheArr = me.cache["_Coe_" + me.currentRationItem.ID];
+                    for (let obj of result.data){rstArr.push(obj)};
+
+                    var curCache = me.cache["_Coe_" + me.curRation.ID];
+                    if (curCache) {
                         for (var i = 0; i < rstArr.length; i++) {
                             var hasDup = false;
-                            for (var j = 0; j < cacheArr.length; j++) {
-                                if (cacheArr[j] == rstArr[i]) {
+                            for (let obj of curCache) {
+                                if (obj.ID == rstArr[i].ID) {
                                     hasDup = true;
                                     break;
                                 }
-                            }
+                            };
                             if (!hasDup) {
                                 newAddArr.push(rstArr[i]);
-                            }
-                        }
-                        cacheArr.sort(function(a, b) {
+                            };
+                        };
+                        curCache.sort(function(a, b) {
                             var rst = 0;
                             if (a > b) rst = 1
                             else if (a < b) rst = -1;
                             return rst;
                         });
-                        me.cache["_Coe_" + me.currentRationItem.ID] = cacheArr.concat(newAddArr);
-                    }
-                    me.showCoeItems(me.currentRationItem.ID);
-                    if (newAddArr.length > 0) {
-                        me.updateRationItem();
-                    }
-                }
+                        me.cache["_Coe_" + me.curRation.ID] = curCache.concat(newAddArr);
+                        if (newAddArr.length > 0) {
+                            me.updateCurRation();
+                        };
+                    }else{
+                        me.cache["_Coe_" + me.curRation.ID] = rstArr;
+                        me.updateCurRation();
+                    };
+                    me.showCoeItems(me.curRation.ID);
+                };
                 sheetCommonObj.lockCells(me.sheet, me.setting);
             },
             error:function(err){
@@ -143,73 +150,74 @@ var rationCoeOprObj = {
         })
     },
 
-    updateRationItem: function() {
+    updateCurRation: function() {
         var me = this, updateArr = [];
-        if (me.currentRationItem) {
-            me.currentRationItem.rationCoeList = me.getCoeIDsArr();
-            updateArr.push(me.currentRationItem);
-            rationOprObj.mixUpdateRequest(updateArr, [], []);
-        }
+        if (me.curRation) {
+            var rst = [];
+            var curCache = me.cache["_Coe_" + me.curRation.ID];
+            if (curCache) {
+                for (let obj of curCache) {
+                    rst.push(obj.ID);
+                };
+                me.curRation.rationCoeList = rst;
+                updateArr.push(me.curRation);
+                rationOprObj.mixUpdateRequest(updateArr, [], []);
+            };
+        };
     },
 
-    getCoeIDsArr: function(){
-        var me = this, rst = [];
-        if (me.currentRationItem && me.cache["_Coe_" + me.currentRationItem.ID]) {
-            var cacheArr = me.cache["_Coe_" + me.currentRationItem.ID];
-            for (var i = 0; i < cacheArr.length; i++) {
-                rst.push(cacheArr[i].ID);
-            }
-        }
-        return rst;
-    },
+    getCoeItems: function(ration) {
+        var me = this;
+        me.curRation = ration;
+
+        if (ration == undefined || ration.rationCoeList == undefined ||
+            ration.rationCoeList.length == 0){return;};
 
-    getCoeItems: function(rationItem) {
-        var me = this, rationID = rationItem.ID, rationCoeList = rationItem.rationCoeList;
-        if (rationCoeList == undefined){return;};
+        var coeList = ration.rationCoeList;
+        var curCache = me.cache["_Coe_" + ration.ID];
 
-        me.currentRationItem = rationItem;
-        //alert('0009 ' + JSON.stringify(me.cache));
-        //alert('0010 ' + JSON.stringify(me.cache["_Coe_" + rationID]));
-        //alert('0011 ' + JSON.stringify(me.libID));
-        if (me.cache["_Coe_" + rationID]) {
-            me.showCoeItems(rationID);
+        //alert('0001 缓存:' + JSON.stringify(curCache));
+        if (curCache && curCache.length > 0) {
+            me.showCoeItems(ration.ID);
             sheetCommonObj.lockCells(me.sheet, me.setting);
         } else {
+            var data = {"libID": me.libID, "coeIDs": coeList};
+            //alert('0002 进入后台:' + JSON.stringify(data));
             $.ajax({
                 type:"POST",
                 url:"api/getCoeItemsByIDs",
-                data: {"data": JSON.stringify({"libID": me.libID, "coeIDs": rationCoeList})},
+                data: {"data": JSON.stringify(data)},
                 dataType:"json",
                 cache:false,
                 timeout:5000,
                 success:function(result){
                     sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
-
+                    //alert('0003 后台结果:' + JSON.stringify(result.data));
                     if (result.data) {
-                        var cacheArr = [];
-                        for (var i = 0; i < result.data.length; i++) {
-                            for (var j = 0; j < rationCoeList.length; j++) {
-                                if (rationCoeList[j] == result.data[i].ID) {
-                                    cacheArr.push(result.data[i]);
-                                    break;
-                                }
-                            }
+                        var tempResult = [];
+                        for (let obj of result.data) {
+                            tempResult.push(obj);
                         };
-                        me.cache["_Coe_" + rationID] = cacheArr;
-                        me.showCoeItems(rationID);
+
+                        me.cache["_Coe_" + ration.ID] = tempResult;
+
+                        me.showCoeItems(ration.ID);
                     }
                     sheetCommonObj.lockCells(me.sheet, me.setting);
                 },
                 error:function(err){
                     alert(err);
                 }
-            })
-        }
+            });
+        };
     },
+
     showCoeItems: function(rationID) {
         var me = this;
-        if (me.cache["_Coe_" + rationID]) {
-            sheetCommonObj.showData(me.sheet, me.setting, me.cache["_Coe_" + rationID]);
+        var curCache = me.cache["_Coe_" + rationID];
+        if (curCache) {
+            sheetCommonObj.showData(me.sheet, me.setting, curCache);
         }
+        rationOprObj.workBook.focus(true);
     }
 }