customerInfo.pagination.js
2.1 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
/**
* @file 客户档案弹框分页纯函数,供 CustomerInfo 组件与单测复用。
*/
/** 客户档案弹框每页条数 */
const DEFAULT_PAGE_SIZE = 20
/**
* 构建按工单查询客户档案的分页参数。
* lowPriceFlag 仅在调用页显式传 0 或 1 时下发,避免改变共享组件其他消费者的查询口径。
*
* @param {Object} options 查询上下文
* @param {number|string} [options.merchantId] 组件传入的门店 ID
* @param {number|string} [options.fallbackMerchantId] 当前登录用户的门店 ID
* @param {number} options.pageNum 当前页码
* @param {string} [options.keyword] 搜索关键字
* @param {number|string|null} [options.lowPriceFlag] 低价工单查询标记;null/undefined 不下发
* @returns {Object} getWorkPackageGoodsList 请求参数
*/
function buildCustomerListRequestParams({
merchantId,
fallbackMerchantId,
pageNum,
keyword = '',
lowPriceFlag
}) {
const params = {
merchantId: merchantId || fallbackMerchantId,
pageNum,
pageSize: DEFAULT_PAGE_SIZE,
statusList: [1],
keyword
}
if ([0, 1, '0', '1'].includes(lowPriceFlag)) {
params.lowPriceFlag = Number(lowPriceFlag)
}
return params
}
/**
* 是否还能加载下一页(与工单首页 onReachBottom 判断一致)
* @param {number} total 总条数
* @param {number} pageNum 当前已加载页码
* @param {number} [pageSize=20] 每页条数
* @returns {boolean}
*/
function canLoadMorePage(total, pageNum, pageSize = DEFAULT_PAGE_SIZE) {
if (!total || !pageNum) return false
return Math.ceil(total / pageSize) > pageNum
}
/**
* 为订单列表项补充车型展示字段
* @param {Array} list 接口返回的 list
* @returns {Array}
*/
function mapCustomerListWithCarType(list) {
if (!list?.length) return []
return list.map((item) => {
if (item.customer?.carSeriesName) {
item.carType = `${item.customer.carBrand || ''}-${item.customer.carChildsBrandName || ''}-${item.customer.carSeriesName || ''}`
}
return item
})
}
export {
DEFAULT_PAGE_SIZE,
buildCustomerListRequestParams,
canLoadMorePage,
mapCustomerListWithCarType
}