Selaa lähdekoodia

支付审批列表页加载优化及分页

ellisran 1 viikko sitten
vanhempi
commit
bc32ef43a9

+ 22 - 15
app/controller/financial_controller.js

@@ -656,18 +656,22 @@ module.exports = app => {
             // 获取所有项目参与者
             const accountList = await ctx.service.projectAccount.getAllSubProjectAccount(ctx.subProject, ['id', 'account', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile']);
             const payTenders = await ctx.service.financialPayTender.getAllDataByCondition({ where: { spid: ctx.subProject.id } });
-            for (const t of tenders) {
-                const info = await ctx.service.tenderInfo.getDataByCondition({ tid: t.id });
-                t.pay_account = info && info.pay_account ? JSON.parse(info.pay_account).project : '';
-                const pt = ctx.helper._.find(payTenders, { tid: t.id });
-                t.pt = pt ? pt : { id: 0, tid: t.id, name: '', bank: '', bank_account: '', contact: '', phone: '' };
-                if (ctx.session.sessionUser.is_admin || ctx.helper._.includes(fptReportTids, t.id)) {
-                    t.dealCode = info && info.deal_info ? JSON.parse(info.deal_info).dealCode : '';
-                    const lastPay = await ctx.service.financialPay.getAllDataByCondition({ where: { spid: ctx.subProject.id, tid: t.id }, columns: ['code'], orders: [['id', 'desc']], limit: 1 });
-                    t.startNum = 1;
-                    if (lastPay.length > 0) {
-                        const startArray = lastPay[0].code.split('-');
-                        t.startNum = parseInt(startArray[startArray.length - 1]) + 1;
+            if (tenders.length > 0) {
+                const allLastPay = await ctx.service.financialPay.getAllDataByCondition({ where: { spid: ctx.subProject.id, tid: ctx.helper._.map(tenders, 'id') }, columns: ['id', 'code'], orders: [['id', 'desc']] });
+                const tenderInfos = await ctx.service.tenderInfo.getAllDataByCondition({ where: { tid: ctx.helper._.map(tenders, 'id') }, columns: ['tid', 'pay_account', 'deal_info'] });
+                for (const t of tenders) {
+                    const info = ctx.helper._.find(tenderInfos, { tid: t.id });
+                    t.pay_account = info && info.pay_account ? JSON.parse(info.pay_account).project : '';
+                    const pt = ctx.helper._.find(payTenders, { tid: t.id });
+                    t.pt = pt ? pt : { id: 0, tid: t.id, name: '', bank: '', bank_account: '', contact: '', phone: '' };
+                    if (ctx.session.sessionUser.is_admin || ctx.helper._.includes(fptReportTids, t.id)) {
+                        t.dealCode = info && info.deal_info ? JSON.parse(info.deal_info).dealCode : '';
+                        const lastPay = ctx.helper._.filter(allLastPay, { tid: t.id });
+                        t.startNum = 1;
+                        if (lastPay.length > 0) {
+                            const startArray = lastPay[0].code.split('-');
+                            t.startNum = parseInt(startArray[startArray.length - 1]) + 1;
+                        }
                     }
                 }
             }
@@ -689,10 +693,13 @@ module.exports = app => {
                     pay.entities = await ctx.service.financialPayContract.getEntities(pay.id);
                 }
             }
-            if (ctx.session.sessionUser.is_admin) {
+            if (ctx.session.sessionUser.is_admin && tenders.length > 0) {
+                const allPermissionList = await ctx.service.financialPayTenderAudit.getAllList(ctx.subProject.id, ctx.helper._.map(tenders, 'id'), accountList);
+                const allAuditGroupList = await ctx.service.shenpiAudit.getAllAuditGroupList(ctx.helper._.map(tenders, 'id'), shenpiConst.sp_other_type.financial, shenpiConst.sp_status.gdspl);
                 for (const t of tenders) {
-                    t.permissionList = await ctx.service.financialPayTenderAudit.getList(ctx.subProject.id, t.id, accountList);
-                    t.auditGroupList = await ctx.service.shenpiAudit.getAuditGroupList(t.id, shenpiConst.sp_other_type.financial, shenpiConst.sp_status.gdspl);
+                    t.permissionList = ctx.helper._.filter(allPermissionList, { tid: t.id }) || [];
+                    // t.auditGroupList = await ctx.service.shenpiAudit.getAuditGroupList(t.id, shenpiConst.sp_other_type.financial, shenpiConst.sp_status.gdspl);
+                    t.auditGroupList = ctx.helper._.find(allAuditGroupList, { tid: t.id }) ? ctx.helper._.find(allAuditGroupList, { tid: t.id }).audits : [];
                 }
             }
             const renderData = {

+ 6 - 0
app/public/js/global.js

@@ -122,6 +122,12 @@ $(function(){
         }
     });
 
+    $('.account-page-size').each(function () {
+        if (getLocalCache('account-pageSize')) {
+            $(this).attr('href', $(this).attr('href') + '?pageSize=' + getLocalCache('account-pageSize'));
+        }
+    });
+
     $('.change_sort_link').each(function () {
         const tender_id = $(this).attr('href').split('/')[2];
         const filterString = setChangeFilterData('change-'+ tender_id +'-list-order');

+ 11 - 3
app/service/financial_pay.js

@@ -38,7 +38,7 @@ module.exports = app => {
          * @param {int} hadlimit - 分页
          * @return {object} list - 列表
          */
-        async getListByStatus(spid, status = 0, tid = null, used = null, pageLimit = 0) {
+        async getListByStatus(spid, status = 0, tid = null, used = null, hadlimit = 0, sortBy = '', orderBy = '') {
             let addSql = '';
             if (tid !== null) {
                 if (tid.length === 0) {
@@ -85,8 +85,16 @@ module.exports = app => {
                 default:
                     break;
             }
-            sql += ' ORDER BY a.create_time DESC';
-            if (pageLimit) {
+            if (sortBy && orderBy) {
+                if (sortBy === 'code') {
+                    sql += ' ORDER BY CHAR_LENGTH(a.code) ' + orderBy + ',convert(a.code using gbk) ' + orderBy;
+                } else {
+                    sql += ' ORDER BY a.create_time ' + orderBy;
+                }
+            } else {
+                sql += ' ORDER BY a.create_time DESC';
+            }
+            if (hadlimit) {
                 const limit = this.ctx.pageSize ? this.ctx.pageSize : this.app.config.pageSize;
                 const offset = limit * (this.ctx.page - 1);
                 const limitString = offset >= 0 ? offset + ',' + limit : limit;

+ 26 - 0
app/service/financial_pay_tender_audit.js

@@ -24,6 +24,32 @@ module.exports = app => {
             this.dataId = 'id';
         }
 
+        async getAllList(spid, tids, accountList = null) {
+            if (accountList === null) {
+                accountList = await this.ctx.service.projectAccount.getAllDataByCondition({
+                    where: { project_id: this.ctx.session.sessionProject.id, enable: 1 },
+                    columns: ['id', 'account', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
+                });
+            }
+            const list = await this.db.select(this.tableName, { where: { spid, tid: tids }, orders: [['id', 'asc']] });
+            const removeList = [];
+            for (const l of list) {
+                const accountInfo = this._.find(accountList, { id: l.uid });
+                if (!accountInfo) {
+                    removeList.push(l.id);
+                    continue;
+                }
+                l.name = accountInfo.name;
+                l.company = accountInfo.company;
+            }
+            if (removeList.length > 0) {
+                for (const r of removeList) {
+                    list.splice(this._.findIndex(list, { id: r }), 1);
+                }
+            }
+            return list;
+        }
+
         async getList(spid, tid, accountList = null) {
             if (accountList === null) {
                 accountList = await this.ctx.service.projectAccount.getAllDataByCondition({

+ 25 - 0
app/service/shenpi_audit.js

@@ -68,6 +68,31 @@ module.exports = app => {
             return await this.db.query(sql, sqlParam);
         }
 
+        async getAllAuditGroupList(tids, type, status, group_id = 0) {
+            const sql = 'SELECT sp.tid, sp.audit_id, sp.audit_type, sp.audit_order, sp.sp_group, pa.name FROM ?? AS sp LEFT JOIN ?? AS pa ON sp.audit_id = pa.id' +
+                ' WHERE sp.tid in (' + this.ctx.helper.getInArrStrSqlFilter(tids) + ') AND sp.sp_type = ? AND sp.sp_status = ? AND sp.sp_group = ? ORDER BY sp.audit_order ASC, sp.id ASC';
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, type, status, group_id];
+            const audits = await this.db.query(sql, sqlParam);
+            const result = [];
+            for (const t of tids) {
+                const oneResult = [];
+                const tidAudits = audits.filter(a => a.tid === t);
+                for (const a of tidAudits) {
+                    if (a.audit_order > 0) {
+                        if (oneResult[a.audit_order - 1]) {
+                            oneResult[a.audit_order - 1].push(a);
+                        } else {
+                            oneResult.push([a]);
+                        }
+                    } else {
+                        oneResult.push([a]);
+                    }
+                }
+                result.push({ tid: t, audits: oneResult });
+            }
+            return result;
+        }
+
         async getAuditGroupList(tid, type, status, group_id = 0) {
             const sql = 'SELECT sp.audit_id, sp.audit_type, sp.audit_order, sp.sp_group, pa.name FROM ?? AS sp LEFT JOIN ?? AS pa ON sp.audit_id = pa.id' +
                 ' WHERE sp.tid = ? AND sp.sp_type = ? AND sp.sp_status = ? AND sp.sp_group = ? ORDER BY sp.audit_order ASC, sp.id ASC';

+ 2 - 2
app/view/financial/sub_menu_list.ejs

@@ -2,7 +2,7 @@
 <div class="nav-box">
     <ul class="nav-list list-unstyled">
         <li class="<% if (ctx.url.indexOf('/transfer') !== -1) { %>active<% } %>">
-            <a href="/sp/<%- ctx.subProject.id %>/financial/transfer"><span class="ml-3">资金划拨</span></a>
+            <a href="/sp/<%- ctx.subProject.id %>/financial/transfer" class="account-page-size"><span class="ml-3">资金划拨</span></a>
         </li>
     </ul>
 </div>
@@ -11,7 +11,7 @@
 <div class="nav-box">
     <ul class="nav-list list-unstyled">
         <li class="<% if (ctx.url.indexOf('/pay') !== -1) { %>active<% } %>">
-            <a href="/sp/<%- ctx.subProject.id %>/financial/pay"><span class="ml-3">资金支付</span></a>
+            <a href="/sp/<%- ctx.subProject.id %>/financial/pay" class="account-page-size"><span class="ml-3">资金支付</span></a>
         </li>
     </ul>
 </div>