PotentialSection.js
7.54 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
// pages/tab/customer/components/PotentialSection/PotentialSection.js
import { IMG_URL } from '~/utils/constantData'
import CustomerApi from '~/api/customerApi/index'
// 预计算安全的月份时间戳,避免初始 0 值
const __NOW__ = new Date()
const __CUR_YM_TS__ = new Date(__NOW__.getFullYear(), __NOW__.getMonth(), 1).getTime()
const __MIN_YM_TS__ = new Date(__NOW__.getFullYear(), __NOW__.getMonth() - 23, 1).getTime()
Component({
options: {
styleIsolation: 'shared'
},
properties: {
showAddIcon: Boolean,
navBarHeight: Number,
searchObj: Object,
userInfo: Object,
personParams: Object
},
data: {
searchKeyword:'',
IMG_URL,
// 列表与分页(保持原有结构)
listTabs: ['全部', '跟进中', '已签约', '未签约'],
customerList: [],
currentPage: 1,
pageSize: 10,
hasMore: true,
loading: false,
statusIndex: 0,
boardMonthText: `${__NOW__.getMonth() + 1}月`,
boardScopeText: '全部',
dashboard: {},
boardMonthActive: true,
boardScopeActive: false,
monthPickerShow: false,
minMonthDate: __MIN_YM_TS__,
maxMonthDate: __CUR_YM_TS__,
monthPickerValue: __CUR_YM_TS__,
// 新增:暂存用户正在选择的值,确认后写入
pendingMonthValue: 0,
// 保持原有的状态标签映射
statusText: {
1: { label: '跟进中', color: '#FF9D0A' },
3: { label: '已签约', color: '#35C376' },
2: { label: '未签约', color: '#F24724' },
4: { label: '已绑定', color: '#347BFF' }
}
},
lifetimes: {
attached() {
}
},
methods: {
onSearchConfirm(e){
let {value} = e.detail
this.setData({
searchKeyword:value
},()=>{
this.resetAndLoad(() => {
this.triggerEvent('needScrollTop', this.data.initialTabTop)
})
})
},
getPageData() {
// 获取数据看板数据
this.getStatic()
// 获取潜客列表数据
this.resetAndLoad()
},
getParams() {
let { boardScopeActive, monthPickerValue, searchObj, statusIndex, userInfo, personParams } = this.data
const statusMap = {
0: 0, // 全部
1: 1, // 待跟进
2: 3, // 已签约
3: 2, // 已绑定
// 4: 2 // 未签约
}
const obj = {
storeName:this.data.searchKeyword,
isAll: boardScopeActive ? 1 : 0,
year: boardScopeActive ? undefined : new Date(monthPickerValue).getFullYear(),
month: boardScopeActive ? undefined : new Date(monthPickerValue).getMonth() + 1,
mainBrandId: searchObj?.selectedMainBrand?.[0]?.id,
subBrandId: searchObj?.selectedMainBrand?.[0]?.children[0]?.id,
cooperationMode: searchObj?.cooperationModelList?.value,
businessTypeList: searchObj?.businessTypeList?.map(val => { if (val.value) return val.value }),
flowSituation: searchObj?.trafficStatusList?.value,
provinceId: searchObj?.provinces?.value,
salesPersonId: personParams?.personId || searchObj?.salesStaffList?.value,
potentialCustomersStatus: statusIndex == 0 ? undefined : statusMap[statusIndex], // 状态
isSuperior: userInfo.loginRole == 1 && (personParams?.personId || searchObj?.salesStaffList?.value) ? 1 : 0,
queryScoure: 3
}
return obj
},
getStatic() {
let params = this.getParams()
delete params.potentialCustomersStatus
wx.$api.showLoading()
CustomerApi.getPotentialStatic(params).then(res => {
wx.$api.hideLoading()
this.setData({
dashboard: res || {}
}, () => {
this.recordTabTop()
})
})
},
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
})
})
},
chooseBoard(e) {
const { type } = e.currentTarget.dataset
if (type === 'month') {
// 打开月份选择器
this.openMonthPicker()
} else {
this.setData({ boardMonthActive: false, boardScopeActive: true }, () => {
this.getPageData()
})
}
},
openMonthPicker() {
this.setData({ monthPickerShow: true, pendingMonthValue: this.data.monthPickerValue })
},
closeMonthPicker() {
this.setData({ monthPickerShow: false })
},
popupConfirm() {
const val = this.data.pendingMonthValue || this.data.monthPickerValue
if (val) {
const d = new Date(val)
this.setData({
monthPickerValue: val,
boardMonthText: `${d.getMonth() + 1}月`,
boardMonthActive: true,
boardScopeActive: false
}, () => {
this.getPageData()
})
}
this.closeMonthPicker()
},
cancel() {
this.closeMonthPicker()
},
onMonthChange(e) {
const values = e.detail.getValues()
const year = Number(String(values?.[0] || '').replace(/[年月日时分]/g, ''))
const month = Number(String(values?.[1] || '').replace(/[年月日时分]/g, ''))
if (!year || !month) return
const ts = new Date(year, month - 1, 1).getTime()
this.setData({ pendingMonthValue: ts })
},
tabClick(e) {
const index = typeof e?.detail === 'number' ? e.detail : 0
this.setData({ statusIndex: index, copyCustomerList: [] }, () => {
this.resetAndLoad(() => {
this.triggerEvent('needScrollTop', this.data.initialTabTop)
})
})
},
resetAndLoad(cb) {
this.setData({ currentPage: 1, hasMore: true, copyCustomerList: [] })
this.loadMore(cb)
},
getMore() {
this.loadMore()
},
async loadMore(cb) {
let { hasMore, copyCustomerList } = this.data
if (!hasMore) return
this.setData({ loading: true })
try {
const { currentPage, pageSize } = this.data
const params = this.getParams()
wx.$api.showLoading()
const res = await CustomerApi.getPotentialList({ currentPage, pageSize, ...params })
wx.$api.hideLoading()
const nextList = res?.list || []
const total = res?.total || res?.count || 0
const pages = res?.pages || (total ? Math.ceil(total / pageSize) : null)
const hasMore = pages != null ? currentPage < pages : nextList.length === pageSize
const data = copyCustomerList.concat(nextList)
this.setData({
customerList: data,
copyCustomerList: data,
currentPage: currentPage + 1,
hasMore,
loading: false
})
cb && cb()
} catch (err) {
this.setData({ loading: false, hasMore: false })
}
},
// 新增潜客
jump(e) {
let { item, name } = e.currentTarget.dataset
if (name) { // 结果反馈
wx.navigateTo({
url: `/packageCustomer/pages/resultFeedback/resultFeedback?query=${encodeURIComponent(JSON.stringify(item))}`
})
} else { // 新增编辑潜客
wx.navigateTo({
url: item && Object.keys(item)?.length > 0 ? `/packageCustomer/pages/createPotential/createPotential?pageType=edit&query=${encodeURIComponent(JSON.stringify(item))}` : `/packageCustomer/pages/createPotential/createPotential?pageType=add`
})
}
},
// 潜客详情
goDetail(e) {
let { item } = e.currentTarget.dataset
wx.navigateTo({
url: `/packageCustomer/pages/potentialDetail/potentialDetail?query=${encodeURIComponent(JSON.stringify(item))}`
})
}
}
})