<template>
	<app-layout>
	<view style="padding-top: 20rpx;">
		<view class="main-left cross-center search">
			<image src="https://t17.9026.com/web/statics/image/index/search.png" mode=""></image>
			<input style="width: 560rpx;" type="text" v-model="name" placeholder="搜索楼盘"
				placeholder-style="font-size:28rpx;color:#999;" @input="search" />
		</view>
		<view class="properties_list">
			<view class="item main-left" v-for="(item,index) in dataList" :key="index" @click="selectEstate(index,item.name,item.id,item)">
				<view class="left">
					<image :src="item.cover_img" mode=""></image>
				</view>
				<view class="main-between-y right ">
					<view class="title">{{item.name}}</view>
					<view class="addr"><image style="width: 18rpx;height: 20rpx;margin-right: 12rpx;" src="https://t17.9026.com/web/statics/image/index/location.png"></image>{{item.address}}</view>
					<view class="content t-omit-two" v-html="item.details"></view>
				</view>
				<image class="bg" src="https://t17.9026.com/web/statics/image/sale/properties_gradual.png" mode="">
				</image>
			</view>
			<view class="no-more" v-if="noMore && dataList.length>0">没有更多了...</view>
			<app-no-goods v-if="dataList.length === 0" :title="'暂无数据'" background="#f7f7f7"></app-no-goods>
		</view>
		<u-popup v-model="show" mode="center" border-radius="14" @close="show = false">
			<view class="model">
				<viwe class="main-right">
					<image src="https://t17.9026.com/web/statics/image/index/close.png" mode=""
						style="width: 25rpx;height: 24rpx;" @click="show=false"></image>
				</viwe>
				<viwe class="title">{{dataList[selectIndex].name}}</viwe>
				<viwe class="main-left cross-center addr">
					<image src="https://t17.9026.com/web/statics/image/index/location.png" mode=""
						style="width: 18rpx;height: 20rpx;margin-right: 8rpx;"></image>
					{{dataList[selectIndex].address}}
				</viwe>
				<viwe class="img">
					<image class="img" :src="dataList[selectIndex].cover_img" mode=""></image>
				</viwe>
				<viwe class="desc t-omit-three" v-html="dataList[selectIndex].details"></viwe>
				<button type="default" class="btn" @click="bindingEstate">确认选择</button> 
			</view>
		</u-popup>
	</view>
	</app-layout>
</template>

<script>
	import appNoGoods from '@/components/page-component/app-no-goods/app-no-goods.vue';
	import uPopup from '@/components/basic-component/u-popup/u-popup.vue';
	export default {
		components: {
			appNoGoods,
			uPopup
		},
		data() {
			return {
				type:'',
				show: false,
				page:1,
				name:'',
				
				dataList:[],
				noMore:false,
				selectIndex:-1,
				regionId:{},
			};
		},
		onLoad(option) {
			'regionId' in option?this.regionId=JSON.parse(option.regionId):''
			'type' in option?this.type=option.type:''
			this.getData(1)
		},
		methods:{
			selectEstate(index,name,id,item){
					let pages = getCurrentPages();
					let currPage = pages[pages.length - 1]; //当前页面
					let prevPage = pages[pages.length - 2]; //上一个页面
					let multiIndex=[item.province_id,item.city_id,item.district_id]
					prevPage.$vm.estateInfo={id:id,name:name,multiIndex:multiIndex,address:item.address,property:item.property}
				this.selectIndex=index
				this.show=true
			},
			bindingEstate(){
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2]; //上一个页面
				if(prevPage.route==='pages/sale/properties/properties'){
					this.$request({
						url: this.$api.sale.binding_estate,
						data: {
							estate_id:this.dataList[this.selectIndex].id
						},
						method: 'post'
					}).then(res=>{
						uni.showToast({
							icon:res.code===0?'success':'none',
							title:res.msg
						})
						this.show=false
					})
				}else{
					uni.navigateBack()
				}
				
			},
			search(e){
				this.$utils.debounce(()=>{
					this.getData(1)
				},800)
			},
			getData(page){
				this.$showLoading()
				this.$request({
					url: this.$api.sale.estate_list,
					data: {
						page: page,
						is_myself: 0,
						name: this.name,
						...this.regionId
					},
					method: 'post'
				}).then(res=>{
					if(res.code===0){
						if(this.page===1){
							this.dataList=res.data.list
						}else{
							this.dataList=this.dataList.concat(res.data.list)
						}
						if(res.data.list.length<20){
							this.noMore=true
						}
					}
					this.$hideLoading()
				})
			}
		},
		onReachBottom() {
			if(!noMore){
				this.page++
				this.getData(this.page)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.model {
		width: 626rpx;
		height: 839rpx;
		background: #FFFFFF;
		border-radius: 14rpx;
		padding: 37rpx 49rpx;

		.title {
			font-size: 36rpx;
			font-weight: bold;
			color: #222222;
		}

		.addr {
			font-size: 22rpx;
			font-weight: 500;
			color: #999999;
			margin-top: 20rpx;
		}

		.img {
			width: 528rpx;
			height: 311rpx;
			border-radius: 14rpx;
			margin-top: 28rpx;
		}

		.desc {
			font-size: 26rpx;
			font-weight: 500;
			color: #222222;
			line-height: 36rpx;
			margin-top: 36rpx;
			max-height: 100rpx;
		}

		.btn {
			width: 525rpx;
			height: 85rpx;
			background: #A18353;
			border-radius: 6rpx;
			margin: 49rpx auto;
			font-size: 32rpx;
			font-weight: bold;
			color: #FFFFFF;
		}
	}

	.page {
		padding: 22rpx 0 0 0;
		min-height: 100vh;
	}

	.search {
		width: 680rpx;
		height: 82rpx;
		background: #FFFFFF;
		border: 1rpx solid #EEEEEE;
		border-radius: 4rpx;
		margin: 0 auto;
		padding-left: 22rpx;

		image {
			width: 22rpx;
			height: 22rpx;
			margin-right: 18rpx;
		}
	}

	.properties_list {
		background-color: #F8F8F8;

		.item {
			font-family: PingFang SC;
			margin: 25rpx auto;
			width: 678rpx;
			height: 206rpx;
			background: #FFFFFF;
			border-radius: 10rpx;
			// background-image: url(https://t17.9026.com/web/statics/image/sale/properties_gradual.png);
			padding: 25rpx;
			position: relative;

			.bg {
				position: absolute;
				top: 0;
				left: 0;
				width: 80%;
				height: 100%;
			}

			.left {
				image {
					width: 153rpx;
					height: 153rpx;
					border-radius: 10rpx;
				}
			}

			.right {
				margin-left: 25rpx;

				.title {
					font-size: 30rpx;

					font-weight: bold;
					color: #222222;
				}

				.addr {
					font-size: 22rpx;

					font-weight: 500;
					color: #222222;
				}

				.content {
					font-size: 24rpx;

					font-weight: 500;
					color: #666666;
					line-height: 34rpx;
				}
			}
		}

		.addPro {
			position: fixed;
			bottom: 0;
			width: 100%;
			height: 100rpx;
			background: #A18353;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
		}
	}
	.no-more {
		font-size: 24rpx;
		font-weight: 500;
		color: #666666;
		margin-top: 37rpx;
		text-align: center;
	}
</style>
