<template>
	<view class="center-box">
		<view class="box flex flex-column flex-start">
			<!-- <view class="search flex  align-items" style="width: 99%;">
				<span class="dashed">
					<image src="../../static/center/search.png" mode=""></image>
				</span>
				<span class="line-search"></span>
				<input type="text" placeholder="搜索活动" v-model="keywords" class="input" placeholder-class="plasty" />
				<span class="searchBtn bg-blue" @click.stop="search()">搜索</span>
			</view> -->

			<u-navbar title="" :border="false" :placeholder="true" :autoBack="false" :is-back="false" :leftIcon="none">
				<view class="" slot="center">
					<u-search class="u-search" v-model="keywords" placeholder="请输入搜索内容" :showAction="false"
						@change="search()"></u-search>
				</view>
			</u-navbar>

			<view class="listBox flex flex-column flex-start">
				<view class="list flex flex-column flex-start" v-for="(item,index) in list" :key="index"
					@click.stop="open(item.id)">
					<image :src="item.headimage" mode="" style="width: 690rpx;height: 260rpx;border-radius: 10rpx;">
					</image>
					<view class="flex align-items" style="margin: 24rpx 0 0 32rpx;">
						<span class="Sign  flex justify-center align-items" style="color: #FFFFFF;background: #A4A4A4;"
							v-if="item.has_sign_expire == 1">已 结 束</span>
						<span class="Sign  flex justify-center align-items"
							style="color: #222222;background: #BEEE03;"
							v-if="item.has_sign_expire == 2">报 名</span>
						<span class="title white-space">{{item.title}}</span>
					</view>

					<view class="icon flex align-items">
						<image src="../../static/index/address.png" mode="" class="icon-size"></image>
						<span class="white-space">{{item.address_detail}}</span>
					</view>
					<view class="icon flex align-items" style="margin-bottom: 32rpx;margin-top: 14rpx;">
						<image src="../../static/index/clock.png" mode="" class="icon-size"></image>
						<span class="white-space">{{item.start_time_text}}</span>
					</view>
					<!-- <span class="Sign bg-hui flex justify-center align-items" v-if="item.has_sign_expire == 1">已 结 束</span>
					<span class="Sign bg-blue flex justify-center align-items" v-if="item.has_sign_expire == 2">报 名</span> -->
				</view>
			</view>
			<view class="footer flex justify-center align-items">
				<u-loadmore :status="loadStatus" />
			</view>
		</view>
		<tab-bar :tabBarShow="2"></tab-bar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				limit: 10,
				keywords: '',
				list: [],
				count: 1,
				loadStatus: 'nomore'

			};
		},
		// onLoad() {
		// 	this.getList()
		// },
		onShow() {
			this.page = 1
			this.limit = 10
			this.list = []
			this.getList()
		},
		onReachBottom() {
			if (this.count) {

				this.getList();
			}
		},
		methods: {
			// 搜索
			search() {
				this.page = 1
				this.limit = 10
				this.list = []
				this.getList()
			},
			getList() {
				uni.$u.http.get('/api/school/activity/activity_list', {
					params: {
						keywords: this.keywords,
						page: this.page,
						limit: this.limit,
						is_expire: 0,
						order: 'normal'
					}
				}).then(res => {
					if (res.code == 1) {
						console.log(res.data.list.data)
						if (res.data.list.data.length > 0) {
							this.count = res.data.list.data.length;
							if (this.count) {
								this.loadStatus = 'nomore';
								this.page++;
							} else {
								this.loadStatus = 'loading';
							}
							this.list = [...this.list, ...res.data.list.data];

							// this.count = this.list.length
							// if (this.list.length >= res.data.count) {
							// 	this.loadStatus = 'loading';
							// } else {
							// 	this.loadStatus = 'nomore';
							// }

						} else {
							this.count = this.list.length
							this.loadStatus = 'nomore';
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				}).catch(error => {
					let token = uni.getStorageSync('token')
					if (token) {
						uni.showToast({
							title: `请在'我的'页面 右上角退出重新登陆`,
							icon: 'none',
							duration: 3000,
							complete: function() {
								setTimeout(function() {
									uni.switchTab({
										url: '/pages/my/index',
									});
								}, 3000);
							}
						});
					} else {
						uni.showToast({
							title: `请在'我的'页面 登陆后重试`,
							icon: 'none',
							duration: 3000,
							complete: function() {
								setTimeout(function() {
									uni.switchTab({
										url: '/pages/my/index',
									});
								}, 3000);
							}
						});
					}

				});
			},
			open(id) {
				uni.navigateTo({
					url: "/packageA/activity/activityDetaill?id=" + id
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.center-box {
		width: 750rpx;
		background: #F1F2F8;
		min-height: calc(100vh - 130rpx);
	}

	.box {
		width: 690rpx;
		padding: 0 30rpx 0rpx 30rpx;
		border-radius: 0px 0px 0px 0px;
	}

	.white-space {
		overflow: hidden;
		/* 确保超出容器的文本被隐藏 */
		white-space: nowrap;
		/* 确保文本在一行内显示 */
		text-overflow: ellipsis;
		/* 使用省略号表示被截断的文本 */
		width: 100%;
	}

	.search {
		margin-top: 27rpx;
		width: 690rpx;
		height: 64rpx;
		background: #FFFFFF;
		box-shadow: 2rpx 2rpx 0rpx 0rpx rgba(0, 0, 0, 0.4);
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 2rpx solid #008CFF;

		.dashed {
			image {
				width: 52rpx;
				height: 52rpx;
			}
		}

		.line-search {
			width: 2rpx;
			height: 42rpx;
			background: #008CFF;
			border-radius: 0rpx 0rpx 0rpx 0rpx;
		}

		.input {
			// border: 4rpx solid #EAEAEA;
			padding-left: 12rpx;
			height: 100%;
			width: 78%;
		}

		/deep/ .input-placeholder {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			color: #C0C0C0;
			line-height: 32rpx;
			text-align: left;
			font-style: normal;
			text-transform: none;

		}

		.searchBtn {
			width: 128rpx;
			height: 64rpx;
			border-radius: 5rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			color: #FFFFFF;
			display: flex;
			justify-content: center;
			align-items: center;
		}

	}

	.white-space {
		overflow: hidden;
		/* 确保超出容器的文本被隐藏 */
		white-space: nowrap;
		/* 确保文本在一行内显示 */
		text-overflow: ellipsis;
		/* 使用省略号表示被截断的文本 */
		width: 100%;
	}

	.w-100 {
		width: 100%;
	}

	.flex {
		display: flex;
	}

	.justify-center {
		justify-content: center;
	}

	.align-items {
		align-items: center;
	}

	.flex-column {
		flex-flow: column;
	}

	.justify-start {
		justify-content: start;
	}

	.listBox {
		width: 690rpx;
		margin-top: 10rpx;

		.list {
			height: 456rpx;
			margin-top: 32rpx;
			position: relative;
			background: #FFFFFF;
			border-radius: 10rpx;

			.title {
				width: 522rpx;
				font-family: Source Han Sans CN, Source Han Sans CN;
				font-weight: bold;
				font-size: 32rpx;
				color: #000000;
			}

			.icon {
				width: 580rpx;
				margin-top: 8rpx;
				margin-left: 32rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #7A7A7A;
			}

			.Sign {
				width: 88rpx;
				height: 40rpx;
				border-radius: 4rpx 4rpx 4rpx 4rpx;
				font-family: Source Han Sans CN, Source Han Sans CN;
				font-weight: 500;
				font-size: 24rpx;
				margin-right: 16rpx;
			}
		}
	}

	.icon-size {
		width: 32rpx;
		height: 32rpx;
		margin-right: 8rpx;
	}

	.footer {
		margin-bottom: 200rpx;
	}

	.slot-wrap {
		display: flex;
		align-items: center;
		/* 如果您想让slot内容占满整个导航栏的宽度 */
		/* flex: 1; */
		/* 如果您想让slot内容与导航栏左右有空隙 */
		/* padding: 0 30rpx; */
	}
</style>