소스 검색

volume price: load/insert contextMenu

MaiXinRong 7 년 전
부모
커밋
3deb4fc9db

+ 1 - 1
lib/ztree/jquery.ztree.exedit.js

@@ -241,7 +241,7 @@
 		setSonNodeLevel: function(setting, parentNode, node) {
 			if (!node) return;
 			var childKey = setting.data.key.children;
-			node.level = (parentNode)? parentNode.level + 1 : 0;
+			node.level = (parentNode) ? parentNode.level + 1 : 0;
 			if (!node[childKey]) return;
 			for (var i = 0, l = node[childKey].length; i < l; i++) {
 				if (node[childKey][i]) data.setSonNodeLevel(setting, node, node[childKey][i]);

+ 2 - 1
modules/main/models/proj_counter.js

@@ -11,7 +11,8 @@ class projCounter extends baseModel {
         let projCounterSchema = new Schema({
             projectID: Number,
             bills: Number,
-            ration: Number
+            ration: Number,
+            volume_price: Number
         });
         let projCounterModel = db.model(name, projCounterSchema);
         super(projCounterModel);

+ 2 - 0
modules/main/models/project.js

@@ -9,6 +9,7 @@ var ration_coe_data = require('../../ration_glj/facade/ration_coe_facade');
 var ration_ass_data = require('../../ration_glj/facade/ration_ass_facade');
 var quantity_detail_data = require('../../ration_glj/facade/quantity_detail_facade');
 let projCounter = require('./proj_counter');
+let volumePriceData = require('../../volume_price/models/volume_price_model');
 var consts = require('./project_consts');
 var projectConsts = consts.projectConst;
 var async = require("async");
@@ -23,6 +24,7 @@ moduleMap[projectConsts.RATION_COE] = ration_coe_data;
 moduleMap[projectConsts.RATION_ASS] = ration_ass_data;
 moduleMap[projectConsts.QUANTITY_DETAIL] = quantity_detail_data;
 moduleMap[projCounter.collectionName] = projCounter;
+moduleMap[volumePriceData.collectionName] = volumePriceData;
 
 
 var Project = function (){};

+ 2 - 2
modules/main/models/project_consts.js

@@ -12,8 +12,8 @@ var projectConst = {
     PROJECTGLJ: 'projectGLJ',
     GLJLIST: 'GLJList',
     UNITPRICEFILE: 'unitPriceFile',
-    PROPERTIES: 'properties'
-
+    PROPERTIES: 'properties',
+    VOLUMEPRICE: 'volume_price'
 };
 
 var commonConst = {

+ 2 - 0
modules/pm/controllers/copy_proj_controller.js

@@ -5,6 +5,7 @@
 let billsData = require('../../main/models/bills');
 let rationData = require('../../main/models/ration');
 let projCounter = require('../../main/models/proj_counter');
+let volumePriceData = require('../../volume_price/models/volume_price_model');
 let async = require('async');
 
 module.exports = {
@@ -29,6 +30,7 @@ module.exports = {
         fun.push(copyData(billsData));
         fun.push(copyData(rationData));
         fun.push(copyData(projCounter));
+        fun.push(copyData(volumePriceData));
         async.parallel(fun, (err) => callback(err));
     }
 };

+ 1 - 1
modules/pm/models/project_schema.js

@@ -20,7 +20,7 @@ let ProjectSchema = new Schema({
     'fullFolder': Array
 });
 
-module.exports = mongoose.model(collectionName, ProjectSchema)
+module.exports = mongoose.model(collectionName, ProjectSchema);
 
 
 

+ 66 - 0
modules/volume_price/models/volume_price_model.js

@@ -0,0 +1,66 @@
+/**
+ * Created by Mai on 2017/7/25.
+ */
+
+let consts = require('../../main/models/project_consts');
+let commonConsts = consts.commonConst;
+
+let mongoose = require('mongoose');
+let volumePrice = require("./volume_price_schema");
+let async = require("async");
+
+let baseModel = require('../../main/models/base_model');
+
+class volumePriceModel extends baseModel {
+    constructor (name) {
+        super(volumePrice);
+        this.collectionName = name;
+    };
+
+    getData (projectID, callback) {
+        volumePrice.find({'$or': [
+            {
+                projectID: projectID,
+                deleteInfo: null
+            }, {
+                projectID: projectID,
+                'deleteInfo.deleted': {$in: [null, false]}
+            }
+        ]},(err,datas)=>{
+            if(err){
+                callback(1, '', null);
+            }else {
+                callback(0, consts.projectConst.VOLUMEPRICE, datas);
+            }
+        })
+    };
+
+    save (user_id, datas, callback) {
+        let funs = [];
+
+        function saveOne(doc) {
+            return function (cb) {
+                switch (doc.updateType) {
+                    case commonConsts.UT_UPDATE:
+                        volumePrice.update({projectID: doc.updateData.projectID, ID: doc.updateData.ID}, doc.updateData, cb);
+                        break;
+                    case commonConsts.UT_CREATE:
+                        volumePrice.create(doc.updateData, cb);
+                        break;
+                    case commonConsts.UT_DELETE:
+                        doc.updateData.deleteInfo = {deleted: true, deleteDateTime: new Date(), deleteBy: user_id};
+                        volumePrice.update({projectID: doc.updateData.projectID, ID: doc.updateData.ID}, doc.updateData, cb);
+                        break;
+                }
+            }
+        }
+        for (let data of datas){
+            funs.push(saveOne(data));
+        }
+
+        async.parallel(funs, callback);
+    };
+
+};
+
+module.exports = new volumePriceModel(consts.projectConst.VOLUMEPRICE);

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

@@ -0,0 +1,33 @@
+/**
+ * Created by Mai on 2017/7/25.
+ * 量价
+ */
+
+let mongoose = require("mongoose");
+let Schema = mongoose.Schema;
+let deleteSchema = require('../../../public/models/delete_schema');
+let subSchema = require('../../main/models/bills_sub_schemas');
+
+let collectionName = 'volume_price';
+let volumePriceSchema = new Schema({
+    // id
+    ID: Number,
+    // 关联pm
+    projectID: Number,
+    // 关联 Bills
+    billsItemID: Number,
+    // 排序
+    serialNo: Number,
+    // 名称
+    name: String,
+    // 单位
+    unit: String,
+    // 数量
+    quantity: Number,
+    // 费用字段
+    fees: [subSchema.feesSchema],
+    // 是否删除
+    deleteInfo: deleteSchema
+});
+
+module.exports = mongoose.model(collectionName, volumePriceSchema);

+ 1 - 1
test/tmp_data/bills_grid_setting.js

@@ -65,7 +65,7 @@ var BillsGridSetting ={
             "data":{
                 "field":"type",
                 "vAlign":1,
-                "hAlign":0,
+                "hAlign":1,
                 "font":"Arial"
             }
         },

+ 3 - 1
test/tmp_data/test_ration_calc/ration_calc_base.js

@@ -27,6 +27,8 @@ const gljType = {
     GENERAL_MACHINE: 301,
     // 机械组成物
     MACHINE_COMPOSITION: 302,
+    // 机上人工
+    MACHINE_LABOUR: 303,
     // ==============机械类型=================
     // 主材
     MAIN_MATERIAL: 4,
@@ -54,7 +56,7 @@ let rationCalcBase = [
         'dispName': '定额基价机上人工费',
         'calcFun': 'base',
         'calcType': baseCalc,
-        'gljTypes': [gljType.MACHINE_COMPOSITION]
+        'gljTypes': [gljType.MACHINE_LABOUR]
     },{
         'dispName': '人工费价差',
         'calcFun': 'diff',

+ 2 - 0
web/building_saas/main/html/main.html

@@ -493,6 +493,7 @@
     <script type="text/javascript" src="/web/building_saas/main/js/models/ration_glj.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/ration_coe.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/ration_ass.js"></script>
+    <script type="text/javascript" src="/web/building_saas/main/js/models/volume_price.js"></script>
 
     <script type="text/javascript" src="/public/web/id_tree.js"></script>
     <script type="text/javascript" src="/test/tmp_data/test_ration_calc/ration_calc_base.js"></script>
@@ -510,6 +511,7 @@
     <script type="text/javascript" src="/test/tmp_data/test_bills_calc/bills_data_15690.js"></script>
     <script type="text/javascript" src="/test/tmp_data/test_bills_calc/drawing_data_10268.js"></script>-->
     <!-- view -->
+    <script type="text/javascript" src="/web/building_saas/main/js/views/main_tree_col.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/views/project_info.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/views/project_view.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/main_ajax.js"></script>

+ 10 - 2
web/building_saas/main/js/calc/bills_calc.js

@@ -92,6 +92,14 @@ class BillsCalc {
         this.InitFields(this.calcFieldName);
     };
 
+    getBillsGLjs (node) {
+        let rations = this.project.Ration.getBillsSortRation(node.source.getID());
+        let gljs = this.project.ration_glj.getGatherGljArrByRations(rations);
+        for (let glj of gljs) {
+            glj.quantity = (glj.quantity / calcFees.getFee(node.data, 'quantity')).toDecimal(4);
+        }
+        return gljs;
+    };
     calcLeaf (node, fields) {
         nodeCalcObj.node = node;
         nodeCalcObj.digit = this.digit;
@@ -100,8 +108,8 @@ class BillsCalc {
 
         // 清单单价:套用定额计算程序
         if (this.CalcFlag === billsPrice) {
-            let rations = this.project.Ration.getBillsSortRation(node.source.getID());
-            rationCalcObj.calcGljs = this.project.ration_glj.getGatherGljArrByRations(rations);
+            rationCalcObj.calcGljs = this.getBillsGLjs(node);
+            console.log(rationCalcObj.calcGljs);
             rationCalcObj.calcFields = rationCalcFields;
             virData = rationCalcObj.calculate();
         }

+ 24 - 0
web/building_saas/main/js/controllers/project_controller.js

@@ -68,6 +68,30 @@ ProjectController = {
             this.syncDisplayNewNode(sheetController, newNode);
         }
     },
+    addVolumePrice: function (project, sheetController) {
+        if (!project || !sheetController) { return null; }
+
+        var selected = project.mainTree.selected;
+        var newSource = null, newNode = null;
+        if(selected === null) {
+            return;
+        }
+
+        if (selected.sourceType === project.Bills.getSourceType() && selected.source.children.length === 0) {
+            newSource = project.VolumePrice.insertVolumePrice(selected.source.getID());
+            newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID());
+        } else if (selected.sourceType === project.VolumePrice.getSourceType()) {
+            newSource = project.VolumePrice.insertVolumePrice(selected.source[project.masterField.volumePrice], selected.source);
+            newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
+        }
+        if (newNode) {
+            newNode.source = newSource;
+            newNode.sourceType = project.VolumePrice.getSourceType();
+            newNode.data = newSource;
+
+            this.syncDisplayNewNode(sheetController, newNode);
+        }
+    },
     calculateAll: function (project, sheetController, CalcType) {
         let date0 = new Date();
         let ration_calc = new RationCalc(project);

+ 2 - 1
web/building_saas/main/js/models/main_consts.js

@@ -10,5 +10,6 @@ const ModuleNames = {
     ration_glj:'ration_glj',
     ration_coe:'ration_coe',
     ration_ass:'ration_ass',
-    quantity_detail:'quantity_detail'
+    quantity_detail:'quantity_detail',
+    volume_price: 'volume_price'
 };

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

@@ -73,8 +73,9 @@ var PROJECT = {
             this.ration_ass = ration_ass.createNew(this);
             this.quantity_detail = quantity_detail.createNew(this);
             this.FeeRate = FeeRate.createNew(this);
+            this.VolumePrice = VolumePrice.createNew(this);
 
-            this.masterField = {ration: 'billsItemID'};
+            this.masterField = {ration: 'billsItemID', volumePrice: 'billsItemID'};
         };
 
         // prototype用于定义public方法
@@ -102,6 +103,15 @@ var PROJECT = {
                     newNode.data = br[i];
                 }
             };
+            let loadVolumePriceNode = function (cacheNode) {
+                let newNode = null, bv = that.VolumePrice.getBillsSortVolumePrice(cacheNode.source.getID());
+                for (let v of bv) {
+                    newNode = that.mainTree.addNode(cacheNode);
+                    newNode.source = v;
+                    newNode.sourceType = that.VolumePrice.getSourceType();
+                    newNode.data = v;
+                }
+            };
             var loadIdTreeNode = function (nodes, parent) {
                 var newNode, i;
                 for (i = 0; i < nodes.length; i++) {
@@ -112,6 +122,7 @@ var PROJECT = {
 
                     if (nodes[i].children.length === 0) {
                         loadRationNode(that.Ration.datas, newNode);
+                        loadVolumePriceNode(newNode);
                     } else {
                         loadIdTreeNode(nodes[i].children, newNode);
                     }

+ 10 - 10
web/building_saas/main/js/models/ration_glj.js

@@ -81,16 +81,16 @@ var ration_glj = {
                     this.refreshAfterSave(data);
                 }
             }
-        };
-        ration_glj.prototype.refreshAfterSave=function(data){
-            if(projectObj.project.ration_glj.datas&&Array.isArray(projectObj.project.ration_glj.datas)){
-                projectObj.project.ration_glj.datas = projectObj.project.ration_glj.datas.concat(data);
-            }else {
-                projectObj.project.ration_glj.datas = data;
-            }
-            sheetCommonObj.showData(gljOprObj.sheet,gljOprObj.setting,data);
-            gljOprObj.sheetData=data;
-            // SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
+            ration_glj.prototype.refreshAfterSave=function(data){
+                if(projectObj.project.ration_glj.datas&&Array.isArray(projectObj.project.ration_glj.datas)){
+                    projectObj.project.ration_glj.datas = projectObj.project.ration_glj.datas.concat(data);
+                }else {
+                    projectObj.project.ration_glj.datas = data;
+                }
+                sheetCommonObj.showData(gljOprObj.sheet,gljOprObj.setting,data);
+                gljOprObj.sheetData=data;
+                // SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
+            };
         };
         ration_glj.prototype.refreshAfterUpdate=function(data){
             var me = this;

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

@@ -0,0 +1,93 @@
+/**
+ * Created by Mai on 2017/7/25.
+ */
+
+var VolumePrice = {
+    createNew: function (project) {
+        let tools = {
+            owner: project
+        };
+
+        class volumePrice {
+            constructor () {
+                this.datas = [];
+
+                let maxID = 0;
+                this.getNewID = function () {
+                    return maxID += 1;
+                };
+                this.maxID = function (ID) {
+                    if (arguments.length === 0) {
+                        return maxID;
+                    } else {
+                        maxID = Math.max(ID, maxID);
+                    }
+                };
+                tools.owner.registerModule(ModuleNames.volume_price, this);
+            };
+
+            getProject () {
+                return tools.owner;
+            };
+            getSourceType () {
+                return ModuleNames.volume_price;
+            };
+
+            loadData (datas) {
+                this.datas = datas;
+            };
+            setMaxID (ID) {
+                this.maxID(ID);
+            }
+
+            getTempVolumePrice (newID, billsID, serialNo) {
+                var newData = {'ID': newID, 'serialNo': serialNo, projectID: tools.owner.ID()};
+                newData[project.masterField.volumePrice] = billsID;
+                return newData;
+            };
+            getBillsSortVolumePrice (billsID) {
+                var arr = this.datas.filter(function (data) {
+                    return data[tools.owner.masterField.volumePrice] === billsID;
+                });
+                arr.sort(function (x, y) {
+                    return x.serialNo - y.serialNo;
+                });
+                return arr;
+            };
+
+            getInsertVolumePriceData (billsID, pre) {
+                let bv = this.getBillsSortVolumePrice(billsID);
+                let updateData = [];
+                if (pre) {
+                    let preIndex = bv.indexOf(pre), i;
+                    updateData.push({updateType: 'ut_create', updateData: this.getTempVolumePrice(this.maxID() + 1, billsID, preIndex < bv.length - 1 ? bv[preIndex + 1].serialNo : bv[preIndex].serialNo + 1)});
+                    for (i = preIndex + 1; i < br.length; i++) {
+                        updateData.push({updateType: 'ut_update', updateData: this.getTempVolumePrice(bv[i].ID, billsID, i < bv.length - 1 ? bv[i+1].serialNo : bv[i].serialNo + 1)});
+                    }
+                } else {
+                    updateData.push({updateType: 'ut_create', updateData: this.getTempVolumePrice(this.maxID() + 1, billsID, bv.length > 0 ? bv[bv.length - 1].serialNo + 1 : 1)});
+                }
+                return updateData;
+            };
+            insertVolumePrice (billsID, pre) {
+                tools.owner.pushNow('insertVolumePrice', [this.getSourceType()], [this.getInsertVolumePriceData(billsID, pre)]);
+
+                let bv = this.getBillsSortVolumePrice(billsID), newVP = null;
+                if (pre) {
+                    let preIndex = bv.indexOf(pre);
+                    newVP = this.getTempVolumePrice(this.getNewID(), billsID, preIndex < bv.length - 1 ? bv[preIndex + 1].serialNo : bv[preIndex].serialNo + 1);
+                    this.datas.push(newVP);
+                    for (let i = preIndex + 1; i < bv.length; i++) {
+                        bv[i].serialNo = i < bv.length - 1 ? bv [i + 1].serialNo : bv[i].serialNo + 1;
+                    }
+                } else {
+                    newVP = this.getTempVolumePrice(this.getNewID(), billsID, bv.length > 0 ? bv[bv.length - 1].serialNo + 1 : 1);
+                    this.datas.push(newVP);
+                }
+                return newVP;
+            }
+        }
+
+        return new volumePrice();
+    }
+}

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

@@ -0,0 +1,19 @@
+/**
+ * Created by Mai on 2017/7/25.
+ */
+
+let ColGetText = {
+    mainTree: {
+        type: function (node) {
+            if (node.sourceType === projectObj.project.Bills.getSourceType()) {
+                return '';
+            } else if (node.sourceType === projectObj.project.Ration.getSourceType()) {
+                return '定';
+            } else if (node.sourceType === projectObj.project.VolumePrice.getSourceType()) {
+                return '量';
+            } else if (node.sourceType === projectObj.project.ration_glj.getSourceType()) {
+                return '主';
+            }
+        }
+    }
+}

+ 44 - 18
web/building_saas/main/js/views/project_view.js

@@ -25,6 +25,9 @@ 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;
+                    }
                 });
                 that.mainController = TREE_SHEET_CONTROLLER.createNew(that.project.mainTree, that.mainSpread.getActiveSheet(), BillsGridSetting);
                 that.mainController.showTreeData();
@@ -36,11 +39,12 @@ var projectObj = {
                             btn.addClass('disabled');
                         }
                     };
-                    setButtonValid(tree.selected && tree.selected.canUpLevel(), $('#upLevel'));
-                    setButtonValid(tree.selected && tree.selected.canDownLevel(), $('#downLevel'));
-                    setButtonValid(tree.selected && tree.selected.canUpMove(), $('#upMove'));
-                    setButtonValid(tree.selected && tree.selected.canDownMove(), $('#downMove'));
-                    setButtonValid(tree.selected ? true : false, $('#delete'));
+                    let selected = tree.selected;
+                    setButtonValid(selected && selected.canUpLevel(), $('#upLevel'));
+                    setButtonValid(selected && selected.canDownLevel(), $('#downLevel'));
+                    setButtonValid(selected && (selected.level > 0) && selected.canUpMove(), $('#upMove'));
+                    setButtonValid(selected && (selected.level > 0) && selected.canDownMove(), $('#downMove'));
+                    setButtonValid(selected, $('#delete'));
                 });
 
               /*  if(!projectObj.gljSpreed){
@@ -92,7 +96,13 @@ var projectObj = {
                             if (selected.sourceType === project.Ration.getSourceType()) {
                                 return false;
                             } else if (selected.sourceType === project.Bills.getSourceType()) {
-                                return selected.source.children.length !== 0;
+                                if (selected.source.children.length === 0) {
+                                    return selected.children.length !== 0 ? selected.firstChild().sourceType !== project.Ration.getSourceType() : false;
+                                } else {
+                                    return true;
+                                }
+                            } else if (selected.sourceType === project.VolumePrice.getSourceType()) {
+                                return true;
                             };
                         } else {
                             return true;
@@ -109,13 +119,22 @@ var projectObj = {
                         var selected = project.mainTree.selected;
                         if (selected) {
                             if (selected.sourceType === project.Ration.getSourceType()) {
-                                return false;
+                                return true;
                             } else if (selected.sourceType === project.Bills.getSourceType()) {
-                                return selected.source.children.length !== 0;
+                                if (selected.source.children.length === 0) {
+                                    return selected.children.length !== 0 ? selected.firstChild().sourceType !== project.VolumePrice.getSourceType() : false;
+                                } else {
+                                    return true;
+                                }
+                            } else if (selected.sourceType === project.VolumePrice.getSourceType()) {
+                                return true;
                             };
                         } else {
                             return true;
                         }
+                    },
+                    callback: function (key, opt) {
+                        ProjectController.addVolumePrice(project, controller);
                     }
                 },
                 "spr1": '--------',
@@ -174,6 +193,8 @@ $('#insert').click(function () {
         ProjectController.addBills(project, controller);
     } else if (selected.sourceType === project.Ration.getSourceType()) {
         ProjectController.addRation(project, controller);
+    } else if (selected.sourceType === project.VolumePrice.getSourceType()) {
+        ProjectController.addVolumePrice(project, controller);
     }
 });
 $('#delete').click(function () {
@@ -189,6 +210,9 @@ $('#delete').click(function () {
             project.ration_glj.deleteByRation(selected.source);
             project.ration_coe.deleteByRation(selected.source);
             controller.delete();
+        } else if (selected.sourceType === project.VolumePrice.getSourceType()) {
+            project.VolumePrice.delete(selected.source);
+            controller.delete();
         };
     }
 });
@@ -219,21 +243,23 @@ $('#upMove').click(function () {
     } else if (selected.sourceType === project.Ration.getSourceType()) {
         project.Ration.changePos(selected.source, selected.preSibling.source);
         controller.upMove();
-    }
-    if (selected) {
+    } else if (selected.sourceType === project.VolumePrice.getSourceType()) {
+        project.VolumePrice.changePos(selected.source, selected.preSibling.source);
+        controller.upMove();
     }
 });
 $('#downMove').click(function () {
     var controller = projectObj.mainController, project = projectObj.project;
     var selected = controller.tree.selected, next, nextSerialNo;
 
-    if (selected) {
-        if (selected.sourceType === project.Bills.getSourceType()) {
-            project.Bills.downMoveBills(selected.source);
-            controller.downMove();
-        } else if (selected.sourceType === project.Ration.getSourceType()) {
-            project.Ration.changePos(selected.source, selected.nextSibling.source);
-            controller.downMove();
-        }
+    if (selected.sourceType === project.Bills.getSourceType()) {
+        project.Bills.downMoveBills(selected.source);
+        controller.downMove();
+    } else if (selected.sourceType === project.Ration.getSourceType()) {
+        project.Ration.changePos(selected.source, selected.nextSibling.source);
+        controller.downMove();
+    } else if (selected.sourceType === project.VolumePrice.getSourceType()) {
+        project.VolumePrice.changePos(selected.source, selected.nextSibling.source);
+        controller.downMove();
     }
 });