<template>
	<view class="content">
		<u-navbar title="" placeholder autoBack>
			<view class="hflex acenter u-nav-center" slot="center">
				<view class="item" :class="current == 1 ? 'active' : ''" @click="tochangetab(1)">通知</view>
				<view class="item" :class="current == 2 ? 'active' : ''" @click="tochangetab(2)">私信</view>
			</view>
		</u-navbar>
		<view class="top hflex acenter jbetween" v-if="current == 1">
			<view class="item vflex acenter jcenter" @click="todianzan">
				<image src="/static/images/dianzan-light.png" mode="aspectFill"></image>
				<text>点赞</text>
			</view>
			<view class="item vflex acenter jcenter" @click="tocollect">
				<image src="/static/images/collect-light.png" mode="aspectFill"></image>
				<text>收藏</text>
			</view>
			<view class="item vflex acenter jcenter" @click="topinglun">
				<image src="/static/images/pinglun-light.png" mode="aspectFill"></image>
				<text>评论</text>
			</view>
		</view>
		<view class="list" v-if="list.length == 0 && current == 1">
			<view class="empty">没有通知消息</view>
		</view>
		<view class="list" v-if="list.length> 0 && current == 1">
			<view class="list-item" v-for="(item,index) in list" :key="index">
				<view class="item-top hflex acenter jbetween">
					<text class="text_hide">{{item.title}}</text>
					<text>{{item.created_at}}</text>
				</view>
				<view class="text">{{item.content}}</view>
			</view>
		</view>
		<view class="list" v-if="list.length == 0 && current == 2">
			<view class="empty">没有私信消息</view>
		</view>
		<view class="list" v-if="list.length > 0 && current == 2">
			<view class="list-item2 hflex acenter" v-for="(item,index) in list" :key="index" @click="tochat(item)">
				<image :src="item.chat_user.avatar" mode="aspectFill"></image>
				<view class="img-right">
					<view class="hflex acenter jbetween right-top">
						<text>{{item.chat_user.username}}</text>
						<text>{{item.created_at}}</text>
					</view>
					<view class="hflex acneter jbetween">
						<view class="text text_hide">{{item.content}}</view>
						<view class="num" v-if="item.unread_count > 0">{{item.unread_count}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	var that = ''
	export default {
		data() {
			return {
				current: 1,
				list: [],
				page: 1,
				last_page: 1
			}
		},
		onLoad() {
			that = this
		},
		onShow() {
			this.list = []
			this.page = 1
			this.getlist()
		},
		onPullDownRefresh() {

		},
		onReachBottom() {
			if (this.last_page == this.page) {
				uni.$u.toast('已经到底了')
				return
			} else {
				this.page++
				this.getlist()
			}
		},
		methods: {
			getlist() {
				if (this.current == 1) {
					$api.req({
						url: 'notification',
						data: {
							is_page: 1,
							page: that.page,
							limit: 10,
							type: 'system'
						}
					}, function(res) {
						that.list = that.list.concat(res.data.list)
						that.last_page = res.data.last_page
					})
				} else {
					$api.req({
						url: 'chat',
						data: {
							is_page: 1,
							page: that.page,
							limit: 10,
						}
					}, function(res) {
						that.list = that.list.concat(res.data)
						that.last_page = res.data.last_page
					})
				}

			},
			tochat(item) {
				uni.navigateTo({
					url: '/pageA/chat?chat_user_id=' + item.chat_user_id
				})
			},
			topinglun() {
				uni.navigateTo({
					url: '/pageA/pinglun-list'
				})
			},
			tocollect() {
				uni.navigateTo({
					url: '/pageA/shoucang-list'
				})
			},
			todianzan() {
				uni.navigateTo({
					url: '/pageA/dianzan-list'
				})
			},
			tochangetab(index) {
				this.current = index
				this.list = []
				this.page = 1
				this.getlist()
			}
		}
	}
</script>

<style lang="scss">
	.content {
		background: #F5F5F5;

		.list {
			width: 100%;
			min-height: calc(100vh - 400rpx);
			background: #FFFFFF;
			box-sizing: border-box;
			padding: 0 28rpx;

			.list-item {
				padding: 28rpx 0 32rpx;
				border-bottom: 1px solid #F5F5F5;

				.item-top {
					width: 100%;

					text:first-child {
						font-size: 32rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 600;
						color: #333333;
						max-width: 550rpx;
					}

					text:last-child {
						font-size: 22rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						color: #666666;
					}
				}

				.text {
					font-size: 24rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #666666;
					padding: 20rpx 0 0;
				}
			}

			.list-item2 {
				padding: 28rpx 0 32rpx;
				border-bottom: 1px solid #F5F5F5;

				image {
					width: 92rpx;
					height: 92rpx;
					border-radius: 50%;
				}

				.img-right {
					width: calc(100% - 92rpx);
					padding: 0 0 0 20rpx;

					.right-top {
						width: 100%;

						text:first-child {
							font-size: 32rpx;
							font-family: PingFangSC, PingFang SC;
							font-weight: 600;
							color: #333333;
						}

						text:last-child {
							font-size: 22rpx;
							font-family: PingFangSC, PingFang SC;
							font-weight: 400;
							color: #999999;
						}
					}

					.text {
						max-width: 500rpx;
						font-size: 24rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						color: #666666;
						padding: 14rpx 0 0;
					}

					.num {
						background: #F34025;
						font-size: 20rpx;
						font-family: SFPro, SFPro;
						font-weight: 400;
						color: #FFFFFF;
						padding: 2rpx 10rpx;
						margin: 14rpx 0 0;
						border-radius: 50%;
					}
				}
			}

			.empty {
				width: 264rpx;
				padding-top: 264rpx;
				margin: 0 auto 0;
				font-size: 44rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				color: rgba(34, 34, 34, .5);
			}
		}

		.top {
			width: 100%;
			box-sizing: border-box;
			padding: 44rpx 72rpx 34rpx;
			background: #FFFFFF;
			margin: 0 0 20rpx;

			.item {
				image {
					width: 96rpx;
					height: 96rpx;
				}

				text {
					font-size: 24rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #222222;
					padding: 16rpx 0 0;
				}
			}

		}

		.u-nav-center {
			.item {
				font-size: 36rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				color: rgba(34, 34, 34, .4);
				padding-right: 46rpx;
			}

			.active {
				color: #222222;
			}
		}
	}
</style>