Forráskód Böngészése

删除标段和报错信息显示

laiguoran 6 éve
szülő
commit
4175c0c27d

+ 12 - 1
app/base/base_controller.js

@@ -52,9 +52,20 @@ class BaseController extends Controller {
     async layout(view, data = {}, modal = '') {
         data.moment = moment;
         // 获取消息提示
-        const message = this.ctx.session.message;
+        let message = this.ctx.session.message;
         // 取出后删除
         this.ctx.session.message = null;
+        // 获取报错信息
+        const postError = this.ctx.session.postError;
+        // 取出后删除
+        this.ctx.session.postError = null;
+        if (message === null && postError !== null) {
+            message = {
+                type: 'error',
+                icon: 'exclamation-circle',
+                message: postError,
+            };
+        }
 
         try {
             data.min = this.app.config.min;

+ 0 - 1
app/controller/stage_controller.js

@@ -747,7 +747,6 @@ module.exports = app => {
                 ctx.redirect(ctx.request.header.referer);
             } catch (err) {
                 this.log(err);
-                console.log(err);
                 ctx.session.postError = err.toString();
                 ctx.redirect(ctx.request.header.referer);
             }

+ 3 - 3
app/controller/tender_controller.js

@@ -31,9 +31,9 @@ module.exports = app => {
             ctx.showTitle = true;
         }
 
-        async _list(view, setting, modal = '') {
+        async _list(view, setting, modal = '', listStatus = '') {
             try {
-                const tenderList = await this.ctx.service.tender.getList();
+                const tenderList = await this.ctx.service.tender.getList(listStatus);
                 for (const t of tenderList) {
                     t.lastStage = await this.ctx.service.stage.getLastestStage(t.id, true);
                     t.completeStage = await this.ctx.service.stage.getLastestCompleteStage(t.id);
@@ -95,7 +95,7 @@ module.exports = app => {
             const userPermission = accountInfo !== undefined && accountInfo.permission !== '' ? JSON.parse(accountInfo.permission) : null;
             if (userPermission !== null && userPermission.tender !== undefined && userPermission.tender.indexOf('1') !== -1) {
                 this.jsFiles = this.app.jsFiles.tender.manage;
-                await this._list('tender/manage.ejs', tenderConst.manageTableCol, 'tender/manage_modal.ejs');
+                await this._list('tender/manage.ejs', tenderConst.manageTableCol, 'tender/manage_modal.ejs', 'manage');
             } else {
                 this.ctx.redirect('/dashboard');
             }

+ 3 - 3
app/public/js/tender_list_manage.js

@@ -259,9 +259,9 @@ function recursiveGetTenderNodeHtml (node, arr) {
     html.push('<td tid="' + node.id + '">');
     if (!node.cid) {
         html.push('<a href="#javascript: void(0)" name="edit" class="btn btn-outline-primary btn-sm">编辑</a>');
-        if (node.ledger_status === auditConst.ledger.status.uncheck) {
+        // if (node.ledger_status === auditConst.ledger.status.uncheck) {
             html.push('<a href="javascript: void(0)" name="del" class="btn btn-outline-danger btn-sm">删除</a>');
-        }
+        // }
     }
     html.push('</td>');
     html.push('</tr>');
@@ -472,4 +472,4 @@ $(document).ready(() => {
             $('#del-bd').modal('hide');
         }
     });
-});
+});

+ 1 - 1
app/service/stage_audit.js

@@ -176,7 +176,7 @@ module.exports = app => {
         async start(stageId, times = 1) {
             const audit = await this.getDataByCondition({sid: stageId, times: times, order: 1});
             if (!audit) {
-                throw '审核人信息错误';
+                throw '请先选择审批人,再上报数据';
             }
 
             const transaction = await this.db.beginTransaction();

+ 57 - 31
app/service/tender.js

@@ -10,6 +10,8 @@
 
 const tenderConst = require('../const/tender');
 const auditConst = require('../const/audit');
+const fs = require('fs');
+const path = require('path');
 const commonQueryColumns = ['id', 'project_id', 'name', 'status', 'category', 'ledger_times', 'ledger_status', 'measure_type', 'user_id'];
 
 module.exports = app => {
@@ -75,38 +77,50 @@ module.exports = app => {
          *
          * @return {Array} - 返回标段数据
          */
-        async getList() {
+        async getList(listStatus) {
             // 获取当前项目信息
             const session = this.ctx.session;
-            // tender 163条数据,project_account 68条数据测试
-            // 查询两张表耗时0.003s,查询tender左连接project_account耗时0.002s
-            const sql = 'SELECT t.`id`, t.`project_id`, t.`name`, t.`status`, t.`category`, t.`ledger_times`, t.`ledger_status`, t.`measure_type`, t.`user_id`, t.`create_time`, '+
-                        '    pa.`name` As `user_name`, pa.`role` As `user_role`, pa.`company` As `user_company` ' +
-                        // '  FROM ?? As t, ?? As pa ' +
-                        // '  WHERE t.`project_id` = ? AND t.`user_id` = pa.`id` AND (' +
-                        '  FROM ?? As t ' +
-                        '  Left Join ?? As pa ' +
-                        '  ON t.`user_id` = pa.`id` ' +
-                        '  WHERE t.`project_id` = ? AND (' +
-                        // 创建的标段
-                        '    t.`user_id` = ?' +
-                        // 参与审批 台账 的标段
-                        '    OR (t.`ledger_status` != ' + auditConst.ledger.status.uncheck + ' AND ' +
-                        '        t.id IN ( SELECT la.`tender_id` FROM ?? As la WHERE la.`audit_id` = ? GROUP BY la.`tender_id`))' +
-                        // 参与审批 计量期 的标段
-                        '    OR (t.`ledger_status` = ' + auditConst.ledger.status.checked + ' AND ' +
-                        '        t.id IN ( SELECT sa.`tid` FROM ?? As sa WHERE sa.`aid` = ? GROUP BY sa.`tid`))' +
-                        // 参与审批 变更令 的标段
-                        '    OR (t.`ledger_status` = ' + auditConst.ledger.status.checked + ' AND ' +
-                        '        t.id IN ( SELECT ca.`tid` FROM ?? AS ca WHERE ca.`uid` = ? GROUP BY ca.`tid`))' +
-                        // 未参与,但可见的标段
-                        ')';
-            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, session.sessionProject.id, session.sessionUser.accountId,
-            this.ctx.service.ledgerAudit.tableName, session.sessionUser.accountId,
-            this.ctx.service.stageAudit.tableName, session.sessionUser.accountId,
-            this.ctx.service.changeAudit.tableName, session.sessionUser.accountId];
-
-            //console.log(this.db.format(sql, sqlParam));
+            let sql = '';
+            let sqlParam = [];
+            if (listStatus === 'manage') {
+                // 管理页面只取属于自己创建的标段
+                sql = 'SELECT t.`id`, t.`project_id`, t.`name`, t.`status`, t.`category`, t.`ledger_times`, t.`ledger_status`, t.`measure_type`, t.`user_id`, t.`create_time`, ' +
+                    '    pa.`name` As `user_name`, pa.`role` As `user_role`, pa.`company` As `user_company` ' +
+                    '  FROM ?? As t ' +
+                    '  Left Join ?? As pa ' +
+                    '  ON t.`user_id` = pa.`id` ' +
+                    '  WHERE t.`project_id` = ? AND t.`user_id` = ?';
+                sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, session.sessionProject.id, session.sessionUser.accountId];
+            } else {
+                // tender 163条数据,project_account 68条数据测试
+                // 查询两张表耗时0.003s,查询tender左连接project_account耗时0.002s
+                sql = 'SELECT t.`id`, t.`project_id`, t.`name`, t.`status`, t.`category`, t.`ledger_times`, t.`ledger_status`, t.`measure_type`, t.`user_id`, t.`create_time`, ' +
+                    '    pa.`name` As `user_name`, pa.`role` As `user_role`, pa.`company` As `user_company` ' +
+                    // '  FROM ?? As t, ?? As pa ' +
+                    // '  WHERE t.`project_id` = ? AND t.`user_id` = pa.`id` AND (' +
+                    '  FROM ?? As t ' +
+                    '  Left Join ?? As pa ' +
+                    '  ON t.`user_id` = pa.`id` ' +
+                    '  WHERE t.`project_id` = ? AND (' +
+                    // 创建的标段
+                    '    t.`user_id` = ?' +
+                    // 参与审批 台账 的标段
+                    '    OR (t.`ledger_status` != ' + auditConst.ledger.status.uncheck + ' AND ' +
+                    '        t.id IN ( SELECT la.`tender_id` FROM ?? As la WHERE la.`audit_id` = ? GROUP BY la.`tender_id`))' +
+                    // 参与审批 计量期 的标段
+                    '    OR (t.`ledger_status` = ' + auditConst.ledger.status.checked + ' AND ' +
+                    '        t.id IN ( SELECT sa.`tid` FROM ?? As sa WHERE sa.`aid` = ? GROUP BY sa.`tid`))' +
+                    // 参与审批 变更令 的标段
+                    '    OR (t.`ledger_status` = ' + auditConst.ledger.status.checked + ' AND ' +
+                    '        t.id IN ( SELECT ca.`tid` FROM ?? AS ca WHERE ca.`uid` = ? GROUP BY ca.`tid`))' +
+                    // 未参与,但可见的标段
+                    ')';
+                sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, session.sessionProject.id, session.sessionUser.accountId,
+                    this.ctx.service.ledgerAudit.tableName, session.sessionUser.accountId,
+                    this.ctx.service.stageAudit.tableName, session.sessionUser.accountId,
+                    this.ctx.service.changeAudit.tableName, session.sessionUser.accountId];
+            }
+            // console.log(this.db.format(sql, sqlParam));
             const list = await this.db.query(sql, sqlParam);
             for (const l of list) {
                 l.category = l.category && l.category !== '' ? JSON.parse(l.category) : null;
@@ -239,6 +253,18 @@ module.exports = app => {
                 await transaction.delete(this.ctx.service.stagePos.tableName, {tid: id});
                 await transaction.delete(this.ctx.service.stageDetail.tableName, {tid: id});
                 //await transaction.delete(this.ctx.service.stagePay.tableName, {tid: id});
+                await transaction.delete(this.ctx.service.change.tableName, {tid: id});
+                await transaction.delete(this.ctx.service.changeAudit.tableName, {tid: id});
+                await transaction.delete(this.ctx.service.changeAuditList.tableName, {tid: id});
+                await transaction.delete(this.ctx.service.changeCompany.tableName, {tid: id});
+                // 先删除附件文件
+                const attList = await this.ctx.service.changeAtt.getAllDataByCondition({ where: { tid: id } });
+                if (attList.length !== 0) {
+                    for (const att of attList) {
+                        await fs.unlinkSync(path.join(this.app.baseDir, att.filepath));
+                    }
+                }
+                await transaction.delete(this.ctx.service.changeAtt.tableName, {tid: id});
                 await transaction.commit();
                 return true;
             } catch (err) {
@@ -288,4 +314,4 @@ module.exports = app => {
     }
 
     return Tender;
-};
+};

+ 1 - 1
app/view/stage/index.ejs

@@ -245,7 +245,7 @@
         </div>
     </div>
 </div>
-<img src="/public/images/ellipsis_horizontal.png" id="ellipsis-icon" />
+<!--<img src="/public/images/ellipsis_horizontal.png" id="ellipsis-icon" />-->
 <script>
     GC.Spread.Sheets.LicenseKey = "559432293813965#A0y3iTOzEDOzkjMyMDN9UTNiojIklkI1pjIEJCLi4TPB9mM5AFNTd4cvZ7SaJUVy3CWKtWYXx4VVhjMpp7dYNGdx2ia9sEVlZGOTh7NRlTUwkWR9wEV4gmbjBDZ4ElR8N7cGdHVvEWVBtCOwIGW0ZmeYVWVr3mI0IyUiwCMzETN8kzNzYTM0IicfJye&Qf35VfiEzRwEkI0IyQiwiIwEjL6ByUKBCZhVmcwNlI0IiTis7W0ICZyBlIsIyNyMzM5ADI5ADNwcTMwIjI0ICdyNkIsIibj9SbvNmL4N7bjRnch56ciojIz5GRiwiI8+Y9sWY9QmZ0Jyp96uL9v6L0wap9biY9qiq95q197Wr9g+89iojIh94Wiqi";
 </script>