<template>
	<view class="page">
		<loadSke :loading="loading" :list="typeList">
			<view class="tabs">
				<view class="tab" :class="{selected:index==active}" @click="tabClick(index)"
					v-for="(item,index) in typeList" :key='index'>
					{{item.type_name}}
				</view>
			</view>
			<scroll-view class='scroll-view' :scroll-into-view="scrollId" :scroll-y='true' :scroll-with-animation='true' @scroll='scrollChange'>
				<view class="box" v-for="(item,index) in typeList" :key='index' :id="'scroll'+index">
					<view class="type_name">
						<m-icon type="name_left" color="red" />
						<text>{{item.type_name}}</text>
						<m-icon type="name_right" color="red" />
					</view>
					<view class="type-box">
						<view class="type" v-for="(itemSon,indexSon) in item.list" :key='indexSon'
							@click="$utils.goPage('/pages/fulu/placeorder',null,{product_ids:itemSon.product_ids,icon:itemSon.icon,remark:itemSon.remark})">
							<view class="top-des">
								<image class="icon" :src="itemSon.icon" mode="scaleToFill"></image>
								<view class="right">
									<text class="name">{{itemSon.name}}</text>
									<text class="introduction">{{itemSon.introduction}}</text>
								</view>
							</view>
							<text class="btn">立即充值</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</loadSke>
	</view>

</template>

<script>
	export default {
		data: () => ({
			active: 0,
			typeList: [],
			loading: true,
			scrollId: 'scroll0'
		}),
		async mounted() {
			this.loading = true
			let res = await this.$api.fulu.goods.getTypeList()
			console.log(res)
			this.typeList = res.data
			this.$nextTick(() => {
				this.loading = false
			})
		},
		methods: {
			tabClick(index) {
				this.active = index
				this.scrollId = 'scroll' + index
			},
			scrollChange(e){
				console.log(e)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		.tabs {
			display: flex;
			justify-content: space-around;
			align-items: center;
			background-color: #FFFFFF;
			padding: 0 20rpx;
			position: sticky;
			top: 0;
			left: 0;
			z-index: 1;
			overflow-x: auto;

			.tab {
				text-align: center;
				flex-shrink: 0;
				width: 250rpx;
				padding: 20rpx 0;
				height: 80rpx;
				box-sizing: border-box;
			}

			.selected {
				position: relative;

				&::after {
					content: '';
					width: 80rpx;
					height: 6rpx;
					background-color: red;
					position: absolute;
					bottom: 0;
					left: 50%;
					transform: translateX(-50%);
				}
			}
		}
		
		.scroll-view{
			height: calc(100vh - 100rpx);
		}

		.box {
			margin-top: 20rpx;
			background-color: #FFFFFF;

			&:nth-last-of-type(1) {
				height: calc(100vh - 100rpx);
			}

			.type_name {
				display: flex;
				justify-content: center;
				align-items: center;
				padding: 20rpx;
			}

			.type-box {
				display: flex;
				justify-content: flex-start;
				align-items: center;
				flex-wrap: wrap;
				padding-left: 20rpx;

				.type {
					width: 345rpx;
					background: linear-gradient(0deg, #FDDEAF, #FDF3D8);
					margin-right: auto;
					margin-bottom: 20rpx;
					border-radius: 20rpx;
					padding: 30rpx;
					box-sizing: border-box;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;

					.top-des {
						width: 100%;
						display: flex;
						justify-content: flex-start;
						align-items: center;

						.icon {
							width: 91rpx;
							height: 75rpx;
							margin-right: 20rpx;
						}

						.right {
							display: flex;
							flex-direction: column;
							align-items: center;

							.name {
								color: #744520;
								font-size: 30rpx;
								font-weight: 500;
							}

							.introduction {
								margin-top: 15rpx;
								font-weight: 400;
								color: #744520;
								font-size: 26rpx;
								white-space: nowrap;
							}
						}
					}

					.btn {
						margin-top: 30rpx;
						width: 166rpx;
						height: 60rpx;
						background: linear-gradient(90deg, #E31818, #ED3E24, #ED4F24);
						border-radius: 30px;
						padding: 18rpx;
						box-sizing: border-box;
						font-size: 26rpx;
						font-weight: 400;
						color: #FFFFFF;
						display: flex;
						justify-content: center;
						align-items: center;
					}
				}
			}
		}
	}
</style>
