소스 검색

Merge branch 'master' into olym

caiaolin 8 년 전
부모
커밋
8e72172924

+ 2 - 0
modules/volume_price/models/volume_price_schema.js

@@ -18,6 +18,8 @@ let volumePriceSchema = new Schema({
     billsItemID: Number,
     billsItemID: Number,
     // 排序
     // 排序
     serialNo: Number,
     serialNo: Number,
+    // 编号
+    code: String,
     // 名称
     // 名称
     name: String,
     name: String,
     // 单位
     // 单位

+ 62 - 69
public/calc_util.js

@@ -1,59 +1,40 @@
 /**
 /**
  * Created by Tony on 2017/6/21.
  * Created by Tony on 2017/6/21.
  */
  */
-let calcBaseCodeCollection = ["定额基价人工费", "定额基价材料费", "定额基价机械费"
-    , "定额基价人工费(调整后)", "定额基价材料费(调整后)", "定额基价机械费(调整后)"
-    , "市场价格人工费", "市场价格材料费", "市场价格机械费"
-    , "定额基价机上人工费", "主材费", "设备费"
-];
-let dummyCalcBaseCodeTypeCollection = [[2], [6], [64]
-    , [], [], []
-    , [], [], []
-    , [], [], []
-];
-
 let executeObj = {
 let executeObj = {
-    currentTpl : null,
-    currentRationItem: null,
-    currentFeeRateFile: null,
+    calculation : null,
+    ration: null,
+    feeRate: null,
     at: function(ID) {
     at: function(ID) {
         let me = executeObj,
         let me = executeObj,
             rst = 0;
             rst = 0;
-        rst = me.currentTpl.compileAssistantObj[ID].unitFee;
+        rst = me.calculation.compileAssistantObj[ID].unitFee;
         rst = parseFloat(rst);
         rst = parseFloat(rst);
         return rst;
         return rst;
     },
     },
-    base: function(calcBaseCode) {
+    base: function(calcBaseName) {
         let me = executeObj, rst = 0,
         let me = executeObj, rst = 0,
-            idx = calcBaseCodeCollection.indexOf(calcBaseCode);
-        if (idx >= 0) {
-            if (dummyCalcBaseCodeTypeCollection[idx].length > 0) {
-                let tmpSum = 0;
-                for (let glj of me.currentRationItem.data.gljList) {
-                    if (dummyCalcBaseCodeTypeCollection[idx].indexOf(glj["type"]) >= 0) {
-                        tmpSum += glj["basePrice"] * glj["quantity"];
-                    }
-                }
-                rst = tmpSum;
-            } else {
-                //rst = 10 + idx; //随便给个数
-            }
-        }
-        //rst = idx; //暂时返回值,测试用
+            base = getRationCalcBase(calcBaseName);
+
+        if (base != null) {
+            let price = 0, tmpSum = 0;
+            for (let glj of me.ration.data.gljList) {
+                if (base.gljTypes.indexOf(glj.type) >= 0) {
+                    if (base.calcType == baseCalc){ price = glj["basePrice"];}
+                    else if (base.calcType == adjustCalc){price = glj["adjustPrice"];}
+                    else if (base.calcType == budgetCalc){price = glj["marketPrice"];}
+                    else if (base.calcType == diffCalc){price = glj["marketPrice"] - glj["adjustPrice"];};
+                };
+                tmpSum = tmpSum + glj["quantity"] * price;
+                glj = null;
+            };
+            rst = tmpSum;
+        };
         return rst;
         return rst;
     },
     },
     fee: function(feeID) {
     fee: function(feeID) {
         let me = executeObj, rst = 0;
         let me = executeObj, rst = 0;
-        /*
-        for (let fee of me.currentFeeRateFile) {
-            if (fee.ID == feeID) {
-                rst = fee.rate;
-                break;
-            }
-        }
-        /*/
         if (me.compiledFeeRateFile["fee_" + feeID]) rst = me.compiledFeeRateFile["fee_" + feeID].rate;
         if (me.compiledFeeRateFile["fee_" + feeID]) rst = me.compiledFeeRateFile["fee_" + feeID].rate;
-        //*/
         return rst;
         return rst;
     },
     },
     factor: function(factorCode) {
     factor: function(factorCode) {
@@ -63,11 +44,11 @@ let executeObj = {
     }
     }
 };
 };
 
 
-class calculation {
-    init(calcTpl, calFee){
+class Calculation {
+    init(calcTemplate, feeRate){
         let me = this;
         let me = this;
-        me.calcTpl = calcTpl;
-        me.calFee = calFee;
+        me.calcTemplate = calcTemplate;
+        me.feeRate = feeRate;
         me.hasCompiled = false;
         me.hasCompiled = false;
     };
     };
 
 
@@ -101,9 +82,6 @@ class calculation {
             return rst;
             return rst;
         };
         };
         let private_parse_ref = function(item, itemIdx){
         let private_parse_ref = function(item, itemIdx){
-            //let expr = item.expression.split('at(').join('@(');
-            //item.expression = expr;
-            //console.log('expression: ' + expr);
             let idx = item.expression.indexOf('@(', 0);
             let idx = item.expression.indexOf('@(', 0);
             while (idx >= 0) {
             while (idx >= 0) {
                 let ID = private_extract_ID(item.expression, idx);
                 let ID = private_extract_ID(item.expression, idx);
@@ -122,47 +100,46 @@ class calculation {
                 }
                 }
                 idx = item.expression.indexOf('@(', idx + ID.length + 3);
                 idx = item.expression.indexOf('@(', idx + ID.length + 3);
             }
             }
-            if (me.calcTpl.compiledSeq.indexOf(itemIdx) < 0) {
-                me.calcTpl.compiledSeq.push(itemIdx);
+            if (me.calcTemplate.compiledSeq.indexOf(itemIdx) < 0) {
+                me.calcTemplate.compiledSeq.push(itemIdx);
             }
             }
         };
         };
         let private_setup_seq = function(item, itemIdx){
         let private_setup_seq = function(item, itemIdx){
-            if (me.calcTpl.compiledSeq.indexOf(itemIdx) < 0) {
+            if (me.calcTemplate.compiledSeq.indexOf(itemIdx) < 0) {
                 private_parse_ref(item, itemIdx);
                 private_parse_ref(item, itemIdx);
             }
             }
         };
         };
         let private_compile_items = function() {
         let private_compile_items = function() {
-            for (let idx of me.calcTpl.compiledSeq) {
-                let item = me.calcTpl.calcItems[idx];
+            for (let idx of me.calcTemplate.compiledSeq) {
+                let item = me.calcTemplate.calcItems[idx];
                 item.compiledExpr = item.expression.split('@(').join('$CE.at(');
                 item.compiledExpr = item.expression.split('@(').join('$CE.at(');
                 item.compiledExpr = item.compiledExpr.split('base(').join('$CE.base(');
                 item.compiledExpr = item.compiledExpr.split('base(').join('$CE.base(');
                 item.compiledExpr = item.compiledExpr.split('fee(').join('$CE.fee(');
                 item.compiledExpr = item.compiledExpr.split('fee(').join('$CE.fee(');
                 item.compiledExpr = item.compiledExpr.split('factor(').join('$CE.factor(');
                 item.compiledExpr = item.compiledExpr.split('factor(').join('$CE.factor(');
-                //console.log(item.compiledExpr);
             }
             }
         };
         };
         let private_comile_feeFile = function() {
         let private_comile_feeFile = function() {
-            if (me.calFee) {
+            if (me.feeRate) {
                 me.compiledFee = {};
                 me.compiledFee = {};
-                for (let fee of me.calFee) {
+                for (let fee of me.feeRate) {
                     me.compiledFee["fee_" + fee.ID] = fee;
                     me.compiledFee["fee_" + fee.ID] = fee;
                 }
                 }
             }
             }
         };
         };
 
 
-        if (me.calcTpl && me.calcTpl.calcItems && me.calcTpl.calcItems.length > 0) {
-            me.calcTpl.compiledSeq = [];
+        if (me.calcTemplate && me.calcTemplate.calcItems && me.calcTemplate.calcItems.length > 0) {
+            me.calcTemplate.compiledSeq = [];
             me.compileAssistantObj = {};
             me.compileAssistantObj = {};
             //1. first round -> prepare
             //1. first round -> prepare
             private_comile_feeFile();
             private_comile_feeFile();
-            for (let i = 0; i < me.calcTpl.calcItems.length; i++) {
-                let item = me.calcTpl.calcItems[i];
+            for (let i = 0; i < me.calcTemplate.calcItems.length; i++) {
+                let item = me.calcTemplate.calcItems[i];
                 me.compileAssistantObj[item.ID] = item;
                 me.compileAssistantObj[item.ID] = item;
                 me.compileAssistantObj[item.ID + "_idx"] = i;
                 me.compileAssistantObj[item.ID + "_idx"] = i;
             }
             }
             //2. second round -> go!
             //2. second round -> go!
-            for (let i = 0; i < me.calcTpl.calcItems.length; i++) {
-                private_setup_seq(me.calcTpl.calcItems[i], i);
+            for (let i = 0; i < me.calcTemplate.calcItems.length; i++) {
+                private_setup_seq(me.calcTemplate.calcItems[i], i);
             }
             }
             if (me.errs.length == 0) {
             if (me.errs.length == 0) {
                 private_compile_items();
                 private_compile_items();
@@ -172,18 +149,34 @@ class calculation {
             }
             }
         }
         }
     };
     };
-    calculate( $RATION){
+    calculate($RATION){         // 参数$RATION也可以是清单
         let me = this;
         let me = this;
         if ($RATION && me.hasCompiled) {
         if ($RATION && me.hasCompiled) {
             let $CE = executeObj;
             let $CE = executeObj;
-            $CE.currentRationItem = $RATION;
-            $CE.currentTpl = me;
-            $CE.currentFeeRateFile = me.calFee;
+            $CE.ration = $RATION;
+            $CE.calculation = me;
+            $CE.feeRate = me.feeRate;
             $CE.compiledFeeRateFile = me.compiledFee;
             $CE.compiledFeeRateFile = me.compiledFee;
-            for (let idx of me.calcTpl.compiledSeq) {
-                let item = me.calcTpl.calcItems[idx];
-                item.unitFee = eval(item.compiledExpr);
-                item.totalFee = item.unitFee * 3;     // AAAAA 5为测试值 $RATION.data.Quantity
+
+            if (!$RATION.fees) {
+                $RATION.fees = [];
+                $RATION.feesIndex = {};
+            };
+
+            for (let idx of me.calcTemplate.compiledSeq) {
+                let calcItem = me.calcTemplate.calcItems[idx];
+
+                // 这两项用于界面显示。
+                calcItem.unitFee = eval(calcItem.compiledExpr);   // AAAAA 如果eval()对清单树有影响,就换成小麦的Expression对象再试
+                calcItem.totalFee = calcItem.unitFee * 3;     // AAAAA 测试值,因目前定额无数量(保存不上) $RATION.data.Quantity
+
+                // 费用同步到定额
+                // 引入小麦的字段检测后,快速切换定额出现计算卡顿现象,过多的循环造成。这里把她的代码拆出来,减少微循环。
+                if (!$RATION.feesIndex[calcItem.type]){
+                    calcFees.addFee($RATION, calcItem.type);
+                };
+                $RATION.feesIndex[calcItem.type].unitFee = calcItem.unitFee;
+                $RATION.feesIndex[calcItem.type].totalFee = calcItem.totalFee;
             }
             }
         }
         }
     }
     }

+ 10 - 10
test/tmp_data/bills_grid_setting.js

@@ -136,7 +136,7 @@ var BillsGridSetting ={
         },
         },
         {
         {
             "width":180,
             "width":180,
-            "readOnly":false,
+            "readOnly":'readOnly.volumePrice',
             "head":{
             "head":{
                 "titleNames":[
                 "titleNames":[
                     "项目特征"
                     "项目特征"
@@ -166,7 +166,7 @@ var BillsGridSetting ={
         },
         },
         {
         {
             "width":80,
             "width":80,
-            "readOnly":false,
+            "readOnly":'readOnly.volumePrice',
             "head":{
             "head":{
                 "titleNames":[
                 "titleNames":[
                     "工作内容"
                     "工作内容"
@@ -196,7 +196,7 @@ var BillsGridSetting ={
         },
         },
         {
         {
             "width":80,
             "width":80,
-            "readOnly":false,
+            "readOnly":'readOnly.volumePrice',
             "head":{
             "head":{
                 "titleNames":[
                 "titleNames":[
                     "工程专业"
                     "工程专业"
@@ -226,7 +226,7 @@ var BillsGridSetting ={
         },
         },
         {
         {
             "width":80,
             "width":80,
-            "readOnly":false,
+            "readOnly":'readOnly.volumePrice',
             "head":{
             "head":{
                 "titleNames":[
                 "titleNames":[
                     "取费专业"
                     "取费专业"
@@ -286,7 +286,7 @@ var BillsGridSetting ={
         },
         },
         {
         {
             "width":120,
             "width":120,
-            "readOnly":false,
+            "readOnly":true,
             "head":{
             "head":{
                 "titleNames":[
                 "titleNames":[
                     "定额调整状态"
                     "定额调整状态"
@@ -346,7 +346,7 @@ var BillsGridSetting ={
         },
         },
         {
         {
             "width":80,
             "width":80,
-            "readOnly":false,
+            "readOnly":'readOnly.volumePrice',
             "head":{
             "head":{
                 "titleNames":[
                 "titleNames":[
                     "含量"
                     "含量"
@@ -376,7 +376,7 @@ var BillsGridSetting ={
         },
         },
         {
         {
             "width":120,
             "width":120,
-            "readOnly":false,
+            "readOnly":'readOnly.volumePrice',
             "head":{
             "head":{
                 "titleNames":[
                 "titleNames":[
                     "计算基数"
                     "计算基数"
@@ -406,7 +406,7 @@ var BillsGridSetting ={
         },
         },
         {
         {
             "width":80,
             "width":80,
-            "readOnly":false,
+            "readOnly":'readOnly.volumePrice',
             "head":{
             "head":{
                 "titleNames":[
                 "titleNames":[
                     "费率(%)"
                     "费率(%)"
@@ -496,7 +496,7 @@ var BillsGridSetting ={
         },
         },
         {
         {
             "width":80,
             "width":80,
-            "readOnly":false,
+            "readOnly":'readOnly.volumePrice',
             "head":{
             "head":{
                 "titleNames":[
                 "titleNames":[
                     "暂估单价"
                     "暂估单价"
@@ -526,7 +526,7 @@ var BillsGridSetting ={
         },
         },
         {
         {
             "width":80,
             "width":80,
-            "readOnly":false,
+            "readOnly":'readOnly.volumePrice',
             "head":{
             "head":{
                 "titleNames":[
                 "titleNames":[
                     "暂估合价"
                     "暂估合价"

+ 11 - 0
test/tmp_data/test_ration_calc/ration_calc_base.js

@@ -84,3 +84,14 @@ let rationCalcBase = [
         'gljTypes': [gljType.EQUIPMENT]
         'gljTypes': [gljType.EQUIPMENT]
     }
     }
 ];
 ];
+
+function getRationCalcBase(dispName){
+    let rst = null;
+    for (let base of rationCalcBase) {
+       if (base.dispName == dispName) {
+           rst = base;
+           break;
+       };
+    }
+    return rst;
+};

+ 1 - 1
web/building_saas/main/html/main.html

@@ -502,7 +502,7 @@
     <script type="text/javascript" src="/web/building_saas/main/js/calc/ration_calc.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/calc/ration_calc.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/calc/bills_calc.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/calc/bills_calc.js"></script>
     <script type="text/javascript" src="/public/calc_util.js"></script>
     <script type="text/javascript" src="/public/calc_util.js"></script>
-    <script type="text/javascript" src="/web/building_saas/main/js/models/ration_calc.js"></script>
+    <script type="text/javascript" src="/web/building_saas/main/js/models/ration_program.js"></script>
     <!-- Controller -->
     <!-- Controller -->
     <script type="text/javascript" src="/public/web/tree_sheet/tree_sheet_controller.js"></script>
     <script type="text/javascript" src="/public/web/tree_sheet/tree_sheet_controller.js"></script>
     <script type="text/javascript" src="/public/web/tree_sheet/tree_sheet_helper.js"></script>
     <script type="text/javascript" src="/public/web/tree_sheet/tree_sheet_helper.js"></script>

+ 21 - 2
web/building_saas/main/js/calc/calc_fees.js

@@ -19,6 +19,7 @@ let calcFees = {
     findFee: function (data, fieldName) {
     findFee: function (data, fieldName) {
         if (!data.fees) {
         if (!data.fees) {
             data.fees = [];
             data.fees = [];
+            data.feesIndex = {};
         }
         }
         for (let fee of data.fees) {
         for (let fee of data.fees) {
             if (fee.fieldName === fieldName) {
             if (fee.fieldName === fieldName) {
@@ -27,7 +28,7 @@ let calcFees = {
         }
         }
         return null;
         return null;
     },
     },
-    AddFee: function (data, fieldName) {
+    addFee: function (data, fieldName) {
         let fee = {
         let fee = {
             'fieldName': fieldName,
             'fieldName': fieldName,
             'unitFee': 0,
             'unitFee': 0,
@@ -45,7 +46,7 @@ let calcFees = {
         }
         }
         for (let field of fields) {
         for (let field of fields) {
             if (!this.findFee(data, field.type)) {
             if (!this.findFee(data, field.type)) {
-                this.AddFee(data, field.type);
+                this.addFee(data, field.type);
             }
             }
         }
         }
     },
     },
@@ -70,5 +71,23 @@ let calcFees = {
             }
             }
         }
         }
         return value;
         return value;
+    },
+    setFee: function (data, fullField, value) {
+        let fields = fullField.split('.'), valueField = data;
+        for (let i in fields) {
+            if (valueField[fields[i]]) {
+                if (i == fields.length - 1) {
+                    valueField[fields[i]] = value;
+                } else {
+                    valueField = valueField[fields[i]];
+                }
+            } else {
+                if (i == fields.length - 1) {
+                    valueField[fields[i]] = {};
+                } else {
+                    valueField[fields[i]] = value;
+                };
+            }
+        }
     }
     }
 }
 }

+ 28 - 6
web/building_saas/main/js/models/ration_calc.js

@@ -224,6 +224,7 @@ let calcTemplate = {
             ID: "1",
             ID: "1",
             code: "1",
             code: "1",
             name: "基价直接工程费",
             name: "基价直接工程费",
+            type: "baseDirect",
             dispExpr: "F2+F5+F6+F10",
             dispExpr: "F2+F5+F6+F10",
             expression: "@('2') + @('5') + @('6') + @('10')",
             expression: "@('2') + @('5') + @('6') + @('10')",
             compiledExpr: "",
             compiledExpr: "",
@@ -233,6 +234,7 @@ let calcTemplate = {
             ID: "2",
             ID: "2",
             code: "1.1",
             code: "1.1",
             name: "基价人工费",
             name: "基价人工费",
+            type: "baseLabour",
             dispExpr: "F3+F4",
             dispExpr: "F3+F4",
             expression: "@('3') + @('4')",
             expression: "@('3') + @('4')",
             compiledExpr: "",
             compiledExpr: "",
@@ -242,6 +244,7 @@ let calcTemplate = {
             ID: "3",
             ID: "3",
             code: "1.1.1",
             code: "1.1.1",
             name: "定额基价人工费",
             name: "定额基价人工费",
+            type: "rationBaseLabour",
             dispExpr: "[定额基价人工费]",
             dispExpr: "[定额基价人工费]",
             expression: "base('定额基价人工费').toFixed(2)",
             expression: "base('定额基价人工费').toFixed(2)",
             compiledExpr: "",
             compiledExpr: "",
@@ -250,7 +253,8 @@ let calcTemplate = {
         {
         {
             ID: "4",
             ID: "4",
             code: "1.1.2",
             code: "1.1.2",
-            name: "[定额人工单价(基价)调整]",
+            name: "定额人工单价(基价)调整",
+            type: "rationLabourFixed",
             dispExpr: "F3*(1.89-1)",
             dispExpr: "F3*(1.89-1)",
             expression: "@('3') * (1.89-1)",
             expression: "@('3') * (1.89-1)",
             compiledExpr: "",
             compiledExpr: "",
@@ -261,6 +265,7 @@ let calcTemplate = {
             ID: "5",
             ID: "5",
             code: "1.2",
             code: "1.2",
             name: "基价材料费",
             name: "基价材料费",
+            type: "baseMaterial",
             dispExpr: "[定额基价材料费]",
             dispExpr: "[定额基价材料费]",
             expression: "base('定额基价材料费')",
             expression: "base('定额基价材料费')",
             compiledExpr: "",
             compiledExpr: "",
@@ -270,6 +275,7 @@ let calcTemplate = {
             ID: "6",
             ID: "6",
             code: "1.3",
             code: "1.3",
             name: "基价机械费",
             name: "基价机械费",
+            type: "baseMachine",
             dispExpr: "F7+F9",
             dispExpr: "F7+F9",
             expression: "@('7') + @('9')",
             expression: "@('7') + @('9')",
             compiledExpr: "",
             compiledExpr: "",
@@ -279,6 +285,7 @@ let calcTemplate = {
             ID: "7",
             ID: "7",
             code: "1.3.1",
             code: "1.3.1",
             name: "定额基价机械费",
             name: "定额基价机械费",
+            type: "rationBaseMachine",
             dispExpr: "[定额基价机械费]",
             dispExpr: "[定额基价机械费]",
             expression: "base('定额基价机械费')",
             expression: "base('定额基价机械费')",
             compiledExpr: "",
             compiledExpr: "",
@@ -288,6 +295,7 @@ let calcTemplate = {
             ID: "8",
             ID: "8",
             code: "1.3.1.1",
             code: "1.3.1.1",
             name: "其中:定额基价机上人工费",
             name: "其中:定额基价机上人工费",
+            type: "rationBaseMachineLabour",
             dispExpr: "[定额基价机上人工费]",
             dispExpr: "[定额基价机上人工费]",
             expression: "base('定额基价机上人工费')",
             expression: "base('定额基价机上人工费')",
             compiledExpr: "",
             compiledExpr: "",
@@ -297,6 +305,7 @@ let calcTemplate = {
             ID: "9",
             ID: "9",
             code: "1.3.2",
             code: "1.3.2",
             name: "定额机上人工单价(基价)调整",
             name: "定额机上人工单价(基价)调整",
+            type: "rationBaseMachineLabourFixed",
             dispExpr: "F8*(1.89-1)",
             dispExpr: "F8*(1.89-1)",
             expression: "@('8') * (1.89-1)",
             expression: "@('8') * (1.89-1)",
             compiledExpr: "",
             compiledExpr: "",
@@ -306,6 +315,7 @@ let calcTemplate = {
             ID: "10",
             ID: "10",
             code: "1.4",
             code: "1.4",
             name: "未计价材料费",
             name: "未计价材料费",
+            type: "unPriceMaterial",
             dispExpr: "[主材费]+[设备费]",
             dispExpr: "[主材费]+[设备费]",
             expression: "base('主材费') + base('设备费')",
             expression: "base('主材费') + base('设备费')",
             compiledExpr: "",
             compiledExpr: "",
@@ -315,7 +325,9 @@ let calcTemplate = {
             ID: "11",
             ID: "11",
             code: "2",
             code: "2",
             name: "企业管理费",
             name: "企业管理费",
+            type: "manageFee",
             dispExpr: "F3",
             dispExpr: "F3",
+            feeRate: 8.21,
             expression: "@('3')*8.21 / 100",
             expression: "@('3')*8.21 / 100",
             compiledExpr: "",
             compiledExpr: "",
             statement: "定额基价人工费",
             statement: "定额基价人工费",
@@ -325,7 +337,9 @@ let calcTemplate = {
             ID: "12",
             ID: "12",
             code: "3",
             code: "3",
             name: "利润",
             name: "利润",
+            type: "profit",
             dispExpr: "F3",
             dispExpr: "F3",
+            feeRate: 6.5,
             expression: "@('3')*6.5 / 100",
             expression: "@('3')*6.5 / 100",
             compiledExpr: "",
             compiledExpr: "",
             statement: "定额基价人工费"
             statement: "定额基价人工费"
@@ -334,7 +348,9 @@ let calcTemplate = {
             ID: "13",
             ID: "13",
             code: "4",
             code: "4",
             name: "风险因素",
             name: "风险因素",
+            type: "risk",
             dispExpr: "F3",
             dispExpr: "F3",
+            feeRate: 3,
             expression: "@('3')*3 / 100",
             expression: "@('3')*3 / 100",
             compiledExpr: "",
             compiledExpr: "",
             statement: "定额基价人工费",
             statement: "定额基价人工费",
@@ -344,6 +360,7 @@ let calcTemplate = {
             ID: "14",
             ID: "14",
             code: "5",
             code: "5",
             name: "人材机价差",
             name: "人材机价差",
+            type: "lmmDiff",
             dispExpr: "F15+F16+F17",
             dispExpr: "F15+F16+F17",
             expression: "@('15') + @('16') + @('17')",
             expression: "@('15') + @('16') + @('17')",
             compiledExpr: "",
             compiledExpr: "",
@@ -353,7 +370,8 @@ let calcTemplate = {
             ID: "15",
             ID: "15",
             code: "5.1",
             code: "5.1",
             name: "人工费价差",
             name: "人工费价差",
-            dispExpr: "[市场价格人工费]-[调整后的定额人工费(基价)]",
+            type: "labourDiff",
+            dispExpr: "[人工费价差]",
             expression: "base('市场价格人工费') - base('定额基价人工费(调整后)')",
             expression: "base('市场价格人工费') - base('定额基价人工费(调整后)')",
             compiledExpr: "",
             compiledExpr: "",
             statement: "市场价格人工费-调整后的定额人工费(基价)"
             statement: "市场价格人工费-调整后的定额人工费(基价)"
@@ -362,7 +380,8 @@ let calcTemplate = {
             ID: "16",
             ID: "16",
             code: "5.2",
             code: "5.2",
             name: "材料费价差",
             name: "材料费价差",
-            dispExpr: "[市场价格材料费]-[定额基价材料费]",
+            type: "materialDiff",
+            dispExpr: "[材料费价差]",
             expression: "base('市场价格材料费') - base('定额基价材料费(调整后)')",
             expression: "base('市场价格材料费') - base('定额基价材料费(调整后)')",
             compiledExpr: "",
             compiledExpr: "",
             statement: "市场价格材料费-定额基价材料费"
             statement: "市场价格材料费-定额基价材料费"
@@ -371,7 +390,8 @@ let calcTemplate = {
             ID: "17",
             ID: "17",
             code: "5.3",
             code: "5.3",
             name: "机械费价差",
             name: "机械费价差",
-            dispExpr: "[市场价格机械费]-[调整后的定额基价机械费(基价)]",
+            type: "machineDiff",
+            dispExpr: "[机械费价差]",
             expression: "base('市场价格机械费') - base('定额基价机械费(调整后)')",
             expression: "base('市场价格机械费') - base('定额基价机械费(调整后)')",
             compiledExpr: "",
             compiledExpr: "",
             statement: "市场价格机械费-调整后的定额基价机械费(基价)"
             statement: "市场价格机械费-调整后的定额基价机械费(基价)"
@@ -380,6 +400,7 @@ let calcTemplate = {
             ID: "18",
             ID: "18",
             code: "6",
             code: "6",
             name: "综合单价",
             name: "综合单价",
+            type: "common",
             dispExpr: "F1+F11+F12+F13+F14",
             dispExpr: "F1+F11+F12+F13+F14",
             expression: "@('1') + @('11') + @('12') + @('13') + @('14')",
             expression: "@('1') + @('11') + @('12') + @('13') + @('14')",
             compiledExpr: "",
             compiledExpr: "",
@@ -394,10 +415,11 @@ class RationCalc {
     };
     };
 
 
     calculate(ration){
     calculate(ration){
-        let calc = new calculation();
+        ration.data.gljList = projectObj.project.ration_glj.getGljArrByRation(ration.data.ID);
+
+        let calc = new Calculation();
         calc.init(calcTemplate, calcFeeRate);
         calc.init(calcTemplate, calcFeeRate);
         calc.compile();
         calc.compile();
-        ration.data.gljList = projectObj.project.ration_glj.getGljArrByRation(ration.data.ID);
         calc.calculate(ration);
         calc.calculate(ration);
     };
     };
 }
 }

+ 30 - 0
web/building_saas/main/js/models/volume_price.js

@@ -35,7 +35,12 @@ var VolumePrice = {
 
 
             loadData (datas) {
             loadData (datas) {
                 this.datas = datas;
                 this.datas = datas;
+                // generate Fees & Flags Index,For View & Calculate
                 for (let data of datas) {
                 for (let data of datas) {
+                    data.feesIndex = {};
+                    data.fees.forEach(function (fee) {
+                        data.feesIndex[fee.fieldName] = fee;
+                    });
                     this.maxID(data.ID);
                     this.maxID(data.ID);
                 }
                 }
             };
             };
@@ -135,6 +140,31 @@ var VolumePrice = {
                     }
                     }
                 }
                 }
             };
             };
+
+            calculate (volumePrice) {
+                if (!calcFees.findFee(volumePrice, 'common')) {
+                    calcFees.addFee(volumePrice, 'common');
+                }
+                volumePrice.feesIndex.common.totalFee = (volumePrice.feesIndex.common.unitFee * volumePrice.quantity).toDecimal(2);
+                volumePrice.needRefresh = true;
+            }
+            updateField(volumePrice, field, newValue) {
+                calcFees.setFee(volumePrice, field, newValue);
+                let updateData = [];
+                if (field === 'quantity' || field === 'feesIndex.common.unitFee') {
+                    let data = {'ID': volumePrice.ID, 'projectID': this.getProject().ID()};
+                    data[field] = newValue;
+                    this.calculate(volumePrice);
+                    data.fees = volumePrice.fees;
+                    updateData.push({'updateType': 'ut_update', 'updateData': data});
+                    tools.owner.pushNow('updateVolumePrice', this.getSourceType(), updateData);
+                } else {
+                    let data = {'ID': volumePrice.ID, 'projectID': this.getProject().ID()};
+                    data[field] = newValue;
+                    updateData.push({'updateType': 'ut_update', 'updateData': data});
+                    tools.owner.pushNow('updateVolumePrice', this.getSourceType(), updateData);
+                }
+            }
         }
         }
 
 
         return new volumePrice();
         return new volumePrice();

+ 22 - 0
web/building_saas/main/js/views/project_view.js

@@ -7,6 +7,26 @@ var projectObj = {
     mainSpread: null,
     mainSpread: null,
     mainController: null,
     mainController: null,
     gljSpreed:null,
     gljSpreed:null,
+    mainSpreadEditEnded: function (sender, info) {
+        let project = projectObj.project;
+        let node = project.mainTree.items[info.row];
+        let colSetting = projectObj.mainController.setting.cols[info.col];
+        let fieldName = projectObj.mainController.setting.cols[info.col].data.field;
+        if (colSetting.data.wordWrap) {
+            info.sheet.autoFitRow(info.row);
+        }
+        if (node.sourceType === project.Bills.getSourceType()) {
+
+        } else if (node.sourceType === project.Ration.getSourceType()) {
+
+        } else if (node.sourceType === project.VolumePrice.getSourceType()) {
+            project.VolumePrice.updateField(node.source, fieldName, info.editingText);
+            if (node.source.needRefresh) {
+                projectObj.mainController.refreshTreeNode([node]);
+                node.source.needRefresh = false;
+            }
+        };
+    },
     checkMainSpread: function () {
     checkMainSpread: function () {
         if (!this.mainSpread) {
         if (!this.mainSpread) {
             this.mainSpread = SheetDataHelper.createNewSpread($('#billsSpread')[0]);
             this.mainSpread = SheetDataHelper.createNewSpread($('#billsSpread')[0]);
@@ -93,6 +113,8 @@ var projectObj = {
                     }
                     }
                 });
                 });
 
 
+                that.mainSpread.bind(GC.Spread.Sheets.Events.EditEnded, that.mainSpreadEditEnded);
+
                 that.loadMainSpreadContextMenu();
                 that.loadMainSpreadContextMenu();
             }
             }
             else {
             else {

+ 5 - 63
web/building_saas/main/js/views/ration_calc_view.js

@@ -1,63 +1,6 @@
 /**
 /**
  * Created by CSL on 2017-07-17.
  * Created by CSL on 2017-07-17.
  */
  */
-//for test AAAAAAAAAAAAA
-let calcRation = {
-    "sectionId" : 76,
-    "ID" : 15,
-    "code" : "AA0001",
-    "name" : "人工挖土方",
-    "unit" : "100m3",
-    "basePrice" : 840.84,
-    "caption" : "人工挖土方",
-    "feeType" : 2,
-    "rationGljList" : [
-        {
-            "glj" : {
-                "repositoryId" : 3,
-                "ID" : 17,
-                "code" : "00010201",
-                "name" : "土石方综合工日",
-                "specs" : null,
-                "unit" : "工日",
-                "basePrice" : 22,
-                "gljDistType" : "人工",
-                "gljType" : 2
-            },
-            "consumeAmt" : 38.22,
-            "proportion" : 0
-        },{
-            "glj": {
-                "repositoryId" : 3,
-                "ID" : 68,
-                "code" : "85030207",
-                "name" : "履带式起重机",
-                "specs" : "50t",
-                "unit" : "台班",
-                "basePrice" : 1194.05,
-                "gljDistType" : "机械",
-                "gljType" : 64
-            },
-            "consumeAmt" : 1.22,
-            "proportion" : 0
-        },{
-            "glj": {
-                "repositoryId" : 3,
-                "ID" : 200,
-                "code" : "36290101",
-                "name" : "水",
-                "specs" : "",
-                "unit" : "m3",
-                "basePrice" : 2,
-                "gljDistType" : "材料",
-                "gljType" : 6
-            },
-            "consumeAmt" : 9.2,
-            "proportion" : 0
-        }
-    ],
-    "rationRepId" : 3
-};
 
 
 let rationCalcView = {
 let rationCalcView = {
     sheet: null,
     sheet: null,
@@ -67,8 +10,8 @@ let rationCalcView = {
         header: [
         header: [
             {headerName: "费用代号", headerWidth: 75, dataCode: "code", dataType: "String", hAlign: "left"},
             {headerName: "费用代号", headerWidth: 75, dataCode: "code", dataType: "String", hAlign: "left"},
             {headerName: "费用名称", headerWidth: 200, dataCode: "name", dataType: "String"},
             {headerName: "费用名称", headerWidth: 200, dataCode: "name", dataType: "String"},
-            {headerName: "计算基数", headerWidth: 280, dataCode: "dispExpr", dataType: "String"},
-            {headerName: "基数说明", headerWidth: 220, dataCode: "statement", dataType: "String"},
+            {headerName: "计算基数", headerWidth: 200, dataCode: "dispExpr", dataType: "String"},
+            {headerName: "基数说明", headerWidth: 400, dataCode: "statement", dataType: "String"},
             {headerName: "费率", headerWidth: 80, dataCode: "feeRate", dataType: "Number"},   // precision: 3
             {headerName: "费率", headerWidth: 80, dataCode: "feeRate", dataType: "Number"},   // precision: 3
             {headerName: "单价", headerWidth: 100, dataCode: "unitFee", dataType: "Number"},  // execRst
             {headerName: "单价", headerWidth: 100, dataCode: "unitFee", dataType: "Number"},  // execRst
             {headerName: "合价", headerWidth: 100, dataCode: "totalFee", dataType: "Number"},
             {headerName: "合价", headerWidth: 100, dataCode: "totalFee", dataType: "Number"},
@@ -76,20 +19,19 @@ let rationCalcView = {
         ],
         ],
         view: {
         view: {
             comboBox: [],
             comboBox: [],
-            lockColumns: [0, 1, 2, 3, 5, 6, 7]
+            lockColumns: [0, 1, 2, 3, 4, 5, 6, 7]
         }
         }
     },
     },
 
 
     initSheet: function (sheet) {
     initSheet: function (sheet) {
         var me = this;
         var me = this;
         me.sheet = sheet;
         me.sheet = sheet;
-        sheetCommonObj.initSheet(me.sheet, me.setting, 20);     // AAAAAAAA
+        sheetCommonObj.initSheet(me.sheet, me.setting, 20);
     },
     },
 
 
     showData: function (ration) {
     showData: function (ration) {
         var me = this;
         var me = this;
-        me.ration = ration;  // AAAAAAA
-        //me.ration = calcRation;
+        me.ration = ration;
         let rationCalc = new RationCalc(projectObj.project);
         let rationCalc = new RationCalc(projectObj.project);
         rationCalc.calculate(me.ration);
         rationCalc.calculate(me.ration);