const moment = require('../utils/moment.min');
|
const app = getApp();
|
const DEADLINEDAY = app.globalData.userSetting.ledgerDeadline;
|
|
function name(params) {
|
let monthInfo = {
|
totalMust: 0,
|
finishedMust: 0,
|
totalSelf: 0,
|
finishedSelf: 0,
|
totalSelect: 0,
|
finishedSelect: 0,
|
status: '',
|
overtime: '',
|
suggestion: '',
|
};
|
let map = new Map();
|
subtypes.forEach(s => {
|
//月度统计
|
if (s.ledgerTypeId == -1) {
|
monthInfo.totalSelf++;
|
if (s.upLoad) {
|
monthInfo.finishedSelf++;
|
}
|
} else {
|
if (s.needUpdate) {
|
monthInfo.totalMust++;
|
if (s.upLoad) {
|
monthInfo.finishedMust++;
|
}
|
} else {
|
monthInfo.totalSelect++;
|
if (s.upLoad) {
|
monthInfo.finishedSelect++;
|
}
|
}
|
}
|
|
refreshLedgerStatus(s);
|
|
if (!map.has(s.ledgerType)) {
|
map.set(s.ledgerType, []);
|
}
|
map.get(s.ledgerType).push(s);
|
});
|
|
//
|
if (monthInfo.finishedMust + monthInfo.finishedSelf == 0) {
|
monthInfo.status = '未提交';
|
if (lastMonth) {
|
monthInfo.suggestion =
|
'建议:当期台账完全未提交,严重影响评估结果,后续请注意';
|
} else {
|
monthInfo.suggestion = '建议:请尽快提交台账';
|
}
|
} else if (
|
monthInfo.finishedMust + monthInfo.finishedSelf <
|
monthInfo.totalMust + monthInfo.totalSelf
|
) {
|
monthInfo.status = '部分提交';
|
if (lastMonth) {
|
monthInfo.suggestion =
|
'建议:当期台账部分未提交,会影响评估结果,后续请尽量提交所有台账';
|
} else {
|
monthInfo.suggestion = '建议:当前已提交部分台账,请补全剩余台账';
|
}
|
} else {
|
monthInfo.status = '已提交';
|
if (lastMonth) {
|
monthInfo.suggestion = '当期台账已全部提交,请保持';
|
} else {
|
monthInfo.suggestion = '本期台账已全部提交';
|
}
|
}
|
monthInfo.overtime = moment().date() - DEADLINEDAY;
|
monthInfo.percent =
|
monthInfo.totalMust == 0
|
? 0
|
: Math.round((monthInfo.finishedMust / monthInfo.totalMust) * 100);
|
monthInfo.percent2 =
|
monthInfo.totalSelf == 0
|
? 0
|
: Math.round((monthInfo.finishedSelf / monthInfo.totalSelf) * 100);
|
|
//选项卡
|
var t = [];
|
var p = [];
|
var tSelf = [];
|
var pSelf = [];
|
for (let item of map) {
|
let notUpload = 0;
|
item[1].forEach(l => {
|
if (l.needUpdate && !l.upLoad) {
|
notUpload++;
|
}
|
});
|
t.push({
|
name: item[0],
|
tag: notUpload,
|
total: item[1].length,
|
});
|
p.push(item[1]);
|
}
|
|
return { types: t, items: p, monthInfo };
|
}
|
|
/**
|
* 对台账或自巡查进行统计,类型ledgerTypeId为-1的是自巡查,其余为台账
|
* @param {Array} subtypes 台账记录
|
* @param {Boolean} isSelfPatrol 是否统计自巡查类型
|
*/
|
function _parse(subtypes, isSelfPatrol) {
|
// 月度统计
|
let monthInfo = {
|
// 全部必填数
|
totalMust: 0,
|
// 完成必填数
|
finishedMust: 0,
|
// 必填完成百分比
|
percent: 0,
|
// 全部选填数
|
totalSelect: 0,
|
// 完成选填数
|
finishedSelect: 0,
|
// 提交状态:未提交 | 部分提交 | 已提交
|
status: '',
|
// 逾期天数
|
overtime: '',
|
// 建议
|
suggestion: '',
|
};
|
let map = new Map();
|
for (let i = 0; i < subtypes.length; i++) {
|
const s = subtypes[i];
|
// 统计自巡查时,过滤普通台账
|
if (isSelfPatrol && s.ledgerTypeId != -1) continue;
|
// 统计台账时,过滤自巡查
|
if (!isSelfPatrol && s.ledgerTypeId == -1) continue;
|
// 分别统计必填和选填的完成情况
|
if (s.needUpdate) {
|
monthInfo.totalMust++;
|
if (s.upLoad) monthInfo.finishedMust++;
|
} else {
|
monthInfo.totalSelect++;
|
if (s.upLoad) monthInfo.finishedSelect++;
|
}
|
refreshLedgerStatus(s);
|
if (!map.has(s.ledgerType)) map.set(s.ledgerType, []);
|
map.get(s.ledgerType).push(s);
|
}
|
|
//
|
if (monthInfo.finishedMust + monthInfo.finishedSelf == 0) {
|
monthInfo.status = '未提交';
|
monthInfo.suggestion = '台账完全未提交,将严重影响评估结果';
|
} else if (monthInfo.finishedMust < monthInfo.totalMust) {
|
monthInfo.status = '部分提交';
|
monthInfo.suggestion = '台账部分未提交,会影响评估结果';
|
} else {
|
monthInfo.status = '已提交';
|
monthInfo.suggestion = '台账已全部提交';
|
}
|
monthInfo.overtime = moment().date() - DEADLINEDAY;
|
monthInfo.percent =
|
monthInfo.totalMust == 0
|
? 0
|
: Math.round((monthInfo.finishedMust / monthInfo.totalMust) * 100);
|
|
//选项卡
|
var t = [];
|
var p = [];
|
for (let item of map) {
|
let notUpload = 0;
|
item[1].forEach(l => {
|
if (l.needUpdate && !l.upLoad) {
|
notUpload++;
|
}
|
});
|
t.push({
|
name: item[0],
|
tag: notUpload,
|
total: item[1].length,
|
});
|
p.push(item[1]);
|
}
|
|
return { types: t, items: p, monthInfo };
|
}
|
// 统计台账上传情况
|
function parseLedgerStat(subtypes) {
|
return _parse(subtypes);
|
}
|
|
// 统计自巡查上传情况
|
function parseSelfPatrol(subtypes) {
|
return _parse(subtypes, true);
|
}
|
|
function refreshLedgerStatus(s) {
|
// if (s.ledgerFinished) {
|
// s.badge = {
|
// color: 'yellow',
|
// count: '!',
|
// };
|
// s.opacity = 1;
|
// }
|
if (!s.needUpdate) {
|
s.badge = {
|
color: '#00500079',
|
count: '选填',
|
shape: 'bubble',
|
};
|
s.opacity = 1;
|
} else {
|
s.badge = {
|
color: 'ff00005d',
|
count: '必填',
|
shape: 'bubble',
|
};
|
s.opacity = 1;
|
}
|
if (s.upLoad) {
|
s.badge.color = 'gray';
|
// s.badge.count += '✓';
|
s.opacity = 0.4;
|
}
|
}
|
|
export { parseLedgerStat, parseSelfPatrol, refreshLedgerStatus };
|