<template>
	<view class="web_box">
		<!-- <u-navbar height="44" leftIcon="arrow-left" leftIconColor="#000" leftText="我的评论" @leftClick="leftClick" :autoBack="true" bgColor="#fff">
		</u-navbar> -->
		<view class="list" v-if="commentList.length > 0">
			<block v-for="(item,index) in commentList" :key="index">
				<view class="list_item">
					<view class="hflex acenter jbetween">
						<view class="title">{{item.name}}</view>
						<view class="date">{{item.create_at}}</view>
					</view>
					<view class="box">
						<span>{{user_name}}:</span>
						<span style="padding-left: 15rpx;">{{item.content}}</span>
					</view>
				</view>
			</block>
		</view> 
		<view class="list vflex acenter jcenter" v-else>
			<image src="../../static/images/common/comment_none.png" class="img_none"></image>
			<view class="text_none">暂无评论</view>
		</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	export default {
		data() {
			return {
				user_name: '',
				commentList:[],
				page: 1,
				limit: 10,
				total: 0
			}
		},
		onLoad() {
			this.getUserName()
			this.getCommentList()
		},
		methods: {
			leftClick() {
				
			},
			getUserName() {
				var that = this
				$api.req({
					url: '/api/User/userinfo',
				}, function(res) {
					console.log(res)
					if (res.code == 1) {
						that.user_name = res.data.user_name
					}
				})
			},
			// 获取评论列表
			getCommentList() {
				var that = this
				$api.req({
					url: '/api/User/myComments',
					data: {
						page: that.page,
						limit: that.limit
					}
				}, function(res) {
					console.log(res)
					if (res.code == 1) {
						if (that.page == 1) {
							that.total = res.data.count
							that.commentList = res.data.list
						} else {
							that.total = res.data.count
							that.commentList = that.commentList.concat(res.data.list)
						}
					}
				})
			},
			// 触底事件
			onReachBottom() {
				console.log("到底了");
				if (Number(this.page) * Number(this.limit) >= Number(this.total)) {
					$api.info("没有更多了")
				} else {
					this.page++
					this.getCommentList()
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.web_box::v-deep {
		padding: 0 30rpx;
		height: 2000rpx;
		
		.u-navbar {
			width: 100%;
			box-sizing: border-box;
			padding: 36px 16px 58rpx 0;
		}
		.list {
			width: 100%;
		}
		.list_item {
			width: 100%;
			box-sizing: border-box;
			padding: 24rpx 22rpx;
			background: #FFFFFF;
			box-shadow: 0px 2px 6px 0px rgba(213,213,213,0.5);
			border-radius: 24rpx;
			margin-top: 20rpx;
		}
		.title {
			font-size: 32rpx;
			font-weight: 500;
			color: #000000;
		}
		.date {
			font-size: 28rpx;
			font-weight: 400;
			color: #000000;
		}
		.box {
			width: 100%;
			box-sizing: border-box;
			padding: 20rpx 14rpx;
			background: #F8F8F8;
			border-radius: 8rpx;
			font-size: 28rpx;
			font-weight: 400;
			color: #333333;
			line-height: 50rpx;
		}
		.text_none {
			font-size: 32rpx;
			color: #333333;
			margin-top: 44rpx;
		}
		.img_none {
			margin-top: 300rpx;
			width: 530rpx;
			height: 404rpx;
		}
	}
</style>