<template>
	<g-toast :is-show="isShowToast">
		<view class="challenge-num">
			<view class="challenage-num-top">
				<view class="challenage-num-body">
					<view class="challenge-num-item">
						<view>
							<text class="label">参加挑战:</text>
							<text class="spec">
								{{ userServerInfo.challenge_result.data.challenge_num || 0 }}
							</text>
							<text class="label">场</text>
						</view>
						<view>
							<text class="label">参加竞猜:</text>
							<text class="spec">
								{{ userServerInfo.challenge_result.data.guessing_num || 0 }}
							</text>
							<text class="label">场</text>
						</view>
					</view>
					<view class="challenge-num-item">
						<view>
							<text class="label">挑战成功:</text>
							<text class="spec">
								{{ userServerInfo.challenge_result.data.challenge_success || 0 }}
							</text>
							<text class="label">场</text>
						</view>
						<view>
							<text class="label">挑战失败:</text>
							<text class="spec">
								{{ userServerInfo.challenge_result.data.challenge_fail || 0 }}
							</text>
							<text class="label">场</text>
						</view>
					</view>
					<view class="challenge-num-item">
						<view>
							<text class="label">猜赢了:</text>
							<text class="spec">
								{{ userServerInfo.challenge_result.data.guessing_success || 0 }}
							</text>
							<text class="label">场</text>
						</view>
						<view>
							<text class="label">猜输了:</text>
							<text class="spec">
								{{ userServerInfo.challenge_result.data.guessing_fail || 0 }}
							</text>
							<text class="label">场</text>
						</view>
					</view>
				</view>
			</view>
			<view class="challenge-num-btn" @click="toChallenge">查看详情</view>
		</view>
	</g-toast>
</template>

<script>
	import { toClieckedToast } from "../../utils/api/toast.js"
	import GToast from "../../components/global/toast.vue"
	export default {
		components: {
			GToast
		},
		data() {
			return {
				serverUserInfo: uni.getStorageSync("serverUserInfo"),
				initToast: true
			}
		},
		computed: {
			isShowToast() {
				let { challenge_result } = this.serverUserInfo
				return this.initToast && challenge_result && challenge_result.type === 1
			}
		},
		methods: {
			toChallenge() {
				let { challenge_result } = this.serverUserInfo
				toClieckedToast({
					id: challenge_result.id
				}).then(res => {
					this.serverUserInfo.challenge_result = {}
					uni.setStorage({
						key: "serverUserInfo",
						data: this.serverUserInfo,
						success() {
							uni.navigateTo({
								url: "../../pages/challenge/index"
							})
						}
					})
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.challenge-num {
		display: flex;
		flex-direction: column;
		align-items: center;
		.challenage-num-top{
			width: 626rpx;
			height: 612rpx;
			background: url(https://api.jiuweiyun.cn/public/uploads/weapp/icon/challenge_res.png) center no-repeat;
			background-size: 100%;
			margin: 0 auto 94rpx auto;
			position: relative;
			.challenage-num-body {
				width: 570rpx;
				height: 385rpx;
				position: absolute;
				bottom: 28rpx;
				left: 28rpx;
				border-radius: 24rpx;
				padding: 84rpx 30rpx 44rpx 30rpx;
				display: flex;
				justify-content: space-between;
				flex-direction: column;
				box-sizing: border-box;
				.challenge-num-item {
					display: flex;
					align-items: center;
					justify-content: space-between;
					.label {
						color: #5D330D;
						font-size: 32rpx;
						margin-right: 10rpx;
					}
					.spec {
						color: #DD372D;
						font-size: 48rpx;
					}
				}
			}
		}
		.challenge-num-btn {
			width: 502rpx;
			height: 96rpx;
			border-radius: 96rpx;
			background: linear-gradient(180deg, #FEEB71 0%, #F89018 100%);
			color: #984100;
			font-size: 32rpx;
			font-weight: bold;
			line-height: 96rpx;
			text-align: center;
		}
	}
</style>
