Bläddra i källkod

增加同步流程按钮

ellisran 10 månader sedan
förälder
incheckning
d3a80d4875

+ 7 - 0
app/controller/change_controller.js

@@ -131,6 +131,7 @@ module.exports = app => {
                 },
             });
             const apLists = allPlanCodes.length > 0 ? ctx.app._.uniq(ctx.app._.map(allPlanCodes, 'plan_code')) : [];
+            const need_checking = await ctx.service.change.getCheckingList(ctx.tender.id, ctx.session.sessionUser.accountId, true);
 
             const renderData = {
                 moment,
@@ -157,6 +158,7 @@ module.exports = app => {
                 apLists,
                 auditType,
                 precision: ctx.tender.info.precision,
+                need_checking,
             };
 
             if (ctx.session.sessionProject.page_show.openChangeState) {
@@ -354,6 +356,11 @@ module.exports = app => {
                     case 'get_shenpi_list':
                         responseData.data.checkingList = await ctx.service.change.getCheckingList(ctx.tender.id, ctx.session.sessionUser.accountId);
                         break;
+
+                    case 'set_shenpi_list':
+                        await ctx.service.changeAudit.batchSetAudits(ctx.tender.id, data.cids, data.from_cid);
+                        responseData.data.uncheckList = await ctx.service.change.getUncheckList(ctx.tender.id, ctx.tender.info.shenpi.change);
+                        break;
                     default: throw '参数有误';
                 }
                 ctx.body = responseData;

+ 5 - 2
app/service/change.js

@@ -2140,7 +2140,7 @@ module.exports = app => {
                         }
                     }
                 } else if (shenpi_status === shenpiConst.sp_status.gdzs) {
-                    const shenpiInfo = await this.service.shenpiAudit.getDataByCondition({ tid: this.tender.id, sp_type: shenpiConst.sp_type.change, sp_status: shenpi_status });
+                    const shenpiInfo = await this.service.shenpiAudit.getDataByCondition({ tid, sp_type: shenpiConst.sp_type.change, sp_status: shenpi_status });
                     // 判断最后一个id是否与固定终审id相同,不同则删除原审批流中如果存在的id和添加终审
                     const lastAuditors = auditList.filter(x => { return x.usite === auditList.length - 1; });
                     if (shenpiInfo && (lastAuditors.length === 0 || (lastAuditors.length > 1 || shenpiInfo.audit_id !== lastAuditors[0].uid))) {
@@ -2154,10 +2154,13 @@ module.exports = app => {
             return returnList;
         }
 
-        async getCheckingList(tid, uid) {
+        async getCheckingList(tid, uid, checking_count = false) {
             const sql = 'select c.* from ?? as c LEFT JOIN ?? as ca ON c.cid = ca.cid where c.tid = ? and ca.status = ? and ca.uid = ? and ca.usite != 0';
             const sqlParams = [this.tableName, this.ctx.service.changeAudit.tableName, tid, audit.change.status.checking, uid];
             const list = await this.db.query(sql, sqlParams);
+            if (checking_count) {
+                return list.length;
+            }
             const returnList = [];
             // 判断是否是终审
             for (const l of list) {

+ 44 - 0
app/service/change_audit.js

@@ -1369,6 +1369,50 @@ module.exports = app => {
                 throw err;
             }
         }
+
+        async batchSetAudits(tid, cids, from_cid) {
+            const transaction = await this.db.beginTransaction();
+            try {
+                const changes = await this.ctx.service.change.getAllDataByCondition({ where: { tid, cid: cids } });
+                const from_change = await this.ctx.service.change.getDataByCondition({ tid, cid: from_cid });
+                const new_audits = await transaction.select(this.tableName, { where: { cid: from_cid, times: from_change.times }, orders: [['audit_order', 'asc']] });
+                new_audits.shift();
+                const insertAudits = [];
+                const updateChanges = [];
+                for (const c of changes) {
+                    if (from_change.sp_group !== c.sp_group) {
+                        updateChanges.push({
+                            row: { sp_group: from_change.sp_group },
+                            where: { tid, cid: c.cid }
+                        });
+                    }
+                    const newAudits = new_audits.map(x => {
+                        return {
+                            tid, cid: c.cid, uid: x.uid, name: x.name,
+                            company: x.company, jobs: x.role,
+                            usort: x.usort, usite: x.usite,
+                            audit_order: x.audit_order, audit_type: x.audit_type,
+                            times: c.times, status: auditConst.status.uncheck,
+                        };
+                    });
+                    // 先删除旧的审批流(除了原报),再添加新的
+                    const sql = 'DELETE FROM ?? WHERE `cid`= ? AND `times` = ? AND `usite` != 0';
+                    const sqlParam = [this.tableName, c.cid, c.times];
+                    await transaction.query(sql, sqlParam);
+                    // await transaction.delete(this.tableName, { tid, cid: c.cid, times: c.times });
+                    insertAudits.push(...newAudits);
+                }
+                if (updateChanges.length > 0) await transaction.updateRows(this.ctx.service.change.tableName, updateChanges);
+                if (insertAudits.length > 0) await transaction.insert(this.tableName, insertAudits);
+                // 更新到审批流程方法
+                await transaction.commit();
+                return true;
+            } catch (err) {
+                console.log(err);
+                await transaction.rollback();
+                throw err;
+            }
+        }
     }
 
     return ChangeAudit;

+ 2 - 0
app/view/change/index.ejs

@@ -74,7 +74,9 @@
                     <a href="#setting" data-toggle="modal" data-target="#setting" class="btn btn-sm btn-outline-primary pull-right ml-2"><i class="fa fa-cog"></i></a>
                     <a href="#batch-sb" data-toggle="modal" data-target="#batch-sb" class="btn btn-sm btn-primary pull-right ml-2">批量上报</a>
                 <% } %>
+                <% if (need_checking) { %>
                     <a href="#batch-sp" data-toggle="modal" data-target="#batch-sp" class="btn btn-sm btn-success pull-right">批量审批</a>
+                <% } %>
             </div>
         </div>
     </div>

+ 35 - 3
app/view/change/modal.ejs

@@ -234,7 +234,9 @@
                     <!-- 右侧新审批流程 -->
                     <div class="col-6">
                         <div class=" ml-auto">
-                            <div class="dropdown text-right" id="show-audit-select">
+                            <div class="dropdown text-right">
+                                <button class="btn btn-sm btn-primary" id="synchronize_shenpi_btn">同步流程至其它已勾选变更令</button>
+                                <span id="show-audit-select"></span>
                             </div>
                             <div class="card mt-1">
                                 <div class="card-header">
@@ -248,11 +250,11 @@
                         </div>
                     </div>
                 </div>
-                <div class="alert alert-warning mt-2 mb-0">批量操作会覆盖原审批流程,请合理选择。</div>
+                <div class="alert alert-warning mt-2 mb-0">没有设置审批流的变更令将无法上报,请先设置审批流。</div>
             </div>
             <div class="modal-footer">
                 <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">取消</button>
-                <button class="btn btn-sm btn-primary" id="batch_uncheck_btn">确定</button>
+                <button class="btn btn-sm btn-primary" id="batch_uncheck_btn">确定上报</button>
             </div>
         </div>
     </div>
@@ -484,6 +486,36 @@
             $('#uncheck_list tr').find('input[type="checkbox"]').prop('checked', $(this).prop('checked'));
         });
 
+        $('#synchronize_shenpi_btn').click(function () {
+            const this_cid = $('#uncheck_list tr[class="table-warning"]').find('a').attr('href').split('/')[4];
+            const info = uncheckList.find(l => l.cid === this_cid);
+            if (!this_cid || !info) {
+                toastr.error('请先选择一个变更令');
+                return false;
+            }
+            if ($('#uncheck_list input:checked').length === 0) {
+                toastr.error('请至少勾选一个变更令');
+                return false;
+            }
+            const cids = [];
+            $('#uncheck_list input:checked').each(function () {
+                cids.push($(this).val());
+            });
+            if (cids.length === 1 && cids[0] === this_cid) {
+                toastr.error('请至少勾选一个其它变更令');
+                return false;
+            }
+            if (cids.indexOf(this_cid) !== -1) cids.splice(cids.indexOf(this_cid), 1);
+            console.log(cids, info);
+            postData(`/tender/${tenderId}/change/batch/fun`, { type: 'set_shenpi_list', cids, from_cid: this_cid }, function (res) {
+                toastr.success('同步流程成功');
+                uncheckList = res.uncheckList;
+                for (const index in res.uncheckList) {
+                    $('#uncheck_list tr').eq(index).children('td').eq(2).html(setAuditList(res.uncheckList[index].auditList));
+                }
+            });
+        });
+
         let timer = null;
         let oldSearchVal = null;
         $('body').on('input propertychange', 'div[id$="_dropdownMenu"] .gr-search', function(e) {