Browse Source

feat: 计价规则可配置适用类型

zhangweicheng 2 years ago
parent
commit
0a3b43ab2a

+ 2 - 1
modules/all_models/compilation.js

@@ -21,7 +21,8 @@ let childrenSchema = new Schema({
     // 类型
     type: {
         type: Number
-    }
+    },
+    fileTypes:[Number]//创建项目时可用文件类型 估算,概算,预算
 },{_id: false});
 let modelSchema = {
     // 是否发布

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

@@ -502,6 +502,39 @@ class CompilationController extends BaseController {
         response.json(responseData);
     }
 
+
+    /**
+     * 设置计价规则适用类型
+     *
+     * @param {object} request
+     * @param {object} response
+     * @return {void}
+     */
+     async setFileTypes(request, response) {
+        let id = request.body.id;
+        let section = request.params.section;
+        let fileTypes = request.body.fileTypes;
+
+        let responseData = {
+            err: 0,
+            msg: ''
+        };
+        try {
+            let compilationModel = new CompilationModel();
+            let result = await compilationModel.setFileTypes(id, section, fileTypes);
+
+            if (!result) {
+                throw '设置类型失败';
+            }
+        } catch (error) {
+            console.log(error);
+            responseData.err = 1;
+            responseData.msg = error;
+        }
+
+        response.json(responseData);
+    }
+
     /**
      * 发布/取消编办
      *

+ 23 - 1
modules/users/models/compilation_model.js

@@ -37,7 +37,7 @@ class CompilationModel extends BaseModel {
     async getCompilationList(fields = null) {
         // 筛选字段
         let field = fields == null ?{_id: 1, name: 1, is_release: 1, release_time:1,categoryID: 1, description: 1,overWriteUrl: 1,example: 1,edition: 1, "ration_valuation.id": 1, "ration_valuation.name": 1, "ration_valuation.enable": 1,
-            "bill_valuation.id": 1, "bill_valuation.name": 1, "bill_valuation.enable": 1}:fields;
+            "bill_valuation.id": 1, "bill_valuation.name": 1, "bill_valuation.enable": 1, "bill_valuation.fileTypes": 1}:fields;
         let compilationData = await this.findDataByCondition({name: {$ne: ''}}, field, false);
 
         return compilationData === null ? [] : compilationData;
@@ -243,6 +243,28 @@ class CompilationModel extends BaseModel {
         return result !== null && result.ok === 1;
     }
 
+    
+    /**
+     * 设置计价规则适用类型
+     *
+     * @param {String} valuationId
+     * @param {String} section
+     * @param {String} setFileTypes
+     * @return {Promise}
+     */
+     async setFileTypes(valuationId, section, fileTypes) {
+        let sectionString = section + "_valuation";
+        let condition = {};
+        condition[sectionString + ".id"] = valuationId;
+
+        let updateData = {};
+        updateData[sectionString + ".$.fileTypes"] = fileTypes;
+
+        let result = await this.db.update(condition, updateData);
+
+        return result !== null && result.ok === 1;
+    }
+
     /**
      * 过滤计价数据
      *

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

@@ -30,6 +30,7 @@ module.exports = function (app) {
     router.post('/delete-engineer', compilationController.auth, compilationController.init, compilationController.deleteEngineer);
     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);
     router.post('/template/:section/:id/:engineering/update', compilationController.auth, compilationController.init, compilationController.updateBillsTemplate);
     router.post('/addEngineer', compilationController.auth, compilationController.init, compilationController.addEngineer);
     router.post('/copyRationLibs', compilationController.auth, compilationController.init, compilationController.copyRationLibs);

+ 1 - 1
web/maintain/ration_repository/js/ration_coe.js

@@ -327,7 +327,7 @@ var rationCoeOprObj = {
                     sheetCommonObj.cleanData(me.sheet, me.setting, -1);
                     if (result.data) {
                         var tempResult = [];
-                        let stdMap = _.indexBy(result.data,'ID');
+                        let stdMap = _.keyBy(result.data,'ID');
                         for(let i = 0, len = coeList.length; i < len; i++){
                             let obj = stdMap[coeList[i].ID];
                             if(obj){

+ 48 - 4
web/users/js/compilation.js

@@ -515,6 +515,50 @@ $(document).ready(function() {
         });
     });
 
+
+    // 设置适用类型
+    $(".fileType").change(function() {
+       
+        let id = $(this).data('id');
+        if (id === undefined || id === '' || isAdding) {
+            return false;
+        }
+        let fileTypes = [];
+        let oldVal = $(this).attr("checked");
+        if(oldVal){
+            $(this).removeAttr("checked") 
+        }else{
+           $(this).attr("checked","checked")
+        }
+
+        if($('#'+id+'_gusuan').attr("checked")) fileTypes.push(15);
+        if($('#'+id+'_estimate').attr("checked")) fileTypes.push(5);
+        if($('#'+id+'_submission').attr("checked")) fileTypes.push(1);
+        let current = $(this);
+
+        console.log(id,this);
+        $.ajax({
+            url: '/compilation/valuation/' + section + '/fileTypes',
+            type: 'post',
+            dataType: "json",
+            data: {id: id, fileTypes: fileTypes},
+            error: function() {
+                //恢复原值
+               if(oldVal){
+                current.attr("checked","checked")
+               }else{
+                current.removeAttr("checked") 
+               }
+            },
+            success: function(response) {
+                if (response.err !== 0) {
+                    switchChange($(this));
+                    alert('更改失败');
+                }
+            }
+        });
+    });
+
     //计价规则删除
     $('#delete-confirm').click(function () {
         let id = $('#del').attr('selectedId');
@@ -1115,10 +1159,10 @@ function getGroupIndex(groupData) {//用来做唯一标识
     return index;
 }
 function getTaxGroupData() {
-    let programData = programList === undefined ? [] : _.indexBy(JSON.parse(programList), 'id');
-    let billTemplateData = billTemplateList == undefined ? [] : _.indexBy(JSON.parse(billTemplateList),'ID');
-    let mainTreeColData= mainTreeColList == undefined ? [] :  _.indexBy(JSON.parse(mainTreeColList),'ID');
-    let feeLibData = feeRateList === undefined ? [] : _.indexBy(JSON.parse(feeRateList),'id');
+    let programData = programList === undefined ? [] : _.keyBy(JSON.parse(programList), 'id');
+    let billTemplateData = billTemplateList == undefined ? [] : _.keyBy(JSON.parse(billTemplateList),'ID');
+    let mainTreeColData= mainTreeColList == undefined ? [] :  _.keyBy(JSON.parse(mainTreeColList),'ID');
+    let feeLibData = feeRateList === undefined ? [] : _.keyBy(JSON.parse(feeRateList),'id');
     let groupData = {};
     if($("#taxType").val() !==""){
         groupData.taxType = $("#taxType").val();

+ 11 - 0
web/users/views/compilation/index.html

@@ -27,6 +27,7 @@
                     <tr>
                         <th>计价规则</th>
                         <th>启用/禁用</th>
+                        <th>适用类型</th>
                         <th>操作</th>
                     </tr>
                     </thead>
@@ -49,6 +50,11 @@
                             <% } %>
                         </td>
                         <td>
+                           <input type="checkbox" data-id="<%= bill.id %>" class="fileType" id="<%= bill.id %>_gusuan" <% if (bill.fileTypes && bill.fileTypes.includes(15)) { %> checked <% } %> /> 估算  
+                            <input type="checkbox" data-id="<%= bill.id %>" class="fileType" id="<%= bill.id %>_estimate"  <% if (bill.fileTypes && bill.fileTypes.includes(5)) { %> checked <% } %>  /> 概算    
+                            <input type="checkbox" data-id="<%= bill.id %>" class="fileType" id="<%= bill.id %>_submission" <% if (bill.fileTypes && bill.fileTypes.includes(1)) { %> checked <% } %>  /> 预算      
+                        </td>
+                        <td>
                             <a href="/compilation/valuation/bill/<%= bill.id %>" class="btn btn-sm">编辑</a>
                             <a onclick="$('#del').attr('selectedId', '<%= bill.id %>')" href="#" data-id="<%= bill.id %>" data-toggle="modal" data-target="#del" class="btn btn-sm text-danger">删除</a>
                             <!--<a href="/compilation/valuation/bill/delete/<%= bill.id %>" class="btn btn-sm text-danger">删除</a>-->
@@ -66,6 +72,7 @@
                     <tr>
                         <th>计价规则</th>
                         <th>启用/禁用</th>
+                        <th>适用类型</th>
                         <th>操作</th>
                     </tr>
                     </thead>
@@ -88,6 +95,10 @@
                             <% } %>
                         </td>
                         <td>
+
+                            
+                        </td>
+                        <td>
                             <a href="/compilation/valuation/ration/<%= ration.id %>" class="btn btn-sm">编辑</a>
                             <a href="/compilation/valuation/ration/delete/<%= ration.id %>" class="btn btn-sm text-danger">删除</a>
                         </td>