Selaa lähdekoodia

feat: 拷贝工程专业

vian 1 vuosi sitten
vanhempi
commit
7eaf6b2c8e

+ 27 - 0
modules/users/controllers/compilation_controller.js

@@ -384,6 +384,33 @@ class CompilationController extends BaseController {
     }
 
     /**
+     * 通过工程专业ID拷贝工程专业
+     * @param request
+     * @param response
+     * @returns {Promise.<void>}
+     */
+    async copyEngineer(request, response) {
+        let result = {
+            error: 0
+        };
+        try {
+            let data = request.body.data;
+            data = JSON.parse(data);
+            if (data.id) {
+                let engineeringLibModel = new EngineeringLibModel();
+                result.data = await engineeringLibModel.copyEngineer(data.id);
+            } else {
+                throw new Error("提交数据有误");
+            }
+        } catch (err) {
+            console.log(err);
+            result.error = 1;
+            result.message = err.message;
+        }
+        response.json(result);
+    }
+
+    /**
      * 修改保存工程专业信息-用于异步操作
      * @param request
      * @param response

+ 65 - 56
modules/users/models/engineering_lib_model.js

@@ -9,7 +9,7 @@ import mongoose from "mongoose";
 import BaseModel from "../../common/base/base_model";
 import CompilationModel from "./compilation_model";
 let stdRationLibModel = mongoose.model("std_ration_lib_map");
-import {default as EngineeringConst, List as EngineeringList} from "../../common/const/engineering";
+import { default as EngineeringConst, List as EngineeringList } from "../../common/const/engineering";
 const billsGuidanceLibModel = mongoose.model('std_billsGuidance_lib');
 const billsLibListsModel = mongoose.model('std_bills_lib_lists');
 
@@ -38,7 +38,7 @@ class EngineeringLibModel extends BaseModel {
             return result;
         }
         let id = '';
-        for(let tmp of data) {
+        for (let tmp of data) {
             if (tmp.engineering === engineering) {
                 id = tmp.engineering_id;
                 break;
@@ -47,16 +47,16 @@ class EngineeringLibModel extends BaseModel {
         if (id === '') {
             return result;
         }
-        let condition = {_id: id};
+        let condition = { _id: id };
         return this.findDataByCondition(condition);
     }
 
-    async getLibsByValuationID(valuationID){
-        return this.findDataByCondition({valuationID:valuationID},null,false);
+    async getLibsByValuationID(valuationID) {
+        return this.findDataByCondition({ valuationID: valuationID }, null, false);
     }
 
-    async deleteByValuationID(valuationID){
-        return await this.db.delete({valuationID:valuationID});
+    async deleteByValuationID(valuationID) {
+        return await this.db.delete({ valuationID: valuationID });
     }
 
 
@@ -65,14 +65,14 @@ class EngineeringLibModel extends BaseModel {
      * @param valuationID
      * @returns {Promise.<*>}
      */
-    async addStdLib(valuationID){
+    async addStdLib(valuationID) {
         let stdLibs = [];
-        for(let eng of EngineeringList){
+        for (let eng of EngineeringList) {
             let tem = {
-                glj_col:{showAdjustPrice:false},
-                valuationID:valuationID,
-                name:eng.name,
-                engineering:eng.value
+                glj_col: { showAdjustPrice: false },
+                valuationID: valuationID,
+                name: eng.name,
+                engineering: eng.value
             };
             stdLibs.push(tem);
         }
@@ -80,18 +80,18 @@ class EngineeringLibModel extends BaseModel {
         return result;
     }
 
-    async addEngineer(data){
-        data.glj_col = {showAdjustPrice:false};
-        if(data.compilationId && data.compilationId!=""){
+    async addEngineer(data) {
+        data.glj_col = { showAdjustPrice: false };
+        if (data.compilationId && data.compilationId != "") {
             data.ration_lib = [];
-            let rationList = await stdRationLibModel.find({compilationId:data.compilationId},['ID','dispName']);
-            for(let i =0;i< rationList.length;i++){
+            let rationList = await stdRationLibModel.find({ compilationId: data.compilationId }, ['ID', 'dispName']);
+            for (let i = 0; i < rationList.length; i++) {
                 let tem = {
-                    id:rationList[i].ID,
-                    name:rationList[i].dispName,
-                    isDefault:false
+                    id: rationList[i].ID,
+                    name: rationList[i].dispName,
+                    isDefault: false
                 };
-                if(i == 0) tem.isDefault = true;
+                if (i == 0) tem.isDefault = true;
                 data.ration_lib.push(tem);
             }
         }
@@ -99,6 +99,15 @@ class EngineeringLibModel extends BaseModel {
         return result;
     }
 
+    // 拷贝工程专业
+    async copyEngineer(sourceID) {
+        const engineering = await this.db.findOne({ _id: sourceID });
+        const newEngineering = engineering._doc;
+        delete newEngineering._id;
+        newEngineering.visible = false;
+        await this.db.create(newEngineering);
+    }
+
     /**
      * 新增标准库
      *
@@ -107,12 +116,12 @@ class EngineeringLibModel extends BaseModel {
      * @return {Promise}
      */
     async addLib(engineerId, data) {
-        if(data.glj_col){
-            data.glj_col =  JSON.parse(data.glj_col);
+        if (data.glj_col) {
+            data.glj_col = JSON.parse(data.glj_col);
         }
-        data.isInstall == 'true'?data.isInstall=true:data.isInstall=false;
-        data.isItemIncrease == 'true'?data.isItemIncrease=true:data.isItemIncrease=false;
-        data.isAreaIncrease == 'true'?data.isAreaIncrease=true:data.isAreaIncrease=false;
+        data.isInstall == 'true' ? data.isInstall = true : data.isInstall = false;
+        data.isItemIncrease == 'true' ? data.isItemIncrease = true : data.isItemIncrease = false;
+        data.isAreaIncrease == 'true' ? data.isAreaIncrease = true : data.isAreaIncrease = false;
         let result = false;
         data = this.filterLibData(data);
         try {
@@ -136,16 +145,16 @@ class EngineeringLibModel extends BaseModel {
                     lib.libType = libTypeMap[lib.id] || '1';
                 });
             }
-            let engineeringLib = await this.findDataByCondition({_id:engineerId});
-            if(engineeringLib){
+            let engineeringLib = await this.findDataByCondition({ _id: engineerId });
+            if (engineeringLib) {
                 // 存在则直接更新
                 delete data.id;
                 delete data.section;
-                let condition = {_id: engineerId};
+                let condition = { _id: engineerId };
                 result = await this.db.update(condition, data);
                 result = result.ok === 1;
-            }else {
-                throw  new Error("找不到对应的工程专业");
+            } else {
+                throw new Error("找不到对应的工程专业");
             }
 
         } catch (error) {
@@ -170,16 +179,16 @@ class EngineeringLibModel extends BaseModel {
         data.engineering = parseInt(data.engineering);
         //需求修改,工程专业可以随便输入了
         //检测专业工程是否合法
-   /*     let match = false;
-        for(let index in EngineeringConst) {
-            if (EngineeringConst[index] === data.engineering) {
-                match = true;
-                break;
-            }
-        }
-        if (!match) {
-            throw '工程专业错误';
-        }*/
+        /*     let match = false;
+             for(let index in EngineeringConst) {
+                 if (EngineeringConst[index] === data.engineering) {
+                     match = true;
+                     break;
+                 }
+             }
+             if (!match) {
+                 throw '工程专业错误';
+             }*/
 
         // 判断标准清单
         data.bill_lib = this._validLib(data.bill_lib);
@@ -243,24 +252,24 @@ class EngineeringLibModel extends BaseModel {
     _validLib(libData) {
         let result = [];
         // 判断标准库
-        if (libData === undefined || libData ===null ||libData === '') {
+        if (libData === undefined || libData === null || libData === '') {
             return result;//throw '标准库不能为空'; 按新需求,标准库等不做非空判断
         }
         libData = libData instanceof Array ? libData : [libData];
-        for(let tmp in libData) {
+        for (let tmp in libData) {
             result[tmp] = JSON.parse(libData[tmp]);
         }
         return result;
     }
 
     //设置默认定额库
-    setDefaultRation(data){
-        if(data.ration_lib && data.ration_lib.length>0){
-            if(data.ration_isDefault && data.ration_isDefault != ""){
-                for(let r of data.ration_lib){
-                    r.id.toString() == data.ration_isDefault?r.isDefault = true:r.isDefault=false;
+    setDefaultRation(data) {
+        if (data.ration_lib && data.ration_lib.length > 0) {
+            if (data.ration_isDefault && data.ration_isDefault != "") {
+                for (let r of data.ration_lib) {
+                    r.id.toString() == data.ration_isDefault ? r.isDefault = true : r.isDefault = false;
                 }
-            }else {
+            } else {
                 data.ration_lib[0].isDefault = true;
             }
         }
@@ -281,11 +290,11 @@ class EngineeringLibModel extends BaseModel {
 
         // 整理需要查找的数据
         let findIdList = [];
-        for(let engineering of valuationData.engineering_list) {
+        for (let engineering of valuationData.engineering_list) {
             findIdList.push(engineering.engineering_id);
         }
 
-        let condition = {_id: {$in: findIdList}};
+        let condition = { _id: { $in: findIdList } };
         let libData = await this.findDataByCondition(condition, null, false);
         if (libData === null) {
             return result;
@@ -293,7 +302,7 @@ class EngineeringLibModel extends BaseModel {
 
         // 整理数据
         let countData = {};
-        for(let tmp of libData) {
+        for (let tmp of libData) {
             countData[tmp._id] = {
                 bill_count: tmp.bill_lib.length,
                 ration_count: tmp.ration_lib.length,
@@ -305,7 +314,7 @@ class EngineeringLibModel extends BaseModel {
         }
 
 
-        for(let engineering of valuationData.engineering_list) {
+        for (let engineering of valuationData.engineering_list) {
             if (countData[engineering.engineering_id] !== undefined) {
                 result[engineering.engineering] = countData[engineering.engineering_id];
             }
@@ -316,7 +325,7 @@ class EngineeringLibModel extends BaseModel {
 
     async copyRationLibsToOthers(valuationID, engineeringID) {
         const compilationModel = new CompilationModel();
-        const compilation = await compilationModel.model.findOne({ $or: [{ 'bill_valuation.id': valuationID }, { 'ration_valuation.id': valuationID }]});
+        const compilation = await compilationModel.model.findOne({ $or: [{ 'bill_valuation.id': valuationID }, { 'ration_valuation.id': valuationID }] });
         if (!compilation) {
             return;
         }
@@ -329,7 +338,7 @@ class EngineeringLibModel extends BaseModel {
         if (!engineering) {
             return;
         }
-        await this.model.updateMany({ valuationID: { $in: valuationIDList } }, {$set: { ration_lib: engineering.ration_lib }});
+        await this.model.updateMany({ valuationID: { $in: valuationIDList } }, { $set: { ration_lib: engineering.ration_lib } });
     }
 
 }

+ 1 - 0
modules/users/routes/compilation_route.js

@@ -29,6 +29,7 @@ module.exports = function (app) {
     router.post('/save-valuation', compilationController.auth, compilationController.init, compilationController.saveValuation);
     router.post('/update-engineer', compilationController.auth, compilationController.init, compilationController.updateEngineer);
     router.post('/delete-engineer', compilationController.auth, compilationController.init, compilationController.deleteEngineer);
+    router.post('/copy-engineer', compilationController.auth, compilationController.init, compilationController.copyEngineer);
     router.post('/save-lib', compilationController.auth, compilationController.init, compilationController.saveEngineering);
     router.post('/valuation/:section/enable', compilationController.auth, compilationController.init, compilationController.enableSwitch);
     router.post('/valuation/:section/fileTypes', compilationController.auth, compilationController.init, compilationController.setFileTypes);

+ 11 - 0
web/users/js/compilation.js

@@ -1175,6 +1175,17 @@ function deleteEngineerClick(engineerID, element) {
     }, null, ['确定', '取消'], false);
 }
 
+function copyEngineerClick(engineerID) {
+    hintBox.infoBox('操作确认', '是否拷贝所选工程专业?', 2, async function () {
+        try {
+            await ajaxPost('/compilation/copy-engineer', { id: engineerID });
+            window.location.reload();
+        } catch (err) {
+            console.log(err);
+        }
+    }, null, ['确定', '取消'], false);
+}
+
 
 function engineerVisibleChange(checkBox, engineerID) {
     if (engineerID) {

+ 3 - 1
web/users/views/compilation/add.html

@@ -114,7 +114,9 @@
                                     <td><%= engineering.ration_lib.length %></td>
                                     <td><%= engineering.glj_lib.length %></td>
                                     <td><label><input type="checkbox"  <% if (engineering.visible) { %>checked<% } %>  onclick='engineerVisibleChange(this,"<%= engineering._id.toString()%>")'> 显示</label></td>
-                                    <td><a class="btn-link" href="/compilation/<%= section %>/<%= valuationId %>/<%= engineering._id.toString()%>">编辑</a>/<a onclick="deleteEngineerClick('<%= engineering._id.toString()%>',this)" class='btn btn-link btn-sm' style="padding: 0px">删除</a></td>
+                                    <td>
+                                        <a class="btn-link" href="/compilation/<%= section %>/<%= valuationId %>/<%= engineering._id.toString()%>">编辑</a>/<a onclick="deleteEngineerClick('<%= engineering._id.toString()%>',this)" class='btn btn-link btn-sm' style="padding: 0px">删除</a>/<a onclick="copyEngineerClick('<%= engineering._id.toString()%>')" class='btn btn-link btn-sm' style="padding: 0px">拷贝</a>
+                                    </td>
                                 </tr>
                                 <% }) %>
                             </tbody>