<template>
	<view class="content">
		<!-- 选择时间区域 -->
		<view class="time">
			<view class="time_box" :class="{ active: currentIndex == index }" v-for="(item, index) in timeList" :key="index" @click="changeTimeIndex(index)">
				{{ item }}
			</view>
		</view>

		<!-- 列表区域 -->
		<view class="list">
			<view class="list_box" v-for="item in dataList" :key="item.id">
				<image class="img" mode="aspectFill" :src="item.images[0]" @click="clickImg(item.images)"></image>
				<view v-if="item.isPass == 1" class="status ing">审核中...</view>
				<view v-if="item.isPass == 2" class="status pass">审批通过</view>
				<view v-if="item.isPass == 3" class="status nopass">驳回</view>
				<view v-if="item.isPass == 3" class="msg">照片违规，请重新提交</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 { getMyImagePage, getMyUploadPage } from '@/api/index.js'

const $props = defineProps(['type'])

// 页面类型 1为活动相册 2为校友相册
const type = ref()

// 分段器数组
const timeList = ['全部', '审核中', '审核通过', '驳回']

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

onMounted(() => {
	type.value = $props.type
	if ($props.type == 1) {
		// 活动相册
		getData_act()
	}
	if ($props.type == 2) {
		// 校友相册
		getData()
	}
})

// 页面触底触发的回调
onReachBottom(() => {
	if (total.value > dataList.value.length) {
		currentPage.value++
		if (type.value == 1) {
			getData_act()
		} else {
			getData()
		}
	} else {
		uni.showToast({
			title: '没有更多数据了~~',
			icon: 'none'
		})
	}
})

// 获取我上传的活动图片分页数据
const getData_act = async () => {
	let data = {
		currentPage: currentPage.value,
		pageCount: pageCount.value,
		isPass: currentIndex.value
	}
	const res = await getMyUploadPage(data)
	// console.log(res);
	dataList.value = [...dataList.value, ...res.data.list]
	total.value = res.data.totalCount
}

// 获取我上传的校友相册分页数据
const getData = async () => {
	let data = {
		currentPage: currentPage.value,
		pageCount: pageCount.value,
		isPass: currentIndex.value
	}
	const res = await getMyImagePage(data)
	// console.log(res)
	dataList.value = [...dataList.value, ...res.data.list]
	total.value = res.data.totalCount
}

// 分段器切换回调
const changeTimeIndex = (e) => {
	if (e != currentIndex.value) {
		currentIndex.value = e
		currentPage.value = 1
		dataList.value = []
		if (type.value == 1) {
			getData_act()
		} else {
			getData()
		}
	}
}

// 点击图片回调
const clickImg = (urls) => {
	uni.previewImage({
		urls
	})
}
</script>

<style lang="scss" scoped>
.content {
	.time {
		display: flex;
		align-items: center;
		justify-content: space-around;
		margin-top: 20rpx;
		width: 712rpx;
		height: 90rpx;
		font-size: 28rpx;
		border-radius: 8rpx;
		background-color: #f2f7ff;

		.time_box {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 211rpx;
			height: 71rpx;
			border-radius: 8rpx;
		}

		.active {
			font-size: 30rpx;
			color: #0061ff;
			border: 2rpx solid #0061ff;
			background-color: rgba(0, 97, 255, 0.1);
		}
	}

	.list {
		margin-top: 40rpx;

		.list_box {
			position: relative;
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 200rpx;
			border-bottom: 2rpx solid #e5e5e5;

			.img {
				width: 140rpx;
				height: 140rpx;
				border-radius: 8rpx;
			}

			.status {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 157rpx;
				height: 55rpx;
				color: #fff;
				font-size: 28rpx;
				border-radius: 70rpx 40rpx 0 70rpx;
			}

			.pass {
				background: linear-gradient(90deg, #366fff 0%, #5da0fc 100%);
			}

			.ing {
				background: linear-gradient(90deg, #ff7045 0%, #f7a172 100%);
			}

			.nopass {
				background: linear-gradient(90deg, #d43030 0%, #f56c6c 100%);
			}

			.msg {
				position: absolute;
				top: 36rpx;
				left: 157rpx;
				width: 360rpx;
				font-size: 24rpx;
				color: #d43030;
			}
		}
	}
}
</style>
