Преглед изворни кода

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

zhangweicheng пре 7 година
родитељ
комит
be8fd05446

+ 1 - 0
config/gulpConfig.js

@@ -93,6 +93,7 @@ module.exports = {
         'web/building_saas/main/js/models/quantity_detail.js',
         'web/building_saas/main/js/views/glj_view_contextMenu.js',
         'web/building_saas/main/js/views/calc_program_view.js',
+        'web/building_saas/main/js/views/confirm_modal.js'
         'public/web/treeDataHelper.js',
         'public/web/ztree_common.js',
         'public/web/rpt_tpl_def.js',

+ 1 - 1
modules/glj/controllers/glj_controller.js

@@ -109,7 +109,7 @@ class GLJController extends BaseController {
         try {
             // 可编辑的字段
             let editableField = ['is_evaluate', 'unit_price.market_price', 'is_adjust_price', 'mix_ratio.consumption',
-                'supply'];
+                'supply', 'supply_quantity'];
             if (editableField.indexOf(field) < 0) {
                 throw '对应字段不能编辑';
             }

+ 4 - 3
modules/glj/models/glj_list_model.js

@@ -104,7 +104,7 @@ class GLJListModel extends BaseModel {
             let quantityList = {};
             // 整理数据
             for (let tmp of quantityData) {
-                let tmpNum = parseInt(tmp.rationQuantity);
+                let tmpNum = parseFloat(tmp.rationQuantity);
                 tmpNum = isNaN(tmpNum) ? 1 : tmpNum;
                 if (quantityList[tmp.projectGLJID] === undefined) {
                     quantityList[tmp.projectGLJID] = tmp.quantity * tmpNum;
@@ -204,6 +204,7 @@ class GLJListModel extends BaseModel {
             glj.quantity = quantityList[projectGljId] !== undefined ? quantityList[projectGljId] : 0;
             glj.quantity = totalComposition[glj.code] !== undefined ? totalComposition[glj.code] : glj.quantity;
             glj.quantity = compositionConsumption[gljId] !== undefined ?  glj.quantity + compositionConsumption[gljId] : glj.quantity;
+            glj.quantity = parseFloat(glj.quantity).toFixed(3);
 
             // 组成物数据
             gljList[index].ratio_data = mixRatioData[gljId] !== undefined ? mixRatioData[gljId] : [];
@@ -421,7 +422,7 @@ class GLJListModel extends BaseModel {
     async compositionInit(data, unitPriceFileId) {
         let gljId = data.glj_id === undefined ? 0 : data.glj_id;
         let projectId = data.project_id === undefined ? 0 : data.project_id;
-        if (code === 0 || projectId === 0) {
+        if (gljId === 0 || projectId === 0) {
             throw '参数错误';
         }
         let fromTable = data.from === undefined ? 'std' : data.from;
@@ -521,7 +522,7 @@ class GLJListModel extends BaseModel {
             }
 
             // 查找对应的项目工料机数据
-            let [gljData, compositionList] = await this.getCompositionGLJList(projectGLJData.code, projectGLJData.project_id);
+            let [gljData, compositionList] = await this.getCompositionGLJList(projectGLJData.glj_id, projectGLJData.project_id);
 
             if (gljData.length <= 0) {
                 throw '没有对应的组成物项目工料机';

+ 1 - 0
modules/main/facade/labour_coe_facade.js

@@ -59,6 +59,7 @@ function getData(projectID, callback) {
         if (!err) {
             // 旧项目没有人工系数文件,默认给它生成一个。
             if (!datas) {
+                logger.info(`Create a LabourCoe file for old project : ${projectID}`);
                 getStdLabourCoe(1).then(function (stdLC) {
                     let doc = {
                         ID: uuidV1(),

modules/main/models/labour_coe.js → modules/main/models/labour_coe_model.js


+ 1 - 1
server.js

@@ -29,7 +29,7 @@ fileUtils.getGlobbedFiles('./modules/reports/models/*.js').forEach(function(mode
 })
 
 // 引入人工系数模块
-require('./modules/main/models/labour_coe');
+require('./modules/main/models/labour_coe_model');
 
 //config.setupCache();
 let cfgCacheUtil = require("./config/cacheCfg");

+ 1 - 0
web/building_saas/complementary_glj_lib/js/components.js

@@ -237,6 +237,7 @@ let componentOprObj = {
             }
             updateArr.push(re.currentGlj);
             that.updateComponent(updateArr);
+            $('#componentsCacnel').click();
         });
     }
 };

+ 6 - 1
web/building_saas/glj/js/common_spread.js

@@ -49,7 +49,12 @@ CommonSpreadJs.prototype.init = function(target) {
     this.sheet.autoGenerateColumns = false;
     // 设置表单不可编辑
     this.sheet.options.isProtected = true;
-
+    this.sheet.options.protectionOptions = {
+        allowSelectLockedCells: true,
+        allowSelectUnlockedCells: true,
+        allowResizeRows: true,
+        allowResizeColumns: true
+    };
     return this.spread;
 };
 

+ 10 - 5
web/building_saas/glj/js/project_glj_spread.js

@@ -244,6 +244,7 @@ ProjectGLJSpread.prototype.specialColumn = function (sourceData) {
     let connectCodeColumn = this.sheetObj.getFieldColumn('connect_code');
     let consumptionColumn = this.sheetObj.getFieldColumn('consumption');
     let supplyColumn = this.sheetObj.getFieldColumn('supply');
+    let supplyQuantity = this.sheetObj.getFieldColumn('supply_quantity');
     let activeSheet = this.sheetObj.getSheet();
 
     for (let data of sourceData) {
@@ -256,16 +257,20 @@ ProjectGLJSpread.prototype.specialColumn = function (sourceData) {
             activeSheet.getCell(rowCounter, isEvaluateColumn, GC.Spread.Sheets.SheetArea.viewport).locked(true);
             activeSheet.setValue(rowCounter, isEvaluateColumn, '');
         }
-
+        // 设置供货方式列是否可选
+        if (this.supplyReadonlyType.indexOf(data.unit_price.type) >= 0) {
+            // 锁定该单元格
+            activeSheet.getCell(rowCounter, supplyColumn,  GC.Spread.Sheets.SheetArea.viewport).locked(true);
+        }
+        // 如果为部分甲供或者为全部甲供则甲供数量需要可编辑
+        if (data.supply === 1 || data.supply === 2) {
+            activeSheet.getCell(rowCounter, supplyQuantity,  GC.Spread.Sheets.SheetArea.viewport).locked(false);
+        }
         // 供货方式数据
         let supplyIndex = parseInt(data.supply);
         supplyIndex = isNaN(supplyIndex) ? 0 : supplyIndex;
         let supplyText = this.supplyType[supplyIndex] !== undefined ? this.supplyType[supplyIndex] : '自行采购';
         activeSheet.setValue(rowCounter, supplyColumn, supplyText);
-        if (this.supplyReadonlyType.indexOf(data.unit_price.type) >= 0) {
-            // 锁定该单元格
-            activeSheet.getCell(rowCounter, supplyColumn,  GC.Spread.Sheets.SheetArea.viewport).locked(true);
-        }
 
         // 如果类型为混凝土、砂浆、配合比、机械,则市场单价和供货方式不能修改
         if (canNotChangeTypeId.indexOf(data.unit_price.type) >= 0) {

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

@@ -539,6 +539,25 @@
             </div>
         </div>
     </div>
+    <!--弹出清单单位选择设置-->
+    <div class="modal fade" id="std_bills_unit" data-backdrop="static">
+        <div class="modal-dialog modal-lg" role="document">
+            <div class="modal-content">
+                <div class="modal-header">
+                    <h5 class="modal-title"><i class="fa fa-table"></i> 请选择清单计量单位</h5>
+                    <button type="button" class="close" id='std_bills_unit_close' aria-label="Close">
+                        <span aria-hidden="true">&times;</span>
+                    </button>
+                </div>
+                <div class="modal-body modal-auto-height" id="std_bills_unit_spread" style="height: 200px; overflow: hidden;">
+                </div>
+                <div class="modal-footer">
+                    <a href="javascript:void(0);" id="std_bills_unit_ok" class="btn btn-primary">确定</a>
+                    <button type="button" class="btn btn-secondary" id='std_bills_unit_cancel'>关闭</button>
+                </div>
+            </div>
+        </div>
+    </div>    
     <!--弹出列设置-->
     <div class="modal fade" id="column" data-backdrop="static">
         <div class="modal-dialog modal-lg" role="document">
@@ -719,6 +738,7 @@
     <script type="text/javascript" src="/web/building_saas/main/js/models/quantity_detail.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/views/glj_view_contextMenu.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/views/calc_program_view.js"></script>
+    <script type="text/javascript" src='/web/building_saas/main/js/views/confirm_modal.js'></script>
     <!-- reports -->
     <script type="text/javascript" src="/public/web/treeDataHelper.js"></script>
     <script type="text/javascript" src="/public/web/ztree_common.js"></script>

+ 7 - 4
web/building_saas/main/js/controllers/project_controller.js

@@ -17,13 +17,16 @@ ProjectController = {
     addBills: function (project, sheetController, std) {
         if (!project || !sheetController) { return null; }
 
-        var target = project.getParentTarget(project.mainTree.selected, 'sourceType', project.Bills.getSourceType());
-        var newSource = null, newNode = null;
+        let target = project.getParentTarget(project.mainTree.selected, 'sourceType', project.Bills.getSourceType());
+        let newSource = null, newNode = null;
+        let parentID = target ? target.source.getParentID() : project.Bills.tree.setting.rootId;
+        let nextSiblingID = target ? target.source.getNextSiblingID() : project.Bills.tree.setting.rootId;
 
         if (std) {
-            newSource = project.Bills.insertStdBills(target ? target.source.getParentID() : project.Bills.tree.setting.rootId, target ? target.source.getNextSiblingID() : project.Bills.tree.setting.rootId, std.data);
+            let newCode = project.Bills.newFormatCode(std.code);
+            newSource = project.Bills.insertStdBills(parentID, nextSiblingID, std, newCode);
         } else {
-            newSource = project.Bills.insertBills(target ? target.source.getParentID() : project.mainTree.setting.rootId, target ? target.source.getNextSiblingID() : project.mainTree.setting.rootId);
+            newSource = project.Bills.insertBills(parentID, nextSiblingID);
         }
         newNode = project.mainTree.insert(target.getParentID(), target.getNextSiblingID());
 

+ 19 - 13
web/building_saas/main/js/models/bills.js

@@ -37,6 +37,9 @@ var Bills = {
                 let uData = JSON.parse(JSON.stringify(data));
                 delete uData.feesIndex;
                 delete uData.flagsIndex;
+                if (uData.quantity) {
+                    uData.quantity = uData.quantity.toFixed(2);
+                }
                 if (uData.fees) {
                     for (let fee of uData.fees) {
                         fee.unitFee = fee.unitFee.toFixed(2);
@@ -85,6 +88,9 @@ var Bills = {
             this.datas = datas;
             // generate Fees & Flags Index, For View & Calculate
             this.datas.forEach(function (data) {
+                if (data.quantity) {
+                    data.quantity = parseFloat(data.quantity);
+                }
                 data.feesIndex = {};
                 if (data.fees) {
                     data.fees.forEach(function (fee) {
@@ -203,6 +209,7 @@ var Bills = {
             project.quantity_detail.deleteByBills(deleteData);
             project.pushNow('deleteBills', modules, deleteDatas);
 
+            this.datas.splice(this.datas.indexOf(node.data), 1);
             return this.tree.delete(node);
         };
 
@@ -250,25 +257,14 @@ var Bills = {
             } else {
                 data[field] = newValue;
             }
-            updateData.push({'updateType': 'ut_update', 'updateData': data});
+            updateData.push({'updateType': 'ut_update', 'updateData': tools.formatBillsUpdateData(data)});
             this.project.pushNow('updateBills', this.getSourceType(), updateData);
         };
 
         bills.prototype.updateAll = function () {
             let updateData = [];
             for (let data of this.datas) {
-                let uData = JSON.parse(JSON.stringify(data));
-                delete uData.feesIndex;
-                delete uData.flagsIndex;
-                if (uData.fees) {
-                    for (let fee of uData.fees) {
-                        fee.unitFee = fee.unitFee.toFixed(2);
-                        fee.totalFee = fee.totalFee.toFixed(2);
-                        fee.tenderUnitFee = fee.tenderUnitFee.toFixed(2);
-                        fee.tenderTotalFee = fee.tenderTotalFee.toFixed(2);
-                    }
-                }
-                updateData.push({'updateType': 'ut_update', 'updateData': uData});
+                updateData.push({'updateType': 'ut_update', 'updateData': tools.formatBillsUpdateData(data)});
             }
             this.project.pushNow('updateAllBills', this.getSourceType(), updateData);
         };
@@ -333,6 +329,16 @@ var Bills = {
 
             this.project.pushNow('replaceBills', this.getSourceType(), updateData);
             return node;            
+        };
+
+        bills.prototype.sameStdCodeBillsData = function (stdCode) {
+            let reg = new RegExp('^' + stdCode);
+            for (let data of this.datas) {
+                if (data.code && data.code.length === 12 && reg.test(data.code) && /^[\d]+$/.test(data.code)) {
+                    return data;
+                }
+            }
+            return null;            
         }
 
         return new bills(project);

+ 27 - 1
web/building_saas/main/js/models/ration.js

@@ -160,7 +160,7 @@ var Ration = {
             return newRation;
         };
         ration.prototype.insertStdRation = function (billsID, preRation, std) {
-            var br = this.getBillsSortRation(billsID), updateData = this.getInsertRationData(billsID, preRation), newRation = null;
+            var br = this.getBillsSortRation(billsID), updateData = this.getInsertRationData(billsID, preRation), newRation = null, that = this;
             updateData.forEach(function (data) {
 
                 if (data.updateType === 'ut_create') {
@@ -175,6 +175,8 @@ var Ration = {
                         data.updateData.ruleText = std.chapter.ruleText;
                     }
                     data.updateData.rationAssList =  projectObj.project.ration_ass.CreateNewAss(std);
+                    // calculate ration Quantity
+                    that.CalculateQuantity(data.updateData);
                     newRation = data.updateData;
                 }
             });
@@ -282,6 +284,28 @@ var Ration = {
             }
         };
 
+        ration.prototype.FilterNumberFromUnit = function (unit) {
+            let reg = new RegExp('^[0-9]+');
+            if (reg.test(unit)) {
+                return parseInt(unit.match(reg)[0]);
+            } else {
+                return 1;
+            }
+        };
+
+        ration.prototype.CalculateQuantity = function (ration) {
+            // calculate ration Quantity
+            if (optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan')) {
+                let billsNode = this.project.Bills.tree.findNode(ration[this.project.masterField.ration]);
+                let billsQuantity = billsNode.data.quantity ? billsNode.data.quantity : 0;
+                if (optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToRationUnit')) {
+                    ration.quantity = (billsQuantity / this.FilterNumberFromUnit(ration.unit)).toDecimal(4);
+                } else {
+                    ration.quantity = billsQuantity.toDecimal(4);
+                }
+            }
+        };
+
         ration.prototype.replaceRation = function (ration, std) {
             this.project.beginUpdate('replaceRation');
             
@@ -306,6 +330,8 @@ var Ration = {
                 ration.ruleText = std.chapter.ruleText;
             }
             ration.rationAssList = projectObj.project.ration_ass.CreateNewAss(std);
+            // calculate ration Quantity
+            this.CalculateQuantity(ration);
             updateData.push({updateType: 'ut_update', updateData: ration});
             this.project.push(this.getSourceType(), updateData);
 

+ 109 - 0
web/building_saas/main/js/views/confirm_modal.js

@@ -0,0 +1,109 @@
+/**
+ * 
+ * Created by Mai on 2017/10/20.
+ */
+
+let ConfirmModal = {  
+    reBind: function (obj, eventName, fun) {
+         obj.unbind(eventName);
+         obj.bind(eventName, fun);
+    },
+    stdBillsUnit: {
+        modalObj: $('#std_bills_unit'),
+        okObj: $('#std_bills_unit_ok'),
+        cancelObj: $('#std_bills_unit_cancel'),
+        closeObj: $('#std_bills_unit_close'),
+        spread: null,
+        setting: {
+            "emptyRows":0,
+            "headRows":1,
+            "headRowHeight":[25],
+            "defaultRowHeight": 21,
+            "cols":[{
+                "width":120,
+                "readOnly":true,
+                "head":{
+                    "titleNames":["编码"],
+                    "spanCols":[1],
+                    "spanRows":[1],
+                    "vAlign":[1],
+                    "hAlign":[1],
+                    "font":["Arial"]
+                },
+                "data":{
+                    "field":"code",
+                    "vAlign":1,
+                    "hAlign":0,
+                    "font":"Arial"
+                }
+            }, {
+                "width":200,
+                "readOnly":true,
+                "head":{
+                    "titleNames":["名称"],
+                    "spanCols":[1],
+                    "spanRows":[1],
+                    "vAlign":[1],
+                    "hAlign":[1],
+                    "font":["Arial"]
+                },
+                "data":{
+                    "field":"name",
+                    "vAlign":1,
+                    "hAlign":0,
+                    "font":"Arial"
+                }
+            }, {
+                "width":50,
+                "readOnly":true,
+                "head":{
+                    "titleNames":["单位"],
+                    "spanCols":[1],
+                    "spanRows":[1],
+                    "vAlign":[1],
+                    "hAlign":[1],
+                    "font":["Arial"]
+                },
+                "data":{
+                    "field":"unit",
+                    "vAlign":1,
+                    "hAlign":1,
+                    "font":"Arial"
+                }
+            }]
+        },
+        check: function (std, okCallBack, cancelCallBack) {
+            if (!this.spread) {
+                this.spread = SheetDataHelper.createNewSpread($('#std_bills_unit_spread')[0]);
+                SheetDataHelper.loadSheetHeader(this.setting, ConfirmModal.stdBillsUnit.spread.getActiveSheet());
+            }
+            let sheet = ConfirmModal.stdBillsUnit.spread.getActiveSheet();
+            let modalObj = this.modalObj;
+            let okFun = function () {
+                modalObj.modal('toggle');
+                if (okCallBack) {
+                    let newStd = JSON.parse(JSON.stringify(std));
+                    newStd.unit = sheet.getText(sheet.getSelections()[0].row, 2);
+                    okCallBack(newStd);
+                }
+            };
+            let cancelFun = function () {
+                modalObj.modal('toggle');
+                if (cancelCallBack) {
+                    cancelCallBack();
+                }
+            };
+            ConfirmModal.reBind(this.okObj, 'click', okFun);
+            ConfirmModal.reBind(this.cancelObj, 'click', cancelFun);
+            ConfirmModal.reBind(this.closeObj, 'click', cancelFun);
+            let datas = [];
+            let units = std.unit.split('/');
+            for (let unit of units) {
+                datas.push({'code': std.code, 'name': std.name, 'unit': unit});
+            }
+            SheetDataHelper.loadSheetData(this.setting, sheet, datas);
+            this.modalObj.modal({backdrop: false, keyboard: false});  
+            ConfirmModal.stdBillsUnit.spread.refresh();  
+        }
+    }
+};

+ 4 - 0
web/building_saas/main/js/views/options_view.js

@@ -56,6 +56,10 @@ let optionsOprObj = {
             }
         }
         return rst;
+    },
+    getOption: function (type, optionName) {
+        let opts = this.getOptsByType(this.options, type);
+        return opts[optionName];
     }
 };
 

+ 13 - 2
web/building_saas/main/js/views/project_view.js

@@ -139,6 +139,7 @@ var projectObj = {
             calcFees.setFee(node.data, fieldName, value);
             calc.calcNode(node, true);
             nodes = getNodes(node);
+            project.Bills.updateNodes(nodes, true);
         } else if (node.sourceType === projectObj.project.VolumePrice.getSourceType()) {
             project.beginUpdate('VolumePrice_QuantityChange');
             project.VolumePrice.updateField(node.source, fieldName, value, false);
@@ -176,11 +177,21 @@ var projectObj = {
                 CommonAjax.post('/stdBillsEditor/getStdBillsByCode', {userId: userID, billsLibId: libId, code: stdCode}, function (data) {
                     if (data) {
                         data.itemCharacter = pageCCOprObj.safeItemCharater(data.itemCharacter);
-                        project.Bills.replaceBills(node.source, data, formatCode);
+                        if (/\//.test(data.unit)) {
+                            ConfirmModal.stdBillsUnit.check(data, function (std) {
+                                project.Bills.replaceBills(node.source, std, formatCode);
+                                projectObj.mainController.refreshTreeNode([node], false);
+                            }, function () {
+                                projectObj.mainController.refreshTreeNode([node], false);
+                            });
+                        } else {
+                            project.Bills.replaceBills(node.source, data, formatCode);
+                            projectObj.mainController.refreshTreeNode([node], false);
+                        }
                     } else {
                         project.Bills.updateField(node.source, 'code', formatCode, true);
+                        projectObj.mainController.refreshTreeNode([node], false);
                     }
-                    projectObj.mainController.refreshTreeNode([node], false);
                 });
             }
         }

+ 15 - 1
web/building_saas/main/js/views/std_bills_lib.js

@@ -144,10 +144,24 @@ var billsLibObj = {
 
             stdBillsTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, showBillsRela);
             that.stdBillsSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (sender, args) {
+                let selectNode = stdBillsTree.items[args.row];
                 if (stdBillsTree.items[args.row].children.length === 0) {
                     //特征及内容转化
                     pageCCOprObj.setItemContentNode(stdBillsTree.items[args.row], getBillsJobs(stdBillsTree.items[args.row]), getBillsFeatures(stdBillsTree.items[args.row]));
-                    ProjectController.addBills(projectObj.project, projectObj.mainController, stdBillsTree.items[args.row]);
+                    if (/\//.test(selectNode.data.unit)) {
+                        let existB = projectObj.project.Bills.sameStdCodeBillsData(selectNode.data.code);
+                        if (existB) {
+                            let std = JSON.parse(JSON.stringify(selectNode.data));
+                            std.unit = existB.unit;
+                            ProjectController.addBills(projectObj.project, projectObj.mainController, std);
+                        } else {
+                            ConfirmModal.stdBillsUnit.check(selectNode.data, function (std) {
+                                ProjectController.addBills(projectObj.project, projectObj.mainController, std);
+                            });
+                        }
+                    } else {
+                        ProjectController.addBills(projectObj.project, projectObj.mainController, selectNode.data);
+                    }
                 }
             });
         }, function () {

+ 3 - 1
web/building_saas/main/js/views/sub_view.js

@@ -84,8 +84,10 @@ $("#linkJSCX").click(function(){        // 计算程序
     refreshSubSpread();
     subSpread.setActiveSheetIndex(4);
     calcProgramObj.initSheet(subSpread.getSheet(4));
-    let sel = projectObj.mainController.tree.selected;
 
+    if (!projectObj.mainController.tree.selected)
+        projectObj.mainController.tree.selected = projectObj.mainController.tree.firstNode();
+    let sel = projectObj.mainController.tree.selected;
     if (sel.sourceType === projectObj.project.Bills.getSourceType() || sel.sourceType === projectObj.project.Ration.getSourceType()) {
         calcProgramObj.showData(sel);
     } else {