collegeScene.js
9.84 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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
// packageEquity/pages/collegeScene/collegeScene.js
import { staffInfo, orderPerformanceDetail, performancePassword, performancePasswordCheck } from '../../api'
import { ImgUrl } from '~/config.js'
// setConfigInfo
const app = getApp()
Page({
options: {
// multipleSlots: true, // 在组件定义时的选项中启用多 slot 支持
styleIsolation: 'shared' // 自定义覆盖vant样式
},
/**
* 页面的初始数据
*/
data: {
indicatorDots: true,
vertical: false,
autoplay: false,
interval: 2000,
duration: 500,
current: 0,
ImgUrl: ImgUrl + '/miniProgram/',
isStaff: true,
forbid: true,
hasStaffPassword: false,
passwordPop: false,
isSetPassword: true,
orderList: [],
orderListObj: [
{
label: '下单时间',
key: 'orderTimeLabel'
},
{
label: '支付时间',
key: 'paySuccessTimeLabel'
},
{
label: '客户姓名',
key: 'customerName'
},
{
label: '所属门店',
key: 'merchantName'
},
{
label: '转化员',
key: 'staffName'
},
{
label: '订单编号',
key: 'orderCode'
}
]
},
hideStaffInfo() {
// 判断是不是 员工,是关闭
let { isStaff } = this.data
if (isStaff) {
this.setData({
hasStaffPassword: false
})
}
},
bindchange(e) {
this.setData({ current: e.detail.current })
},
remarkConfirm() {
this.setData({
hasStaffPassword: true
})
},
viewPerformance() {
// 判断是第一次还是需要输入秘密
let { hasStaffPassword, staffInfoObj } = this.data
// if (userInfoObj.staffInfo.needSetPwd) {
this.setData({
passwordPop: true,
isSetPassword: staffInfoObj.staffInfo.needSetPwd
})
},
refresh() {
// console.log('refresh', refresh)
this.setData({
orderList: [],
currentPage: 0
})
this.orderPerformanceDetail()
},
onBottomRefresh() {
// console.log('onBottomRefresh')
let { currentPage, monthArray } = this.data
if (currentPage < monthArray.length - 1) {
this.setData({
currentPage: currentPage + 1
})
this.orderPerformanceDetail()
} else {
wx.$util.showToast('没有更多了')
}
},
orderPerformanceDetail() {
let { currentPage, monthArray, orderList } = this.data
let performanceMonth = monthArray[currentPage]
// console.log(performanceMonth, 'performanceMonth')
orderPerformanceDetail({ performanceMonth })
.then(res => {
console.log(res)
let { code, data } = res
if (code == 0 && data.performanceMonth) {
let [year, month] = data.performanceMonth.split('-')
data.year = year
data.month = month
data.orderList = data.orderList || []
data.orderList = data.orderList.map(item => {
item.orderGoodsName = item.orderGoodsName.split(',')
// console.log(orderTime, paySuccessTime, 'orderTime')
item.orderTimeLabel = wx.$util.tsFormatTime(item.orderTime, 'Y年M月D日 h:m:s')
item.paySuccessTimeLabel = wx.$util.tsFormatTime(item.paySuccessTime, 'Y年M月D日 h:m:s')
return item
})
data.orderList = data.orderList.slice(0, 100)
// wx.$util.tsFormatTime(data.orderTime, 'Y年M月D日 h:m:s')
orderList.push({ ...data })
// 当获取不到数据 无法触发scroll-view 触底加载 手动触发加载
if (!data?.orderList.length && currentPage < 2) { // 默认最近三个月数据
this.onBottomRefresh()
}
// console.log(data, 'data')
this.setData({
orderList,
triggered: false
})
}
})
.catch(err => {
console.log(err)
})
},
businessSchoolStaffInfo() {
wx.$util.showLoading('加载中...')
staffInfo({})
.then(res => {
// console.log(res)
let { userInfo } = this.data
let { code, data } = res
if (code == 0) {
if (userInfo.isSuper) {
data.staffInfo = {
entryDate: userInfo.createdDate,
staffName: userInfo.name
}
}
if (data.staffInfo?.entryDate) {
data.staffInfo.entryDate = wx.$util.tsFormatTime(data.staffInfo.entryDate, 'Y年M月D日')
}
data.monthPerformanceList = data.monthPerformanceList.map(item => {
item.performanceMonthLabel = this.extractMonth(item.performanceMonth)
item.height = item.staffDataList.length > 3 ? item.staffDataList.length * 70 + 120 : '300'
// console.log(Boolean(item.minimumWage && item.minimumWage > item.finalWage));
let currentMonthYear = wx.$util.tsFormatTime(new Date(), 'Y-M')
// 获取当前月份
if (currentMonthYear == item.performanceMonth) { // 当月预计工资提成
data.finalWage = item.staffDataList?.[0]?.performanceWage
}
item.staffDataList = item.staffDataList.map((childItem) => {
// 工资=最终工资finalWage-绩效提成performanceWage
childItem.wages = this.Subtr(childItem?.finalWage, childItem?.performanceWage)
// if (Boolean(childItem.minimumWage && childItem.minimumWage > childItem.finalWage)) {
// childItem.finalWage = childItem.minimumWage
// // item.performanceWage = 0
// childItem.hidePerformanceWage = true
// } else {
// childItem.finalWage = childItem.basicWage
// }
//
return childItem
})
// 处理基本工资和提成
// let [year, month] = item.performanceMonth.split('-')
// item.year = year
// item.month = month
return item
})
const titleLabel = {
0: '初级驻店',
1: '中级导师',
2: '高级导师'
}
// 取多场景下最高职级显示
data.staffInfo.titleLabel = userInfo.isSuper ? '超管' : titleLabel[Math.max(data.staffInfo.title)]
// 如果title是2,那导师就是员工自己
if (data.staffInfo.title) {
}
this.setData({
staffInfoObj: data
})
}
})
.catch(err => {
console.log(err)
})
.finally(() => {
// wx.stopPullDownRefresh()
wx.$util.hideLoading()
})
},
// 减法运算解决精度丢失问题
Subtr(num1, num2) {
var r1, r2, m, n
try {
r1 = num1.toString().split('.')[1].length
} catch (e) {
r1 = 0
}
try {
r2 = num2.toString().split(".")[1].length
} catch (e) {
r2 = 0
}
m = Math.pow(10, Math.max(r1, r2))
n = (r1 >= r2) ? r1 : r2
return ((num1 * m - num2 * m) / m).toFixed(n)
},
getDetailInfo() {
let monthArray = this.getYearMonthArray()
this.setData({
monthArray,
// pageSize: monthArray.length,
currentPage: 0
})
// console.log(monthArray, 'monthArray')
// 获取工资绩效员工信息及前3月绩效信息
this.businessSchoolStaffInfo()
//获取工资绩效员工订单绩效明细
this.orderPerformanceDetail()
},
// 获取月份
extractMonth(dateString) {
const regex = /(\d{4})-(\d{2})/
const match = regex.exec(dateString)
if (match && match.length >= 3) {
const year = parseInt(match[1])
const month = parseInt(match[2])
const monthString = `${month}月份`
return monthString
}
return null
},
// 获取年份
getYearMonthArray() {
let currentDate = new Date()
let startYear = currentDate.getFullYear()
let startMonth = currentDate.getMonth() + 1 // Add 1 to adjust for 0-based index
let endYear = 2023
let endMonth = 1
let yearMonthArray = []
while (startYear > endYear || (startYear === endYear && startMonth >= endMonth)) {
let formattedMonth = ('0' + startMonth).slice(-2) // Add leading zero if necessary
let yearMonth = startYear + '-' + formattedMonth
yearMonthArray.push(yearMonth)
startMonth--
if (startMonth === 0) {
startMonth = 12
startYear--
}
}
return yearMonthArray
},
back() {
// let { reLaunchPath } = this.data
// wx.$router.go(reLaunchPath)
wx.$router.back()
},
init(userInfo) {
const isStaff = app.globalData.isStaff
// let { userInfo } = this.data
// console.log(this.data, userInfo, 'userInfo')
this.setData({
isStaff: userInfo.isSuper ? false : isStaff,
hasStaffPassword: !isStaff ? true : false
})
this.getDetailInfo()
},
onRoute(options) {
// let { reLaunchPath, tabIndex } = options
// this.setData({
// reLaunchPath,
// tabIndex
// })
// console.log(options, 'options');
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) { },
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() { },
/**
* 生命周期函数--监听页面显示
*/
onShow(e) { },
/**
* 生命周期函数--监听页面隐藏
*/
onHide() { },
/**
* 生命周期函数--监听页面卸载
*/
onUnload() { },
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() { },
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() { },
/**
* 用户点击右上角分享
*/
onShareAppMessage() { }
})