StoreSection.js
6.83 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
import { IMG_URL } from '~/utils/constantData'
import CustomerApi from '~/api/customerApi/index'
import dayjs from 'dayjs'
// 预计算安全的月份时间戳,避免初始 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: {
navBarHeight: Number,
searchObj: Object,
userInfo: Object,
personParams: Object
},
data: {
searchKeyword:'',
IMG_URL,
// 门店数据看板(示例数据)
boardMonthText: `${__NOW__.getMonth() + 1}月`,
boardScopeText: '全部',
boardMonthActive: true,
boardScopeActive: false,
// 月份选择器
monthPickerShow: false,
minMonthDate: __MIN_YM_TS__,
maxMonthDate: __CUR_YM_TS__,
monthPickerValue: __CUR_YM_TS__,
pendingMonthValue: 0,
// 列表与分页
storeList: [],
currentPage: 1,
pageSize: 10,
hasMore: true,
loading: false,
// 门店状态 TabBar
listTabs: ['全部', '新店', '老店','关店'],
statusIndex: 0
},
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 obj = {
merchantName: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,
storeType: statusIndex ? statusIndex : undefined,
isSuperior: userInfo.loginRole == 1 && (personParams?.personId || searchObj?.salesStaffList?.value) ? 1 : 0,
queryScoure: 3
}
return obj
},
getStatic() {
const params = this.getParams()
delete params.storeType
wx.$api.showLoading()
CustomerApi.getStoreStatic(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 })
},
// TabBar 点击(门店状态筛选)
tabClick(e) {
const index = typeof e?.detail === 'number' ? e.detail : 0
this.setData({ statusIndex: index, storeList: [] }, () => {
this.resetAndLoad(() => {
this.triggerEvent('needScrollTop', this.data.initialTabTop)
})
})
},
// 列表加载逻辑
resetAndLoad(cb) {
this.setData({ currentPage: 1, hasMore: true, storeList: [] })
this.loadMore(cb)
},
getMore() {
this.loadMore()
},
async loadMore(cb) {
let { hasMore } = 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.getStorePageList({ currentPage, pageSize, ...params })
wx.$api.hideLoading()
const nextList = (res.list || []).map(val => {
val.salesUser = val.salePersonnelInfoDTOList?.map(v => { return v.personnelName })?.join('/')
val.signedTime = val.signedTime ? dayjs(val.signedTime).format('YYYY-MM-DD') : ''
val.expectedOperationDate = val.expectedOperationDate ? dayjs(val.expectedOperationDate).format('YYYY-MM-DD') : ''
return val
})
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
this.setData({
storeList: this.data.storeList.concat(nextList),
currentPage: currentPage + 1,
hasMore,
loading: false
})
} catch (err) {
this.setData({ loading: false, hasMore: false })
}
cb && cb()
},
goDetail(e) {
let { item } = e.currentTarget.dataset
wx.navigateTo({
url: `/packageCustomer/pages/merchantDetail/merchantDetail?query=${encodeURIComponent(JSON.stringify(item))}`
})
}
}
})