index.js
8.84 KB
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
import api from '~/api/index/index'
import dayjs from 'dayjs'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/supervisor-miniprogram/'
let timeoutId
Page({
/**
* 页面的初始数据
*/
data: {
IMG_URL,
navBarHeight: 84,
navStyle: 'background-color: rgba(0,0,0,0);',
navTitleStyle: 'font-weight: 600; font- size: 32rpx; color: #000;',
userInfo: {},
staticList: [{
label: '驻店人员',
width: '208',
key: 'staffCount',
background: 'linear-gradient(90deg, #42CCCF 0%, #36D9A5 100%)'
}, {
label: '门店数量',
width: '192',
key: 'shopCount',
background: 'linear-gradient(90deg, #5E69FF 0%, #4079FF 100%)'
}, {
label: '总产值',
key: 'totalValue',
background: 'linear-gradient(90deg, #3D76FC 0%, #4DA6FF 100%)'
}],
tabList: [{
text: '每日任务',
count: 0,
key: 'dailyCount'
}, {
text: '本周任务',
count: 0,
key: 'weeklyCount'
}, {
text: '月度任务',
count: 0,
key: 'monthlyCount'
}, {
text: '专项任务',
count: 0,
key: 'specialCount'
}],
tabIndex: 0,
statusMap: {
0: {name: '待完成', color: '#2C66F7', background: '#2c66f71a'},
1: {name: '进行中', color: '#FF9D0A', background: '#ff9d0a1a'},
2: {name: '已完成', color: '#35C376', background: '#35c3761a'},
},
missionMap: {
3: {name: '录音复盘'},
5: {name: '人员带教'},
0: {name: '督导日报'},
1: {name: '本周复盘'},
2: {name: '督导月度计划'},
4: {name: '专项任务'},
6: {name: '提报优秀案例录音'},
7: {name: '带教要求'}
},
list: [],
scrollTop: 0,
showIcon1: true
},
onTabItemTap(e) {
// 点击埋点
wx.$track.setTrackData(0, 'supervisor_index_page', {}, '')
},
navbarReady(e) {
let navBarHeight = e.detail.height
this.setData({
navBarHeight
})
},
onScroll(e) {
this.setData({
scrollTop: e.detail.scrollTop
})
const {navBarHeight} = this.data
const query = wx.createSelectorQuery().in(this)
query.select('.data-container').boundingClientRect()
query.exec(res => {
this.setData({
isSticky: res[0].top <= navBarHeight
})
})
// 滚动时隐藏第一个图标,显示第二个图标
this.setData({
showIcon1: false
})
// 清除之前的定时器
if (timeoutId) {
clearTimeout(timeoutId)
}
// 设置一个定时器,在滚动停止后一定时间后恢复两个图标的显示状态
timeoutId = setTimeout(() => {
this.setData({
showIcon1: true
})
}, 1000) // 在这里设置等待的时间,单位是毫秒
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let userInfo = wx.$util.getUserInfo()
this.setData({userInfo})
this.getTabData(true)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow () {
this.getTabData()
this.getStaticData()
this.setData({
list: [],
pageNum: 1,
flag: false,
nothing: false
}, () => {
this.getList(true)
})
},
getTabData(loadFlag) {
let { tabIndex, tabList, startStr, endStr } = this.data
let userInfo = wx.$util.getUserInfo()
let params = {
supervisorPhone: userInfo?.phone,
startDate: loadFlag ? undefined : startStr,
endDate: loadFlag ? undefined : endStr
}
api.getTaskTabData(params).then(res => {
let { code, data, message } = res
if (code == 0) {
if (loadFlag) {
tabList?.forEach(val => {
val.count = data[val.key] > 99 ? '99+' : data[val.key]
})
this.setData({
tabList
})
} else {
// 仅更新当前选中tab数量
let key = tabList[tabIndex].key
this.setData({
[`tabList[${tabIndex}].count`]: data[key] > 99 ? '99+' : data[key]
})
}
} else {
wx.$util.showToast(message)
}
})
},
handleMentoring() {
wx.$track.setTrackData(0, `supervisor_start_mentoring_index`, {}, '')
wx.navigateTo({
url: `/packageCrew/pages/mentoring/mentoring`,
})
},
formatThousands (v) {
const s = String(v)
if (!s) return s
const isNeg = s[0] === '-'
const raw = isNeg ? s.slice(1) : s
const [intPart, decPart] = raw.split('.')
const intFmt = String(intPart || '0').replace(/\B(?=(\d{3})+(?!\d))/g, ',')
const res = decPart ? `${intFmt}.${decPart}` : intFmt
return isNeg ? `-${res}` : res
},
getStaticData() {
api.getSupervisorStaticData({}).then(res => {
let { code, data, message } = res
if (code == 0) {
data.staffCount = (data.staffCount ?? '') === '' ? '-' : this.formatThousands(data.staffCount)
data.shopCount = (data.shopCount ?? '') === '' ? '-' : this.formatThousands(data.shopCount)
data.totalValue = (data.totalValue ?? '') === '' ? '-' : this.formatThousands(data.totalValue)
this.setData({staticData: data})
} else {
wx.$util.showToast(message)
}
})
},
tabClick(e) {
let eventCode = ['supervisor_dayTask_tab', 'supervisor_weeklyTask_tab', 'supervisor_monthlyTask_tab', 'supervisor_specificTask_tab']
// 点击埋点
wx.$track.setTrackData(0, eventCode[e.detail], {}, '')
this.setData({
tabIndex: e.detail
})
},
jump(e) {
const { target } = e.currentTarget.dataset
const pageUrl = {
3: '/packageIndex/pages/recordingReview/recordingReview',
5: '/packageCrew/pages/mentoring/mentoring',
0: '/packageIndex/pages/dailySupervisionReport/dailySupervisionReport',
1: '/packageIndex/pages/weeklyReview/weeklyReview',
2: '/packageIndex/pages/monthlyPlan/monthlyPlan',
4: '/packageIndex/pages/specialTask/specialTask',
6: '/packageIndex/pages/caseAudioList/caseAudioList',
7: '/packageIndex/pages/mentorRequirements/mentorRequirements'
}
const eventCode = {
3: {view: 'supervisor_recording_view', execute: 'supervisor_recording_execute'},
5: {view: 'supervisor_mentoring_view', execute: 'supervisor_mentoring_execute'},
0: {view: 'supervisor_report_view', execute: 'supervisor_report_execute'},
1: {view: 'supervisor_weeklyReview_view', execute: 'supervisor_weeklyReview_execute'},
2: {view: 'supervisor_monthlyPlan_view', execute: 'supervisor_monthlyPlan_execute'},
4: {view: 'supervisor_specificTask_view', execute: 'supervisor_specificTask_execute'},
6: {view: 'supervisor_caseAudioList_view', execute: 'supervisor_caseAudioList_view'},
7: {view: 'supervisor_mentorRequirements_view', execute: 'supervisor_mentorRequirements_view'}
}
let status = target.taskStatus != 2 ? 'execute' : 'view'
wx.$track.setTrackData(0, eventCode[target.taskType][status], {}, '')
wx.navigateTo({
url: `${pageUrl[target.taskType]}?taskStatus=${target.taskStatus}&id=${target.id}`,
})
},
search(e) {
this.setData({
list: [],
pageNum: 1,
flag: false,
nothing: false,
startStr: e.detail.startDay?.replace(/\//g, '-'),
endStr: e.detail.endDay?.replace(/\//g, '-')
}, () => {
this.getList(true)
this.getTabData()
})
},
scrollonReachBottom() {
this.getList()
},
// 获取列表数据
getList(repload) {
let { pageNum, nothing, startStr, endStr, tabIndex, topBoxHeight, scrollTop } = this.data
if (nothing) return
const taskList = [[0, 3, 5], [6, 7], [2], [4]]
wx.$util.showLoading()
let params = {
taskTypeList: taskList[tabIndex],
startDate: startStr,
endDate: endStr,
pageNum,
pageSize: 10
}
api.getMissionList(params).then(res => {
wx.$util.hideLoading()
let total = 0
let list = []
let {
code,
data,
message
} = res
data?.list?.forEach(val => {
val.updatedDate = val.updatedDate ? dayjs(val.updatedDate).format('YYYY-MM-DD HH:mm:ss') : ''
val.createTime = val.createTime ? dayjs(val.createTime).format('YYYY-MM-DD HH:mm:ss') : ''
})
if (code == 0) {
list = data.list
total = data.total
} else {
wx.$util.showToast(message)
}
if (total != 0) {
this.setData({
[`list[${pageNum - 1}]`]: list
})
}
// if (repload) {
// const query = wx.createSelectorQuery().in(this)
// query.select('.top-box').boundingClientRect()
// query.exec(res => {
// let topBoxHeight = res[0].height
// if (scrollTop >= topBoxHeight) {
// setTimeout(() => {
// this.setData({
// setScrollTop: topBoxHeight
// })
// }, 200)
// }
// })
// }
this.setData({
total,
flag: true,
triggered: false,
pageNum: pageNum + 1,
nothing: pageNum == data?.pages
})
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {},
onShareTimeline: function () {}
})