瀏覽代碼

叶子清单缺省计算程序的算法、预编译。

Chenshilong 7 年之前
父節點
當前提交
a3cc0f3e85

+ 47 - 22
public/calc_util.js

@@ -83,6 +83,10 @@ let executeObj = {
         };
 
         return rst;
+    },
+    HJ: function () {
+        let me = this;
+        return me.treeNode.data.baseTotalPrice;
     }
 };
 
@@ -338,8 +342,13 @@ class Calculation {
             for (let idx of template.compiledSeq) {
                 let item = template.calcItems[idx];
                 item.dispExprUser = item.dispExpr;    // 用于界面显示。disExpr是公式模板,不允许修改:人工系数占位符被修改后变成数值,第二次无法正确替换。
-                item.compiledExpr = item.expression.split('@(').join('$CE.at(');
-                item.compiledExpr = item.compiledExpr.split('base(').join('$CE.base(');
+                if (item.expression == 'HJ')
+                    item.compiledExpr = '$CE.HJ()'
+                else{
+                    item.compiledExpr = item.expression.split('@(').join('$CE.at(');
+                    item.compiledExpr = item.compiledExpr.split('base(').join('$CE.base(');
+                };
+
                 if (item.labourCoeID){
                     let lc = me.compiledLabourCoes["LabourCoe_" + item.labourCoeID].coe;
                     item.dispExprUser = item.dispExpr.replace(/L/gi, lc.toString());
@@ -383,23 +392,39 @@ class Calculation {
         };
     };
 
-    calculate($treeNode){
+    calculate(treeNode){
         let me = this;
-        let templateID = $treeNode.data.programID;
+        let templateID = treeNode.data.programID;
         if (!templateID) templateID = 1;
         let template = me.compiledTemplates[templateID];
-        $treeNode.data.calcTemplate = template;
+        treeNode.data.calcTemplate = template;
+
+        let project = projectObj.project;
+
+        // 缺省计算程序需要提供总金额作为计算基数,然后每条按比例(费率)计算,不需要工料机明细。
+        if (treeNode.data.baseTotalPrice != undefined){
+            delete treeNode.data.gljList;
+        }
+        else {
+            if (treeNode.sourceType === project.Ration.getSourceType()) {
+                treeNode.data.gljList = project.ration_glj.getGljArrByRation(treeNode.data.ID);
+            }
+            else if (treeNode.sourceType === project.Bills.getSourceType()) {
+                let rations = project.Ration.getBillsSortRation(treeNode.source.getID());
+                treeNode.data.gljList = project.ration_glj.getGatherGljArrByRations(rations);
+            };
+        };
 
-        if ($treeNode && template.hasCompiled) {
+        if (treeNode && template.hasCompiled) {
             let $CE = executeObj;
-            $CE.treeNode = $treeNode;
+            $CE.treeNode = treeNode;
             $CE.template = template;
             $CE.calcBase = me.compiledCalcBases;
 
-            if (!$treeNode.data.fees) {
-                $treeNode.data.fees = [];
-                $treeNode.data.feesIndex = {};
-                $treeNode.changed = true;
+            if (!treeNode.data.fees) {
+                treeNode.data.fees = [];
+                treeNode.data.feesIndex = {};
+                treeNode.changed = true;
             };
 
             for (let idx of template.compiledSeq) {
@@ -409,14 +434,14 @@ class Calculation {
                 if (!feeRate) feeRate = 100;    // 100%
                 calcItem.unitFee = round(eval(calcItem.compiledExpr) * feeRate * 0.01);   // 如果eval()对清单树有影响,就换成小麦的Expression对象再试
 
-                let quantity = $treeNode.data.quantity;
+                let quantity = treeNode.data.quantity;
                 if (!quantity) quantity = 0;
                 calcItem.totalFee = round(calcItem.unitFee * quantity);
 
                 // 费用同步到定额
                 // 引入小麦的字段检测后,快速切换定额出现计算卡顿现象,过多的循环造成。这里把她的代码拆出来,减少微循环。
                 if (calcItem.fieldName != '') {
-                    if (!$treeNode.data.feesIndex[calcItem.fieldName]){
+                    if (!treeNode.data.feesIndex[calcItem.fieldName]){
                         let fee = {
                             'fieldName': calcItem.fieldName,
                             'unitFee': calcItem.unitFee,
@@ -424,19 +449,19 @@ class Calculation {
                             'tenderUnitFee': 0,
                             'tenderTotalFee': 0
                         };
-                        $treeNode.data.fees.push(fee);
-                        $treeNode.data.feesIndex[calcItem.fieldName] = fee;
-                        $treeNode.changed = true;
+                        treeNode.data.fees.push(fee);
+                        treeNode.data.feesIndex[calcItem.fieldName] = fee;
+                        treeNode.changed = true;
                     }
                     else{
-                        if ($treeNode.data.feesIndex[calcItem.fieldName].unitFee != calcItem.unitFee){
-                            $treeNode.data.feesIndex[calcItem.fieldName].unitFee = calcItem.unitFee;
-                            $treeNode.changed = true;
+                        if (treeNode.data.feesIndex[calcItem.fieldName].unitFee != calcItem.unitFee){
+                            treeNode.data.feesIndex[calcItem.fieldName].unitFee = calcItem.unitFee;
+                            treeNode.changed = true;
                         };
 
-                        if ($treeNode.data.feesIndex[calcItem.fieldName].totalFee != calcItem.totalFee){
-                            $treeNode.data.feesIndex[calcItem.fieldName].totalFee = calcItem.totalFee;
-                            $treeNode.changed = true;
+                        if (treeNode.data.feesIndex[calcItem.fieldName].totalFee != calcItem.totalFee){
+                            treeNode.data.feesIndex[calcItem.fieldName].totalFee = calcItem.totalFee;
+                            treeNode.changed = true;
                         };
                     }
                 };

+ 100 - 120
web/building_saas/main/js/models/calc_program.js

@@ -5,95 +5,99 @@
  *  用到费率的规则必须有feeRateID属性,当有该属性时,会自动显示费率值。
  */
 
-let defaultBillTemplate = [
-    {
-        ID: 1,
-        serialNo: '一',
-        code: "A",
-        name: "定额直接费",
-        dispExpr: "A1+A2+A3",
-        statement: "人工费+材料费+机械费",
-        feeRate: null,
-        memo: ''
-    },
-    {
-        ID: 2,
-        serialNo: '1',
-        code: "A1",
-        name: "人工费",
-        dispExpr: "HJ",
-        statement: "合计",
-        feeRate: 50,
-        fieldName: 'labour',
-        memo: ''
-    },
-    {
-        ID: 3,
-        serialNo: '2',
-        code: "A2",
-        name: "材料费",
-        dispExpr: "HJ",
-        statement: "合计",
-        feeRate: 30,
-        fieldName: 'material',
-        memo: ''
-    },
-    {
-        ID: 4,
-        serialNo: '3',
-        code: "A3",
-        name: "机械费",
-        dispExpr: "HJ",
-        statement: "合计",
-        feeRate: 20,
-        fieldName: 'machine',
-        memo: ''
-    },
-    {
-        ID: 5,
-        serialNo: '二',
-        code: "A4",
-        name: "管理费",
-        dispExpr: "A",
-        statement: "定额直接费",
-        feeRate: null,
-        fieldName: 'manage',
-        memo: ''
-    },
-    {
-        ID: 6,
-        serialNo: '三',
-        code: "B",
-        name: "利润",
-        dispExpr: "A",
-        statement: "定额直接费",
-        feeRate: null,
-        fieldName: 'profit',
-        memo: ''
-    },
-    {
-        ID: 7,
-        serialNo: '四',
-        code: "C",
-        name: "风险费用",
-        dispExpr: "",
-        statement: "",
-        feeRate: null,
-        fieldName: 'risk',
-        memo: ''
-    },
-    {
-        ID: 8,
-        serialNo: '',
-        code: "",
-        name: "综合单价",
-        dispExpr: "A+B",
-        statement: "定额直接费+利润",
-        feeRate: null,
-        fieldName: 'common',
-        memo: ''
-    }
-];
+let defaultBillTemplate = {
+    ID: 15,
+    name: "清单缺省",
+    calcItems: [
+        {
+            ID: 1,
+            code: "1",
+            name: "定额直接费",
+            dispExpr: "F2+F3+F4",
+            expression: "@('2')+@('3')+@('4')",
+            statement: "人工费+材料费+机械费",
+            feeRate: null,
+            memo: ''
+        },
+        {
+            ID: 2,
+            code: "1.1",
+            name: "人工费",
+            dispExpr: "HJ",
+            expression: "HJ",
+            statement: "合计",
+            feeRate: 50,
+            fieldName: 'labour',
+            memo: ''
+        },
+        {
+            ID: 3,
+            code: "1.2",
+            name: "材料费",
+            dispExpr: "HJ",
+            expression: "HJ",
+            statement: "合计",
+            feeRate: 30,
+            fieldName: 'material',
+            memo: ''
+        },
+        {
+            ID: 4,
+            code: "1.3",
+            name: "机械费",
+            dispExpr: "HJ",
+            expression: "HJ",
+            statement: "合计",
+            feeRate: 20,
+            fieldName: 'machine',
+            memo: ''
+        },
+        {
+            ID: 5,
+            code: "2",
+            name: "企业管理费",
+            dispExpr: "F1",
+            expression: "@('1')",
+            statement: "定额直接费",
+            feeRate: null,
+            fieldName: 'manage',
+            memo: ''
+        },
+        {
+            ID: 6,
+            code: "3",
+            name: "利润",
+            dispExpr: "F1",
+            expression: "@('1')",
+            statement: "定额直接费",
+            feeRate: null,
+            fieldName: 'profit',
+            memo: ''
+        },
+        {
+            ID: 7,
+            code: "4",
+            name: "风险费用",
+            dispExpr: "F1",
+            expression: "@('1')",
+            statement: "定额直接费",
+            feeRate: null,
+            fieldName: 'risk',
+            memo: ''
+        },
+        {
+            ID: 8,
+            code: "5",
+            name: "综合单价",
+            dispExpr: "F1+F5+F6+F7",
+            expression: "@('1')+@('5')+@('6')+@('7')",
+            statement: "定额直接费+企业管理费+利润+风险费用",
+            feeRate: null,
+            fieldName: 'common',
+            memo: ''
+        }
+    ]
+};
 
 class CalcProgram {
     constructor(project){
@@ -124,6 +128,7 @@ class CalcProgram {
         let calcFeeRates = this.project.FeeRate.datas.rates;
         let calcLabourCoes = this.project.labourCoe.datas.coes;
         let calcTemplates = this.project.calcProgram.datas.templates;
+        calcTemplates.push(defaultBillTemplate);
 
         this.calc.compilePublics(calcFeeRates, calcLabourCoes, feeType, rationCalcBase);
         for (let ct of calcTemplates){
@@ -143,22 +148,12 @@ class CalcProgram {
 
     calculate(treeNode){
         let me = this;
-        if (treeNode.sourceType === this.project.Ration.getSourceType()) {
-            treeNode.data.gljList = this.project.ration_glj.getGljArrByRation(treeNode.data.ID);
-        }
-        else if (treeNode.sourceType === this.project.Bills.getSourceType()) {
-             let rations = this.project.Ration.getBillsSortRation(treeNode.source.getID());
-            treeNode.data.gljList = this.project.ration_glj.getGatherGljArrByRations(rations);
-        };
-
-        this.calc.calculate(treeNode);
-
+        me.calc.calculate(treeNode);
         // 存储、刷新本结点、所有父结点
         if (treeNode.changed) {
             me.saveAndCalcParents(treeNode);
             delete treeNode.changed;
         };
-
     };
 
     saveAndCalcParents(treeNode) {
@@ -263,33 +258,18 @@ class CalcProgram {
     calcDefaultBillTemp(treeNode, totalPrice){
         let me = this;
         let rst = [];
-        if (treeNode.sourceType != this.project.Bills.getSourceType()){return rst};
-        me.initFees(treeNode);
-        for (let item of defaultBillTemplate) {
-            let num = totalPrice;
-            item.dispExprUser = item.dispExpr;
-            item.displayFieldName = me.calc.compiledFeeTypes[item.fieldName];
-
-            if (item.feeRate)
-                item.unitFee = (totalPrice * item.feeRate * 0.01).toDecimal(me.digit)
-            else
-                item.unitFee = 0;
+        if (treeNode.sourceType != me.project.Bills.getSourceType()){return rst};
 
-            let quantity = treeNode.data.quantity;
-            if (!quantity) quantity = 0;
-            item.totalFee = (item.unitFee * quantity).toDecimal(me.digit);
-            item.tenderUnitFee = 0;
-            item.tenderTotalFee = 0;
-
-            me.checkFee(treeNode, item);
-        };
+        treeNode.data.baseTotalPrice = totalPrice;
+        treeNode.data.programID = defaultBillTemplate.ID;
+        me.calc.calculate(treeNode);
 
         if (treeNode.changed) {
             me.saveAndCalcParents(treeNode);
             delete treeNode.changed;
         };
 
-        rst = defaultBillTemplate;
+        rst = treeNode.data.calcTemplate.calcItems;
         return rst;
     };
 

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

@@ -52,7 +52,6 @@ let rationPM = {
         };
         me.mainSpread = sheetCommonObj.buildSheet($('#mainSpread')[0], me.mainSetting, me.datas.length);
         me.detailSpread = sheetCommonObj.buildSheet($('#detailSpread')[0], me.detailSetting, me.datas[0].calcItems.length);
-
         var fieldName = new GC.Spread.Sheets.CellTypes.ComboBox();
         fieldName.items(projectObj.project.calcProgram.calc.compiledFeeTypeNames);
         me.detailSpread.getSheet(0).getRange(-1, 4, -1, 1).cellType(fieldName);
@@ -75,6 +74,7 @@ let rationPM = {
         me.detailSpread.suspendPaint();
         var dSheet = me.detailSpread.getSheet(0);
         var dData = me.datas[row].calcItems;
+        dSheet.setRowCount(dData.length, GC.Spread.Sheets.SheetArea.viewport);
         sheetCommonObj.showData(dSheet, me.detailSetting, dData);
         me.detailSpread.resumePaint();
     },

+ 0 - 16
web/building_saas/main/js/views/calc_program_view.js

@@ -229,22 +229,6 @@ let calcProgramObj = {
         var me = this;
         me.treeNode = treeNode;
         me.datas = projectObj.project.calcProgram.getCalcDatas(treeNode);
-
-        function checkSerialNo() {     // 检测序号列。隐藏列的方式焦点难控制,体验不佳,这里动态添加删除。
-            let srlCol = {headerName: "序号", headerWidth: CP_Col_Width.serialNo, dataCode: "serialNo", dataType: "String", hAlign: "center"};
-            if (me.datas.length > 0 && me.datas[0].serialNo){
-                if (me.setting.header[0].dataCode != "serialNo"){
-                    me.setting.header.splice(0, 0, srlCol);
-                };
-            }
-            else {
-                if (me.setting.header[0].dataCode == "serialNo"){
-                    me.setting.header.splice(0, 1);
-                };
-            }
-        };
-
-        checkSerialNo();
         sheetCommonObj.initSheet(me.sheet, me.setting, me.datas.length);
         sheetCommonObj.showData(me.sheet, me.setting, me.datas);