Browse Source

mainTree: modify 'quantity'

MaiXinRong 8 years ago
parent
commit
995b0a66b1

+ 3 - 0
public/web/tree_sheet/tree_sheet_helper.js

@@ -11,6 +11,9 @@ var TREE_SHEET_HELPER = {
         style.hAlign = setting.data.hAlign;
         style.vAlign = setting.data.vAlign;
         style.wordWrap = setting.data.wordWrap;
+        if (setting.data.formatter) {
+            style.formatter = setting.data.formatter;
+        }
         return style;
     },
     loadSheetHeader: function (setting, sheet) {

+ 11 - 6
test/tmp_data/bills_grid_setting.js

@@ -316,7 +316,7 @@ var BillsGridSetting ={
         },
         {
             "width":80,
-            "readOnly":false,
+            "readOnly":'readOnly.billsParent',
             "head":{
                 "titleNames":[
                     "工程量"
@@ -341,7 +341,8 @@ var BillsGridSetting ={
                 "field":"quantity",
                 "vAlign":1,
                 "hAlign":2,
-                "font":"Arial"
+                "font":"Arial",
+                "digit": 'common.quantity'
             }
         },
         {
@@ -461,7 +462,8 @@ var BillsGridSetting ={
                 "field":"feesIndex.common.unitFee",
                 "vAlign":1,
                 "hAlign":2,
-                "font":"Arial"
+                "font":"Arial",
+                "digit": 'common.unitFee'
             }
         },
         {
@@ -491,7 +493,8 @@ var BillsGridSetting ={
                 "field":"feesIndex.common.totalFee",
                 "vAlign":1,
                 "hAlign":2,
-                "font":"Arial"
+                "font":"Arial",
+                "digit": 'common.totalFee'
             }
         },
         {
@@ -521,7 +524,8 @@ var BillsGridSetting ={
                 "field":"feesIndex.zangu.unitFee",
                 "vAlign":1,
                 "hAlign":2,
-                "font":"Arial"
+                "font":"Arial",
+                "digit": 'common.unitFee'
             }
         },
         {
@@ -551,7 +555,8 @@ var BillsGridSetting ={
                 "field":"feesIndex.zangu.totalFee",
                 "vAlign":1,
                 "hAlign":2,
-                "font":"Arial"
+                "font":"Arial",
+                "digit": 'common.totalFee'
             }
         },
         {

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

@@ -83,9 +83,9 @@ let calcFees = {
                 }
             } else {
                 if (i == fields.length - 1) {
-                    valueField[fields[i]] = {};
-                } else {
                     valueField[fields[i]] = value;
+                } else {
+                    valueField[fields[i]] = {};
                 };
             }
         }

+ 23 - 2
web/building_saas/main/js/models/bills.js

@@ -178,7 +178,6 @@ var Bills = {
             return this.tree.delete(node);
         };
 
-
         bills.prototype.upMoveBills = function (node) {
             var upMoveData = node.getUpMoveData();
             project.pushNow('upMoveBills', this.getSourceType(), tools.coverseTreeUpdateData(upMoveData, this.project.ID()));
@@ -202,7 +201,29 @@ var Bills = {
             project.pushNow('downLevelBills', [this.getSourceType()], [tools.coverseTreeUpdateData(downLevelData, this.project.ID())]);
 
             return node.downLevel();
-        }
+        };
+
+        bills.prototype.updateField = function (node, field, newValue) {
+            calcFees.setFee(node.data, field, newValue);
+            let updateData = [];
+            let data = {'ID': node.getID(), 'projectID': this.project.ID()};
+            if (field === 'quantity') {
+                data[field] = newValue;
+                // to do Calculate
+                if (node.data.fees) {
+                    data.fees = node.data.fees;
+                }
+            } else if (field === 'feesIndex.common.unitFee') {
+                // to do Calculate
+                if (node.data.fees) {
+                    data.fees = node.data.fees;
+                }
+            } else {
+                data[field] = newValue;
+            }
+            updateData.push({'updateType': 'ut_update', 'updateData': data});
+            this.project.pushNow('updateBills', this.getSourceType(), updateData);
+        };
 
         return new bills(project);
     }

+ 23 - 1
web/building_saas/main/js/models/project.js

@@ -74,6 +74,13 @@ var PROJECT = {
             this.quantity_detail = quantity_detail.createNew(this);
             this.FeeRate = FeeRate.createNew(this);
             this.VolumePrice = VolumePrice.createNew(this);
+            this.Decimal = {
+                common: {
+                    quantity: 2,
+                    unitFee: 2,
+                    totalFee: 2
+                }
+            };
 
             this.masterField = {ration: 'billsItemID', volumePrice: 'billsItemID'};
         };
@@ -90,7 +97,22 @@ var PROJECT = {
 
         project.prototype.projCounter = function () {
             return tools.projCounter;
-        }
+        };
+        project.prototype.getDecimal = function (fullName) {
+            let names = fullName.split('.'), decimal = this.Decimal;
+            for (let name of names) {
+                if (decimal[name]) {
+                    decimal = decimal[name];
+                } else {
+                    return null;
+                }
+            }
+            if (Object.prototype.toString.apply(decimal) === '[object Number]') {
+                return decimal;
+            } else {
+                return null;
+            }
+        };
 
         project.prototype.loadMainTree = function () {
             var that = this;

+ 22 - 0
web/building_saas/main/js/models/ration.js

@@ -229,6 +229,28 @@ var Ration = {
             ration2.serialNo = preSerialNo;
         };
 
+        ration.prototype.updateField = function (ration, field, newValue) {
+            calcFees.setFee(ration, field, newValue);
+            let updateData = [];
+            let data = {'ID': ration.ID, 'projectID': this.project.ID()};
+            if (field === 'quantity') {
+                data[field] = newValue;
+                // to do Calculate
+                if (ration.fees) {
+                    data.fees = ration.fees;
+                }
+            } else if (field === 'feesIndex.common.unitFee') {
+                // to do Calculate
+                if (ration.fees) {
+                    data.fees = ration.fees;
+                }
+            } else {
+                data[field] = newValue;
+            }
+            updateData.push({'updateType': 'ut_update', 'updateData': data});
+            this.project.pushNow('updateBills', this.getSourceType(), updateData);
+        };
+
         return new ration(project);
     }
 };

+ 8 - 8
web/building_saas/main/js/models/volume_price.js

@@ -145,25 +145,25 @@ var VolumePrice = {
                 if (!calcFees.findFee(volumePrice, 'common')) {
                     calcFees.addFee(volumePrice, 'common');
                 }
-                volumePrice.feesIndex.common.totalFee = (volumePrice.feesIndex.common.unitFee * volumePrice.quantity).toDecimal(2);
+                volumePrice.feesIndex.common.totalFee = (volumePrice.feesIndex.common.unitFee * volumePrice.quantity).toDecimal(tools.owner.Decimal.common.totalFee);
                 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()};
+                let data = {'ID': volumePrice.ID, 'projectID': this.getProject().ID()};
+                if (field === 'quantity') {
                     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 if (field === 'feesIndex.common.unitFee') {
+                    this.calculate(volumePrice);
+                    data.fees = volumePrice.fees;
                 } 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);
                 }
+                updateData.push({'updateType': 'ut_update', 'updateData': data});
+                tools.owner.pushNow('updateVolumePrice', this.getSourceType(), updateData);
             }
         }
 

+ 21 - 0
web/building_saas/main/js/views/main_tree_col.js

@@ -19,6 +19,9 @@ let MainTreeCol = {
     readOnly: {
         volumePrice: function (node) {
             return node.sourceType === projectObj.project.VolumePrice.getSourceType();
+        },
+        billsParent: function (node) {
+            return node.sourceType === projectObj.project.Bills.getSourceType() && node.source.children.length > 0;
         }
     },
     getEvent: function (eventName) {
@@ -36,5 +39,23 @@ let MainTreeCol = {
         } else {
             return event;
         }
+    },
+    getNumberFormatter: function (digit) {
+        switch (digit) {
+            case 1:
+                return '0.#';
+            case 2:
+                return '0.##';
+            case 3:
+                return '0.###';
+            case 4:
+                return '0.####';
+            case 5:
+                return '0.#####';
+            case 6:
+                return '0.######';
+            default:
+                return '0.##';
+        }
     }
 }

+ 51 - 10
web/building_saas/main/js/views/project_view.js

@@ -7,25 +7,62 @@ var projectObj = {
     mainSpread: null,
     mainController: null,
     gljSpreed:null,
+    checkCommonField: function (editingText, colSetting) {
+        let value;
+        if (colSetting.data.decimal) {
+            value = Number(editingText);
+            if (number_util.isNumber(value)) {
+                value = value.toDecimal(colSetting.data.decimal);
+            } else {
+                value = null;
+                alert('当前输入的数据类型不正确,请重新输入。');
+            }
+        } else {
+            value = info.editingText;
+        }
+        return value;
+    },
+    checkQuantityField: function (editingText, colSetting) {
+        let value = Number(editingText);
+        if (!value) {
+            let exp = new Expression('');
+            exp.Expression(editingText);
+            value = exp.Evaluate();
+        }
+        if (value) {
+            value = value.toDecimal(colSetting.data.decimal);
+        } else {
+            value = null;
+            alert('当前输入的数据类型不正确,请重新输入。');
+        }
+        return value;
+    },
+    checkSpreadEditingText: function (editingText, colSetting) {
+        if (colSetting.data.field === 'quantity') {
+            return this.checkQuantityField(editingText, colSetting);
+        } else {
+            return this.checkCommonField(editingText, colSetting);
+        }
+    },
     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;
+        let value = projectObj.checkSpreadEditingText(info.editingText, colSetting);
         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;
+        if (value) {
+            if (node.sourceType === project.Bills.getSourceType()) {
+                project.Bills.updateField(node.source, fieldName, value);
+            } else if (node.sourceType === project.Ration.getSourceType()) {
+                project.Ration.updateField(node.source, fieldName, value);
+            } else if (node.sourceType === project.VolumePrice.getSourceType()) {
+                project.VolumePrice.updateField(node.source, fieldName, value);
             }
-        };
+        }
+        projectObj.mainController.refreshTreeNode([node]);
     },
     checkMainSpread: function () {
         if (!this.mainSpread) {
@@ -51,6 +88,10 @@ var projectObj = {
                     if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
                         col.readOnly = MainTreeCol.getEvent(col.readOnly);
                     }
+                    if (col.data.digit && Object.prototype.toString.apply(col.data.digit) === "[object String]") {
+                        col.data.decimal = that.project.getDecimal(col.data.digit);
+                        col.data.formatter = MainTreeCol.getNumberFormatter(col.data.decimal);
+                    }
                 });
                 that.mainController = TREE_SHEET_CONTROLLER.createNew(that.project.mainTree, that.mainSpread.getActiveSheet(), BillsGridSetting);
                 that.mainController.showTreeData();