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