效果图:
js:
dealTime: function (num) {
var time = new Date()
var date = new Date(time.setDate(time.getDate() + num)).getDate()
var year = time.getFullYear()
var month = time.getMonth() + 1
var day = time.getDay()
switch (day) {
case 0: day = "日"
break
case 1: day = "一"
break
case 2: day = "二"
break
case 3: day = "三"
break
case 4: day = "四"
break
case 5: day = "五"
break
case 6: day = "六"
break
}
var obj = {
day: month + '.' + date,
week:day,
date:year+'-'+month + '-' + date
}
return obj
},
onLoad: function (options) {
var arr = []
for (let i = 0; i < 7; i++) {
arr.push(this.dealTime(i))
}
this.setData({
weekInfo: arr
},()=>{
console.log(this.data.aWeek)
})
},
wxml
<scroll-view scroll-x class=" nav bg-white" scroll-with-animation scroll-left="{{scrollLeft}}" style="padding-left:8rpx">
<view class="cu-item date-item {{index==DateTabCur?' Datecur':''}}" wx:for="{{weekInfo}}" wx:key="*this" bindtap="DatetabSelect" data-id="{{index}}" style="padding: 0px 8rpx;">
<view> {{item.day}}</view>
<view class="weeks">{{item.week}}</view>
</view>
</scroll-view>
wxss
.nav .date-item {
height: 166rpx;
text-align: center;
color: #9a9a9a;
border: none;
line-height: 78rpx;
}
.date-item .weeks {
width: 70rpx;
height: 70rpx;
border-radius: 50%;
background: #333333;
text-align: center;
line-height: 70rpx;
color: white;
}
.nav .date-item.Datecur .weeks {
border: 4rpx solid red;
color: #333333;
background:white;
}