Selaa lähdekoodia

feat: 添加审批组切换功能,优化审批流程

caipin 2 viikkoa sitten
vanhempi
commit
1c908dc21f

+ 16 - 0
app/controller/stage_controller.js

@@ -189,6 +189,7 @@ module.exports = app => {
                 renderData.categoryData = await ctx.service.category.getAllCategory(ctx.subProject);
                 renderData.settleStatus = ctx.service.settle.settleStatus;
                 renderData.deleteFilePermission = PermissionCheck.delFile(this.ctx.session.sessionUser.permission);
+                renderData.spGroupList = await ctx.service.shenpiGroup.getGroupListByStage(ctx.tender.id, shenpiConst.sp_type.stage);
                 await this.layout('stage/index.ejs', renderData, 'stage/modal.ejs');
             } catch (err) {
                 this.log(err);
@@ -2515,6 +2516,21 @@ module.exports = app => {
             }
         }
 
+        async changeSpGroup(ctx) {
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                const result = await ctx.service.stageAudit.stageSpGroup(ctx.stage, data.sp_group);
+                if (!result) {
+                    throw '切换审批组失败';
+                }
+                
+                const auditors = await ctx.service.stageAudit.getUserGroup(ctx.stage.id, ctx.stage.times);
+                ctx.body = { err: 0, msg: '', data: auditors };
+            } catch (err) {
+                ctx.body = { err: 1, msg: err.toString(), data: null };
+            }
+        }
+
     }
 
     return StageController;

+ 11 - 4
app/middleware/stage_check.js

@@ -46,7 +46,7 @@ module.exports = options => {
             if (!stage) {
                 throw '期数据错误';
             }
-
+            
             // 读取原报、审核人数据
             yield this.service.stage.loadStageUser(stage);
             yield this.service.stage.loadPreCheckedStage(stage);
@@ -69,7 +69,7 @@ module.exports = options => {
                 pp.rela_stage = pp.rela_stage ? JSON.parse(pp.rela_stage) : [];
                 return pp.rela_stage.find(x => { return x.stage_id === stage.id; });
             });
-
+            
             // 权限相关
             // todo 校验权限 (标段参与人、分享、游客)
             const accountId = this.session.sessionUser.accountId;
@@ -153,7 +153,14 @@ module.exports = options => {
                 // 进一步比较审批流是否与审批流程设置的相同,不同则替换为固定审批流或固定的终审
                 const auditList = yield this.service.stageAudit.getAllDataByCondition({ where: { sid: stage.id, times: stage.times }, orders: [['order', 'asc']] });
                 if (shenpi_status === shenpiConst.sp_status.gdspl) {
-                    const shenpiList = yield this.service.shenpiAudit.getAllDataByCondition({ where: { tid: stage.tid, sp_type: shenpiConst.sp_type.stage, sp_status: shenpi_status } });
+                    // 判断并获取审批组
+                    const group = yield this.service.shenpiGroup.getSelectGroupByStageType(this.tender.id, shenpiConst.sp_type.stage, stage.sp_group);
+                    if ((group && stage.sp_group !== group.id) || (!group && stage.sp_group !== 0)) {
+                        stage.sp_group = group ? group.id : 0;
+                        yield this.service.stage.defaultUpdate({ sp_group: stage.sp_group }, { where: { id: stage.id } });
+                    }
+                    const condition = { tid: this.tender.id, sp_type: shenpiConst.sp_type.stage, sp_status: shenpi_status, sp_group: stage.sp_group };
+                    const shenpiList = yield this.service.shenpiAudit.getAllDataByCondition({ where: condition, orders: [['audit_order', 'asc']] });
                     // 判断2个id数组是否相同,不同则删除原审批流,切换成固定的审批流
                     let sameAudit = auditList.length === shenpiList.length;
                     if (sameAudit) {
@@ -182,7 +189,7 @@ module.exports = options => {
                     }
                 }
             }
-
+        
             yield next;
         } catch (err) {
             this.helper.log(err);

+ 3 - 2
app/public/js/shenpi.js

@@ -345,7 +345,7 @@ $(document).ready(function () {
                 for(const [i, auditGroup] of flow.auditGroupList.entries()) {
                     addhtml += this.getAuditGroupHtml(this_code, auditGroup, i + 1);
                 }
-                const addGroupHtml = this_code === 'change' && (!flow.groupList || (flow.groupList && flow.groupList.length === 0)) ?
+                const addGroupHtml = (this_code === 'change' || this_code === 'stage') && (!flow.groupList || (flow.groupList && flow.groupList.length === 0)) ?
                     `<span class="pl-3"><a href="javascript:void(0);" class="show-spzsave" data-code="${this_code}"><i class="fa fa-save"></i> 存为审批组</a></span>\n` : '';
                 addhtml += '<li>\n' +
                     '                                            <span class="pl-3"><a href="javascript:void(0);" class="add-audit" ><i class="fa fa-plus"></i> 添加流程</a></span>\n' + addGroupHtml +
@@ -494,6 +494,7 @@ $(document).ready(function () {
     // 选中审批人
     $('body').on('click', 'div[id$="_dropdownMenu"] dl dd', function () {
         const id = parseInt($(this).data('id'));
+        console.log("选中审批人ID:"+id);
         if (!id) return;
 
         let this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
@@ -533,7 +534,7 @@ $(document).ready(function () {
                     const auditGroup = auditUtils.addAudit(this_code, { audit_id: data.audit_id, name: user.name, audit_type: data.audit_type, audit_order: data.audit_order }, prop.audit_order - 1);
                     if (_self.parents('ul').find('.add-audit').length === 0) {
                         const flow = sp_lc.find(x => { return x.code === this_code; });
-                        const addGroupHtml = this_code === 'change' && (!flow.groupList || (flow.groupList && flow.groupList.length === 0)) ?
+                        const addGroupHtml = (this_code === 'change'||this_code ==='stage') && (!flow.groupList || (flow.groupList && flow.groupList.length === 0)) ?
                             `<span class="pl-3"><a href="javascript:void(0);" class="show-spzsave" data-code="${this_code}"><i class="fa fa-save"></i> 存为审批组</a></span>\n` : '';
                         _self.parents('ul').append('<li>\n' +
                             '                                            <span class="pl-3"><a href="javascript:void(0);" class="add-audit" ><i class="fa fa-plus"></i> 添加流程</a></span>\n' + addGroupHtml +

+ 67 - 0
app/public/js/stage_audit.js

@@ -479,6 +479,72 @@ $(document).ready(function () {
         return html;
     }
 
+    function makeSpHtml(datas) {
+        const html = [];
+        // 如果是重新上报,添加到重新上报列表中
+        const auditorshtml = [];
+        for (const [index,data] of datas.entries()) {
+            if (index !== 0) {
+                html.push('<li class="list-group-item d-flex" auditorId="'+ data[0].aid +'">');
+                html.push(`<div class="col-auto">${index}</div>`);
+                html.push('<div class="col">');
+                for (const auditor of data) {
+                    html.push(`<div class="d-inline-block mx-1" auditorId="${auditor.uid}"><i class="fa fa-user text-muted"></i> ${auditor.name} <small class="text-muted">${auditor.role}</small></div>`);
+                }
+                html.push('</div>');
+                html.push('<div class="col-auto">');
+                // todo 添加会签或签时
+                if (data[0].audit_type !== auditType.key.common) {
+                    html.push(`<span class="badge badge-pill badge-${auditType.info[data[0].audit_type].class} badge-bg-small"><small>${auditType.info[data[0].audit_type].long}</small></span>`);
+                }
+                // html.push('<span class="badge badge-pill badge-primary badge-bg-small"><small></small></span>');
+                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('</div>');
+                html.push('</li>');
+            }
+            // 添加新审批人流程修改
+            auditorshtml.push('<li class="list-group-item d-flex justify-content-between align-items-center" data-auditorid="' + data[0].aid + '">');
+            auditorshtml.push('<span class="mr-1"><i class="fa ' + (index === 0 ? 'fa-play-circle fa-rotate-90' : index+1 === datas.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i></span>');
+            auditorshtml.push('<span class="text-muted">');
+            for (const auditor of data) {
+                auditorshtml.push(`<small class="d-inline-block text-dark mx-1" title="${auditor.role}" data-auditorId="${auditor.uid}">${auditor.name}</small>`);
+            }
+            auditorshtml.push('</span>');
+            auditorshtml.push('<div class="d-flex ml-auto">');
+            if (data[0].audit_type !== auditType.key.common) {
+                auditorshtml.push(`<span class="badge badge-pill badge-${auditType.info[data[0].audit_type].class} p-1"><small>${auditType.info[data[0].audit_type].short}</small></span>`);
+            }
+            if (index === 0) {
+                auditorshtml.push('<span class="badge badge-light badge-pill ml-auto"><small>原报</small></span>');
+            } else if (index+1 === datas.length) {
+                auditorshtml.push('<span class="badge badge-light badge-pill"><small>终审</small></span>');
+            } else {
+                auditorshtml.push('<span class="badge badge-light badge-pill"><small>'+ transFormToChinese(index) +'审</small></span>');
+            }
+            auditorshtml.push('</div>');
+            auditorshtml.push('</li>');
+        }
+        $('#auditors').html(html.join(''));
+        $('#auditors-list').html(auditorshtml.join(''));
+    }
+
+    $('#change-sp-group').change(function () {
+        const data = {
+            type: 'change_sp_group',
+            sp_group: parseInt($(this).val()),
+        }
+        if (!data.sp_group) {
+            toastr.error('请选择固定审批组');
+            return false;
+        }
+        postData(preUrl + '/audit/spgroup', data, (datas) => {
+            makeSpHtml(datas);
+        });
+    });
+
+
 });
 // 检查上报情况
 function checkAuditorFrom () {
@@ -544,3 +610,4 @@ function codeSuccess(btn) {
         counter -= 1;
     }, 1000);
 }
+

+ 1 - 0
app/router.js

@@ -672,6 +672,7 @@ module.exports = app => {
     app.get('/tender/:id/measure/stage/:order/im-file/download', sessionAuth, tenderCheck, subProjectCheck, uncheckTenderCheck, stageCheck, 'stageController.downloadImFile');
     app.get('/tender/:id/measure/stage/:order/cpd', sessionAuth, tenderCheck, subProjectCheck, uncheckTenderCheck, stageCheck, 'stageController.exportStageData');
     app.post('/tender/:id/measure/stage/:order/cpd/load', sessionAuth, tenderCheck, subProjectCheck, uncheckTenderCheck, stageCheck, 'stageController.importStageData');
+    app.post('/tender/:id/measure/stage/:order/audit/spgroup', sessionAuth, tenderCheck, subProjectCheck, uncheckTenderCheck, stageCheck, 'stageController.changeSpGroup');
 
     // 暂存计量
     app.post('/tender/:id/measure/stage/:order/stash/list', sessionAuth, tenderCheck, subProjectCheck, stageCheck, 'stageController.stashList');

+ 26 - 0
app/service/shenpi_group.js

@@ -139,6 +139,32 @@ module.exports = app => {
             return await this.getDataByCondition({ tid, sp_type, is_select: 1 });
         }
 
+        async getGroupListByStage(tid, sp_type) {
+            const sql = 'select * from ?? where tid= ? and sp_type= ? order by id asc';
+            const sqlParam = [this.tableName, tid, sp_type];
+            return await this.db.query(sql, sqlParam);
+        }
+
+        async getSelectGroupByStageType(tid, sp_type, group_id = 0) {
+            const result = await this.getGroupListByStage(tid, sp_type);
+            if (result && result.length > 0) {
+                if (group_id !== 0) {
+                    const group = await this._.find(result, function(item) {
+                        return item.id === group_id;
+                    });
+                    if (group) return group;
+                }
+                const hadSelect = this._.find(result, function(item) {
+                    return item.is_select === 1;
+                });
+                if (hadSelect) {
+                    return hadSelect;
+                }
+                return result[0];
+            }
+            return null;
+        }
+
         async getGroupListByChangeType(tid, sp_type, change_type) {
             const sql = 'select * from ?? where tid= ? and sp_type= ? and JSON_CONTAINS(change_type, json_object(?, true)) order by id asc';
             const sqlParam = [this.tableName, tid, sp_type, change_type];

+ 20 - 0
app/service/stage_audit.js

@@ -2404,6 +2404,26 @@ module.exports = app => {
             ];
             return await this.db.query(sql, sqlParam);
         }
+
+        async stageSpGroup(stage, sp_group) {
+            const transaction = await this.db.beginTransaction();
+            try {
+                const group = await this.ctx.service.shenpiGroup.getDataById(sp_group);
+                if (!group) {
+                    throw '该固定审批组不存在,请刷新页面重新获取';
+                }
+
+                const shenpiList = await this.ctx.service.shenpiAudit.getAllDataByCondition({ where: { tid: this.ctx.tender.id, sp_type: shenpiConst.sp_type.stage, sp_status: shenpiConst.sp_status.gdspl, sp_group: group.id } });
+                // console.log('stageSpGroup shenpiList:', shenpiList);
+                await this.updateNewAuditList(stage, shenpiList);
+                await transaction.update(this.ctx.service.stage.tableName, { sp_group: group.id }, { where: { id: stage.id } });
+                await transaction.commit();
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+            return true;
+        }
     }
 
     return StageAudit;

+ 11 - 0
app/view/stage/audit_modal.ejs

@@ -35,6 +35,17 @@
                                 <% }) %>
                             </dl>
                         </div>
+                        <% } else if(spGroupList.length > 0) { %>
+                            <div class="row">
+                                <div class="col-7"></div>
+                                <div class="col-5">
+                                    <select class="form-control form-control-sm" id="change-sp-group">
+                                        <% for (const g of spGroupList) { %>
+                                            <option value="<%= g.id %>" <% if (g.id === ctx.stage.sp_group) { %>selected<% } %>><%= g.name %></option>
+                                        <% } %>
+                                    </select>
+                                </div>
+                            </div>
                         <% } %>
                     </div>
                     <div class="card mt-3">

+ 2 - 0
app/view/tender/shenpi.ejs

@@ -117,6 +117,8 @@
                                             <span class="pl-3"><a href="javascript:void(0);" class="add-audit" ><i class="fa fa-plus"></i> 添加流程</a></span>
                                             <% if (sp.code === 'change' && (!sp.groupList || (sp.groupList && sp.groupList.length === 0))) { %>
                                             <span class="pl-3"><a href="javascript:void(0);" class="show-spzsave" data-code="<%- sp.code %>"><i class="fa fa-save"></i> 存为审批组</a></span>
+                                            <% } else if (sp.code === 'stage' && (!sp.groupList || sp.groupList.length === 0)) { %>
+                                            <span class="pl-3"><a href="javascript:void(0);" class="show-spzsave" data-code="<%- sp.code %>"><i class="fa fa-save"></i> 存为审批组</a></span>
                                             <% } %>
                                         </li>
                                         <% } else { %>