customer.js
8.27 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
// pages/tab/customer/customer.js
import { IMG_URL } from '~/utils/constantData'
import { getUserInfo } from '~/utils/cache/userInfo'
const navStyleTransparent = 'background-color: transparent;'
import reportPageTrackMixin from '~/mixins/reportPageTrackMixin'
const app = getApp()
Page({
behaviors: [reportPageTrackMixin],
/**
* 页面的初始数据
*/
data: {
IMG_URL,
navStyle: navStyleTransparent,
userInfo: {},
tabList: [{
id: 1,
name: '潜客'
}, {
id: 2,
name: '门店'
}],
myTabIdx: 0,
scrollIntoView: '',
selectedScreenPotential: [{
label: '主营品牌',
valueText: '',
key: 'selectedMainBrand'
}, {
label: '业务类型',
valueText: '',
key: 'businessTypeList'
}, {
label: '合作模式',
valueText: '',
key: 'cooperationModelList'
}, {
label: '流量情况',
valueText: '',
key: 'trafficStatusList'
}, {
label: '所属省份',
valueText: '',
key: 'provinces'
}, {
label: '销售人员',
valueText: '',
key: 'salesStaffList'
}],
selectedScreenStore: [{
label: '主营品牌',
valueText: '',
key: 'selectedMainBrand'
}, {
label: '业务类型',
valueText: '',
key: 'businessTypeList'
}, {
label: '合作模式',
valueText: '',
key: 'cooperationModelList'
}, {
label: '流量情况',
valueText: '',
key: 'trafficStatusList'
}, {
label: '所属省份',
valueText: '',
key: 'provinces'
}, {
label: '销售人员',
valueText: '',
key: 'salesStaffList'
}],
pendingMonthValue: null,
showAddIcon: true,
navBarHeight: 0,
navigationBarHeight: 0,
scrollTop: 0,
setScrollTop: 0,
track_event_code: 'sales_customer_view_page',
personParams: {} // 总监通过销售人员进入参数
},
// 总监有查看某个员工的潜客数据,手动触发时,将员工过滤条件清除
onTabItemTap(e) {
// 点击埋点
wx.$track.setTrackData(0, 'sales_customer_page', {}, '')
// 重新加载数据
this.setData({
myTabIdx: 0,
scrollTop: 0,
setScrollTop: 0,
personParams: {}
}, () => {
this.onShow()
})
},
// 导航栏就绪,记录高度并进行一次测量
navbarReady(e) {
const {height, navigationBarHeight} = e.detail
this.setData({
navBarHeight: height,
navigationBarHeight
})
},
onReady() {
const query = wx.createSelectorQuery().in(this)
query.select('.fixed-header').boundingClientRect()
query.exec(res => {
const height = res[0]?.height
this.setData({
fixedHeight: height
})
})
},
onLoad(options) {
this.setData({
userInfo: getUserInfo()
})
},
onShow() {
// 总监从销售小结跳入
const obj = app.getTabParams('customerObj')?.itemParams || {}
if (Object.keys(obj)?.length) {
const data = {name: obj.personName, value: obj.personId}
this.setData({
personParams: obj,
'searchObj.salesStaffList': data, // 将带入的销售人员选中
'storeSearchObj.salesStaffList': data // 将带入的销售人员选中
}, () => {
this.search()
})
return
}
// 从我的门店待跟进看板跳入
const params = app.getTabParams('customer')
let myTabIdx
if (params) {
this.setData({myTabIdx: Number(params.type)})
myTabIdx = Number(params.type)
} else {
myTabIdx = this.data.myTabIdx
}
const component = myTabIdx == 0 ? 'potentialSection' : 'storeSection'
this.setData({
setScrollTop: 0
})
const coms = this.selectComponent(`#${component}`)
if (coms.getPageData) coms.getPageData()
this.onPageShow()
},
getMore() {
let { myTabIdx } = this.data
const component = myTabIdx == 0 ? 'potentialSection' : 'storeSection'
const coms = this.selectComponent(`#${component}`)
if (coms.getMore) coms.getMore()
},
onPageScroll(e) {
const scrollTop = e.detail.scrollTop
// 悬浮按钮:滚动中收起,停止后展开
if (this._fabTimer) clearTimeout(this._fabTimer)
this.setData({ showAddIcon: false, scrollTop })
this._fabTimer = setTimeout(() => {
this.setData({ showAddIcon: true })
}, 120)
},
scrollToListTop(e) {
let { scrollTop, navBarHeight, fixedHeight } = this.data
wx.nextTick(() => {
setTimeout(() => {
let setScrollTop = e.detail - navBarHeight - fixedHeight
if (scrollTop >= setScrollTop) {
this.setData({
setScrollTop: setScrollTop > 0 ? setScrollTop : 0
})
}
}, 200)
})
},
// 触底加载转发到当前组件
onReachBottom() {
const comp = this.data.myTabIdx === 0 ? this.selectComponent('#potentialSection') : this.selectComponent('#storeSection')
comp && comp.loadMore && comp.loadMore()
},
// 筛选页面返回
back() {
this.setData({
show_confirm: false,
})
wx.showTabBar()
},
// 筛选页面确认
search() {
// 当有页面带入参数时,判断再次选中的销售人员是否与带入相同,不同时清掉数据
if ((Object.keys(this.data.personParams)?.length && this.data.searchObj?.salesStaffList?.value != this.data.personParams.personId) || (Object.keys(this.data.personParams)?.length && this.data.storeSearchObj?.salesStaffList?.value != this.data.personParams.personId)) {
this.setData({
personParams: {}
})
}
const { selectedScreenPotential, selectedScreenStore, searchObj, storeSearchObj, myTabIdx } = this.data
const sourceList = myTabIdx == 0 ? selectedScreenPotential : selectedScreenStore
const valueObj = myTabIdx == 0 ? (searchObj || {}) : (storeSearchObj || {})
const nextSelected = (sourceList || []).map(item => {
const key = item.key
const val = valueObj[key]
let text = ''
if (val) {
if (key === 'businessTypeList') {
// 业务类型为多选;当为“全部”或空时不回显
if (Array.isArray(val)) {
const filtered = val.filter(v => !(v?.name === '全部' || v?.value === ''))
text = filtered.length ? filtered.map(v => v.name).join('/') : ''
}
} else if (key === 'selectedMainBrand') {
// 主营品牌为数组;为空不回显
text = Array.isArray(val)
? val.map(v => (`${v.name}${v?.children?.[0]?.name}`))
.filter(Boolean)
.join('/')
: ''
} else {
// 单选项;选择“全部”或空值不回显
text = (val?.name === '全部' || val?.value === '') ? '' : (val?.name || '')
}
}
return { ...item, valueText: text }
})
if (Object.keys(this.data.personParams)?.length) {
this.setData({
selectedScreenPotential: nextSelected,
selectedScreenStore: nextSelected
})
}
if (myTabIdx == 0) {
this.setData({ selectedScreenPotential: nextSelected, scrollTop: 0, setScrollTop: 0 }, () => {
const potential = this.selectComponent('#potentialSection')
if (potential) potential.getPageData()
})
} else {
this.setData({ selectedScreenStore: nextSelected, scrollTop: 0, setScrollTop: 0 }, () => {
const storeSection = this.selectComponent('#storeSection')
if (storeSection) storeSection.getPageData()
})
}
},
// 选择筛选条件
changeScreen() {
this.setData({
showRendering: true,
show_confirm: true,
});
wx.hideTabBar()
},
createPotential() {
wx.navigateTo({ url: '/packageCustomer/pages/createPotential/createPotential' })
},
changeMyTab(e) {
const index = e?.currentTarget?.dataset?.id
const nextIdx = typeof index === 'number' ? index : 0
if (nextIdx === this.data.myTabIdx) return
this.setData({ myTabIdx: nextIdx, scrollTop: 0, setScrollTop: 0 })
wx.nextTick(() => {
this.setData({ scrollTop: 0, setScrollTop: 0, scrollLeft: 0 })
const component = nextIdx == 0 ? 'potentialSection' : 'storeSection'
const coms = this.selectComponent(`#${component}`)
if (coms.getPageData) coms.getPageData()
})
},
onHide() {
this.onPageHide()
},
onUnload() {
this.onPageHide()
}
})