import { fetchProblemsStatistic } from '../../../services/inspection/fetchInspection'; export const useStatistic = Behavior({ data: { statistic: { proNum: 0, changeNum: 0, }, }, methods: { fetchProblems(params, page) { return fetchProblemsStatistic(params).then(res => { let proNum = 0, changeNum = 0, changePer = 0; res.data.forEach(r => { proNum += r.count; changeNum += r.changeCount; }); if (proNum > 0) { changePer = Math.round((changeNum / proNum) * 1000) / 10; changePer += '%'; } this.setData({ statistic: { proNum, changeNum, changePer }, }); return res.head; }); }, }, });