zhangweicheng 6 rokov pred
rodič
commit
d16b1c1026

+ 1 - 0
modules/ration_glj/facade/ration_glj_facade.js

@@ -628,6 +628,7 @@ async function replaceGLJ(data) {
     let result = await projectGljModel.addList(getGLJSearchInfo(data));
     let typeString = result.type+'';
     data.projectGLJID = result.id;
+
     let updateResult = await ration_glj.findOneAndUpdate({ID: data.ID, projectID: data.projectID}, data);//更新定额工料机
     //组装回传数据
     data.marketPrice = result.unit_price.market_price;

+ 55 - 0
web/building_saas/main/js/models/ration_glj.js

@@ -641,6 +641,61 @@ var ration_glj = {
                 $.bootstrapLoading.end();
             });
         };
+
+        ration_glj.prototype.updateRationGLJByChangeCode = function (recode, updateField, newval) {
+            let me = this;
+            let priceMap = projectObj.project.projectGLJ.datas.unitPriceMap;
+            let priceObj = priceMap[newval];
+            if(priceObj){
+                if (recode.createType===undefined || recode.createType == 'normal') {// createTypel 默认是normal 只有是定额下带的工料机才需把类型改成替换,其它的保持不变
+                    recode.rcode = recode.code;
+                    recode.createType = 'replace';
+                }
+                recode.code = priceObj.code;
+                recode.name = priceObj.name;
+                recode.type = priceObj.type;
+                recode.unit = priceObj.unit;
+                recode.shortName = priceObj.short_name;
+                recode.specs = priceObj.specs;
+                recode.GLJID=priceObj.glj_id;
+                recode.original_code =  priceObj.original_code;
+                recode.basePrice = priceObj.base_price;
+                recode.marketPrice = priceObj.market_price;
+            }
+            $.bootstrapLoading.start();
+            CommonAjax.post("/rationGlj/replaceGLJ", recode, function (result) {
+                if (result) {
+                    //result.adjustState;
+                    var glj_list = me.datas;
+                    var data = result.data;
+                    var list_index = _.findIndex(glj_list, {'ID': data.ID});
+                    let rationNode = projectObj.project.mainTree.findNode(data.rationID);
+                    var nodes =  [rationNode];
+                    glj_list[list_index] = data;
+                    project.projectGLJ.loadData(function () {//加载完项目工料机再计算
+                        gljOprObj.refreshView();
+                        if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
+                            var node = project.ration_glj.findGLJNodeByID(data.ID);
+                            if (node) {
+                                project.ration_glj.transferToNodeData(data);
+                                node.source = data;
+                                node.data = data;
+                            }
+                            node ? nodes.push(node) : "";
+                        }
+                        rationNode.data.adjustState = result.adjustState;
+                        projectObj.mainController.refreshTreeNode(nodes);
+                        project.calcProgram.calcAndSave(rationNode);
+                        $.bootstrapLoading.end();
+                    });
+                }
+            }, function () {
+                $.bootstrapLoading.end();
+            });
+
+
+        };
+
         ration_glj.prototype.replaceGLJ = function (selectCode, oldData, callback) {
             var allGLJ = gljOprObj.AllRecode;
             var glj = _.find(allGLJ, function (item) {

+ 1 - 1
web/building_saas/main/js/views/glj_col.js

@@ -18,7 +18,7 @@ let gljCol = {
             {headerName: "暂估", headerWidth: 45, dataCode: "isEstimate", dataType: "String", hAlign: "center", vAlign: "center", cellType: "checkBox"}
         ],
         view: {
-            lockColumns: [0, 5, 7, 9, 10, 11]
+            lockColumns: [ 5, 7, 9, 10, 11]
         },
         // 工料机类型是混凝土、砂浆、配合比、机械台班时,价格不可编辑。
         editedTyep:[GLJTypeConst.MAIN_MATERIAL,GLJTypeConst.EQUIPMENT]//主材设备

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

@@ -114,6 +114,9 @@ var gljOprObj = {
         if(!projectReadOnly){
             gljContextMenu.loadGLJSpreadContextMenu();
         }
+        sheet.bind(GC.Spread.Sheets.Events.SelectionChanged,function (sender,args) {
+            args.sheet.repaint();
+        });
     },
     initDetailSheet: function (sheet) {
         var me = this;
@@ -504,36 +507,49 @@ var gljOprObj = {
         let selected = this.sheet.getSelections();
         this.combineWithProjectGlj(this.sheetData);
         this.sheet.setRowCount(0);
-        //console.log(+new Date())
-        //this.sheet.getRange(0,-1,this.sheet.getRowCount(),-1).visible(true); //这个方法导致加载缓慢
         this.sheetData = sortRationGLJ(this.sheetData);
         this.sumQuantity();//计算总消耗量
         this.addMixRatioToShow();//显示组成物信息
-        this.initRationTree(init);
+        this.initRationTree(init,this.getUnitPriceCodeMap());
         sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
         if(selected){//定位光标到之前的位置
             this.sheet.setSelection(selected[0].row,selected[0].col,selected[0].rowCount,selected[0].colCount);
         }
     },
-    initRationTree: function (init) {
-        this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType(this.sheetData));
+    getUnitPriceCodeMap : function (sheetData) {//取单价文件中,编码前缀一样的映射表
+        let codeMap = {};
+        let priceMap = projectObj.project.projectGLJ.datas.unitPriceMap;
+        if(priceMap){
+            for(let connectKey in priceMap){
+                let code = priceMap[connectKey].code;
+                if(code){
+                   let preCode = code.split("-")[0];
+                   if(codeMap[preCode]) {
+                       codeMap[preCode].push({text:code,value:connectKey});
+                   }else {
+                       codeMap[preCode]=[{text:code,value:connectKey}];
+                   }
+                }
+            }
+        }
+        return codeMap;
+    },
+
+    initRationTree: function (init,codeMap) {
+        this.sheet.suspendPaint();
+        this.sheet.suspendEvent();
+        this.sheet.setRowCount(this.sheetData.length >30?this.sheetData.length:30);
         for (var i = 0; i < this.sheetData.length; i++) {
+            this.sheet.setCellType(i, 0,this.getTreeNodeCellType(this.sheetData,i,codeMap),GC.Spread.Sheets.SheetArea.viewport);
             if (this.sheetData[i].hasOwnProperty('subList')) {
-               /* var collapsed = false;
-                if (init) {
-                    this.sheetData[i].collapsed = true;
-                    collapsed = true;
-                } else {
-                    collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
-                }*/
                 var collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
                 if (collapsed == true) {
                     this.sheet.getRange(i + 1, -1, this.sheetData[i].subList.length, -1).visible(false);
                 }
-                //this.sheet.getRange(i+1, -1, this.sheetData[i].subList.length, -1).visible(!collapsed);// this.sheet.getRange(i+1, -1, this.sheetData[i].subList.length, -1).locked(true);
-                //这个方法导致加载缓慢
             }
         }
+        this.sheet.resumeEvent();
+        this.sheet.resumePaint();
     },
     filterGljByRation: function (ration, datas) {
         var gljList = [];
@@ -752,6 +768,12 @@ var gljOprObj = {
                     return;
                 }
             }
+            if(updateField == 'code'){
+                if (!gljUtil.isDef(args.editingText)||args.editingText==''||args.editingText.indexOf('|-|') === -1||this.isRationGLJExit(args.editingText)) {//说明是选中自已,或者是已存在的工料机
+                    me.sheet.getCell(args.row, args.col).value(recode[updateField]);
+                    return;
+                }
+            }
             newval = args.editingText == null ? "" : args.editingText;
         }
         if (newval === recode[updateField]) {//如果值完全相等,则不需要更新
@@ -759,10 +781,23 @@ var gljOprObj = {
         }
         if (updateField == 'marketPrice' || updateField == 'basePrice') {
             projectObj.project.projectGLJ.updatePriceFromRG(recode, updateField, newval);
+        }else if(updateField == 'code'){//替换单价文件中已经有的工料机
+            projectObj.project.ration_glj.updateRationGLJByChangeCode(recode, updateField, newval);
         } else {
             projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
         }
     },
+    isRationGLJExit:function (connectKey) {
+        for(let rg of gljOprObj.sheetData){
+            if(rg.isMixRatio == true){
+                continue;
+            }
+            if(gljOprObj.getIndex(rg, gljKeyArray) == connectKey){//存在一样的工料机
+                return true;
+            }
+        }
+       return false;
+    },
     updateRationTypeGLJ: function (value, node, fieldName,editingText) {
         let newval;
         let updatePrice = false;
@@ -965,9 +1000,12 @@ var gljOprObj = {
         var project = projectObj.project;
         gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
             var rg = _.find(gljOprObj.sheetData, function (item) {
+                if(item.isMixRatio == true){
+                    return false;
+                }
                 var i_key = gljOprObj.getIndex(item, gljKeyArray);
                 return n == i_key
-            })
+            });
             return rg ? false : true;
         })
         if (gljOprObj.GLJSelection.length > 0 && selected && selected.sourceType == ModuleNames.ration) {
@@ -1121,7 +1159,7 @@ var gljOprObj = {
         }
         return node;
     },
-    getTreeNodeCellType: function (data) {
+    getTreeNodeCellType: function (data,index,codeMap) {
         var ns = GC.Spread.Sheets;
         var rectW = 10;
         var rectH = 10;
@@ -1183,7 +1221,7 @@ var gljOprObj = {
             return offset;
         }
 
-        TreeNodeCellType.prototype = new ns.CellTypes.Text();
+        TreeNodeCellType.prototype =  data[index]&&data[index].isMixRatio?new ns.CellTypes.Text(): sheetCommonObj.getDynamicCombo();//new ns.CellTypes.Text();
         TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
             if (value != null) {
                 var offset = margin + rectW + 6;
@@ -1203,17 +1241,21 @@ var gljOprObj = {
                 GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
             }
         };
-        // override getHitInfo to allow cell type get mouse messages
         TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
-            return {
-                x: x,
-                y: y,
-                row: context.row,
-                col: context.col,
-                cellStyle: cellStyle,
-                cellRect: cellRect,
-                sheetArea: context.sheetArea
-            };
+            if(x < cellRect.x+cellRect.width -15){
+                return {
+                    x: x,
+                    y: y,
+                    row: context.row,
+                    col: context.col,
+                    cellStyle: cellStyle,
+                    cellRect: cellRect,
+                    sheetArea: context.sheetArea
+                };
+            }else {
+                return GC.Spread.Sheets.CellTypes.ComboBox.prototype.getHitInfo.apply(this, arguments);
+            }
+
         };
         TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
             var recode = data[hitinfo.row];
@@ -1227,10 +1269,26 @@ var gljOprObj = {
                     hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
                     hitinfo.sheet.invalidateLayout();
                     hitinfo.sheet.repaint();
+                    return;
                 }
             }
+            GC.Spread.Sheets.CellTypes.ComboBox.prototype.processMouseDown.apply(this, arguments);
+           // GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
         };
-        return new TreeNodeCellType()
+        let cellType = new TreeNodeCellType();
+        let options = [];
+        if(!(data[index]&&data[index].isMixRatio)){
+            let code = data[index].code;
+            if(code) {
+                let preCode = code.split("-")[0];
+                if( codeMap[preCode]) options = codeMap[preCode];
+                if(options.length>0) _.remove(options,{'value':gljOprObj.getIndex(data[index], gljKeyArray)})//去掉本身
+
+            }
+            cellType.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
+            cellType.itemHeight(options.length).items(options);
+        }
+        return cellType;
     },
     marketPriceReadOnly: function (node) {
         let hasCom = false;