Procházet zdrojové kódy

同步角色功能

laiguoran před 2 roky
rodič
revize
d9500ff73d

+ 13 - 4
app/controller/payment_controller.js

@@ -376,7 +376,6 @@ module.exports = app => {
                         return { groupName: item, groupList };
                     });
                 }
-                renderData.rptAuditList = await ctx.service.paymentRptAudit.getListByDetail(ctx.detail.id);
                 await this.layout('payment/detail.ejs', renderData, 'payment/detail_modal.ejs');
             } catch (err) {
                 console.log(err);
@@ -399,7 +398,7 @@ module.exports = app => {
                 if (ctx.detail.uid !== ctx.session.sessionUser.accountId && data.type !== 'update_sign') {
                     throw '您无权操作';
                 }
-                if (data.type !== 'update_sign' && (ctx.detail.status === auditConst.status.checking || ctx.detail.status === auditConst.status.checked)) {
+                if (data.type !== 'update_sign' && ctx.detail.status !== auditConst.status.uncheck && ctx.detail.status !== auditConst.status.checkNo) {
                     throw '您无权操作';
                 }
                 const responseData = {
@@ -451,6 +450,16 @@ module.exports = app => {
                         }
                         responseData.data = await ctx.service.paymentDetailAudit.getAuditors(ctx.detail.id, ctx.detail.times);
                         break;
+                    case 'follow_rpt_audit':
+                        if (ctx.trInfo.shenpi_status === shenpiConst.sp_status.gdspl) {
+                            throw '当前表单已设置为固定审批流,无法同步';
+                        }
+                        const result3 = await ctx.service.paymentDetailAudit.followAuditByRptAudit(ctx.detail);
+                        if (!result3) {
+                            throw '同步表单角色失败';
+                        }
+                        responseData.data = await ctx.service.paymentDetailAudit.getAuditorsWithOwner(ctx.detail.id, ctx.detail.times);
+                        break;
                     default: throw '参数有误';
                 }
                 ctx.body = responseData;
@@ -529,7 +538,7 @@ module.exports = app => {
                 await this.getNewRptProjectList(ctx, newRptList, rptProjectList, 1);
                 const tenderRptList = await ctx.service.paymentTenderRpt.getProcessList(ctx.tender.id);
                 if (tenderRptList === -1) {
-                    throw '未配置审批模块,请联系管理员处理';
+                    throw '未配置表单设置,请联系管理员处理';
                 }
                 return await ctx.service.paymentTenderRpt.checkAndUpdateList(tenderRptList, rptProjectList, formProcess);
             }
@@ -636,7 +645,7 @@ module.exports = app => {
             try {
                 const tenderRptList = await this._returnRptProjectList(ctx);
                 if (tenderRptList === -1) {
-                    throw '未配置审批模块,请联系管理员处理';
+                    throw '未配置表单设置,请联系管理员处理';
                 }
                 if (tenderRptList.length === 0) {
                     throw '未配置表单设置,请联系管理员处理';

+ 2 - 2
app/middleware/payment_detail_check.js

@@ -37,11 +37,11 @@ module.exports = options => {
             // 读取原报、审核人数据
             detail.auditors = yield this.service.paymentDetailAudit.getAuditors(detail.id, detail.times);
             detail.curAuditor = yield this.service.paymentDetailAudit.getCurAuditor(detail.id, detail.times);
-            const rptAudits = yield this.service.paymentRptAudit.getAllDataByCondition({ where: { td_id: detail.id } });
+            detail.rptAudits = yield this.service.paymentRptAudit.getListByDetail(detail.id);
 
             const accountId = this.session.sessionUser.accountId,
                 auditorIds = _.map(detail.auditors, 'aid'),
-                rptAuditIds = _.map(rptAudits, 'uid');
+                rptAuditIds = _.map(detail.rptAudits, 'uid');
             if (accountId === detail.uid) { // 原报
                 detail.curTimes = detail.times;
                 if (detail.status === status.uncheck || detail.status === status.checkNo) {

+ 48 - 56
app/public/js/payment_detail_audit.js

@@ -69,68 +69,52 @@ $(document).ready(function () {
             })
         }
         return false
-    })
+    });
+
+    function remakeShenpiHtml(datas) {
+        const html = [];
+        // 如果是重新上报,添加到重新上报列表中
+        const auditorshtml = [];
+        for (const [index,data] of datas.entries()) {
+            if (index !== 0) {
+                html.push('<li class="list-group-item" auditorId="'+ data.aid +'">');
+                if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== datas.length)) {
+                    html.push('<a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
+                }
+                html.push('<span>');
+                html.push(data.order + ' ');
+                html.push(data.name + ' ');
+                html.push('</span>');
+                if (_.findIndex(rptAuditList, { uid: data.aid }) !== -1) {
+                    html.push('&nbsp;(' + _.find(rptAuditList, { uid: data.aid }).signature_name + ')');
+                }
+                html.push('<small class="text-muted">');
+                html.push(data.role);
+                html.push('</small></li>');
+            }
+            // 添加新审批人流程修改
+            auditorshtml.push('<li class="list-group-item" data-auditorid="' + data.aid + '">');
+            auditorshtml.push('<i class="fa ' + (index+1 === datas.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i> ');
+            auditorshtml.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
+            if (index === 0) {
+                auditorshtml.push('<span class="pull-right">原报</span>');
+            } else if (index+1 === datas.length) {
+                auditorshtml.push('<span class="pull-right">终审</span>');
+            } else {
+                auditorshtml.push('<span class="pull-right">'+ transFormToChinese(index) +'审</span>');
+            }
+            auditorshtml.push('</li>');
+        }
+        $('#auditors').html(html.join(''));
+        $('#auditors-list').html(auditorshtml.join(''));
+    }
 
     // 添加到审批流程中
     $('dl').on('click', 'dd', function () {
         const id = parseInt($(this).data('id'));
         if (id) {
             postData('/payment/' + tenderId + '/detail/' + detailId + '/save', { type: 'add_audit', auditorId: id }, (datas) => {
-                const html = [];
-                // 如果是重新上报,添加到重新上报列表中
-                const auditorshtml = [];
-                for (const [index,data] of datas.entries()) {
-                    if (index !== 0) {
-                        html.push('<li class="list-group-item" auditorId="'+ data.aid +'">');
-                        if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== datas.length)) {
-                            html.push('<a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
-                        }
-                        html.push('<span>');
-                        html.push(data.order + ' ');
-                        html.push(data.name + ' ');
-                        html.push('</span>');
-                        if (_.findIndex(rptAuditList, { uid: data.aid }) !== -1) {
-                            html.push('&nbsp;(' + _.find(rptAuditList, { uid: data.aid }).signature_name + ')');
-                        }
-                        html.push('<small class="text-muted">');
-                        html.push(data.role);
-                        html.push('</small></li>');
-                    }
-                    // 添加新审批人流程修改
-                    auditorshtml.push('<li class="list-group-item" data-auditorid="' + data.aid + '">');
-                    auditorshtml.push('<i class="fa ' + (index+1 === datas.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i> ');
-                    auditorshtml.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
-                    if (index === 0) {
-                        auditorshtml.push('<span class="pull-right">原报</span>');
-                    } else if (index+1 === datas.length) {
-                        auditorshtml.push('<span class="pull-right">终审</span>');
-                    } else {
-                        auditorshtml.push('<span class="pull-right">'+ transFormToChinese(index) +'审</span>');
-                    }
-                    auditorshtml.push('</li>');
-                }
-                $('#auditors').html(html.join(''));
-
-
-                // 重新上报时。令其它的审批人流程图标转换
-                // $('#auditors-list li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
-                // for (let i = 0; i < $('#auditors-list li').length; i++) {
-                //     $('#auditors-list li').eq(i).find('.pull-right').text(transFormToChinese(i+1) + '审');
-                //     $('#auditors-list2 li').eq(i).find('.pull-right').text(transFormToChinese(i+1) + '审');
-                // }
-
-                $('#auditors-list').html(auditorshtml.join(''));
-
-                // const auditorshtml2 = [];
-                // // 重新上报时。令其它的审批人流程图标转换
-                // $('#auditors-list2 li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
-                // // 添加新审批人
-                // auditorshtml2.push('<li class="list-group-item" data-auditid="' + data.aid + '">');
-                // auditorshtml2.push('<h5 class="card-title"><i class="fa fa-stop-circle"></i> ');
-                // auditorshtml2.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
-                // auditorshtml2.push('<span class="pull-right">终审</span>');
-                // auditorshtml2.push('</h5></li>');
-                // $('#auditors-list2').append(auditorshtml2.join(''));
+                remakeShenpiHtml(datas);
             });
         }
     });
@@ -207,6 +191,14 @@ $(document).ready(function () {
             }
         });
     });
+
+    // 同步报表角色
+    $('#follow_rpt_audit_btn').click(function () {
+        postData('/payment/' + tenderId + '/detail/' + detailId + '/save', { type: 'follow_rpt_audit' }, (datas) => {
+            toastr.success('同步成功');
+            remakeShenpiHtml(datas);
+        });
+    });
 });
 // 检查上报情况
 function checkAuditorFrom () {

+ 44 - 0
app/service/payment_detail_audit.js

@@ -529,6 +529,50 @@ module.exports = app => {
                     throw '无效审批操作';
             }
         }
+
+        async followAuditByRptAudit(detail) {
+            const transaction = await this.db.beginTransaction();
+            try {
+                const newAuditIds = this._.map(detail.rptAudits, 'uid');
+                // 去除上报人
+                if (this._.includes(newAuditIds, detail.uid)) {
+                    this._.pull(newAuditIds, detail.uid);
+                }
+                // 如果存在固定终审,判断它是否在报表人员里,存在则把该id移到最后,不存在则插入newAuditIds最后;
+                if (this.ctx.trInfo.sp_status === shenpiConst.sp_status.gdzs) {
+                    const gdzsInfo = await this.ctx.service.paymentShenpiAudit.getAudit(detail.tender_id, detail.tr_id, shenpiConst.sp_status.gdzs);
+                    if (gdzsInfo && gdzsInfo.audit_id !== newAuditIds[newAuditIds.length - 1]) {
+                        if (this._.includes(newAuditIds, gdzsInfo.audit_id)) {
+                            this._.pull(newAuditIds, gdzsInfo.audit_id);
+                        }
+                        newAuditIds.push(gdzsInfo.audit_id);
+                    }
+                }
+                // 删除原审批流
+                await transaction.delete(this.tableName, { td_id: detail.id, times: detail.times });
+                // 添加新审批流
+                const insertDatas = [];
+                let order = 1;
+                for (const id of newAuditIds) {
+                    insertDatas.push({
+                        tender_id: detail.tender_id,
+                        tr_id: detail.tr_id,
+                        td_id: detail.id,
+                        aid: id,
+                        order,
+                        times: detail.times,
+                        status: auditConst.status.uncheck,
+                    });
+                    order = order + 1;
+                }
+                if (insertDatas.length > 0) await transaction.insert(this.tableName, insertDatas);
+                await transaction.commit();
+                return true;
+            } catch (error) {
+                await transaction.rollback();
+                throw error;
+            }
+        }
     }
 
     return PaymentDetailAudit;

+ 5 - 4
app/view/payment/audit_modal.ejs

@@ -17,7 +17,7 @@
                                     报表表单角色
                                 </div>
                                 <ul class="list-group list-group-flush">
-                                    <% for (const [index, ra] of rptAuditList.entries()) { %>
+                                    <% for (const [index, ra] of ctx.detail.rptAudits.entries()) { %>
                                         <li class="list-group-item">
                                             <div class="row">
                                                 <span class="col-2"><%- index+1 %></span>
@@ -32,6 +32,7 @@
                         <div class="col-7" style="overflow: auto">
                             <div class="dropdown text-right">
                                 <% if (trInfo.sp_status !== shenpiConst.sp_status.gdspl && ctx.session.sessionUser.accountId === ctx.detail.uid) { %>
+                                    <button class="btn btn-sm btn-primary mr-2" id="follow_rpt_audit_btn">同步表单角色</button>
                                     <button class="btn btn-outline-primary btn-sm dropdown-toggle" type="button"
                                             id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true"
                                             aria-expanded="false">
@@ -48,7 +49,7 @@
                                                     <% group.groupList.forEach(item => { %>
                                                         <% if (item.id !== ctx.session.sessionUser.accountId) { %>
                                                             <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> <% if (ctx.helper._.findIndex(rptAuditList, { uid: item.id }) !== -1) { %>&nbsp;(<%- ctx.helper._.find(rptAuditList, { uid: item.id }).signature_name %>)<% } %><span
+                                                                <p class="mb-0 d-flex"><span class="text-primary"><%- item.name %></span> <% if (ctx.helper._.findIndex(ctx.detail.rptAudits, { uid: item.id }) !== -1) { %>&nbsp;(<%- ctx.helper._.find(ctx.detail.rptAudits, { uid: item.id }).signature_name %>)<% } %><span
                                                                             class="ml-auto"><%- item.mobile %></span></p>
                                                                 <span class="text-muted"><%- item.role %></span>
                                                             </dd>
@@ -73,7 +74,7 @@
                                                     <a href="javascript: void(0)" class="text-danger pull-right">移除</a>
                                                 <% } %>
                                                 <span><%- ctx.detail.auditorList[i].order %> <%- ctx.detail.auditorList[i].name %></span>
-                                                <% if (ctx.helper._.findIndex(rptAuditList, { uid: ctx.detail.auditorList[i].aid }) !== -1) { %>&nbsp;(<%- ctx.helper._.find(rptAuditList, { uid: ctx.detail.auditorList[i].aid }).signature_name %>)<% } %>
+                                                <% if (ctx.helper._.findIndex(ctx.detail.rptAudits, { uid: ctx.detail.auditorList[i].aid }) !== -1) { %>&nbsp;(<%- ctx.helper._.find(ctx.detail.rptAudits, { uid: ctx.detail.auditorList[i].aid }).signature_name %>)<% } %>
                                                 <small class="text-muted"><%- ctx.detail.auditorList[i].role %></small>
                                             </li>
                                         <% } %>
@@ -776,7 +777,7 @@
         const accountList = JSON.parse(unescape('<%- escape(JSON.stringify(accountList)) %>'));
         const shenpi_status = <%- trInfo.sp_status %>;
         const shenpiConst =  JSON.parse('<%- JSON.stringify(shenpiConst) %>');
-        const rptAuditList = JSON.parse(unescape('<%- escape(JSON.stringify(rptAuditList)) %>'));
+        const rptAuditList = JSON.parse(unescape('<%- escape(JSON.stringify(ctx.detail.rptAudits)) %>'));
     </script>
 <% } %>
 <script>const cur_uid = parseInt('<%- ctx.session.sessionUser.accountId %>');</script>

+ 1 - 1
app/view/payment/detail_modal.ejs

@@ -119,7 +119,7 @@
                     </tr>
                     </thead>
                     <tbody>
-                    <% for (const [index, ra] of rptAuditList.entries()) { %>
+                    <% for (const [index, ra] of ctx.detail.rptAudits.entries()) { %>
                     <tr class="text-center" <% if (rptAudit && rptAudit.id === ra.id) { %>id="rpt_audit_sign"<% } %>>
                         <td><%- index+1 %></td>
                         <td><%- ra.signature_name %></td>