PageScreen.js
8.38 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
// pages/tabWorkOrder/components/OrderScreen/OrderScreen.js
import { IMG_URL, SCENELIST, COOPERATIONMODELIST, TRSFFICSTATUSLIST } from '~/utils/constantData'
import CustomerApi from '~/api/customerApi/index'
Component({
/**
* 组件的属性列表
*/
properties: {
userInfo: Object,
navBarHeight: String,
show: {
type: Boolean,
observer: function (n, o) {
if (n) {
this.setViewData()
let { userInfo } = this.data
if (userInfo.loginRole == 1) {
// 总监获取销售人员数据
this.getSalesList()
// 总监获取省份数据
this.getAreaData()
}
const page = wx.$router.getPageInstance()
const criteria = (this.data.currentTab === 1 ? page.data?.storeSearchObj : page.data?.searchObj) || {}
this.applySelectedCriteria(criteria)
} else {
this.setData({
x: this.data.windowWidth
})
}
}
},
currentTab: Number
},
/**
* 组件的初始数据
*/
data: {
IMG_URL,
form: {
businessTypeList: [{
name: '全部',
active: true,
value: ''
}, ...SCENELIST],
cooperationModelList: [{
name: '全部',
active: true,
value: ''
}, ...COOPERATIONMODELIST],
trafficStatusList: [{
name: '全部',
active: true,
value: ''
}, ...TRSFFICSTATUSLIST],
provinces: [],
salesStaffList: [],
selectedMainBrand: []
},
salesStaffShowMore: false
},
/**
* 组件的方法列表
*/
methods: {
applySelectedCriteria(criteria = {}) {
const toVal = (item) => {
// 统一取值优先级:value > id > staffId > code > name
return item?.value ?? item?.id ?? item?.staffId ?? item?.code ?? item?.name
}
const setSingleActive = (list = [], selected) => {
const selectedVal = selected ? toVal(selected) : undefined
return (list || []).map((opt, idx) => {
const isAll = idx === 0 // “全部”项
const match = selectedVal !== undefined && toVal(opt) === selectedVal
return { ...opt, active: match ? true : (isAll && selectedVal === undefined) }
})
}
const setMultiActive = (list = [], selectedArr = []) => {
const selectedVals = Array.isArray(selectedArr) ? selectedArr.map(toVal).filter(v => v !== undefined) : []
const next = (list || []).map((opt, idx) => {
const isAll = idx === 0
const match = selectedVals.includes(toVal(opt))
return { ...opt, active: match ? true : false }
})
const anySelected = next.some((opt, idx) => idx !== 0 && opt.active)
// 如果多选为空,则激活“全部”
next[0] = { ...next[0], active: !anySelected }
return next
}
// 业务类型(多选)
const businessTypeList = setMultiActive(this.data.form.businessTypeList, criteria.businessTypeList)
// 合作模式 / 流量情况 / 省份 / 销售人员(单选)
const cooperationModelList = setSingleActive(this.data.form.cooperationModelList, criteria.cooperationModelList)
const trafficStatusList = setSingleActive(this.data.form.trafficStatusList, criteria.trafficStatusList)
const provinces = setSingleActive(this.data.form.provinces, criteria.provinces)
const salesStaffList = setSingleActive(this.data.form.salesStaffList, criteria.salesStaffList)
// 主营品牌(数组直接回填)
const selectedMainBrand = Array.isArray(criteria.selectedMainBrand) ? criteria.selectedMainBrand : []
this.setData({
'form.businessTypeList': businessTypeList,
'form.cooperationModelList': cooperationModelList,
'form.trafficStatusList': trafficStatusList,
'form.provinces': provinces,
'form.salesStaffList': salesStaffList,
'form.selectedMainBrand': selectedMainBrand,
isReset: false
})
},
setViewData() {
let { navBarHeight } = this.data
wx.$api.getViewInfo(
'.btn-box',
res => {
this.setData({
height: navBarHeight,
btnHeight: res[0].height
})
},
this
)
},
// 选择主营品牌
chooseCarBrand() {
this.setData({
carBrandPopupShow: true
})
},
getSalesList() {
CustomerApi.getSalesPersonList({}).then(res => {
res?.forEach(val => {
val.value = val.userId,
val.name = val.userName
})
res.unshift({
name: '全部',
active: true,
value: ''
})
this.setData({
'form.salesStaffList': res
}, () => {
const page = wx.$router.getPageInstance()
const criteria = (this.data.currentTab === 1 ? page.data?.storeSearchObj : page.data?.searchObj) || {}
this.applySelectedCriteria(criteria)
})
})
},
getAreaData() {
CustomerApi.getAreaTreeList({}).then(res => {
const data = res?.districts[0]?.districts
data.unshift({
name: '全部',
active: true,
value: ''
})
data?.forEach(v => {
v.value = v.code
})
this.setData({
'form.provinces': data
}, () => {
const page = wx.$router.getPageInstance()
const criteria = (this.data.currentTab === 1 ? page.data?.storeSearchObj : page.data?.searchObj) || {}
this.applySelectedCriteria(criteria)
})
})
},
showMore(e) {
let { type } = e.currentTarget.dataset
let prop = type
this.setData({
[prop]: !this.data[type]
})
},
choose(e) {
let { index, listName } = e.currentTarget.dataset
let target = this.data.form[listName]
// 多选
if (listName === 'businessTypeList') {
if (index == 0) {
target.forEach(i => i.active = false)
target[index].active = true
} else {
target[index].active = !target[index].active
target[0].active = false
if (!target.filter(val => val.active).length) target[0].active = true
}
} else {
target.forEach(i => {
i.active = false
})
target[index].active = true
}
this.setData({
[`form.${listName}`]: target,
isReset: false
})
},
reset() {
let { businessTypeList, cooperationModelList, trafficStatusList, provinces, salesStaffList } = this.data.form
const setActiveStatus = (list) => {
return list?.map((item, index) => ({
...item,
active: index === 0
}));
};
this.setData({
'form.businessTypeList': setActiveStatus(businessTypeList),
'form.cooperationModelList': setActiveStatus(cooperationModelList),
'form.trafficStatusList': setActiveStatus(trafficStatusList),
'form.provinces': setActiveStatus(provinces),
'form.salesStaffList': setActiveStatus(salesStaffList),
'form.selectedMainBrand': [],
isReset: true
})
},
brandConfirm() {
let brandMoudle = this.selectComponent('#car-brand')
this.setData({
'form.selectedMainBrand': brandMoudle && brandMoudle.handleConfirm() || []
})
this.hideBrandPopup()
},
hideBrandPopup() {
this.setData({
carBrandPopupShow: !this.data.carBrandPopupShow
})
},
handleChooseBrand() {
// wx.$router.go('packageMine.carBrandList')
this.hideBrandPopup()
},
confirm() {
let { form, isReset, currentTab } = this.data
let obj = {}
Object.keys(form).forEach(e => {
let arr = []
form[e]?.map(i => {
if (i.active) {
obj[e] = i
if (e == 'businessTypeList') {
arr.push(i)
obj[e] = arr
}
}
})
})
obj.selectedMainBrand = form.selectedMainBrand
let page = wx.$router.getPageInstance()
if (isReset) {
obj = {}
}
const currentTarget = currentTab == 0 ? 'searchObj' : 'storeSearchObj'
page.setData({
[currentTarget]: obj
})
page.back()
page.search()
}
},
attached() {
wx.$api.getSystemInfo(info => {
let { windowWidth } = info
this.setData({
x: windowWidth,
windowWidth
})
})
}
})