CustomerInfo.js
5.37 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
/**
* @file 客户档案选择弹框:分页拉取工单客户列表,不调 setData 外的页面实例。
*/
import api from '~/api/api.js'
import {
DEFAULT_PAGE_SIZE,
buildCustomerListRequestParams,
canLoadMorePage,
mapCustomerListWithCarType
} from './customerInfo.pagination.js'
Component({
properties: {
show: {
type: Boolean,
observer(n) {
if (n) {
wx.$util.pointRecord(19)
this.init()
return
}
this.resetList()
this.setData({ orderInfo: {} })
}
},
merchantId: {
type: Number,
observer(n) {
if (n) {
// 销售顾问切换门店时重新拉取顾客数据
this.init()
}
}
},
apiType: Number,
/** 调用页显式传入时才下发,null 保持其他消费者原查询口径 */
lowPriceFlag: {
type: null,
value: null
}
},
data: {
orderInfo: {},
customerList: [],
pageNum: 1,
total: 0,
nothing: false,
keyword: '',
loading: false
},
pageLifetimes: {
show() {},
hide() {}
},
methods: {
/** 阻止弹框列表滚到底后 touchmove 穿透到底层页面 */
noScroll() {},
/**
* 首次打开 / 搜索 / 切换门店入口,重置后加载第一页
* @param {string} [keyword] 搜索关键字
*/
init(keyword) {
const { apiType } = this.data
if (apiType == 2) {
this.loadCustomerFileList(keyword)
return
}
this.resetList(keyword)
this.loadList()
},
/**
* 重置分页状态(搜索或重新筛选时)
* @param {string} [keyword]
*/
resetList(keyword = '') {
this.setData({
pageNum: 1,
total: 0,
nothing: false,
keyword: keyword || '',
customerList: []
})
},
/**
* 按当前 pageNum 请求一页并追加到 customerList
*/
loadList() {
const { merchantId, pageNum, keyword, loading, lowPriceFlag } = this.data
if (loading) return
const userInfo = wx.$util.getUserInfo()
const params = buildCustomerListRequestParams({
merchantId,
fallbackMerchantId: userInfo?.shopMerchantId,
pageNum,
keyword,
lowPriceFlag
})
this.setData({ loading: true })
wx.$util.showLoading()
api.getWorkPackageGoodsList(params).then((res) => {
wx.$util.hideLoading()
const { data, code } = res
let { customerList, total } = this.data
if (code == 0 && data) {
total = data.total || 0
const pageItems = mapCustomerListWithCarType(data.list || [])
customerList = pageNum === 1 ? pageItems : customerList.concat(pageItems)
}
const nothing = !canLoadMorePage(total, pageNum, DEFAULT_PAGE_SIZE)
this.setData({
customerList,
total,
nothing,
loading: false
})
}).catch(() => {
wx.$util.hideLoading()
this.setData({ loading: false })
})
},
/**
* apiType=2 时走客户档案独立接口,保持原全量逻辑
* @param {string} [keyword]
*/
loadCustomerFileList(keyword) {
const { merchantId } = this.data
const userInfo = wx.$util.getUserInfo()
let customerList = []
wx.$util.showLoading()
api.getCustomerFileList({
currentPage: 1,
merchantId: merchantId || userInfo?.shopMerchantId,
pageSize: 999999,
search: keyword
}).then(({ code, data }) => {
wx.$util.hideLoading()
if (code == 0 && data?.list?.length) {
data.list.forEach((item) => {
customerList.push({
customer: item,
carType: `${item.carBrand || ''}-${item.carChildsBrandName || ''}-${item.carSeriesName || ''}`
})
})
}
this.setData({ customerList })
}).catch(() => {
wx.$util.hideLoading()
})
},
searchCar(e) {
const { value } = e.detail
this.init(value)
},
/** scroll-view 触底加载下一页 */
scrolltolower() {
const { total, pageNum, nothing, loading } = this.data
if (loading || nothing) return
if (canLoadMorePage(total, pageNum, DEFAULT_PAGE_SIZE)) {
this.setData({ pageNum: pageNum + 1 }, () => this.loadList())
} else {
this.setData({ nothing: true })
}
},
choose(e) {
const { item, index } = e.currentTarget.dataset
let { customerList } = this.data
customerList = customerList.map((row) => {
row.active = false
return row
})
customerList[index].active = true
const orderInfo = item
orderInfo.orderSource = 4
const deleteList = ['associateOrderCode', 'merchantDistributionList', 'expenseCategoryList', 'profitAllocatinList']
for (let i = 0; i < deleteList.length; i++) {
delete orderInfo[deleteList[i]]
}
this.setData({
customerList,
orderInfo
})
},
/** 取消时通知父页面关闭,便于 page-meta 解锁 */
onPopupCancel() {
this.triggerEvent('cancel')
},
confirm() {
const { orderInfo, customerList } = this.data
const flag = customerList.some((item) => item.active)
if (!flag) {
return wx.$util.showToast('请选择客户')
}
this.triggerEvent('confirm', orderInfo)
}
}
})