import dayjs from 'dayjs';
|
import {
|
fetchSubtask,
|
fetchSubtaskSummary,
|
fetchProblems,
|
} from '../../../services/inspection/fetchInspection';
|
import { newBehavior } from '../../../behaviors/picker/basePicker';
|
|
const PICKER_NAME = 'subtask';
|
const useSubtaskPicker = newBehavior(PICKER_NAME, []);
|
|
/**
|
* 巡查监管任务详情
|
*/
|
export const useSubtask = Behavior({
|
behaviors: [useSubtaskPicker],
|
data: {
|
subTask: {},
|
problemList: [],
|
problemLoading: false,
|
},
|
methods: {
|
fetchSubtaskSummary() {
|
const { scene, year, startTime, endTime } = this.data;
|
const sceneId = scene.guid;
|
return fetchSubtaskSummary({ sceneId, startTime, endTime }).then(res => {
|
this.setData({ subtaskSummary: res });
|
if (res.length > 0) {
|
this.refreshSubtaskPicker();
|
}
|
this.refreshChart();
|
});
|
},
|
|
fetchSubtask(subtaskId) {
|
return fetchSubtask(subtaskId).then(res => {
|
this.setData({ subTask: res });
|
});
|
},
|
|
fetchProblems(subtaskId) {
|
this.setData({ problemLoading: true });
|
return fetchProblems(subtaskId, true)
|
.then(res => {
|
this.setData({ problemList: res });
|
})
|
.finally(() => this.setData({ problemLoading: false }));
|
},
|
|
/**
|
* 刷新巡查任务选择器
|
*/
|
refreshSubtaskPicker() {
|
const { time, subtaskSummary } = this.data;
|
const t1 = dayjs(time);
|
let index = 0;
|
let maxDay;
|
const optionList = subtaskSummary.map((item, i) => {
|
// 筛选与传入的时间相同月份中最新的一条巡查任务,作为默认展示的任务
|
const t2 = dayjs(item.stPlanTime);
|
if (t1.month() == t2.month()) {
|
if (maxDay) {
|
if (maxDay.isBefore(t2)) {
|
maxDay = t2;
|
index = i;
|
}
|
} else {
|
maxDay = t2;
|
index = i;
|
}
|
}
|
return {
|
label: t2.format('MM月DD日'),
|
value: item.stGuid,
|
};
|
});
|
this.setSelectOptions(PICKER_NAME, optionList, index);
|
if (optionList.length > 0) {
|
const subtaskId = optionList[index].value;
|
this.fetchSubtask(subtaskId);
|
this.fetchProblems(subtaskId);
|
}
|
},
|
|
_confirm(e) {
|
const { subtaskText, subtaskValue } = this.data;
|
this.fetchSubtask(subtaskValue[0]);
|
this.fetchProblems(subtaskValue[0]);
|
},
|
},
|
});
|