riku
3 小时以前 b09c7e7aefd41a62326ea56460092aa0db54c083
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import dayjs from 'dayjs';
import taskApi from '../../api/taskApi';
 
/**
 * 子任务列表模块
 */
export const useSubTaskItem = Behavior({
  data: {
    subTaskLoading: false,
    // 当日的子任务
    subtaskList: [],
  },
  methods: {
    statusType(status) {
      switch (status) {
        case '未执行':
          return {
            type: 'danger',
            icon: 'assignment-error-filled',
          };
        case '正在执行':
          return {
            type: 'success',
            icon: 'time',
          };
        case '已结束':
          return {
            type: '',
            icon: 'assignment-checked-filled',
          };
        default:
          return {
            type: 'danger',
            icon: 'assignment-error-filled',
          };
      }
    },
    /**
     * 获取子任务
     */
    fetchSubtaskByDayTask() {
      this.setData({ subTaskLoading: true });
      const { thisDate, daytasks } = this.data;
      const fdt = daytasks.find(d => {
        return dayjs(d.date).isSame(dayjs(thisDate), 'day');
      });
      if (fdt) {
        taskApi
          .fetchSubtaskByDayTask(fdt.guid)
          .then(res => {
            this.setData({
              subtaskList: res
                .sort((a, b) => {
                  if (a.sceneTypeId != b.sceneTypeId) {
                    return a.sceneTypeId - b.sceneTypeId;
                  } else {
                    return dayjs(b.executionstarttime).unix() - dayjs(a.executionstarttime).unix();
                  }
                })
                .map(stask => {
                  const changePerType = () => {
                    if (status.value.changeNum == 0) {
                      if (status.value.proNum == 0) {
                        return 'success';
                      } else {
                        return 'danger';
                      }
                    } else if (status.value.proNum == status.value.changeNum) {
                      return 'success';
                    } else {
                      return 'warning';
                    }
                  };
                  const timeformat = date => {
                    return date ? dayjs(date).format('YYYY-MM-DD HH:mm') : '----/--/-- --:--';
                  };
                  return {
                    ...stask,
                    startTime: timeformat(stask.executionstarttime),
                    endTime: timeformat(stask.executionendtime),
                    statusType: this.statusType(stask.status),
                  };
                }),
            });
          })
          .finally(() => this.setData({ subTaskLoading: false }));
      } else {
        this.setData({
          subtaskList: [],
          subTaskLoading: false,
        });
      }
    },
 
    /**
     * 点击子任务事件处理函数
     */
    handleItemClick(e) {
      const { index } = e.currentTarget.dataset;
      const { subtaskList } = this.data;
      const subtask = subtaskList[index];
      wx.navigateTo({
        url: '/package_supervision/pages/inspection/index',
        success: result => {
          result.eventChannel.emit('acceptSubTaskData', {
            subtask,
          });
        },
        events: {
          // 任务状态变更事件
          changeStatusEvent: data => {
            const { daytasks } = this.data;
            subtask.status = data?.subtask?.status;
            subtask.statusType = this.statusType(subtask.status);
            // 若任务结束,则更新日任务中的完成任务数量统计
            if (subtask.status == '已结束') {
              let _index;
              const daytask = daytasks.find((d, i) => {
                if (d.guid == subtask.tsguid) {
                  _index = i;
                  return true;
                }
              });
              daytask.completeTaskNum++;
              this.setData({
                [`daytasks[${_index}]`]: daytask,
              });
            }
            this.setData({
              [`subtaskList[${index}]`]: subtask,
            });
            this.selectThisDay();
 
          },
        },
      });
    },
  },
});