不多说,看图说话。
最终的效果就是左右可以滑动选择日期,点击日期查询数据。
WXML
<!-- 横向日期 --> <swiper class="swiper" display-multiple-items="{{clientWidthCount}}"> <block wx:for="{{Dates}}" wx:key="{{item.id}}"> <swiper-item id="{{item.id}}" bindtap="ClickDateCheng"> <text class="swiper-xingqi {{dateCurrentStr==item.id?'selZhou':''}}">{{item.text}}</text> <image class="{{dateCurrentStr==item.id?'selImg':''}}" src="{{bgWhiteImgUrl}}" /> <text class="swiper-day {{dateCurrentStr==item.id?'selDay':''}}">{{dateCurrentStr==item.id?item.mon+'-'+item.day:item.day}}</text> <text class="swiper-price {{dateCurrentStr==item.id?'selPrice':''}}">{{item.price}}</text> </swiper-item> </block> </swiper> <view class="data-month"> <navigator url='/pages/calendardj/index'> <image src="/images/dijia.jpg"></image> </navigator> </view>
JS
let app = getApp(); let compose = require('../../utils/compose'); let dateFormat = require('../../utils/dateutil'); let utils = require('../../utils/utils'); Page({ data: { dateCurrentStr: dateFormat.formatDay(new Date()), // 正选择日期的 id bgWhiteImgUrl: 'http://img0.imgtn.bdimg.com/it/u=1641805254,627977274&fm=26&gp=0.jpg', //选中的日期白色背景图 Dates: [], dateListArray: ['周 日', '周 一', '周 二', '周 三', '周 四', '周 五', '周 六'], maxCount: 15, //横向日期默认显示的日期数量 clientHeight: 0, clientWidthCount: 0 }, onLoad: function () { //加载前设置loading为true var that = this; wx.getSystemInfo({ success: function (res) { that.setData({ clientHeight: res.windowHeight - 90, clientWidthCount: parseInt(res.windowWidth / 50) ///一个小正方形宽度50,获得屏幕宽度计算数量 }); } }) // 在日期数组中添加10条记录(从当天开始) this.add(new Date(), "今 天"); for (var i = 1; i <= this.data.maxCount; i++) { //获取AddDayCount天后的日期 var txt = ""; if (i == 1) { txt = "明 天" } if (i == 2) { txt = "后 天" } this.add(new Date().setDate(new Date().getDate() + i), txt); } this.setData({ loading: true, Dates: this.data.Dates }); }, // 日历组件部分 add: function (obj, txt) { var date = new Date(obj); var year = date.getFullYear(); var mon = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1; var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(); var week = this.data.dateListArray[date.getDay()]; if (txt != "") { week = txt; } var obj = { id: year + '-' + mon + '-' + day, text: week, mon: mon, day: day, price: '¥100' }; this.data.Dates.push(obj); }, ClickDateCheng: function (e) { var currentDate = e.currentTarget.id; this.setData({ dateCurrentStr: currentDate }); // 刷新列表 wx.showToast({ title: '加载中...', icon: 'loading', duration: 1000 }) } })
WXSS
/* 横向日期 */ /*横向日期轮播图*/ .swiper { height: 58px; 100%; background: #39BF7A; color: white; padding: 12rpx 8rpx; position: relative; } .swiper image { height: 46px; 46px; border-radius: 6px; opacity: 0.2; } .swiper-xingqi{ position:absolute; left: 24%; top: 2rpx; font-size: 19rpx; z-index: 5; } .swiper-day{ position:absolute; left: 24%; top: 27%; font-size: 33rpx; } .swiper-price{ position:absolute; left: 15%; bottom: 5.2%; font-size: 20rpx; } /* 当前选中星期 */ .swiper .selZhou{ color: black; } /* 当前选中日期 */ .swiper .selDay{ color: black; position:absolute; left: 6rpx; font-size: 30rpx; } .swiper .selImg{ opacity: 0.9; } .swiper .selPrice{ color: red; } .data-month { position: absolute; right: 5rpx; top: 10rpx; } .data-month image{ 46px; height: 46px; } /* 日期下面的广告位 */ .date-choose_img{ 100%; height: 60px; position: relative; } .date-choose_img image{ 100%; height: 100%; padding: 6px; } .date-choose_img view{ position: absolute; top: 26%; left: 7%; font-weight: bold; font-size: 33rpx; } .date-choose_txt{ color: red; font-size: 35rpx; } .day_price{ font-size: 16rpx; color: rgb(255, 0, 34); }
最后点击右边的低价日历跳转到日历页面,效果如下:
有需要这个日历的找我要哈。网上也有的