123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- 'use strict';
- /**
- * 标段对比 控制器
- *
- * @author Mai
- * @date 2020/2/21
- * @version
- */
- const measureType = require('../const/tender').measureType;
- const status = require('../const/audit').stage.status;
- module.exports = app => {
- class SpssController extends app.BaseController {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局context
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- ctx.showProject = true;
- }
- async _getTzData(tid, includePos = false) {
- const tender = await this.ctx.service.tender.getTender(tid);
- if (!tender || tender.project_id !== this.ctx.session.sessionProject.id) {
- throw '不存在该标段';
- }
- const bills = await this.ctx.service.ledger.getData(tid);
- const pos = tender.measure_type === measureType.tz.value || includePos
- ? await this.ctx.service.pos.getPosData({tid: tid})
- : [];
- return { id: tid, name: tender.name, bills: bills, pos: pos };
- }
- async _checkStage(tid, sorder) {
- const _ = this.ctx.helper._;
- const stage = await this.service.stage.getDataByCondition({ tid: tid, order: sorder });
- if (!stage) throw '期数据错误';
- // 读取原报、审核人数据
- stage.auditors = await this.service.stageAudit.getAuditors(stage.id, stage.times);
- stage.curAuditor = await this.service.stageAudit.getCurAuditor(stage.id, stage.times);
- const accountId = this.ctx.session.sessionUser.accountId, auditorIds = _.map(stage.auditors, 'aid'), shareIds = [];
- const permission = this.ctx.session.sessionUser.permission;
- if (accountId === stage.user_id) { // 原报
- stage.curTimes = stage.times;
- if (stage.status === status.uncheck || stage.status === status.checkNo) {
- stage.curOrder = 0;
- } else if (stage.status === status.checked) {
- stage.curOrder = _.max(_.map(stage.auditors, 'order'));
- } else {
- stage.curOrder = stage.curAuditor.aid === accountId ? stage.curAuditor.order : stage.curAuditor.order - 1;
- }
- } else if (auditorIds.indexOf(accountId) !== -1) { // 审批人
- if (stage.status === status.uncheck) {
- throw '您无权查看该数据';
- }
- stage.curTimes = stage.status === status.checkNo ? stage.times - 1 : stage.times;
- if (stage.status === status.checked) {
- stage.curOrder = _.max(_.map(stage.auditors, 'order'));
- } else if (stage.status === status.checkNo) {
- const audit = await this.service.stageAudit.getDataByCondition({
- sid: stage.id, times: stage.times - 1, status: status.checkNo
- });
- stage.curOrder = audit.order;
- } else {
- stage.curOrder = accountId === stage.curAuditor.aid ? stage.curAuditor.order : stage.curAuditor.order - 1;
- }
- } else if (shareIds.indexOf(accountId) !== -1 || (permission !== null && permission.tender !== undefined && permission.tender.indexOf('2') !== -1)) { // 分享人
- if (stage.status === status.uncheck) {
- throw '您无权查看该数据';
- }
- stage.curTimes = stage.status === status.checkNo ? stage.times - 1 : stage.times;
- stage.curOrder = stage.status === status.checked ? _.max(_.map(stage.auditors, 'order')) : stage.curAuditor.order - 1;
- } else { // 其他不可见
- throw '您无权查看该数据';
- }
- return stage;
- }
- async _getStageData(tid, sorder) {
- const data = await this._getTzData(tid, true);
- const stage = await this._checkStage(tid, sorder);
- const bills = await this.ctx.service.stageBills.getAuditorStageData2(tid, stage.id, stage.curTimes, stage.curOrder);
- const pos = await this.ctx.service.stagePos.getAuditorStageData(tid, stage.id, stage.curTimes, stage.curOrder);
- data.stage = {
- sid: stage.id, sorder: stage.order, curTimes: stage.curTimes, curOrder: stage.curOrder,
- bills: bills, pos: pos
- };
- return data;
- }
- /**
- * 台账 对比 页面
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- async compareTz(ctx) {
- try {
- const renderData = {
- jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.compare.tz)
- };
- await this.layout('spss/compare_tz.ejs', renderData, 'spss/compare_tz_modal.ejs');
- } catch (err) {
- ctx.helper.log(err);
- }
- }
- /**
- * 获取 台账 对比 数据(Ajax)
- * @param ctx
- * @returns {Promise<void>}
- */
- async loadCompareTz(ctx) {
- try {
- const data = JSON.parse(ctx.request.body.data);
- const responseData = {err: 0, msg: '', data: {}};
- // const tender1 = await ctx.service.tender.getTender(data.tid1);
- // responseData.data.tender1 = {
- // name: tender1.name,
- // bills: await ctx.service.ledger.getData(data.tid1),
- // pos: tender1.measure_type === measureType.tz.value
- // ? await ctx.service.pos.getPosData({tid: data.tid1}) : []
- // };
- // const tender2 = await ctx.service.tender.getTender(data.tid2);
- // responseData.data.tender2 = {
- // name: tender2.name,
- // bills: await ctx.service.ledger.getData(data.tid2),
- // pos: tender2.measure_type === measureType.tz.value
- // ? await ctx.service.pos.getPosData({tid: data.tid2}) : []
- // };
- responseData.data.tender1 = await this._getTzData(data.tid1);
- responseData.data.tender2 = await this._getTzData(data.tid2);
- ctx.body = responseData;
- } catch (err) {
- ctx.helper.log(err);
- ctx.body = this.ajaxErrorBody(err, '查询数据错误');
- }
- }
- /**
- * 期计量 对比 页面
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- async compareStage(ctx) {
- try {
- const renderData = {
- jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.compare.stage)
- };
- await this.layout('spss/compare_tz.ejs', renderData, 'spss/compare_stage_modal.ejs');
- } catch (err) {
- ctx.helper.log(err);
- }
- }
- /**
- * 获取 期计量 对比 数据(Ajax)
- * @param ctx
- * @returns {Promise<void>}
- */
- async loadCompareStage(ctx) {
- try {
- const data = JSON.parse(ctx.request.body.data);
- const responseData = {err: 0, msg: '', data: {}};
- responseData.data.tender1 = await this._getStageData(data.tid1, data.sorder1);
- responseData.data.tender2 = await this._getStageData(data.tid2, data.sorder2);
- ctx.body = responseData;
- } catch (err) {
- ctx.helper.log(err);
- ctx.body = this.ajaxErrorBody(err, '查询数据错误');
- }
- }
- /**
- * 台账 汇总 页面
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- async gatherTz(ctx) {
- try {
- const renderData = {
- jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.gather.tz)
- };
- await this.layout('spss/compare_tz.ejs', renderData, 'spss/gather_tz_modal.ejs');
- } catch (err) {
- ctx.helper.log(err);
- }
- }
- /**
- * 获取 台账 汇总 数据(Ajax)
- * @param ctx
- * @returns {Promise<void>}
- */
- async loadGatherTz(ctx) {
- try {
- const data = JSON.parse(ctx.request.body.data);
- const responseData = {err: 0, msg: '', data: []};
- for (const t of data.tenders) {
- responseData.data.push(await this._getTzData(t.id));
- }
- ctx.body = responseData;
- } catch (err) {
- ctx.helper.log(err);
- ctx.body = this.ajaxErrorBody(err, '查询数据错误');
- }
- }
- /**
- * 期计量 汇总 页面
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- async gatherStage(ctx) {
- try {
- const renderData = {
- jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.gather.stage)
- };
- await this.layout('spss/compare_tz.ejs', renderData, 'spss/gather_stage_modal.ejs');
- } catch (err) {
- ctx.helper.log(err);
- }
- }
- /**
- * 获取 期计量 汇总 数据(Ajax)
- * @param ctx
- * @returns {Promise<void>}
- */
- async loadGatherStage(ctx) {
- try {
- const data = JSON.parse(ctx.request.body.data);
- const responseData = {err: 0, msg: '', data: []};
- for (const t of data.tenders) {
- responseData.data.push(await this._getStageData(t.id, t.sorder));
- }
- ctx.body = responseData;
- } catch (err) {
- ctx.helper.log(err);
- ctx.body = this.ajaxErrorBody(err, '查询数据错误');
- }
- }
- /**
- * 检测台账 页面
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- async checkTz(ctx) {
- try {
- const renderData = {
- jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.tools.checkTz)
- };
- await this.layout('spss/check_tz.ejs', renderData);
- } catch (err) {
- ctx.helper.log(err);
- }
- }
- /**
- * 获取 期计量 汇总 数据(Ajax)
- * @param ctx
- * @returns {Promise<void>}
- */
- async loadBaseData(ctx) {
- try {
- const data = JSON.parse(ctx.request.body.data);
- const responseData = {err: 0, msg: '', data: []};
- responseData.data = await this._getTzData(data.id);
- ctx.body = responseData;
- } catch (err) {
- ctx.helper.log(err);
- ctx.body = this.ajaxErrorBody(err, '查询数据错误');
- }
- }
- }
- return SpssController;
- };
|