'use strict';
/**
*
*
* @author Mai
* @date 2018/10/11
* @version
*/
const tenderListSpec = (function(){
function getProgressHtml(total, pre, cur) {
if (total !== 0) {
let preP = ZhCalc.mul(ZhCalc.div(pre, total, 2), 100, 0);
let curP = ZhCalc.mul(ZhCalc.div(cur, total, 2), 100, 0);
let other = Math.max(ZhCalc.sub(ZhCalc.sub(total, pre), cur), 0);
let otherP = Math.max(100 - preP - curP, 0);
const html = '
' +
'
' + preP + '%
' +
'
' + curP + '%
' +
'
' + otherP + '%
' +
'
';
return html;
} else {
return '';
}
}
function getTenderNodeHtml(node, arr, pid) {
const html = [];
html.push('');
// 名称
html.push('');
if (node.cid) {
html.push(' ');
html.push((node.level === 1 ? '' : ''), node.name, (node.level === 1 ? '' : ''));
} else {
html.push('');
html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
html.push('');
//html.push('', node[c.field], '');
html.push('', node.name, '');
}
html.push(' | ');
// 计量进度
html.push('');
if (!node.cid && node.cur_flow) {
if (node.progress) {
html.push(node.progress.title + ' (' + '' + node.progress.status + '' + ')');
} else {
html.push(node.cur_flow.title + ' (' + '' + node.cur_flow.status + '' + ')');
}
}
html.push(' | ');
// 当前流程
html.push('');
if (!node.cid && node.cur_flow) {
const curUser = node.cur_flow instanceof Array && node.cur_flow[0].audit_type && node.cur_flow[0].audit_type !== auditType.key.common
? transFormToChinese(node.cur_flow[0].audit_order) + '审'
: node.cur_flow instanceof Array ? (node.cur_flow[0].name + (node.cur_flow[0].role ? '-'+node.cur_flow[0].role : '')): (node.cur_flow.name + (node.cur_flow.role ? '-'+node.cur_flow.role : ''));
if (node.stage_status !== undefined) {
html.push(((node.stage_count && node.stage_status === auditConst.stage.status.uncheck) || node.ledger_status === auditConst.ledger.status.uncheck)
? curUser
: `${curUser}`
);
html.push(`${node.progress.status}`);
} else {
html.push((node.lastStage && node.lastStage.status === auditConst.stage.status.uncheck) || (!node.lastStage && node.ledger_status === auditConst.ledger.status.uncheck ) ? '' :
'');
html.push(curUser);
html.push((node.lastStage && node.lastStage.status === auditConst.stage.status.uncheck) || (!node.lastStage && node.ledger_status === auditConst.ledger.status.uncheck ) ? ' ':
' ');
if (node.cur_flow instanceof Array) {
html.push('' + node.cur_flow[0].status + '');
} else {
html.push('' + node.cur_flow.status + '');
}
}
}
html.push(' | ');
// 上一流程审批时间
html.push('');
if (!node.cid && node.pre_flow) {
if (node.pre_flow instanceof Array) {
if (node.pre_flow.length > 1) {
html.push(transFormToChinese(node.pre_flow[0].audit_order) + '审' + ' ' + moment(node.pre_flow[0].time).format('YYYY-MM-DD'));
} else {
html.push(node.pre_flow[0].name + ' ' + moment(node.pre_flow[0].time).format('YYYY-MM-DD'));
}
} else {
html.push(node.pre_flow.name + ' ' + moment(node.pre_flow.time).format('YYYY-MM-DD'));
}
}
html.push(' | ');
// 签约合同价
html.push('');
html.push(node.contract_price ? node.contract_price : '');
html.push(' | ');
// 总价
html.push('');
html.push(node.sum_tp ? node.sum_tp : '');
html.push(' | ');
// 截止本期累计完成/本期完成/未完成
html.push('');
if (node.lastStage || node.stage_count > 0) {
html.push(getProgressHtml(node.sum_tp, node.pre_gather_tp, node.gather_tp));
} else {
html.push('');
}
html.push(' | ');
html.push('
');
return html.join('');
}
function getTenderTreeHeaderHtml() {
const html = [];
html.push('');
html.push('', '');
// html.push('', '');
html.push('', '标段名称', ' | ');
html.push('', '计量进度', ' | ');
html.push('', '当前流程', ' | ');
html.push('', '上一流程审批时间', ' | ');
html.push('', '签约合同价', ' | ');
html.push('', '总价 ', ' | ');
html.push('', '截止上期完成/本期完成/未完成', ' | ');
html.push('
', '');
return html.join('');
}
function calculateTender(tender) {
if (tender.stage_tp) {
tender.end_qc_tp = ZhCalc.sum([tender.stage_tp.pre_qc_tp, tender.stage_tp.qc_tp, tender.stage_tp.qc_pc_tp]);
tender.pre_gather_tp = ZhCalc.add(tender.stage_tp.pre_contract_tp, tender.stage_tp.pre_qc_tp);
tender.gather_tp = ZhCalc.sum([tender.stage_tp.contract_tp, tender.stage_tp.qc_tp, tender.stage_tp.pc_tp]);
tender.sum_tp = ZhCalc.add(tender.total_price, tender.end_qc_tp);
} else if (tender.lastStage) {
tender.end_qc_tp = ZhCalc.sum([tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp, tender.lastStage.qc_pc_tp]);
tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
tender.gather_tp = ZhCalc.sum([tender.lastStage.contract_tp, tender.lastStage.qc_tp, tender.lastStage.pc_tp]);
tender.sum_tp = ZhCalc.add(tender.total_price, tender.end_qc_tp);
} else {
tender.sum_tp = tender.total_price;
}
}
function calculateParent(node) {
if (node.children && node.cid) {
node.end_qc_tp = 0;
node.pre_gather_tp = 0;
node.gather_tp = 0;
node.sum_tp = 0;
node.lastStage = 0;
node.contract_price = 0;
node.stage_count = 0;
for (const c of node.children) {
calculateParent(c);
node.end_qc_tp = ZhCalc.add(node.end_qc_tp, c.end_qc_tp);
node.pre_gather_tp = ZhCalc.add(node.pre_gather_tp, c.pre_gather_tp);
node.gather_tp = ZhCalc.add(node.gather_tp, c.gather_tp);
node.sum_tp = ZhCalc.add(node.sum_tp, c.sum_tp);
node.lastStage = c.cid
? Math.max(node.lastStage, c.lastStage)
: (c.lastStage ? Math.max(node.lastStage, c.lastStage.order) : node.lastStage);
node.stage_count = c.cid ? Math.max(node.stage_count, c.stage_count) : (c.stage_count ? Math.max(node.stage_count, c.stage_count): node.stage_count);
node.contract_price = ZhCalc.add(node.contract_price, c.contract_price);
}
}
}
return { getTenderNodeHtml, getTenderTreeHeaderHtml, calculateTender, calculateParent }
})();