<!-- 
每月挑战
http://localhost:5173/card/#/pages/mytz/index
https://oss-mbh5.colormaprun.com/card/#/pages/mytz/index
 -->
<template>
	<view class="body body-radius">
		<view class="content uni-column" :class="contentBg" @click="btnClick">
			<view class="main uni-column">
				<image mode="aspectFit" class="logo" :src="logoSrc"></image>
				<text class="type">{{ecName}}</text>
				<text class="name">{{name}}</text>
				<button class="button button-txtcolor">{{btnText}}</button>
			</view>
		</view>
	</view>
</template>

<script>
	import tools from '../../common/tools';
	import {
		ossUrl,
		token,
		apiCardBaseQuery,
	} from '../../common/api';
	 
	export default {
		data() {
			return {
				queryString: "",
				token: "",
				
				ecId: 0,	// 卡片id
				ecName: '', // 卡片名称
				ecDesc: '', // 卡片简介
				beginSecond: null, // 卡片开始时间戳，单位秒
				endSecond: null, // 卡片结束时间戳，单位秒
				
				contentBg: "",
				logoSrc: "",
				type: "",
				name: "",
				btnText: "",
			}
		},
		computed: {
			curYearMonth() {
				var currentDate = new Date();
				var currentYear = currentDate.getFullYear();
				var currentMonth = currentDate.getMonth() + 1; // 月份从0开始，所以要加1
				 
				return `${currentYear}年${currentMonth}月`;
			}
		},
		onLoad(event) { // 类型非必填，可自动推导
			// console.log(event);
			this.queryString = tools.objectToQueryString(event);
			// console.log(queryString);
			
			this.token = event["token"] ?? token;
			this.ecId = event["id"] ?? 0;
			
			this.contentBg = "content-bg-" + (event["bg"] ?? "blue");
			this.logoSrc = "/static/logo/" + (event["logo"] ?? "mytz") + '.png';
			// this.type = event["type"] ?? "每月挑战";
			this.name = event["name"] ?? this.curYearMonth;
			this.btnText = event["btnText"] ?? "开始挑战";
			
			this.getCardBaseQuery();
		},
		onUnload() {
		},
		methods: {
			// 卡片基本信息查询
			getCardBaseQuery() {
				uni.request({
					url: apiCardBaseQuery,
					header: {
						"Content-Type": "application/x-www-form-urlencoded",
						"token": this.token,
					},
					method: "POST",
					data: {
						ecId: this.ecId
					},
					success: (res) => {
						// console.log("getCardBaseQuery", res)
						const data = res.data.data;
						
						this.ecName = data.ecName;
						this.ecDesc = data.ecDesc;
						this.beginSecond = data.beginSecond;
						this.endSecond = data.endSecond;
					},
					fail: (err) => {
						console.log("getCardBaseQuery err", err)
					},
				});
			},
			btnClick() {
				window.location.href = `${ossUrl}#/pages/mytz/detail?${this.queryString}`;
			}
		}
	}
</script>

<style>
	.content {
		width: 100vw;
		height: 100vh;
		justify-content: center;
	}
	
	.content-bg-blue {
		background: linear-gradient(180deg,#178bff 0%,#004d9b 100%);
	}
	
	.content-bg-green {
		background: linear-gradient(180deg,#7aedff 0%,#047200 100%);
	}
	
	.content-bg-brown {
		background: linear-gradient(180deg,#ad4301 0%,#8d2219 100%);
	}

	.main {
		width: 100%;
		height: 700rpx;
		/* margin-top: 20rpx; */
		justify-content: space-evenly;
	}

	.logo {
		/* width: 230rpx; */
		height: 230rpx;
	}
	
	.type {
		opacity: 60%;
		/* line-height: 25px; */
		font-family: Roboto;
		color: #ffffff;
		font-size: 36rpx;
		text-align: center;
	}
	
	.name {
		font-family: Roboto;
		color: #ffffff;
		font-size: 46rpx;
		text-align: center;
	}
	
	.button {
		width: 320rpx;
		height: 86rpx;
		background: #ffffff;
		border-radius: 56rpx;
		font-size: 46rpx;
		line-height: 80rpx;
	}
	
	.button-txtcolor {
		color: #0458ad;
	}
	
</style>