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
Component({
mixins: [],
data: {
timeData: [],
timeHour: ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09','10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23'],
timeMin: ['00', '05', '10', '15', '20', '25', '30', '35', '40', '45', '50', '55'],
pickerValue: [],
time: ''
},
props: {
isShowModal: 'false'
},
didMount() {
let timeData = [];
for(let i=365;i>=0;i--) {
timeData.push(this.GetDateStr(-i));
}
for(var i=1;i<365;i++){
timeData.push(this.GetDateStr(i));
}
this.setData({
timeData: timeData
})
},
didUpdate() {
var date = new Date(this.props.time);
var y = date.getFullYear();
var m = (date.getMonth()+1)<10?"0"+(date.getMonth()+1):(date.getMonth()+1);//获取当前月份的日期,不足10补0
var d = date.getDate()<10?"0"+date.getDate():date.getDate();//获取当前几号,不足10补0
var weekList = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
var w = weekList[date.getDay()];
var h = date.getHours()<10? "0"+date.getHours() : date.getHours();
var min = date.getMinutes()<10? "0"+date.getMinutes() :date.getMinutes();
var pickerValue = [this.data.timeData.indexOf(y+"/"+m+"/"+d+" "+w),this.data.timeHour.indexOf(`${h}`),this.data.timeMin.indexOf(`${min}`)]
this.setData({
pickerValue: pickerValue,
time: this.props.time
})
},
didUnmount() {},
methods: {
showModal(e) {
console.log(e)
},
onCancel(e) {
this.props.onChange({status: 0})
},
GetDateStr(AddDayCount) {
var time = new Date();
time.setDate(time.getDate()+AddDayCount);//获取AddDayCount天后的日期
var y = time.getFullYear();
var m = (time.getMonth()+1)<10?"0"+(time.getMonth()+1):(time.getMonth()+1);//获取当前月份的日期,不足10补0
var d = time.getDate()<10?"0"+time.getDate():time.getDate();//获取当前几号,不足10补0
var weekList = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
var w = weekList[time.getDay()]
return y+"/"+m+"/"+d+" "+w;
},
onDetermine(e) {
this.props.onChange({status: 1, time: this.data.time})
},
onChange(e) {
console.log(e)
let index = e.detail.value
this.props.time = `${this.data.timeData[index[0]].slice(0,10)} ${this.data.timeHour[index[1]]}:${this.data.timeMin[index[2]]}`
this.setData({
time: `${this.data.timeData[index[0]].slice(0,10)} ${this.data.timeHour[index[1]]}:${this.data.timeMin[index[2]]}`
})
console.log(this.data.time)
}
},
});