TonyKang 4 лет назад
Родитель
Сommit
af2ed55fc7

+ 1 - 1
modules/reports/controllers/rpt_controller.js

@@ -244,7 +244,7 @@ function getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, custo
                 if (!err) {
                     let buildPageData = function() {
                         try {
-                            // fsUtil.writeObjToFile(rawDataObj, `D:/GitHome/ConstructionCost/tmp/rawDataObj_${(new Date).getTime()}.jsp`);
+                            // fsUtil.writeObjToFile(rawDataObj, `D:/GitHome/YangHuCost/tmp/rawDataObj_${(new Date).getTime()}.jsp`);
                             let tplData = rptDataUtil.assembleData(rawDataObj);
                             let printCom = JpcEx.createNew();
                             if (pageSize) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;

+ 19 - 1
modules/reports/facade/rpt_tpl_data_facade.js

@@ -7,6 +7,7 @@
 let prjMdl = require('../../../modules/pm/models/project_model');
 let projectDataMdl = require('../../../modules/main/models/project');
 let projectFacade = require('../../../modules/main/facade/project_facade');
+let billsUnitPriceFeatureModel = mongoose.model('std_bills_unitprice_feature_lib');
 
 module.exports = {
     prepareProjectData: prepareProjectData,
@@ -17,10 +18,18 @@ module.exports = {
 function prepareProjectData(userId, prjId, filter, callback) {
     let rawDataObj = null;
     let basicInformation = prjMdl.project.getBasicInfo(prjId);
+    let estUnitPriceFeature = null;
     prjMdl.project.getUserProject(userId, prjId, function(err, msg, rst){
         if (!err) {
             rawDataObj = {};
             rawDataObj.prj = rst;
+            let doc = rst._doc? rst._doc : rst;
+            if (doc.property.engineeringName === '指标估算') {
+                //要加料
+                let conditions = {compilationId: doc.compilation};
+                estUnitPriceFeature = billsUnitPriceFeatureModel.findOne(conditions,{_id: 0}).lean();
+                // billsUnitPriceFeatureModel
+            }
             projectDataMdl.getFilterData(prjId, filter, function (results) {
                 if (results) {
                     rawDataObj.prjData = results;
@@ -29,7 +38,16 @@ function prepareProjectData(userId, prjId, filter, callback) {
                             let doc = (rawDataObj.prj._doc)?rawDataObj.prj._doc:rawDataObj.prj;
                             doc.property.basicInformation = basicRst;
                         }
-                        callback(false, 'Succeeded!', rawDataObj);
+                        if (estUnitPriceFeature) {
+                            estUnitPriceFeature.then( (features) => {
+                                let doc = (rawDataObj.prj._doc)?rawDataObj.prj._doc:rawDataObj.prj;
+                                doc.property.estUnitPriceFeature = features.feature;
+                                // console.log(features);
+                                callback(false, 'Succeeded!', rawDataObj);
+                            });
+                        } else {
+                            callback(false, 'Succeeded!', rawDataObj);
+                        }
                     });
                     // callback(false, 'Succeeded!', rawDataObj);
                 } else {

+ 84 - 180
web/building_saas/main/js/views/std_bills_unit_price_feature.js

@@ -9,15 +9,15 @@
 function _chkIfEquals(orgStr, targetStr) {
     //㎡ ㎥ 立方
     let rst = false;
-    if (orgStr !== null && targetStr !== null) {
+    if (typeof(orgStr) == 'string' && typeof(targetStr) == 'string') {
         let regExp1 = new RegExp('㎡', "gm");
-        let regExp2 = new RegExp('㎥', "gm");
-        let orgS = orgStr.replace(regExp1, 'm2');
-        let targetS = targetStr.replace(regExp2, 'm3');
+        let regExp2 = new RegExp('(', "gm");
+        let regExp3 = new RegExp(')', "gm");
+        let orgS = orgStr.replace(regExp1, 'm2').replace(regExp2, '(').replace(regExp3, ')');
+        let targetS = targetStr.replace(regExp1, 'm2').replace(regExp2, '(').replace(regExp3, ')');
         rst = (orgS === targetS);
     }
     return rst;
-    //
 }
 
 function chkAndSetBillsUnitPrice(billsNodes) {
@@ -25,70 +25,15 @@ function chkAndSetBillsUnitPrice(billsNodes) {
     if (billsUnitPriceFeature !== null) {
         for (const node of billsNodes) {
             if (node.updateType === 'create') {
-                //只有创建的才设置初始化单价
-                let isMatch = true;
-                // 1. 基本数量
-                // 先判断此bills是否有配置
-                let basicValue = 0;
-                for (const bm of billsUnitPriceFeature.feature.basicMappings) {
-                    isMatch = true;
-                    if (bm.parentBasicKeys.length === billsUnitPriceFeature.feature.basicKeyOptions.length) {
-                        for (let kIdx = 0; kIdx < bm.parentBasicKeys.length; kIdx++) {
-                            if (bm.parentBasicKeys[kIdx] !== 'ALL' && !_chkIfEquals(node.updateData[billsUnitPriceFeature.feature.basicKeyOptions[kIdx].key], bm.parentBasicKeys[kIdx]) ) {
-                                isMatch = false;
-                                break;
-                            }
-                        }
-                    } else {
-                        isMatch = false;
-                        break;
-                    }
-                    if (isMatch) {
-                        //再根据相关项目属性指定基数
-                        for (const bms of bm.subs) {
-                            if (chkUnitPriceFeatureKeys(bms.keys)) {
-                                basicValue = bms.basicValue;
-                                break;
-                            }
-                        }
-                        break;
-                    }
-                }
-                // 2. 相关系数(允许多个)
-                let factors = [];
-                for (const fm of billsUnitPriceFeature.feature.factorMappings) {
-                    isMatch = true;
-                    if (fm.basicFactorKeys.length === billsUnitPriceFeature.feature.basicKeyOptions.length) {
-                        for (let kIdx = 0; kIdx < fm.basicFactorKeys.length; kIdx++) {
-                            if (fm.basicFactorKeys[kIdx] !== 'ALL' && !_chkIfEquals(node.updateData[billsUnitPriceFeature.feature.basicKeyOptions[kIdx].key], fm.basicFactorKeys[kIdx]) ) {
-                                isMatch = false;
-                                break;
-                            }
-                        }
-                    } else {
-                        isMatch = false;
-                        break;
-                    }
-                    if (isMatch) {
-                        for (const fms of fm.subs) {
-                            if (chkUnitPriceFeatureKeys(fms.keys)) {
-                                factors.push(fms.basicValue);
-                            }
-                        }
-                        // 允许多个,不break;
-                    }
-                }
-                //3. 装配(指标基价 即 默认的清单单价)
-                let unitFeeVal = basicValue;
-                for (const factor of factors) {
-                    unitFeeVal = unitFeeVal * parseFloat(factor);
-                }
                 // 暂时未设小数位数 scMathUtil.roundTo(unitFeeVal,2);
-                node.updateData.calcFlag = 2; //当用户输入单价
-                if (!node.updateData.hasOwnProperty('fees')) {
-                    node.updateData.fees = [];
+                let unitFeeVal = _commonChkAndSetPrice(node.updateData, true);
+                if (unitFeeVal !== 0) {
+                    node.updateData.calcFlag = 2; //当用户输入单价
+                    if (!node.updateData.hasOwnProperty('fees')) {
+                        node.updateData.fees = [];
+                    }
+                    node.updateData.fees.push({fieldName: 'common', unitFee: unitFeeVal, totalFee: 0, tenderUnitFee: unitFeeVal, tenderTotalFee: 0});
                 }
-                node.updateData.fees.push({fieldName: 'common', unitFee: unitFeeVal, totalFee: 0, tenderUnitFee: unitFeeVal, tenderTotalFee: 0});
             }
         }
     }
@@ -98,38 +43,86 @@ function chkAndResetBills() {
     //用户调整了工程特征后调用
     for (let key in projectObj.project.mainTree.nodes) {
         const node = projectObj.project.mainTree.nodes[key];
-        // 1. 基本数量
-        // 先判断此bills是否有配置
-        let isMatch = true;
-        let basicValue = 0;
-        for (const bm of billsUnitPriceFeature.feature.basicMappings) {
-            // node.data[bm]
-            isMatch = true;
+        let unitFeeVal = _commonChkAndSetPrice(node.data, true);
+        if (unitFeeVal !== 0) {
+            // 暂时未设小数位数 scMathUtil.roundTo(unitFeeVal,2);
+            if (!node.data.hasOwnProperty('fees')) {
+                node.data.fees = [];
+            }
+            for (let idx = node.data.fees.length - 1; idx >= 0; idx--) {
+                if (node.data.fees[idx].fieldName === 'common') {
+                    node.data.fees[idx].unitFee = unitFeeVal;
+                    node.data.fees[idx].tenderUnitFee = unitFeeVal;
+                    node.data.feesIndex.common.unitFee = unitFeeVal;
+                    node.data.feesIndex.common.tenderUnitFee = unitFeeVal;
+                    break;
+                }
+            }
+        }
+    }
+    // 调整了后需要重新计算
+    $.bootstrapLoading.start();
+    projectObj.project.calcProgram.calcAllNodesAndSave(calcAllType.catAll, function () {
+        projectObj.project.projectGLJ.loadData(function () {
+            $.bootstrapLoading.end();
+        });
+    });
+}
+
+function chkAndAddEstUnitPrice(orgBills) {
+    //只显示基本价格,无系数!
+    if (billsUnitPriceFeature !== null) {
+        for (const node of orgBills) {
+            let unitFeeVal = _commonChkAndSetPrice(node, false);
+            if (!isNaN(parseFloat(unitFeeVal))) {
+                unitFeeVal = unitFeeVal.toFixed(2);
+                if (unitFeeVal === '0.00') unitFeeVal = '';
+            }
+            // 暂时未设小数位数 scMathUtil.roundTo(unitFeeVal,2);
+            node.baseEstUnitPrice = unitFeeVal;
+        }
+    }
+}
+
+function _commonChkAndSetPrice(curItem, isNeedFactor) {
+    let rst = 0;
+    let isMatch = true;
+    // 1. 基本数量
+    // 先判断此bills是否有配置
+    let basicValue = 0;
+    for (const bm of billsUnitPriceFeature.feature.basicMappings) {
+        isMatch = true;
+        if (bm.parentBasicKeys.length === billsUnitPriceFeature.feature.basicKeyOptions.length) {
             for (let kIdx = 0; kIdx < bm.parentBasicKeys.length; kIdx++) {
-                if (bm.parentBasicKeys[kIdx] !== 'ALL' && !_chkIfEquals(node.data[billsUnitPriceFeature.feature.basicKeyOptions[kIdx].key], bm.parentBasicKeys[kIdx])) {
+                if (bm.parentBasicKeys[kIdx] !== 'ALL' && !_chkIfEquals(curItem[billsUnitPriceFeature.feature.basicKeyOptions[kIdx].key], bm.parentBasicKeys[kIdx]) ) {
                     isMatch = false;
                     break;
                 }
             }
-            if (isMatch) {
-                //再根据相关项目属性指定基数
-                for (const bms of bm.subs) {
-                    if (chkUnitPriceFeatureKeys(bms.keys)) {
-                        basicValue = bms.basicValue;
-                        break;
-                    }
+        } else {
+            isMatch = false;
+            continue;
+        }
+        if (isMatch) {
+            //再根据相关项目属性指定基数
+            for (const bms of bm.subs) {
+                if (_chkUnitPriceFeatureKeys(bms.keys)) {
+                    basicValue = bms.basicValue;
+                    break;
                 }
-                break;
             }
+            break;
         }
-        if (!isMatch) continue; //未匹配上,下一轮,无需继续
-        // 2. 相关系数(允许多个)
-        let factors = [];
+    }
+    let factors = [];
+    if (!isMatch || !isNeedFactor) {
+        rst = basicValue;
+    } else {
         for (const fm of billsUnitPriceFeature.feature.factorMappings) {
             isMatch = true;
             if (fm.basicFactorKeys.length === billsUnitPriceFeature.feature.basicKeyOptions.length) {
                 for (let kIdx = 0; kIdx < fm.basicFactorKeys.length; kIdx++) {
-                    if (fm.basicFactorKeys[kIdx] !== 'ALL' && !_chkIfEquals(node.data[billsUnitPriceFeature.feature.basicKeyOptions[kIdx].key], fm.basicFactorKeys[kIdx])) {
+                    if (fm.basicFactorKeys[kIdx] !== 'ALL' && !_chkIfEquals(curItem[billsUnitPriceFeature.feature.basicKeyOptions[kIdx].key], fm.basicFactorKeys[kIdx])) {
                         isMatch = false;
                         break;
                     }
@@ -140,7 +133,7 @@ function chkAndResetBills() {
             }
             if (isMatch) {
                 for (const fms of fm.subs) {
-                    if (chkUnitPriceFeatureKeys(fms.keys)) {
+                    if (_chkUnitPriceFeatureKeys(fms.keys)) {
                         factors.push(fms.basicValue);
                     }
                 }
@@ -152,101 +145,12 @@ function chkAndResetBills() {
         for (const factor of factors) {
             unitFeeVal = unitFeeVal * parseFloat(factor);
         }
-        // 暂时未设小数位数 scMathUtil.roundTo(unitFeeVal,2);
-        if (!node.data.hasOwnProperty('fees')) {
-            node.data.fees = [];
-        }
-        for (let idx = node.data.fees.length - 1; idx >= 0; idx--) {
-            if (node.data.fees[idx].fieldName === 'common') {
-                node.data.fees[idx].unitFee = unitFeeVal;
-                node.data.fees[idx].tenderUnitFee = unitFeeVal;
-                node.data.feesIndex.common.unitFee = unitFeeVal;
-                node.data.feesIndex.common.tenderUnitFee = unitFeeVal;
-                break;
-            }
-        }
-    }
-    // 调整了后需要重新计算
-    $.bootstrapLoading.start();
-    projectObj.project.calcProgram.calcAllNodesAndSave(calcAllType.catAll, function () {
-        projectObj.project.projectGLJ.loadData(function () {
-            $.bootstrapLoading.end();
-        });
-    });
-}
-
-function chkAndAddEstUnitPrice(orgBills) {
-    if (billsUnitPriceFeature !== null) {
-        for (const node of orgBills) {
-            //只有创建的才设置初始化单价
-            let isMatch = true;
-            // 1. 基本数量
-            // 先判断此bills是否有配置
-            let basicValue = 0;
-            for (const bm of billsUnitPriceFeature.feature.basicMappings) {
-                isMatch = true;
-                if (bm.parentBasicKeys.length === billsUnitPriceFeature.feature.basicKeyOptions.length) {
-                    for (let kIdx = 0; kIdx < bm.parentBasicKeys.length; kIdx++) {
-                        if (bm.parentBasicKeys[kIdx] !== 'ALL' && !_chkIfEquals(node[billsUnitPriceFeature.feature.basicKeyOptions[kIdx].key], bm.parentBasicKeys[kIdx])) {
-                            isMatch = false;
-                            break;
-                        }
-                    }
-                } else {
-                    isMatch = false;
-                    break;
-                }
-                if (isMatch) {
-                    //再根据相关项目属性指定基数
-                    for (const bms of bm.subs) {
-                        if (chkUnitPriceFeatureKeys(bms.keys)) {
-                            basicValue = bms.basicValue;
-                            break;
-                        }
-                    }
-                    break;
-                }
-            }
-            // 2. 相关系数(允许多个)
-            let factors = [];
-            for (const fm of billsUnitPriceFeature.feature.factorMappings) {
-                isMatch = true;
-                if (fm.basicFactorKeys.length === billsUnitPriceFeature.feature.basicKeyOptions.length) {
-                    for (let kIdx = 0; kIdx < fm.basicFactorKeys.length; kIdx++) {
-                        if (fm.basicFactorKeys[kIdx] !== 'ALL' && !_chkIfEquals(node[billsUnitPriceFeature.feature.basicKeyOptions[kIdx].key], fm.basicFactorKeys[kIdx])) {
-                            isMatch = false;
-                            break;
-                        }
-                    }
-                } else {
-                    isMatch = false;
-                    break;
-                }
-                if (isMatch) {
-                    for (const fms of fm.subs) {
-                        if (chkUnitPriceFeatureKeys(fms.keys)) {
-                            factors.push(fms.basicValue);
-                        }
-                    }
-                    // 允许多个,不break;
-                }
-            }
-            //3. 装配(指标基价 即 默认的清单单价)
-            let unitFeeVal = basicValue;
-            for (const factor of factors) {
-                unitFeeVal = unitFeeVal * parseFloat(factor);
-            }
-            if (!isNaN(parseFloat(unitFeeVal))) {
-                unitFeeVal = unitFeeVal.toFixed(2);
-                if (unitFeeVal === '0.00') unitFeeVal = '';
-            }
-            // 暂时未设小数位数 scMathUtil.roundTo(unitFeeVal,2);
-            node.baseEstUnitPrice = unitFeeVal;
-        }
+        rst = unitFeeVal;
     }
+    return rst;
 }
 
-function chkUnitPriceFeatureKeys(keys) {
+function _chkUnitPriceFeatureKeys(keys) {
     let rst = false;
     for (const subKey of keys) {
         let isPrjFeatureMatch = false;

+ 5 - 4
web/building_saas/pm/js/pm_newMain.js

@@ -2589,15 +2589,16 @@ function initProjectOptSet($target) {
                             ` : ''}
                             ${COMPILATION_NAME.includes('内蒙古高速公路日常养护估算(2021)') ? `
                                 ${_getOptionDivDomStr(ESTIMATION, "valuation-type", "估算", "type-suggestion", true)}
-                                ` : `
-                                `
+                                ` : ``
                             }
                             ${COMPILATION_NAME.includes('广东农村养护(2021)') ? `
                                     ${_getOptionDivDomStr(BUDGET, "valuation-type", "预算", "type-budget", true)}
-                                ` : `
+                                ` : ``
+                            }
+                            ${(COMPILATION_NAME !== '内蒙古高速公路日常养护估算(2021)' && COMPILATION_NAME !== '广东农村养护(2021)') ? `
                                 ${_getOptionDivDomStr(BUDGET, "valuation-type", "预算", "type-budget", !COMPILATION_NAME.includes('公路造价'))}
                                 ${_getOptionDivDomStr(BOQ, "valuation-type", "工程量清单", "type-boq", false)}
-                                `
+                                ` : ``
                             }
                         </div>
                     </div>