Browse Source

feat: 材料调差审批弹窗改版

lanjianrong 4 years ago
parent
commit
a381f64788

+ 0 - 1
app/controller/advance_controller.js

@@ -87,7 +87,6 @@ module.exports = app => {
                     columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
                 });
                 data.accountList = accountList;
-                console.log('accountList', accountList);
                 data.accountGroup = accountGroup.map((item, idx) => {
                     const groupList = accountList.filter(item => item.account_group === idx);
                     return { groupName: item, groupList };

+ 9 - 6
app/controller/material_controller.js

@@ -176,13 +176,17 @@ module.exports = app => {
                 material: ctx.material,
             };
             if ((ctx.material.status === auditConst.status.uncheck || ctx.material.status === auditConst.status.checkNo) && ctx.session.sessionUser.accountId === ctx.material.user_id) {
-                data.accountGroup = accountGroup;
+                // data.accountGroup = accountGroup;
                 // 获取所有项目参与者
                 const accountList = await ctx.service.projectAccount.getAllDataByCondition({
                     where: { project_id: ctx.session.sessionProject.id, enable: 1 },
-                    columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group'],
+                    columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
                 });
                 data.accountList = accountList;
+                data.accountGroup = accountGroup.map((item, idx) => {
+                    const groupList = accountList.filter(item => item.account_group === idx);
+                    return { groupName: item, groupList };
+                });
             }
             data.tenderMenu.back.children[0].url = '/tender/' + ctx.tender.id + '/measure/material';
             return data;
@@ -202,17 +206,16 @@ module.exports = app => {
             const times = ctx.material.status === auditConst.status.checkNo ? ctx.material.times - 1 : ctx.material.times;
             ctx.material.user = await ctx.service.projectAccount.getAccountInfoById(ctx.material.user_id);
             ctx.material.auditHistory = [];
-            if (ctx.material.times > 1) {
-                for (let i = 1; i < ctx.material.times; i++) {
+            if (times >= 1) {
+                for (let i = 1; i <= times; i++) {
                     ctx.material.auditHistory.push(await ctx.service.materialAudit.getAuditors(ctx.material.id, i));
                 }
             }
             // 获取审批流程中左边列表
-            ctx.material.auditors2 = await ctx.service.materialAudit.getAuditGroupByList(ctx.material.id, times);
+            ctx.material.auditors2 = await ctx.service.materialAudit.getAuditorsWithOwner(ctx.material.id, times);
             if (ctx.material.status === auditConst.status.uncheck || ctx.material.status === auditConst.status.checkNo) {
                 ctx.material.auditorList = await ctx.service.materialAudit.getAuditors(ctx.material.id, ctx.material.times);
             }
-            console.log(ctx.material.auditHistory);
         }
 
         /**

+ 0 - 1
app/middleware/material_check.js

@@ -43,7 +43,6 @@ module.exports = options => {
             if (!material) {
                 throw '材料调差期数据错误';
             }
-
             // 读取原报、审核人数据
             material.auditors = yield this.service.materialAudit.getAuditors(material.id, material.times);
             // if (material.status > 1) {

+ 6 - 0
app/public/css/main.css

@@ -1137,3 +1137,9 @@ a.maintain-icon:hover .fa{
 .book-list dd:hover{
   background-color: #f2f2f2
 }
+.dd-content {
+  display: none;
+}
+.fold-card {
+  display: none;
+}

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

@@ -89,8 +89,7 @@ $(document).ready(function () {
 
     // 添加到审批流程中
     $('dl').on('click', 'dd', function () {
-        let id = $(this).data('id')
-        id = parseInt(id)
+        const id = parseInt($(this).data('id'))
         if (id !== 0) {
             postData(preUrl + '/audit/add', { auditorId: id }, (data) => {
                 // <p class="m-0 ml-2"><small class="text-muted">中交第一公路工程局有限公司国道311线满别公路施工一分部</small></p>

+ 96 - 33
app/public/js/material_audit.js

@@ -9,6 +9,8 @@
  */
 
 $(document).ready(function () {
+    let timer = null
+    let oldSearchVal = null
     // 获取审核相关url
     function getUrlPre () {
         const path = window.location.pathname.split('/');
@@ -16,29 +18,70 @@ $(document).ready(function () {
     }
 
     // 搜索审批人
-    $('#searchAccount').click(() => {
-        const data = {
-            keyword: $('#searchName').val(),
-        };
-        postData('/search/user', data, (data) => {
-            const resultDiv = $('#searchResult');
-            if (data) {
-                $('h5>span', resultDiv).text(data.name);
-                $('#addAuditor').attr('auditorId', data.id);
-                $('h6', resultDiv).text(data.role);
-                $('p', resultDiv).text(data.company);
-                resultDiv.show();
+    // $('#searchAccount').click(() => {
+    //     const data = {
+    //         keyword: $('#searchName').val(),
+    //     };
+    //     postData('/search/user', data, (data) => {
+    //         const resultDiv = $('#searchResult');
+    //         if (data) {
+    //             $('h5>span', resultDiv).text(data.name);
+    //             $('#addAuditor').attr('auditorId', data.id);
+    //             $('h6', resultDiv).text(data.role);
+    //             $('p', resultDiv).text(data.company);
+    //             resultDiv.show();
+    //         } else {
+    //             toast('未查询到该审核人', 'info');
+    //             resultDiv.hide();
+    //         }
+    //     }, () => {
+    //         $('#searchResult').hide();
+    //     });
+    // });
+    $('#gr-search').bind('input propertychange', function(e) {
+        oldSearchVal = e.target.value
+        timer && clearTimeout(timer)
+        timer = setTimeout(() => {
+            const newVal = $('#gr-search').val()
+            let html = ''
+            if (newVal && newVal === oldSearchVal) {
+                accountList.filter(item => item && cur_uid !== item.id && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
+                    html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
+                        <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
+                                class="ml-auto">${item.mobile || ''}</span></p>
+                        <span class="text-muted">${item.role || ''}</span>
+                    </dd>`
+                })
+                $('.book-list').empty()
+                $('.book-list').append(html)
             } else {
-                toast('未查询到该审核人', 'info');
-                resultDiv.hide();
+                if (!$('.acc-btn').length) {
+                    accountGroup.forEach((group, idx) => {
+                        if (!group) return
+                        html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
+                        </a> ${group.groupName}</dt>
+                        <div class="dd-content" data-toggleid="${idx}">`
+                        group.groupList.forEach(item => {
+                            if (item.id !== cur_uid) {
+                                html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
+                                    <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
+                                            class="ml-auto">${item.mobile || ''}</span></p>
+                                    <span class="text-muted">${item.role || ''}</span>
+                                </dd>`
+                            }
+                        });
+                        html += '</div>'
+                    })
+                    $('.book-list').empty()
+                    $('.book-list').append(html)
+                }
             }
-        }, () => {
-            $('#searchResult').hide();
-        });
-    });
+        }, 400);
+    })
     // 添加审批人
-    $('#addAuditor').click(() => {
-        postData(getUrlPre() + '/audit/add', { auditorId: $('#addAuditor').attr('auditorId') }, (data) => {
+    $('dl').on('click', 'dd', function() {
+        const id = parseInt($(this).data('id'))
+        postData(getUrlPre() + '/audit/add', { auditorId: id }, (data) => {
             const html = [];
             html.push('<li class="list-group-item" auditorId="'+ data.aid +'"><a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
             html.push('<span>');
@@ -51,18 +94,38 @@ $(document).ready(function () {
             $('#auditors').append(html.join(''));
         });
     });
-    // 审批人分组选择
-    $('#account_group').change(function () {
-        let account_html = '<option value="0">选择审批人</option>';
-        for (const account of accountList) {
-            if (parseInt($(this).val()) === 0 || parseInt($(this).val()) === account.account_group) {
-                const role = account.role !== '' ? '(' + account.role + ')' : '';
-                const company = account.company !== '' ? ' -' + account.company : '';
-                account_html += '<option value="' + account.id + '">' + account.name + role + company + '</option>';
-            }
+
+    // 添加审批流程按钮逻辑
+    $('.book-list').on('click', '.acc-btn', function () {
+        const idx = $(this).attr('data-groupid')
+        const type = $(this).attr('data-type')
+        if (type === 'hide') {
+            $(this).parent().parent().find(`div[data-toggleid="${idx}"]`).show(() => {
+                $(this).children().removeClass('fa-plus-square').addClass('fa-minus-square-o')
+                $(this).attr('data-type', 'show')
+
+            })
+        } else {
+            $(this).parent().parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
+                $(this).children().removeClass('fa-minus-square-o').addClass('fa-plus-square')
+                $(this).attr('data-type', 'hide')
+            })
         }
-        $('#account_list').html(account_html);
-    });
+        return false
+    })
+
+    // 审批人分组选择
+    // $('#account_group').change(function () {
+    //     let account_html = '<option value="0">选择审批人</option>';
+    //     for (const account of accountList) {
+    //         if (parseInt($(this).val()) === 0 || parseInt($(this).val()) === account.account_group) {
+    //             const role = account.role !== '' ? '(' + account.role + ')' : '';
+    //             const company = account.company !== '' ? ' -' + account.company : '';
+    //             account_html += '<option value="' + account.id + '">' + account.name + role + company + '</option>';
+    //         }
+    //     }
+    //     $('#account_list').html(account_html);
+    // });
     // 添加到审批流程中
     $('body').on('change', '#account_list', function () {
         let id = $(this).val();
@@ -142,14 +205,14 @@ $(document).ready(function () {
     });
     // 退回选择修改审批人流程
     $('#hideSp').click(function () {
-        $('#sp-list2').modal('hide');
+        $('#sp-list').modal('hide');
     });
     $('a[f-target]').click(function () {
         $($(this).attr('f-target')).modal('show');
     });
 
     // 多层modal关闭后的滚动bug修复
-    $('#sp-list2').on('hidden.bs.modal', function (e) {
+    $('#sp-list').on('hidden.bs.modal', function (e) {
         $(document.body).addClass('modal-open');
     });
 });

+ 25 - 1
app/service/material_audit.js

@@ -373,7 +373,7 @@ module.exports = app => {
                 auditors.forEach(audit => {
                     records.push({ pid, type: pushType.material, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent });
                 });
-                await transaction.insert('zh_notice', records);
+                await transaction.insert(this.ctx.service.noticePush.tableName, records);
                 // 同步期信息
                 await transaction.update(this.ctx.service.material.tableName, {
                     id: materialId, status: checkData.checkType,
@@ -651,6 +651,30 @@ module.exports = app => {
         }
 
         /**
+         * 获取审核人流程列表(包括原报)
+         * @param {Number} materialId 调差id
+         * @param {Number} times 审核次数
+         * @return {Promise<Array>} 查询结果集(包括原报)
+         */
+        async getAuditorsWithOwner(materialId, times = 1) {
+            const result = await this.getAuditGroupByList(materialId, times);
+            const sql =
+                'SELECT pa.`id` As aid, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As mid, 0 As `order`' +
+                '  FROM ' +
+                this.ctx.service.material.tableName +
+                ' As s' +
+                '  LEFT JOIN ' +
+                this.ctx.service.projectAccount.tableName +
+                ' As pa' +
+                '  ON s.user_id = pa.id' +
+                '  WHERE s.id = ?';
+            const sqlParam = [times, materialId, materialId];
+            const user = await this.db.queryOne(sql, sqlParam);
+            result.unshift(user);
+            return result;
+        }
+
+        /**
          * 复制上一期的审批人列表给最新一期
          *
          * @param transaction - 新增一期的事务

+ 1 - 8
app/view/advance/detail.ejs

@@ -393,11 +393,4 @@
     const accountGroup = JSON.parse('<%- JSON.stringify(accountGroup) %>');
 </script>
 <% } %>
-<style>
-    .fold-card {
-        display: none;
-    }
-    .dd-content {
-        display: none;
-    }
-</style>
+

+ 12 - 2
app/view/material/audit_btn.ejs

@@ -13,9 +13,19 @@
     <% } else if (ctx.material.status === auditConst.status.checked) { %>
         <a href="#sp-list" data-toggle="modal" data-target="#sp-list" class="btn btn-outline-secondary btn-sm btn-block">审批完成</a>
     <% } else if (ctx.material.status === auditConst.status.checkNo) { %>
-        <a href="#sp-list" data-toggle="modal" data-target="#sp-list" class="btn btn-outline-warning btn-sm btn-block text-muted">审批退回</a>
+        <a href="#sp-list"  data-type="hide" data-toggle="modal" data-target="#sp-list" class="btn btn-outline-warning btn-sm btn-block text-muted sp-list-btn">审批退回</a>
         <% if (ctx.session.sessionUser.accountId === ctx.material.user_id) { %>
-            <a id="sp-list2-btn" href="javascript: void(0);" data-toggle="modal" data-target="#sp-list2" class="btn btn-primary btn-sm btn-block">重新上报</a>
+            <a href="#sp-list" data-type="show" data-toggle="modal" data-target="#sp-list"  class="btn btn-primary btn-sm btn-block sp-list-btn">重新上报</a>
         <% } %>
     <% } %>
 </div>
+<script>
+    $('.sp-list-btn').click(function () {
+        const type = $(this).data('type')
+        if (type === 'hide') {
+            $('.sp-list-item').hide()
+        } else {
+            $('.sp-list-item').show()
+        }
+    });
+</script>

File diff suppressed because it is too large
+ 580 - 752
app/view/material/audit_modal.ejs