import { fetchSubtasksByProType } from '../../services/inspection/fetchInspection'; import { fetchScene } from '../../services/inspection/fetchScene'; import { fetchUserMap } from '../../services/usercenter/fetchUser'; import dayjs from 'dayjs'; import { toTime, toPeriod } from '../../utils/period'; /** * 监管问题分析统计相关信息逻辑 */ export const useAnalysis = Behavior({ data: { thisSubtasks: [], lastSubtasks: [], problemType: '', problemCount: 0, }, methods: { onChartClick(params) { const { name, value } = params; this.setData({ problemType: name, problemCount: value, }); if (name) { this.fetchSubTasks(); } }, fetchSubTasks(page) { const { problemType } = this.data; const params = this._getParamsArea(); // 本月统计 const f1 = fetchSubtasksByProType({ area: params, pType: problemType, }).then(res => { this.setData({ thisSubtasks: res.data }); return res.head; }); // 上月统计 params.starttime = dayjs(params.starttime).subtract(1, 'month').format('YYYY-MM-DD HH:mm:ss'); params.endtime = dayjs(params.endtime).subtract(1, 'month').format('YYYY-MM-DD HH:mm:ss'); const f2 = fetchSubtasksByProType({ area: params, pType: problemType, }).then(res => { this.setData({ lastSubtasks: res.data }); return res.head; }); // 统一获取 return Promise.all([f1, f2]).then(res => { return res[0]; }); }, fetchUserId(subtask) { return fetchUserMap(subtask.scenseid).then(res => { return res.tzUserId; }); }, navToDetail(e) { const { index } = e.currentTarget.dataset; const { inspection, sceneTypeText, sceneTypeValue, time } = this.data; const subtask = this.data.thisSubtasks[index]; // this.fetchUserId(subtask).then(userId => { // wx.navigateTo({ // url: '/pages/enterprise/detail/index', // success: result => { // result.eventChannel.emit('acceptEnterpriseData', { // subtask: subtask, // enterprise: { // id: userId, // name: subtask.scensename, // sceneType: sceneTypeText, // sceneTypeId: sceneTypeValue, // district: inspection.districtName, // }, // period: toPeriod(time), // }); // }, // }); // }); fetchScene(subtask.scenseid).then(res => { wx.navigateTo({ url: '/pages/inspection/detail/index', success: result => { result.eventChannel.emit('acceptInspectionDetailData', { scene: res, time: time, }); }, }); }); }, }, });