DatePicker.js
3.11 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
// components/DatePicker/DatePicker.js
import api from '../../api/api'
Component({
/**
* 组件的属性列表
*/
properties: {
show: {
type: Boolean,
observer: function (n) {
if (n) {
this.setDayList()
}
}
},
merchantId: null
},
/**
* 组件的初始数据
*/
data: {
dayIndex: 0,
timeIndex: 0,
},
/**
* 组件的方法列表
*/
methods: {
noScroll(){},
hide(e) {
let {
name
} = e.currentTarget.dataset
let thisPage = wx.$router.getPageInstance()
thisPage.setData({
[name]: false
})
},
getInviteDateList(date) {
let {
merchantId
} = this.data
api.getInviteDateList({
merchantId,
...date
}).then(res => {
wx.hideLoading()
let {
code,
data,
message
} = res
let timeList = []
if (code == 0) {
let now = new Date()
data.map(e => {
e.timeStats.map(i => {
let inviteDate = i.inviteDate.replace(/\-/g,'/')
let invite_Date = new Date(`${inviteDate} ${i.inviteEndTime}:59`)
i.disabled = invite_Date < now
timeList.push(i)
})
})
} else {
wx.$util.showToast(message)
}
this.setData({
timeList
})
console.log(res)
})
},
setDayList() {
let now = new Date()
let days = []
for (let i = 0; i < 31; i++) {
let day = new Date().setDate(now.getDate() + i)
let value = new Date(day).format('yyyy-MM-dd')
days.push({
name: i == 0 ? '今天' : i == 1 ? '明天' : value,
value
})
}
this.setData({
days
})
this.getInviteDateList({
startDate: now.format('yyyy-MM-dd'),
endDate: now.format('yyyy-MM-dd'),
})
},
confirm() {
let thisPage = wx.$router.getPageInstance()
let {
dayIndex,
timeIndex,
timeList,
days,
} = this.data
let timeItem = timeList[timeIndex]
if (timeItem.disabled) {
wx.$util.showToast('该时段已过预约时间')
return
}
if(timeItem.maxNum == 0 ){
wx.$util.showToast('该时段不可约')
return
}
if (timeItem.maxNum == timeItem.inviteNum) {
wx.$util.showToast('该时间段已约满')
return
}
thisPage.setData({
inviteDateStr: `${days[dayIndex].value} ${timeItem.inviteTime}:00`
})
wx.$util.showLoading('预约中...')
thisPage.setInviteDate()
},
changeDate(e) {
console.log(e)
let {
days
} = this.data
let [index] = e.detail.value
wx.$util.showLoading('查询中...')
this.getInviteDateList({
startDate: days[index].value,
endDate: days[index].value,
})
this.setData({
dayIndex: index
})
},
changeTime(e) {
let [index] = e.detail.value
this.setData({
timeIndex: index
})
},
}
})