<template>
	<view class="main">
		<view class="leftcontainer">
			<scroll-view scroll-y="true" style="height: 700rpx;">
				<view :class="leftindex==index?'leftstyle leftstyle_active':'leftstyle'" v-for="(item,index) in date[0]" @click="selectdate(item,index)"
				 :key="index">
					<view class="">
						{{formatdate(item.week)}}
					</view>
					<view class="">
						{{item.date}}
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="rightcontainer">
			<scroll-view scroll-y="true" style="height: 700rpx;">
				<u-grid :col="3">
					<u-grid-item v-for="(itm,idx) in rightday" @click="selectday(itm)" :key="idx">
						<view class="text-sm">
							{{itm.intro}}
						</view>
						<view class="margin-top-sm">{{itm.start_time_period}} - {{itm.end_time_period}}</view>
						<view :class="itm.can_appoint_num==0?'margin-top-sm text-gray text-sm':'margin-top-sm text-blue text-sm'">
							可预约号源：{{itm.can_appoint_num}}
						</view>
					</u-grid-item>
				</u-grid>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			date: {
				type: Array,
			}
		},
		mounted() {

		},
		data() {
			return {
				leftindex: 0,
				rightday: [],
				year: ""
			}
		},

		methods: {
			formatdate(week) {
				switch (week) {
					case 1:
						return "周一"
						break;
					case 2:
						return "周二"
						break;
					case 3:
						return "周三"
						break;
					case 4:
						return "周四"
						break;
					case 5:
						return "周五"
						break;
					case 6:
						return "周六"
						break;
					case 7:
						return "周日"
						break;
					default:
						break;
				}
			},
			selectdate(item, index) {
				this.leftindex = index
				this.year = item.date
				this.date[1].forEach(data => {
					data.forEach(itm => {
						if (itm.schedule_id == item.id) {
							this.rightday = data
						}
					})
				})
			},
			selectday(itm) {
				let arr = itm.year + " " + itm.end_time_period;
				arr = arr.split(/[- :]/)
				let nndate = new Date(arr[0], arr[1] - 1, arr[2], arr[3], arr[4]);
				nndate = Date.parse(nndate)
				let currentTime = Date.parse(new Date())
				if (nndate < currentTime) {
					uni.showToast({
						title: "不可预约已过时间",
						icon: "none"
					})
					return false
				}
				if (itm.can_appoint_num == 0) {
					uni.showToast({
						title: "已无号源可预约",
						icon: "none"
					})
					return false
				}
				if (this.year != "") {
					itm.year = this.year
				}
				this.$emit('callbacktime', itm)
			}
		}
	};
</script>

<style scoped>
	.main {
		display: flex;
		/* margin-left: 15rpx;
		margin-right: 15rpx; */
	}

	.leftcontainer {
		border-right: 1rpx solid #efefef;
		width: 25%;
	}

	.rightcontainer {
		width: 75%;
	}

	.leftstyle {
		width: 100%;
		height: 80rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 30rpx;
		color: #0B73B9;
		flex-direction: column;
	}

	.leftstyle_active {
		color: #fff;
		background-color: #0B73B9;
	}
</style>
