Browse Source

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

zhongzewei 7 years ago
parent
commit
cfba2632d0

+ 7 - 7
modules/main/facade/labour_coe_facade.js

@@ -87,22 +87,22 @@ function getData(projectID, callback) {
 // needUpdateDatas: [{ID: 5, value: 2.87}, {ID: 13, value: 2.91}]
 function save (data, callback) {
     let updateArr = [];
-    let datas = JSON.parse(data);
+    // let datas = JSON.parse(data);
 
-    if (datas.libID){
+    if (data.libID){
         let ItemObj = {
             updateOne: {
-                filter: {projectID: datas.projectID},
-                update: { 'libID': datas.projectID, 'libName': datas.libName }
+                filter: {projectID: data.projectID},
+                update: { 'libID': data.projectID, 'libName': data.libName }
             }
         };
         updateArr.push(ItemObj);
     };
 
-    for (let Item of datas.newItemArr) {
+    for (let Item of data.newItemArr) {
          let ItemObj = {
              updateOne: {
-                 filter: {projectID: datas.projectID, 'coes.ID': Item.ID},
+                 filter: {projectID: data.projectID, 'coes.ID': Item.ID},
                  update: { 'coes.$.coe': Item.coe }
              }
          };
@@ -111,7 +111,7 @@ function save (data, callback) {
     // console.log(JSON.stringify(updateArr));
     projectLabourCoesModel.bulkWrite(updateArr)
         .then(function(){
-            logger.info(`Project LabourCoe saved successful : ${datas.projectID}`);
+            logger.info(`Project LabourCoe saved successful : ${data.projectID}`);
             callback(0, '', null);
         })
         .catch(function (err) {

+ 20 - 8
modules/pm/controllers/pm_controller.js

@@ -4,6 +4,8 @@
 import UnitPriceFileModel from "../../glj/models/unit_price_file_model";
 let ProjectsData = require('../models/project_model').project;
 let projectM = require('../../main/models/project');
+let projectSchema = require("../models/project_schema");
+let labourCoe = require('../../main/facade/labour_coe_facade');
 let projType = require('../models/project_model').projType;
 let fileType = require('../models/project_model').fileType;
 const engineering = require("../../common/const/engineering");
@@ -68,14 +70,24 @@ module.exports = {
                 callback(req, res, err, message, null);
             }
         };
-        let datas = JSON.parse(req.body.data);
-        for (let data of datas){
-              if (data.sourceType == 'properties'){
-                  ProjectsData.updateUserProjects(req.session.sessionUser.ssoId, data.updateData, callBackInner);
-              }
-              else{
-                projectM.save(data, callBackInner);
-              }
+
+        let datas = JSON.parse(req.body.data).mixDataArr;
+
+        if (datas.labourCoes.updateData){
+            datas.labourCoes.updateData.projectID = datas.projectID;
+            labourCoe.save(datas.labourCoes.updateData, callBackInner);
+        };
+
+        if (datas.rations.length > 0){
+            // projectM.save(data, callBackInner);
+        };
+
+        if (datas.bills.length > 0){
+
+        };
+
+        if (Object.keys(datas.properties).length > 0){
+            projectSchema.update({ID: datas.projectID}, datas.properties, callBackInner);
         };
     },
     updateFiles: async function(req, res){

+ 6 - 3
modules/pm/models/project_model.js

@@ -72,7 +72,8 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
             }
             if (data.updateType === 'update') {
                 Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
-            } else if (data.updateType === 'new') {
+            }
+            else if (data.updateType === 'new') {
                 data.updateData['userID'] = userId;
                 data.updateData['compilation'] = compilationId;
                 data.updateData['createDateTime'] = new Date();
@@ -136,7 +137,8 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
                         updateAll(err);
                     }
                 });
-            } else if (data.updateType === 'delete') {
+            }
+            else if (data.updateType === 'delete') {
                 deleteInfo = {};
                 deleteInfo['deleted'] = true;
                 deleteInfo['deleteDateTime'] = new Date();
@@ -190,7 +192,8 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
                 catch (error){
                     callback(1, error, null);
                 }
-            } else {
+            }
+            else {
                 hasError = true;
                 callback(1, '提交数据错误.', null);
             }

+ 3 - 2
web/building_saas/main/js/views/project_property_display_view.js

@@ -27,8 +27,9 @@ let projDisplayView = {
         if(this.datas.autoHeight!==autoHeight||this.datas.disPlayMainMaterial!==disPlayMainMaterial){
             this.datas.autoHeight=autoHeight;
             this.datas.disPlayMainMaterial=disPlayMainMaterial;
-            let updateData = {sourceType: 'properties', updateType: 'update', updateData: {ID: projectID, 'property.displaySetting':this.datas}};
-            properties.push(updateData);
+            // let updateData = {sourceType: 'properties', updateType: 'update', updateData: {ID: projectID, 'property.displaySetting':this.datas}};
+            properties['property.displaySetting'] = this.datas;
+            // mixDatas.properties = properties;
         }
     }
 };

+ 46 - 37
web/building_saas/main/js/views/project_view.js

@@ -703,75 +703,75 @@ $('#poj-set').on('show.bs.modal', function () {
     }
 });
 $('#property_ok').click(function () {
-    let properties = [], projectID = parseInt(scUrlUtil.GetQueryString('project'));
-    let project = projectObj.project, reCalcBills= false, reCalcRations= false;
-    let b = parseInt($("input[name='calcFlag']:checked").val());
+    let project = projectObj.project,
+        projectID = project.ID(),
+
+        properties = {},
+        labourCoes = {},
+        rations = [],
+        bills = [],
+
+        mixDatas = {
+            projectID: projectID,
+            updateType: 'update',
+            properties: properties,
+            labourCoes: labourCoes,
+            rations: rations,
+            bills: bills
+        },
+
+        reCalcBills= false,
+        reCalcRations= false;
 
+    let b = parseInt($("input[name='calcFlag']:checked").val());
     if (b !== project.property.billsCalcMode) {
-        let bData = {sourceType: 'properties', updateType: 'update', updateData: {ID: projectID, 'property.billsCalcMode': b}};
-        properties.push(bData);
+        properties['property.billsCalcMode'] = b;
         project.property.billsCalcMode = b;
         reCalcBills = true;
     };
 
     let zg = parseInt($("input[name='zangu']:checked").val());
     if (zg !== project.property.zanguCalcMode) {
-        let zgData = {sourceType: 'properties', updateType: 'update', updateData: {ID: projectID, 'property.zanguCalcMode': zg}};
-        properties.push(zgData);
+        properties['property.zanguCalcMode'] = zg;
         project.property.zanguCalcMode = zg;
         reCalcBills = true;
     };
 
     //基本信息
     if(basicInfoView.toUpdate(basicInfoView.orgDatas, basicInfoView.datas)){
-        let updateData = {sourceType: 'properties', updateType: 'update', updateData: {ID: projectID, 'property.basicInformation': basicInfoView.toSaveDatas(basicInfoView.datas)}};
-        properties.push(updateData);
+        properties['property.basicInformation'] = basicInfoView.toSaveDatas(basicInfoView.datas);
     }
     //工程特征
     if(projFeatureView.toUpdate(projFeatureView.orgDatas, projFeatureView.datas)){
-        let updateData = {sourceType: 'properties', updateType: 'update', updateData: {ID: projectID, 'property.projectFeature': projFeatureView.toSaveDatas(projFeatureView.datas)}};
-        properties.push(updateData);
+        properties['property.projectFeature'] = projFeatureView.toSaveDatas(projFeatureView.datas);
     }
     //清单工程量精度
     let newBillsDecimalDatas = billsDecimalView.toBillsDecimalDatas(billsDecimalView.cache);
     if(billsDecimalView.toUpdate(billsQuanDecimal.datas, newBillsDecimalDatas)){
         reCalcBills = true;
-        let updateData = {sourceType: 'properties', updateType: 'update', updateData: {ID: projectID, 'property.billsQuantityDecimal': newBillsDecimalDatas}};
-        properties.push(updateData);
+        properties['property.billsQuantityDecimal'] = newBillsDecimalDatas;
     }
     //小数位数
-    //获取更新的数据
     let updateDecimal = m_getDecimalData($('input', '#poj-settings-decimal'));
     if(toUpdateDecimal(decimalObj, updateDecimal)){
         reCalcRations = true;
         reCalcBills = true;
-        let updateData = {sourceType: 'properties', updateType: 'update', updateData: {ID: projectID, 'property.decimal': updateDecimal}};
-        properties.push(updateData);
+        properties['property.decimal'] = updateDecimal;
     };
+    // 呈现选项
+    projDisplayView.updateChecking(projectID, properties);
 
     // 人工系数
-    let lcData;
     if (labourCoeView.needSave()){
         reCalcRations = true;
         reCalcBills = true;
         project.calcProgram.compileAllTemps();
 
-        let projectID = projectInfoObj.projectInfo.ID;
         let libID = $("#std_labour_coe_files").children("option:selected").val();
         let libName = $("#std_labour_coe_files").children("option:selected").text();
-        lcData = {sourceType: 'labourCoe', projectID: projectID, libID: libID, libName: libName, newItemArr: labourCoeView.needUpdateDatas};
-        properties.push(lcData);
-    };
 
-    // 呈现选项
-    projDisplayView.updateChecking(projectID,properties);
- /*   const autoHeight = $("#autoHeight:checked").length > 0;
-    const disPlayMainMaterial = $("#disPlayMainMaterial:checked").length > 0;*/
-/*    if (projDisplayView.needUpdate(autoHeight, disPlayMainMaterial)) {
-        const displaySetting = { autoHeight, disPlayMainMaterial };
-        let updateData = {sourceType: 'properties', updateType: 'update', updateData: {ID: projectID, 'property.displaySetting': displaySetting}};
-        properties.push(updateData);
-    }*/
+        labourCoes.updateData = {libID: libID, libName: libName, newItemArr: labourCoeView.needUpdateDatas};
+    };
 
     // 重新计算树节点
     let changedNodes = [];
@@ -782,7 +782,7 @@ $('#property_ok').click(function () {
     if (changedNodes.length > 0) {
         for (let node of changedNodes){
             let data = {
-                projectID: project.ID(),
+                projectID: projectID,
                 ID: node.data.ID,
                 quantity: node.data.quantity,
                 calcBase: node.data.calcBase,
@@ -793,18 +793,27 @@ $('#property_ok').click(function () {
                 feeRate: node.data.feeRate,
                 feeRateID: node.data.feeRateID
             };
-            let dataObj = {sourceType: node.sourceType, updateType: 'ut_update', updateData: data};
-            properties.push(dataObj);
+            if (node.sourceType == 'ration'){
+                rations.push(data);
+            }
+            else if (node.sourceType == 'bills'){
+                bills.push(data);
+            };
         };
     };
 
-    console.log(properties);
-    if(properties.length > 0){
-        CommonAjax.post('/pm/api/updateMixDatas', {user_id: userID, updateData: properties}, function (rstData) {
+    console.log(mixDatas);
+    function hasMixData() {
+        return Object.keys(mixDatas.properties).length > 0 ||
+            mixDatas.labourCoes.updateData || mixDatas.rations.length > 0 || mixDatas.bills.length > 0;
+    }
+
+    if(hasMixData){
+        CommonAjax.post('/pm/api/updateMixDatas', {user_id: userID, mixDataArr: mixDatas}, function (rstData) {
             if (changedNodes.length > 0) {
                 for (let node of changedNodes){delete node.changed};
             };
-            if (lcData) labourCoeView.refresh(lcData);
+            if (mixDatas.labourCoes.updateData) labourCoeView.refresh(mixDatas.labourCoes.updateData);
             window.location.href = '/main?project=' + projectID;
         });
     }