<template>
<gracePage :customHeader="false">
<!-- 页面主体 -->
<view slot="gBody">
<scroll-view class="grace-scroll-x" scroll-x :scroll-into-view="'scrollItem'+currentIndex">
<view class="grace-scroll-items"
v-for="(item, index) in dateList" :key="index" :class="[currentIndex == index ? 'grace-scroll-day-active' : '']"
@tap="changeDay(index)" :id="'scrollItem'+index">
<view class="grace-scroll-items-date" :class="[currentIndex == index ? 'grace-scroll-day-active' : '']">{{item.day}}</view>
<view class="grace-scroll-items-week" :class="[currentIndex == index ? 'grace-scroll-day-active' : '']">{{item.week}}</view>
</view>
</scroll-view>
<!-- 列表数据请根据选择的日期动态读取并渲染 -->
<!-- 不建议使用选项卡模式 数据量大运行会卡顿 -->
<view class="grace-list">
<view class="grace-list-items" v-for="(item, index) in 10" :key="index">
<view class="grace-list-body grace-border-b">
<view class="grace-list-title">
<text class="grace-list-title-text">07:00 - 18:00</text>
</view>
<view class="grace-list-body-desc">某科急诊<text class="price">¥25</text></view>
</view>
<view class="button">预约</view>
</view>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/components/gracePage.vue";
var graceDate = require("../../graceUI/jsTools/date.js");
// 起始日期, 格式 2019-08-01
// 例如今天
var startDay = getNowFormatDate();
// 区间天数
var timeRegion = 14;
// 获取当天时间
function getNowFormatDate() {
var date = new Date();
var seperator1 = "-";
var year = date.getFullYear();
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = year + seperator1 + month + seperator1 + strDate;
return currentdate;
}
// 区间天数转换为一个数组
var weekday=["周日","周一","周二","周三","周四","周五","周六"];
var dateList = [];
var todayTimer = graceDate.dateTimeToTimeStamp(startDay + ' 01:01:00');
for(let i = 0; i < timeRegion; i++){
var timeStamp = todayTimer + (i * 3600*24);
var obj = {};
obj.day = graceDate.formatDateTime(timeStamp, 'str').substring(5, 10);
var date = new Date();
date.setTime(timeStamp * 1000);
obj.week = weekday[date.getDay()];
dateList.push(obj);
}
export default {
data() {
return {
dateList : dateList,
currentIndex : 0
}
},
methods:{
changeDay : function(index){
var selectedDay = this.dateList[index];
console.log(selectedDay);
this.currentIndex = index;
}
},
components:{gracePage}
}
</script>
<style>
.grace-scroll-x{border-bottom:1px solid #F1F1F1; background-color:#F5F6F8;}
.grace-scroll-items{width:150rpx; margin:0; padding:12rpx 0; display:inline-flex; flex-direction:column;}
.grace-scroll-items-date{font-size:28rpx; width:100%; line-height:50rpx; text-align:center;}
.grace-scroll-items-week{font-size:22rpx; width:100%; line-height:36rpx; margin-bottom:10rpx; text-align:center;}
.grace-scroll-day-active{background:#3688FF; color:#FFFFFF;}
.grace-list-items{position:relative;}
.price{color: #FF9B00; margin:0 10rpx;}
.button{position:absolute; z-index:1; right:8px; bottom:15px; background:#3688FF; color:#FFFFFF; width:100rpx; height:50rpx; font-size:24rpx; line-height:50rpx; text-align:center; border-radius:50rpx;}
</style>
<template>
<gracePage :customHeader="false">
<!-- 页面主体 -->
<view slot="gBody">
<scroll-view class="grace-scroll-x grace-border-b" :scroll-into-view="'scrollItem'+currentIndex" scroll-x>
<view class="grace-scroll-items" :id="'scrollItem'+index"
v-for="(item, index) in dateList" :key="index" :class="[currentIndex == index ? 'grace-scroll-day-active' : '']" @tap="changeDay(index)">
<text class="grace-scroll-items-date" :class="[currentIndex == index ? 'grace-scroll-day-active' : '']">{{item.day}}</text>
<text class="grace-scroll-items-week" :class="[currentIndex == index ? 'grace-scroll-day-active' : '']">{{item.week}}</text>
</view>
</scroll-view>
<!-- 列表数据请根据选择的日期动态读取并渲染 -->
<!-- 不建议使用选项卡模式 数据量大运行会卡顿 -->
<view class="grace-list">
<view class="grace-list-items" v-for="(item, index) in 10" :key="index">
<view class="grace-list-body grace-border-b">
<view class="grace-list-title">
<text class="grace-list-title-text">07:00 - 18:00</text>
</view>
<view class="grace-rows">
<text class="grace-list-body-desc">某科急诊</text>
<text class="price">¥25</text>
</view>
</view>
<text class="button">预约</text>
</view>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/weexComponents/gracePage.nvue";
var graceDate = require("../../graceUI/jsTools/date.js");
// 起始日期, 格式 2019-08-01
// 例如今天
var startDay = getNowFormatDate();
// 区间天数
var timeRegion = 14;
// 获取当天时间
function getNowFormatDate() {
var date = new Date();
var seperator1 = "-";
var year = date.getFullYear();
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = year + seperator1 + month + seperator1 + strDate;
return currentdate;
}
// 区间天数转换为一个数组
var weekday=["周日","周一","周二","周三","周四","周五","周六"];
var dateList = [];
var todayTimer = graceDate.dateTimeToTimeStamp(startDay + ' 01:01:00');
for(let i = 0; i < timeRegion; i++){
var timeStamp = todayTimer + (i * 3600*24);
var obj = {};
obj.day = graceDate.formatDateTime(timeStamp, 'str').substring(5, 10);
var date = new Date();
date.setTime(timeStamp * 1000);
obj.week = weekday[date.getDay()];
dateList.push(obj);
}
export default {
data() {
return {
dateList : dateList,
currentIndex : 0
}
},
methods:{
changeDay : function(index){
var selectedDay = this.dateList[index];
console.log(selectedDay);
this.currentIndex = index;
}
},
components:{gracePage}
}
</script>
<style>
.grace-scroll-x{background-color:#F5F6F8;}
.grace-scroll-items{width:150rpx; margin:0; padding:12rpx 0; flex-direction:column;}
.grace-scroll-items-date{font-size:28rpx; line-height:50rpx; text-align:center;}
.grace-scroll-items-week{font-size:22rpx; line-height:36rpx; margin-bottom:10rpx; text-align:center;}
.grace-scroll-day-active{background-color:#3688FF; color:#FFFFFF;}
.price{color: #FF9B00; font-size:24rpx; margin:0 10rpx;}
.button{position:absolute; right:8px; bottom:15px; background-color:#3688FF; color:#FFFFFF; width:100rpx; height:50rpx; font-size:24rpx; line-height:50rpx; text-align:center; border-radius:50rpx;}
</style>
.json
{
"usingComponents": {
"gracePage": "../../graceUI/components/gracePage"
}
}.wxml
<gracePage customHeader="{{false}}">
<!-- 页面主体 -->
<view slot="gBody">
<scroll-view class="grace-scroll-x" scroll-x scroll-into-view="{{'scrollItem'+currentIndex}}">
<view class="grace-scroll-items {{currentIndex == index ? 'grace-scroll-day-active' : ''}}" wx:for="{{dateList}}" wx:key="index"
bindtap="changeDay" id="{{'scrollItem'+index}}" data-index="{{index}}">
<view class="grace-scroll-items-date {{currentIndex == index ? 'grace-scroll-day-active' : ''}}">{{item.day}}</view>
<view class="grace-scroll-items-week {{currentIndex == index ? 'grace-scroll-day-active' : ''}}">{{item.week}}</view>
</view>
</scroll-view>
<!-- 列表数据请根据选择的日期动态读取并渲染 -->
<!-- 不建议使用选项卡模式 数据量大运行会卡顿 -->
<view class="grace-list">
<view class="grace-list-items" wx:for="{{10}}" wx:key="index">
<view class="grace-list-body grace-border-b">
<view class="grace-list-title">
<text class="grace-list-title-text">07:00 - 18:00</text>
</view>
<view class="grace-list-body-desc">某科急诊<text class="price">¥25</text></view>
</view>
<view class="button">预约</view>
</view>
</view>
</view>
</gracePage>.wxss
.grace-scroll-x{border-bottom:1px solid #F1F1F1; background-color:#F5F6F8;}
.grace-scroll-items{width:150rpx; margin:0; padding:12rpx 0; display:inline-flex; flex-direction:column;}
.grace-scroll-items-date{font-size:28rpx; width:100%; line-height:50rpx; text-align:center;}
.grace-scroll-items-week{font-size:22rpx; width:100%; line-height:36rpx; margin-bottom:10rpx; text-align:center;}
.grace-scroll-day-active{background:#3688FF; color:#FFFFFF;}
.grace-list-items{position:relative;}
.price{color: #FF9B00; margin:0 10rpx;}
.button{position:absolute; z-index:1; right:8px; bottom:15px; background:#3688FF; color:#FFFFFF; width:100rpx; height:50rpx; font-size:24rpx; line-height:50rpx; text-align:center; border-radius:50rpx;}.js
var graceDate = require("../../graceUI/jsTools/date.js");
// 起始日期, 格式 2019-08-01
// 例如今天
var startDay = getNowFormatDate();
// 区间天数
var timeRegion = 14;
// 获取当天时间
function getNowFormatDate() {
var date = new Date();
var seperator1 = "-";
var year = date.getFullYear();
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = year + seperator1 + month + seperator1 + strDate;
return currentdate;
}
// 区间天数转换为一个数组
var weekday = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
var dateList = [];
var todayTimer = graceDate.dateTimeToTimeStamp(startDay + ' 01:01:00');
for (let i = 0; i < timeRegion; i++) {
var timeStamp = todayTimer + (i * 3600 * 24);
var obj = {};
obj.day = graceDate.formatDateTime(timeStamp, 'str').substring(5, 10);
var date = new Date();
date.setTime(timeStamp * 1000);
obj.week = weekday[date.getDay()];
dateList.push(obj);
}
Page({
data: {
dateList: dateList,
currentIndex: 0
},
changeDay: function (e) {
var index = e.currentTarget.dataset.index;
var selectedDay = this.data.dateList[index];
console.log(selectedDay);
this.setData({currentIndex : index});
}
});