mySpecialTaskList.js
2.34 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
import api from '~/api/index/index'
import dayjs from 'dayjs'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/supervisor-miniprogram/'
Page({
data: {
IMG_URL,
navBarHeight: 84,
statusMap: {
0: { name: '待完成', color: '#2C66F7', background: '#2c66f71a' },
1: { name: '已完成', color: '#35C376', background: '#35c3761a' }
},
list: [],
total: 0,
pageNum: 1,
pageSize: 10,
nothing: false,
flag: false
},
navbarReady(e) {
const navBarHeight = e.detail?.height
if (!navBarHeight) return
this.setData({ navBarHeight })
},
onLoad() {
this.reload()
},
onShow() {},
reload() {
this.setData(
{
list: [],
total: 0,
pageNum: 1,
nothing: false,
flag: false
},
() => {
this.getList(true)
}
)
},
onBottom() {
this.getList()
},
getList(reload) {
const { pageNum, pageSize, nothing } = this.data
if (nothing) return
const params = {
pageNum,
pageSize
}
wx.$util.showLoading()
api
.getSpecialTaskList(params)
.then(res => {
wx.$util.hideLoading()
const { code, data, message } = res || {}
if (code != 0) {
wx.$util.showToast(message || '加载失败')
this.setData({ flag: true })
return
}
const pageList = Array.isArray(data?.list) ? data.list : []
pageList.forEach(val => {
val.completeTime = val.completeTime ? dayjs(val.completeTime).format('YYYY-MM-DD HH:mm:ss') : ''
})
const nextList = reload ? pageList : this.data.list.concat(pageList)
const total = data?.total || 0
const isNothing = pageNum == data?.pages
this.setData({
list: nextList,
total,
pageNum: pageNum + 1,
nothing: !!isNothing,
flag: true
})
})
.catch(() => {
wx.$util.hideLoading()
this.setData({ flag: true })
})
},
viewDetail(e) {
const item = e.currentTarget?.dataset?.item || {}
wx.navigateTo({
url: `/packageIndex/pages/specialTaskApply/specialTaskApply?id=${item.id}`
})
},
goCreate() {
wx.navigateTo({
url: '/packageIndex/pages/specialTaskApply/specialTaskApply'
})
},
back() {
wx.navigateBack()
}
})