<template>
	<s-layout title="食堂招租">
		<view class="container">
			<!-- 顶部 -->
			<view class="top">
				<!-- 顶部-地址&搜索 -->
				<view class="locTop">
					<view class="locTop-right">
						<uni-section style="border-radius: 192rpx;padding: 0;" type="line">
							<uni-search-bar :value="listQuery.keywords" style="border-radius: 192rpx;" radius="23" placeholder="搜索您需要的信息"
								bgColor="#EEEEEE" clearButton="none" cancelButton="none" @confirm="searchRent"
								@blur="searchRent1" />
						</uni-section>
						<!-- <uni-search-bar></uni-search-bar> @confirm="search"-->
					</view>
					<view class="locTop-left">
						<view class="locTop-left-left" @click="state.showRegion = true">
							<view
								style="font-size: 28rpx;font-weight: 400;line-height: 32rpx;color: #999999;width: auto;">
								{{state.model.city_name ? proCity:'地区' }}
							</view>
							<image style="width: 27rpx;height: 27rpx;margin-left: 10rpx;"
								src="https://jiangxiaoxian.0rui.cn/rentMore.png" mode=""></image>
						</view>
						<picker mode="selector" :value="tagList" :range="tagList" range-key="dictLabel"
							@change="onChangeTag">
							<view class="picker"
								style="width: auto; position: relative;font-size: 28rpx;font-weight: 400;color: #999999;line-height: 32rpx;">

								{{dictLabel || '标签'}}
								<image style="width: 27rpx;height: 27rpx;margin-left: 6rpx;"
									src="https://jiangxiaoxian.0rui.cn/rentMore.png" mode=""></image>
							</view>
						</picker>


					</view>

				</view>


			</view>

			<!-- 推荐列表 -->
			<view class="recommend-box">
				<view class="rrecommList" v-for="(item,index) in rentList" :key="index">
					<view class="reListItem">
						<!-- 左侧图片 -->
						<view class="listItem-images">
							<image v-if="item.recommend == 1"
								style="width: 77rpx;height: 36rpx;z-index: 100;position: relative;top: 34rpx;left: 0rpx;"
								src="https://jiangxiaoxian.0rui.cn/hot.png"></image>
							<image class="iamges-mainImg" :src="item.images[0]"></image>
						</view>
						<!-- 右侧内容 -->
						<view class="listItem-contents">
							<view class="title2" style="margin-bottom: 20rpx;">{{item.platform_title}}</view>
							<scroll-view class="">标签</scroll-view>
							<view class="cons-third">
								<view style="display: flex;">
									<image style="width: 24rpx;height: 24rpx;"
										src="https://jiangxiaoxian.0rui.cn/locationList.png"></image>
									<view class="title3" style="margin-left: 10rpx;">{{item.address_city_text}}</view>
								</view>
								<view class="title3">{{item.release_time_text}}</view>
								<view style="display: flex;">
									<image style="width: 26rpx;height: 20rpx;"
										src="https://jiangxiaoxian.0rui.cn/eye.png"></image>
									<view class="title3" style="margin-left: 10rpx;">{{item.views}}</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>

		</view>

		<!-- 省市区弹窗 -->
		<su-regionCity-picker :show="state.showRegion" @cancel="state.showRegion = false" @confirm="onRegionConfirm">
		</su-regionCity-picker>
		
		<uni-load-more
		  v-if="state.pagination.total > 0"
		  :status="state.loadStatus"
		  :content-text="{
		    contentdown: '上拉加载更多',
		  }"
		  @tap="loadmore"
		/>
		
	</s-layout>
</template>

<script setup>
	import {
		computed,
		ref,
		reactive,
	} from 'vue';
	import {
		onLoad,
		onShow,
		onPageScroll,
		onPullDownRefresh,
		onReachBottom
	} from '@dcloudio/uni-app';
	import {
		consignee,
		mobile,
		address,
		region
	} from '@/sheep/validate/form';
	import rent from '../../sheep/api/rent';
	import sheep from '@/sheep';

	const listQuery = ref({
		page: 1,
		limit: 10,
		addrLatitude: null,
		addrLongitude: null,
		address: null,
		address1: null,
		categoryId: null,
		tags: '',
		area: null,
		city: null,
		district: null,
		keywords:null,

		// district: '',
	})
	const dictLabel = ref(null)
	const tagList = ref([])

	onLoad(() => {
		getList();
	})

	onShow(() => {})
	
	// 数据
	const pagination = {
	  data: [],
	  current_page: 1,
	  total: 1,
	  last_page: 1,
	};
	
	const state = reactive({
		showRegion: false,
		model: {
			consignee: '',
			mobile: '',
			address: '',
			is_default: false,
			region: '',
		},
		rules: {
			consignee,
			mobile,
			address,
			region,
		},
		currentTab: 0,
		pagination: {
		  data: [],
		  current_page: 1,
		  total: 1,
		  last_page: 1,
		},
		loadStatus: '',
		type: '',
	});

	const proCity = ref(''); //省市页面显示

	function searchRent() {
		console.log('搜索');
	}

	const onRegionConfirm = (e) => {
		console.log('onRegionConfirm', e);

		state.model = {
			...state.model,
			...e,
		};

		proCity.value = state.model.province_name + " " + state.model.city_name

		console.log('onRegionConfirm33', state.model, proCity.value);
		state.showRegion = false;
	};

	/* 标签 */
	// const getTagList = () => {
	// 	const obj = [{
	// 		dictLabel:'全部',
	// 		dictCode:''
	// 	}]
	// 	getTag(listQuery.value).then(res => {
	// 		tagList.value = obj.concat(res.data)
	// 		total.value = res.total
	// 	})
	// }

	/**选择标签 */
	// function onChangeTag(e) {
	// 	const value = e.detail.value;
	// 	listQuery.value.tags = tagList.value[e.detail.value].dictLabel;
	// 	dictLabel.value = tagList.value[e.detail.value].dictLabel;
	// 	console.log('标签',listQuery.value);
	// 	getList(listQuery.value);

	// }

	const rentList = ref([])
	//招租列表
	async function getList() {
		// state.loadStatus = 'loading';
		let res = await sheep.$api.rent.rentlist({
			keywords: listQuery.keywords,
			page:listQuery.page,
			limit: listQuery.limit,
			my:1,
			order:'normal',
			status:1,
		});
		console.log('getList',res);
		if (res.code === 1) {
			rentList.value = res.data.list
			for(let i = 0;i<rentList.value.length;i++) {
				 rentList.value[i].release_time_text = rentList.value[i].release_time_text.split(' ')[0]
			}
			console.log('rentList', rentList.value);
		}
		// if (state.pagination.current_page < state.pagination.last_page) {
		//   state.loadStatus = 'more';
		// } else {
		//   state.loadStatus = 'noMore';
		// }
	}
	
	// 加载更多
	function loadmore() {
	  if (state.loadStatus !== 'noMore') {
	    if (state.currentTab == 0) {
	      getList(state.pagination.current_page + 1);
	    } else {
	      getList(state.pagination.current_page + 1);
	    }
	  }
	}
	
	onReachBottom(() => {
	  // loadmore();
	});
</script>

<style lang="scss" scoped>
	.search-result {
		padding-top: 10px;
		padding-bottom: 20px;
		text-align: center;
	}

	.search-result-text {
		text-align: center;
		font-size: 14px;
		color: #666;
	}

	.example-body {
		/* #ifndef APP-NVUE */
		display: block;
		/* #endif */
		padding: 0px;
	}

	.uni-mt-10 {
		margin-top: 10px;
	}

	.title2 {
		color: #3d3d3d;
		font-size: 30rpx;
		font-weight: 800;
		line-height: 42rpx;
	}

	.title3 {
		font-size: 20rpx;
		font-weight: 400;
		color: #999999;
		line-height: 22rpx;
	}

	.container {
		width: 100%;
		height: 100%;

		.top {
			width: 100%;
			height: 80rpx;
			background-color: #ffffff;
			// background-image: url('https://jiangxiaoxian.0rui.cn/topBack.png');
			background-size: 100%;
			padding: 20rpx 30rpx;
			display: grid;

			.locTop {
				width: 96%;
				height: 70rpx;
				display: flex;
				// justify-content: space-between;
				align-items: center;

				.locTop-left {
					position: absolute;
					right: 5%;
					width: 176rpx auto;
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-right: 20rpx;

					.locTop-left-left {
						width: 176rpx auto;
						display: flex;
						align-items: center;
						justify-content: flex-start;
						margin-right: 20rpx;
					}

				}

				.locTop-right {
					width: 406rpx;
					height: 70rpx;

				}
			}

		}

		.recommend-box {
			margin-top: 30rpx;
			padding: 0rpx 30rpx;

			.rrecommList {
				// margin: 0 auto;
				// margin-top: 30rpx;
				// padding: 30rpx;

				.reListItem {
					background-color: #ffffff;
					width: 640rpx;
					height: 190rpx;
					padding: 30rpx;
					display: flex;
					justify-content: flex-start;
					align-items: center;
					border-radius: 18rpx;

					.listItem-images {
						display: grid;
						justify-content: flex-start;

						.iamges-mainImg {
							width: 190rpx;
							height: 190rpx;
							position: relative;
							right: 0rpx;
							bottom: 18rpx;
							z-index: 1;

						}
					}

					.listItem-contents {
						margin-left: 20rpx;

						.cons-third {
							margin-top: 20rpx;
							display: flex;
							justify-content: space-between;
							align-items: center;
						}
					}
				}

			}

		}

	}
</style>