<template>
	<view class="content">
		<!-- 活动列表区域 -->
		<view class="list">
			<!-- 每一个活动区域 -->
			<view class="list_box" v-for="item in dataList" :key="item.id" @click="clickItem(item.id)">
				<view class="box_top">
					<img v-if="item.poster" class="img" :src="item.poster" mode="aspectFill" />
					<img v-else class="img" src="@/static/images/3.png" mode="aspectFill" />
					<view class="top_msg">
						<view class="msg_title">{{ item.theme }}</view>
						<view class="msg_name">{{ item.orgName }}</view>
						<view class="">{{ item.startTime }} 至 {{ item.endTime }}</view>
					</view>
				</view>
				<view v-if="item.statuName == '报名进行中'" class="box_bottom on">报名进行中</view>
				<view v-if="item.statuName == '活动已结束'" class="box_bottom off">活动已结束</view>
				<view v-if="item.statuName == '活动未开始'" class="box_bottom nostart">活动未开始</view>
			</view>

			<noData v-if="!dataList.length"></noData>
		</view>
	</view>
</template>

<script setup>
import { onReachBottom } from '@dcloudio/uni-app'
import { ref, onMounted } from 'vue'
import { getMyJoinActivityPages } from '@/api/index.js'

// 当前页
const currentPage = ref(1)
// 每页多少条
const pageCount = ref(6)
// 总条数
const total = ref(0)
// 列表数据
const dataList = ref([])

onMounted(() => {
	// 获取我参加的活动分页数据
	getData()
})

onReachBottom(() => {
	if (total.value > dataList.value.length) {
		currentPage.value++
		getData()
	} else {
		uni.showToast({
			title: '没有更多数据了~~',
			icon: 'none'
		})
	}
})

// 获取我参加的活动分页数据
const getData = async () => {
	let data = {
		currentPage: currentPage.value,
		pageCount: pageCount.value
	}
	const res = await getMyJoinActivityPages(data)
	// console.log(res)
	dataList.value = [...dataList.value, ...res.data.list]
	total.value = res.data.totalCount
}

// 点击每一个活动的回调
const clickItem = (id) => {
	uni.navigateTo({
		url: `/pages/act_detail/act_detail?id=${id}`
	})
}
</script>

<style lang="scss" scoped>
.content {
	.list {
		margin-top: 20rpx;

		.list_box {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			padding: 30rpx 25rpx;
			margin-bottom: 20rpx;
			width: 714rpx;
			height: 344rpx;
			border-radius: 28rpx;
			box-shadow: 0 4rpx 35rpx #d3d3d3;
			background-color: #fff;

			.box_top {
				display: flex;
				justify-content: space-between;

				.img {
					margin-right: 24rpx;
					width: 249rpx;
					height: 168rpx;
					border-radius: 8rpx;
				}

				.top_msg {
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					flex: 1;
					font-size: 24rpx;
					color: #808080;
					overflow: hidden;

					.msg_title {
						font-size: 28rpx;
						font-weight: bold;
						color: #000;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
					}

					.msg_name {
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}
				}
			}

			.box_bottom {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 661rpx;
				height: 80rpx;
				border-radius: 8rpx;
			}

			.on {
				color: #fff;
				background-color: #007aff;
			}

			.off {
				color: #a6a6a6;
				background-color: #e5e5e5;
			}

			.nostart {
				color: #fff;
				background-color: #007aff;
				opacity: 0.3;
			}
		}
	}
}
</style>
