<template>
	<view class="container">
		<uni-nav-bar dark :fixed="true" backgroundColor="#3F9EFF" statusBar="false" left-icon="left" left-text="返回"
			@clickLeft="toBack">
			<view style="width: 100%;display: flex;flex-direction: row;justify-content: center;align-items: center;">
				<text style="color: white;font-size: 1rem;">{{title}}</text>
			</view>
		</uni-nav-bar>
		<uni-list>
			<uni-list-item ellipsis="1" v-for="item in noticeList" :key="item.id" :title="item.title"
				:note="item.releaseTime" showArrow clickable @click="onNoticeItemClick(item.id)"></uni-list-item>
		</uni-list>
		<uni-load-more :status="status" @clickLoadMore="clickLoadMore" />
	</view>
</template>

<script>
	import uLoadMore from '@/uview-ui/components/u-loadmore/u-loadmore.vue'
	import uList from '@/uni_modules/uni-list/components/uni-list/uni-list.vue'
	import uListItem from '@/uni_modules/uni-list/components/uni-list-item/uni-list-item.vue'
	import uNavBar from '@/uni_modules/uni-nav-bar/components/uni-nav-bar/uni-nav-bar.vue'
	import uniDataPicker from '@/uni_modules/uni-data-picker/components/uni-data-picker/uni-data-picker.vue'
	import uGroup from '@/uni_modules/uni-group/uni-group.vue'
	import uniSection from '@/uni_modules/uni-section/uni-section.vue'
	import pageNav from '@/components/page-nav/page-nav.vue';
	import uniTable from '@/uni_modules/uni-table/components/uni-table/uni-table.vue'
	import uniPagination from '@/uni_modules/uni-pagination/components/uni-pagination/uni-pagination.vue'
	import uniBreadcrumb from '@/uni_modules/uni-breadcrumb/components/uni-breadcrumb/uni-breadcrumb.vue'
	import http from '@/http/api.js';
	export default {
		components: {
			uList,
			uListItem,
			uNavBar,
			uLoadMore,
		},
		data() {
			return {
				title: '公告消息',
				status: 'more',
				pageCurrent: 1,
				pageSize: 10,
				noticeList: [],
				totalCount: 0,
			};
		},
		onLoad() {
			this.getNotice();
		},
		onReady() {
			//let that = this;
			// uni.getSystemInfo({
			// 	success(e) {
			// 		console.log(e);
			// 		let {
			// 			windowWidth,
			// 			windowHeight,
			// 			safeArea
			// 		} = e;
			// 		const query = uni.createSelectorQuery().in(that);
			// 		query
			// 			.select('#swiperBox')
			// 			.boundingClientRect(data => {
			// 				that.swiperHeight = safeArea.bottom - data.top;
			// 			})
			// 			.exec();
			// 	}
			// });

		},
		onPullDownRefresh() {
			// uni.showToast({
			// 	icon: 'none',
			// 	title: "当前状态：" + this.status
			// })
			// setTimeout(() => {
			// 	uni.stopPullDownRefresh();
			// }, 1500);
		},
		onReachBottom() {
			// uni.showToast({
			// 	icon: 'none',
			// 	title: "当前状态：" + this.status
			// })
			if (this.totalCount > this.noticeList.length) {

				this.status = 'loading';

				setTimeout(() => {

					this.pageCurrent++

					this.getNotice(); //执行的方法

				}, 1000)

			} else { //停止加载

				this.status = 'noMore';

			}

			// 后续将改为与后端联动
			// if (this.page >= 3) return;
			// this.status = 'loading';
			// this.page = ++this.page;
			// setTimeout(() => {
			// 	this.list += 10;
			// 	if (this.page >= 3) this.status = 'nomore';
			// 	else this.status = 'loading';
			// 	this.newsList.push(...[{}, {}]);
			// }, 2000);
		},
		methods: {
			toBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			clickLoadMore(e) {
				// uni.showToast({
				// 	icon: 'none',
				// 	title: "当前状态：" + e.detail.status
				// })

				// })
				if (this.totalCount > this.noticeList.length) {

					this.status = 'loading';

					setTimeout(() => {

						this.pageCurrent++

						this.getNotice(); //执行的方法

					}, 1000)

				} else { //停止加载

					this.status = 'noMore';

				}
			},
			getNotice() {
				const that = this;
				const current = this.pageCurrent;
				const size = this.pageSize;
				//const isSubmit = '0';
				http.request({
					url: '/galaxy-test/notice/list',
					method: 'GET',
					params: {
						current,
						size,
					},
				}).then(res => {
					if (res.data.records != null) {
						for (var i = 0; i < res.data.records.length; i++) {
							that.noticeList.push(res.data.records[i]);
						}
					}
					that.totalCount = res.data.total;
					if (that.totalCount > that.noticeList.length) {
						this.status = 'more';
					}
					that.viewNotice();
				}).catch(err => {
					console.log(err)
				})
			},
			viewNotice() {
				http.request({
					url: '/galaxy-test/notice/view',
					method: 'POST',
				}).then(res => {}).catch(err => {
					console.log(err)
				})
			},
			onNoticeItemClick(id) {

				console.log('执行click事件', id)
				uni.navigateTo({
					url: '/pages/news/detail?id=' + id
				})

			},

		}
	};
</script>

<style lang="scss">
	.message-icon {
		width: 32rpx;
		height: auto;
		margin-right: 27rpx;
	}

	.tab {
		margin: 0 0 10rpx;
		border-bottom: 1px solid #e4e7ed;
	}

	.content {
		padding: 0 0 150rpx;

		.news {
			&:not(:last-of-type) {
				border-bottom: 2rpx solid #e4e7ed;
			}
		}
	}

	.nomore {
		padding: 30rpx 20rpx;
	}

	.news {
		margin: 30rpx 30rpx 0;
		padding: 0 0 30rpx;

		.head {
			display: flex;

			.avatar {
				flex-shrink: 0;
				width: 69rpx;
				height: 69rpx;
				background: #ffffff;
				border: 1px solid #14b9c8;
				border-radius: 50%;
			}

			.info {
				flex: 1;
				margin-left: 14rpx;

				.name {
					display: flex;
					align-items: center;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #000000;
					line-height: 36rpx;

					.tag {
						margin-left: 15rpx;
						display: inline-block;
						padding: 8rpx 10rpx;
						font-size: 14rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #4cbeca;
						line-height: 21rpx;
						border: 1px solid #0bb9c8;
						border-radius: 6px;
					}
				}

				.date {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #a3a3a3;
					line-height: 36rpx;
				}
			}
		}

		.des {
			margin-top: 40rpx;
			font-size: 30rpx;
			font-family: PingFang SC;
			color: #000000;
			line-height: 47rpx;
		}
	}

	.swiper-box {
		height: 100vh;
	}
</style>
