<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="#242424"></uni-icons>
			</view>
		</view>
		
		
		<view class="goodBox">
			<view class="goodItem flex-column" 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>
					<view class="collect" @click.stop="like(item)">
						<image src="https://tongli.sz-trip.com/uploads/20240829/9dbb80cafe8375bd6d5c96fccb617962.png" v-if="item.is_collect"></image>
						<image src="https://tongli.sz-trip.com/uploads/20240826/564af778708591f5de29174d3b14bbff.png" v-else></image>
					</view>
					
				</view>
				
				<view class="contentBox flex-column flex-1 h-1rpx">
					<view class="title text-overflow">{{item.title}}</view>
					<view class="flex-between">
						<view class="flex-1 w-1rpx">
							<view class="tag-container no-scrollbar" v-if="item.label">
								<view class="tag" v-for="(tag,tagIndex) in item.label.split(',')" :key="tagIndex">{{tag}}</view>
							</view>
						</view>
						
					</view>
					<view class="flex-between">
						<view class="distance">{{item.distance?`距您约${item.distance/1000+'km'}`:''}}</view>
						<view class="priceBox flex-shrink-0">
							<view class="price">{{item.price/100}}</view>
						</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: [],
				actNavIndex: 0,
				type_id: 11,//酒店分类id
			}
		},
		onShow() {
			this.headImg = 'https://tongli.sz-trip.com/uploads/20240826/8653c32761e01ee683505eddba1ae22b.png'
			this.finished = false
			// this.getHeadImg('piaowu')
		},
		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)
			  }
			})
		},
		  
		methods: {

			getHeadImg(type){
				this.headImg = null
				this.Post(
					{
						type,
					},
					'https://yjdtadmin.sz-trip.com/api/public_service/getKumgangHeadImgList'
				).then(res => {
					this.headImg = res.data[0].image
				});
			},
			// 根据景点标签获取景点列表
			getList(){
				this.Post({
					scenic_type_id: this.type_id,offset: this.list.length,limit: 10,
					lon: uni.getStorageSync('location').lon || '120',
					lat: uni.getStorageSync('location').lat || '30',
				},
				'/api/Scenic/getScenicByType').then(res => {
					this.list = [...this.list, ...res.data];
					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: #FFFFFF;
	}
	.topImg{
		width: 100%;
		height: 440rpx;
		.icon-back{
			position: absolute;
			display: flex;
			align-items: center;
			z-index: 50;
		}
	}
	
	
	.goodBox{
		width: 100%;
		z-index: 2;
		padding: 26rpx;
		
		.goodItem{
			width: 100%;
			height: 525rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 9rpx 0rpx rgba(153,153,153,0.38);
			margin-bottom: 26rpx;
			border-radius: 13rpx;
			.left-image{
				width: 100%;
				height: 321rpx;
				border-radius: 13rpx 13rpx 0rpx 0rpx;
				
				.collect{
					position: absolute;
					top: 22rpx;
					right: 22rpx;
					width: 51rpx;
					height: 51rpx;
					background: rgba(0,0,0,0.5);
					border-radius: 50%;
					display: flex;
					align-items: center;
					justify-content: center;
					image{
						width: 35rpx;
						height: 35rpx;
					}
				}
			}
			
			.contentBox{
				padding:19rpx 26rpx;
				width: 100%;
				justify-content: space-between;
				
				.title{
					width: 100%;
					font-weight: bold;
					font-size: 31rpx;
					color: #000000;
				}
				
				.tag-container{
					display: flex;
					flex-wrap: nowrap;
					overflow-x: auto;
					.tag{
						background: rgba(205,233,209,0.3);
						border-radius: 7rpx 5rpx 5rpx 7rpx;
						border: 1px solid rgba(135,205,147,0.3);
					
						padding: 4rpx 14rpx;
						font-weight: 500;
						font-size: 25rpx;
						color: #5BA06A;
						text-align: center;
						margin-right: 12rpx;
						flex-shrink: 0;
					}
				}
				
				
				.priceBox{
					width: 120rpx;
					.price{
						font-family: PingFang SC;
						font-weight: bold;
						font-size: 33rpx;
						color: #F02A2A;
						text-align: right;
					}
					.price::before{
						content: '￥';
						color: #F02A2A;
						font-size: 24rpx;
					}
					.price::after{
						content: '起';
						color: #999;
						font-size: 24rpx;
						font-weight: normal;
					}
				}
				
				.distance{
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 27rpx;
					color: #999999;
				}
				.order-btn{
					width: 173rpx;
					height: 55rpx;
					background: #70B57F;
					border-radius: 27rpx 27rpx 27rpx 27rpx;
					font-weight: bold;
					font-size: 29rpx;
					color: #FFFFFF;
					text-align: center;
					line-height: 55rpx;
				}
			
			}
		}
	}
</style>