<template>
	<view class="page" :style="{'height':h+'px','padding-top':mt+'px'}">
		<c-nav-bar title="房情表"></c-nav-bar>
		<view class="table">
			<view class="t_th">
				<view class="tt_year b_rb" @tap="show=true">
					<text>{{year}}年</text>
					<u-icon name="arrow-down" size="24" color="#999999"></u-icon>
				</view>
				<view class="tt_title b_rb">数量</view>
				<view class="tt_title b_rb">可售</view>
				<view class="tt_title b_rb">占用</view>
				<view class="tt_title b_rb">不可售</view>
			</view>
			<view class="t_item" v-for="(item,index) in list" :key="index">
				<view class="ti_date b_rb" @tap="toDetails(item)">
					<view :class="item.color">
						<text>{{item.yr}}</text>
						<text>{{item.week}}</text>
					</view>
					<u-icon name="arrow-right" size="24" color="#999999"></u-icon>
				</view>
				<view class="ti_num b_rb">{{item.num}}</view>
				<view class="ti_num b_rb">{{item.ksNum}}</view>
				<view class="ti_num b_rb">{{item.zyNum}}</view>
				<view class="ti_num b_rb">{{item.bksNum}}</view>
			</view>
		</view>
		<u-calendar :show="show" :monthNum="24" mode="single" @confirm="confirm"></u-calendar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				year:new Date().getFullYear(),
				weekCfg:{0:'周日',1:'周一',2:'周二',3:'周三',4:'周四',5:'周五',6:'周六'},
				show:false,
				startDate:new Date().Format('yyyy-MM-dd'),
				list:[],
				resData:[]
			}
		},
		onLoad() {
			this.getList();
		},
		methods: {
			getList(){
				this.resData = [];
				for(let i=0;i<7;i++){
					this.resData.push({
						date:new Date(new Date().setDate(new Date(this.startDate).getDate()+i)).Format('yyyy-MM-dd'),
						num:10,
						ksNum:10,
						zyNum:10,
						bksNum:10
					})
				}
				this.list = this.resData;
				let n = new Date().Format('yyyy-MM-dd');
				this.list.forEach(l=>{
					let w = new Date(l.date).getDay();
					l.yr = new Date(l.date).Format('MM-dd');
					l.week = n==l.date?'今天':this.weekCfg[w];
					l.color = n==l.date?'c_today':([6,0].includes(w)?'c_week':'c_normal');
				})
			},
			confirm(e){
				this.show = false;
				this.year = new Date(e[0]).Format('yyyy');
				this.startDate = e[0];
				this.getList();
			},
			toDetails(item){
				uni.navigateTo({
					url:'/pages/home/details?item='+encodeURIComponent(JSON.stringify(item))
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.page{
		background: #F9FAFC;
		.table{
			width: 100%;
			border-top: 1rpx solid #D1D1D1;
			border-left: 1rpx solid #D1D1D1;
			margin-top: 20rpx;
			.t_th{
				display: flex;
				align-items: center;
				justify-content: space-around;
				&>view{
					width: 25%;
					display: flex;
					align-items: center;
					justify-content: center;
					padding: 20rpx 0;
					box-sizing: border-box;
					&.tt_year{
						text{
							font-size: 24rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							color: #1F2425;
							margin-right: 10rpx;
						}
					}
					&.tt_title{
						background: #FAFAFA;
						font-size: 24rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						color: #1F2425;
					}
				}
			}
		
			.t_item{
				display: flex;
				align-items: center;
				justify-content: space-around;
				&>view{
					width: 25%;
					height: 106rpx;
				}
				.ti_date{
					display: flex;
					align-items: center;
					justify-content: center;
					background: #FAFAFA;
					box-sizing: border-box;
					&>view{
						display: flex;
						flex-direction: column;
						align-items: center;
						margin-right: 20rpx;
						text{
							font-size: 24rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							color: #245BED;
						}
					}
				}
				.ti_num{
					box-sizing: border-box;
					background: #ffffff;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 24rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #1F2425;
				}
			}
		}
		
		.b_rb{
			border-right: 1rpx solid #D1D1D1;
			border-bottom: 1rpx solid #D1D1D1;
		}
		
		.c_today{
			text{
				color: #245BED !important;
			}
		}
		.c_week{
			text{
				color: #FF0000 !important;
			}
		}
		.c_normal{
			text{
				color: #1F2425 !important;
			}
		}
	}
	
	::v-deep .u-transition{
		.u-calendar-month__days__day{
			height: 104rpx !important;
		}
		.u-calendar__confirm .u-button{
			width: calc(100% - 24rpx) !important;
			height: 88rpx !important;
			background: #0DBFFD !important;
			border-radius: 44rpx !important;
		}
		.u-calendar__confirm .u-button text{
			font-size: 32rpx !important;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #FFFFFF !important;
		}
		.u-calendar scroll-view{
			height: 600rpx !important;
		}
		.u-icon__icon{
			font-size: 14px !important;
			line-height: 14px !important;
		}
	}
</style>