浏览代码

审批流程

laiguoran 4 年之前
父节点
当前提交
3eeb5b6b51
共有 7 个文件被更改,包括 275 次插入70 次删除
  1. 1 1
      app/const/shenpi.js
  2. 75 0
      app/controller/tender_controller.js
  3. 107 58
      app/public/js/shenpi.js
  4. 2 0
      app/router.js
  5. 63 0
      app/service/shenpi_audit.js
  6. 24 10
      app/view/tender/shenpi.ejs
  7. 3 1
      sql/update.sql

+ 1 - 1
app/const/shenpi.js

@@ -4,7 +4,7 @@
  * 审批流程设置
  *
  * @author ELlisran
- * @date 2019/10/20
+ * @date 2020/10/20
  * @version
  */
 // 审批类型

+ 75 - 0
app/controller/tender_controller.js

@@ -749,6 +749,15 @@ module.exports = app => {
                 const groupList = accountList.filter(item => item.account_group === idx);
                 return { groupName: item, groupList };
             });
+            for (const sp of shenpiConst.sp_lc) {
+                sp.status = ctx.tender.info.shenpi ? JSON.parse(ctx.tender.info.shenpi)[sp.code] : shenpiConst.sp_status.sqspr;
+                if (sp.status === shenpiConst.sp_status.gdspl) {
+                    sp.auditList = await ctx.service.shenpiAudit.getAuditList(ctx.tender.id, sp.type, sp.status);
+                } else if (sp.status === shenpiConst.sp_status.gdzs) {
+                    sp.audit = await ctx.service.shenpiAudit.getAudit(ctx.tender.id, sp.type, sp.status);
+                }
+            }
+            // 获取固定审批流 or 固定终审
             const renderData = {
                 shenpi: shenpiConst,
                 accountList,
@@ -756,6 +765,72 @@ module.exports = app => {
             };
             await this._list('tender/shenpi.ejs', renderData);
         }
+
+        async saveTenderInfoShenpi(ctx) {
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                if (!data) {
+                    throw '提交数据错误';
+                }
+                // 判断修改权限
+                if (ctx.session.sessionUser.is_admin === 0) {
+                    throw '你没有权限修改审批流程';
+                }
+                let postData = {};
+                if (!ctx.tender.info.shenpi) {
+                    for (const sp of shenpiConst.sp_lc) {
+                        if (sp.code === data.code) {
+                            postData[sp.code] = data.status;
+                        } else {
+                            postData[sp.code] = shenpiConst.sp_status.sqspr;
+                        }
+                    }
+                } else {
+                    postData = JSON.parse(ctx.tender.info.shenpi);
+                    postData[data.code] = data.status;
+                }
+                await ctx.service.tenderInfo.saveTenderInfo(ctx.tender.id, { shenpi: JSON.stringify(postData) });
+                let auditList = [];
+                if (data.status === shenpiConst.sp_status.gdspl) {
+                    auditList = await ctx.service.shenpiAudit.getAuditList(ctx.tender.id, shenpiConst.sp_type[data.code], data.status);
+                } else if (data.status === shenpiConst.sp_status.gdzs) {
+                    auditList = await ctx.service.shenpiAudit.getAudit(ctx.tender.id, shenpiConst.sp_type[data.code], data.status);
+                }
+                ctx.body = { err: 0, msg: '', data: auditList };
+            } catch (err) {
+                this.log(err);
+                ctx.body = this.ajaxErrorBody(err, '保存审批流程设置失败');
+            }
+        }
+
+        async saveShenpiAudit(ctx) {
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                if (!data) {
+                    throw '提交数据错误';
+                }
+                // 判断修改权限
+                if (ctx.session.sessionUser.is_admin === 0) {
+                    throw '你没有权限修改审批流程';
+                }
+                switch (data.type) {
+                    case 'add':
+                        const result = await ctx.service.shenpiAudit.addAudit(data);
+                        if (result) {
+                            throw '添加审批人失败';
+                        }
+                        break;
+                    case 'del':
+                        await ctx.service.shenpiAudit.removeAudit(data);
+                        break;
+                    default:break;
+                }
+                ctx.body = { err: 0, msg: '' };
+            } catch (err) {
+                this.log(err);
+                ctx.body = this.ajaxErrorBody(err, '保存审批流程设置失败');
+            }
+        }
     }
 
     return TenderController;

+ 107 - 58
app/public/js/shenpi.js

@@ -9,8 +9,8 @@
  */
 
 $(document).ready(function () {
-    let timer = null
-    let oldSearchVal = null
+    let timer = null;
+    let oldSearchVal = null;
     $('body').bind('input propertychange', '.gr-search', function(e) {
         oldSearchVal = e.target.value;
         timer && clearTimeout(timer);
@@ -40,10 +40,10 @@ $(document).ready(function () {
                                     <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>`
+                                </dd>`;
                             }
                         });
-                        html += '</div>'
+                        html += '</div>';
                     });
                     $('.book-list').empty();
                     $('.book-list').append(html);
@@ -54,18 +54,18 @@ $(document).ready(function () {
 
     // 添加审批流程按钮逻辑
     $('body').on('click', '.book-list dt', function () {
-        const idx = $(this).find('.acc-btn').attr('data-groupid')
-        const type = $(this).find('.acc-btn').attr('data-type')
+        const idx = $(this).find('.acc-btn').attr('data-groupid');
+        const type = $(this).find('.acc-btn').attr('data-type');
         if (type === 'hide') {
             $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
-                $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
-                $(this).find('.acc-btn').attr('data-type', 'show')
+                $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o');
+                $(this).find('.acc-btn').attr('data-type', 'show');
 
             })
         } else {
             $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
-                $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
-                $(this).find('.acc-btn').attr('data-type', 'hide')
+                $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square');
+                $(this).find('.acc-btn').attr('data-type', 'hide');
             })
         }
         return false;
@@ -78,25 +78,41 @@ $(document).ready(function () {
         const this_code = $(this).data('code');
         const spt = sp_status_list[this_status];
         $(this).parents('.form-group').siblings('.alert-warning').text(spt.name + ':' + spt.msg);
-        if (this_status === sp_status.sqspr) {
-            $(this).parents('.form-group').siblings('.lc-show').html('');
-        } else if (this_status === sp_status.gdspl) {
-            let addhtml = '<ul class="list-unstyled">\n';
-            addhtml += makeSelectAudit(this_code, '一');
-            addhtml += '</ul>\n';
-            $(this).parents('.form-group').siblings('.lc-show').html(addhtml);
-        } else if (this_status === sp_status.gdzs) {
-            let addhtml = '<ul class="list-unstyled">\n' +
-                '                                        <li class="d-flex justify-content-start mb-3">\n' +
-                '                                            <span class="col-auto">授权审批人</span>\n' +
-                '                                            <span class="col-7">\n' +
-                '                                                <span class="d-inline-block"></span>\n' +
-                '                                            </span>\n' +
-                '                                        </li>\n';
-            addhtml += makeSelectAudit(this_code);
-            addhtml += '</ul>\n';
-            $(this).parents('.form-group').siblings('.lc-show').html(addhtml);
-        }
+        // 拼接post json
+        const prop = {
+            code: this_code,
+            status: this_status
+        };
+        const _self = $(this);
+        const tenderId = window.location.pathname.split('/')[2];
+        postData('/tender/' + tenderId + '/shenpi/save', prop, function (data) {
+            if (this_status === sp_status.sqspr) {
+                _self.parents('.form-group').siblings('.lc-show').html('');
+            } else if (this_status === sp_status.gdspl) {
+                let addhtml = '<ul class="list-unstyled">\n';
+                if (data.length !== 0) {
+                    for(const [i, audit] of data.entries()) {
+                        addhtml += makeAudit(audit, transFormToChinese(i+1));
+                    }
+                    addhtml += '<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>';
+                } else {
+                    addhtml += makeSelectAudit(this_code, '一');
+                }
+                addhtml += '</ul>\n';
+                _self.parents('.form-group').siblings('.lc-show').html(addhtml);
+            } else if (this_status === sp_status.gdzs) {
+                let addhtml = '<ul class="list-unstyled">\n' +
+                    '                                        <li class="d-flex justify-content-start mb-3">\n' +
+                    '                                            <span class="col-auto">授权审批人</span>\n' +
+                    '                                            <span class="col-7">\n' +
+                    '                                                <span class="d-inline-block"></span>\n' +
+                    '                                            </span>\n' +
+                    '                                        </li>\n';
+                addhtml += data ? makeAudit(data) : makeSelectAudit(this_code);
+                addhtml += '</ul>\n';
+                _self.parents('.form-group').siblings('.lc-show').html(addhtml);
+            }
+        });
     });
 
     // 选中审批人
@@ -106,8 +122,8 @@ $(document).ready(function () {
             const user = _.find(accountList, function (item) {
                 return item.id === id;
             });
-
             const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
+            const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
             if (this_status === sp_status.gdspl) {
                 // 判断是否已存在审批人
                 const aid_num = $(this).parents('ul').find('.remove-audit').length;
@@ -118,11 +134,23 @@ $(document).ready(function () {
                         return;
                     }
                 }
-                $(this).parents('ul').append('<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>');
-            }
-            $(this).parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
-                '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <a href="javascript:void(0);" class="remove-audit btn-sm text-danger px-1" title="移除" data-id="'+ user.id +'"><i class="fa fa-remove"></i></a></span> </span>');
 
+            }
+            const prop = {
+                status: this_status,
+                code: sp_type[this_code],
+                audit_id: id,
+                type: 'add',
+            };
+            const _self = $(this);
+            const tenderId = window.location.pathname.split('/')[2];
+            postData('/tender/' + tenderId + '/shenpi/audit/save', prop, function (data) {
+                if (this_status === sp_status.gdspl) {
+                    _self.parents('ul').append('<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>');
+                }
+                _self.parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
+                    '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <a href="javascript:void(0);" class="remove-audit btn-sm text-danger px-1" title="移除" data-id="'+ user.id +'"><i class="fa fa-remove"></i></a></span> </span>');
+            });
         }
     });
 
@@ -131,32 +159,42 @@ $(document).ready(function () {
         const id = parseInt($(this).data('id'));
         const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
         const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
-        if (this_status === sp_status.gdspl) {
-            const _self = $(this).parents('.lc-show');
-            $(this).parents('li').remove();
-            const aid_num = parseInt(_self.children('ul').find('li.d-flex').length);
-            if (aid_num === 0) {
-                let addhtml = '<ul class="list-unstyled">\n';
-                addhtml += makeSelectAudit(this_code, '一');
-                addhtml += '</ul>\n';
-                _self.html(addhtml);
-            } else {
-                for (let i = 0; i < aid_num; i++) {
-                    _self.find('li.d-flex').eq(i).find('.col-auto').text(transFormToChinese(i+1) + '审');
+        const prop = {
+            status: this_status,
+            code: sp_type[this_code],
+            audit_id: id,
+            type: 'del',
+        };
+        const _self = $(this);
+        const tenderId = window.location.pathname.split('/')[2];
+        postData('/tender/' + tenderId + '/shenpi/audit/save', prop, function (data) {
+            if (this_status === sp_status.gdspl) {
+                const _selflc = _self.parents('.lc-show');
+                _self.parents('li').remove();
+                const aid_num = parseInt(_selflc.children('ul').find('li.d-flex').length);
+                if (aid_num === 0) {
+                    let addhtml = '<ul class="list-unstyled">\n';
+                    addhtml += makeSelectAudit(this_code, '一');
+                    addhtml += '</ul>\n';
+                    _selflc.html(addhtml);
+                } else {
+                    for (let i = 0; i < aid_num; i++) {
+                        _selflc.find('li.d-flex').eq(i).find('.col-auto').text(transFormToChinese(i+1) + '审');
+                    }
                 }
+            } else if (this_status === sp_status.gdzs) {
+                let addhtml = '<ul class="list-unstyled">\n' +
+                    '                                        <li class="d-flex justify-content-start mb-3">\n' +
+                    '                                            <span class="col-auto">授权审批人</span>\n' +
+                    '                                            <span class="col-7">\n' +
+                    '                                                <span class="d-inline-block"></span>\n' +
+                    '                                            </span>\n' +
+                    '                                        </li>\n';
+                addhtml += makeSelectAudit(this_code);
+                addhtml += '</ul>\n';
+                _self.parents('.lc-show').html(addhtml);
             }
-        } else if (this_status === sp_status.gdzs) {
-            let addhtml = '<ul class="list-unstyled">\n' +
-                '                                        <li class="d-flex justify-content-start mb-3">\n' +
-                '                                            <span class="col-auto">授权审批人</span>\n' +
-                '                                            <span class="col-7">\n' +
-                '                                                <span class="d-inline-block"></span>\n' +
-                '                                            </span>\n' +
-                '                                        </li>\n';
-            addhtml += makeSelectAudit(this_code);
-            addhtml += '</ul>\n';
-            $(this).parents('.lc-show').html(addhtml);
-        }
+        })
     });
 
     // 固定审批流-添加流程
@@ -168,6 +206,17 @@ $(document).ready(function () {
         $(this).parents('li').remove();
     });
 
+    // 审批流程-审批人html 生成
+    function makeAudit(audit, i = '终') {
+        return '<li class="d-flex justify-content-start mb-3">\n' +
+            '                                            <span class="col-auto">'+ i +'审</span>\n' +
+            '                                            <span class="col-7 spr-span">\n' +
+            '                                            <span class="d-inline-block"></span>\n' +
+            '                                            <span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <a href="javascript:void(0);" class="remove-audit btn-sm text-danger px-1" title="移除" data-id="'+ audit.audit_id +'"><i class="fa fa-remove"></i></a></span> </span>\n' +
+            '                                            </span>\n' +
+            '                                        </li>';
+    }
+
     // 审批流程-选择审批人html 生成
     function makeSelectAudit(code, i = '终') {
         let divhtml = '';

+ 2 - 0
app/router.js

@@ -108,6 +108,8 @@ module.exports = app => {
     app.post('/tender/rule', sessionAuth, 'tenderController.rule');
     app.post('/tender/:id/rule/first', sessionAuth, tenderCheck, 'tenderController.ruleFirst');
     app.get('/tender/:id/shenpi', sessionAuth, tenderCheck, 'tenderController.shenpiSet');
+    app.post('/tender/:id/shenpi/save', sessionAuth, tenderCheck, 'tenderController.saveTenderInfoShenpi');
+    app.post('/tender/:id/shenpi/audit/save', sessionAuth, tenderCheck, 'tenderController.saveShenpiAudit');
 
     // 预付款
     app.get('/tender/:id/advance', sessionAuth, tenderCheck, 'advanceController.index');

+ 63 - 0
app/service/shenpi_audit.js

@@ -0,0 +1,63 @@
+'use strict';
+
+/**
+ * 版本数据模型
+ *
+ * @author CaiAoLin
+ * @date 2017/10/25
+ * @version
+ */
+
+module.exports = app => {
+
+    class ShenpiAudit extends app.BaseService {
+
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'shenpi_audit';
+        }
+
+        async getAudit(tid, type, status) {
+            const sql = 'SELECT sp.audit_id, 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 = ?';
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tid, type, status];
+            return await this.db.queryOne(sql, sqlParam);
+        }
+
+        async getAuditList(tid, type, status) {
+            const sql = 'SELECT sp.audit_id, 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 = ? ORDER BY sp.id ASC';
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tid, type, status];
+            return await this.db.query(sql, sqlParam);
+        }
+
+        async addAudit(data) {
+            const insertData = {
+                tid: this.ctx.tender.id,
+                sp_type: data.code,
+                sp_status: data.status,
+                audit_id: data.audit_id,
+            };
+            const result = await this.db.insert(this.tableName, insertData);
+            return result.effectRows === 1;
+        }
+
+        async removeAudit(data) {
+            const delData = {
+                tid: this.ctx.tender.id,
+                sp_type: data.code,
+                sp_status: data.status,
+                audit_id: data.audit_id,
+            };
+            return await this.db.delete(this.tableName, delData);
+        }
+    }
+
+    return ShenpiAudit;
+};

+ 24 - 10
app/view/tender/shenpi.ejs

@@ -19,27 +19,30 @@
                                         <div class="form-group form-check">
                                             <% for (const st in shenpi.sp_status_list) { %>
                                                 <div class="custom-control custom-checkbox custom-control-inline">
-                                                    <input type="radio" class="custom-control-input" data-code="<%- sp.code %>" value="<%- shenpi.sp_status_list[st].status %>" name="<%- sp.code %>" id="<%- sp.code %>_<%- shenpi.sp_status_list[st].status %>" <%if (sp.status && sp.status === shenpi.sp_status_list[st].status) { %>checked<% } %>>
+                                                    <input type="radio" class="custom-control-input" data-code="<%- sp.code %>" value="<%- shenpi.sp_status_list[st].status %>" name="<%- sp.code %>" id="<%- sp.code %>_<%- shenpi.sp_status_list[st].status %>" <%if (sp.status === shenpi.sp_status_list[st].status) { %>checked<% } %>>
                                                     <label class="custom-control-label" for="<%- sp.code %>_<%- shenpi.sp_status_list[st].status %>"><%- shenpi.sp_status_list[st].name %></label>
                                                 </div>
                                             <% } %>
                                         </div>
                                     </div>
-                                    <div class="alert alert-warning">
-                                        <% if (sp.status) { %><%- shenpi.sp_status_list[sp.status].name %>:<%- shenpi.sp_status_list[sp.status].msg %><% } %>
-                                    </div>
+                                    <div class="alert alert-warning"><%- shenpi.sp_status_list[sp.status].name %>:<%- shenpi.sp_status_list[sp.status].msg %></div>
                                     <div class="lc-show">
-                                    <% if (sp.status && sp.status === shenpi.sp_status.gdspl) { %>
+                                    <% if (sp.status === shenpi.sp_status.gdspl) { %>
                                     <ul class="list-unstyled">
+                                        <% if (sp.auditList.length > 0) { %>
+                                        <% for (const [i, audit] of sp.auditList.entries()) { %>
                                         <li class="d-flex justify-content-start mb-3">
-                                            <span class="col-auto">一审</span>
+                                            <span class="col-auto"><%- ctx.helper.transFormToChinese(i+1) %>审</span>
                                             <span class="col-7 spr-span">
                                                 <span class="d-inline-block"></span>
-                                                <span class="d-inline-block"><span class="badge badge-light">王五 <a href="javascript:void(0);" class="remove-audit btn-sm text-danger px-1" title="移除"><i class="fa fa-remove"></i></a></span> </span>
+                                                <span class="d-inline-block"><span class="badge badge-light"><%- audit.name %> <a href="javascript:void(0);" class="remove-audit btn-sm text-danger px-1" title="移除" data-id="<%- audit.audit_id %>"><i class="fa fa-remove"></i></a></span> </span>
                                             </span>
                                         </li>
+                                        <% } %>
+                                        <li class="pl-3"><a href="javascript:void(0);" class="add-audit" ><i class="fa fa-plus"></i> 添加流程</a></li>
+                                        <% } else { %>
                                         <li class="d-flex justify-content-start mb-3">
-                                            <span class="col-auto">二审</span>
+                                            <span class="col-auto">审</span>
                                             <span class="col-7 spr-span">
                                             <span class="d-inline-block">
                                                 <div class="dropdown text-right">
@@ -70,9 +73,9 @@
                                             </span>
                                         </span>
                                         </li>
-                                        <li class="pl-3"><a href="javascript:void(0);" class="add-audit" ><i class="fa fa-plus"></i> 添加流程</a></li>
+                                        <% } %>
                                     </ul>
-                                    <% } else if (sp.status && sp.status === shenpi.sp_status.gdzs) { %>
+                                    <% } else if (sp.status === shenpi.sp_status.gdzs) { %>
                                     <ul class="list-unstyled">
                                         <li class="d-flex justify-content-start mb-3">
                                             <span class="col-auto">授权审批人</span>
@@ -80,6 +83,15 @@
                                                 <span class="d-inline-block"></span>
                                             </span>
                                         </li>
+                                        <% if (sp.audit) { %>
+                                        <li class="d-flex justify-content-start mb-3">
+                                            <span class="col-auto">终审</span>
+                                            <span class="col-7 spr-span">
+                                            <span class="d-inline-block"></span>
+                                            <span class="d-inline-block"><span class="badge badge-light"><%- sp.audit.name %> <a href="javascript:void(0);" class="remove-audit btn-sm text-danger px-1" title="移除" data-id="<%- sp.audit.audit_id %>"><i class="fa fa-remove"></i></a></span> </span>
+                                            </span>
+                                        </li>
+                                        <% } else { %>
                                         <li class="d-flex justify-content-start mb-3">
                                             <span class="col-auto">终审</span>
                                             <span class="col-7 spr-span">
@@ -112,6 +124,7 @@
                                                 </span>
                                             </span>
                                         </li>
+                                        <% } %>
                                     </ul>
                                     <% } %>
                                     </div>
@@ -126,6 +139,7 @@
 </div>
 <script src="/public/js/sub_menu.js"></script>
 <script>
+    const sp_type = JSON.parse('<%- JSON.stringify(shenpi.sp_type) %>');
     const sp_status = JSON.parse('<%- JSON.stringify(shenpi.sp_status) %>');
     const sp_status_list = JSON.parse('<%- JSON.stringify(shenpi.sp_status_list) %>');
     const accountGroup = JSON.parse('<%- JSON.stringify(accountGroup) %>');

+ 3 - 1
sql/update.sql

@@ -1,2 +1,4 @@
 ALTER TABLE `zh_s2b_proj`
-ADD COLUMN `common_option`  text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '通用配置' AFTER `dagl_option`;
+ADD COLUMN `common_option`  text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '通用配置' AFTER `dagl_option`;
+
+ALTER TABLE `zh_tender_info` ADD `shenpi` VARCHAR(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '审批流程设置' AFTER `pay_account`;