import { fetchProblemsStatistic } from '../../../services/inspection/fetchInspection'; /** * 问题复发分析 */ export const useRecurrence = Behavior({ data: { problemStatistic: [], summaryText: '', }, methods: { fetchProblemsStatistic() { const { startTime, endTime, scene } = this.data; const params = { starttime: startTime, endtime: endTime, sceneId: scene.guid, }; return fetchProblemsStatistic(params).then(res => { const problemStatistic = res.data.sort((a, b) => { return b.count - a.count; }); this.setData({ problemStatistic }); this.summaryAnalysis(); return res.head; }); }, summaryAnalysis() { const { problemStatistic, recentTimeText } = this.data; let summaryText = ''; if (problemStatistic.length == 0) { summaryText = `该场景${recentTimeText}无现场问题`; } else { let totalP = 0, totalC = 0; problemStatistic.forEach(p => { totalP += p.count; totalC += p.changeCount; }); const cPer = totalP == 0 ? '--' : Math.round((totalC / totalP) * 1000) / 10 + '%'; summaryText = `该场景${recentTimeText}共发现${problemStatistic.length}种类型问题,问题总计${totalP}个,整改率${cPer}`; } this.setData({ summaryText }); }, }, });