potentialDetail.js
9.11 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
import { IMG_URL, COOPERATIONMODELIST, TRSFFICSTATUSLIST, SCENELIST, ROLELIST } from '~/utils/constantData'
import CustomerApi from '~/api/customerApi/index'
import { getUserInfo } from '~/utils/cache/userInfo'
import dayjs from 'dayjs'
Page({
data: {
IMG_URL: IMG_URL,
userInfo: {},
navStyle: 'background: #fff;',
showVisitButton: true,
infoBoardItems: [], // 信息看板数据
listTabs: ['拜访记录', '资料详情'],
tabIndex: 0,
scrollTop: 0, // 监听页面滚动位置
initialTabTop: 0, // 初始tab的top值
setScrollTop: 0, // scroll-view的滚动位置
statusText: {
1: {label: '跟进中', color: '#FF9D0A'},
3: {label: '已签约', color: '#35C376'},
2: {label: '未签约', color: '#F24724'},
4: {label: '已绑定', color: '#347BFF'}
},
visitRecords: [],
pageNum: 1,
pageSize: 10,
bgUrl: `${IMG_URL}/customer/nothing.png`,
cardItemObj: [{
label: '拜访时间',
key: 'visitTime'
}, {
label: '联系人',
key: 'contactPerson'
}, {
label: '拜访内容',
key: 'visitContent'
}, {
label: '拜访签到',
key: 'checkInLocation'
}, {
label: '拜访照片',
key: 'visitPhotos',
type: 'image'
}],
infoDetail: {}
},
onReady() {
// 记录tab的位置 请求接口后再记录一次位置 数据加载 假数据
this.recordTabTop()
},
onLoad(options) {
let { query } = options
if (query) {
const pageQuery = JSON.parse(decodeURIComponent(query))
this.setData({pageQuery})
}
this.setData({
userInfo: getUserInfo()
})
},
onShow() {
// 获取潜客详情数据
this.getPotentialDetail()
// 初始加载数据
this.resetAndLoad()
this.measureLayout()
},
getPotentialDetail() {
let { pageQuery } = this.data
wx.$api.showLoading()
if (!pageQuery.id) {
wx.$sentry.reportParamError(
'潜客详情参数异常: id',
pageQuery
)
}
CustomerApi.getCustomerData({id: pageQuery.id}).then(res => {
wx.$api.hideLoading()
this.setData({showPage: true})
// 处理数据回显
this.progressData(res)
})
},
// 图片预览
previewImage(e) {
let { url } = e.currentTarget.dataset
wx.previewImage({
urls: [url]
})
},
progressData(data) {
// 添加基础数据校验
if (!data || typeof data !== 'object') {
wx.$sentry.reportError(
'潜客详情数据异常: data',
data
)
this.setData({
infoDetail: {}
})
return
}
try {
// 主营品牌
data.mainCategory = ''
if (Array.isArray(data?.salePotentialCustomerBrandDTOList)) {
data.mainCategory = data.salePotentialCustomerBrandDTOList.map(val => {
try {
if (!val || typeof val !== 'object') return ''
const mainBrand = val.mainBrandName || ''
const subBrand = val.subBrandName || ''
return mainBrand || subBrand ? `${mainBrand}${subBrand}` : ''
} catch (error) {
wx.$sentry.reportError(
'主营品牌数据异常: data.salePotentialCustomerBrandDTOList',
data.salePotentialCustomerBrandDTOList
)
return ''
}
}).filter(item => item) // 过滤空字符串
.join('/') || ''
}
// 合作模式
data.coopMode = ''
if (data.cooperationMode !== undefined && data.cooperationMode !== null) {
try {
data.coopMode = COOPERATIONMODELIST?.find(v => v?.value == data.cooperationMode)?.name || ''
} catch (error) {
wx.$sentry.reportError(
'合作模式数据异常: data.cooperationMode',
data.cooperationMode
)
}
}
// 流量情况
data.flowScale = ''
if (data.flowSituation !== undefined && data.flowSituation !== null) {
try {
data.flowScale = TRSFFICSTATUSLIST?.find(val => val?.value == data.flowSituation)?.name || ''
} catch (error) {
wx.$sentry.reportError(
'流量情况数据异常: data.flowSituation',
data.flowSituation
)
}
}
// 业务类型
data.bizType = ''
if (Array.isArray(data?.businessTypeList)) {
data.bizType = data.businessTypeList.map(val => {
try {
const sceneItem = SCENELIST?.find(v => v?.value == val)
return sceneItem?.name || ''
} catch (error) {
wx.$sentry.reportError(
'业务类型数据异常: data.businessTypeList',
data.businessTypeList
)
return ''
}
}).filter(item => item) // 过滤空字符串
.join('/') || ''
}
// 人员类型
if (Array.isArray(data?.salePotentialCustomerPersonnelInfoDTOList)) {
data.salePotentialCustomerPersonnelInfoDTOList.forEach(val => {
try {
if (val && typeof val === 'object') {
val.roleName = ROLELIST?.find(v => v?.value == val.personnelType)?.label || ''
}
} catch (error) {
wx.$sentry.reportError(
'人员信息数据异常: data.salePotentialCustomerPersonnelInfoDTOList',
data.salePotentialCustomerPersonnelInfoDTOList
)
val.roleName = ''
}
})
}
// 店面门头照片
data.storePhotoList = []
if (typeof data.storePhoto === 'string') {
try {
data.storePhotoList = data.storePhoto.split(',')
} catch (error) {
wx.$sentry.reportError(
'店面照片数据异常: data.storePhoto',
data.storePhoto
)
}
}
// 设置数据,添加错误处理
this.setData({
infoDetail: data
}, () => {
try {
this.buildInfoBoard && this.buildInfoBoard()
this.recordTabTop && this.recordTabTop()
} catch (error) {
console.error('执行回调函数时出错:', error)
}
})
} catch (error) {
wx.$sentry.reportParamError(
'潜客详情数据异常: data',
data
)
// 确保即使出错也有基本的数据结构
this.setData({
infoDetail: {
...data,
mainCategory: '',
coopMode: '',
flowScale: '',
bizType: '',
salePotentialCustomerPersonnelInfoDTOList: [],
storePhotoList: []
}
})
}
},
recordTabTop() {
const query = wx.createSelectorQuery().in(this)
query.select('.tabbar-anchor').boundingClientRect()
query.exec(res => {
const top = res[0]?.top
const height = res[0]?.height
this.setData({
initialTabTop: top,
tabHeight: height
})
})
},
buildInfoBoard() {
const { infoDetail } = this.data
const items = [
{ label: '主营品牌', value: infoDetail.mainCategory },
{ label: '合作模式', value: infoDetail.coopMode },
{ label: '拜访次数', value: infoDetail.visitCount != null ? `${infoDetail.visitCount}` : '', highlight: true },
{ label: '流量情况', value: infoDetail.flowScale },
[3, 4].includes(infoDetail.potentialCustomersStatus) ? { label: '预计展业时间', value: infoDetail.expectedOperationDate ? dayjs(infoDetail.expectedOperationDate).format('YYYY-MM-DD') : '' } : null, // 已签约或已绑定展示
[3, 4].includes(infoDetail.potentialCustomersStatus) ? { label: '分润规则', value: infoDetail.profitRule } : null, // 已签约或已绑定展示
{ label: '业务类型', value: infoDetail.bizType, span: 2, full: [3, 4].includes(infoDetail.potentialCustomersStatus), clampLines: 1, threshold: 16 },
[3, 4].includes(infoDetail.potentialCustomersStatus) ? { label: '上架商品', value: infoDetail.productShelfInfo, full: true } : null
].filter(Boolean)
this.setData({ infoBoardItems: items })
},
// 加载逻辑
resetAndLoad() {
let { pageQuery } = this.data
if (!pageQuery.id) {
wx.$sentry.reportParamError(
'拜访记录参数异常: id',
pageQuery
)
}
CustomerApi.getVisitList({id: pageQuery.id}).then(res => {
this.setData({
visitRecords: res || []
})
})
},
navbarReady(e) {
let navBarHeight = e.detail.height
this.setData({
navBarHeight
})
},
tabClick(e) {
const index = typeof e?.detail === 'number' ? e.detail : 0
this.setData({
tabIndex: index
})
if (index == 0) this.resetAndLoad()
wx.nextTick(() => { this.measureLayout() })
},
onScroll(e) {
const scrollTop = e.detail.scrollTop
this.setData({ scrollTop })
},
measureLayout(cb) {
const { scrollTop, initialTabTop, navBarHeight } = this.data
if (scrollTop >= (initialTabTop - navBarHeight)) {
this.setData({
setScrollTop: (initialTabTop - navBarHeight)
})
}
},
onCreateVisit() {
let { pageQuery } = this.data
wx.navigateTo({
url: `/packageCustomer/pages/createVisit/createVisit?id=${pageQuery.id}`
})
}
});