<template>
	<view class="bg">
		<image v-if="headImg" :src="showImg(headImg)" class="topImg" mode="widthFix"></image>
		
		<image class="what-img" @click="openPop()" mode="aspectFill" src="https://static.ticket.sz-trip.com/uploads/20250916/d5e91bdb2114c3e485349d8edae18173.png"></image>
		
		<view class="main-container" style="margin-top: -2400rpx;position: relative;" >

			<view class="type-container no-scrollbar" style="padding: 0 20rpx;">
				<view :class="['type-item']" @click="changeTypeIndex(i)"
				v-for="(item,i) in typeList" :key="i">
					<image v-show="typeIndex==i" mode="aspectFill" :src="item.imgs"></image>
					<image v-show="typeIndex!=i" mode="aspectFill" :src="item.img"></image>
				</view>
			</view>
			<uni-transition :mode-class="['slide-left','fade']" :show="show">
			<view class="type-container">
				<image :src="typeList[typeIndex].textImg" mode="widthFix" style="width: 100%;margin: 25rpx 0 30rpx;"></image>
			</view>
			</uni-transition>
		
			

			<view class="flex-between" style="flex-wrap: wrap;padding: 0 26rpx;box-sizing: border-box;">
				<view class="column-product"  @click="gotoDetailByType(item)" :key="index"
					v-for="(item,index) in typeList[typeIndex].list.slice(0,typeList[typeIndex].viewNum)">
					<image class="img" :src="showImg(item.headimg)" mode="aspectFill"></image>
					<view class="content flex-column">
						<view class="title text-overflowRows">{{item.title}}</view>
						<view>
							<view class="tags"  v-if="item.display_tags">
								<view class="tag text-overflow" v-for="(tag,tagI) in item.display_tags.split(',')" :key="tagI">{{tag}}</view>
							</view>
						
						
							<view class="flex-between">
								<view class="price">{{item.price/100}}</view>
								<view class="btn">立即购买</view>
							</view>
						</view>
					</view>
					
				</view>
			</view>
			
			<view class="view-more" v-if="typeList[typeIndex].list.length>0&&typeList[typeIndex].viewNum<=6" @click="typeList[typeIndex].viewNum=999">
			查看更多<image src="https://static.ticket.sz-trip.com/uploads/20250909/848e3a18b3ad3227fa4b2952890b91ef.png"></image>
			</view>
			
			<image class="bottom-img" src="https://static.ticket.sz-trip.com/uploads/20250909/55c100f9650df6cbd4a4e5a18c8201de.png"></image>
			<image @click="returnTop" v-show="showGoTop" class="back-img" src="https://static.ticket.sz-trip.com/uploads/20250915/74031edf3be17888e522df104e790540.png"></image>
			
		</view>
		
		<uni-popup ref="popup" type="center" mask-background-color="rgba(10,13,11,0.72);">
			<view style="idth: 608.67rpx;height: 592.67rpx;position: relative;">
				<image style="width: 608.67rpx;height: 592.67rpx;" mode="aspectFill"
				src="https://static.ticket.sz-trip.com/uploads/20250915/7a262bdbe38f2fb6efb202d2a14d7512.png"></image>
				<view style="position: absolute;width: 60rpx;height: 60rpx;top: 10rpx;right: 10rpx;"
				@click="$refs.popup.close()"></view>
			</view>
			
		</uni-popup>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				viewNum: 3,
				headImg: '',
				typeIndex: 0,
				typeList: [
					{
						id: 104,title: "绿色食品",viewNum:6, list: [],
						img:"https://static.ticket.sz-trip.com/uploads/20250916/70b50a9d3f0b70454763e7146ac0a4d1.png",
						imgs:"https://static.ticket.sz-trip.com/uploads/20250916/3b251683c250cf6669378266ed786de4.png",
						textImg: "https://static.ticket.sz-trip.com/uploads/20250916/e03b1f9e7a9880d2c7f67ee6b4a58643.png",
					},
					{
						id: 105,title: "有机农产品",viewNum:6, list: [],
						img:"https://static.ticket.sz-trip.com/uploads/20250916/600b3f0ca1b6582da3dc128f98cc1ea9.png",
						imgs:"https://static.ticket.sz-trip.com/uploads/20250916/9692497b22091c3e3d3d69bf9c4fd311.png",
						textImg:"https://static.ticket.sz-trip.com/uploads/20250916/51606f5e0a94c364a8237777e5398aaa.png",
					},
					{
						id: 106,title: "名特优新",viewNum:6, list: [],
						img:"https://static.ticket.sz-trip.com/uploads/20250916/9810f9261e137b354132063fced2d43c.png",
						imgs:"https://static.ticket.sz-trip.com/uploads/20250916/2b3cfb94571cd911af3cca2b4027438c.png",
						textImg:"https://static.ticket.sz-trip.com/uploads/20250916/d99a160fb1caa3eb56697344fc08df46.png",
					},
					{
						id: 107,title: "农产品地理标志",viewNum:6, list: [],
						img:"https://static.ticket.sz-trip.com/uploads/20250916/6c8216888e1224e9534309bde2a87a14.png",
						imgs:"https://static.ticket.sz-trip.com/uploads/20250916/37d84af1f692cce86158ff0784fefb73.png",
						textImg:"https://static.ticket.sz-trip.com/uploads/20250916/898fda5fdc950817faa0bfd318f1fa95.png",
					},
				],
				showGoTop: false,
				
				show: true,
			}
		},
		onLoad(option) {
			this.getHeadImg(2397)
			this.getGoods()
		},
		onReady() {
			
		},
		methods: {
			changeTypeIndex (i) {
				if (this.typeIndex==i) {
					return
				}
				this.show = false
				setTimeout(()=>{
					this.typeIndex = i;
					this.show = true;
				},300)
			},
			getHeadImg (id) {
				this.Post({id},'/api/multimedia/detail').then(res => {
					this.headImg = res.data.head_img
					uni.setNavigationBarTitle({
						title:res.data.title
					})
				});	
			},
			goRule (id) {
				uni.navigateTo({
					url:"/subPackages/activity/commonRule?id="+id
				})
			},
			openPop () {
				this.$refs.popup.open()
			},
			
			// 产品列表
			getGoods() {
				for(let p of this.typeList) {
					this.Post({
						tag_id: p.id,
						offset: 0,
					    limit: 999,
					},'/api/product/get_product_by_tag_subject').then(res => {
						if (res.data.list.length < p.viewNum) {
							p.viewNum = 999
						}
						p.list = res.data.list
						console.log(p)
					})
				}
			
			},
			viewDetail(item) {
				this.gotoDetailByType(item)
			},
			returnTop(){
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 200,
				})
			},
		},
		onPageScroll(res) {
			this.showGoTop = res.scrollTop > 200 ? true : false;
		}
	}
</script>

<style lang="scss" scoped>
	view{
		box-sizing: border-box;
	}
	.bg {
		width: 750rpx;
		min-height: 100vh;
		padding-bottom: 60rpx;
		position: relative;
		background: white;
	}
	
	.topImg {
		width: 100%;
	}
	.what-img{
		position: absolute;
		top: 40rpx;
		right: 0;
		width: 230.67rpx;
		height: 46.67rpx;
	}
	
	.main-container{
		width: 100%;
		padding: 48rpx 0 60rpx;
		
	}
	.type-item:first-of-type{
		width: 238.67rpx;
	}
	.type-item:nth-of-type(1){
		width: 262.67rpx
	}
	.type-item:nth-of-type(2){
		width: 238.67rpx
	}
	.type-item:nth-of-type(2){
		width: 307.33rpx
	}
	
	
	.title{
		font-weight: 600;
		font-size: 28rpx;
		color: #000000;
	}
	.tags{
		width: 100%;
		display: flex;
		overflow: hidden;
		margin-bottom: 18rpx;
		.tag{
			
			height: 40rpx;
			line-height: 38rpx;
			font-weight: 400;
			font-size: 24rpx;
			color: #0E6500;
			padding: 0rpx 10rpx;
			border-radius: 20rpx;
			border: 1px solid #317626;
			margin-right: 13rpx;
		}
	}
	.view-more{
		font-weight: 400;
		font-size: 24rpx;
		color: #8C8C8C;
		text-align: center;
		margin: 27rpx auto 40rpx;
		image{
			width: 18.67rpx;
			height: 18.67rpx;
			margin-left: 8rpx;
		}
	}

	.type-container{
		display: flex;
		flex-wrap: nowrap;
		width: 100%;
		overflow-y: hidden;
		overflow-x: auto;
		padding:0 26rpx;
		.type-item{
			height: 88rpx;
			margin-right: 10rpx;
			flex-shrink: 0;
			image{
				width: 100%;
				height: 100%;
			}
		}
		.type-item:first-of-type{
			width: 238.67rpx;
		}
		.type-item:nth-of-type(2){
			width: 262.67rpx
		}
		.type-item:nth-of-type(3){
			width: 238.67rpx
		}
		.type-item:nth-of-type(4){
			width: 307.33rpx;
			margin-right: 0;
		}
	}

	.column-product{
		width: 335rpx;
		height: 569rpx;
		background: #ECFFE9;
		border-radius: 25rpx;
		overflow: hidden;
		margin-bottom: 32rpx;
		font-size: 0;
		box-shadow: 0rpx 3rpx 15rpx 0rpx rgba(0,0,0,0.18);
		.img{
			width: 335rpx;
			height: 335rpx;
			border-radius: 25rpx 25rpx 0rpx 0rpx;
			flex-shrink: 0;
		}
		.content{
			width: 100%;
			flex: 1;
			height: 234rpx;
			justify-content: space-between;
			padding:10rpx 16rpx 20rpx;
		}
		.price{
			font-weight: bold;
			font-size: 28rpx;
			color: #FF7700;
			&::before{
				content: "￥";
				font-size: 24rpx;
				font-weight: 500;
			}
			&::after{
				content: "起";
				font-size: 24rpx;
				font-weight: 500;
			}
		}
		.btn{
			width: 160rpx;
			height: 57rpx;
			background: linear-gradient( 270deg, #319F56 0%, #9CED46 100%);
			border-radius: 200rpx 200rpx 200rpx 200rpx;
			font-weight: bold;
			font-size: 28rpx;
			color: #FFFFFF;
			line-height: 57rpx;
			text-align: center;
			text-shadow: 0px 2px 4px #244705;
		}
	}
	
	.bottom-img{
		width: 149.33rpx;
		height: 64rpx;
		margin: 27rpx auto 0;
		display: block;
	}
	.back-img{
		position: fixed;
		width: 68rpx;
		height: 68rpx;
		bottom: 66rpx;
		right: 26rpx;
	}
</style>