<template>
	<view class="container main">
		<view class="one">
			<view class="title">
				<span>决赛时间:</span>
				<span>{{info.final_start_time}}</span>
			</view>
			<view class="button">
				<button class="button_1" type="primary" @tap="toSign('0')">确认参加</button>
				<button class="button_2" type="warn" @tap="toSign('1')">放弃参加</button>
			</view>
		</view>
	</view>
</template>

<script>
	import moment from 'moment';
	export default {
		components: {},
		data() {
			return {
				id: '',
				user: {},
				info: {},
			}
		},
		onLoad: async function(e) {
			const that = this;
			that.$set(that, `id`, e && e.id || '');
			await that.searchToken();
			await that.search();
		},
		methods: {
			// 用户信息
			searchToken() {
				const that = this;
				try {
					const res = uni.getStorageSync('token');
					if (res) {
						const user = that.$jwt(res);
						that.$set(that, `user`, user);
					}
				} catch (e) {}
			},
			// 查询
			async search() {
				const that = this;
				if (that.id) {
					let res;
					res = await that.$api(`/matchReg/${that.id}`, 'GET', {})
					if (res.errcode == '0') {
						that.$set(that, `info`, res.data)
					} else {
						uni.showToast({
							title: res.errmsg,
							icon: 'none'
						});
					}
				}
			},
			async toSign(type) {
				const that = this;
				let res;
				if (type == '0') {
					res = await that.$api(`/matchExt/step5/confirm/${that.info.match_id}`, 'POST', {
						user_id: that.user.id
					})
				} else {
					res = await that.$api(`/matchExt/step5/refuse/${that.info.match_id}`, 'POST', {
						user_id: that.user.id
					})
				}
				if (res.errcode == '0') {
					uni.showModal({
						content: "维护成功！",
						showCancel: false
					});
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.showToast({
						title: res.errmsg,
						icon: 'none'
					});
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		.one {
			padding: 2vw;

			.title {
				padding: 2vw;
				text-align: center;
			}

			.button {
				display: flex;
				margin: 2vw 0 0 0;
				padding: 2vw;

				.button_1 {
					color: var(--mainColor);
					font-size: var(--font14Size);
					border-radius: 2vw;
					background-color: var(--f3CColor);
				}

				.button_2 {
					color: var(--mainColor);
					font-size: var(--font14Size);
					border-radius: 2vw;
					background-color: var(--fF0Color);
				}

			}
		}
	}
</style>