<template>
	<view>
		<view class="root">
			<view class="mask" @click="handleMask"></view>
			<view class="list-container">
				<view class="item" v-for="(item,index) in list" :key="item" :class="{isActive: activeIndex === index}"
					@click="handleActive(index)">
					<text class="list-text">{{item}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			list: {
				type: Array,
				default () {
					return []
				}
			},
			type: {
				type: String,
				default () {
					return ''
				}
			}
		},
		data() {
			return {
				activeIndex: 0,
				queryInfo: {}
			}
		},
		methods: {
			handleMask() {
				this.$emit('cancelDrop');
			},
			sendQueryInfo() {
				console.log(this.queryInfo);
				if (this.type === '行业') {
					
						this.queryInfo = {
							business: this.activeIndex
						}
					
					
				} 
				if (this.type === '区域') {
					
						this.queryInfo = {
							region: this.activeIndex
						}
					
				}
				if (this.type === '面积') {
					
						this.queryInfo = {
							areatype: this.activeIndex
						}
					
					
				}
				if (this.type === '筛选') {
					
						this.queryInfo = {
							sortType: this.activeIndex
						}
					
					
				}
				// if (this.type === '行业') {
				// 	if(this.list[this.activeIndex] == '全部'){
				// 		this.queryInfo = {
				// 			business: ''
				// 		}
				// 	}else{
				// 		this.queryInfo = {
				// 			business: this.activeIndex
				// 		}
				// 	}
					
				// } else if (this.type === '区域') {
				// 	if(this.list[this.activeIndex] == '全区域'){
				// 		this.queryInfo = {
				// 			region: ''
				// 		}
				// 	}else{
				// 		this.queryInfo = {
				// 			region: this.activeIndex
				// 		}
				// 	}
				// } else if (this.type === '面积') {
				// 	if(this.list[this.activeIndex] == '任意面积'){
				// 		this.queryInfo = {
				// 			areatype: ''
				// 		}
				// 	}else {
				// 		this.queryInfo = {
				// 			areatype: this.activeIndex
				// 		}
				// 	}
					
				// } else if (this.type === '筛选') {
				// 	if(this.list[this.activeIndex] == '全部'){
				// 		this.queryInfo = {
				// 			sortType: ''
				// 		}
				// 	}else{
				// 		this.queryInfo = {
				// 			sortType: this.activeIndex
				// 		}
				// 	}
					
				// }
				// 发送queryInfo
				console.log(this.queryInfo, 'sendqueryInfo');
				this.$emit('getQueryInfo', this.queryInfo);	
			},
			async handleActive(index) {
				this.activeIndex = index;
				this.sendQueryInfo();
				// 设置一个定时器，等待200毫秒
				const delayPromise = this.delay(200);
				// 等待定时器完成
				await delayPromise;
				this.handleMask();
			},
			delay(ms) {
				return new Promise((resolve) => {
					// 设置一个定时器，并将定时器的ID存储在this.timerId中
					this.timerId = setTimeout(() => {
						resolve();
						// 清除定时器
						clearTimeout(this.timerId);
					}, ms);
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.isActive {
		color: #CC3333;
	}

	.mask {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background-color: #000;
		-webkit-backdrop-filter: saturate(150%) blur(8px);
		background-color: rgba(0, 0, 0, .3);
		z-index: 20;
	}

	.root {
		position: absolute;
		top: 0;
		width: 100%;

		font-size: 28rpx;
		background-color: #fff;
		position: absolute;
		z-index: 1;

		.list-container {
			position: relative;
			background-color: #fff;
			width: 100%;
			z-index: 21;
			border-radius: 0px 0px 20px 20px;
			height: 320rpx;
			overflow-y: auto;
			.item {
				border-top: 1px solid #EEEEEE;
				font-weight: 500;
				padding-left: 61rpx;
				height: 80rpx;

				display: flex;
				flex-direction: column;
				justify-content: center;
			}
		}
	}
</style>