<template>
	<view class="container">
		<view class="search">
			<u-search @change="search" placeholder="房间号搜索" height="78" :show-action="false" v-model="keyword"></u-search>
		</view>
		<view class="calendar">
			<view class="date" @click="openCalendar(0)">
				 <view v-if="starDate">{{starDate}}</view>
				 <view v-else class="desc">起始日期</view>
			</view>
			<view class="date" @click="openCalendar(1)">
				<view v-if="endDate">{{endDate}}</view>
				<view v-else class="desc">结束日期</view>
			</view>
			<u-calendar v-model="calendarShow" :min-date="mindate" :max-date="maxdate" mode="date" @change="changeDate"></u-calendar>
		</view>
		<view class="list-item" v-for="(item,index) in listData" :key="index">
			<view class="top">
				{{item.address||''}}({{item.account_num}})
				<view class="goon" @click="topage(item)">续期</view>
			</view>
			<view class="time">合同时间：{{item.rent_date_end}} - {{item.rent_date_end}}</view>
			<view class="bot">
				<view>租客：{{item.customer_name}}</view>
				<view>租金{{item.rent_price}}</view>
				<view class="tel"><image class="tel-icon" src="/static/my/tel.png" mode="" />{{item.customer_tel}}</view>
			</view>
		</view>
		<view class="empty-box" v-if="listData.length==0&&!loading">
				<image class="img" src="http://images.2weisou.com/20221031114904TSF6jF4S.png" mode=""/>
				<view class="no-data">暂无数据</view>
			</view>
		<view class="loading" v-if="loading">
			<u-loading size="40" :show="loading"/>
			正在加载中
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				keyword: '',
				starDate: '',
				endDate: '',
				mindate: '',
				loading: false,
				maxdate: '2099-12-31',
				type: 0,// 默认是开始时间
				calendarShow: false,
				listData: [],
				pageNo: 1,
				pageSize: 10,
				loadDone: false,
			};
		},
		onLoad(options) {
		},
		onShow() {
		
		},
		created() {
			this.getList()
		},
		onReachBottom() {
			this.getList();
		},
		methods: {
			openCalendar(type){
				if(type==0){
					this.type = 0
					this.mindate = ''
					this.maxdate = this.endDate
				}else{
					this.type = 1
					this.mindate = this.starDate
					this.maxdate = '2099-12-31'
				}
				this.calendarShow = true;
			},
			search(){
				this.pageNo=1
				this.listData = []
				this.loadDone = false
				this.getList();
			},
			topage(item){
				uni.setStorageSync('electContractInfo',item)
				uni.navigateTo({ 
					url:'/pages/my/electContract?roomId='+ item.roomId+ '&oldContractId='+ item.proxy_contract_id
				})
			},
			getList(){
				if (this.loadDone) return;
				this.loading = true;
				let params = {
					account: this.keyword,
					pageNo:this.pageNo,
					pageSize:this.pageSize,
					rentDateBegin: this.starDate,
					rentDateEnd: this.endDate
				}
				this.$u.api.contractList({body:params}).then((res)=>{
					console.log(res)
					this.loading = false;
					if(res.result&&res.result.length){
						if(this.pageNo==1){
							this.listData = res.result
						}else{
							this.listData = [...this.listData, ...res.result];
						}
						if(res.result.length<this.pageSize){
							this.loadDone = true;
							return ;
						}
						this.pageNo += 1;
						this.loadDone = false
					}else{
						this.loadDone = true;
						if(this.pageNo==1){
							this.listData = []
							
						}
					}
				})
			},
			
			changeDate(e){
				// console.log(e)
				if(this.type==0){
					this.starDate = e.result
				}else{
					this.endDate = e.result
				}
				this.search()
			}
		},
	};
</script>

<style lang="scss" scoped>
.container{
	width: 750rpx;
	min-height: 100vh;
	background: #F8F8F8;
	.search{
		width: 100%;
		height: 110rpx;
		padding: 16rpx 30rpx;
		background: #fff;
	}
	.calendar{
		width: 750rpx;
		height: 92rpx;
		background: #FFFFFF;
		margin-bottom: 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;
		font-size: 26rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		padding: 0 40rpx;
		.date{
			flex:1;
			color: #333333;
			position: relative;
			text-align: center;
			&::after{
				position: absolute;
				content: "";
				top: 16rpx;
				right: 60rpx;
				border-color: #FF6D25;
				border: 8rpx solid transparent;
				border-top: 8rpx solid #FF6D25;
			}
			.desc{
				color: #999999;
			}
		}
	}
	.list-item{
		margin-bottom: 20rpx;
		padding: 30rpx;
		background: #fff;
		.top{
			height: 42rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 42rpx;
			font-size: 30rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #333333;
			line-height: 42rpx;
			margin-bottom: 24rpx;
			.goon{
				flex: 0 0 62rpx;
				color: #FF6D25;
				margin-left: 12rpx;
			}
		}
		.time{
			height: 42rpx;
			font-size: 30rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #333333;
			line-height: 42rpx;
			margin-bottom: 24rpx;
		}
		.bot{
			height: 96rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 30rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #505050;
			padding-top: 24rpx;
			border-top: 1px solid #e0e0e0;
			.tel{
				display: flex;
				align-items: center;
				.tel-icon{
					width: 30rpx;
					height: 30rpx;
					margin-right: 12rpx;
				}

			}
		}
	}
}
</style>
