Ver código fonte

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

olym 7 anos atrás
pai
commit
fded82edad

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

@@ -163,10 +163,10 @@ class GLJListModel extends BaseModel {
                     }else {
                         mixRationMap[t_index]=[tmp];
                     }
-                    if (mixRatioConnectData[tmp.glj_id] !== undefined) {
-                        mixRatioConnectData[tmp.glj_id].push(tmp.connect_key);
+                    if (mixRatioConnectData[m_index] !== undefined) {
+                        mixRatioConnectData[m_index].push(tmp.connect_key);
                     } else {
-                        mixRatioConnectData[tmp.glj_id] = [tmp.connect_key];
+                        mixRatioConnectData[m_index] = [tmp.connect_key];
                     }
                 }
             }

+ 12 - 6
modules/glj/models/unit_price_model.js

@@ -86,10 +86,10 @@ class UnitPriceModel extends BaseModel {
             return [null, false];
         }
         // 先查找是否有原始code相同的记录
-        let unitPriceData = await this.findDataByCondition({original_code: data.original_code, unit_price_file_id: unitPriceFileId}, null, false);
+        let unitPriceData = await this.db.model.find({original_code: data.original_code, unit_price_file_id: unitPriceFileId}).sort('code').exec();
         // 如果有记录,判断是否存在一样的名称,单位...等,有则直接返回数据
         let unitPrice=null;
-        if(operation=='add'){//新增操作时,要把code也一起判断,是否完全一样
+        if(operation=='add'){//新增操作时,要把code也一起判断,是否完全一样。(新增的时候有可能存在编码一样,但是名称规格等不一样的情况,这种情况的话编码不用改变)
             unitPrice =  this.isPropertyInclude(unitPriceData,['code','name','specs','unit','type'],data);
         }else {//修改操作时,code不用加入判断,因为code是需要改变的
             unitPrice =  this.isPropertyInclude(unitPriceData,['name','specs','unit','type'],data);
@@ -123,7 +123,7 @@ class UnitPriceModel extends BaseModel {
             insertData.is_add=1;
         }
 
-        if (unitPriceData&&unitPriceData.length>0) {// 如果原始编码能找到,但不存在一样的编号,名称,单位.型号等,更改code和添加新增标记
+        if (unitPriceData&&unitPriceData.length>0&&operation!='add') {// 如果原始编码能找到,但不存在一样的编号,名称,单位.型号等,更改code和添加新增标记,新增的时候除外。新增的情况下能到这一步说明有存在编码一致但其它属性不一致的情况,所以不用更改编码
             insertData.code = data.original_code+"-"+unitPriceData.length;
             insertData.is_add=1;
         }
@@ -219,14 +219,20 @@ class UnitPriceModel extends BaseModel {
         // 额外更新数据
         if (extend !== '') {
             extend = JSON.parse(extend);
-            for (let code in extend) {
+            let indexList = ['code','name','specs','unit','type'];
+            for (let conKey in extend) {
                 let extendUpdateData = {
-                    market_price: extend[code].market_price,
+                    market_price: extend[conKey].market_price,
                 };
                 let tmpCondition = {
                     unit_price_file_id: unitPriceData.unit_price_file_id,
-                    code: code
                 };
+                let keyList = conKey.split("|-|");
+                for(let i = 1;i<keyList.length;i++){
+                    if(keyList[i]!='null'){
+                        tmpCondition[indexList[i]]=keyList[i];
+                    }
+                }
                 let extendResult = await this.db.update(tmpCondition, extendUpdateData);
                 if (!extendResult) {
                     throw '更新额外数据,编码为' + code + '的数据失败!';

+ 154 - 107
modules/pm/models/project_model.js

@@ -5,7 +5,14 @@ import mongoose from 'mongoose';
 import async_c from 'async';
 import UnitPriceFileModel from "../../glj/models/unit_price_file_model";
 import UnitPriceFiles from '../../glj/models/schemas/unit_price_file';
-import {defaultDecimal, billsQuantityDecimal, basicInformation, projectFeature,displaySetting} from './project_property_template';
+import {
+    defaultDecimal,
+    billsQuantityDecimal,
+    basicInformation,
+    projectFeature,
+    displaySetting,
+    calcOptions
+} from './project_property_template';
 import fixedFlag from '../../common/const/bills_fixed';
 let FeeRateFiles = mongoose.model('fee_rate_file');
 let counter = require("../../../public/counter/counter.js");
@@ -30,25 +37,36 @@ let fileType = {
     feeRateFile: 'FeeRateFile'
 };
 
-let ProjectsDAO = function(){};
+let ProjectsDAO = function () {
+};
 
-ProjectsDAO.prototype.getUserProjects = async function(userId, compilation, callback){
+ProjectsDAO.prototype.getUserProjects = async function (userId, compilation, callback) {
     try {
-        let projects = await Projects.find({'$or': [{'userID': userId, 'compilation': compilation, 'deleteInfo': null}, {'userID': userId, 'compilation': compilation, 'deleteInfo.deleted': {'$in': [null, false]}}]}, '-_id');
-        for(let i = 0 , len = projects.length; i < len; i++){
+        let projects = await Projects.find({
+            '$or': [{
+                'userID': userId,
+                'compilation': compilation,
+                'deleteInfo': null
+            }, {'userID': userId, 'compilation': compilation, 'deleteInfo.deleted': {'$in': [null, false]}}]
+        }, '-_id');
+        for (let i = 0, len = projects.length; i < len; i++) {
             let proj = projects[i];
-            let engineeringCost = await BillsModel.find({projectID: proj.ID, 'flags.flag': fixedFlag.ENGINEERINGCOST, 'fees.totalFee': {$exists:  true}});
+            let engineeringCost = await BillsModel.find({
+                projectID: proj.ID,
+                'flags.flag': fixedFlag.ENGINEERINGCOST,
+                'fees.totalFee': {$exists: true}
+            });
             proj._doc.engineeringCost = engineeringCost.length > 0 ? engineeringCost[0].fees[0].totalFee : 0;
         }
         callback(0, '', projects);
     }
-    catch (err){
+    catch (err) {
         callback(1, 'Error', null);
     }
 };
 
 ProjectsDAO.prototype.getUserProject = function (userId, ProjId, callback) {
-    Projects.findOne({userID: userId, ID: ProjId}, '-_id', function(err, template){
+    Projects.findOne({userID: userId, ID: ProjId}, '-_id', function (err, template) {
         if (err) {
             callback(1, '找不到标段数据', null);
         } else {
@@ -57,22 +75,22 @@ ProjectsDAO.prototype.getUserProject = function (userId, ProjId, callback) {
     });
 }
 
-ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId, datas, callback){
+ProjectsDAO.prototype.updateUserProjects = async function (userId, compilationId, datas, callback) {
     let data, project, updateLength = 0, hasError = false, deleteInfo = null, i, newProject;
     let updateAll = function (err) {
-            if (!err){
-                updateLength += 1;
-                if (updateLength === datas.length) {
-                    callback(0, '', datas);
-                }
-            } else {
-                hasError = true;
-                console.log(err);
-                callback(1, '提交数据出错.', null);
+        if (!err) {
+            updateLength += 1;
+            if (updateLength === datas.length) {
+                callback(0, '', datas);
             }
-        };
-    if (datas){
-        for (i = 0; i < datas.length && !hasError; i++){
+        } else {
+            hasError = true;
+            console.log(err);
+            callback(1, '提交数据出错.', null);
+        }
+    };
+    if (datas) {
+        for (i = 0; i < datas.length && !hasError; i++) {
             data = datas[i];
             if (data.updateData.name !== undefined) {
                 data.updateData.name = data.updateData.name.trim();
@@ -103,7 +121,7 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
                     }
                     data.updateData.property.unitPriceFile.id = addResult.id;
                 }
-                if(data.updateData.projType === projectType.tender){
+                if (data.updateData.projType === projectType.tender) {
                     //小数位数
                     data.updateData.property.decimal = defaultDecimal;
                     //清单工程量精度
@@ -114,10 +132,13 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
                     //工程特征
                     data.updateData.property.projectFeature = projectFeature;
                     //呈现选项
-		    data.updateData.property.displaySetting = displaySetting;
-		    
+                    data.updateData.property.displaySetting = displaySetting;
+
                     data.updateData.property.billsCalcMode = 0;
-		    data.updateData.property.zanguCalcMode = 0;
+                    data.updateData.property.zanguCalcMode = 0;
+                    //计算选项
+                    data.updateData.property.calcOptions = calcOptions
+
                 }
                 newProject = new Projects(data.updateData);
                 // 查找同级是否存在同名数据
@@ -126,9 +147,9 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
                     callback(1, '同级目录已存在相同名称数据.', null);
                     return;
                 }
-                if(data.updateData.projType==='Tender'){
-                    let  feeRateFileID = await feeRateFacade.newFeeRateFile(userId, data.updateData);
-                    newProject.property.feeFile = feeRateFileID?feeRateFileID:-1;
+                if (data.updateData.projType === 'Tender') {
+                    let feeRateFileID = await feeRateFacade.newFeeRateFile(userId, data.updateData);
+                    newProject.property.feeFile = feeRateFileID ? feeRateFileID : -1;
 
                     // 新建人工系数文件 CSL, 2017.10.13
                     let lcFile = await labourCoeFacade.newProjectLabourCoe(data.updateData);
@@ -153,22 +174,28 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
                 data.updateData['deleteInfo'] = deleteInfo;
                 //Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
                 //update
-                try{
-                    if(data.updateData.projType === projectType.project){
+                try {
+                    if (data.updateData.projType === projectType.project) {
                         let engineerings = await Projects.find({userID: userId, ParentID: data.updateData.ID});
                         let isExist = false;
-                        if(engineerings.length > 0){
-                            for(let j = 0, jLen = engineerings.length; j < jLen; j++){
+                        if (engineerings.length > 0) {
+                            for (let j = 0, jLen = engineerings.length; j < jLen; j++) {
                                 let e_tenders = await Projects.find({userID: userId, ParentID: engineerings[j].ID});
-                                if(e_tenders.length > 0){
+                                if (e_tenders.length > 0) {
                                     isExist = true;
                                     break;
                                 }
                             }
                         }
-                        if(isExist){//fake
-                            await UnitPriceFiles.update({user_id: userId, root_project_id: data.updateData.ID}, {$set: {deleteInfo: deleteInfo}}, {multi: true});
-                            await FeeRateFiles.update({userID: userId, rootProjectID: data.updateData.ID}, {$set: {deleteInfo: deleteInfo}}, {multi: true});
+                        if (isExist) {//fake
+                            await UnitPriceFiles.update({
+                                user_id: userId,
+                                root_project_id: data.updateData.ID
+                            }, {$set: {deleteInfo: deleteInfo}}, {multi: true});
+                            await FeeRateFiles.update({
+                                userID: userId,
+                                rootProjectID: data.updateData.ID
+                            }, {$set: {deleteInfo: deleteInfo}}, {multi: true});
                             await Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
                         }
                         else {//true
@@ -178,9 +205,9 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
                             await Projects.remove({userID: userId, ID: data.updateData.ID}, updateAll);
                         }
                     }
-                    else if(data.updateData.projType === projectType.engineering){
+                    else if (data.updateData.projType === projectType.engineering) {
                         let tenders = await Projects.find({userID: userId, ParentID: data.updateData.ID});
-                        if(tenders.length > 0){//fake
+                        if (tenders.length > 0) {//fake
                             await Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
                         }
                         else {//true
@@ -188,15 +215,15 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
                             await Projects.remove({userID: userId, ID: data.updateData.ID}, updateAll);
                         }
                     }
-                    else if(data.updateData.projType === projectType.tender){//fake
+                    else if (data.updateData.projType === projectType.tender) {//fake
                         await Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
                     }
-                    else if(data.updateData.projType === projectType.folder){//true
+                    else if (data.updateData.projType === projectType.folder) {//true
                         await Projects.remove({userID: userId, ID: data.updateData.ID}, updateAll);
                     }
                     else throw '未知文件类型,删除失败!';
                 }
-                catch (error){
+                catch (error) {
                     callback(1, error, null);
                 }
             }
@@ -208,29 +235,38 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
     }
 };
 
-ProjectsDAO.prototype.udpateUserFiles = async function (userId, datas, callback){
+ProjectsDAO.prototype.udpateUserFiles = async function (userId, datas, callback) {
     let updateType = {update: 'update', delete: 'delete'};
     let deleteInfo = Object.create(null);
     deleteInfo.deleted = true;
     deleteInfo.deleteBy = userId;
     deleteInfo.deleteDateTime = new Date();
-    try{
-        for(let i = 0, len = datas.length; i < len; i++){
+    try {
+        for (let i = 0, len = datas.length; i < len; i++) {
             let data = datas[i];
-            if(data.updateType === updateType.update && data.fileType === fileType.unitPriceFile){
+            if (data.updateType === updateType.update && data.fileType === fileType.unitPriceFile) {
                 await UnitPriceFiles.update({user_id: userId, id: parseInt(data.updateData.id)}, data.updateData);
-                await Projects.update({userID: userId, 'property.unitPriceFile.id': data.updateData.id}, {$set: {'property.unitPriceFile.name': data.updateData.name}});
+                await Projects.update({
+                    userID: userId,
+                    'property.unitPriceFile.id': data.updateData.id
+                }, {$set: {'property.unitPriceFile.name': data.updateData.name}});
             }
-            else if(data.updateType === updateType.update && data.fileType === fileType.feeRateFile){
+            else if (data.updateType === updateType.update && data.fileType === fileType.feeRateFile) {
                 await FeeRateFiles.update({userID: userId, ID: data.updateData.ID}, data.updateData);
-                await Projects.update({userID: userId, 'property.feeFile.id': data.updateData.ID}, {$set: {'property.feeFile.name': data.updateData.name}});
+                await Projects.update({
+                    userID: userId,
+                    'property.feeFile.id': data.updateData.ID
+                }, {$set: {'property.feeFile.name': data.updateData.name}});
             }
-            else if(data.updateType === updateType.delete && data.fileType === fileType.unitPriceFile){
+            else if (data.updateType === updateType.delete && data.fileType === fileType.unitPriceFile) {
                 data.updateData.deleteInfo = deleteInfo;
                 await UnitPriceFiles.update({user_id: userId, id: parseInt(data.updateData.id)}, data.updateData);
-                await Projects.update({userID: userId, 'property.feeFile.id': data.updateData.id}, {$set: {'property.feeFile.name': data.updateData.name}});
+                await Projects.update({
+                    userID: userId,
+                    'property.feeFile.id': data.updateData.id
+                }, {$set: {'property.feeFile.name': data.updateData.name}});
             }
-            else if(data.updateType === updateType.delete && data.fileType === fileType.feeRateFile){
+            else if (data.updateType === updateType.delete && data.fileType === fileType.feeRateFile) {
                 data.updateData.deleteInfo = deleteInfo;
                 await FeeRateFiles.update({userID: userId, ID: data.updateData.ID}, data.updateData);
             }
@@ -238,7 +274,7 @@ ProjectsDAO.prototype.udpateUserFiles = async function (userId, datas, callback)
         }
         callback(false, '删除成功', null);
     }
-    catch(error){
+    catch (error) {
         callback(true, '删除失败', null);
     }
 };
@@ -246,7 +282,7 @@ ProjectsDAO.prototype.udpateUserFiles = async function (userId, datas, callback)
 ProjectsDAO.prototype.copyUserProjects = function (userId, datas, callback) {
     let data, project, updateLength = 0, hasError = false, deleteInfo = null, tempType = 1, i;
     let updateAll = function (err) {
-        if (!err){
+        if (!err) {
             updateLength += 1;
             if (updateLength === datas.length) {
                 callback(0, '', datas);
@@ -281,7 +317,7 @@ ProjectsDAO.prototype.copyUserProjects = function (userId, datas, callback) {
     }
 };
 
-ProjectsDAO.prototype.rename = async function (userId, compilationId, data, callback){
+ProjectsDAO.prototype.rename = async function (userId, compilationId, data, callback) {
     try {
         if (data.id === undefined || data.id === '') {
             throw '数据错误!';
@@ -296,8 +332,8 @@ ProjectsDAO.prototype.rename = async function (userId, compilationId, data, call
             throw '同级目录已存在相同名称数据';
         }
 
-        Projects.update({userID: userId, ID: data.id}, {name: data.newName}, function(err){
-            if (err){
+        Projects.update({userID: userId, ID: data.id}, {name: data.newName}, function (err) {
+            if (err) {
                 throw '项目不存在';
             }
         });
@@ -308,10 +344,10 @@ ProjectsDAO.prototype.rename = async function (userId, compilationId, data, call
     callback(0, '');
 };
 
-ProjectsDAO.prototype.beforeOpenProject = function (userId, projectId, updateData, callback){
+ProjectsDAO.prototype.beforeOpenProject = function (userId, projectId, updateData, callback) {
     updateData['recentDateTime'] = new Date();
-    Projects.update({userID: userId, ID: projectId}, updateData, function(err){
-        if (err){
+    Projects.update({userID: userId, ID: projectId}, updateData, function (err) {
+        if (err) {
             callback(1, '项目不存在.');
         } else {
             callback(0, '');
@@ -344,28 +380,28 @@ ProjectsDAO.prototype.getProject = function (key, callback) {
     }
 };
 
-ProjectsDAO.prototype.getProjectsByIds = async function (userId, compilationId, ids){
+ProjectsDAO.prototype.getProjectsByIds = async function (userId, compilationId, ids) {
     return await Projects.find({userID: userId, compilation: compilationId, ID: {$in: ids}});
 };
 
-ProjectsDAO.prototype.getGCFiles = async function (fileType, userID){
+ProjectsDAO.prototype.getGCFiles = async function (fileType, userID) {
     let rst;
-    if(fileType === 'UnitPriceFile'){
+    if (fileType === 'UnitPriceFile') {
         let unitPriceFileModel = new UnitPriceFileModel();
         rst = await unitPriceFileModel.getGCUnitPriceFiles(userID);
     }
-    else if(fileType === 'FeeRateFile'){
+    else if (fileType === 'FeeRateFile') {
         rst = await feeRateFacade.getGCFeeRateFiles(userID);
     }
     else {
         let isExist = false;
-        for(let type in projectType){
-            if(projectType[type] === fileType) {
+        for (let type in projectType) {
+            if (projectType[type] === fileType) {
                 isExist = true;
                 break;
             }
         }
-        if(!isExist) throw '不存在此项目类型!';
+        if (!isExist) throw '不存在此项目类型!';
         rst = await Projects.find({userID: userID, projType: fileType, 'deleteInfo.deleted': true});
     }
     return rst;
@@ -373,55 +409,55 @@ ProjectsDAO.prototype.getGCFiles = async function (fileType, userID){
 
 ProjectsDAO.prototype.getFirstNodeID = async function (userID, pid) {
     let nodes = await Projects.find({userID: userID, ParentID: pid, deleteInfo: null});
-    if(nodes.length === 0){
+    if (nodes.length === 0) {
         return -1;
     }
     else {
         let prefix = 'ID_';
         let chain = Object.create(null);
-        for(let i = 0, len = nodes.length; i < len; i++){
+        for (let i = 0, len = nodes.length; i < len; i++) {
             let nodeDoc = nodes[i]._doc;
             let node = Object.create(null);
             node.ID = nodeDoc.ID;
             node.NextSiblingID = nodeDoc.NextSiblingID;
             chain[prefix + node.ID] = node;
         }
-        for(let i =0, len = nodes.length; i < len; i++){
+        for (let i = 0, len = nodes.length; i < len; i++) {
             let nodeDoc = nodes[i]._doc;
             let next = nodeDoc.NextSiblingID > 0 ? chain[prefix + nodeDoc.NextSiblingID] : null;
             chain[prefix + nodeDoc.ID].next = next;
-            if(next){
+            if (next) {
                 next.pre = chain[prefix + nodeDoc.ID]
             }
         }
-        for(let node in chain){
+        for (let node in chain) {
             let pre = chain[node].pre || null;
-            if(!pre){
+            if (!pre) {
                 return chain[node].ID;
             }
         }
     }
 };
 
-ProjectsDAO.prototype.recGC = async function(userID, datas, callback){
+ProjectsDAO.prototype.recGC = async function (userID, datas, callback) {
     let functions = [];
     let updateDatas = [];
-    for(let i = 0, len = datas.length; i < len; i++){
-        if(datas[i].findData.ParentID !== undefined && datas[i].findData.NextSiblingID === -1 && !datas[i].findData.deleteInfo){//维护项目管理树
+    for (let i = 0, len = datas.length; i < len; i++) {
+        if (datas[i].findData.ParentID !== undefined && datas[i].findData.NextSiblingID === -1 && !datas[i].findData.deleteInfo) {//维护项目管理树
             let findNode = await Projects.find(datas[i].findData);
-            if(findNode.length > 0){
+            if (findNode.length > 0) {
                 datas[i].findData = Object.create(null);
                 datas[i].findData.ID = findNode[0].ID;
                 updateDatas.push(datas[i]);
             }
         }
         else {
-            if(datas[i].updateType === projectType.project && datas[i].updateData.NextSiblingID === undefined){//则为待查询NextSiblingID,前端无法查询
+            if (datas[i].updateType === projectType.project && datas[i].updateData.NextSiblingID === undefined) {//则为待查询NextSiblingID,前端无法查询
                 let projData = await Projects.find({userID: userID, ID: datas[i].findData.ID});//建设项目原本可能属于某文件夹、文件夹的存在需要判断
                 let projPid = projData[0].ParentID;
-                if(projPid !== -1){
+                if (projPid !== -1) {
                     let projFolder = await Projects.find({userID: userID, ID: projPid});
-                    if(projFolder.length === 0){//文件夹已不存在
+                    if (projFolder.length === 0) {//文件夹已不存在
                         projPid = -1;
                         datas[i].updateData.ParentID = -1;
                     }
@@ -432,45 +468,50 @@ ProjectsDAO.prototype.recGC = async function(userID, datas, callback){
             updateDatas.push(datas[i])
         }
     }
-    for(let i = 0, len = updateDatas.length; i < len; i ++){
-        functions.push((function(data){
+    for (let i = 0, len = updateDatas.length; i < len; i++) {
+        functions.push((function (data) {
                 return function (cb) {
-                    if(data.updateType === fileType.unitPriceFile){
+                    if (data.updateType === fileType.unitPriceFile) {
                         UnitPriceFiles.update({id: parseInt(data.findData.id)}, data.updateData, function (err) {
-                            if(err) cb(err);
+                            if (err) cb(err);
                             else {
-                                Projects.update({userID: userID, 'property.unitPriceFile.id': data.findData.id}, {$set: {'property.unitPriceFile.name': data.updateData.name}}, function (err) {
-                                    if(err) cb(err);
+                                Projects.update({
+                                    userID: userID,
+                                    'property.unitPriceFile.id': data.findData.id
+                                }, {$set: {'property.unitPriceFile.name': data.updateData.name}}, function (err) {
+                                    if (err) cb(err);
                                     else cb(false);
                                 });
                             }
                         })
                     }
-                    else if(data.updateType === fileType.feeRateFile){
+                    else if (data.updateType === fileType.feeRateFile) {
                         FeeRateFiles.update(data.findData, data.updateData, function (err) {
-                            if(err) cb(err);
+                            if (err) cb(err);
                             else {
-                                Projects.update({userID: userID, 'property.feeFile.id': data.findData.ID}, {$set: {'property.feeFile.name': data.updateData.name}}, function (err) {
-                                    if(err) cb(err);
+                                Projects.update({
+                                    userID: userID,
+                                    'property.feeFile.id': data.findData.ID
+                                }, {$set: {'property.feeFile.name': data.updateData.name}}, function (err) {
+                                    if (err) cb(err);
                                     else cb(false);
                                 });
                             }
                         });
                     }
-                    else{
-                        if(data){
+                    else {
+                        if (data) {
                             Projects.update(data.findData, data.updateData, function (err) {
-                                if(err)cb(err);
+                                if (err) cb(err);
                                 else cb(false);
                             });
                         }
                     }
                 }
-            }
-        )(updateDatas[i]));
+            })(updateDatas[i]));
     }
     async_c.parallel(functions, function (err, results) {
-        if(err) callback(err, 'fail', null);
+        if (err) callback(err, 'fail', null);
         else callback(0, 'success', null);
     });
 };
@@ -481,12 +522,18 @@ ProjectsDAO.prototype.recGC = async function(userID, datas, callback){
  * @param {Object} data
  * @return {Boolean}
  */
-ProjectsDAO.prototype.isExist = async function(userId, compilationId, name, parentID) {
+ProjectsDAO.prototype.isExist = async function (userId, compilationId, name, parentID) {
     parentID = parseInt(parentID);
     if (name === '' || isNaN(parentID)) {
         return true;
     }
-    let condition = {userID: userId, compilation: compilationId, ParentID: parentID, name: name, "$or":[{deleteInfo: null}, {"deleteInfo.deleted": false}]};
+    let condition = {
+        userID: userId,
+        compilation: compilationId,
+        ParentID: parentID,
+        name: name,
+        "$or": [{deleteInfo: null}, {"deleteInfo.deleted": false}]
+    };
     let count = await Projects.count(condition);
     return count > 0;
 };
@@ -497,7 +544,7 @@ ProjectsDAO.prototype.isExist = async function(userId, compilationId, name, pare
  * @param {Number} projectId
  * @return {Promise}
  */
-ProjectsDAO.prototype.getTenderByProjectId = async function(projectId) {
+ProjectsDAO.prototype.getTenderByProjectId = async function (projectId) {
     let result = [];
     // 首先获取对应的单位工程id
     let engineeringData = await Projects.find({ParentID: projectId});
@@ -506,7 +553,7 @@ ProjectsDAO.prototype.getTenderByProjectId = async function(projectId) {
     }
 
     let engineeringIdList = [];
-    for(let tmp of engineeringData) {
+    for (let tmp of engineeringData) {
         engineeringIdList.push(tmp.ID);
     }
 
@@ -516,7 +563,7 @@ ProjectsDAO.prototype.getTenderByProjectId = async function(projectId) {
         return result;
     }
 
-    for(let tmp of tenderData) {
+    for (let tmp of tenderData) {
         result.push(tmp.ID);
     }
 
@@ -529,7 +576,7 @@ ProjectsDAO.prototype.getTenderByProjectId = async function(projectId) {
  * @param {Number} unitPriceFileId
  * @return {Promise}
  */
-ProjectsDAO.prototype.getTenderByUnitPriceFileId = async function(unitPriceFileId) {
+ProjectsDAO.prototype.getTenderByUnitPriceFileId = async function (unitPriceFileId) {
     let result = [];
 
     unitPriceFileId = parseInt(unitPriceFileId);
@@ -549,7 +596,7 @@ ProjectsDAO.prototype.getTenderByUnitPriceFileId = async function(unitPriceFileI
  * @param {Number} projectId
  * @return {Promise}
  */
-ProjectsDAO.prototype.getUnitPriceFileId = async function(projectId) {
+ProjectsDAO.prototype.getUnitPriceFileId = async function (projectId) {
     let result = 0;
     let projectData = await Projects.findOne({ID: projectId});
     if (projectData === null) {
@@ -566,12 +613,12 @@ ProjectsDAO.prototype.getUnitPriceFileId = async function(projectId) {
  * @param {Number} userId
  * @return {Promise}
  */
-ProjectsDAO.prototype.getUserProjectData = async function(userId) {
+ProjectsDAO.prototype.getUserProjectData = async function (userId) {
     let projectList = await Projects.find({
         '$or': [
             {'userID': userId, 'deleteInfo': null, projType: 'Project'},
             {'userID': userId, 'deleteInfo.deleted': {'$in': [null, false]}, projType: 'Project'}
-            ]
+        ]
     }, {_id: 0, name: 1, ID: 1});
 
     return projectList;
@@ -584,7 +631,7 @@ ProjectsDAO.prototype.getUserProjectData = async function(userId) {
  * @param {Object} changeInfo
  * @return {Promise}
  */
-ProjectsDAO.prototype.changeUnitPriceFileInfo = async function(projectId, changeInfo) {
+ProjectsDAO.prototype.changeUnitPriceFileInfo = async function (projectId, changeInfo) {
     projectId = parseInt(projectId);
     if (isNaN(projectId) || projectId <= 0) {
         return false;
@@ -594,6 +641,7 @@ ProjectsDAO.prototype.changeUnitPriceFileInfo = async function(projectId, change
     return result.ok === 1;
 };
 
+
 /**
  * 更新项目属性
  *
@@ -613,8 +661,7 @@ ProjectsDAO.prototype.updateProjectProperty = async function(projectId, property
     return result.ok === 1;
 };
 
-module.exports ={
-    project: new ProjectsDAO(),
+module.exports ={    project: new ProjectsDAO(),
     projType: projectType,
     fileType: fileType
 };

+ 6 - 1
modules/pm/models/project_property_template.js

@@ -16,6 +16,11 @@ const displaySetting = {
     disPlayMainMaterial:true
 }
 
+const calcOptions={
+    calc_main:false,
+    calc_add:true,
+    calc_est:true
+}
 /*
 * 单位工程清单工程量精度模板
 * */
@@ -123,4 +128,4 @@ const projectFeature = [
     {dispName: '门窗材料及装饰', key: 'doorsWindowsMaterial', value: ''}
 ];
 
-export {defaultDecimal, billsQuantityDecimal, basicInformation, projectFeature,displaySetting};
+export {defaultDecimal, billsQuantityDecimal, basicInformation, projectFeature,displaySetting,calcOptions};

Diferenças do arquivo suprimidas por serem muito extensas
+ 441 - 415
modules/ration_glj/facade/ration_glj_facade.js


+ 26 - 0
web/building_saas/glj/js/common_spread.js

@@ -294,4 +294,30 @@ CommonSpreadJs.prototype.getActiveDataByField = function(field) {
 
     result = this.sheet.getValue(activeGLJRow, column);
     return result;
+};
+CommonSpreadJs.prototype.setProjectGLJDiffPrice = function (data) {
+    if(gljOprObj.calcPriceDiff(data)==true){//是否记算价差
+        data.base_price = data.unit_price.base_price;
+        data.adjust_price = projectObj.project.projectGLJ.getAdjustPrice(data);
+    }else {
+        data.base_price = data.unit_price.market_price;
+        data.adjust_price = data.unit_price.market_price;
+    }
+    return data;
+};
+
+CommonSpreadJs.prototype.getUnitPrice = function (data) {
+    let gljList=projectObj.project.projectGLJ.datas.gljList;
+    var pg = _.find(gljList, {
+        'code': data.code,
+        'name': data.name,
+        'specs': data.specs,
+        'type': data.type,
+        'unit': data.unit
+    })
+    if(pg){
+        return pg.unit_price;
+    }
+
+    return null;
 };

+ 2 - 2
web/building_saas/glj/js/composition.js

@@ -67,9 +67,9 @@ function compositionSuccess(info) {
     let row= projectGLJSheet.sheet.getActiveRowIndex();//取父机械或组成物的下标
     let parentData = jsonData[row];
     let ratioData = _.find(parentData.ratio_data,{"id":info.id});
-    let con_key = gljOprObj.getIndex(ratioData,['code', 'name', 'specs', 'unit', 'type']);
+    let con_key = gljOprObj.getIndex(ratioData,gljKeyArray);
     for(let i=0;i< jsonData.length;i++){
-        let tem_key = gljOprObj.getIndex(jsonData[i],['code', 'name', 'specs', 'unit', 'type']);
+        let tem_key = gljOprObj.getIndex(jsonData[i],gljKeyArray);
         if(con_key == tem_key){
             //乘以父工料机的消耗量得到该组成物总消耗量的改变量
             info.change = operationWithRound(parentData.quantity,info.change,"glj.quantity","*");

+ 8 - 3
web/building_saas/glj/js/composition_spread.js

@@ -32,7 +32,7 @@ CompositionSpread.prototype.init = function(target) {
         {name: '单位', field: 'unit', visible: true},
         {name: 'ID', field: 'id', visible: false},
         {name: '类型', field: 'unit_price.type', visible: false},
-        {name: '定额价', field: "unit_price.base_price", visible: true,decimalField:"glj.unitPrice"},
+        {name: '定额价', field: "base_price", visible: true,decimalField:"glj.unitPrice"},
         {name: '调整价', field: 'adjust_price', visible: true,decimalField:"glj.unitPrice"},
         {name: '市场价', field: "unit_price.market_price", visible: true,decimalField:"glj.unitPrice"},
         {name: name, field: 'consumption', visible: true, validator: 'number',decimalField:'glj.quantity'},
@@ -46,7 +46,7 @@ CompositionSpread.prototype.init = function(target) {
     let codeColumn = this.sheetObj.getFieldColumn('code');
     let unitColumn = this.sheetObj.getFieldColumn('unit');
     let consumptionColumn = this.sheetObj.getFieldColumn('consumption');
-    let basePriceCol = this.sheetObj.getFieldColumn('unit_price.base_price');
+    let basePriceCol = this.sheetObj.getFieldColumn('base_price');
     let adjustPriceCol = this.sheetObj.getFieldColumn('adjust_price');
     let marketPriceCol = this.sheetObj.getFieldColumn('unit_price.market_price');
     // 居中样式
@@ -154,6 +154,8 @@ CompositionSpread.prototype.specialColumn = function(sourceData) {
     let rowCounter = 0;
     // 获取市场单价列号
     let consumptionColumn = this.sheetObj.getFieldColumn('consumption');
+    let basePriceColumn = this.sheetObj.getFieldColumn('base_price');
+    let adjustPriceColumn = this.sheetObj.getFieldColumn('adjust_price');
     let idColumn = this.sheetObj.getFieldColumn('mix_ratio_id');
     let activeSheet = this.sheetObj.getSheet();
     for(let data of sourceData) {
@@ -162,6 +164,9 @@ CompositionSpread.prototype.specialColumn = function(sourceData) {
             activeSheet.setValue(rowCounter, consumptionColumn, data.ratio_data.consumption);
             activeSheet.setValue(rowCounter, idColumn, data.ratio_data.id);
         }
+        data=this.sheetObj.setProjectGLJDiffPrice(data);
+        activeSheet.setValue(rowCounter, basePriceColumn, data.base_price);
+        activeSheet.setValue(rowCounter, adjustPriceColumn, data.adjust_price);
         rowCounter++;
     }
 };
@@ -249,7 +254,7 @@ CompositionSpread.prototype.getCompositionSumPrice = function(scene, affectRow,
     // 获取对应列的列号
     let marketPriceColumn = this.sheetObj.getFieldColumn('unit_price.market_price');
     let consumptionColumn = this.sheetObj.getFieldColumn('consumption');
-    let basePriceColumn = this.sheetObj.getFieldColumn('unit_price.base_price');
+    let basePriceColumn = this.sheetObj.getFieldColumn('base_price');
 
     let parentMarketPrice = 0;
     let parentBasePrice = 0;

+ 1 - 1
web/building_saas/glj/js/project_glj.js

@@ -334,7 +334,6 @@ function successTrigger(field, info) {
 
             // 触发websocket通知
             socket.emit('dataNotify', JSON.stringify(info));
-            console.log(info);
             break;
         case 'supply':
             // 供货方式更改成功后
@@ -344,6 +343,7 @@ function successTrigger(field, info) {
     // 重新加载数据到缓存
     projectObj.project.projectGLJ.loadData(function () {
         projectObj.project.projectGLJ.loadCacheData();
+        $.bootstrapLoading.end();
     });
 
     // 更新定额工料机

+ 40 - 49
web/building_saas/glj/js/project_glj_spread.js

@@ -48,7 +48,7 @@ ProjectGLJSpread.prototype.init = function () {
         {name: 'ID', field: 'id', visible: false},
         {name: '类型', field: 'unit_price.type', visible: false},
         {name: '总消耗量', field: 'quantity', visible: true,width:100,decimalField:'glj.quantity'},
-        {name: '定额价', field: "unit_price.base_price", visible: true,width:70,decimalField:"glj.unitPrice"},
+        {name: '定额价', field: "base_price", visible: true,width:70,decimalField:"glj.unitPrice"},
         {name: '调整价', field: 'adjust_price', visible: true,width:70,decimalField:"glj.unitPrice"},
         {name: '市场价', field: "unit_price.market_price", visible: true, validator: 'number',width:70,decimalField:"glj.unitPrice"},
         {
@@ -87,7 +87,7 @@ ProjectGLJSpread.prototype.init = function () {
     let isAdjustPriceColumn = this.sheetObj.getFieldColumn('is_adjust_price');
     let unitColumn = this.sheetObj.getFieldColumn('unit');
     let quantityColumn = this.sheetObj.getFieldColumn('quantity');
-    let basePriceColumn = this.sheetObj.getFieldColumn('unit_price.base_price');
+    let basePriceColumn = this.sheetObj.getFieldColumn('base_price');
     let adjustPriceColumn = this.sheetObj.getFieldColumn('adjust_price');
     let marketPriceColumn = this.sheetObj.getFieldColumn('unit_price.market_price');
     let supplyColumn = this.sheetObj.getFieldColumn('supply');
@@ -198,7 +198,8 @@ ProjectGLJSpread.prototype.updateProjectGLJField = function(info, callback) {
 
     // 直接在前端计算后传值后台改
     let extend = {};
-    let parentMarketPrice = projectGLJSpread.compositionCalculate(row);
+    let updateRecord = jsonData[row];
+    let parentMarketPrice = projectGLJSpread.compositionCalculate(updateRecord);
     if (parentMarketPrice !== null && Object.keys(parentMarketPrice).length > 0) {
         for (let activeCode in parentMarketPrice) {
             let tmpObject = {
@@ -220,6 +221,7 @@ ProjectGLJSpread.prototype.updateProjectGLJField = function(info, callback) {
         value= value.toDecimal(getDecimal('glj.unitPrice'));
     }
     extend = Object.keys(extend).length > 0 ?  JSON.stringify(extend) : '';
+    $.bootstrapLoading.start();
     $.ajax({
         url: '/glj/update',
         type: 'post',
@@ -263,6 +265,7 @@ ProjectGLJSpread.prototype.specialColumn = function (sourceData) {
     // 获取列号
     let isEvaluateColumn = this.sheetObj.getFieldColumn('is_evaluate');
     let marketPriceColumn = this.sheetObj.getFieldColumn('unit_price.market_price');
+    let basePriceColumn = this.sheetObj.getFieldColumn('base_price');
     let adjustPriceColumn = this.sheetObj.getFieldColumn("adjust_price");
     let connectCodeColumn = this.sheetObj.getFieldColumn('connect_code');
     let consumptionColumn = this.sheetObj.getFieldColumn('consumption');
@@ -322,7 +325,7 @@ ProjectGLJSpread.prototype.specialColumn = function (sourceData) {
             let connectCode = [];
             let consumption = [];
             for (let tmp of data.ratio_data) {
-                connectCode.push(tmp.connect_code);
+                connectCode.push(tmp.connect_key);
                 consumption.push(tmp.consumption);
             }
             let connectCodeString = connectCode.join(',');
@@ -330,7 +333,8 @@ ProjectGLJSpread.prototype.specialColumn = function (sourceData) {
             activeSheet.setValue(rowCounter, connectCodeColumn, connectCodeString);
             activeSheet.setValue(rowCounter, consumptionColumn, consumptionString);
         }
-        data.adjust_price = projectObj.project.projectGLJ.getAdjustPrice(data);
+        data=this.sheetObj.setProjectGLJDiffPrice(data);
+        activeSheet.setValue(rowCounter,basePriceColumn,data.base_price);
         activeSheet.setValue(rowCounter,adjustPriceColumn,data.adjust_price);
         rowCounter++;
     }
@@ -342,53 +346,29 @@ ProjectGLJSpread.prototype.specialColumn = function (sourceData) {
  * @param {Number} row
  * @return {Object}
  */
-ProjectGLJSpread.prototype.compositionCalculate = function(row) {
-    let activeSheet = this.sheetObj.getSheet();
-    // 获取相关列号
-    let connectCodeColumn = this.sheetObj.getFieldColumn('connect_code');
-    let consumptionColumn = this.sheetObj.getFieldColumn('consumption');
-    let marketPriceColumn = this.sheetObj.getFieldColumn('unit_price.market_price');
-
-    let activeConnectCode = activeSheet.getValue(row, connectCodeColumn);
-    // 不属于组成物则忽略
-    if (activeConnectCode === '' || activeConnectCode === null) {
+ProjectGLJSpread.prototype.compositionCalculate = function(updateRecord) {
+    let gljData = projectObj.project.projectGLJ.datas;
+    let m_index = gljOprObj.getIndex(updateRecord,gljKeyArray);
+    let parent_connect_keys = gljData.mixRatioConnectData[m_index];
+    if(!parent_connect_keys||parent_connect_keys.length<=0){// 不属于组成物则忽略
         return null;
     }
-    activeConnectCode = activeConnectCode.split(',');
-    // 计算同级组成物的价格
-    // 遍历所有记录
-    let maxRow = activeSheet.getRowCount();
-
+    let q_decimal = getDecimal("glj.quantity");
+    let p_decimal = getDecimal("glj.unitPrice");
     let parentMarketPrice = {};
-    for (let i = 0; i < maxRow; i++) {
-        let connectCode = activeSheet.getValue(i, connectCodeColumn);
-        if (connectCode === null) {
-            continue;
-        }
-        connectCode = connectCode.split(',');
-        // 消耗量
-        let consumption = activeSheet.getValue(i, consumptionColumn);
-        consumption = consumption.split(',');
-
-        // 获取市场价
-        let marketPrice = activeSheet.getValue(i, marketPriceColumn);
-
-        for (let active of activeConnectCode) {
-            let index = connectCode.indexOf(active);
-            if (index < 0) {
-                continue;
+    for(let p  of parent_connect_keys) {
+        let mix_ratios = gljData.mixRatioMap[p];
+        let sum = 0;
+        for (let m of mix_ratios) {
+            let unitPrice = this.sheetObj.getUnitPrice(m);
+            if (unitPrice) {
+                let com = scMathUtil.roundForObj(m.consumption, q_decimal);
+                let marketPrice = scMathUtil.roundForObj(unitPrice.market_price, p_decimal);
+                sum = scMathUtil.roundForObj(marketPrice * com + sum, p_decimal);
             }
-            let rowConsumption = consumption[index] === undefined ? 0 : consumption[index];
-            let decimal = getDecimal("glj.unitPrice");
-            // 计算价格
-            let rowMarketPrice = (marketPrice * rowConsumption).toDecimal(decimal);
-            parentMarketPrice[active] = parentMarketPrice[active] === undefined ?
-                rowMarketPrice : (parentMarketPrice[active] + rowMarketPrice).toDecimal(decimal);
-
         }
-
+        parentMarketPrice[p]=sum;
     }
-
     return parentMarketPrice;
 };
 
@@ -417,12 +397,23 @@ ProjectGLJSpread.prototype.compositionParentUpdate = function(parentMarketPrice)
 ProjectGLJSpread.prototype.priceCalculate = function(info) {
     let row = info.row;
     let typeColumn = this.sheetObj.getFieldColumn('unit_price.type');
-    let basePriceColumn = this.sheetObj.getFieldColumn('unit_price.base_price');
+    let basePriceColumn = this.sheetObj.getFieldColumn('base_price');
     let adjustPriceColumn = projectGLJSheet.getFieldColumn('adjust_price');
     let activeSheet = this.sheetObj.getSheet();
 
     // 获取类型
     let type = activeSheet.getValue(row, typeColumn);
+  /*  let data = jsonData[row];
+    if(gljOprObj.calcPriceDiff(data)==true){//是否记算价差
+        data.base_price = data.unit_price.base_price;
+        data.adjust_price = projectObj.project.projectGLJ.getAdjustPrice(data);
+    }else {
+        data.base_price = data.unit_price.market_price;
+        data.adjust_price = data.unit_price.market_price;
+    }
+    activeSheet.setValue(info.row,basePriceColumn,data.base_price);
+    activeSheet.setValue(info.row,adjustPriceColumn,data.adjust_price);*/
+
 
   /*  // 基价单价计算
     switch (type) {
@@ -433,7 +424,7 @@ ProjectGLJSpread.prototype.priceCalculate = function(info) {
             break;
     }*/
 
-    // 调整基价计算
+ /*   // 调整基价计算
     switch (type) {
         // 材料、主材、设备 调整基价=基价单价
         case GLJTypeConst.MAIN_MATERIAL:
@@ -442,7 +433,7 @@ ProjectGLJSpread.prototype.priceCalculate = function(info) {
             activeSheet.setValue(info.row, adjustPriceColumn, basePrice);
             break;
 
-    }
+    }*/
 
     // 市场单价计算
     switch (type) {

+ 22 - 1
web/building_saas/main/html/main.html

@@ -287,7 +287,7 @@
                                 <li class="nav-item"><a class="nav-link active" data-toggle="pill" href="#poj-settings-basicInfo" role="tab" id="tab_poj-settings-basicInfo">基本信息</a></li>
                                 <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#poj-settings-projFeature" id="tab_poj-settings-projFeature" role="tab">工程特征</a></li>
                                 <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#poj-settings-3" role="tab">指标信息</a></li>
-                                <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#poj-settings-4" role="tab">关于计算</a></li>
+                                <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#poj-settings-4" id="about-calc" role="tab">关于计算</a></li>
                                 <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#poj-settings-billsQuanDecimal" id="tab_poj-settings-bqDecimal" role="tab">清单工程量精度</a></li>
                                 <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#poj-settings-decimal" role="tab" id="tab_poj-settings-decimal">小数位数</a></li>
                                 <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#poj-settings-6" role="tab" id="tab_poj-settings-6">人工单价调整</a></li>
@@ -358,6 +358,27 @@
                                                 </label>
                                             </div>
                                         </fieldset>
+                                        <fieldset class="form-group">
+                                            <h5>计算选项</h5>
+                                            <div class="form-check">
+                                                <label class="form-check-label">
+                                                    <input class="form-check-input" type="checkbox" id="calc_main">
+                                                    主材、设备、未计价材料计取价差
+                                                </label>
+                                            </div>
+                                            <div class="form-check">
+                                                <label class="form-check-label">
+                                                    <input class="form-check-input" type="checkbox" id="calc_add">
+                                                    新增工料机计取价差
+                                                </label>
+                                            </div>
+                                            <div class="form-check">
+                                                <label class="form-check-label">
+                                                    <input class="form-check-input" type="checkbox" id="calc_est">
+                                                    暂估材料计取价差
+                                                </label>
+                                            </div>
+                                        </fieldset>
                                     </div>
                                 </div>
                                 <!--清单工程精度-->

+ 6 - 7
web/building_saas/main/js/models/calc_program.js

@@ -536,11 +536,6 @@ class CalcProgram {
                 template.compiledSeq.push(itemIdx);
             }
         };
-        let private_setup_seq = function(item, itemIdx){
-            if (template.compiledSeq.indexOf(itemIdx) < 0) {
-                private_parse_ref(item, itemIdx);
-            }
-        };
         let private_compile_items = function() {
             for (let idx of template.compiledSeq) {
                 let item = template.calcItems[idx];
@@ -584,8 +579,12 @@ class CalcProgram {
             }
 
             for (let i = 0; i < template.calcItems.length; i++) {
-                private_setup_seq(template.calcItems[i], i);
+                let item = template.calcItems[i];
+                if (template.compiledSeq.indexOf(i) < 0) {
+                    private_parse_ref(item, i);
+                }
             }
+
             if (template.errs.length == 0) {
                 private_compile_items();
                 template.hasCompiled = true;
@@ -956,7 +955,7 @@ class CalcProgram {
         };
     };
 
-/*    计算所有树结点(分3种情况),并返回发生变动的零散的多个树结点。
+    /* 计算所有树结点(分3种情况),并返回发生变动的零散的多个树结点。
     参数取值如下:
     calcAllType.catAll       计算所有树结点 (不指定参数时的默认值)
     calcAllType.catBills     计算所有清单 (改变项目属性中清单取费算法时会用到)

+ 3 - 0
web/building_saas/main/js/models/main_consts.js

@@ -132,3 +132,6 @@ const zanguCalcType = {
     common: 0,
     gatherMaterial: 1
 };
+
+const gljKeyArray =['code','name','specs','unit','type'];
+const gljLibKeyArray =['code', 'name', 'specs', 'unit', 'gljType']

+ 4 - 0
web/building_saas/main/js/models/project_glj.js

@@ -307,6 +307,8 @@ ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
 }
 
 ProjectGLJ.prototype.refreshProjectGLJPrice = function (data) {
+    let parentGlj = [];
+    //
     let projectGljs = this.datas.gljList;
     let indexList = ['code', 'name', 'specs', 'unit', 'type'];
     for (let d of data) {
@@ -324,9 +326,11 @@ ProjectGLJ.prototype.refreshProjectGLJPrice = function (data) {
                 this.setAdjustPrice(glj);
                 this.refreshRationGLJPrice(glj);
                 this.refreshTreeNodePriceIfNeed(glj);
+                parentGlj.push(glj);
             }
         }
     }
+    return parentGlj;
 }
 
 ProjectGLJ.prototype.setAdjustPrice = function (glj) {

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

@@ -447,7 +447,7 @@ var ration_glj = {
             serialNo == 0 ? serialNo = children.length : "";
             for (let con_key of GLJSelection) {
                 var glj = _.find(allGLJ, function (item) {
-                    let i_key = gljOprObj.getIndex(item, ['code', 'name', 'specs', 'unit', 'gljType']);
+                    let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
                     return i_key == con_key;
                 });
                 if (glj) {
@@ -529,7 +529,7 @@ var ration_glj = {
             GLJSelection.sort();
             _.forEach(GLJSelection, function (g) {
                 var glj = _.find(allGLJ, function (item) {
-                    var i_key = gljOprObj.getIndex(item, ['code', 'name', 'specs', 'unit', 'gljType']);
+                    var i_key = gljOprObj.getIndex(item, gljLibKeyArray);
                     return i_key == g;
                 });
                 var ration_glj = {
@@ -568,10 +568,10 @@ var ration_glj = {
         ration_glj.prototype.replaceGLJ = function (selectCode, oldData, callback) {
             var allGLJ = gljOprObj.AllRecode;
             var glj = _.find(allGLJ, function (item) {
-                var i_key = gljOprObj.getIndex(item, ['code', 'name', 'specs', 'unit', 'gljType']);
+                var i_key = gljOprObj.getIndex(item, gljLibKeyArray);
                 return i_key == selectCode;
             });
-            if (selectCode == gljOprObj.getIndex(oldData, ['code', 'name', 'specs', 'unit', 'type'])) {
+            if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
                 return callback(null);
             }
             if (oldData.createType != 'replace') {
@@ -603,10 +603,10 @@ var ration_glj = {
         ration_glj.prototype.mReplaceGLJ = function (selectCode, oldData, callback) {
             var allGLJ = gljOprObj.AllRecode;
             var glj = _.find(allGLJ, function (item) {
-                var i_key = gljOprObj.getIndex(item, ['code', 'name', 'specs', 'unit', 'gljType']);
+                var i_key = gljOprObj.getIndex(item, gljLibKeyArray);
                 return i_key == selectCode;
             });
-            if (selectCode == gljOprObj.getIndex(oldData, ['code', 'name', 'specs', 'unit', 'type'])) {
+            if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
                 return callback(null);
             }
             var query = {
@@ -678,7 +678,7 @@ var ration_glj = {
                     ration.basePrice = glj.unit_price.base_price;
                     ration.marketUnitFee = glj.unit_price.market_price;
                     ration.isAdd = glj.unit_price.is_add;
-                    var connect_index = gljOprObj.getIndex(glj, ['code', 'name', 'specs', 'unit', 'type'])
+                    var connect_index = gljOprObj.getIndex(glj, gljKeyArray);
                     if (mixRatioMap.hasOwnProperty(connect_index)) {
                         var mixRatios = gljOprObj.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
                         ration.subList = mixRatios;

+ 43 - 17
web/building_saas/main/js/views/glj_view.js

@@ -602,7 +602,7 @@ var gljOprObj = {
     },
     hasComposition:function (ration_glj) {//判断是否有组成物,有则返回true
         if(notEditType.indexOf(ration_glj.type)!=-1){
-            let con_key = this.getIndex(ration_glj,['code', 'name', 'specs', 'unit', 'type']);
+            let con_key = this.getIndex(ration_glj,gljKeyArray);
             var mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
             if(mixRatioMap[con_key]&&mixRatioMap[con_key].length>0){
                 return true;
@@ -712,6 +712,7 @@ var gljOprObj = {
         }
     },
     showRationGLJSheetData: function (init) {
+        this.combineWithProjectGlj(this.sheetData);
         this.sheet.setRowCount(0);
         //console.log(+new Date())
         //this.sheet.getRange(0,-1,this.sheet.getRowCount(),-1).visible(true); //这个方法导致加载缓慢
@@ -749,7 +750,7 @@ var gljOprObj = {
         return gljList;
     },
     showInSheet: function (gljList) {
-        this.sheetData = this.combineWithProjectGlj(gljList);
+        this.sheetData = gljList;
         this.showRationGLJSheetData(true);
     },
     sumQuantity: function (node) {
@@ -806,12 +807,9 @@ var gljOprObj = {
                     if (typeString.indexOf("2") != -1) {//只有材料类型才显示是否暂估
                         ration_gljs[i].isEstimate = glj.is_evaluate;
                     }
-                    ration_gljs[i].basePrice = glj.unit_price.base_price;
-                    ration_gljs[i].marketPrice = glj.unit_price.market_price;
-                    //ration_gljs[i].adjustPrice=glj.adjust_price;
                     ration_gljs[i].isAdd = glj.unit_price.is_add;
-                    ration_gljs[i].adjustPrice = projectObj.project.projectGLJ.getAdjustPrice(glj);
-                    var connect_index = this.getIndex(glj, ['code', 'name', 'specs', 'unit', 'type'])
+                    ration_gljs[i]=this.setGLJPrice(ration_gljs[i],glj);//设置工料机价格
+                    var connect_index = this.getIndex(glj, gljKeyArray)
                     if (mixRatioMap.hasOwnProperty(connect_index)) {
                         var mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
                         ration_gljs[i].subList = mixRatios;
@@ -821,6 +819,34 @@ var gljOprObj = {
         }
         return ration_gljs;
     },
+    setGLJPrice:function (data,glj) {
+        glj = glj?glj:_.find(projectObj.project.projectGLJ.datas.projectGljs, {'id': ration_gljs[i].projectGLJID});
+        if(this.calcPriceDiff(glj)==true) {//计取价差
+            data.basePrice = glj.unit_price.base_price;
+            data.marketPrice = glj.unit_price.market_price;
+            data.adjustPrice = projectObj.project.projectGLJ.getAdjustPrice(glj);
+        }else {//不计价差
+            data.basePrice = glj.unit_price.market_price;
+            data.marketPrice = glj.unit_price.market_price;
+            data.adjustPrice = glj.unit_price.market_price;
+        }
+        return data;
+
+    },
+    calcPriceDiff:function (glj) {
+        let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
+        if(glj.is_evaluate==1){//先按是否暂估判断
+            return calcOptions.calc_est;
+        }
+        if(glj.type==gljType.MAIN_MATERIAL||glj.type==gljType.EQUIPMENT){//再判断是否是主材和设备
+            return calcOptions.calc_main;
+        }
+        if(glj.unit_price.is_add==1){//再判断是否新增
+            return calcOptions.calc_add;
+        }
+        return true;
+    },
+
     getIndex(obj, pops){
         let t_index = '';
         let k_arr = [];
@@ -1084,7 +1110,7 @@ var gljOprObj = {
         }
     },
     addGLJsSelection: function (args, newVal) {
-        var con_key = this.getIndex(this.gljLibSheetData[args.row], ['code', 'name', 'specs', 'unit', 'gljType'])
+        var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
         if (newVal == 1) {
             this.GLJSelection.push(con_key);
             this.gljLibSheetData[args.row].select = 1;
@@ -1100,10 +1126,10 @@ var gljOprObj = {
             args.sheet.getCell(args.row, args.col).value(1);
             return;
         }
-        this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], ['code', 'name', 'specs', 'unit', 'gljType'])];
+        this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray)];
         this.gljLibSheetData[args.row].select = 1;
         var oindex = _.findIndex(this.gljLibSheetData, function (item) {
-            var i_key = me.getIndex(item, ['code', 'name', 'specs', 'unit', 'gljType']);
+            var i_key = me.getIndex(item, gljLibKeyArray);
             return oldSelection == i_key;
         });
         if (oindex != -1) {
@@ -1111,7 +1137,7 @@ var gljOprObj = {
             this.gljLibSheetData[oindex].select = 0;
         } else {
             var oldData = _.find(gljOprObj.AllRecode, function (item) {
-                var i_key = me.getIndex(item, ['code', 'name', 'specs', 'unit', 'gljType']);
+                var i_key = me.getIndex(item, gljLibKeyArray);
                 return oldSelection == i_key;
             });
             oldData ? oldData.select = 0 : "";
@@ -1172,7 +1198,7 @@ var gljOprObj = {
         var project = projectObj.project;
         gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
             var rg = _.find(gljOprObj.sheetData, function (item) {
-                var i_key = gljOprObj.getIndex(item, ['code', 'name', 'specs', 'unit', 'type']);
+                var i_key = gljOprObj.getIndex(item, gljKeyArray);
                 return n == i_key
             })
             return rg ? false : true;
@@ -1245,10 +1271,10 @@ var gljOprObj = {
         project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result) {
             var data = result.data;
             var stateList = result.stateList;
-            var n_index = me.getIndex(data.query, ['code', 'name', 'specs', 'unit', 'type']);
+            var n_index = me.getIndex(data.query, gljKeyArray);
             var nodes = [];
             _.forEach(project.ration_glj.datas, function (t) {
-                var t_index = me.getIndex(t, ['code', 'name', 'specs', 'unit', 'type']);
+                var t_index = me.getIndex(t, gljKeyArray);
                 if (n_index == t_index) {
                     me.updateProperty(t, data.doc);
                     if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
@@ -1444,15 +1470,15 @@ $(function () {
             gljOprObj.GLJSelection = [];
         } else {
             selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
-            var connect_key = gljOprObj.getIndex(selected, ['code', 'name', 'specs', 'unit', 'type'])
+            var connect_key = gljOprObj.getIndex(selected, gljKeyArray);
             gljOprObj.GLJSelection = [connect_key];
             gljOprObj.filterLibGLJByType();
         }
 
         if (selected != null) {
-            var s_key = gljOprObj.getIndex(selected, ['code', 'name', 'specs', 'unit', 'gljType']);
+            var s_key = gljOprObj.getIndex(selected, gljLibKeyArray);
             var r = _.find(gljOprObj.gljLibSheetData, function (item) {
-                var item_key = gljOprObj.getIndex(item, ['code', 'name', 'specs', 'unit', 'type']);
+                var item_key = gljOprObj.getIndex(item, gljKeyArray);
                 return s_key == item_key;
             });
             r ? r.select = 1 : "";

+ 44 - 14
web/building_saas/main/js/views/project_property_display_view.js

@@ -3,38 +3,68 @@
  */
 let projDisplayView = {
     datas: null,//just for view
-    init:function () {
+    init: function () {
         this.datas = projectInfoObj.projectInfo.property.displaySetting;
-        this.datas = this.datas === undefined ? { autoHeight: true, disPlayMainMaterial: true } : this.datas;
-        $("#autoHeight").attr("checked",this.datas.autoHeight);
-        $("#disPlayMainMaterial").attr("checked",this.datas.disPlayMainMaterial);
+        this.datas = this.datas === undefined ? {autoHeight: true, disPlayMainMaterial: true} : this.datas;
+        $("#autoHeight").attr("checked", this.datas.autoHeight);
+        $("#disPlayMainMaterial").attr("checked", this.datas.disPlayMainMaterial);
         //$('#disPlayMainMateria').prop('checked')
- },
+    },
 
-    needUpdate: function(autoHeight, disPlayMainMaterial) {
-        if(this.datas==null){
+    needUpdate: function (autoHeight, disPlayMainMaterial) {
+        if (this.datas == null) {
             return;
         }
         return autoHeight !== this.datas.autoHeight || disPlayMainMaterial !== this.datas.disPlayMainMaterial;
     },
 
-    updateChecking:function (projectID,properties) {
-        if(this.datas==null){
+    updateChecking: function (properties) {
+        if (this.datas == null) {
             return;
         }
-        var autoHeight = $('#autoHeight').prop('checked');
-        var disPlayMainMaterial = $('#disPlayMainMaterial').prop('checked');
-        if(this.datas.autoHeight!==autoHeight||this.datas.disPlayMainMaterial!==disPlayMainMaterial){
-            this.datas.autoHeight=autoHeight;
-            this.datas.disPlayMainMaterial=disPlayMainMaterial;
+        let autoHeight = $('#autoHeight').prop('checked');
+        let disPlayMainMaterial = $('#disPlayMainMaterial').prop('checked');
+        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['property.displaySetting'] = this.datas;
         }
     }
 };
 
+let calcOptions = {
+    datas: null,//just for view
+    init: function () {
+        this.datas = projectInfoObj.projectInfo.property.calcOptions;
+        $("#calc_main").attr("checked", this.datas.calc_main);
+        $("#calc_add").attr("checked", this.datas.calc_add);
+        $("#calc_est").attr("checked", this.datas.calc_est);
+    },
+    updateChecking: function (properties) {
+        if (this.datas == null) {
+            return false;
+        }
+        let calc_main = $('#calc_main').prop('checked');
+        let calc_add = $('#calc_add').prop('checked');
+        let calc_est = $('#calc_est').prop('checked');
+        if (this.datas.calc_main !== calc_main || this.datas.calc_add !== calc_add||this.datas.calc_est !== calc_est) {
+            this.datas.calc_main = calc_main;
+            this.datas.calc_add = calc_add;
+            this.datas.calc_est = calc_est;
+            properties['property.calcOptions'] = this.datas;
+            return true
+        }
+        return false
+    }
+}
+
+
 $(document).ready(function () {
     $('#tab_display_setting').on('shown.bs.tab', function () {
         projDisplayView.init();
     });
+    $('#about-calc').on('shown.bs.tab', function () {
+        calcOptions.init();
+    });
 });

+ 5 - 1
web/building_saas/main/js/views/project_view.js

@@ -863,7 +863,11 @@ $('#property_ok').click(function () {
         properties['property.decimal'] = updateDecimal;
     }
     // 呈现选项
-    projDisplayView.updateChecking(projectID, properties);
+    projDisplayView.updateChecking(properties);
+
+    if(calcOptions.updateChecking(properties)){
+        reCalcRations = true;
+    }
 
     // 人工系数
     if (labourCoeView.needSave()){

+ 6 - 4
web/building_saas/pm/js/pm_main.js

@@ -1726,10 +1726,12 @@ function getUsedObj(tenders, fileId, type){
     rst.usedCount = 0;
     rst.usedInfo = null;
     for(let i = 0, len = tenders.length; i < len; i++){
-        let theFile = type === fileType.unitPriceFile ? tenders[i].data.property.unitPriceFile || null : tenders[i].data.property.feeFile || null;
-        if(theFile && theFile.id == fileId){
-            usedCount ++;
-            usedInfo += tenders[i].data.name + '<br>';
+        if(tenders[i].data.property){
+            let theFile = type === fileType.unitPriceFile ? tenders[i].data.property.unitPriceFile || null : tenders[i].data.property.feeFile || null;
+            if(theFile && theFile.id == fileId){
+                usedCount ++;
+                usedInfo += tenders[i].data.name + '<br>';
+            }
         }
     }
     if(usedCount > 0){