timepicker.js
5.7 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
// component/time-picker/index.js
let utils = require("../../utils/util.js")
let method = require("../../utils/reuqest.js")
const app = getApp()
Component({
data: {
deliveryTime: "",
selfData: [], //自提日期
showDelivery: false,
list: [], //自提时间数组
nowDay: 0,
selectTime: '', //自提时间
selectTimeIndex: '',
selectDay: 0,
},
pageLifetimes: {
show: function () {
this.getDliveryTime()
}
},
properties: {
timeLists: {
type: Array,
value: true
}
},
/**
* 组件的方法列表
*/
lifetimes: {
created() {
let _this = this;
if (_this.data.nowDay == 0) {
method.getRequest("/myUser/period/" + '1', data => {
//let list=this
if (data.statusCode == 0) {
_this.setData({
list: data.data
})
}
console.log(_this.data.nowDay, 'now')
console.log(_this.data.deliveryTimeList, 'list')
})
} else {
method.getRequest("/myUser/period/" + '2', data => {
if (data.statusCode == 0) {
_this.setData({
list: data.data
})
}
console.log(_this.data.nowDay, 'now')
console.log(_this.data.deliveryTimeList, 'list')
})
}
},
attached() {
console.log("在组件实例进入页面节点树时执行")
},
ready() {
console.log("在组件在视图层布局完成后执行")
},
moved() {
console.log("在组件实例被移动到节点树另一个位置时执行")
},
detached() {
console.log("在组件实例被从页面节点树移除时执行")
},
error() {
console.log("每当组件方法抛出错误时执行")
},
},
methods: {
getnowDay(e) {
this.setData({
nowDay: e.currentTarget.dataset.index
})
console.log(this.data.nowDay, 'nowday')
let _this = this;
if (_this.data.nowDay == 0) {
method.getRequest("/myUser/period/" + '1', data => {
if (data.statusCode == 0) {
_this.setData({
list: data.data
})
}
console.log(_this.data.nowDay, 'now')
console.log(_this.data.deliveryTimeList, 'list')
})
} else {
method.getRequest("/myUser/period/" + '2', data => {
//let list=this
if (data.statusCode == 0) {
_this.setData({
list: data.data
})
}
console.log(_this.data.nowDay, 'now')
console.log(_this.data.deliveryTimeList, 'list')
})
}
},
clickTime(e) {
let selfData = this.data.selfData[this.data.nowDay]
let id = e.currentTarget.dataset.id;
let index = e.currentTarget.dataset.index;
let _this = this;
let deliveryTime = selfData.year + '-' + selfData.month + '-' + selfData.day + ' '
let nowDay = this.data.nowDay
this.setData({
selectTimeIndex: index,
// selectTime: selectTime,
deliveryTime: deliveryTime,
selectDay: nowDay
})
this.data.list.map((item, index) => {
if (item.id === id) {
let times = item.start + '-' + item.end
_this.triggerEvent('selectTime', {
time: times,
flag: false,
timeId: item.id,
deliveryTime: this.data.deliveryTime
})
wx.setStorageSync('selecClick', true)
}
})
},
//计算配送时间
getDliveryTime() {
let that = this;
let deliveryTimeList = [];
let date = new Date();
this.setData({
selfData: utils.getDates(5)
})
//获取时间段
let timeDate = new Date(date.getTime());
// let todayList = getTimeList(timeDate.getHours(), 1);
// deliveryTimeList.push({
// timeList: todayList
// });
// let nextDayList = getTimeList(9, 0);
// for (let i = 1; i < 5; i++) {
// deliveryTimeList.push({
// timeList: nextDayList
// });
// }
// this.triggerEvent('selectTime', {
// deliveryTime: this.data.deliveryTime
// })
// this.setData({
// deliveryTimeList: []
// })
// this.setData({
// deliveryTimeList: deliveryTimeList
// })
//获取时间段
// today 1 是今天 0 不是今天
// function getTimeList(hour, today) {
// let timeList = [];
// // let startTime = hour <= 9 ? 9 : hour;
// // for (let i = 0; i < 8; i++) {
// // if (((hour <= 9) && (startTime + 2 * i >21)) || ((hour > 9) && (startTime + 2 * i >= 21))) {
// // break;
// // } else {
// // if (hour <= 9) {
// // timeList.push(
// // startTime + 2 * i + ":00" + "-" + (startTime + 2 * (i + 1)) + ":00"
// // );
// // } else {
// // if (startTime % 2 === 0) {
// // timeList.push(
// // startTime + 2 * i + 1 + ":00" + "-" + (startTime + 2 * i + 3) + ":00"
// // );
// // } else {
// // console.log(i,'i')
// // timeList.push(
// // startTime + 2 * i +2 + ":00" + "-" + (startTime + 2 * i + 4) + ":00"
// // );
// // }
// // }
// // }
// // }
// method.getRequest("/myUser/period/" + '1', data => {
// if (data.statusCode == 0) {
// that.setData({
// deliveryTimeList: data.data
// })
// timeList = data.data
// }
// })
// return timeList;
// }
}
}
})