<template>
	<view>
		<cu-custom :backUrl="'/pages/apps/apps'" :isBack="true" bgColor="bg-gradual-blue" >
			<block slot="backText">返回</block>
			<block slot="content">IT小组招募</block>
			<block slot="right" >
				<view  @click="back()">
					刷新
				</view>
			</block>
		</cu-custom>

		<view class="cu-card article">
			<view class="cu-item shadow" v-for="item in dataList" @click="detail(item.id, item.switchFlag)">
				<view class="title">
					<view class="text-cut"> {{item.name}} </view>
				</view>
				<view class="content">
					<image src="/static/first.jpg"
					 mode="aspectFill"></image>
					<view class="desc">
						<view class="text-content"> {{item.detail}} </view>
						<view>
							<view :class="item.switchFlag === '1' ? 'cu-tag bg-green light sm' : 'cu-tag bg-grey light sm' ">
								{{item.switchFlag === '1' ? '进行中' : '未开始'}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import LuckyDrawEventsService from '@/api/test/luckyDraw/LuckyDrawEventsService'
	export default {
		data() {
			return {
				dataList: [],
				loading: false,
				searchForm: {},
				tablePage: {
					total: ''
				}
			};
		},
		luckyDrawEventsService: null,
		onLoad(option) {
			let { is_sucess } = option
			if (is_sucess == '200') {
				uni.showToast({
					title: '报名成功',
					icon: 'sucess',
					duration: 1500
				})
			}
			this.luckyDrawEventsService = new LuckyDrawEventsService()
			this.refreshList()
		},
		onShow() {
			this.refreshList()
		},
		methods: {
			refreshList() {
			  this.loading = true
			  this.luckyDrawEventsService.list({
				  'current': '1',
				  'size': '-1',
				  ...this.searchForm
				}).then((data) => {
				  this.dataList = data.records
				  this.tablePage.total = data.total
				  this.loading = false
				})
				
			},
			// 跳转活动详情页面
			detail(id, switchFlag) {
				if (switchFlag === '1') {
					// 活动进行中
					uni.navigateTo({
					  url: '/pages/test/luckyDraw/LuckyDrawList?eventId='+id
					})
				} else {
					// 活动未开始
					uni.showToast({
						title: '活动未开始，请选择进行中的项目参与',
						icon: 'none',
						duration: 1500
					})
				}
				
			},
			back () {
				uni.navigateTo({
				  url: '/pages/test/luckyDraw/LuckyDrawEvents_pc'
				})
			}
		}
	}
</script>

<style>

</style>
