vue中datepicker的使用教程实例代码详解

2020-06-13 10:26:39易采站长站整理

},
getTomorrow: function (time) {
let tomorrow = new Date(time);
let nowDate = this.getNowFormatDate();
tomorrow.setTime(tomorrow.getTime() + 24 * 60 * 60 * 1000);
let reduce = '-';
let year = tomorrow.getFullYear() + reduce + this.addZero(tomorrow.getMonth() + 1) + reduce + this.addZero(tomorrow.getDate());

let t_timestamp = Math.round(new Date(year) / 1000);
let n_timestamp = Math.round(new Date(nowDate) / 1000);

if(t_timestamp > n_timestamp){
return mui.toast('不能超过今天');
}else{
this.startTime.time = year;
}
},
getNowFormatDate: function () {
let date = new Date();
let reduce = "-";
let currentdate = date.getFullYear() + reduce + this.addZero(date.getMonth() + 1) + reduce + this.addZero(date.getDate());

return currentdate;
},
addZero: function (time) {
if (time >= 1 && time <= 9) {
time = "0" + time;
}
return time;
},
countvouchertype: function (params) {
// 设置选项卡
for(let key in this.active){
if(params['active'] == key){
this.active[key] = true;
}else{
this.active[key] = false;
}
}

this.$store.state.mastloadding = true;
console.dir(params);
this.API.countvouchertype(params).then((response) => {

this.checkCouponList = response;
console.dir(this.checkCouponList);
this.$store.state.mastloadding = false;
}, (response) => {
this.$store.state.mastloadding = false;
mui.toast('网络错误');
});
},
countvoucherinfo: function (params) {
this.API.countvoucherinfo(params).then((response) => {
console.dir(response);
this.statistics = response;
}, (response) => {
mui.toast('网络错误');
});
}
},
components:{
Header,
myDatepicker
},
mounted(){
this.startTime.time = this.$store.state.cashtime1 ? this.$store.state.cashtime1 : this.getNowFormatDate();
// this.startTime.time = this.getNowFormatDate();
},
watch: {
startTime: {
    handler(newValue, oldValue) {
      console.log(newValue);
let newTimestamp = Math.round(new Date(newValue .time) / 1000);
let oldTimestamp = Math.round(new Date(this.getNowFormatDate()) / 1000);
if(newTimestamp > oldTimestamp){
this.startTime.time = this.getNowFormatDate();
mui.toast('不能超过今天');
}else{
let active = '';
let ticket_type = 1;
for(let key in this.active){
if(this.active[key]){
active = key
if(key=='meituan'){
ticket_type = 2
}