<template>
	<view class="notice">
		<view class="tz_item" v-for="(item, index) in list" :key="index" @click="detail(item)">
			<view class="ctop">
				<text class="icon tb">&#xe734;</text>
				<text class="tag">通知公告</text>
				<view class="clear"></view>
			</view>
			<view class="content">
				<view class="title omit">{{ item.title }}</view>
			</view>
			<view class="time">{{ item.createTime }}</view>
			<view class="clear"></view>
		</view>
		<view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
		<u-empty v-if="!loadMore && list.length == 0"></u-empty>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [],
			param: { pageNum: 1, pageSize: 10, orderByColumn: 'createTime', isAsc: 'desc' },
			loadMore: true
		};
	},
	onLoad(e) {
		this.getData();
	},
	methods: {
		getData() {
			this.http.request({
				url: '/app/user/company/list',
				data: this.param,
				loading: 'false',
				success: (res) => {
					this.loadMore = res.data.pages > this.param.pageNum ? true : false;
					res.data.rows.forEach((item) => {
						item.createTime = uni.$u.timeFrom(Date.parse(item.createTime));
						this.list.push(item);
					});
				}
			});
		},
		detail(item) {
			uni.navigateTo({
				url: '/pages/notice/detail?id=' + item.id
			});
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNum = 1;
			this.list = [];
			this.getData();
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			this.refresh();
			uni.stopPullDownRefresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNum++;
			this.getData();
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: white;
}
.notice {
	background-color: white;
	.tz_item {
		padding: 7px 15px 15px 15px;
		color: $font-c;
		margin-bottom: 10px;
		border-bottom: 1px solid #f0f2f7;
		cursor: pointer;
		.ctop {
			position: relative;
			.bage {
				position: absolute;
				width: 8px;
				height: 8px;
				left: 23px;
				top: 0px;
				border: 1px solid white;
				border-radius: 50%;
				background-color: red;
			}
			.tb {
				width: 30px;
				height: 30px;
				line-height: 28px;
				text-align: center;
				border-radius: 50%;
				font-size: 20px;
				margin-right: 5px;
				float: left;
				background-color: #4581fb;
				color: white;
			}
			.tag {
				float: left;
				font-size: 14px;
				font-weight: bold;
				margin-top: 4px;
				margin-left: 5px;
			}
		}
		.content {
			float: left;
			width: 75%;
			margin-top: 10px;
			color: #717171;
			.title {
				font-size: 14px;
			}
		}
		.time {
			font-size: 14px;
			padding: 10px 0px 0px 0px;
			float: right;
		}
	}
}
</style>
