|
@@ -9,6 +9,13 @@
|
|
|
*/
|
|
|
|
|
|
const auditConst = require('../const/audit');
|
|
|
+const shenpiConst = require('../const/shenpi');
|
|
|
+
|
|
|
+const tenderConst = require('../const/tender');
|
|
|
+const measureType = tenderConst.measureType;
|
|
|
+
|
|
|
+const spreadConst = require('../const/spread');
|
|
|
+const spreadSetting = require('../lib/spread_setting');
|
|
|
|
|
|
module.exports = app => {
|
|
|
|
|
@@ -41,6 +48,18 @@ module.exports = app => {
|
|
|
auditType: auditConst.auditType,
|
|
|
};
|
|
|
renderData.settles = await ctx.service.settle.getValidSettles(ctx.tender.id);
|
|
|
+ for (const s of renderData.settles) {
|
|
|
+ if (s.status === auditConst.settle.status.uncheck) {
|
|
|
+ s.curAuditors = [];
|
|
|
+ } else if (s.status === auditConst.settle.status.checkNo) {
|
|
|
+ s.curAuditors = await ctx.service.settleAudit.getAuditorsByStatus(sid, s.status, s.times - 1);
|
|
|
+ } else {
|
|
|
+ s.curAuditors = await ctx.service.settleAudit.getAuditorsByStatus(s.id, s.status, s.times);
|
|
|
+ }
|
|
|
+ if (s.status === auditConst.settle.status.checkNoPre) {
|
|
|
+ s.curAuditorsPre = await ctx.service.stageAudit.getAuditorsByStatus(s.id, auditConst.settle.status.checking, s.times);
|
|
|
+ }
|
|
|
+ }
|
|
|
renderData.checkedStageCount = await ctx.service.stage.count({ tid: ctx.tender.id, status: auditConst.stage.status.checked });
|
|
|
await this.layout('settle/list.ejs', renderData, 'settle/list_modal.ejs');
|
|
|
} catch (err) {
|
|
@@ -128,9 +147,98 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async _getDefaultRenderData(ctx) {
|
|
|
+ const data = {
|
|
|
+ tender: ctx.tender.data,
|
|
|
+ tenderMenu: JSON.parse(JSON.stringify(this.menu.settleMenu)),
|
|
|
+ auditConst: auditConst.settle,
|
|
|
+ measureType,
|
|
|
+ preUrl: '/tender/' + ctx.tender.id + '/settle/' + ctx.params.sorder,
|
|
|
+ settle: ctx.settle,
|
|
|
+ shenpiConst,
|
|
|
+ auditType: auditConst.auditType,
|
|
|
+ };
|
|
|
+ data.tenderMenu.back.children[0].url = '/tender/' + ctx.tender.id + '/measure/stage';
|
|
|
+ // 是否已验证手机短信
|
|
|
+ const pa = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
|
|
|
+ data.authMobile = pa.auth_mobile;
|
|
|
+
|
|
|
+ const loadAccount = ctx.session.sessionUser.is_admin
|
|
|
+ ? true
|
|
|
+ : ctx.session.sessionUser.accountId === ctx.settle.user_id && ([auditConst.settle.status.uncheck, auditConst.settle.status.checkNo].indexOf(ctx.settle.audit_status) >= 0);
|
|
|
+ if (!loadAccount) return data;
|
|
|
+
|
|
|
+ // 获取所有项目参与者
|
|
|
+ const accountList = await ctx.service.projectAccount.getAllDataByCondition({
|
|
|
+ where: { project_id: ctx.session.sessionProject.id, enable: 1 },
|
|
|
+ columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
|
|
|
+ });
|
|
|
+ data.accountList = accountList;
|
|
|
+ const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
|
|
|
+ data.accountGroup = unitList.map(item => {
|
|
|
+ const groupList = accountList.filter(item1 => item1.company === item.name);
|
|
|
+ return { groupName: item.name, groupList };
|
|
|
+ });
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
async index(ctx) {
|
|
|
- await ctx.service.stage.loadStageAuditViewData(ctx.stage);
|
|
|
+ try {
|
|
|
+ await ctx.service.settle.loadAuditViewData(ctx.settle);
|
|
|
+ const renderData = await this._getDefaultRenderData(ctx);
|
|
|
+
|
|
|
+ const projectFunInfo = await this.ctx.service.project.getFunRela(ctx.session.sessionProject.id);
|
|
|
+ renderData.minusNoValue = projectFunInfo.minusNoValue && ctx.tender.info.fun_rela.stage_change.minusNoValue;
|
|
|
+ [renderData.ledgerSpread, renderData.posSpread] = await spreadSetting.getStageSpreadSetting(ctx, ctx.tender.id,
|
|
|
+ this.ctx.stage.readOnly || this.ctx.stage.revising, {minusNoValue: renderData.minusNoValue});
|
|
|
+ renderData.whiteList = this.ctx.app.config.multipart.whitelist;
|
|
|
+ await this.layout('settle/index.ejs', renderData, 'settle/modal.ejs');
|
|
|
+ } catch(err) {
|
|
|
+ ctx.log(err);
|
|
|
+ ctx.redirect('/tender/' + ctx.tender.id + '/settle');
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ async _loadSettleDataByKey(ctx, key, hpack) {
|
|
|
+ switch (key) {
|
|
|
+ case 'stageBills':
|
|
|
+ if (!ctx.settle.latestStage) ctx.settle.latestStage = await this.ctx.service.stage.getLastestCompleteStage(ctx.tender.id);
|
|
|
+ const bills = await this._getStageBillsData(ctx);
|
|
|
+ return hpack ? [this.ctx.helper.hpackArr(bills), 'stageBills'] : [bills, ''];
|
|
|
+ case 'stagePos':
|
|
|
+ if (!ctx.settle.latestStage) ctx.settle.latestStage = await this.ctx.service.stage.getLastestCompleteStage(ctx.tender.id);
|
|
|
+ const pos = await this._getStagePosData(ctx);
|
|
|
+ return hpack ? [this.ctx.helper.hpackArr(pos), 'stagePos'] : [pos, ''];
|
|
|
+ case 'settleBills':
|
|
|
+ return ctx.service.settleBills.getAllDataByCondition({ where: { settle_id: ctx.settle.id } });
|
|
|
+ case 'settlePos':
|
|
|
+ return ctx.service.settlePos.getAllDataByCondition({ where: { settle_id: ctx.settle.id } });
|
|
|
+ case 'settleSelect':
|
|
|
+ return ctx.service.settleSelect.getAllDataByCondition({ where: { settle_id: ctx.settle.id } });
|
|
|
+ break;
|
|
|
+ case 'tag':
|
|
|
+ return await ctx.service.ledgerTag.getDatas(ctx.tender.id, ctx.stage.id, ctx.settle.id);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async loadSettleData(ctx) {
|
|
|
+ try {
|
|
|
+ const data = JSON.parse(ctx.request.body.data);
|
|
|
+ const filter = data.filter.split(';');
|
|
|
+ const responseData = { err: 0, msg: '', data: {}, hpack: [] };
|
|
|
+ const hpack = true;
|
|
|
+ for (const f of filter) {
|
|
|
+ const [relaData, hpackKey] = await this._loadSettleDataByKey(f, hpack);
|
|
|
+ responseData.data[f] = relaData;
|
|
|
+ if (hpackKey) responseData.hpack.push(hpackKey);
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx.body = responseData;
|
|
|
+ } catch (err) {
|
|
|
+ this.log(err);
|
|
|
+ ctx.body = { err: 1, msg: err.toString(), data: null };
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|