JS代码如下
|
data( ) {
return {
startDate
: {
//
创建时间限制: 2000.1.1~2050.1.1
disabledDate
:
time
=>
{
return
time
.
getTime
()
<
new
Date
(
'2000-01-01 00:00:00'
).
getTime
()
||
time
.
getTime
()
>
new
Date
(
'2050-01-01 00:00:00'
).
getTime
()
}
},
endDate
: {
//
到期时间限制:选择的创建时间~2050.1.1,若没选择时间:2000.1.1~2050.1.1
disabledDate
:
time
=>
{
if
(
this
.
formInline
.
creationTime
) {
let
longTime
=
new
Date
(
new
Date
(
this
.
formInline
.
creationTime
).
setFullYear
(
new
Date
(
this
.
formInline
.
creationTime
).
getFullYear
()
+
50
)).
getTime
()
return
time
.
getTime
()
<
new
Date
(
this
.
formInline
.
creationTime
).
getTime
()
||
time
.
getTime
()
>
longTime
}
return
time
.
getTime
()
<
new
Date
(
'2000-01-01 00:00:00'
).
getTime
()
||
time
.
getTime
()
>
new
Date
(
'2050-01-01 00:00:00'
).
getTime
()
}
}
},
}
}
|
写在
data中:例:
data(){
如下彩色代码部分
return {}
}
// 时间选择
const
newTime
=
new
Date
(
new
Date
().
getFullYear
(),
new
Date
().
getMonth
(),
new
Date
().
getDate
())
const
times
=
[{
text
:
'今年至今'
,
onClick
(
picker
) {
const
end
=
new
Date
();
const
start
=
new
Date
(
new
Date
().
getFullYear
(),
0
);
picker
.
$emit
(
'pick'
, [
start
,
end
]);
}
}, {
text
:
'最近一个月'
,
onClick
(
picker
) {
const
end
=
new
Date
();
// const start = newTime;
// 原先发现的问题(连续点击最近一个月,开始时间往下累减,把newTime 换成了new Date())
const
start
=
new
Date
()
start
.
setMonth
(
new
Date
().
getMonth
()
-
1
);
picker
.
$emit
(
'pick'
, [
start
,
end
]);
}
}, {
text
:
'最近三个月'
,
onClick
(
picker
) {
const
end
=
new
Date
();
const
start
=
new
Date
();
start
.
setMonth
(
new
Date
().
getMonth
()
-
3
);
picker
.
$emit
(
'pick'
, [
start
,
end
]);
}
}, {
text
:
'最近六个月'
,
onClick
(
picker
) {
const
end
=
new
Date
();
const
start
=
new
Date
();
start
.
setMonth
(
new
Date
().
getMonth
()
-
6
);
picker
.
$emit
(
'pick'
, [
start
,
end
]);
}
}]
|