riku
2023-11-29 9b09d13712c0c005891450a3bf4b6d848ec0ff37
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// pages/mExtra/pSupervisiontask/pSupervisiontask.js
import bLoadingStatus from '../../../base/behaviors/bLoadingStatus'
import bLoadingToast from '../../../base/behaviors/bLoadingToast'
import {sceneTypes2} from '../../../data/sceneTypes'
import moment from '../../../utils/moment.min'
import $f from "../../../service/baserequest";
 
const taskservice = require('../../../service/taskservice')
 
Page({
  behaviors: [bLoadingStatus, bLoadingToast],
  /**
   * 页面的初始数据
   */
  data: {
    //场景类型
    sceneTypes: [],
    sIndex: 0,
    //总任务
    taskList: [],
    tIndex: 0,
 
    //子任务
    subTaskList: [[], []],
 
    //统计
    changedSubTask: 0,
    unChangedSubTask: 0,
 
    tabIndex: 0,
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      sceneTypes: sceneTypes2
    })
    this.getTopTask()
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
 
  },
 
  onShow() {
    this.refreshTopMargin()
  },
 
  onShareAppMessage(e) {
    console.log(e);
    if (e.from == 'button') {
      const i = e.target.dataset.index
      const subTask = this.data.subTaskList[this.data.tabIndex][i]
      console.log(subTask);
      let t = new Date()
      t = t.getTime()
      console.log(t);
      return {
        title: `[待整改]${subTask.sceneName}`,
        path: `/pages/mExtra/pSupervisionchange/pSupervisionchange?subTaskId=${subTask.stGuid}&time=${t}`,
        imageUrl: $f.baseIconUrl + 'res/change_icon.png'
      }
    }
  },
 
  /**
   * 动态刷新列表顶部外边距
   */
  refreshTopMargin() {
    let that = this;
    let query = this.createSelectorQuery().in(this); //必须要先创建一个查询
    query.select('.page__hd').boundingClientRect(function (rect) {
      that.setData({
        topMargin: rect.height + 'px'
      });
    }).exec();
  },
 
  /**
   * 获取总任务
   */
  getTopTask() {
    var that = this
    this.setData({loading: true})
    taskservice.getTopTask({
      success(data) {
        that.setData({
          taskList: data
        })
      },
      fail(err) {
        that.setData({
          taskList: []
        })
      },
      complete() {
        that.setData({
          loading: false
        })
      }
    })
  },
 
  /**
   * 获取总任务下的子任务统计
   */
  getSubTaskSummary() {
    var that = this
    this.setData({loading: true})
    const {sceneTypes, sIndex, taskList, tIndex} = this.data
    const topTaskId = taskList[tIndex].tguid
    const sceneTypeId = sceneTypes[sIndex].value
    taskservice.getSubTaskSummary(topTaskId, sceneTypeId, {
      success(data) {
        data.sort((a, b) => {
          return moment(b.stPlanTime).diff(moment(a.stPlanTime))
        })
        const subTaskList = [[], []]
        let changedSubTask = 0
        let unChangedSubTask = 0
        data.forEach(d => {
          d.stPlanTime = moment(d.stPlanTime).format('YYYY年MM月DD日')
          if (d.proNum > 0 && d.proNum > d.changeNum) {
            subTaskList[0].push(d)
            unChangedSubTask++
          } else {
            subTaskList[1].push(d)
            changedSubTask++
          }
        });
        that.setData({subTaskList, unChangedSubTask, changedSubTask})
      },
      fail(err) {
        that.setData({
          subTaskList: [[], []]
        })
      },
      complete() {
        that.setData({
          loading: false
        })
      }
    })
  },
 
  selectTab(e) {
    let i = e.currentTarget.dataset.index
    this.setData({
      tabIndex: i,
    })
  },
 
  bindTaskChange(e) {
    let t = e.detail.value
    this.setData({
      tIndex: t,
    })
  },
 
  bindSceneTypeChange(e) {
    let s = e.detail.value
    this.setData({
      sIndex: s,
    })
  }
})