<template>
	<view>
		<view class="hm-header-xian"></view>
		<scroll-view scroll-y class="hm-w-h" @scrolltolower="reachBottom">
			<!-- 评分列表 -->
			<view v-if="(list.data).length">
				<view class="score-list hm-border-b" v-for="(item, index) in list.data" :key="index">
					<view class="left">
						<image :src="item.user.avatar.url"></image>
					</view>
					<view class="right">
						<view class="hm-font-30 hm-p-l-10">
							{{item.user.nickname}}
							<text class="hm-fr hm-col-tips hm-font-22">{{$u.timeFormat(item.create_time)}}</text>
						</view>
						<view class="hm-p-b-10">
							<u-rate :value="item.total" activeColor="#ff9900" inactiveColor="#909399" readonly
								allowHalf></u-rate>
						</view>
						<view class="hm-p-tb-20 hm-font-28 hm-border-t">{{item.content}}</view>
						<view v-if="item.reply" class="hm-bg hm-p-20 hm-br-8 hm-col-tips hm-font-26">
							{{item.reply}}
						</view>
					</view>
				</view>
				<view class="hm-p-20">
					<u-loadmore :status="loadStatus" bgColor="#f3f4f6"></u-loadmore>
				</view>
			</view>
			<view v-else class="hm">
				<img :src="applet.domain + '/addons/food/img/empty/order.png'" />
				<view class="text">暂无评价记录</view>
			</view>
			<!-- 技术支持 -->
			<view class="hm">
				{{applet.copyright}} <text class="v">V{{applet.version}}</text>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	let App = getApp();
	export default {
		data() {
			return {
				list: {data:{}},
				applet: {},
				loadStatus: 'loadmore',
				page: 1
			};
		},
		components: {},
		props: {},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			let _this = this;
			_this.applet = uni.getStorageSync('applet');
			_this.getList();
		},
		methods: {
			/**
			 * 触底加载
			 */
			reachBottom: function() {
				let _this = this;
				_this.loadStatus = "loading"; //加载中
				setTimeout(() => {
					// 已经是最后一页
					if (_this.page >= _this.list.last_page) {
						_this.loadStatus = "nomore"; //没有数据
						return false;
					}
					// 加载下一页列表
					_this.getList(true, ++_this.page);
				}, 1500);
			},

			/**
			 * 获取评分和评论列表
			 */
			getList: function(isPage, page) {
				let _this = this;
				App._get('user.comment/lists', {
					page: page || 1
				}, function(result) {
					let resList = result.data.list,
						dataList = _this.list;
					if (isPage == true) {
						_this.list.data = dataList.data.concat(resList.data);
					} else {
						_this.list = resList;
					}
					_this.loadStatus = 'loadmore';
				});
			}
		}
	};
</script>
<style lang="scss" scoped>
	 
</style>
