Browse Source

选择其他建筑项目时另存为操作

olym 7 years ago
parent
commit
f37afb0d17

+ 16 - 3
modules/glj/controllers/glj_controller.js

@@ -318,23 +318,36 @@ class GLJController extends BaseController {
     async changeUnitPriceFile(request, response) {
         let projectId = request.body.project_id;
         let changeUnitPriceId = request.body.change_id;
+        let type = request.body.type;
+        type = parseInt(type);
         let responseData = {
             err: 0,
             msg: ''
         };
         try {
             let currentUnitPriceId = await ProjectModel.getUnitPriceFileId(projectId);
+            let unitPriceFileModel = new UnitPriceFileModel();
 
+            let insertData = null;
+            if (type > 0) {
+                let currentUnitPrice = await unitPriceFileModel.findDataByCondition({id: changeUnitPriceId});
+                if (currentUnitPrice === null) {
+                    throw '不存在对应单价文件';
+                }
+                insertData = JSON.parse(JSON.stringify(currentUnitPrice));
+                delete insertData._id;
+                delete insertData.ID;
+            }
             // 获取即将更改的单价文件信息
-            let unitPriceFileModel = new UnitPriceFileModel();
-            let targetUnitPriceFile = await unitPriceFileModel.findDataByCondition({id: changeUnitPriceId});
+            let targetUnitPriceFile = type === 0 ? await unitPriceFileModel.findDataByCondition({id: changeUnitPriceId}) :
+                await unitPriceFileModel.add(insertData);
             if (targetUnitPriceFile === null) {
                 throw '没有找到对应的单价文件';
             }
 
             // 查找对应单价文件的项目工料机数据
             let unitPriceModel = new UnitPriceModel();
-            let copyResult = await unitPriceModel.copyNotExist(currentUnitPriceId, changeUnitPriceId);
+            let copyResult = await unitPriceModel.copyNotExist(currentUnitPriceId, targetUnitPriceFile.id);
             // 复制成功后更改project数据
             if (!copyResult) {
                 throw '复制数据失败';

+ 2 - 2
modules/pm/models/project_model.js

@@ -286,7 +286,7 @@ ProjectsDAO.prototype.getTenderByUnitPriceFileId = async function(unitPriceFileI
         return result;
     }
 
-    let condition = {projType: 'Tender', "property.unitPriceFile.id": unitPriceFileId + ''};
+    let condition = {projType: 'Tender', "property.unitPriceFile.id": unitPriceFileId};
     result = await Projects.find(condition);
 
     return result;
@@ -305,7 +305,7 @@ ProjectsDAO.prototype.getUnitPriceFileId = async function(projectId) {
         return result;
     }
 
-    result = projectData.property.unitPriceFile.id;
+    result = projectData.property.unitPriceFile !== undefined ? projectData.property.unitPriceFile.id : 0;
     return result;
 };
 

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

@@ -163,7 +163,7 @@ $(document).ready(function () {
         $.ajax({
             url: '/glj/change-file',
             type: 'post',
-            data: {project_id: scUrlUtil.GetQueryString('project'), change_id: changeUnitPriceId},
+            data: {project_id: scUrlUtil.GetQueryString('project'), change_id: changeUnitPriceId, type: type},
             error: function() {
                 isChanging = false;
             },