<template>
	<view class="content">
		<Nav title="消息" :isBack="false" />
		<view class="section">
			<u-list finished-text="没有更多了" @scrolltolower="scrolltolower" height="85vh" :key="key">
				<view v-for="item in msgList" :key="item.id" @click="handelDetail(item)">
					<u-list-item>
						<u-cell-group class="cell">
							<u-cell :label="item.createTime" isLink>
								<view slot="title" class="title">
									<u-badge v-if="item.readState===0" isDot type="error" class="strick"></u-badge>
									<view class="title-content" :style="item.readState===0?'padding-left:20rpx':''">
										{{item.noticeTitle}}
									</view>
								</view>
							</u-cell>
						</u-cell-group>
					</u-list-item>
				</view>
			</u-list>
			<view class="empty" v-if="!this.msgList.length">
				<u-empty text="暂无数据" class="empty-icon" mode="data" icon="../../static/data.png">
				</u-empty>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 查询参数
				queryParams: {
					page: 1,
					limit: 20
				},
				// 列表数据
				msgList: [],
				key: 0
			};
		},
		onShow() {
			this.queryParams.limit = 20
			this.getMsgList()
			this.key++
		},
		onPullDownRefresh() {
			this.queryParams.limit += 10
			this.getMsgList()
		},
		methods: {
			// 获取消息数据
			getMsgList() {
				uni.$http.get('/messageNotice/getAllMessageNotice', this.queryParams).then(res => {
					const data = res.data
					if (data.code === 200) {
						this.msgList = data.data.messageNoticeList
						uni.stopPullDownRefresh()
					}
				})
			},
			// 跳转详情页
			handelDetail({
				id,
				readState
			}) {
				uni.navigateTo({
					url: "/pages/message/msg-detail/index?id=" + id + "&state=" + readState
				})
			},
			// 列表滚动到底部触发
			scrolltolower() {
				this.queryParams.limit += 10
				this.getMsgList()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 0 25rpx 0rpx 25rpx;
	}

	.section {
		position: relative;
	}

	.empty {
		width: 400rpx;
		height: 400rpx;
		position: absolute;
		top: 50%;
		left: 50%;
		margin-top: -200rpx;
		margin-left: -200rpx;
	}

	.cell {

		.title {
			position: relative;

			.title-content {
				width: 550rpx;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
			}

			.strick {
				height: 15rpx;
				width: 15rpx;
				position: absolute;
				top: 0;
				left: 0;
				margin-top: 12rpx
			}
		}
	}
</style>
