<template>
	<view>
		<view class="tab">
			<u-tabs :list="tab" @click="click" :lineHeight="5"></u-tabs>
		</view>
		<view class="list">
			<view class="item" v-for="(item, index) in list" :key="index" @click="detail(item)">
				<view class="top">
					<view class="icon">&#xe60d;</view>
					<view class="title" v-if="item.types == 1">系统消息</view>
					<view class="title" v-if="item.types == 2">交易消息</view>
					<view class="date">{{ item.createTime }}</view>
				</view>
				<view class="content">{{ item.contents }}</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>
	</view>
</template>

<script>
export default {
	data() {
		return {
			user: this.getUser(),
			tab: [
				{ name: '交易消息', types: 2 },
				{ name: '系统消息', types: 1 }
			],
			list: [],
			param: { pageNo: 1, pageSize: 10, types: 2 },
			loadMore: true
		};
	},
	onShow() {
		uni.removeTabBarBadge({ index: 1 });
		this.param.types = 2;
		this.refresh();
	},
	methods: {
		getData() {
			this.http.request({
				url: '/sp-admin/app/TbMessage/getList',
				data: this.param,
				loading: 'false',
				success: res => {
					this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
					this.list.push(...res.data.data);
				}
			});
		},
		//点击tab切换
		click(e) {
			this.param.types = e.types;
			this.refresh();
		},
		detail(item) {
			uni.navigateTo({ url: item.url });
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNo = 1;
			this.list = [];
			this.getData();
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			this.refresh();
			uni.stopPullDownRefresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNo++;
			this.getData();
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #f5f5f5;
}
.list {
	padding: 12px;
	.item {
		background-color: white;
		border-bottom: 1px solid #f0f2f7;
		padding: 14px;
		margin-bottom: 10px;
		border-radius: 10px;
		.top {
			color: $font-c;
			border-bottom: 1px solid $line;
			padding-bottom: 13px;
			overflow: hidden;
			.icon {
				float: left;
				width: 17px;
				height: 17px;
				border-radius: 50%;
				background-color: $main-color;
				padding: 5px;
				text-align: center;
				line-height: 19px;
				color: white;
			}
			.title {
				float: left;
				font-weight: bold;
				padding-left: 7px;
				color: #192b20;
			}
			.date {
				float: right;
				color: #a0a2a6;
			}
		}
		.content {
			padding-top: 15px;
			color: #666666;
			line-height: 25px;
		}
	}
}
</style>
