<template>
	<!-- 报名历史 -->
	<view class="sign">
		<view class="list_con" v-for="(item, index) in signList" :key="index">
			<view class="list_title">
				<text>第{{ item.season}}届大卫博士创业{{ item.type == 1 ? '密训' : '实战' }}营</text>
			</view>
			
			<view>
				<text class="gray">支付金额：</text>
				<text>￥{{ item.money }}</text>
			</view>
			<view class="time">
				<view>
					<text class="gray">支付时间：</text>
					<text>{{ item.pay_time }}</text>
				</view>
			</view>
			<view class="state" :class="{ finish_bg: item.status == 0 || item.status == 2, offline_bg: item.status == 1 }">
				<text v-if="item.status == 0">已结束</text>
				<text v-if="item.status == 1">开启中</text>
				<text v-if="item.status == 2">未开启</text>
			</view>
		</view>
		<view class="nodata" v-if="signList.length == 0">---暂无更多报名记录---</view>
	</view>
</template>

<script>
import { signList, seasonLog } from '../../api/sign.js';
export default {
	data() {
		return {
			signList: [], //报名列表
			userInfo: {}
		};
	},
	onLoad() {
		if (!uni.getStorageSync('userInfo')) {
			uni.redirectTo({
				url: '../index/index'
			});
			return false;
		}
		this.userInfo = uni.getStorageSync('userInfo');
		this.getList();
	},
	onShow() {
		if (uni.getStorageSync('userInfo')) {
			this.userInfo = uni.getStorageSync('userInfo');
		}
	},
	methods: {
		getList() {
			let that = this;
			signList().then(res => {
				if (res.code == 200) {
					let list = res.data.list;
					list.map(i => {
						if (i.season == this.userInfo.season) {
							let { time_end, time_start } = this.userInfo;
							if (time_end * 1000 > Date.now() && time_start * 1000 < Date.now()) {
								//活动中
								this.$set(i, 'status', 1);
								return false;
							}
							if (time_start * 1000 > Date.now()) {
								//活动未开始
								this.$set(i, 'status', 2);
								return false;
							}
							this.$set(i, 'status', 0); //活动已结束
						} else {
							this.$set(i, 'status', 0);
						}
					});
					that.signList = list;
					console.log(list);
				} else {
					uni.showModal({
						content: res.message || '请求失败',
						showCancel: false
					});
				}
			});
		},
		// 查看详情
		skipDetail(item) {
			uni.navigateTo({
				url: '../written_off/written_off?type=' + item.type + '&season=' + item.season + '&pay_time=' + item.pay_time + '&path=' + 1
			});
		}
	}
};
</script>
<style lang="scss" scoped>
.sign {
	padding-bottom: 40rpx;
}
.list_con {
	width: 690rpx;
	margin: 20rpx auto 0;
	background-color: #fff;
	font-size: 28rpx;
	padding: 0 20rpx 20rpx;
	box-sizing: border-box;
	border-radius: 8rpx;
	position: relative;
	.list_title {
		font-size: 32rpx;
		color: #333;
		padding: 37rpx 0 42rpx;
		font-weight: 500;
	}
	.gray {
		color: #999;
	}
	.time {
		margin-top: 20rpx;
		display: flex;
		align-items: center;
		.list_detail {
			width: 181rpx;
			height: 54rpx;
			border-radius: 27rpx;
			text-align: center;
			line-height: 54rpx;
			margin-left: 49rpx;
		}
		.offline {
			box-shadow: 0px 3rpx 15rpx 1rpx #ff5432;
			color: #ff5432;
		}
		.online {
			box-shadow: 0px 3rpx 15rpx 1px rgba(252, 190, 24, 0.35);
			color: #fcbe18;
		}
		.finish {
			box-shadow: 0px 3rpx 15rpx 1rpx rgba(102, 102, 102, 0.35);
			color: #666666;
		}
	}
	.state {
		width: 138rpx;
		height: 48rpx;
		border-radius: 0px 8rpx 0px 48rpx;
		position: absolute;
		top: 0;
		right: 0;
		color: #fff;
		text-align: center;
		line-height: 48rpx;
	}
	.offline_bg {
		background: #ff5432;
	}
	.online_bg {
		background: #fcbe18;
	}
	.finish_bg {
		background: #cccccc;
	}
}
.nodata {
	width: 100%;
	text-align: center;
	color: #ccc;
	font-size: 24rpx;
	margin-top: 44rpx;
}
</style>
