<template>
	<view class="content">
		<empty v-if="loaded && list.length == 0"></empty>
		<view class="action" v-for="item in list" @click="goAction(item)">
			<image :src="item.image_input[0]" mode="" class="action-img"></image>
			<view class="action-tit">
				{{item.title}}
			</view>
			<view class=" time">
				<view class="">
					活动时间：{{getTime(item.start_time)}} - {{getTime(item.end_time)}}
				</view>
			</view>
		</view>
		<uni-load-more :status="loadingType"></uni-load-more>
	</view>
</template>
<script>
	import { getTime } from '@/utils/rocessor.js'
	import {
		articleList,
		record,
	} from '@/api/index.js'
	export default {
		data() {
			return {
				page: 1,
				limit: 10,
				list: [],
				loadingType: 'more',
				loaded: false,
				type: 0,
			};
		},
		onLoad(opt) {
			if(opt.type) {
				this.type = opt.type
			}
		},
		onShow() {
			this.getActionList()
		},
		onReachBottom() {

		},
		methods: {
			getTime,
			goAction(item) {
				if(this.type == 0) {
					let time = new Date().getTime()
					console.log(time);
					if(time < item.start_time*1000) {
						return this.$api.msg('活动未开始，请耐心等待')
					}
					if(time > item.end_time*1000) {
						return this.$api.msg('活动已结束')
					}
					uni.navigateTo({
						url: '/pages/index/action?id=' + item.id
					})
				}
				
			},
			getActionList() {
				if (this.loadingType == 'loading' || this.loadingType == 'noMore') {
					return
				}
				this.loadingType = 'more'
				articleList({
					page: this.page,
					limit: this.limit
				},2).then(res => {
					this.list = this.list.concat(res.data.data)
					this.page++
					if (res.data.lengt == this.limit) {
						this.loadingType = 'more'
					} else {
						this.loadingType = 'noMore'
					}
					this.loaded = true
				})
			}
		}
	};
</script>
<style lang="scss" scoped>
	page {
		background-color: #f2f2f2;
		height: auto;
		min-height: 100%;
	}

	.action {
		width: 700rpx;
		margin: 25rpx auto;
		border-radius: 35rpx;
		overflow: hidden;
		background-color: #fff;

		.action-img {
			width: 700rpx;
			height: 300rpx;
			background-color: #333;
		}

		.action-tit {
			min-height: 100rpx;
			font-size: 34rpx;
			font-weight: 500;
			color: #0E0E0E;
			display: flex;
			align-items: center;
			padding: 15rpx;
			padding-left: 30rpx;
		}
		.time {
			font-size: 12rpx;
			padding: 20rpx;
			padding-top: 0;
		}
	}
</style>