ソースを参照

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

zhangweicheng 8 年 前
コミット
1887d221f5

+ 10 - 1
public/web/tree_sheet/tree_sheet_helper.js

@@ -5,7 +5,7 @@
 var TREE_SHEET_HELPER = {
     getSheetCellStyle: function (setting) {
         var style = new GC.Spread.Sheets.Style();
-        style.locked = setting.readOnly ? true : false;
+        //style.locked = setting.readOnly ? true : false;
         style.name = setting.id;
         style.font = setting.data.font;
         style.hAlign = setting.data.hAlign;
@@ -99,6 +99,15 @@ var TREE_SHEET_HELPER = {
                 } else {
                     cell.value(getFieldText2());
                 }
+                if (colSetting.readOnly) {
+                    if (Object.prototype.toString.apply(colSetting.readOnly) === "[object Function]") {
+                        cell.locked(colSetting.readOnly(node));
+                    } else {
+                        cell.locked(true);
+                    }
+                } else {
+                    cell.locked(false);
+                }
             });
             sheet.autoFitRow(node.serialNo());
             if (recursive) {

+ 4 - 3
test/tmp_data/bills_grid_setting.js

@@ -41,7 +41,7 @@ var BillsGridSetting ={
         },
         {
             "width":50,
-            "readOnly":false,
+            "readOnly":true,
             "head":{
                 "titleNames":[
                     "类别"
@@ -66,7 +66,8 @@ var BillsGridSetting ={
                 "field":"type",
                 "vAlign":1,
                 "hAlign":1,
-                "font":"Arial"
+                "font":"Arial",
+                "getText": 'getText.type'
             }
         },
         {
@@ -255,7 +256,7 @@ var BillsGridSetting ={
         },
         {
             "width":120,
-            "readOnly":false,
+            "readOnly": 'readOnly.volumePrice',
             "head":{
                 "titleNames":[
                     "工程量计算规则"

+ 2 - 0
web/building_saas/fee_rates/fee_rate.html

@@ -14,6 +14,8 @@
     <script src="/lib/spreadjs/views/gc.spread.views.dataview.10.0.0.min.js" type="text/javascript"></script>
     <script src="/lib/spreadjs/views/plugins/gc.spread.views.gridlayout.10.0.0.min.js" type="text/javascript"></script>
     <script src="/lib/spreadjs/views/locale/gc.spread.views.dataview.locale.zh-CN.10.0.0.min.js" type="text/javascript"></script>
+    <script>GC.Spread.Sheets.LicenseKey = "559432293813965#A0y3iTOzEDOzkjMyMDN9UTNiojIklkI1pjIEJCLi4TPB9mM5AFNTd4cvZ7SaJUVy3CWKtWYXx4VVhjMpp7dYNGdx2ia9sEVlZGOTh7NRlTUwkWR9wEV4gmbjBDZ4ElR8N7cGdHVvEWVBtCOwIGW0ZmeYVWVr3mI0IyUiwCMzETN8kzNzYTM0IicfJye&Qf35VfiEzRwEkI0IyQiwiIwEjL6ByUKBCZhVmcwNlI0IiTis7W0ICZyBlIsIyNyMzM5ADI5ADNwcTMwIjI0ICdyNkIsIibj9SbvNmL4N7bjRnch56ciojIz5GRiwiI8+Y9sWY9QmZ0Jyp96uL9v6L0wap9biY9qiq95q197Wr9g+89iojIh94Wiqi";</script>
+
 
     <style>
         .grid { height: 500px; margin:0 10px 10px 40px;}

+ 20 - 9
web/building_saas/main/js/calc/bills_calc.js

@@ -75,21 +75,21 @@ class BillsCalcHelper {
         this.digit = 2;
         switch (this.CalcFlag) {
             case rationContent:
-                this.calcFieldName = rationContentCalcFields;
+                this.calcField = rationContentCalcFields;
                 break;
             case rationPrice:
-                this.calcFieldName = rationPriceCalcFields;
+                this.calcField = rationPriceCalcFields;
                 break;
             case rationPriceConverse:
-                this.calcFieldName = rationPriceConverseCalcFields;
+                this.calcField = rationPriceConverseCalcFields;
                 break;
             case billsPrice:
-                this.calcFieldName = billsPriceCalcFields;
+                this.calcField = billsPriceCalcFields;
                 break;
             default:
-                this.calcFieldName = [];
+                this.calcField = [];
         }
-        this.InitFields(this.calcFieldName);
+        this.InitFields(this.calcField);
     };
 
     getBillsGLjs (node) {
@@ -100,7 +100,7 @@ class BillsCalcHelper {
         }
         return gljs;
     };
-    calcLeaf (node, fields) {
+    calcRationLeaf (node, fields) {
         nodeCalcObj.node = node;
         nodeCalcObj.digit = this.digit;
         calcFees.checkFields(node.data, fields);
@@ -141,6 +141,9 @@ class BillsCalcHelper {
             }
         }
     };
+    calcVolumePriceLeaf (node, fields) {
+
+    };
     calcParent (node, fields) {
         nodeCalcObj.node = node;
         calcFees.checkFields(node.data, fields);
@@ -157,9 +160,17 @@ class BillsCalcHelper {
 
             if (node.source.children.length > 0) {
                 this.calcNodes(node.children);
-                this.calcParent(node, this.calcFieldName);
+                this.calcParent(node, this.calcField);
             } else {
-                this.calcLeaf(node, this.calcFieldName);
+                if (node.children.length > 0) {
+                    if (node.firstChild().sourceType === this.project.Ration.getSourceType()) {
+                        this.calcRationLeaf(node, this.calcField);
+                    } else {
+                        this.calcVolumePriceLeaf(node, this.calcField);
+                    }
+                } else {
+
+                }
             }
         }
     };

+ 4 - 0
web/building_saas/main/js/calc/calc_fees.js

@@ -26,6 +26,10 @@ let calcFees = {
         data.feesIndex[fieldName] = fee;
     },
     checkFields: function (data, fields) {
+        if (!data.fees) {
+            data.fees = [];
+            data.feesIndex = {};
+        }
         for (let field of fields) {
             if (!this.findFee(data, field.type)) {
                 this.AddFee(data, field.type);

+ 7 - 8
web/building_saas/main/js/calc/ration_calc.js

@@ -156,12 +156,12 @@ let rationCalcFields = [
         statement: "基价人工费+基价材料费+基价机械费+未计价材料费"
     },
     {
-        type: 'management', code: "2", name: "企业管理费",
+        type: 'management', code: "2", name: "企业管理费", feeRate: 7,
         dispExpr: "1.1.1", expression: "at('1.1.1')", compiledExpr: "",
         statement: "定额基价人工费"
     },
     {
-        type: 'profit', code: "3", name: "利润",
+        type: 'profit', code: "3", name: "利润", feeRate: 13,
         dispExpr: "1.1.1", expression: "at('1.1.1')", compiledExpr: "",
         statement: "定额基价人工费"
     },
@@ -295,7 +295,8 @@ let rationCalcObj = {
         let result = {};
         for (let field of this.calcFields) {
             let calcExpr = this.getCalcExpr(field.expression);
-            field.fee = calcEvaluate(calcExpr).toDecimal(2);
+            let feeRate = (field.feeRate && field.feeRate !== 0) ? field.feeRate : 1;
+            field.fee = (calcEvaluate(calcExpr) * feeRate).toDecimal(2);
             result[field.type] = field.fee;
         }
         return result;
@@ -313,7 +314,8 @@ class RationCalcHelper {
         calcFees.checkFields(ration, rationCalcFields);
         for (let field of rationCalcFields) {
             let calcExpr = rationCalcObj.getCalcExpr(field.expression);
-            field.fee = calcEvaluate(calcExpr).toDecimal(2);
+            let feeRate = (field.feeRate && field.feeRate !== 0) ? field.feeRate : 1;
+            field.fee = (calcEvaluate(calcExpr) * feeRate).toDecimal(2);
             ration.feesIndex[field.type].unitFee = field.fee;
             ration.feesIndex[field.type].totalFee = (field.fee * calcFees.getFee(ration, 'quantity')).toDecimal(2);
             calcExpr = null;
@@ -322,10 +324,7 @@ class RationCalcHelper {
 
     calculateAll () {
         for (let rationData of this.project.Ration.datas) {
-            let cnt = 1;
-            for (let i = 0 ; i< cnt; i++) {
-                this.calculate(rationData);
-            }
+            this.calculate(rationData);
         }
     };
 }

+ 15 - 1
web/building_saas/main/js/models/ration_calc.js

@@ -368,4 +368,18 @@ let calcTemplate = {
             statement: "基价直接工程费+企业管理费+利润+风险因素+人材机价差"
         }
     ]
-};
+};
+
+class RationCalc {
+    constructor(project){
+        this.project = project;
+    };
+
+    calculate(ration){
+        let calc = new calculation();
+        calc.init(calcTemplate, calcFeeRate);
+        calc.compile();
+        ration.data.gljList = projectObj.project.ration_glj.getGljArrByRation(ration.data.ID);
+        calc.calculate(ration);
+    };
+}

+ 15 - 4
web/building_saas/main/js/models/ration_glj.js

@@ -48,12 +48,21 @@ var ration_glj = {
         };
         ration_glj.prototype.getGatherGljArrByRations = function (rations) {
             let result = [];
+            let clone = function (obj) {
+                if (obj === null) return null;
+
+                var o = Object.prototype.toString.apply(obj) === "[object Array]" ? [] : {};
+                for (var i in obj) {
+                    o[i] = (obj[i] instanceof Date) ? new Date(obj[i].getTime()) : (typeof obj[i] === "object" ? clone(obj[i]) : obj[i]);
+                }
+                return o;
+            }
             let findGlj = function (sourceGlj, gljArr) {
-                gljArr.forEach(function (glj) {
+                for (let glj of gljArr) {
                     if (glj.projectGLJID === sourceGlj.projectGLJID) {
-                        return glj
+                        return glj;
                     }
-                });
+                }
                 return null;
             }
             for (let ration of rations) {
@@ -61,7 +70,9 @@ var ration_glj = {
                 for (let glj of rationGljs) {
                     let sameGlj = findGlj(glj, result);
                     if (!sameGlj) {
-                        result.push(glj);
+                        sameGlj = clone(glj);
+                        sameGlj.quantity = (sameGlj.quantity * ration.quantity).toDecimal(4);
+                        result.push(sameGlj);
                     } else {
                         sameGlj.quantity = sameGlj.quantity + (glj.quantity * ration.quantity).toDecimal(4);
                     }

+ 23 - 2
web/building_saas/main/js/views/main_tree_col.js

@@ -2,8 +2,8 @@
  * Created by Mai on 2017/7/25.
  */
 
-let ColGetText = {
-    mainTree: {
+let MainTreeCol = {
+    getText: {
         type: function (node) {
             if (node.sourceType === projectObj.project.Bills.getSourceType()) {
                 return '';
@@ -15,5 +15,26 @@ let ColGetText = {
                 return '主';
             }
         }
+    },
+    readOnly: {
+        volumePrice: function (node) {
+            return node.sourceType === projectObj.project.VolumePrice.getSourceType();
+        }
+    },
+    getEvent: function (eventName) {
+        let names = eventName.split('.');
+        let event = this;
+        for (let name of names) {
+            if (event[name]) {
+                event = event[name];
+            } else {
+                return null;
+            }
+        }
+        if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
+            return null;
+        } else {
+            return event;
+        }
     }
 }

+ 29 - 4
web/building_saas/main/js/views/project_view.js

@@ -25,8 +25,11 @@ var projectObj = {
             if (!err) {
                 BillsGridSetting.cols.forEach(function (col) {
                     col.data.splitFields = col.data.field.split('.');
-                    if (col.data.field === 'type') {
-                        col.data.getText = ColGetText.mainTree.type;
+                    if (col.data.getText && Object.prototype.toString.apply(col.data.getText) === "[object String]") {
+                        col.data.getText = MainTreeCol.getEvent(col.data.getText);
+                    }
+                    if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
+                        col.readOnly = MainTreeCol.getEvent(col.readOnly);
                     }
                 });
                 that.mainController = TREE_SHEET_CONTROLLER.createNew(that.project.mainTree, that.mainSpread.getActiveSheet(), BillsGridSetting);
@@ -40,8 +43,30 @@ var projectObj = {
                         }
                     };
                     let selected = tree.selected;
-                    setButtonValid(selected && selected.canUpLevel(), $('#upLevel'));
-                    setButtonValid(selected && selected.canDownLevel(), $('#downLevel'));
+                    let canUpLevel = function (node) {
+                        if (selected && selected.depth() > 0 && selected.canUpLevel()) {
+                            if (selected.sourceType === that.project.Bills.getSourceType()) {
+                                return (!selected.nextSibling) || (selected.children.length === 0) || (selected.source.children.length > 0);
+                            } else {
+                                return false;
+                            }
+                        } else {
+                            return false;
+                        }
+                    };
+                    let canDownLevel = function (node) {
+                        if (selected && selected.depth() > 0 && selected.canDownLevel()) {
+                            if (selected.sourceType === that.project.Bills.getSourceType()) {
+                                return (selected.preSibling.children.length === 0) || (selected.preSibling.source.children.length > 0);
+                            } else {
+                                return false;
+                            }
+                        } else {
+                            return false;
+                        }
+                    };
+                    setButtonValid(canUpLevel(selected), $('#upLevel'));
+                    setButtonValid(canDownLevel(selected), $('#downLevel'));
                     setButtonValid(selected && (selected.depth() > 0) && selected.canUpMove(), $('#upMove'));
                     setButtonValid(selected && (selected.depth() > 0) && selected.canDownMove(), $('#downMove'));
                     setButtonValid(selected, $('#delete'));