<template>
	<view class="bg">
		<view class="topImg relative">
			<img v-if="headImg" :src="showImg(headImg)" class="topImg" mode="aspectFill">
			<view class="icon-back"  :style="{top:systemInfo.textTop,left:'19rpx'}" @click="goBack()" >
				<uni-icons type="left" size="24" color="#fff"></uni-icons>
			</view>
		</view>
		
		
		<view class="goodBox">
			<view class="type-container">
				<view :class="['type',activeType==13?'active':'']" @click="changeActiveType(13)">精选酒店</view>
				<view :class="['type',activeType==14?'active':'']" @click="changeActiveType(14)">特色民宿</view>
			</view>
			
			<view class="goodItem" v-for="(item,index) in list" :key="index" @click="viewDetail(item)">
				<view class="left-image flex-shrink-0 relative">
					<image class="left-image " :src="showImg(item.image)" mode="aspectFill"></image>
					<!-- <div class="hot-tag text-overflow" v-if="item.label">{{ item.label.split(',')[0] }}</div>
					<div class="sale-tag text-overflow">已售{{ item.sales_number || 0 }}份</div> -->
				</view>
				
				<view class="contentBox flex flex-column flex-1">
					<view class="title text-overflowRows">{{item.title}}</view>

					<view class="flex-1 h-1rpx">
						<view class="hotel-tags">
							<!-- <template v-if="item.product_data">
							<view class="hotel-item" v-for="(itemShow,indexShow) in item.product_data_show || []" :key="indexShow">
								<view class="hotel-tip" v-if="indexShow<3">{{ itemShow.title }}</view>
								<view class="hotel-info text-overflow" v-if="indexShow<3">{{ itemShow.intro.map(v=>v.title).join("+") }}</view>
							</view>
							</template> -->
							<view class="tag-label no-scrollbar" v-if="item.label">
								<view class="tag-item" v-for="(itemShow,indexShow) in item.label.split(',')" :key="indexShow">
									{{itemShow}}
								</view>
							</view>
							<view class="hotel-item" v-if="item.address">
								<view class="hotel-tip-image">
									<img src="https://static.ticket.sz-trip.com/uploads/20240912/a0301af16f413baca5c9e7f36026ab14.png">
								</view>
								<view class="hotel-info text-overflow">{{ item.address }}</view>
							</view>
						</view>
					</view>
						

					<view class="flex-between">
						<view class="priceBox flex-1 w-1rpx">
							<view class="price">{{item.price/100}}</view>
						</view>
						<view class="order-btn flex-shrink-0">立即预定</view>
			
					</view>

					
				</view>
			</view>
		</view>
		<!-- <view class="finished-text" v-if="finished">没有更多数据了</view> -->
	</view>
</template>

<script>
	export default{
		data(){
			return {
				systemInfo: {
					height:"0px",
					textHeight:"0px",
					textTop:"0px",
					contentTop: '0px',
				},
				
				list: [],
				finished: false,
				headImg:null,
				navList: [],
				activeType: 13,
			}
		},
		onShow() {
			this.finished = false
			
		},
		onReady() {
			this.getList()
		},
		onLoad(options) {
			let that = this
			uni.getSystemInfo({
			  success(res) {
			    console.log(res)
			    that.systemInfo.height =res.windowHeight+'px'
				const menu=uni.getMenuButtonBoundingClientRect()
				that.systemInfo.textHeight=menu.height+"px"
				that.systemInfo.textTop=menu.top+"px"
				that.systemInfo.contentTop = (menu.height + menu.top)+"px"
			    console.log(that.systemInfo)
			  }
			})
			this.getHeadImg('hotel').then(res => {this.headImg = res})
		},
		  
		methods: {
			changeActiveType (val) {
				if (val!=this.activeType) {
					this.activeType = val
					this.list = []
					this.getList()
				}
			},
			
			// 根据景点标签获取景点列表
			getList(){
				this.Post({
					scenic_type_id: this.activeType,offset: this.list.length,limit: 10,
					lon: uni.getStorageSync('location').lon || '120',
					lat: uni.getStorageSync('location').lat || '30',
				},
				'/api/Scenic/getScenicByType').then(res => {
					let resData = res.data || []
     //                resData.forEach(v=>{
					// 	v.product_data_show = []
     //                    if (v.product_data) {
     //                        try{
					// 			v.product_data.forEach(x=>{
					// 				let [title,intro] = Object.entries(x)[0]
					// 				intro = JSON.parse(intro)
					// 				v.product_data_show.push({title: title, intro:intro})
					// 			})
     //                        } catch (e) {
     //                            console.log(v)
     //                        }
     //                    }
     //                })
					// console.log(resData)
					this.list = [...this.list, ...resData];
					if (res.data.length < 10) {
						this.finished = true
					}
				})
			},
			
			// 收藏按钮
			like(item){
				this.Post({
					type: 4,
					id: item.id
				}, '/api/scenic/collect').then(res => {
					if (res.code == 1) {
						uni.showToast({title: res.msg,icon:'none'})
						if (item.is_collect == 1) {
							item.is_collect = 0
						} else {
							item.is_collect = 1
						}
					}
				})
			},

			viewDetail (item) {
				this.goOtherDetail(item)
				if(!item.link_type) {
					uni.navigateTo({
						url: '/subPackages/hotelHomestay/detail?id=' + item.id
					});
				}
			}
		},
		onReachBottom() {
			setTimeout(() => {
				if (!this.finished) this.getList()
			},1000)
		}
	}
</script>

<style scoped lang="scss">
	*{
		box-sizing: border-box;
		font-family: PingFangSC;
	}
	.bg{
		min-height: 100vh;
		background: #F5F5F5;;
	}
	.topImg{
		width: 100%;
		height: 440rpx;
		.icon-back{
			position: absolute;
			display: flex;
			align-items: center;
			z-index: 50;
			background: rgba(0,0,0,0.5);
			border-radius: 50%;
			width: 60rpx;
			height: 60rpx;
			padding-left: 5rpx;
		}
	}
	
	
	.goodBox{
		width: 100%;
		z-index: 2;
		position: relative;
		padding: 26rpx;
		padding-top: 0;
		margin-top: -36rpx;
		
		.type-container{
			width: 532rpx;
			height: 73rpx;
			margin: 0 auto;
			display: flex;
			border-radius: 13rpx;
			overflow: hidden;
			margin-bottom: 26rpx;
			
			.type{
				flex: 1;
				text-align: center;
				line-height: 73rpx;
				font-weight: bold;
				font-size: 31rpx;
				background: #FFFFFF;
				color: #000000;
			}
			.type.active{
				color: #FFFFFF;
				background: #515150;
			}
		}
		
		
		.goodItem{
			width: 100%;
			height: 314rpx;
			background: #FFFFFF;
			margin-bottom: 26rpx;
			border-radius: 13rpx;
			display: flex;
			.left-image{
				width: 266rpx;
				height: 100%;
				border-radius: 13rpx 0rpx 13rpx 0rpx;
				flex-shrink: 0;
				
				.hot-tag{
					position: absolute;
					top: 0;
					left: 0;
					font-family: DingTalk JinBuTi;
					font-weight: 400;
					font-size: 28rpx;
					color: #FFFFFF;
					background: linear-gradient(-90deg,#FF413B, #FFAB2E);
					border-radius: 13rpx 0rem 13rpx 0rem;
					padding: 0 21rpx;
					line-height: 44rpx;
					height: 44rpx;
					max-width: 100%;
				}
				.sale-tag{
					position: absolute;
					bottom: 0;
					left: 0;
					right: 0;
					font-weight: 500;
					font-size: 24rpx;
					color: #FFFFFF;
					height: 47rpx;
					
					padding: 6rpx 21rpx;
					background: linear-gradient(90deg,rgba(0,0,0,0.5), rgba(0,0,0,0));
					border-radius: 0rem 0rem 0rem 13rpx;
				}
			}
			
			.contentBox{
				flex: 1;
				width: 1rpx;
				height: 100%;
				padding:19rpx 26rpx;
				justify-content: space-between;

				.title{
					width: 100%;
					font-weight: 500;
					font-size: 33rpx;
					color: #000000;
				}
				
				.tag-container{
					display: flex;
					flex-wrap: nowrap;
					overflow-x: auto;
					
				}
				
				
				.priceBox{
					padding-right: 15rpx;
					color: #000000;
					font-size: 24rpx;
					.price{
						font-family: PingFang SC;
						font-weight: bold;
						font-size: 38rpx;
						color: #C3282E;
						display: inline-block;
					}
					.price::before{
						content: '￥';
						color: #C3282E;
						font-size: 24rpx;
					}
					.price::after{
						content: '起';
						color: #000000;
						font-size: 24rpx;
						font-weight: normal;
					}
				}
				
				
				.order-btn{
					width: 147rpx;
					height: 53rpx;
					background: #C3282E;
					border-radius: 27rpx;
					font-weight: bold;
					font-size: 28rpx;
					color: #FFFFFF;
					text-align: center;
					line-height: 53rpx;
				}
			
			}
		}
		
		.hotel-tags{
                width: 100%;
                padding: 25rpx 0;
                .hotel-item{
                    display: flex;
                    align-items: center;
                    width: 100%;
                    margin-bottom:6rpx;
                }
                .hotel-tip{
                    width: 33rpx;
                    height: 33rpx;
                    background: #248BAA;
                    border-radius: 50%;
                    flex-shrink: 0;
                    margin-right: 8rpx;
                    font-weight: 500;
                    font-size: 23rpx;
                    color: #FFFFFF;
                    text-align: center;
                    line-height: 33rpx;
                }
                .hotel-tip-image{
                    width: 33rpx;
                    height: 33rpx;
                    margin-right: 8rpx;
                    text-align: center;
					line-height: 33rpx;
                    img{
                        width: 17rpx;
                        height: 21rpx;
                    }
                }
                .hotel-info{
                    font-family: PingFang SC;
                    font-weight: 500;
                    font-size: 23rpx;
                    color: #666666;
                    flex: 1;
                    width: 1px;
                    height: 33rpx;
					overflow-y: hidden;
                }
            }
	}
	.tag-label{
		width: 100%;
		display: flex;
		flex-wrap: nowrap;
		overflow-x: auto;
		margin-bottom: 34rpx;

		.tag-item{
			padding: 3rpx 15rpx;
			border-radius: 19rpx 18rpx 18rpx 19rpx;
			border: 1px solid #515150;
			font-weight: 500;
			font-size: 25rpx;
			color: #515150;
			flex-shrink: 0;
			margin-right: 14rpx;
		}
	}
</style>