فهرست منبع

feat: 变更养护类别、费用标准,费率自动关联变更

vian 4 سال پیش
والد
کامیت
6c39b4b30f
2فایلهای تغییر یافته به همراه46 افزوده شده و 27 حذف شده
  1. 11 4
      modules/pm/controllers/pm_controller.js
  2. 35 23
      web/building_saas/main/js/views/project_view.js

+ 11 - 4
modules/pm/controllers/pm_controller.js

@@ -105,6 +105,7 @@ module.exports = {
     updateMixDatas: async function (req, res) {
         let datas = JSON.parse(req.body.data).mixDataArr;
         let functions = [];
+        let specialResult = {};
 
         function updateFunc(model, cod, doc) {
             return function (cb) {
@@ -134,13 +135,19 @@ module.exports = {
                 const engineeringItem = _.find(datas.properties['property.projectFeature'], { key: 'engineering' });
                 const feeStandardItem = _.find(datas.properties['property.projectFeature'], { key: 'feeStandard' });
                 if (engineeringItem && engineeringItem.value && feeStandardItem && feeStandardItem.value) {
-                    const project = await projectModel.findOne({ ID: datas.projectID }, { 'property.valuation': 1 }).lean();
+                    const project = await projectModel.findOne({ ID: datas.projectID }, { 'property.valuation': 1, 'property.engineering_id': 1 }).lean();
                     if (project) {
-                        const engineering = await engineeringModel.findOne({ valuationID: project.property.valuation, name: engineeringItem.value, feeName: feeStandardItem.value }, { _id: 1 }).lean();
-                        if (engineering) {
+                        const orgEngineeringID = project.property.engineering_id;
+                        const engineering = await engineeringModel.findOne({ valuationID: project.property.valuation, name: engineeringItem.value, feeName: feeStandardItem.value }, { _id: 1, tax_group: 1 }).lean();
+                        if (engineering && orgEngineeringID !== engineering._id.toString()) {
                             datas.properties['property.engineeringName'] = engineeringItem.value;
                             datas.properties['property.feeStandardName'] = feeStandardItem.value;
                             datas.properties['property.engineering_id'] = engineering._id.toString();
+                            if (engineering.tax_group && engineering.tax_group[0] && engineering.tax_group[0].fee_lib) {
+                                // 工程专业变更,需要更改费率
+                                specialResult.newFeeLibID = engineering.tax_group[0].fee_lib.id;
+                            }
+                            
                         }
                     }
                 }
@@ -175,7 +182,7 @@ module.exports = {
         asyncTool.parallel(functions, function (err, result) {
             {
                 if (!err) {
-                    res.json({ error: 0, message: err, data: result });
+                    res.json({ error: 0, message: err, data: specialResult});
                 } else {
                     res.json({ error: 1, message: err, data: null });
                 }

+ 35 - 23
web/building_saas/main/js/views/project_view.js

@@ -2758,32 +2758,44 @@ $('#property_ok').click(function () {
 
     if(hasMixData()){
         CommonAjax.post('/pm/api/updateMixDatas', {user_id: userID, mixDataArr: mixDatas}, function (rstData) {
-            //需要重载页面
-            if(needToReload(mixDatas)){
-                window.location.href = '/main?project=' + projectID;
-            }
-            else{
-                if(mixDatas.properties.hasOwnProperty('property.maxPriceRate')){
-                    projectObj.project.property.maxPriceRate = maxPriceRate;
-                }
-                if(mixDatas.properties.hasOwnProperty('property.minPriceRate')){
-                    projectObj.project.property.minPriceRate = minPriceRate;
-                }
-                if(mixDatas.properties.hasOwnProperty('property.basicInformation')){
-                    basicInfoView.orgDatas = basicInfoView.toViewDatas(mixDatas.properties['property.basicInformation']);
-                }
-                if(mixDatas.properties.hasOwnProperty('property.projectFeature')){
-                    projFeatureView.orgDatas = projFeatureView.toViewDatas(mixDatas.properties['property.projectFeature']);
+            const doAferSuccess = () => {
+                $.bootstrapLoading.end();
+                //需要重载页面
+                if(needToReload(mixDatas)){
+                    window.location.href = '/main?project=' + projectID;
                 }
-                if(mixDatas.options && mixDatas.options.updateData){
-                    let v1 = mixDatas.options.updateData['rationQuanACToBillsQuan'],
-                        v2 = mixDatas.options.updateData['rationQuanACToRationUnit'],
-                        progressiveType = mixDatas.options.updateData['progressiveType']  ;
-                    optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'rationQuanACToBillsQuan', value: v1});
-                    optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'rationQuanACToRationUnit', value: v2});
-                    optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'progressiveType', value: progressiveType});
+                else{
+                    if(mixDatas.properties.hasOwnProperty('property.maxPriceRate')){
+                        projectObj.project.property.maxPriceRate = maxPriceRate;
+                    }
+                    if(mixDatas.properties.hasOwnProperty('property.minPriceRate')){
+                        projectObj.project.property.minPriceRate = minPriceRate;
+                    }
+                    if(mixDatas.properties.hasOwnProperty('property.basicInformation')){
+                        basicInfoView.orgDatas = basicInfoView.toViewDatas(mixDatas.properties['property.basicInformation']);
+                    }
+                    if(mixDatas.properties.hasOwnProperty('property.projectFeature')){
+                        projFeatureView.orgDatas = projFeatureView.toViewDatas(mixDatas.properties['property.projectFeature']);
+                    }
+                    if(mixDatas.options && mixDatas.options.updateData){
+                        let v1 = mixDatas.options.updateData['rationQuanACToBillsQuan'],
+                            v2 = mixDatas.options.updateData['rationQuanACToRationUnit'],
+                            progressiveType = mixDatas.options.updateData['progressiveType']  ;
+                        optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'rationQuanACToBillsQuan', value: v1});
+                        optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'rationQuanACToRationUnit', value: v2});
+                        optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'progressiveType', value: progressiveType});
+                    }
                 }
             }
+            // 需要改变费率
+            if (rstData && rstData.newFeeLibID) {
+                $.bootstrapLoading.start();
+                feeRateObject.feeRateSTDLoaded = false;
+                feeRateObject.feeRateSTDList = [];
+                projectObj.project.FeeRate.changeFeeRateStandard(rstData.newFeeLibID,doAferSuccess);
+            } else {
+                doAferSuccess();
+            }
         });
     }
 });