<template>
	<view class="container">
		<view class="banner">
			<swiper indicator-dots="true" indicator-active-color="#fff" circular="true" autoplay="true" interval="3000"
				duration="500" class="swiper-container">
				<swiper-item v-for="(item, index) in bannerList" :key="index">
					<image :src="item.image" class="swiper-image"></image>
				</swiper-item>
			</swiper>
		</view>
		<!-- item -->
		<view class="content">
			<view class="content-item" v-for="(item,index) in dataList" :key="index" @click="togamestrategy(item.name)">
				<image :src="item.img" mode=""></image>
			</view>
		</view>
		<!-- list -->
		<view style="padding: 20rpx;">
			<view class="popular">
				<view class="title">
					推薦遊戲
				</view>
				<scroll-view scroll-y="true" style="height: 90%;">
					<view class="gameitem" v-for="item in list" :key="item.id" @click.stop="togamesDetailPage(item)">
						<view class="g_img">
							<image :src="publicUrl + item.img" mode=""></image>
						</view>
						<view class="g_rig">
							<view class="g_top">
								<view class="g_name">
									{{item.title_cn}}
								</view>
								<view class="g_btn" @click.stop="toRegistergame(item)">
									加入
								</view>
							</view>
							<view class="ga_cont">
								{{item.desc_cn}}
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
    import { BASE_URL} from '@/request/config.js'
    import {_pubgame} from "@/request/api.js"
	export default {
		data() {
			return {
				publicUrl:"",
				bannerList: [{
						image: '../../static/swiper4.png'
					},
					{
						image: '../../static/swiper5.png'
					},
					{
						image: '../../static/swiper6.png'
					}
				],
				dataList: [{
					name: '遊戲攻略',
					img: '../../static/game2.png'
				}, {
					name: '郵箱賬號',
					img: '../../static/game3.png'
				}],
                page:1,
                total:0,
                list :[],
			};
		},
        mounted() {
            this.loadList();
			this.publicUrl = BASE_URL;
        },
		methods: {
			togamesDetailPage(item){
				let gameItem = JSON.stringify(item);
				if(item.reflink == '/page/geme/regeditgame'){
					uni.navigateTo({
						url: '/pages/interstellareye/Registergame?item=' + gameItem
					})
				}else{
					uni.navigateTo({
						url:`/pages/game/games-detail?item=${gameItem}`
					})
				}
			},
            async loadList(){
               const res =  await _pubgame({page:this.page})
               this.total = res.data.total
               this.page = res.data.total
               this.list = res.data.data
            },
			togamestrategy(name) {
				switch (name) {
					case '遊戲攻略':
						uni.navigateTo({
							url: '/pages/game/gamestrategy'
						})
						break;
					case '郵箱賬號':
						uni.navigateTo({
							url: '/pages/game/accountnumber'
						})
						break;
				}
			},
			toRegistergame(item) {
				let gameItem = JSON.stringify(item);
				if(item.reflink == '/page/geme/regeditgame'){
					uni.navigateTo({
						url: '/pages/interstellareye/Registergame?item=' + gameItem
					})
				}else{
					uni.setClipboardData({
						data: item.reflink,
						success: () => {
					        uni.showToast({
					            icon:'none',
					            title:"游戏链接已复制,请使用浏览器打开"
					        })
						}
					});
				}
			}
		}
	}
</script>

<style lang="scss">
	.container {
		border-top: 1px solid dimgrey;
		width: 100vw;
		min-height: 100vh;
		padding: 10px;
		box-sizing: border-box;
		background: linear-gradient(to bottom, #000033, #51599b);

		.banner {
			height: 250rpx;
			width: 100%;
			padding: 15rpx;
			box-sizing: border-box;
			border-radius: 20rpx;
			overflow: hidden;

			image {
				width: 100%;
				height: 100%;
				border-radius: 20rpx;
			}

			.swiper-container {
				width: 100%;
				height: 100%;
				overflow: hidden;
				border-radius: 20rpx;

				.swiper-item {
					border-radius: 20rpx;
				}
			}
		}

		.content {
			padding: 15rpx;
			width: 100%;
			box-sizing: border-box;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;

			.content-item {
				width: 330rpx;
				height: 140rpx;
				margin-bottom: 20rpx;
				border-radius: 20rpx;
				position: relative;
			}
		}

		image {
			width: 100%;
			height: 100%;
			border-radius: 20rpx;
		}

		.popular {
			background-color: #383d84;
			padding: 30rpx;
			border-radius: 20rpx;
			height: 1000rpx;
			color: #fff;
			width: 100%;
			box-sizing: border-box;

			.title {
				padding: 15rpx;
				border-bottom: 1rpx solid #41468d;
				margin-bottom: 20rpx;
			}

			.p_top {
				display: flex;
				align-items: center;
				justify-content: space-between;
				background-color: #fdf7f2;
				width: 100%;
				height: 60rpx;
				font-size: 28rpx;
				border-radius: 20rpx;
				margin-bottom: 30rpx;
				padding: 0 20rpx;
				box-sizing: border-box;

				.tit {
					color: #EAA97D;
					font-size: 24rpx;
				}
			}

			.gameitem {
				width: 100%;
				height: 160rpx;
				display: flex;
				padding: 1rpx;
				align-items: center;
				margin-bottom: 20rpx;

				.g_img {
					width: 150rpx;
					height: 150rpx;
					background-color: #51599b;
					border-radius: 20rpx;
				}

				.g_rig {
					flex: 1;
					padding: 1rpx;
					margin-left: 10rpx;
					display: flex;
					justify-content: space-between;
					flex-direction: column;

					.g_top {
						display: flex;
						justify-content: space-between;
						margin-bottom: 20rpx;

						.g_btn {
							width: 90rpx;
							height: 50rpx;
							background-color: #4f5ad6;
							display: flex;
							justify-content: center;
							align-items: center;
							border-radius: 40rpx;
							font-size: 26rpx;
						}
					}

					.ga_cont {
						font-size: 22rpx;
						color: #D7D8E6;
						display: -webkit-box;
						/* 将对象作为弹性伸缩盒子模型显示 */
						-webkit-box-orient: vertical;
						/* 从上到下垂直排列子元素 */
						-webkit-line-clamp: 2;
						/* 限制显示的行数为2行 */
						overflow: hidden;
						/* 溢出隐藏 */
						text-overflow: ellipsis;
					}
				}
			}
		}
	}
</style>