createPotential.js
13.3 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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
// packageCustomer/pages/createPotential/createPotential.js
import { IMG_URL, SCENELIST, COOPERATIONMODELIST, TRSFFICSTATUSLIST, ROLELIST } from '~/utils/constantData'
import CustomerApi from '~/api/customerApi/index'
import { commonApi } from "~/api/api"
Page({
data: {
IMG_URL,
navHeight: 0,
pageType: 'create',
baseForm: [
{ label: '门店名称', key: 'storeName', type: 'textarea', maxLength: 20 },
{ label: '业务类型', key: 'bizType', type: 'select', callback: 'changeScene' },
{ label: '合作模式', key: 'coopMode', type: 'select', callback: 'changecoopMode' },
{ label: '主营品牌', key: 'mainCategory', type: 'select', callback: 'changemainCategory' },
{ label: '流量情况', key: 'flowScale', type: 'select', callback: 'changeFlowScale' }
],
addressForm: [{
label: '所在地区',
key: 'area',
type: 'select',
callback: 'changeArea'
}, {
label: '详细地址',
key: 'address',
type: 'textarea',
maxLength: 30
}],
infoData: {},
remarkLength: 0,
managerRoles: ROLELIST
},
onLoad(options) {
let { pageType, query } = options
if (query) {
const pageQuery = JSON.parse(decodeURIComponent(query))
this.setData({pageQuery})
// 获取潜客详情数据
this.getDetail(pageQuery)
}
// 获取行政区域数据
this.getAreaData()
this.setData({
pageType
})
},
onReady() {
this.resultDialog = this.selectComponent('#resultDialog')
},
onShow() {
},
getAreaData() {
CustomerApi.getAreaTreeList({}).then(res => {
const areaData = this.convertToVanAreaData(res)
this.setData({
areaList: areaData || []
})
})
},
convertToVanAreaData(originalData) {
const result = {
province_list: {},
city_list: {},
county_list: {}
}
function processDistricts(districts, level = 0) {
districts.forEach(item => {
if (item.level === 0) {
// 国家级,处理其子节点(省份)
processDistricts(item.districts, 1)
} else if (item.level === 1) {
// 省份级别
result.province_list[item.code] = item.name
// 处理城市
item.districts.forEach(city => {
if (city.level === 2) {
result.city_list[city.code] = city.name
// 处理区县
city.districts.forEach(county => {
if (county.level === 3) {
result.county_list[county.code] = county.name
}
})
}
})
}
})
}
processDistricts(originalData.districts)
return result
},
getDetail(par) {
if (!par.id) {
wx.$sentry.reportParamError(
'潜客详情参数异常: id',
par
)
}
CustomerApi.getCustomerData({id: par.id}).then(res => {
// 处理数据
this.progressData(res)
})
},
progressData(data) {
let { baseForm, managerRoles } = this.data
data.bizType = data?.businessTypeList?.map(val => { return `${SCENELIST?.find(v => v.value == val).name}` })?.join('/')
data.bizType_value = data?.businessTypeList?.map(val => { return val })
data.coopMode = COOPERATIONMODELIST.find(v => v.value == data.cooperationMode).name
data.coopMode_value = [data.cooperationMode]
data.mainCategory = data?.salePotentialCustomerBrandDTOList?.map(val => {return `${val.mainBrandName}${val.subBrandName}`})?.join('/')
let selectedMainBrand = []
data?.salePotentialCustomerBrandDTOList?.forEach(val => {
val.children = [{id: val.subBrandId, name: val.subBrandName}]
val.id = val.mainBrandId
val.name = val.mainBrandName
selectedMainBrand.push(val)
})
data.area_value = [data.provinceId, data.cityId, data.districtId]
data.area_name = [data.provinceName, data.city, data.districtName]
data.flowScale = TRSFFICSTATUSLIST?.find(val => val.value == data.flowSituation)?.name
data.flowScale_value = [data.flowSituation]
data.area = `${data.provinceName} ${data.city} ${data.districtName}`
data.attachmentList = data.storePhoto ? [data.storePhoto] : []
managerRoles?.forEach(item => {
const obj = data.salePotentialCustomerPersonnelInfoDTOList?.find(val => val.personnelType == item.value)
item.checked = obj && Object.keys(obj)?.length
item.personnelName = obj?.personnelName || ''
item.personnelPhone = obj?.personnelPhone || ''
})
// 未保存数据,默认将店总选中
if (managerRoles?.findIndex(v => v.checked) < 0) managerRoles[0].checked = true
// 2025-11-24版本放开信息完善门店名称和品牌编辑
// baseForm?.forEach(val => {
// if (val.key == 'storeName' || val.key == 'mainCategory') val.disabled = true
// })
this.setData({
infoData: data,
selectedMainBrand,
remarkLength: data.remark?.length,
baseForm,
managerRoles
})
},
onInput(e) {
const key = e.currentTarget?.dataset?.key || ''
let val = e.detail?.value || ''
val = val.replace(/[\u0020\u00A0\u3000]/g, '')
let maxLen
const baseForm = this.data.baseForm || []
const found = baseForm.find(i => i.key === key && typeof i.maxLength === 'number')
if (found) maxLen = found.maxLength
if (val.length > maxLen) {
val = val.slice(0, maxLen)
}
this.setData({ [`infoData.${key}`]: val })
},
// 备注输入框
onRemarkInput(e) {
let val = e.detail.value || ""
if (val.length > 200) {
val = val.substring(0, 200)
}
this.setData({
'infoData.remark': val,
remarkLength: val.length
})
},
showPopup(e) {
let { target } = e.currentTarget.dataset
if (!target.callback || target.disabled) return
this[target.callback]()
},
// 选择主营品牌
changemainCategory() {
this.setData({
carBrandPopupShow: true
})
},
hideBrandPopup() {
this.setData({
carBrandPopupShow: !this.data.carBrandPopupShow
})
},
brandConfirm() {
let brandMoudle = this.selectComponent('#car-brand')
const selected = brandMoudle && brandMoudle.handleConfirm() || []
let arr = []
selected?.forEach(val => {
val.children?.forEach(v => {
arr.push(`${val.name}${v.name}`)
})
})
this.setData({
'infoData.mainCategory': arr?.join('/'),
selectedMainBrand: selected
})
this.hideBrandPopup()
},
// 选择业务类型
changeScene() {
this.setData({
showSelectPopup: true,
selectOptions: SCENELIST,
selectTitle: '选择业务类型',
selectMultiple: true,
selectType: 'bizType',
selectValues: this.data.infoData['bizType_value'] || []
})
},
// 选择合作模式
changecoopMode() {
this.setData({
showSelectPopup: true,
selectOptions: COOPERATIONMODELIST,
selectTitle: '选择合作模式',
selectMultiple: false,
selectType: 'coopMode',
selectValue: this.data.infoData['coopMode_value'] || null
})
},
// 选择流量情况
changeFlowScale() {
this.setData({
showSelectPopup: true,
selectOptions: TRSFFICSTATUSLIST,
selectTitle: '选择流量情况',
selectMultiple: false,
selectType: 'flowScale',
selectValue: this.data.infoData['flowScale_value'] || null
})
},
handlePopupConfirm(e) {
const { values, items } = e.detail
let { selectType } = this.data
this.setData({
[`infoData.${selectType}`]: items?.map(val => { return val.name })?.join('/'),
[`infoData.${selectType}_value`]: values
})
this.hideSelectPopup()
},
hideSelectPopup() {
this.setData({
showSelectPopup: false
})
},
// 选择所在地区
showArea(e) {
let { type } = e.currentTarget.dataset
if (type != 'select') return
this.setData({
showSelectArea: true
})
},
areaConfirm(e) {
const { names, codes } = e.detail
this.setData({
'infoData.area': names?.join(' '),
'infoData.area_value': codes,
'infoData.area_name': names
})
this.areaCancel()
},
areaCancel() {
this.setData({
showSelectArea: false
})
},
changeManage(e) {
let { target, index } = e.currentTarget.dataset
this.setData({
[`managerRoles[${index}].checked`]: !target.checked
})
},
// 上传图片
uploadImages() {
let _this = this
wx.chooseImage({
count: 1,
success(res) {
let [tempFiles] = res.tempFilePaths
let tempFilesList = tempFiles.split('.')
let imgType = tempFilesList[tempFilesList.length - 1]
let type = imgType == 'unknown' ? 'jpg' : imgType
if (res?.tempFiles?.[0]?.size > 10 * 1024 * 1024) return wx.$api.showToast('图片不能大于10M')
wx.getFileSystemManager().readFile({
filePath: tempFiles, //选择图片返回的相对路径
encoding: 'base64', //编码格式
success(_res) {
wx.$api.showLoading('上传中...')
commonApi.uploadImg({
file: `${type}@${_res.data}`
}).then(img => {
wx.$api.hideLoading()
_this.setData({
'infoData.attachmentList': [img]
})
})
}
})
},
fail(err) {
console.log(err)
}
})
},
// 图片预览
previewImage(e) {
let { url, index } = e.currentTarget.dataset
let imageUrl = url?.map(v => { return v})
wx.previewImage({
urls: imageUrl,
current: imageUrl[index]
})
},
// 删除图片
deleteFile(e) {
let { index } = e.currentTarget.dataset
let { infoData } = this.data
infoData.attachmentList.splice(index, 1)
this.setData({infoData})
},
manangeInput(e) {
let { type, index } = e.currentTarget.dataset
let { managerRoles } = this.data
let value = e.detail.value
value = value.replace(/\s+/g, '')
if (managerRoles[index]) {
managerRoles[index][type] = value
this.setData({
[`managerRoles[${index}].${type}`]: value
})
}
},
handleCancel() {
wx.navigateBack()
},
handleConfirm() {
let { infoData, managerRoles, selectedMainBrand } = this.data
if (!infoData.storeName || !infoData.bizType || !infoData.coopMode || !infoData.mainCategory || !infoData.flowScale || !infoData.area || !infoData.address) return wx.$api.showToast('请填入必填信息')
const phoneRex = /^[1]([3-9])[0-9]{9}$/
for (const item of (managerRoles || [])) {
if (item.checked && item.personnelPhone) {
if (!phoneRex.test(item.personnelPhone)) {
wx.$api.showToast("请填写正确手机号")
return false
}
}
}
const {
storeName,
bizType_value,
coopMode_value,
flowScale_value,
area_value = [],
area_name = [],
address,
attachmentList,
remark
} = infoData
// 空值处理函数
const getValue = (value, defaultValue = '') => value ?? defaultValue
const brand = []
selectedMainBrand?.forEach(item => {
item.children?.forEach(val => {
brand.push({
mainBrandId: item.id,
mainBrandName: item.name,
subBrandId: val.id,
subBrandName: val.name
})
})
})
let params = {
id: infoData.id,
storeName: getValue(storeName),
businessTypeList: getValue(bizType_value?.join(',')),
cooperationMode: getValue(coopMode_value?.[0]),
flowSituation: getValue(flowScale_value?.[0]),
provinceId: getValue(area_value[0]),
provinceName: getValue(area_name[0]),
cityId: getValue(area_value[1]),
city: getValue(area_name[1]),
districtId: getValue(area_value[2]),
districtName: getValue(area_name[2]),
address: getValue(address),
storePhoto: getValue(attachmentList?.[0]),
remark: getValue(remark),
salePotentialCustomerPersonnelInfoDTOList: managerRoles
.filter(val => val.checked && (val.personnelName || val.personnelPhone))
.map(val => ({
personnelName: getValue(val.personnelName),
personnelPhone: getValue(val.personnelPhone),
personnelType: getValue(val.value)
})),
salePotentialCustomerBrandDTOList: brand
}
if (this.data.confirmFlag) return
this.setData({confirmFlag: true})
wx.$api.showLoading()
const methodName = this.data.pageQuery ? 'editCustomer' : 'addCustomer'
CustomerApi[methodName](params).then(res => {
wx.$api.hideLoading()
this.setData({
confirmFlag: false
})
let { code, message } = res
const okText = '我知道了'
if (this.resultDialog) {
this.setData({
textareaDisabled: true
})
if (code == 0) {
this.resultDialog.open({
type: 'success',
title: this.data.pageQuery ? '您的潜客信息已完善!' : '您的潜客添加完成!',
description: '',
okText
})
} else {
this.resultDialog.open({
type: 'error',
title: message,
description: '',
okText
})
}
}
})
},
// 接口请求结果弹窗确认
onDialogOk() {
this.handleCancel()
},
onHide() {
},
onUnload() {
},
onPullDownRefresh() {
},
onReachBottom() {
},
onShareAppMessage() {
},
})