<!-- 
http://localhost:5173/custom/#/pages/tpl/challenge/index?pagetype=challenge_result&status=fail
https://oss-mbh5.colormaprun.com/custom/#/pages/tpl/challenge/index?pagetype=challenge_result&status=fail
 -->
<template>
	<view :class="tplStyle">
		<view class="body">
			<view class="content uni-column">
				<view class="top uni-column">
					<image v-if="logo.length > 0 && sublogo.length > 0" class="logo-small" mode="aspectFit" :src="logo">
					</image>
					<image v-if="logo.length > 0 && sublogo.length == 0" class="logo" mode="aspectFit" :src="logo">
					</image>
					<image v-if="sublogo.length > 0" class="sublogo" mode="aspectFit" :src="sublogo"></image>
					<text class="subTitle">{{subTitle}}</text>
					<text class="gameName">{{ecName}}</text>
				</view>
				<view class="main uni-column uni-jcsa">
					<view class="fail failBg"></view>
					<view class="nostop nostopBg"></view>
				</view>

				<view class="btnRankList btnRankListBg" @click="btnRankList">点击查看排行榜</view>
			</view>

			<my-fab></my-fab>
		</view>
	</view>
</template>

<script>
	import tools from '/common/tools';
	import {
		token,
		apiCardUrlQuery,
		checkResCode
	} from '/common/api';

	export default {
		data() {
			return {
				token: "",
				matchType: 0, 	// 游戏类型 1 普通活动 2 线下赛 3 线上赛
				ecId: 0, 		// 卡片id
				ecName: "",		// 卡片名称
				tplStyle: "",	//模板类型 对应tplConfigs的key
				logo: "",
				sublogo: "",
				subTitle: "",

				urlRs: [],		// Url集合
			}
		},
		computed: {
		},
		onLoad(event) { // 类型非必填，可自动推导
			this.token = event["token"] ?? token;
			this.actId = event["id"] ?? 0;
			this.matchType = event["matchType"] ?? 0;

			this.tplStyle = event["tplStyle"] ?? "orange";
			this.logo = event["logo"] ?? "";
			this.sublogo = event["sublogo"] ?? "";
			this.subTitle = event["subTitle"] ?? "";

			// console.log("event:", JSON.stringify(event));
			// uni.showToast({
			// 	title: 'event：' + JSON.stringify(event),
			// 	icon: 'none',
			// 	duration: 10000
			// });

			this.cardUrlQuery();
		},
		methods: {
			// 根据游戏id查询卡片信息
			cardUrlQuery() {
				uni.request({
					url: apiCardUrlQuery,
					header: {
						"Content-Type": "application/x-www-form-urlencoded",
						"token": this.token,
					},
					method: "POST",
					data: {
						actId: this.actId,
						matchType: this.matchType
					},
					success: (res) => {
						// console.log("cardUrlQuery", res);
						if (res.data.code == 0) {
							const data = res.data.data;
							this.ecId = data.ecId;
							this.ecName = data.ecName;
							this.urlRs = data.urlRs;
						}
					},
					fail: (err) => {
						console.log("cardUrlQuery err", err);
					},
				});
			},
			btnRankList() {
				// console.log("urlRs", this.urlRs);
				// const rankListUrl = this.urlRs.find(item => item.name === 'rankListUrl');
				const rankListUrl = this.urlRs.rankListUrl;
				// console.log("rankListUrl", rankListUrl);
				if (rankListUrl != null) {
					let url = "";
					if (rankListUrl.indexOf('?') !== -1) {
						url = rankListUrl + '&token=' + this.token + '&id=' + this.ecId;
					} else {
						url = rankListUrl + '?token=' + this.token + '&id=' + this.ecId;
					}
					console.log("url", url);
					// uni.navigateTo({
					// 	url: url
					// });
					window.location.href = url;
				} else {
					uni.showToast({
						// title: '网址错误：' + rankListUrl,
						title: '请升级APP到最新版才能查看排行榜',
						icon: 'none',
						duration: 3000
					});
				}
			}
		}
	}
</script>

<style lang="scss">
	.orange {
		.body {
			background-color: #FF5E00;
		}

		.subTitle {
			color: #FFF45E;
		}

		.gameName {
			color: #FFF45E;
		}

		.failBg {
			background-image: url("/static/tpl/challenge/fail.png");
		}

		.nostopBg {
			background-image: url("/static/tpl/challenge/nostop.png");
		}
		
		.btnRankListBg {
			background: #FFFFFF;
			color: #E05200;
		}
	}

	.body {
		width: 100vw;
		min-height: 100vh;
	}

	.content {
		width: 750rpx;
		min-height: 100vh;
	}

	.top {
		width: 100%;
		padding-top: 90rpx;
	}

	.logo {
		width: 105px;
		height: 105px;
	}

	.logo-small {
		width: 86px;
		height: 86px;
	}

	.sublogo {
		width: 100%;
		height: 36px;
		margin-top: 10px;
	}

	.subTitle {
		padding-top: 15px;
		/* padding-bottom: 30rpx; */
		font-family: Source Han Sans CN;
		font-weight: 400;
		font-size: 23px;
		color: #FFEE0B;
		// text-shadow: 2.21px 2.21px 0px  #640008;
		white-space: nowrap;
	}

	.gameName {
		padding-top: 30rpx;
		padding-bottom: 30rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		font-size: 50rpx;
		color: #ffffff;
		white-space: nowrap;
	}

	.main {
		width: 100%;
		height: 39vh;
		// background-color: #b0352e;
	}

	.fail {
		width: 100%;
		height: 120rpx;
		background-repeat: no-repeat;
		background-position: center;
		background-size: contain;
	}
	
	.nostop {
		width: 100%;
		height: 100rpx;
		background-repeat: no-repeat;
		background-position: center;
		background-size: contain;
	}
	
	.btnRankList {
		// opacity: 30%;
		width: 194px;
		height: 35px;
		margin-top: 90rpx;
		margin-bottom: 60rpx;
		background: #b0352e;
		border-radius: 18px;
		align-items: center;
		color: #ffffff;
		font-size: 16px;
		line-height: 35px;
	}
	
</style>