add-date.js
2.07 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
// pack-book/components/book/time/add-date.js
import util from '../../../../utils/util'
Component({
/**
* 组件的属性列表
*/
properties: {
nowtime:Number,
},
lifetimes: {
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
attached: function () {
this.initView()
},
moved: function () { },
detached: function () { },
},
/**
* 组件的初始数据
*/
data: {
checked:-1,
list:[
{
time:new Date()/1000,
},
{
time:new Date()/1000+86400,
},
{
time:0,
}
],
calendarMaskLoad: false,
calendarMask: false,
},
checked:-1,
/**
* 组件的方法列表
*/
methods: {
initView(){
//console.log('add-date',this.data.nowtime,this.data.today)
setTimeout(() => {
this.setData({
calendarMaskLoad: true,
})
}, 1000);
this.initChecked(this.data.nowtime)
},
initChecked(nowtime){
let nowStr=util.unixtoTime(nowtime,"YYYY-MM-DD");
let list=this.data.list
this.checked=2
this.checkedTime=nowtime
if(nowStr==util.unixtoTime(list[0].time,"YYYY-MM-DD")){
this.checked=0
}else if(nowStr==util.unixtoTime(list[1].time,"YYYY-MM-DD")){
this.checked=1
}
this.setData({
checked:this.checked,
[`list[2].time`]:nowtime,
})
this.trigger()
},
selectedValue(e){
this.checked=util.attr(e,'value')
this.checkedTime=this.data.list[this.checked].time
this.setData({
checked:this.checked,
})
this.trigger()
},
trigger(){
this.triggerEvent('event',{
checked:this.checked,
checkedTime:this.checkedTime,
})
},
calendarShow(e){
this.setData({
calendarMask: true
})
},
calendarClose(){
this.setData({
calendarMask: false,
})
},
dateChange(event){
let cktime = util.timetouUnix(event.detail.date)
this.initChecked(cktime)
this.calendarClose();
},
}
})