选择今天,明天或者后天中的某一天
外面的样子
选取时候的样子
image是右侧的箭头
<view class="addText">
<picker class="pickClass" :range="visitorTime" :value="visitorTimeIndex" @change="visitorChange">
<view class="innerBox">
<view>{{visitorTime[visitorTimeIndex]}}</view>
<image src="/static/homeImgs/vTangle.png" mode="widthFix" class="arrDown"></image>
</view>
</picker>
</view>
data的代码
data(){
return{
visitorTime:[],//访客时间
visitorTimeNum:[],//访客时间另一种格式,接口传参需要
visitorTimeIndex:0,//当前访客所选时间
}
},
methods的代码
//获取时间
getCurrentTime(){
var time = new Date()
var tempTime= [];
var yM = time.getFullYear() + '年' + (this.checkTime(time.getMonth()+1)) +'月'
var today = time.getDate()
var moni1 = time.setDate(today + 1);
var yM2 = new Date(moni1).getFullYear() + '年' + (this.checkTime(new Date(moni1).getMonth() + 1)) +'月'
var time1 = new Date()
var today2 = time1.getDate()
var moni2 = time1.setDate(today2 + 2);
var yM3 = new Date(moni2).getFullYear() + '年' + (this.checkTime(new Date(moni2).getMonth() + 1)) +'月'
var temp1 = yM + this.checkTime(today) +'日' +' 今天'
var temp2 = yM2 + this.checkTime(new Date(moni1).getDate()) +'日' +' 明天'
var temp3 = yM3 + this.checkTime(new Date(moni2).getDate()) +'日' +' 后天'
tempTime.splice(0,0,temp1)
tempTime.splice(1,0,temp2)
tempTime.splice(2,0,temp3)
this.visitorTime = tempTime;
var tempNum = [];
var yNum = time.getFullYear() + '-' + (this.checkTime(time.getMonth()+1)) +'-';
var yNum1 = new Date(moni1).getFullYear() + '-' + (this.checkTime(new Date(moni1).getMonth()+1)) +'-';
var yNum2 = new Date(moni2).getFullYear() + '-' + (this.checkTime(new Date(moni2).getMonth()+1)) +'-';
var num1 = yNum + this.checkTime(today)
var num2 = yNum1 + this.checkTime(new Date(moni1).getDate())
var num3 = yNum2 + this.checkTime(new Date(moni2).getDate())
tempNum.splice(0,0,num1)
tempNum.splice(1,0,num2)
tempNum.splice(2,0,num3)
this.visitorTimeNum = tempNum;
},
checkTime(i){
if(i<10) return "0"+i;
return i;
},
//选择通行时间
visitorChange(e){
this.visitorTimeIndex = e.detail.value;
},
css样式
/* 选择时间 */
.addText{
width: 84%;
box-sizing: border-box;
padding-right: 18rpx;
}
.pickClass{
width: 100%;
}
.innerBox{
width: 100%;
display: flex;
justify-content: space-between;
flex-wrap: nowrap;
font-size: 32rpx;
}
.arrDown{
width: 40rpx;
}