<template>
	<!-- #ifdef H5 -->
	<zj-page-layout
	  :hasFooter="false"
	  :isScroll="true"
	  :refresherTriggered="refresherTriggered"
	  @refresherrefresh="refresherrefresh"
	  @scrolltolower="scrolltolower">
		<view class="top-container" v-if="dataList.length">
			<view class="top">
				<view class="left">
					<text>综合评分</text><uni-rate :size="18" :margin="4" :value="5" color="#fff" active-color="#FE781F" :readonly="true" />
				</view>
				<view class="right">{{countDetail.goodRate}}%好评</view>
			</view>
			<view class="tabs">
				<view class="item" :class="currentTab === '' ? 'current':''" @tap="changeTabs('')">全部</view>
				<block v-for="(item, index) in countDetail.tagCountList" :key="index">
					<view class="item" :class="currentTab === item.tag ? 'current':''" @tap="changeTabs(item.tag)">{{item.tag}}({{item.total}})</view>
				</block>
			</view>
		</view>

		<view class="list-container">
			<view class="item" v-for="(item, index) in dataList">
				<view class="top">
					<view class="user">
						<image :src="item.avatar" mode="aspectFill" v-if="item.avatar.indexOf('http') >= 0"></image>
						<image :src="imageUrl + item.avatar" mode="aspectFill" v-else></image>
						<view class="right">
							<view class="name ellipsis">{{item.userName}}</view>
							<view class="date">{{item.createTime}}</view>
						</view>
					</view>
				</view>
				<view class="rate">
					<view class="it">
						<view class="text">综合评分</view>
						<u-rate :count="5" readonly activeColor="#FE781F" :value="Number((((item.commentGoods || 0)+(item.commentService || 0)+(item.commentExpress || 0)) / 3).toFixed(2))"></u-rate>
					</view>
					<!-- <view class="it">
						<view class="text">商品质量</view>
						<u-rate :count="5" readonly activeColor="#FE781F" v-model="item.commentGoods"></u-rate>
					</view>
					<view class="it">
						<view class="text">服务质量</view>
						<u-rate :count="5" readonly activeColor="#FE781F" v-model="item.commentService"></u-rate>
					</view>
					<view class="it">
						<view class="text">配送质量</view>
						<u-rate :count="5" readonly activeColor="#FE781F" v-model="item.commentExpress"></u-rate>
					</view> -->
				</view>
				<view class="tags">
					<view class="it" v-for="(it, idx) in item.tags">{{it}}</view>
				</view>
				<!-- <view class="tagss">
					<view class="it" v-for="(it, idx) in item.tags">#{{it}}#</view>
				</view> -->
				<view class="content">{{item.content}}</view>
				<view class="images" v-if="item.imgs && item.imgs.length > 0">
					<image v-for="(it, idx) in item.imgs" :src="it" @tap="previewEvaluateImage(it, item.imgs)"></image>
				</view>
			</view>
		</view>
    <Loading :loadStatus="loadStatus" :dataList="dataList" />

  </zj-page-layout>
  <!-- #endif -->
  <!-- #ifndef H5 -->
  <web-view :src="webViewHref(`/packageGoods/pages/evaluate`, pam,crossPagePam)" @message="crossPage.$listener"></web-view>
  <!-- #endif -->
</template>

<script>
  // #ifdef H5
	export default {
		data() {
			return {
				imageUrl: this.$imageUrl,
				goodsId: null,
				countDetail: {},
				dataList: [],
				pageNum: 1,
        loadStatus: 0,
        refresherTriggered: false,
				currentTab: '',
			}
		},
    
		onLoad({goodsId}) {
			this.goodsId = goodsId;
			this.getList();
			this.getCount();
		},

		methods: {
			// 获取统计
			getCount() {
				this.$api.get('/order/comment/goods/count', {
					goodsId: this.goodsId,
				}).then(res => {
					this.countDetail = res.data;
				})
			},

			// 获取列表
			getList() {
				this.$api.get('/order/comment/goods', {
          pageNo: this.pageNum,
          pageSize: 10,
          goodsId: this.goodsId,
          tag: this.currentTab,
				}).then(res => {
					this.loadStatus = 0;
					let list = res.data.records;
					if (list.length < 10) {
					  this.loadStatus = 2;
					}
					this.dataList = this.dataList.concat(list);
				}).catch(() => {
          this.loadStatus = 2;
        }).finally(res => {
          this.refresherTriggered = false;
        })
			},
      
      // 滚动到底部
      scrolltolower(e) {
        if (this.loadStatus === 0) {
          this.pageNum++;
          this.getList();
        }
      },
      
      // 触发下拉刷新
      refresherrefresh(e) {
        this.refresherTriggered = true;
        this.refreshList();
        this.getCount();
      },
      
      refreshList() {
        this.dataList = [];
        this.pageNum = 1;
        this.getList();
      },

			changeTabs(tag) {
				this.currentTab = tag;
				this.refreshList();
			},

			// 预览评价图片
			previewEvaluateImage(url, imgs) {
				uni.previewImage({
					urls: imgs,
					current: url
				});
			},
		}
	}
  // #endif
  // #ifndef H5
  export default {
    data() {
      return {
        pam: {},
      }
    },

    onLoad(pam) {
      this.pam = pam;
    },
  }
  // #endif
</script>

<style lang="scss" scoped>
	.top-container {
		background: #FFFFFF;
		padding: 20rpx;
		margin-bottom: 20rpx;
		.top {
			display: flex;
			justify-content: space-between;
			align-items: center;
			.left {
				display: flex;
				align-items: center;
				font-size: 28rpx;
				color: #333333;
				margin-top: 5rpx;
				&>text {
					margin-right: 14rpx;
				}
			}
			.right {
				font-size: 24rpx;
				color: #666666;
			}
		}
		.tabs {
			display: flex;
			overflow-x: scroll;
			.item {
				flex-shrink: 0;
				height: 52rpx;
				line-height: 52rpx;
				border-radius: 52rpx;
				padding: 0 25rpx;
				border: 1px solid #eaeaea;
				color: #333333;
				font-size: 24rpx;
				margin-right: 16rpx;
				margin-top: 16rpx;
				&.current {
					border: 1px solid $theme-color;
					background: $theme-color;
					color: #FFFFFF;
				}
			}
		}
	}
	.list-container {
		padding: 0 20rpx;
		background: #FFFFFF;
		.item {
			padding: 20rpx 0;
			border-bottom: 1px solid #eaeaea;
			&:last-child {
				border-bottom: none;
			}
			.top {
				display: flex;
				justify-content: space-between;
				align-items: center;
				.user {
					display: flex;
					align-items: center;
					image {
						width: 80rpx;
						height: 80rpx;
						display: block;
						border-radius: 50%;
						margin-right: 20rpx;
					}
					.right {
						.name {
							max-width: 300rpx;
							font-size: 28rpx;
							color: #333333;
							font-weight: 500;
						}
						.date {
							font-size: 24rpx;
							color: #999999;
							margin-top: 12rpx;
						}
					}
				}
			}
			.rate {
				margin-top: 14rpx;
				.it {
					display: flex;
					align-items: center;
					font-size: 24rpx;
					color: #666666;
					margin-top: 5rpx;
					.text {
						margin-right: 10rpx;
						margin-top: 4rpx;
					}
				}
			}
			.tags {
				display: flex;
				flex-wrap: wrap;
				.it {
					line-height: 44rpx;
					padding: 0 15rpx;
					border: 1px solid #eaeaea;
					border-radius: 44rpx;
					font-size: 24rpx;
					margin-right: 14rpx;
					margin-top: 14rpx;
					color: #666666;
				}
			}
			.tagss {
				display: flex;
				flex-wrap: wrap;
				margin-top: 14rpx;
				.it {
					font-size: 24rpx;
					color: $theme-color;
					margin-right: 6rpx;
				}
			}
			.content {
				font-size: 28rpx;
				color: #333333;
				margin-top: 14rpx;
			}
			.images {
				display: flex;
				flex-wrap: wrap;
				image {
					width: 140rpx;
					height: 140rpx;
					margin-right: 20rpx;
					margin-top: 20rpx;
				}
			}
		}
	}
</style>
