ScreenConfirmBox.js
8.74 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
// pages/tab/output/components/ScreenConfirmBox/ScreenConfirmBox.js
import USERAPI from '~/api/usersApi/index'
import outputValueApi from '~/api/outputValueApi/index'
import { setUserInfo } from '~/utils/cache/storageApi'
Component({
/**
* 组件的属性列表
*/
properties: {
tabBarStyle: String,
formData: Object,
show: {
type: Boolean,
observer: function (n, o) {
if (n) {
const thisPage = wx.$router.getPageInstance()
thisPage.setData({
isShowFilterScreen: true
})
// if (!this.data.formData.startTime || !this.data.formData.endTime) this.setDate() // 默认展示当前月份
this.setViewData()
}
}
},
tabType: Number, // tab值 0我的门店 1我的员工
userInfo: Object,
statusBarHeight: Number,
navigationBarHeight: Number
},
/**
* 组件的初始数据
*/
data: {
servicePopupShow: false,
merchantRange: [],
sceneList: [
{
id: '',
label: '全部',
active: true
},
{
id: '1',
label: '太阳膜'
},
{
id: '3',
label: '售后众筹'
},
{
id: '0',
label: '会员权益/升级'
}
],
staffList: [],
isShowCalendarMonth: true // 重置重新渲染日历组件 没有传值回显日期功能
},
/**
* 组件的方法列表
*/
methods: {
setViewData() {
let { tabBarStyle } = this.data
wx.$api.getViewInfo(
'.btn-box',
res => {
this.setData({
height: tabBarStyle,
btnHeight: res[0]?.height
})
},
this
)
},
getMerchantRange() {
let { userInfo } = this.data
// 判断是超管才需要切换账号
if (userInfo?.isSuper) {
USERAPI.adminSelectLogin()
.then(result => {
let { merchantList: merchantRange } = result
merchantRange.forEach((item, index) => {
item.show = true
})
this.setData({
merchantRange
})
})
.catch(err => { })
} else {
let merchantRange = [{ merchantId: userInfo?.subLoginUser?.merchantId, merchantName: userInfo?.subLoginUser?.merchantName }]
this.setData({
merchantRange
})
}
},
changeMerchantRange(e) {
let { merchantRange, subIndex, formData } = this.data
let { merchantId } = e.detail
this.reset('', false)
merchantRange.forEach((item, index) => {
item.show = true
if (item.merchantId == merchantId) {
subIndex = index
item.act = true
}
})
formData.partnerMerchantIds = [merchantId]
// if (!this.data.formData.startTime || !this.data.formData.endTime) this.setDate() // 未选择时间默认展示当前月份
this.setData({
merchantRange,
subIndex,
formData
})
this.getStaffList()
this.servicePicker()
},
// 服务商切换
servicePicker() {
let { userInfo } = this.data
if (!userInfo?.isSuper) return
this.setData({
servicePopupShow: !this.data.servicePopupShow
})
},
// 月份确定
dateRangeSelect(e) {
let { start, end } = e.detail.date
let { formData } = this.data
let [year, month] = end.split('-')
let day = this.getLastDay(year, month)
formData.startTime = start + '-01' + ' 00:00:00'
formData.endTime = end + '-' + day + ' 23:59:59'
this.setData({
formData
})
},
setDate() {
let { formData } = this.data
let month = new Date().getMonth() + 1
let year = new Date().getFullYear()
let day = this.getLastDay(year, month)
formData.startTime = year + '-' + month + '-01' + ' 00:00:00'
formData.endTime = year + '-' + month + '-' + day + ' 23:59:59'
this.setData({
formData
})
},
getLastDay(year, month) {
var new_year = year //取当前的年份
var new_month = month++ //取下一个月的第一天,方便计算(最后一天不固定)
if (month > 12) {
new_month -= 12 //月份减
new_year++ //年份增
}
var new_date = new Date(new_year, new_month, 1) //取当年当月中的第一天
return new Date(new_date.getTime() - 1000 * 60 * 60 * 24).getDate() //获取当月最后一天日期
},
// 员工数据
getStaffList() {
let { partnerMerchantIds } = this.data.formData
let { userInfo } = this.data
console.log(partnerMerchantIds, 'partnerMerchantIds')
let params = {
partnerMerchantIds: partnerMerchantIds.length ? partnerMerchantIds : userInfo?.subLoginUser?.merchantId
}
outputValueApi.GETALLSTAFFDATAAPI(params).then(res => {
let arr = res || []
if (!arr?.length || arr[0]?.staffName !== '全部') {
arr.unshift({
active: true,
uuid: '',
staffName: '全部'
})
}
this.setData({
staffList: arr
})
})
},
init() {
this.getMerchantRange()
this.getStaffList() // 我的员工有员工筛选条件
},
choose(e) {
let { index, listName } = e.currentTarget.dataset
let { formData } = this.data
let target = this.data[listName]
switch (listName) {
case 'staffList':
if (index == 0) { // 选择全部
target.map(i => (i.active = false))
target[index].active = true
} else {
target[index].active = !target[index].active
target[0].active = false
}
let activeFlag = target.findIndex(val => val.active)
if (activeFlag < 0) target[0].active = true
break
case 'sceneList':
target.map(i => (i.active = false))
target[index].active = true
formData.sceneType = target[index]?.id
this.setData({
formData
})
break
}
this.setData({
[`${listName}`]: target,
isReset: false
})
},
// 日期组件
showCalendar(e) {
let calendarMonthModule = this.selectComponent('#calendarMonth')
calendarMonthModule.showCalendar && calendarMonthModule.showCalendar(e)
},
confirm() {
if (this.data.screenConfirmFlag) return
wx.$api.showLoading('加载中')
let { userInfo, formData, staffList, sceneList } = this.data
formData.sceneType = sceneList.filter(val => val.active)[0]?.id || ''
let staffArr = []
staffList.filter(val => val.active).map(subVal => {if (subVal.uuid) staffArr.push(subVal.uuid)})
formData.staffUUIDs = staffArr
this.triggerEvent('screenFlag')
this.setData({screenConfirmFlag: true})
const thisPage = wx.$router.getPageInstance()
if (formData?.partnerMerchantIds[0] !== userInfo.subLoginUser.merchantId) {
USERAPI.switchSubLoginInfo({ merchantId: formData?.partnerMerchantIds[0] }).then(res => {
setUserInfo(res)
wx.$api.hideLoading()
// 切换服务商 清空已选的门店
formData.shopMerchantIds = []
formData.shopMerchantNames = '全部门店'
// 获取服务商下门店
this.triggerEvent('changeService')
thisPage.setData({
screenFormData: formData,
})
thisPage.searchEvent()
this.setData({ screenConfirmFlag: false })
})
} else {
wx.$api.hideLoading()
thisPage.setData({
screenFormData: formData
})
thisPage.searchEvent()
this.setData({ screenConfirmFlag: false })
}
},
reset(e, isresetTime = true) {
let { formData, userInfo, sceneList, staffList, tabType, merchantRange, subIndex } = this.data
formData.partnerMerchantIds = [userInfo?.merchantId]
if (isresetTime) {
formData.startTime = ''
formData.endTime = ''
}
if (e) this.getStaffList() // 点击重置
// this.setDate()
// this.setData({
// isShowCalendarMonth: false
// })
formData.sceneType = ''
formData.staffUUIDs = []
if (tabType == 0) {
sceneList.map(val => val.active = false)
sceneList[0].active = true
} else if (tabType == 1) {
staffList.map(val => val.active = false)
staffList[0].active = true
}
merchantRange.forEach((item, index) => {
item.show = true
if (item.merchantId == userInfo?.merchantId) {
subIndex = index
}
})
this.setData({
formData,
sceneList,
staffList,
merchantRange,
subIndex,
isShowCalendarMonth: true
})
}
},
attached() {
this.init()
}
})