<template>
	<view class="container">
		<view class="top-box">
			<view class="search-box">
				<u-search v-model="keyword" @change="searchFun" placeholder="请输入小区名/台账号" :show-action="false" :clearabled="true" bg-color="#F8F8F8" shape="round" height="78"></u-search>
			</view>
		</view>
		<view class="select-box">
			<view class="select-item" @click="addressShow=true">位置</view>
			<view class="select-item" @click="priceShow=true">价格</view>
			<view class="select-item" @click="buildTypeShow=true">房型</view>
			<view class="select-item" @click="houseTypeShow=true">户型</view>
		</view>
		<view class="list-box">
			<view class="list-item" @click="topage(item)" v-for="(item,index) in listData" :key="index">
				<!-- roomFlag 1转租、2违约 -->
				<view class="mark" v-if="item.roomFlag==1">转租</view>
				<image class="house-img" :src="item.pictrues[0].pictureUrl||'/static/kehu/pic1.png'" mode="" />
				<view class="item-info">
					<view class="house-name u-line-1">{{item.address}}</view>
					<view class="type">{{item.houseType}} / {{item.area}}㎡
						<!-- rentPeriod  1 收定  2退定 -->
						<view class="type-status" v-if="item.rentPeriod==1">收定</view>
					</view>
					<view class="rent-time">剩余租期：{{item.remainderPeriod}}个月</view>
					<view class="bot-wrap">
						<view class="left u-line-1"><image class="person-icon" src="/static/person.png" mode="" />{{item.personName}}</view>
						<view class="money">{{item.rentPrice}}/月</view>
					</view>
				</view>
			</view>
			<view class="loading" v-if="loading">
				<u-loading size="40" :show="loading"/>
				正在加载中
			</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>
		<!-- 位置 -->
		<u-popup v-model="addressShow" mode="top">
			<view class="select-list select-list1">
				<view class="left-box">
					<view class="item" :class="{'selected':item.code==searchForm.addressQuval}" v-for="(item,index) in addressList" :key="index" @click="secectAddressQu(item,index)">
						{{item.text}}
					</view>
				</view>
				<view class="right-box">
					<view class="item" :class="{'selected':item.code==searchForm.addressCityval}" v-for="(item,index) in addressListRight" :key="index" @click="secectAddressCity(item)">
						{{item.text}}
					</view>
				</view>
			</view>
		</u-popup>
		<!-- 价格弹窗 -->
		<u-popup v-model="priceShow" mode="top">
			<view class="select-list">
				<view class="item" :class="{'selected':item.code==searchForm.priceval}" v-for="(item,index) in priceList" :key="index" @click="secectPrice(item,index)">
					{{item.text}}
				</view>
			</view>
		</u-popup>
		<!-- 房型弹窗 -->
		<u-popup v-model="buildTypeShow" mode="top">
			<view class="select-list">
				<view class="item" :class="{'selected':item.code==searchForm.buildTypeval}" v-for="(item,index) in buildTypeList" :key="index" @click="selectBuildType(item,index)">
					{{item.text}}
				</view>
			</view>
		</u-popup>
		<!-- 户型弹窗 -->
		<u-popup v-model="houseTypeShow" mode="top">
			<view class="select-list">
				<view class="item" :class="{'selected':item.code==searchForm.houseTypeval}" v-for="(item,index) in houseTypeList" :key="index" @click="secectHouseType(item,index)">
					{{item.text}}
				</view>
			</view>
		</u-popup>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				loading: false,
				addressShow: false,
				priceShow: false,
				houseTypeShow: false,
				buildTypeShow: false,
				keyword: '',
				searchForm: {
					addressQuval: '',
					buildTypeval: '',
					priceval: '',
					priceLabel: '',
					houseTypeval: '',
					addressIndex: '',
					addressCityval: ''
				},
				addressList: [
					{
						text: '不限',
						code: '',
						children:[]
					}
				],
				addressListRight: [],
				buildTypeList: [
					{
						text: '不限',
						code: ''
					}
				],
				priceList: [
					{
						text: '不限',
						code: ''
					}
				],
				houseTypeList: [
					{
						text: '不限',
						code: ''
					}
				],
				listData: [],
				pageNo: 1,
				pageSize: 10,
				loadDone: false,
			};
		},
		created(){
			this.getList()
			this.getbaseData()
			// this.getRoomType()
		},
		onReachBottom() {
			this.getList();
		},
		methods: {
			// 获取筛选下拉的数据
			getbaseData(){
				this.$u.api.region({body:{}}).then((res)=>{
					// console.log(res)
					this.addressList = this.addressList.concat(res.result.area)
					this.buildTypeList = this.buildTypeList.concat(res.result.buildType)
					this.priceList = this.priceList.concat(res.result.rentMoney)
					this.houseTypeList = this.houseTypeList.concat(res.result.houseType)
					this.addressListRight = this.addressList[0].children
				})
			},

			getRoomType(){
				this.$u.api.getRoomType({body:{}}).then((res)=>{
					// console.log(res)
					if(res.result&&res.result.length){
						this.buildTypeList = this.buildTypeList.concat(res.result)
					}
				})
			},
			secectAddressQu(item,index){
				if(index==0) {// 不限
					this.searchForm.addressQuval = ''
					this.searchForm.addressCityval = ''
					this.addressShow = false
					this.pageNo = 1
					this.loadDone = false
					this.getList()
					return ;
				}
				this.searchForm.addressQuval = item.code
				this.addressListRight = this.addressList[index].children
				this.searchForm.addressIndex = index
			},
			secectAddressCity(item){
				this.searchForm.addressCityval = item.code
				this.addressShow = false
				this.pageNo = 1
				this.loadDone = false
				this.getList()
			},
			// 房型选择
			selectBuildType(item,index){
				if(index==0) {// 不限
					this.searchForm.buildTypeval = ''
					this.buildTypeShow = false
					this.pageNo = 1
					this.loadDone = false
					this.getList()
					return ;
				}
				this.searchForm.buildTypeval = item.code
				this.buildTypeShow = false
				this.pageNo = 1
				this.loadDone = false
				this.getList()
			},
			// 价格选择
			secectPrice(item,index){
				if(index==0) {// 不限
					this.searchForm.priceval = ''
					this.searchForm.priceLabel = item.text
					this.pageNo = 1
					this.loadDone = false
					this.priceShow = false
					this.getList()
					return ;
				}
				this.searchForm.priceval = item.code
				this.searchForm.priceLabel = item.text
				this.priceShow = false
				this.pageNo = 1
				this.loadDone = false
				this.getList()
			},
			// 户型选择
			secectHouseType(item,index){
				if(index==0) {// 不限
					this.searchForm.houseTypeval = ''
					this.pageNo = 1
					this.loadDone = false
					this.houseTypeShow = false
					this.getList()
					return ;
				}
				this.searchForm.houseTypeval = item.code
				this.houseTypeShow = false
				this.pageNo = 1
				this.loadDone = false
				this.getList()
			},
			topage(item){
				uni.setStorageSync('roomInfo',item)
				uni.navigateTo({
					url: '/pages/otherPage/rentDetail?id=' + item.roomId
				})
			},
			searchFun(){
				this.loadDone = false
				this.pageNo = 1
				this.getList()
			},
			getList(){
				if (this.loadDone) return;
				this.loading = true;
				let params = {
					pageNo:this.pageNo,
					pageSize:this.pageSize,
					message:this.keyword,
					priceMin:this.searchForm.priceval?this.searchForm.priceLabel.split('~')[0]:'',
					priceMax:this.searchForm.priceval?this.searchForm.priceLabel.split('~')[1]:'',
					rentStatus:"",//出租状态 1,出租中 2,收定金
					districtId:this.searchForm.addressQuval,//区域
					roomType:this.searchForm.houseTypeval,//户型
					subDistrictId: this.searchForm.addressCityval,//片区
					buildType: this.searchForm.buildTypeval//房型
				}
				
				this.$u.api.roomList({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 = []
						}
					}
				})
			}
    },
	};
</script>

<style lang="scss" scoped>
.container{
	width: 750rpx;
	min-height: 100vh;
	.top-box{
		padding: 0 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background: #fff;
		.search-box{
			width: 690rpx;
			height: 78rpx;
		}
	}
	.select-box{
		display: flex;
		justify-content: space-around;
		align-items: center;
		background: #fff;
		padding: 30rpx 0;
		border-bottom: 1px solid #e0e0e0;
		.select-item{
			flex:1;
			height: 36rpx;
			font-size: 26rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #333333;
			line-height: 36rpx;
			letter-spacing: 1px;
			position: relative;
			text-align: center;
			&::after{
				position: absolute;
				content: '';
				top: 16rpx;
    		right: 36rpx;
				border-color: #969696;
				border: 8rpx solid transparent;
      	border-top: 8rpx solid #969696;
			}
		}
	}
	.list-box{
		padding: 30rpx;
		.list-item{
			width: 690rpx;
			height: 202rpx;
			margin-bottom: 30rpx;
			display: flex;
			position: relative;
			.mark{
				position: absolute;
				left: 0;
				top: 0;
				width: 80rpx;
				height: 44rpx;
				line-height: 44rpx;
				text-align: center;
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				background: #FF6D25;
				border-radius: 12rpx 0px 12rpx 0px;
			}
			.house-img{
				width: 248rpx;
				height: 202rpx;
				border-radius: 12rpx;
				margin-right: 24rpx;
				flex: 0 0 248rpx;
			}
			.item-info{
				flex: 1;
				.house-name{
					height: 44rpx;
					font-size: 32rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #333333;
					line-height: 44rpx;
					margin-bottom: 15rpx;
					max-width: 410rpx;
				}
				.type{
					height: 44rpx;
					font-size: 26rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
					margin-bottom: 12rpx;
					display: flex;
					align-items: center;
					.type-status{
						margin-left: 24rpx;
						width: 108rpx;
						height: 44rpx;
						line-height: 44rpx;
						text-align: center;
						background: #FFFFFF;
						border-radius: 8rpx;
						font-size: 26rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						color: #2671E2;
						border: 1rpx solid #2671E2;
					}
				}
				.rent-time{
					height: 36rpx;
					font-size: 26rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
					margin-bottom: 12rpx;
				}
				.bot-wrap{
					display: flex;
					justify-content: space-between;
					align-items: center;
					.left{
						display: flex;
						align-items: center;
						.person-icon{
							width: 32rpx;
							height: 32rpx;
							border-radius: 50%;
							margin-right: 12rpx;
						}
					}
					.money{
					height: 48rpx;
					font-size: 34rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #FF6D25;
					line-height: 48rpx;
					}
				}
				
			}

		}
	}
	.select-list1{
		display: flex;
	}
	.select-list{
		padding: 0 40rpx;
		max-height: 600rpx;
		overflow: auto;
		.item{
			height: 90rpx;
			line-height: 90rpx;
			font-size: 30rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #333333;
			border-bottom: 1px solid #e0e0e0;
			&:last-child{
				border: 0;
			}
			&.selected{
				color: #FF6D25;
			}
		}
		.left-box{
			width: 300rpx;
			.item{
				border: 0
			}
		}
		.right-box{
			flex:1;
			.item{
				border: 0
			}
		}
	}
	
}
</style>
