<template>
	<view class="index">
		<view class="search">
			<uni-search-bar @confirm="search" cancelButton="none" :focus="true" @clear="onClear" v-model="queryParams.keyWords">
			</uni-search-bar>
		</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.createTime}}</view>
						<view v-if="item.status==1" class="active">已处理</view>
						<view v-else class="staydark">待处理</view>
					</view>
					<view>
						<text>关键词：</text>
						<text>{{item.keyWords}}</text>
					</view>
					<view>
						<text>联系人：</text>
						<text>{{item.contact}}</text>
					</view>
					<view>
						<text>联系电话：</text>
						<text>{{item.contactNumber}}</text>
					</view>
					<view>
						<text>问题反馈：</text>
						<text>{{item.desc}}</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 class="add" @tap="addComplaint">
			+
		</view>
	</view>
</template>

<script>
	import {
		complaintList
	} from '@/api/OneStopCommunity/complaint.js'
	export default {
		data() {
			return {
				list: [],
				loading: false,
				topLoading: true,
				totalPages:0,
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					keyWords:"",
					createId:uni.getStorageSync("stuId")
				}
			}
		},
		onLoad() {
			this.getlist();
		},
		methods: {
			scrolltolower() {
				console.log(this.totalPages);
				if (this.queryParams.pageNum < this.totalPages) {
					this.queryParams.pageNum++;
					this.loading = true;
					setTimeout(() => {
						//请求参数
						this.getlist()
					}, 1000)
				} else {
			
				}
			},
			search(res) {
				this.queryParams.pageNum = 1;
				this.getlist()
			},
			onClear(){
				this.queryParams.pageNum = 1;
				this.queryParams.keyWords="";
				this.getlist();
			},
			addComplaint(){
				uni.navigateTo({
					url:"./add"
				})
			},
			async getlist() {
				let res = await complaintList(this.queryParams)
				if (res.code == 200) {
					this.loading = false;
					console.log(this.queryParams.pageNum);
					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;
				}
			},
			detail(item){
				uni.navigateTo({
					url:"./detail?id="+item.id
				})
			}
		}
	}
</script>

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

		.search {
			margin-top:5rpx;
			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;
			}
		}

		.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;

						&>view:last-child {
							padding: 8rpx 10rpx;
							font-size: 22rpx;
						}

						.active {
							background-color: #E7FAF0;
							border: 1px solid #D0F5E0;
							color: #71E2A3;
						}
						.staydark {
							background-color: #FFF8E6;
							border: 1px solid #FFE399;
							color: #FFBA00;
						}
					}

					&>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;
				}
			}
		}
		.add {
			background-color: #1890FF;
			width: 90rpx;
			height: 90rpx;
			border-radius: 50%;
			color: white;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 60rpx;
			position: fixed;
			bottom: 50px;
			right: 25px;
		}
	}
</style>