<template>
	<view class="container">
		<scroll-view class="message-list-box" scroll-y="true" @scrolltolower="handleLoadMore()">
			<view style="padding-top: 20px;" v-if="assessList.length<=0">
				<u-divider color="#909399" border-color="#909399">没有更多了</u-divider>
			</view>
			<view class="assess-row" v-for="(item, index1) in assessList" :key="index1">
				<image class="assess-head" :src="item.headimg"></image>
				<view class="assess-info">
					<view class="assess-name">{{item.nickname}}</view>
					<view class="assess-date">{{item.evaluateTime}}</view>
					<view class="assess-sore-box">
						<u-rate v-model="item.score" active-color="#FFAE21" disabled></u-rate>
					</view>
					<view class="assess-text">{{item.evaluateContent}}</view>
					<view class="assess-img-box">
						<image class="img-col" v-for="(site, index2) in item.evaluateImgs" :key="index2" :src="site.imgUrl" @tap="_previewImage(site.imgUrl,i)"></image>
					</view>
				</view>
				<view class="shop-reply-box" v-if="item.replyContent">
					<view class="shop-head">
						<view class="iconfont icondianpu"></view>
						<view class="shop-name">店家回复</view>
					</view>
					<view class="shop-reply">{{item.replyContent}}</view>
				</view>
			</view>
		</scroll-view>
		<u-top-tips ref="uTips"></u-top-tips>
	</view>
</template>

<script>
	const NET = require('@/utils/request')
	const API = require('@/config/api')
	export default {
		data() {
			return {
				goodId: '',
				pageIndex: 1,
				isOver: false,
				assessList: [],
				preview: false
			}
		},
		onLoad(options) {
			this.goodId = options.goodId
		},
		onShow() {
			if (!this.preview) {
				this.pageIndex = 1
				this.assessList = []
				this.getMessageList('refresh')
			}
		},
		onPullDownRefresh() {
			this.pageIndex = 1
			this.assessList = []
			this.getMessageList('refresh')
		},
		methods: {
			//  懒加载
			handleLoadMore() {
				if (!this.isOver) {
					this.pageIndex++
					this.getMessageList()
				}
			},
			//  获取全部留言
			getMessageList(type) {
				NET.request(API.getAssessList + this.goodId + '/' + this.pageIndex + '/10', {}, 'GET').then(res => {
					if (type == 'refresh') {
						uni.stopPullDownRefresh();
					}
					this.isOver = res.data.list.length != 10
					this.assessList = this.assessList.concat(res.data.list)
				}).catch(error => {
					this.$refs.uTips.show({
						title: error.data.msg,
						type: 'warning',
					})
				})
			},
			// 图片预览
			_previewImage(image,index) {
				this.preview = true
				var imgArr = [];
				imgArr.push(image);
				//预览图片
				uni.previewImage({
					urls: imgArr,
					current: imgArr[index]
				});
			}
		}
	}
</script>

<style lang="less" scoped>
	page {
		width: 100%;
		height: 100%;
	}

	.container {
		width: 100%;
		height: 100%;
		float: left;
		position: relative;

		.message-list-box {
			width: 100%;
			height: 100%;
			float: left;

			.assess-row {
				width: calc(100% - 30px);
				margin: 0 15px;
				float: left;
				border-top: 1px solid #F6F6F6;
				padding: 12px 0;

				.assess-head {
					width: 50px;
					height: 50px;
					float: left;
					object-fit: cover;
					border-radius: 50%;
				}

				.assess-info {
					width: calc(100% - 62px);
					margin-left: 12px;
					float: left;

					.assess-name {
						height: 18px;
						float: left;
						line-height: 18px;
						font-size: 15px;
						font-family: PingFang SC;
						font-weight: bold;
						color: #343434;
					}

					.assess-date {
						height: 18px;
						float: right;
						line-height: 18px;
						font-size: 12px;
						font-family: PingFang SC;
						font-weight: bold;
						color: #666666;
					}

					.assess-sore-box {
						width: 100%;
						height: 16px;
						float: left;
						margin: 6px 0;
					}

					.assess-text {
						width: 100%;
						float: left;
						font-size: 12px;
						font-family: PingFang SC;
						font-weight: bold;
						color: #666666;
						line-height: 16px;
						margin: 8px 0 10px 0;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
						word-wrap: break-word;
					}

					.assess-img-box {
						width: 100%;
						float: left;
						display: flex;

						.img-col {
							height: 60px;
							width: 60px;
							object-fit: cover;
							margin: 0 10px 10px 0;
						}
					}
				}

				.shop-reply-box {
					width: 100%;
					float: left;
					background: #F5F5F5;
					border-radius: 5px;
					margin-top: 10px;

					.shop-head {
						width: 100%;
						height: 36px;
						float: left;
						box-sizing: border-box;
						padding: 10px 12px;

						.icondianpu {
							width: 16px;
							height: 16px;
							float: left;
							color: #52A63A;
							font-size: 20px;
							margin-right: 8px;
						}

						.shop-name {
							height: 16px;
							float: left;
							font-size: 15px;
							font-family: PingFang SC;
							color: #52A63A;
							line-height: 16px;
						}
					}

					.shop-reply {
						width: 100%;
						float: left;
						box-sizing: border-box;
						padding: 0 12px 12px 12px;
						font-size: 12px;
						font-family: PingFang SC;
						color: #666666;
						line-height: 16px;
					}
				}
			}

			.assess-row:first-child {
				border-top: none;
			}
		}
	}
</style>