riku
2022-08-09 87f6bb4bcb2446b9c9065b58391ae400cd358b77
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// pages/grade/grade.js
const assessmentService = require("../../service/assessmentservice")
const moment = require('../../utils/moment.min')
const app = getApp()
 
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    // {
    //   title1: '在线监测设备',
    //   sub1: [{
    //     title2: '设备',
    //     group: 0,
    //     sub2: [{
    //         content: '设备未安装',
    //         score: '-10',
    //         select: false
    //       },
    //       {
    //         content: '设备私自拆除',
    //         score: '-10',
    //         select: false
    //       },
    //       {
    //         content: '设备未运行',
    //         score: '-10',
    //         select: false
    //       }, {
    //         content: '设备未运维',
    //         score: '-10',
    //         select: false
    //       }
    //     ]
    //   }, {
    //     title2: '数据',
    //     group: 1,
    //     sub2: [{
    //         content: '数据未超标',
    //         score: '-10',
    //         select: false
    //       },
    //       {
    //         content: '数据部分超标',
    //         score: '-10',
    //         select: false
    //       },
    //       {
    //         content: '数据大量超标',
    //         score: '-10',
    //         select: false
    //       }, {
    //         content: '数据严重超标',
    //         score: '-10',
    //         select: false
    //       }
    //     ]
    //   }],
    // }
    evaluations: []
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getScoreHistory()
  },
 
  /**
   * 获取本期的评估规则及记录
   */
  getScoreHistory() {
    var that = this
    let now = moment()
    //根据当前时间获取评估周期YYYY/M-M
    this.period = `${now.year()}/${now.month()+1}-${now.month()+1}`
    assessmentService.getScore(app.globalData.accessToken.userId, this.period, {
      success(data) {
        that.setData({
          evaluations: data
        })
      }
    })
  },
 
  choose: function (e) {
    var index = e.currentTarget.dataset.index
    var group = e.currentTarget.dataset.group
    var evaluations = this.data.evaluations
    for (let i = 0; i < evaluations.length; i++) {
      const e1 = evaluations[i];
      var found = false
      for (let y = 0; y < e1.sub1.length; y++) {
        const e2 = e1.sub1[y];
        if (e2.group == group) {
          e2.sub2.forEach(s2 => {
            s2.select = false
          });
          e2.sub2[index].select = true
          found = true
          break
        }
      }
      if (found) {
        break
      }
    }
 
    this.setData({
      evaluations: evaluations
    })
  },
 
  onSubmit: function () {
    var itemList = []
    var evaluations = this.data.evaluations
    for (let i = 0; i < evaluations.length; i++) {
      const e1 = evaluations[i];
      for (let y = 0; y < e1.sub1.length; y++) {
        const e2 = e1.sub1[y];
        for (let t = 0; t < e2.sub2.length; t++) {
          const s2 = e2.sub2[t];
          if (s2.select) {
            itemList.push({
              first: s2.id,
              second: s2.score + ''
            })
          }
        }
      }
    }
 
    if (itemList.length == 0) {
      wx.showToast({
        title: '请至少选择一项进行评估',
        icon: 'none',
      })
    } else {
      this.setData({
        itemList: itemList,
        showDialog: true,
        startCalculate: false
      })
    }
  },
 
  upload: function () {
    var that = this
    this.setData({
      showDialog: false,
      showDialog2: true,
      startCalculate: true,
      loadingOverText: ''
    })
 
    this.loadingText("计算总分中", function () {
      that.setData({
        loadingOverText: ['计算总分完成']
      })
      that.loadingText('等级评估中', function () {
        that.setData({
          loadingOverText: ['计算总分完成', '等级评估完成']
        })
        var h = that.loadingText('生成综合测评报告', function () {
          that.setData({
            loadingText: '',
            loadingOverText: ['计算总分完成', '等级评估完成', '综合测评报告生成失败']
          })
        }, 25)
        assessmentService.uploadScore(app.globalData.accessToken.userId, that.period, that.data.itemList, {
          success(data) {
            clearInterval(h)
            that.setData({
              startCalculate: false,
              loadingText: '',
              loadingOverText: ['计算总分完成', '等级评估完成', '综合测评报告生成']
            })
          }
        })
      })
    })
  },
 
  gotoReport() {
    this.setData({
      showDialog2: false,
    })
    wx.redirectTo({
      url: '/pages/gradereport/gradereport'
    })
  },
 
  goBack() {
    this.setData({
      showDialog2: false,
    })
    wx.navigateBack({
      delta: 1,
    })
  },
 
  loadingText(text, onDone, max) {
    var i = 0
    if (max == undefined) {
      max = 5
    }
    var h = setInterval(() => {
      if (i > max) {
        clearInterval(h)
        onDone()
      } else {
        var points = ''
        var n = i % 3
        for (let t = 0; t < n + 1; t++) {
          points += '.'
        }
        this.setData({
          loadingText: text + points
        })
        i++
      }
    }, 200);
 
    return h
  },
})