specialTaskApply.js
10.5 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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
import indexApi from '~/api/index/index'
import crewApi from '~/api/crew/index'
import dayjs from 'dayjs'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/supervisor-miniprogram/'
Page({
data: {
IMG_URL,
navBarHeight: 84,
pageTitle: '发起专项任务',
readonly: false,
isFullSucreen: false,
businessList: [
{ label: '延保', value: 1 },
{ label: '权益', value: 3 },
{ label: '轻改', value: 2 }
],
bizTypeOptions: [
{ itemName: '人员更换评估', itemValue: 'staff-replace-access' },
{ itemName: '商务政策更新', itemValue: 'policy-update-access' },
{ itemName: '流量问题改善', itemValue: 'traffic-optimize' }
],
merchantOptions: [],
staffOptions: [],
operatorOptions: [],
form: {
bizType: '',
categoryName: '',
merchantId: '',
merchantName: '',
businessType: '',
problemStaffList: [],
regionOperatorPhone: '',
regionOperatorName: '',
description: ''
},
descriptionLength: 0,
showSelectPopup: false,
selectOptions: [],
selectMultiple: false,
selectValues: [],
selectValue: null,
selectTitle: '',
selectPopupHeight: '55%',
labelKey: 'itemName',
valueKey: 'itemValue',
selectScene: '',
allowSearch: false
},
navbarReady(e) {
const navBarHeight = e.detail?.height
if (!navBarHeight) return
this.setData({ navBarHeight })
},
onLoad(options) {
this.setData({
pageQuery: options || {},
readonly: !!options?.id,
pageTitle: options?.id ? '查看专项任务' : '发起专项任务'
})
this.getMerchantList()
this.getAreaOperatorList()
if (options?.id) {
this.getDetail(options.id)
}
},
back() {
wx.navigateBack()
},
getMerchantList() {
indexApi.getSupervisorMerchantList({}).then(res => {
const { code, data, message } = res || {}
if (code == 0) {
const list = Array.isArray(data) ? data : []
list.forEach(val => {
val.itemName = val.merchantName
val.itemValue = val.merchantId
})
this.setData({ merchantOptions: list })
} else {
wx.$util.showToast(message || '门店列表获取失败')
}
})
},
getStaffListByMerchant(merchantId) {
if (!merchantId) {
this.setData({ staffOptions: [] })
return
}
let params = {
pageNum: 1,
pageSize: 9999,
merchantIdList: [merchantId]
}
crewApi.getParticipantOptions(params).then(res => {
const { code, data, message } = res || {}
if (code == 0) {
const list = Array.isArray(data) ? data : data?.list || []
list.forEach(val => {
val.itemName = val.staffName || val.name
val.itemValue = val.staffPhone || val.phone
})
this.setData({ staffOptions: list })
} else {
wx.$util.showToast(message || '人员列表获取失败')
}
})
},
getAreaOperatorList() {
indexApi.getAreaOperatorList({}).then(res => {
const { code, data, message } = res || {}
if (code == 0) {
const list = Array.isArray(data) ? data : data?.list || []
list.forEach(v => {
v.itemName = v.name
v.itemValue = v.phone
})
this.setData({ operatorOptions: list })
} else {
wx.$util.showToast(message || '区域运营获取失败')
}
})
},
getDetail(id) {
indexApi.getSpecialTaskDetail({ id }).then(res => {
const { code, data, message } = res || {}
if (code != 0) {
wx.$util.showToast(message || '详情获取失败')
return
}
const detail = data || {}
const bizType = detail.bizTypeAttr || detail.bizType || ''
const categoryName = detail.categoryName || ''
const merchantId = detail.merchantId || ''
const merchantName = detail.merchantName || ''
const businessType = Number(detail.businessType || detail.business || '') || ''
const regionOperatorName = detail.regionOperatorName || ''
const regionOperatorPhone = detail.regionOperatorPhone || ''
const description = detail.description || ''
this.setData({
descriptionLength: description?.length || 0,
form: {
...this.data.form,
bizType: String(bizType),
categoryName: categoryName || this.findcategoryName(String(bizType)),
merchantId,
merchantName,
businessType,
regionOperatorName,
regionOperatorPhone,
problemStaffList: detail?.problemStaffName?.split(',')?.map(val => {return {name: val}}),
description
}
})
this.getStaffListByMerchant(merchantId)
})
},
findcategoryName(bizType) {
const found = (this.data.bizTypeOptions || []).find(v => String(v.itemValue) === String(bizType))
return found?.itemName || ''
},
openbizType() {
if (this.data.readonly) return
this.openPopup({
scene: 'bizType',
title: '任务类型',
options: this.data.bizTypeOptions,
labelKey: 'itemName',
valueKey: 'itemValue',
multiple: false,
value: this.data.form.bizType || null,
allowSearch: false
})
},
openMerchant() {
if (this.data.readonly) return
this.openPopup({
scene: 'merchant',
title: '门店选择',
options: this.data.merchantOptions,
labelKey: 'itemName',
valueKey: 'itemValue',
multiple: false,
value: [this.data.form.merchantId] || null,
allowSearch: true
})
},
openProblemSales() {
if (this.data.readonly) return
if (this.data.form.bizType !== 'staff-replace-access') return
if (!this.data.form.merchantId) return wx.$util.showToast('请先选择归属门店')
if (!this.data.staffOptions.length) return wx.$util.showToast('当前门店暂无可选人员')
const selectedPhones = (this.data.form.problemStaffList || []).map(v => v.phone).filter(Boolean)
this.openPopup({
scene: 'problemSales',
title: '问题驻店销售',
options: this.data.staffOptions,
labelKey: 'itemName',
valueKey: 'itemValue',
multiple: true,
values: selectedPhones,
allowSearch: true
})
},
openOperator() {
if (this.data.readonly) return
if (!this.data.operatorOptions.length) return wx.$util.showToast('未配置区域运营,请联系总部处理')
this.openPopup({
scene: 'operator',
title: '指定区域运营',
options: this.data.operatorOptions,
labelKey: 'itemName',
valueKey: 'itemValue',
multiple: false,
value: [this.data.form.regionOperatorPhone] || null,
allowSearch: true
})
},
openPopup({ scene, title, options, multiple, value, values, labelKey, valueKey, allowSearch }) {
this.setData({
selectScene: scene,
selectTitle: title,
selectOptions: options || [],
selectMultiple: !!multiple,
selectValue: value !== undefined ? value : null,
selectValues: Array.isArray(values) ? values : [],
labelKey: labelKey || 'itemName',
valueKey: valueKey || 'itemValue',
allowSearch: !!allowSearch,
showSelectPopup: true
})
},
hideSelectPopup() {
this.setData({ showSelectPopup: false })
},
handlePopupConfirm(e) {
const { values, items } = e.detail || {}
const scene = this.data.selectScene
this.setData({ showSelectPopup: false })
if (scene === 'bizType') {
const val = values?.[0] || ''
const name = items?.[0]?.itemName || ''
this.setData({
'form.bizType': val,
'form.categoryName': name,
'form.problemStaffList': val === 'staff-replace-access' ? this.data.form.problemStaffList : []
})
return
}
if (scene === 'merchant') {
const val = values?.[0] || ''
const name = items?.[0]?.itemName || ''
this.setData({
'form.merchantId': val,
'form.merchantName': name,
'form.problemStaffList': []
})
this.getStaffListByMerchant(val)
return
}
if (scene === 'operator') {
const val = values?.[0] || ''
const name = items?.[0]?.itemName || ''
this.setData({
'form.regionOperatorPhone': val,
'form.regionOperatorName': name
})
return
}
if (scene === 'problemSales') {
const list = (items || []).map(v => ({
name: v.itemName,
phone: v.itemValue
}))
this.setData({
'form.problemStaffList': list
})
}
},
removeProblemSales(e) {
const idx = Number(e.currentTarget?.dataset?.index)
if (Number.isNaN(idx)) return
const next = (this.data.form.problemStaffList || []).slice()
next.splice(idx, 1)
this.setData({
'form.problemStaffList': next
})
},
changeBusiness(e) {
if (this.data.readonly) return
const val = e.currentTarget?.dataset?.value
this.setData({
'form.businessType': val
})
},
descriptionInput(e) {
if (this.data.readonly) return
let val = e.detail?.value || ''
if (val.length > 500) val = val.substring(0, 500)
this.setData({
'form.description': val,
descriptionLength: val.length
})
},
validate() {
const f = this.data.form || {}
if (!f.bizType) return '请选择任务类型'
if (!f.merchantId) return '请选择归属门店'
if (!f.businessType) return '请选择归属业务'
if (f.bizType === 'staff-replace-access') {
if (!Array.isArray(f.problemStaffList) || !f.problemStaffList.length) return '请选择问题驻店销售'
}
if (!f.regionOperatorPhone) return '请选择指定区域运营'
if (!String(f.description || '').trim()) return '请输入任务事项描述'
return ''
},
submit() {
const msg = this.validate()
if (msg) return wx.$util.showToast(msg)
const f = this.data.form || {}
const params = {
bizType: f.bizType,
categoryName: f.categoryName,
merchantId: f.merchantId,
merchantName: f.merchantName,
businessType: f.businessType,
problemStaffList: f.problemStaffList?.map(v => {return {name: v.name, phone: v.phone}}),
regionOperatorList: [{name: f.regionOperatorName, phone: f.regionOperatorPhone}],
description: f.description
}
wx.$util.showLoading()
indexApi
.createSpecialTask(params)
.then(res => {
wx.$util.hideLoading()
const { code, message } = res || {}
if (code == 0) {
wx.$util.showToast('操作成功')
this.back()
} else {
wx.$util.showToast(message || '提交失败')
}
})
.catch(() => {
wx.$util.hideLoading()
})
}
})