<template>
	<view class="container">
		<view class="contentBox">
			<z-paging ref="paging" v-model="listData" @query="onGetOrderList" refresher-update-time-key="list" :auto="false">
				<view class="listInfoBox">
					<view class="listInfo" v-for="(item, index) in listData" :key="index" @tap="onViewTo(item.notificationId)">
						<view class="listDetailBox">
							<text class="listDate">{{item.creationTime}}</text>
						</view>
						<rich-text :nodes="item.title" class="listTitle"></rich-text>
					</view>
				</view>
			</z-paging>
		</view>
	</view>
</template>

<script>
	var that;
	export default {
		data() {
			return {
				listData: [],
				isReLoad: false,
				type: 0,
				titleName: '通知公告'
			}
		},
		onLoad(options) {
			that = this;
			that.type = options.type;
			that.titleName = that.type == 0 ? '通知公告' : '宣传视频'
			that.$nextTick(function() {
				uni.setNavigationBarTitle({
					title: that.titleName
				})
				that.$refs.paging.reload()
			})
		},
		methods: {
			onGetOrderList(pageNo, pageSize) {
				that.$admin.req({
					method: 'GET',
					url: '/api/v1/Snapshot/notification?NotifyType=' + that.type + '&QueryIndex=' + (pageNo - 1) + '&QueryCount=' + pageSize
				}).then(res => {
					if (res && res.length > 0) {
						res.forEach((item, index) => {
							item.creationTime = that.$util.formatTime(new Date(item.creationTime));
						})
						that.$refs.paging.complete(res);
					} else if (res && res.length == 0) {
						that.$refs.paging.complete([]);
					} else {
						that.$util.msg('网络出错！');
						that.$refs.paging.complete(false);
					}
					typeof fun === 'function' && fun();
				}, err => {
					if (!that.isReLoad) {
						that.isReLoad = true;
						that.onGetOrderList(pageNo, pageSize);
					} else {
						that.$util.msg(err);
						that.$refs.paging.complete(false);
					}
				})
			},
			onViewTo(id) {
				uni.navigateTo({
					url: '/pagesPointsBase/Publicize/View?type='+ that.type +'&id=' + encodeURIComponent(id)
				})
			},
		}
	}
</script>

<style lang="less">
	.container {
		background-color: #f3f3f3;
	}

	.contentBox {
		position: relative;
		height: calc(100%);
	}

	.listInfo {
		padding: 30rpx 20rpx;
		background-color: #fff;
		border-bottom: 2rpx #eee solid;
	}
	
	.listDetailBox {
		color: #666666;
		font-size: 24rpx;
		display: block;
		text-align: right;
		text-align: right;
	}
	
	.listDate {
		font-size: 24rpx;
	}

	.listTitle {
		color: #000405;
		font-size: 32rpx;
		line-height: 46rpx;
		white-space: pre-line;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		/*行向垂直排列*/
		-webkit-line-clamp: 2;
		width: 100%;
	}
</style>