Browse Source

支付审批添加表单树结构

laiguoran 2 years ago
parent
commit
ff003cbe3f

+ 18 - 1
app/controller/payment_controller.js

@@ -508,7 +508,10 @@ module.exports = app => {
             // 获取报表表单列表
             if (ctx.payment.auditPermission.view_all || ctx.tender.uid === ctx.session.sessionUser.accountId || formProcess) {
                 const rptProject = await ctx.service.rptTreeNode.getDataByCondition({ pid: ctx.session.sessionProject.id, name: '01.支付审批报表' });
-                const rptProjectList = rptProject && rptProject.items ? JSON.parse(rptProject.items) : [];
+                const rptProjectList = [];
+                const newRptList = rptProject && rptProject.items ? JSON.parse(rptProject.items) : [];
+                ctx.rptListNum = 0;
+                await this.getNewRptProjectList(ctx, newRptList, rptProjectList, 1);
                 const tenderRptList = await ctx.service.paymentTenderRpt.getProcessList(ctx.tender.id);
                 if (tenderRptList === -1) {
                     throw '未配置审批模块,请联系管理员处理';
@@ -517,6 +520,20 @@ module.exports = app => {
             }
             return await ctx.service.paymentTenderRpt.getList(ctx.tender.id, ctx.session.sessionUser.accountId);
         }
+        // 循环获取到到rptProject
+        async getNewRptProjectList(ctx, newRptList, rptProjectList, level = 1) {
+            if (newRptList.length > 0) {
+                for (const r of newRptList) {
+                    r.level = level;
+                    r.index = ctx.rptListNum;
+                    ctx.rptListNum = ctx.rptListNum + 1;
+                    rptProjectList.push(r);
+                    if (r.items && r.items.length > 0) {
+                        await this.getNewRptProjectList(ctx, r.items, rptProjectList, level + 1);
+                    }
+                }
+            }
+        }
 
         async process(ctx) {
             try {

+ 37 - 1
app/public/js/payment_process.js

@@ -3,8 +3,12 @@ $(function () {
 
     // 全选报表
     $('#select_all_rpt_checkbox').click(function () {
-        $('#rpt_table input[name="rptId[]"]').prop('checked', true);
         $(this).prop('checked', false);
+        $('#rpt_table input[name="rptId[]"]').each(function () {
+            if (parseInt($(this).val()) !== -1) {
+                $(this).prop('checked', true);
+            }
+        });
     });
 
     $('#add_rpt_btn').click(function () {
@@ -350,5 +354,37 @@ $(function () {
             '                                        </span>\n' +
             '                                        </li>';
         return html;
+    };
+
+    $('#add-rpt').on('show.bs.modal', function () {
+        $('#rpt-table').find('input:checked:not(:disabled)').prop('checked', false);
+        $('#rpt-table').find('input:not(:disabled)').each(function () {
+            if (_.findIndex(tenderRptList, { rpt_id: parseInt($(this).val()) }) !== -1) {
+                $(this).prop('checked', true);
+            }
+        });
+    });
+
+    $('#rpt_table input').on('click', function () {
+        if ($(this).is(':checked') && parseInt($(this).val()) === -1) {
+            $(this).prop('checked', false);
+            const index = $("#rpt_table input").index(this);
+            console.log(rptProjectList[index]);
+            // 循环选中当前子项值
+            checkedRptProjectList(rptProjectList[index].items);
+        }
+    });
+
+    function checkedRptProjectList(items) {
+        if (items && items.length > 0) {
+            for (const item of items) {
+                if (item.ID !== -1 && item.items === null) {
+                    console.log(item);
+                    $('#rpt_table input').eq(item.index).prop('checked', true);
+                } else {
+                    checkedRptProjectList(item.items);
+                }
+            }
+        }
     }
 });

+ 2 - 0
app/view/payment/process.ejs

@@ -141,4 +141,6 @@
     const accountList = JSON.parse(unescape('<%- escape(JSON.stringify(accountList)) %>'));
     const cur_uid = parseInt('<%- ctx.tender.uid %>');
     let tenderRptList = JSON.parse(unescape('<%- escape(JSON.stringify(tenderRptList)) %>'));
+    const rptProjectList = JSON.parse(unescape('<%- escape(JSON.stringify(rptProjectList)) %>'));
+    console.log(rptProjectList);
 </script>

+ 6 - 4
app/view/payment/process_modal.ejs

@@ -4,7 +4,7 @@
             <div class="modal-header">
                 <h5 class="modal-title">添加表单</h5>
             </div>
-            <div class="modal-body">
+            <div class="modal-body" style="max-height:800px;overflow: auto">
                 <table id="rpt-table" class="table table-bordered">
                     <thead>
                     <tr>
@@ -15,9 +15,11 @@
                     <tbody id="rpt_table">
                     <% for (const rpt of rptProjectList) { %>
                     <tr>
-                        <td class="text-center"><input type="checkbox" name="rptId[]" data-name="<%- rpt.name %>" value="<%- rpt.ID %>"
-                                                       <% if (ctx.helper._.findIndex(tenderRptList, { rpt_id: rpt.ID }) !== -1) { %>checked<% } %> <% if (rpt.had_rpt) { %>disabled<% } %>></td>
-                        <td><%- rpt.name %></td>
+                        <td class="text-center">
+                            <input type="checkbox" name="rptId[]" data-name="<%- rpt.name %>" value="<%- rpt.ID %>"
+                                                       <% if (ctx.helper._.findIndex(tenderRptList, { rpt_id: rpt.ID }) !== -1) { %>checked<% } %> <% if (rpt.had_rpt) { %>disabled<% } %>>
+                        </td>
+                        <td class="in-<%- rpt.level %>"><% if (rpt.items && rpt.items.length > 0) { %><i class="fa fa-folder-o"></i> <% } %><%- rpt.name %></td>
                     </tr>
                     <% } %>
                     </tbody>