TotalTab.js
6.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
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
// pages/tab/output/components/TotalTab/TotalTab.js
import { scenceList } from '~/pages/tab/index/constant/data'
const busiOptSceneCode = ['-1', 'SC002', 'SC004', 'SC001', 'SC003']
import outputApi from '~/api/outputApi/index'
import { getNowMonth } from '~/utils/format'
Component({
/**
* 组件的属性列表
*/
properties: {
},
/**
* 组件的初始数据
*/
data: {
busiOptSceneCode,
tabActive: 'store',
// tabActive: 'business',
formData: {
// 0:全部-1;1:精品升级SC002;2:售后众筹SC004;3:会员权益/升级SC001
busiIdx: 0,
sceneCode: '-1',
// 时间筛选Idx(全部,精品升级,会员权益)
timeIdx: 0,
// 产品/状态筛选Idx(售后众筹)
proIdx: 0,
statusIdx: 0
},
// 众筹-筛选
isCrowdPopupShow: false,
crowdFormData: {
proIdx: 0,
statusIdx: 0
},
baseData: {
busiList: [],
proList: [],
timeList: ['全部', '本月', '本日'],
actStatusList: ['全部', '申请中', '活动中', '已结束']
}
},
lifetimes: {
attached() {
this.initTime()
this.dealBusiList()
this.getProList('SC004')
}
},
/**
* 组件的方法列表
*/
methods: {
resetBusiSearch() {
this.setData({
['formData.timeIdx']: 0,
['formData.proIdx']: 0,
['formData.statusIdx']: 0
})
},
getProList(sceneCode) {
var params = {
sceneCode: sceneCode
}
outputApi.findProByScene(params).then(res => {
let list = res[0]?.productList || []
list.unshift({
productCode: '',
productName: '全部'
})
this.setData({
['baseData.proList']: list
})
})
},
dealBusiList() {
let list = [{
name: '全部',
sceneCode: '-1'
}]
busiOptSceneCode.forEach(item => {
let _target = scenceList.find(k => k.sceneCode == item)
if (_target) {
list.push({
name: _target.name,
sceneCode: _target.sceneCode
})
}
})
this.setData({
['baseData.busiList']: list
})
},
handleSet(e) {
let { attr, val } = e.currentTarget.dataset
this.setData({
[attr]: val
})
this.triggerEvent('tabChange', { tabActive: val })
},
handleClickTab(e) {
let { tabActive, baseData: { busiList } } = this.data
// 切换tab
if (tabActive != 'business') {
this.handleSet(e)
// this.handleSearch()
return true
}
// 筛选
wx.showActionSheet({
itemList: busiList.map(item => item.name),
success: res => {
this.resetBusiSearch()
this.setData({
['formData.busiIdx']: res.tapIndex,
['formData.sceneCode']: busiOptSceneCode[res.tapIndex]
})
this.handleBusiSearch()
}
})
},
handleTimeChange(e) {
let { scenecode } = e.currentTarget.dataset
let { baseData: { timeList, actStatusList } } = this.data
wx.showActionSheet({
itemList: scenecode == 'SC003' ? actStatusList : timeList,
success: res => {
if (scenecode == 'SC003') {
this.setData({
['formData.statusIdx']: res.tapIndex
})
} else {
this.setData({
['formData.timeIdx']: res.tapIndex
})
}
this.handleBusiSearch()
}
})
},
// 众筹-筛选
handlePopupConChange(e) {
let { idx, attr } = e.currentTarget.dataset
this.setData({
[`crowdFormData.${attr}`]: idx
})
},
handleCrowdPopup() {
let { formData: { proIdx, statusIdx } } = this.data
this.setData({
['crowdFormData.proIdx']: proIdx,
['crowdFormData.statusIdx']: statusIdx,
isCrowdPopupShow: !this.data.isCrowdPopupShow
})
},
handleCrowdConfirm() {
let { crowdFormData: { proIdx, statusIdx } } = this.data
this.setData({
['formData.proIdx']: proIdx,
['formData.statusIdx']: statusIdx,
isCrowdPopupShow: !this.data.isCrowdPopupShow
})
this.handleBusiSearch()
},
// 格式化时间
initTime() {
let date = new Date()
let today = date.getDate()
let month = getNowMonth()
const todayTime = {
startTime: `${month}-${today} 00:00:00`,
endTime: `${month}-${today} 23:59:59`
}
const monthTime = {
startTime: `${month}-01 00:00:00`,
endTime: `${month}-${today} 23:59:59`
}
const defaultTime = {
startTime: '',
endTime: `${month}-${today} 23:59:59`
}
this.setData({
dataObj: {
todayTime,
monthTime,
defaultTime
}
})
},
dealSearchTime() {
let { dataObj, formData } = this.data
var params = {}
switch (formData.timeIdx) {
// 本月
case 1:
params = dataObj.monthTime
break
// 本日
case 2:
params = dataObj.todayTime
break
}
return params
},
dealSearchStatus() {
let { formData } = this.data
var activityStatuList = []
let activityStatus = ''
switch (formData.statusIdx) {
case 0:
activityStatuList = [1, 2, 3]
break
// 申请中
case 1:
activityStatuList = [1]
activityStatus = '1'
break
// 活动中
case 2:
activityStatuList = [2]
activityStatus = '2'
break
// 已结束
case 3:
activityStatuList = [3]
activityStatus = '3'
break
}
return {
activityStatuList,
activityStatus
}
},
dealSearchCrowd() {
let params = []
let { formData, baseData: { proList } } = this.data
let attrToNum = {
'PC005': 1,
'PC006': 2,
'PC007': 3,
'PC008': 4,
'PC009': 5
}
if (formData.sceneCode == 'SC003') {
params.activityStatus = this.dealSearchStatus().activityStatus
} else if (formData.busiIdx == 2 && formData?.proIdx) {
params.categoryList = [attrToNum[proList[formData?.proIdx].productCode] || '-1']
params.activityStatusList = this.dealSearchStatus().activityStatusList
}
return params
},
dealParams() {
let { formData } = this.data
let params = {
type: formData.busiIdx || '',
...this.dealSearchTime(),
...this.dealSearchCrowd()
}
return params
},
handleBusiSearch() {
this.triggerEvent('busiSearch')
}
}
})