today-plan-customer-popup.js
5.69 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
/**
* 洽谈明细 — 今日计划到店客户多选弹层
* @file 底部弹层:日期切换、多选列表、确认导入
*/
const negotiationApi = require('../../api/negotiationDailyReport.js')
const {
formatPlanStoreDateLabel,
shiftPlanStoreDate,
canShiftPlanStoreDate,
formatCustomerCarSeriesLabel,
maskCustomerPhone
} = require('../../services/today-plan-date.js')
var timeUtil = require('~/utils/timeFormat/time-utils.js')
const {
buildWeappIconUrl,
TODAY_PLAN_CHECK_ICON
} = require('../../utils/upgrade-icon-url.js')
Component({
properties: {
/** 父页控制显隐;true 时打开弹层并重置为 anchorDate */
show: {
type: Boolean,
value: false,
observer(n) {
if (n) {
this.openPopup()
}
}
},
/** 周历选中日(弹层日期锚点,默认今天) */
anchorDate: {
type: String,
value: ''
},
/** 4S 店商户号 */
merchantId: {
type: String,
value: ''
},
/** 驻店零售员工 id(staffUuid) */
advanceUserId: {
type: String,
value: ''
},
staffName: {
type: String,
value: ''
}
},
data: {
visible: false,
currentDate: '',
dateLabel: '',
canPrev: false,
canNext: false,
customerList: [],
selectedCount: 0,
isAllSelected: false,
loading: false,
loadComplete: false,
isFullSucreen: false,
checkIconUrl: ''
},
methods: {
noScroll() {},
/** 解析弹层日期锚点(周历选中日,缺省为今天) */
resolveAnchorDate() {
return this.properties.anchorDate || timeUtil.getTodayDateStr()
},
/** 打开弹层并重置为锚点日 */
openPopup() {
const anchorDate = this.resolveAnchorDate()
this.setData({
visible: true,
currentDate: anchorDate,
customerList: [],
selectedCount: 0,
isAllSelected: false,
loadComplete: false
})
this.syncDateNavState(anchorDate)
this.loadCustomerList(anchorDate)
},
/** 同步日期导航按钮与文案 */
syncDateNavState(dateStr) {
const anchorDate = this.resolveAnchorDate()
this.setData({
dateLabel: formatPlanStoreDateLabel(dateStr, anchorDate),
canPrev: canShiftPlanStoreDate(dateStr, -1, anchorDate),
canNext: canShiftPlanStoreDate(dateStr, 1, anchorDate)
})
},
/** 拉取当前日期客户列表 */
async loadCustomerList(inviteDate) {
const { merchantId, advanceUserId } = this.properties
if (!merchantId || !advanceUserId || !inviteDate) {
this.setData({ customerList: [], loadComplete: true, loading: false })
return
}
this.setData({ loading: true, loadComplete: false })
try {
const res = await negotiationApi.fetchTodayPlanStoreList({
merchantId,
advanceUserId,
inviteDate
})
const list = (res.code === 0 ? res.data : []) || []
const customerList = list.map((item, index) => ({
...item,
_rowKey: `${inviteDate}_${index}`,
selected: false,
carSeriesLabel: formatCustomerCarSeriesLabel(item),
phoneMasked: maskCustomerPhone(item.customerPhone)
}))
this.setData({
customerList,
selectedCount: 0,
isAllSelected: false,
loadComplete: true
})
} catch (error) {
console.error(error)
wx.$util?.showToast?.('加载客户列表失败')
this.setData({ customerList: [], loadComplete: true })
} finally {
this.setData({ loading: false })
}
},
onMaskTap() {
this.closePopup()
},
onCancel() {
this.closePopup()
},
/** 关闭弹层并通知父页 */
closePopup() {
this.setData({ visible: false })
this.triggerEvent('cancel')
},
onPrevDay() {
const anchorDate = this.resolveAnchorDate()
const next = shiftPlanStoreDate(this.data.currentDate, -1, anchorDate)
if (!next) return
this.changeDate(next)
},
onNextDay() {
const anchorDate = this.resolveAnchorDate()
const next = shiftPlanStoreDate(this.data.currentDate, 1, anchorDate)
if (!next) return
this.changeDate(next)
},
/** 切换日期:清空勾选并重新拉列表 */
changeDate(dateStr) {
this.setData({
currentDate: dateStr,
customerList: [],
selectedCount: 0,
isAllSelected: false
})
this.syncDateNavState(dateStr)
this.loadCustomerList(dateStr)
},
/** 切换单条客户勾选 */
onToggleItem(e) {
const index = e.currentTarget.dataset.index
const list = [...this.data.customerList]
if (!list[index]) return
list[index] = { ...list[index], selected: !list[index].selected }
this.updateSelectionState(list)
},
/** 全选 / 取消全选 */
onToggleAll() {
const { customerList, isAllSelected } = this.data
if (!customerList.length) return
const nextAll = !isAllSelected
const list = customerList.map(item => ({ ...item, selected: nextAll }))
this.updateSelectionState(list)
},
/** 同步 selectedCount、isAllSelected 到 data */
updateSelectionState(customerList) {
const selectedCount = customerList.filter(item => item.selected).length
const isAllSelected =
customerList.length > 0 && selectedCount === customerList.length
this.setData({ customerList, selectedCount, isAllSelected })
},
/**
* 确认导入:向父页派发 confirm,剥离 UI 衍生字段
* @fires confirm detail.customers 原始客户对象数组
*/
onConfirm() {
const selected = this.data.customerList.filter(item => item.selected)
if (!selected.length) return
const payload = selected.map(({ selected: _s, _rowKey, carSeriesLabel, phoneMasked, ...rest }) => rest)
this.setData({ visible: false })
this.triggerEvent('confirm', { customers: payload })
}
},
/** 生命周期:安全区与勾选 CDN 图标(根目录 check.png) */
attached() {
this.setData({
isFullSucreen: wx.$util?.isFullSucreen?.(true) || false,
checkIconUrl: buildWeappIconUrl(TODAY_PLAN_CHECK_ICON)
})
}
})