MaiXinRong 1 день назад
Родитель
Сommit
0a234cc95d

+ 24 - 0
app/controller/stage_controller.js

@@ -490,6 +490,11 @@ module.exports = app => {
                             const exprData = await ctx.service.expr.getAllDataByCondition({ where: { tid: ctx.stage.tid, calc_module: 'stage' } });
                             responseData.data.expr = exprData;
                             break;
+                        case 'auditLocked':
+                            responseData.data.auditLocked = ctx.session.sessionUser.is_admin
+                                ? ctx.stage.auditLocked
+                                : ctx.stage.auditLocked.filter(x => { return x.aid === ctx.session.sessionUser.accountId; });
+                            break;
                     }
                 }
 
@@ -499,6 +504,25 @@ module.exports = app => {
                 ctx.body = { err: 1, msg: err.toString(), data: null };
             }
         }
+        async unlock(ctx) {
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                if (!data.updateType || !data.updateData) throw '数据错误';
+
+                const responseData = { err: 0, msg: '' };
+                switch(data.updateType) {
+                    case 'audit_locked_lid':
+                        responseData.data = await ctx.service.stageAudit.updateUnlockLid(ctx.stage, data.updateData);
+                        break;
+                    default:
+                        throw '数据错误';
+                }
+                ctx.body = responseData;
+            } catch (err) {
+                ctx.log(err);
+                ctx.ajaxErrorBody(err, '解锁数据失败');
+            }
+        }
 
         async _innerCheckChangeBillsOver(ctx, checkData) {
             const change = await this.ctx.service.change.getAllDataByCondition({ where: { tid: ctx.tender.id } });

+ 1 - 1
app/middleware/stage_check.js

@@ -74,7 +74,6 @@ module.exports = options => {
             // todo 校验权限 (标段参与人、分享、游客)
             const accountId = this.session.sessionUser.accountId;
             const shareIds = [];
-            console.log(stage.curAuditors);
             if (stage.status === status.uncheck) {
                 stage.readOnly = accountId !== stage.user_id && stage.userAssistIds.indexOf(accountId) < 0;
                 if (!stage.readOnly) {
@@ -152,6 +151,7 @@ module.exports = options => {
             // 根据状态判断是否需要更新审批人列表
             yield this.service.stage.doCheckStageCanCancel(stage);
             stage.readySettle = yield this.service.settle.getReadySettle(stage.tid);
+            stage.auditLocked = yield this.service.stageAudit.getAuditLockedId(stage);
             this.stage = stage;
             // 根据状态判断是否需要更新审批人列表
             if ((stage.status === status.uncheck || stage.status === status.checkNo) && this.tender.info.shenpi.stage !== shenpiConst.sp_status.sqspr) {

+ 102 - 26
app/public/js/stage.js

@@ -5477,13 +5477,28 @@ $(document).ready(() => {
 
     // 审批退回锁定
     const spBackLock = (function(){
-        let lockSpread, lockSheet, lockTree;
+        let lockSpread, lockSheet, lockTree, auditLockedHis;
+        let lockType;
         const getLockedLid = function() {
             if (!lockTree) return '';
             const lockedLid = lockTree.nodes.filter(x => { return x.locked; }).map(y => { return y.ledger_id; });
             if (lockedLid.length > 200) throw '锁定的节点过多,请尽量在父项锁定数据';
             return lockedLid.join(',');
         };
+        const getAuditLocked = function() {
+            if (!lockTree) return [];
+            const lockedLid = lockTree.nodes.filter(x => { return x.locked; }).map(y => { return y.ledger_id});
+            auditLockedHis.forEach(x => {
+                x.org_locked_lid = x.audit_locked_lid.split(',').map(y => { return parseInt(y); });
+                x.new_locked_lid = [];
+                for (const lid in x.org_locked_lid) {
+                    if (lockedLid.indexOf(lid) >= 0) x.new_locked_lid.push(lid);
+                }
+            });
+            const result = auditLockedHis.filter(x => { return x.new_locked_lid.length < x.org_locked_lid.length; })
+                .map(y => { return { id: y.id, audit_locked_lid: y.new_locked_lid.join(',') }; });
+            return result;
+        };
         const init = function(setting) {
             if (lockSpread) return;
             lockSpread = SpreadJsObj.createNewSpread($('#sp-lock-spread')[0]);
@@ -5533,32 +5548,53 @@ $(document).ready(() => {
             lockTree.refreshNodeVisible();
             SpreadJsObj.loadSheetData(lockSheet, SpreadJsObj.DataType.Tree, lockTree);
 
-            lockSpread.bind(spreadNS.Events.ButtonClicked, function(e, info) {
-                if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
+            if (lockType === 'lock') {
+                lockSpread.bind(spreadNS.Events.ButtonClicked, function(e, info) {
+                    if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
 
-                const col = info.sheet.zh_setting.cols[info.col];
-                if (col.field !== 'locked') return;
+                    const col = info.sheet.zh_setting.cols[info.col];
+                    if (col.field !== 'locked') return;
 
-                const node = SpreadJsObj.getSelectObject(info.sheet);
-                if (node._fixed) {
-                    toastr.warning('无权锁定该节点,如需锁定,请在子项尝试');
-                    return;
-                }
-                if (!node.locked) {
-                    const parents = info.sheet.zh_tree.getAllParents(node);
-                    if (parents.find(x => { return x.locked; })) {
-                        toastr.warning('父项已锁定,请勿在子项重复锁定');
+                    const node = SpreadJsObj.getSelectObject(info.sheet);
+                    if (node._fixed) {
+                        toastr.warning('无权锁定该节点,如需锁定,请在子项尝试');
                         return;
                     }
-                }
-                node.locked = !node.locked;
-                SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
-            });
+                    if (!node.locked) {
+                        const parents = info.sheet.zh_tree.getAllParents(node);
+                        if (parents.find(x => { return x.locked; })) {
+                            toastr.warning('父项已锁定,请勿在子项重复锁定');
+                            return;
+                        }
+                    }
+                    node.locked = !node.locked;
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
+                });
+            } else {
+                lockSpread.bind(spreadNS.Events.ButtonClicked, function(e, info) {
+                    if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
+
+                    const col = info.sheet.zh_setting.cols[info.col];
+                    if (col.field !== 'locked') return;
+
+                    const node = SpreadJsObj.getSelectObject(info.sheet);
+                    if (!node.locked && !node.org_locked) {
+                        toastr.warning('仅可解锁节点,不可锁定新节点');
+                        return;
+                    }
+
+                    node.locked = !node.locked;
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
+                });
+            }
 
             $('#sp-lock-ok').click(function() {
-                setting.callback(getLockedLid());
+                if (lockType === 'lock') {
+                    setting.callback(getLockedLid());
+                } else if (lockType === 'unlock') {
+                    setting.callback(getAuditLocked());
+                }
                 $('#sp-lock').modal('hide');
-                $('#sp-back').modal('show');
             });
             $('#sp-lock').on('shown.bs.modal', function() {
                 lockSpread.refresh();
@@ -5568,24 +5604,64 @@ $(document).ready(() => {
             if (!lid) return;
             const lidList = lid.split(',');
             lockTree.nodes.forEach(x => {
-                if (lidList.indexOf(x.ledger_id + '') >= 0) x.locked = 1;
-            })
+                if (lidList.indexOf(x.ledger_id + '') >= 0) {
+                    x.locked = 1;
+                }
+            });
+        };
+        const loadAuditLocked = function(auditLocked) {
+            auditLockedHis = auditLocked;
+            const lidList = auditLockedHis.map(x => { return x.audit_locked_lid; }).join(',').split(',');
+            lockTree.nodes.forEach(x => {
+                if (lidList.indexOf(x.ledger_id + '') >= 0) {
+                    x.locked = 1;
+                    x.org_locked = 1;
+                }
+            });
+            SpreadJsObj.reloadColData(lockSheet, 0);
         };
-        const show = function(setting) {
+        const showLocked = function(setting) {
+            lockType = 'lock';
             init(setting);
             loadLockedLid(setting.locked_lid);
             $('#sp-back').modal('hide');
             $('#sp-lock').modal('show');
         };
-        return { show }
+        const showUnlocked = function(setting) {
+            lockType = 'unlock';
+            init(setting);
+            loadAuditLocked(setting.auditLocked);
+            $('#sp-lock').modal('show');
+        };
+        return { showLocked, showUnlocked }
     })();
     $('#sp-back-lock').click(function(){
-        spBackLock.show({
+        spBackLock.showLocked({
             tree: stageTree,
             locked_lid: $('[name=audit_locked_lid]').val(),
-            callback: function(lid) { $('[name=audit_locked_lid]').val(lid) },
+            callback: function(lid) {
+                $('[name=audit_locked_lid]').val(lid);
+                $('#sp-back').modal('show');
+            },
         })
     });
+    $('#sp-unlock').click(function(){
+        postData(window.location.pathname + '/load', { filter: 'auditLocked'}, function(result){
+            if (!result.auditLocked || result.auditLocked.length === 0) {
+                toastr.warning('暂无需要解锁的数据');
+                return;
+            }
+
+            spBackLock.showUnlocked({
+                tree: stageTree,
+                auditLocked: result.auditLocked,
+                callback: async function(auditLocked) {
+                    const newAuditLocked = await postDataAsync(window.location.pathname + '/unlock', { updateType: 'audit_locked_lid', updateData: auditLocked});
+                    if (newAuditLocked.length === 0) $('#sp-unlock').hide();
+                }
+            })
+        });
+    });
 });
 function makeOneShouFang(sf) {
     const lData = _.find(ledgerData, { id: sf.lid });

+ 1 - 0
app/router.js

@@ -813,6 +813,7 @@ module.exports = app => {
     app.get('/tender/:id/measure/stage/:order', sessionAuth, tenderCheck, subProjectCheck, uncheckTenderCheck, stageCheck, 'stageController.index');
     app.get('/tender/:id/stage/:order', sessionAuth, tenderCheck, subProjectCheck, uncheckTenderCheck, stageCheck, 'stageController.index');// 针对旧数据wap端跳转web问题
     app.post('/tender/:id/measure/stage/:order/load', sessionAuth, tenderCheck, subProjectCheck, uncheckTenderCheck, stageCheck, 'stageController.getStageData');
+    app.post('/tender/:id/measure/stage/:order/unlock', sessionAuth, tenderCheck, subProjectCheck, uncheckTenderCheck, stageCheck, 'stageController.unlock');
     app.post('/tender/:id/measure/stage/:order/pos', sessionAuth, tenderCheck, subProjectCheck, uncheckTenderCheck, stageCheck, 'stageController.getStagePosData');
     app.post('/tender/:id/measure/stage/:order/update', sessionAuth, tenderCheck, subProjectCheck, uncheckTenderCheck, stageCheck, 'stageController.updateStageData');
     app.post('/tender/:id/measure/stage/:order/valid-change', sessionAuth, tenderCheck, subProjectCheck, uncheckTenderCheck, stageCheck, 'stageController.searchValidChange');

+ 17 - 1
app/service/stage_audit.js

@@ -2388,7 +2388,23 @@ module.exports = app => {
         }
 
         async getAuditLockedId(stage) {
-            return await this.db.query(`SELECT * FROM ${this.tableName} where sid = ? and times = ? and audit_locked_lid <> '' and status <> ?`, [stage.id, stage.times, auditConst.status.checking]);
+            const sql = `SELECT sa.*, pa.name, pa.company, pa.role FROM ${this.tableName} sa LEFT JOIN ${this.ctx.service.projectAccount.tableName} pa ON sa.aid = pa.id` +
+                " WHERE sid = ? AND times = ? AND audit_locked_lid <> '' AND status <> ?";
+            return await this.db.query(sql, [stage.id, stage.times, auditConst.status.checking]);
+        }
+
+        async updateUnlockLid(stage, data) {
+            const updateData = [];
+            for (const d of data) {
+                if (!stage.auditLocked.find(x => {return x.id === d.id; })) continue;
+                updateData.push({ id: d.id, audit_locked_lid: d.audit_locked_lid });
+            }
+            if (updateData.length > 0) {
+                await this.db.updateRows(this.tableName, updateData);
+                return this.getAuditLockedId(stage);
+            } else {
+                return stage.auditLocked;
+            }
         }
 
         /**

+ 8 - 0
app/view/stage/audit_btn.ejs

@@ -54,6 +54,14 @@
     <% if (ctx.stage.user_id === ctx.session.sessionUser.accountId && ctx.stage.order === ctx.stage.highOrder && (ctx.stage.status === auditConst.status.checkNo || ctx.stage.status === auditConst.status.uncheck)) { %>
         <a href="#del-qi" data-toggle="modal" data-target="#del-qi" class="btn btn-outline-danger btn-sm btn-block mt-5">删除本期</a>
     <% } %>
+    <% if (ctx.stage.auditLocked && ctx.stage.auditLocked.length > 0) { %>
+        <% if (ctx.session.sessionUser.is_admin) { %>
+            <button class="btn btn-outline-danger btn-sm btn-block mt-5" id="sp-unlock-list">解锁</button>
+        <% } %>
+        <% if (ctx.stage.auditLocked.find(x => { return x.aid === ctx.session.sessionUser.accountId; })) { %>
+            <button class="btn btn-outline-danger btn-sm btn-block mt-5" id="sp-unlock">解锁</button>
+        <% } %>
+    <% } %>
 </div>
 <script>
     $('.sp-list-btn').click(function () {