Procházet zdrojové kódy

Merge branch 'master' of http://smartcost.f3322.net:3000/SmartCost/ConstructionOperation

TonyKang před 7 roky
rodič
revize
a58f0a8a3e

+ 84 - 0
modules/ration_repository/models/ration_item.js

@@ -488,6 +488,79 @@ rationItemDAO.prototype.updateAnnotation = function (lastOpr, repId, updateArr,
     });
 };
 
+//计算导入数据的价格
+rationItemDAO.prototype.calcForRation = function (stdGljList, ration) {
+    //根据工料机类型划分价格
+    const labour = [1],  material = [201, 202, 203, 204, 205, 206], machine = [301, 302, 303];
+    let labourPrc = [], materialPrc = [], machinePrc = [], singlePrc, updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, basePrice: 0};
+    let rationGljList = ration.rationGljList;
+    for(let rationGlj of rationGljList){
+        let glj = stdGljList[rationGlj.gljId];
+        let prcType = isDef(glj) ? getParentType(glj.gljType) : null;
+        if(isDef(prcType)){
+            singlePrc = scMathUtil.roundTo(parseFloat(glj.basePrice) * parseFloat(rationGlj.consumeAmt), -3);
+            if(prcType === 'labour'){
+                labourPrc.push(singlePrc);
+            }
+            else if(prcType === 'material'){
+                materialPrc.push(singlePrc);
+            }
+            else if(prcType === 'machine'){
+                machinePrc.push(singlePrc);
+            }
+        }
+    }
+    //计算人工费
+    if(labourPrc.length > 0){
+        let sumLaP = 0;
+        for(let i = 0, len  = labourPrc.length; i < len; i++){
+            sumLaP += labourPrc[i];
+        }
+        updatePrc.labourPrice = scMathUtil.roundTo(sumLaP, -2);
+    }
+    //材料费
+    if(materialPrc.length > 0){
+        let sumLaP = 0;
+        for(let i = 0, len  = materialPrc.length; i < len; i++){
+            sumLaP += materialPrc[i];
+        }
+        updatePrc.materialPrice = scMathUtil.roundTo(sumLaP, -2);
+    }
+    //机械费
+    if(machinePrc.length > 0){
+        let sumLaP = 0;
+        for(let i = 0, len  = machinePrc.length; i < len; i++){
+            sumLaP += machinePrc[i];
+        }
+        updatePrc.machinePrice = scMathUtil.roundTo(sumLaP, -2);
+    }
+    //基价
+    updatePrc.basePrice = scMathUtil.roundTo(updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice, -2);
+    //更新定额数据
+    ration.labourPrice = updatePrc.labourPrice.toString();
+    ration.materialPrice = updatePrc.materialPrice.toString();
+    ration.machinePrice = updatePrc.machinePrice.toString();
+    ration.basePrice = updatePrc.basePrice.toString();
+
+    function isDef(v){
+        return v !== undefined && v !== null;
+    }
+    //是否属于人工、材料、机械类型
+    function getParentType(type){
+        if(labour.indexOf(type) !== -1){
+            return 'labour';
+        }
+        if(material.indexOf(type) !== -1){
+            return 'material';
+        }
+        if(machine.indexOf(type) !== -1){
+            return 'machine';
+        }
+        return null;
+    }
+
+};
+
 /**
  * 根据条件获取定额数据
  *
@@ -533,8 +606,10 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) {
     const stdGLJData = await stdBillsLibListsModel.getGljItemsByRep(rationRepository[0].gljLib);
     // 整理标准工料机库数据
     let stdGLJList = {};
+    let stdGLJListByID = {};
     for (const tmp of stdGLJData) {
         stdGLJList[tmp.code.toString()] = tmp.ID;
+        stdGLJListByID[tmp.ID] = tmp;
     }
     let lastData = {};
     const rationData = [];
@@ -579,6 +654,10 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) {
             caption: tmp[2],
             rationRepId: rationRepId,
             sectionId: 0,
+            labourPrice: '0',
+            materialPrice: '0',
+            machinePrice: '0',
+            basePrice: '0',
             rationGljList: []
         };
         // 防止重复加入
@@ -607,6 +686,11 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) {
     if (insertData.length <= 0) {
         return true;
     }
+    //计算价格
+    for(let ration of insertData){
+        this.calcForRation(stdGLJListByID, ration);
+    }
+
     // 组织id
     const counterInfo = await counter.counterDAO.getIDAfterCount(counter.moduleName.rations, insertData.length);
     let maxId = counterInfo.value.sequence_value;

+ 174 - 10
web/maintain/ration_repository/js/ration_coe.js

@@ -31,7 +31,126 @@ var rationCoeOprObj = {
         me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
         me.sheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStarting);
         me.sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
-       // me.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
+        //右键
+        me.onContextmenuOpr();
+    },
+
+    isDef: function (v) {
+        return v !== undefined && v !== null;
+    },
+
+    onContextmenuOpr: function () {
+        let me = rationCoeOprObj;
+        $.contextMenu({
+            selector: '#rdSpread',
+            build: function($triggerElement, e){
+                //控制允许右键菜单在哪个位置出现
+                let sheet = me.sheet;
+                let offset = $("#rdSpread").offset(),
+                    x = e.pageX - offset.left,
+                    y = e.pageY - offset.top;
+                let target = sheet.hitTest(x, y);
+                if(sheet.getParent().getActiveSheetIndex() === 2 && target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
+                    let currentCache = me.isDef(me.cache["_Coe_" + me.curRation.ID])  ? me.cache["_Coe_" + me.curRation.ID] : [];
+                    sheet.setActiveCell(target.row, target.col);
+                    //控制按钮是否可用
+                    let upDis = false,
+                        downDis = false,
+                        refDis = false;
+                    if(target.row >= currentCache.length){
+                        upDis = true;
+                        downDis = true;
+                        refDis = true;
+                    }
+                    else {
+                        if(!me.isDef(currentCache[target.row - 1])){
+                            upDis = true;
+                        }
+                        if(!me.isDef(currentCache[target.row + 1])){
+                            downDis = true;
+                        }
+                    }
+                    return {
+                        callback: function(){},
+                        items: {
+                            "upMove": {name: "上移", disabled: upDis, icon: "fa-arrow-up", callback: function (key, opt) {
+                                me.upMove(currentCache[target.row], currentCache[target.row - 1], {row: target.row - 1, col: target.col});
+                            }},
+                            "downMove": {name: "下移", disabled: downDis, icon: "fa-arrow-down", callback: function (key, opt) {
+                                me.downMove(currentCache[target.row], currentCache[target.row + 1], {row: target.row + 1, col: target.col});
+                            }},
+                            "ref": {name: "添加到本节其他定额", disabled: refDis, icon: "fa-arrow-left", callback: function (key, opt) {
+                                me.updateSectionRation(rationOprObj.currentRations["_SEC_ID_" + rationOprObj.currentSectionId], currentCache[target.row], function (updateArr) {
+                                    for(let i = 0, len = updateArr.length; i < len; i++){
+                                        let ration = updateArr[i];
+                                        let rationCoeList = updateArr[i].rationCoeList;
+                                        let newNo = 1;
+                                        for(let j = 0, jLen = rationCoeList.length; j < jLen; j++){
+                                            if(rationCoeList[j].no >= newNo){
+                                                newNo = rationCoeList[j].no + 1;
+                                            }
+                                        }
+                                        let theCache = me.cache["_Coe_" + ration.ID];
+                                        if(theCache !== undefined && theCache !== null){
+                                            let newCoe = {};
+                                            for(let attr in currentCache[target.row]){
+                                                newCoe[attr] = currentCache[target.row][attr];
+                                            }
+                                            newCoe.no = newNo;
+                                            theCache.push(newCoe);
+                                        }
+                                    }
+                                });
+                            }}
+                        }
+                    };
+                }
+                else{
+                    return false;
+                }
+            }
+        });
+    },
+
+    upMove: function (thisObj, preObj, cell) {
+        let me = this;
+        let tempNo = thisObj.no;
+        thisObj.no = preObj.no;
+        preObj.no = tempNo;
+        //ajax
+        me.updateCurRation(function () {
+            me.showCoeItems(me.curRation.ID);
+            me.sheet.setActiveCell(cell.row, cell.col);
+        });
+    },
+
+    downMove: function (thisObj, nextObj, cell) {
+        let me = this;
+        let tempNo = thisObj.no;
+        thisObj.no = nextObj.no;
+        nextObj.no = tempNo;
+        me.updateCurRation(function () {
+            me.showCoeItems(me.curRation.ID);
+            me.sheet.setActiveCell(cell.row, cell.col);
+        });
+    },
+
+    //本节所有使用此条件
+    useAll: function (coe) {
+
+    },
+
+    sortByNo: function (cache) {
+        cache.sort(function (a, b) {
+            let rst = 0;
+            if(a.no > b.no){
+                rst = 1;
+            }
+            else if(a.no < b.no){
+                rst = -1;
+            }
+            return rst;
+        });
     },
 
     onClipboardPasting: function(sender, args) {
@@ -221,7 +340,11 @@ var rationCoeOprObj = {
                 success:function(result){
                     if (result) {
                         var rstArr = [];
-                        for (let obj of result.data){rstArr.push(obj)};
+                        let newNo = curCache && curCache.length > 0 ? curCache[curCache.length - 1].no + 1 : 1;
+                        for (let obj of result.data){
+                            obj.no = newNo++;
+                            rstArr.push(obj)
+                        }
                         if (curCache) {
                             curCache = curCache.concat(rstArr);
                         }else{
@@ -254,12 +377,16 @@ var rationCoeOprObj = {
             ration.rationCoeList.length == 0){return;};*/
 
         var coeList = ration.rationCoeList;
+        let coeIDs = [];
+        for(let i = 0, len = coeList.length; i < len; i++){
+            coeIDs.push(coeList[i].ID);
+        }
         var curCache = me.cache["_Coe_" + ration.ID];
         if (curCache) {
             me.showCoeItems(ration.ID);
             //sheetCommonObj.lockCells(me.sheet, me.setting);
         } else if(!curCache && typeof coeList !== 'undefined' && coeList.length > 0) {
-            var data = {"libID": me.libID, "coeIDs": coeList};
+            var data = {"libID": me.libID, "coeIDs": coeIDs};
             $.ajax({
                 type:"POST",
                 url:"api/getCoeItemsByIDs",
@@ -272,9 +399,16 @@ var rationCoeOprObj = {
                     if (result.data) {
                         var tempResult = [];
                         for (let obj of result.data) {
-                            tempResult.push(obj);
+                            for(let i = 0, len = coeList.length; i < len; i++){
+                                if(obj.ID === coeList[i].ID){
+                                    obj.no = coeList[i].no;
+                                    tempResult.push(obj);
+                                    break;
+                                }
+                            }
                         };
 
+
                         me.cache["_Coe_" + ration.ID] = tempResult;
 
                         me.showCoeItems(ration.ID);
@@ -295,8 +429,8 @@ var rationCoeOprObj = {
         if (curCache) {
             curCache.sort(function(a, b) {
                 var rst = 0;
-                if (a.serialNo > b.serialNo) rst = 1
-                else if (a.serialNo < b.serialNo) rst = -1;
+                if (a.no > b.no) rst = 1
+                else if (a.no < b.no) rst = -1;
                 return rst;
             });
             sheetsOprObj.showData(me.sheet, me.setting, curCache);
@@ -310,15 +444,45 @@ var rationCoeOprObj = {
             var curCache = me.cache["_Coe_" + me.curRation.ID];
             if (curCache) {
                 for (let obj of curCache) {
-                    rst.push(obj.ID);
-                };
+                    rst.push({ID: obj.ID, no: obj.no});
+                }
                 me.curRation.rationCoeList = rst;
                 updateArr.push(me.curRation);
                 rationOprObj.mixUpdateRequest(updateArr, [], [], function () {
                     if(callback) callback();
                 });
-            };
-        };
+            }
+        }
+    },
+
+    //更新本节所有定额
+    updateSectionRation: function (rations, coe, callback) {
+        let me = this;
+        let updateArr = [];
+        for(let i = 0, len = rations.length; i < len; i++){
+            if(rations[i].ID !== me.curRation.ID){
+                let rationCoeList = rations[i].rationCoeList;
+                let isExist = false;
+                let newNo = 1;
+                for(let j = 0, jLen = rationCoeList.length; j < jLen; j++){
+                    if(rationCoeList[j].no >= newNo){
+                        newNo = rationCoeList[j].no + 1;
+                    }
+                    if(rationCoeList[j].ID === coe.ID){
+                        isExist = true;
+                    }
+                }
+                if(!isExist){
+                    rationCoeList.push({ID: coe.ID, no: newNo});
+                    updateArr.push(rations[i]);
+                }
+            }
+        }
+        if(updateArr.length > 0){
+            rationOprObj.mixUpdateRequest(updateArr, [], [], function () {
+                if(callback) callback(updateArr);
+            });
+        }
     }
 }