<template>
	<view class="index">
			<view class="search">
				<uni-search-bar @confirm="search" cancelButton="none" @clear="onClear" v-model="queryParams.activityTheme">
				</uni-search-bar>
			</view>
			<br />
			<br />
			<view class="right" @tap="toAdd">
				<svg t="1723014605442" class="icon" viewBox="0 0 1024 1024" version="1.1"
					xmlns="http://www.w3.org/2000/svg" p-id="1215" width="60" height="60">
					<path
						d="M665 81v105H369V81h296m20-80H349c-33.1 0-60 26.9-60 60v145c0 33.1 26.9 60 60 60h336c33.1 0 60-26.9 60-60V61c0-33.1-26.9-60-60-60zM298.5 689c-37.2 0-67.5-30.3-67.5-67.5s30.3-67.5 67.5-67.5 67.5 30.3 67.5 67.5-30.3 67.5-67.5 67.5z m0-80c-6.9 0-12.5 5.6-12.5 12.5s5.6 12.5 12.5 12.5 12.5-5.6 12.5-12.5-5.6-12.5-12.5-12.5zM298.5 884c-37.2 0-67.5-30.3-67.5-67.5s30.3-67.5 67.5-67.5 67.5 30.3 67.5 67.5-30.3 67.5-67.5 67.5z m0-80c-6.9 0-12.5 5.6-12.5 12.5s5.6 12.5 12.5 12.5 12.5-5.6 12.5-12.5-5.6-12.5-12.5-12.5zM642 661H477c-22.1 0-40-17.9-40-40s17.9-40 40-40h165c22.1 0 40 17.9 40 40s-17.9 40-40 40zM762 859H477c-22.1 0-40-17.9-40-40s17.9-40 40-40h285c22.1 0 40 17.9 40 40s-17.9 40-40 40zM762 469H477c-22.1 0-40-17.9-40-40s17.9-40 40-40h285c22.1 0 40 17.9 40 40s-17.9 40-40 40z"
						fill="#1890FF" p-id="1216"></path>
					<path
						d="M863 177v767H171V177h118v9c0 44.2 35.8 80 80 80h296c44.2 0 80-35.8 80-80v-9h118m20-80H665v89H369V97H151c-33.1 0-60 26.9-60 60v807c0 33.1 26.9 60 60 60h732c33.1 0 60-26.9 60-60V157c0-33.1-26.9-60-60-60z"
						fill="#1890FF" p-id="1217"></path>
					<path
						d="M298.8 493.6c-10.2 0-20.4-3.9-28.2-11.6l-35.8-35.6c-15.7-15.6-15.8-40.9-0.2-56.6 15.6-15.7 40.9-15.8 56.6-0.2l7.6 7.6 52-51.6c15.7-15.6 41-15.5 56.6 0.2 15.6 15.7 15.5 41-0.2 56.6L327 482c-7.8 7.7-18 11.6-28.2 11.6z"
						fill="#1890FF" p-id="1218"></path>
				</svg>
				新增
			</view>
			<scroll-view class="scroll-views" scroll-y="true" @scrolltolower="scrolltolower">
				<view class="list">
					<view v-for="(item,index) in list" :key="index" @click="detail(item)" class="box">
						<view>
							<view>活动主题：{{item.activityTheme}}</view>
						</view>
						<view>
							<text>活动发起人：</text>
							<text>{{item.eventPromoter}}</text>
						</view>
						<view>
							<text>参与人员类型：</text>
							<text>{{item.personnelType}}</text>
						</view>
						<view>
							<text>时间：</text>
							<text>{{item.constructTime}}</text>
						</view>
						<!--活动开始时间 知无涯  -->
						<view>
							<text>服务学生人次：</text>
							<text>{{item.stuNumber}}</text>
						</view>
					</view>
				</view>
	
				<view class="empty" v-if="list.length==0&&topLoading==false">
					<image src="@/static/empty.png" mode="widthFix"></image>
					暂时没有数据
				</view>
				<view class="loading-more-top" v-if="topLoading">
					<uni-load-more style="padding-top: 90px;" status="loading" />
				</view>
				<view class="loading-more" v-if="loading">
					<uni-load-more status="loading" />
				</view>
				<view class="no-more" v-if="!loading&&list.length!=0">
					到底啦~~
				</view>
			</scroll-view>
		</view>
</template>

<script>
	import {
		listOneStopCommunityConstruction
	} from '@/api/OneStopCommunity/communityBuilding.js'
	import {
		baseUrl
	} from "@/config.js";
	export default {
		data() {
			return {
				basePath: baseUrl,
				list: [],
				loading: false,
				topLoading: true,
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					activityTheme: ""
					// publishStatus: 0
				}
			}
		},
		methods: {
			search(res) {
				// uni.showToast({
				// 	title: '搜索：' + res.value,
				// 	icon: 'none'
				// })
				this.getlist()
			},
			onClear() {
				this.queryParams.pageNum = 1;
				this.queryParams.activityTheme = "";
				this.getlist();
			},
			toDetailPage(item) {
	
			},
			scrolltolower() {
				if (this.queryParams.pageNum < this.totalPages) {
					this.queryParams.pageNum++;
					this.loading = true;
					setTimeout(() => {
						//请求参数
						this.getlist()
					}, 1000)
				} else {
	
				}
			},
			// detail(item) {
			// 	uni.navigateTo({
			// 		url: `detail?activityId=${item.activityId}&activityTheme=${item.activityTheme}&initiator=${item.eventPromoter}`
			// 	})
			// },
			async getlist() {
				let res = await listOneStopCommunityConstruction(this.queryParams)
				if (res.code == 200) {
					this.loading = false;
					if (this.queryParams.pageNum == 1) {
						this.list = res.rows; // 如果是第一页，直接显示新数据
					} else {
						this.list = this.list.concat(res.rows); // 否则追加新数据到列表中
					}
					this.totalPages = Math.ceil(res.total / this.queryParams.pageSize);
					this.topLoading = false;
				}
			},
			toAdd() {
				uni.navigateTo({
					url: "/pages/OneStopCommunity/communityBuilding/add"
				})
			}
		},
		onLoad() {},
		onShow() {
			this.topLoading = true;
			this.queryParams.pageNum = 1;
			this.list = [];
			this.getlist();
		}
	}
</script>

<style lang="scss" scoped>
	.index {
		background-color: #F5F5F7;
		min-height: 100vh;

		.search {
			width: 100%;
			background-color: white;
			position: fixed;
			z-index: 10;
			top: 80rpx;
			padding: 0rpx 8rpx;
			background-color: #F5F5F7;

			/deep/ .uni-searchbar__box {
				background-color: white !important;
			}
		}
		.right {
		  position: fixed;
		  top: 40rpx;
		  right: 20rpx;
		  z-index: 11; /* 设置比.search更高的z - index */
		  display: flex;
		  align-items: center;
		
		 .icon {
		    width: 20px;
		    height: 20px;
		  }
		}
		

		.scroll-views {
			height: calc(100vh - 10px);

			.list {
				margin-top: 100rpx;
				padding: 24rpx;

				&>view:nth-child(n+2) {
					margin-top: 30rpx;
				}

				.box {
					width: 100%;
					// height: 364rpx;
					padding: 20rpx 40rpx;
					border-radius: 16rpx;
					background-color: white;
					font-size: 28rpx;

					&>view {
						word-break: break-all;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 1;
						text-overflow: ellipsis;
					}

					&>view:nth-child(1) {
						display: flex;
						justify-content: space-between;

						image {
							width: 100%;
							height: 334rpx;
						}

						.active {
							background-color: #E7FAF0;
							border: 1px solid #D0F5E0;
							padding: 4rpx;
							font-size: 20rpx;
							color: #71E2A3;
						}

						.dark {
							background-color: #F5F5F7;
							border: 1px solid #C1CCDF;
							padding: 4rpx;
							font-size: 20rpx;
							color: #A7A8AC;
						}
					}

					&>view:nth-child(2) {
						margin-top: 40rpx;
					}

					&>view:nth-child(n+2) {
						line-height: 50rpx;
					}
				}
			}

			.no-more {
				text-align: center;
				color: gray;
				padding-bottom: 10px;
			}

			.empty {
				display: flex;
				flex-direction: column;
				align-items: center;
				margin-top: 200rpx;
				color: #9E9E9E;
				font-size: 36rpx;

				image {
					width: 250rpx;
					margin-bottom: 50rpx;
				}
			}
		}	
	}
</style>