瀏覽代碼

feat: 添加审批人功能增加搜索功能

lanjianrong 4 年之前
父節點
當前提交
642650cfc0

+ 1 - 1
app/controller/advance_controller.js

@@ -86,7 +86,7 @@ module.exports = app => {
                     where: { project_id: ctx.session.sessionProject.id, enable: 1 },
                     columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group'],
                 });
-                // data.accountList = accountList;
+                data.accountList = accountList;
                 data.accountGroup = accountGroup.map((item, idx) => {
                     const groupList = accountList.filter(item => item.account_group === idx);
                     return { groupName: item, groupList };

+ 1 - 1
app/middleware/advance_check.js

@@ -43,7 +43,7 @@ module.exports = () => {
 
             advance.user = yield this.service.projectAccount.getAccountInfoById(advance.uid);
             // 读取审核人列表数据
-            advance.auditors = yield this.service.advanceAudit.getAuditors(advance.id, advance.times === 1 ? advance.times : advance.times - 1);
+            advance.auditors = yield this.service.advanceAudit.getAuditors(advance.id, advance.times);
             advance.curAuditor = yield this.service.advanceAudit.getCurAuditor(advance.id, advance.times);
 
             // 获取最新的期

+ 44 - 13
app/public/js/advance_audit.js

@@ -12,6 +12,7 @@ $(document).ready(function () {
     autoFlashHeight()
     let oldVal = null
     let timer = null
+    let oldSearchVal = null
     handleFileList(fileList)
     // 控制上报弹窗的文案
     function checkModal(isHide) {
@@ -25,21 +26,50 @@ $(document).ready(function () {
             $('#tm-submit').show()
         }
     }
-    // 审批人分组选择
-    // $('#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) && account.id !== parseInt(userID)) {
-    //             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)
-    // });
+
+    $('#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.name.indexOf(newVal) !== -1 || item.mobile === newVal).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 {
+                if (!$('.acc-btn').length) {
+                    console.log('accountGroup', accountGroup)
+                    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 => {
+                            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)
+                }
+            }
+        }, 400);
+    })
 
     // 添加审批流程按钮逻辑
-    $('.acc-btn').click(function () {
+    $('.book-list').on('click', '.acc-btn', function () {
         const idx = $(this).attr('data-groupid')
         const type = $(this).attr('data-type')
         if (type === 'hide') {
@@ -56,6 +86,7 @@ $(document).ready(function () {
         }
         return false
     })
+
     // 添加到审批流程中
     $('dl').on('click', 'dd', function () {
         let id = $(this).data('id')

+ 7 - 1
app/service/advance.js

@@ -31,7 +31,6 @@ module.exports = app => {
             }
             this.sqlBuilder.orderBy = [['order', 'desc']];
             const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
-            console.log(sql);
             const advance = await this.db.query(sql, sqlParam);
             for (const item of advance) {
                 item.curAuditor = await this.ctx.service.advanceAudit.getAuditorByStatus(item.id, item.status, item.times);
@@ -92,6 +91,13 @@ module.exports = app => {
                 latestOrder.order = latestOrder.order + 1;
             }
             const record = await this.db.insert(this.tableName, { type, uid, tid, status: auditConst.status.uncheck, order: latestOrder.order, prev_amount: latestOrder.prev_total_amount, prev_total_amount: latestOrder.prev_total_amount });
+            const auditors = await ctx.service.advanceAudit.getAuditGroupByList(latestOrder.id, latestOrder.times);
+            auditors.forEach(async (auditor, idx) => {
+                const { audit_id } = auditor;
+                await ctx.service.advanceAudit.db.insert(ctx.service.advanceAudit.tableName, {
+                    tid: latestOrder.tid, audit_id, type: latestOrder.type, vid: record.insertId, times: 1, order: idx + 1, status: 1, create_time: new Date(),
+                });
+            });
             return await this.getDataById(record.insertId);
         }
 

+ 3 - 2
app/view/advance/detail.ejs

@@ -132,7 +132,7 @@
                                         <div class="dropdown-menu" aria-labelledby="dropdownMenuButton"
                                             style="width:220px">
                                             <div class="mb-2 p-2"><input class="form-control form-control-sm"
-                                                    placeholder="姓名/手机 检索"></div>
+                                                    placeholder="姓名/手机 检索" id="gr-search"></div>
                                             <dl class="list-unstyled book-list">
                                                 <% accountGroup.forEach((group, idx) => { %>
                                                     <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>
@@ -387,7 +387,8 @@
 </script>
 <% if(isEdited && ctx.session.sessionUser.accountId === ctx.advance.uid) { %>
 <script>
-
+    const accountList = JSON.parse('<%- JSON.stringify(accountList) %>');
+    const accountGroup = JSON.parse('<%- JSON.stringify(accountGroup) %>');
 </script>
 <% } %>
 <style>