Browse Source

动态投资,汇总条件相关

MaiXinRong 3 weeks ago
parent
commit
813c4cecba

+ 4 - 0
app/controller/budget_controller.js

@@ -131,6 +131,10 @@ module.exports = app => {
         async compareFinal(ctx) {
             try {
                 const data = JSON.parse(ctx.request.body.data);
+                if (data.final_type !== ctx.budget.final_type) {
+                    await ctx.service.budget.defaultUpdate({ id: ctx.budget.id, final_type: data.final_type });
+                    ctx.budget.final_type === data.final_type;
+                }
                 if (ctx.budget.final_id && data.final_id !== ctx.budget.final_id) {
                     const final = await ctx.service.budgetFinal.getAllDataByCondition({ where: { final_id: ctx.budget.final_id } });
                     const finalInfo = await ctx.service.budgetFinalList.getFinal(ctx.budget.final_id);

+ 9 - 1
app/lib/budget_final.js

@@ -16,16 +16,23 @@ class FinalTree extends BillsTree {
     constructor(ctx, setting) {
         super(ctx, setting);
         this._newId = 1;
+        this.checkField = ['code', 'name'];
     }
+
     get newId() {
         return this._newId++;
     }
 
     loadNode(node, parent, loadFun) {
         if (node.b_code) return;
+        const checkField = this.checkField;
         const siblings = parent ? parent.children : this.children;
         let cur = siblings.find(function (x) {
-            return x.code === node.code && x.name === node.name;
+            for (const cf of checkField) {
+                if (x[cf] !== node[cf]) return false;
+            }
+            return true;
+            // return x.code === node.code && x.name === node.name;
         });
         if (!cur) {
             cur = { children: [], code: node.code || '', name: node.name || '', unit: node.unit || '' };
@@ -293,6 +300,7 @@ class BudgetFinal {
     async doFinal(budget, final) {
         this.budget = budget;
         this.final = final;
+        this.finalTree.checkField = budget.final_type.split('_');
 
         await this._loadGai(budget);
         await this._loadGu(budget);

+ 2 - 1
app/public/js/budget_compare.js

@@ -488,7 +488,8 @@ $(document).ready(() => {
             $('#select-final-ok').click(() => {
                 const rela = self.getSelects();
                 if (rela.length === 0) return;
-                postData(window.location.pathname + '/final', {final_id: compareObj.curFinalId(), id: rela}, function(result, msg) {
+                const data = { final_id: compareObj.curFinalId(), id: rela, final_type: $('[name=final_type]:checked').val() };
+                postData(window.location.pathname + '/final', data, function(result, msg) {
                     compareObj.loadFinalData(result, msg);
                     $('#select-final').modal('hide');
                 });

+ 10 - 0
app/view/budget/compare_modal.ejs

@@ -9,6 +9,16 @@
                 <div id="sf-spread" style="height: 300px"></div>
             </div>
             <div class="modal-footer">
+                <div class="form-check form-check-inline">汇总条件:</div>
+                <div class="form-check form-check-inline">
+                    <input class="form-check-input" type="radio" name="final_type" id="inlineRadio2" value="code" <%if (ctx.budget.final_type === 'code') {%> checked <% }%>>
+                    <label class="form-check-label" for="inlineRadio2">编号</label>
+                </div>
+                <div class="form-check form-check-inline" style="margin-right: 136px">
+                    <% console.log(ctx.budget) %>
+                    <input class="form-check-input" type="radio" name="final_type" id="inlineRadio3" value="code_name" <%if (ctx.budget.final_type === 'code_name') {%> checked <% }%>>
+                    <label class="form-check-label" for="inlineRadio3">编号+名称</label>
+                </div>
                 <div class="form-check form-check-inline">
                     <input class="form-check-input" type="checkbox" id="sf-select-all">
                     <label class="form-check-label" for="sr-select-all">全选</label>

+ 3 - 0
sql/update.sql

@@ -65,6 +65,9 @@ ADD COLUMN `check_api` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NO
 ALTER TABLE `zh_tender_permission`
 ADD COLUMN `inspection` varchar(255) NOT NULL DEFAULT '' COMMENT '质量巡检权限(,分隔,具体见代码定义)' AFTER `quality`;
 
+ALTER TABLE `zh_budget`
+ADD COLUMN `final_type` varchar(50) NOT NULL DEFAULT 'code_name' COMMENT '决算汇总规则' AFTER `final_id`;
+
 ------------------------------------
 -- 表数据
 ------------------------------------