<template>
<view class="container">
	<view class="head_box">
		<view class="item" :class="{'itemz':type === 0}" @click="headChange(0)">
			全部
		</view>
		<view class="item" :class="{'itemz':type === 1}" @click="headChange(1)">
			图片
		</view>
		<view class="item" :class="{'itemz':type === 2}" @click="headChange(2)">
			文字
		</view>
	</view>
	<view class="comment">
		<view v-for="(item, index) in datalist" :key="index" class="item">
			<view class="top_box" style="display: flex; align-items: center; justify-content: space-between;">
				<view class="f1" style="display: flex; width: auto;">
					<image class="t1" :src="item.headimg"/>
					<view>
						<view class="t2">{{item.nickname}}</view>
						<view class="t3"><image class="img" v-for="(item2,index2) in [0,1,2,3,4]" :src="event_rul +'/static/img/static/img/star' + (item.score>item2?'2':'') + '.png'"/></view>
					</view>
				</view>
				<view class="time" style="color: #c2c2c2;">
					{{item.createtime}}
				</view>
			</view>
			<view class="f2">
				<text class="t1">{{item.content}}</text>
				<view class="t2">
					<block v-if="item.content_pic!=''">
						<block v-for="(itemp, index) in item.content_pic" :key="index">
							<view @tap="previewImage" :data-url="itemp" :data-urls="item.content_pic">
								<image :src="itemp" />
							</view>
						</block>
					</block>
				</view>
				<text class="t3">规格：{{item.ggname}}</text>
			</view>
			<view class="f3" v-if="item.reply_content">
				<view class="arrow"></view>
				<view class="t1">商家回复：{{item.reply_content}}</view>
			</view>
		</view>
  </view>
	
	<nomore v-if="nomore"></nomore>
	<nodata v-if="nodata" text="暂无评价~"></nodata>
	<loading v-if="loading"></loading>
	<dp-tabbar :opt="opt"></dp-tabbar>
	<popmsg ref="popmsg"></popmsg>
</view>
</template>

<script>
var app = getApp();

export default {
  data() {
    return {
		type:0,
		opt:{},
		loading:false,
		isload: false,
		menuindex:-1,

		datalist: [],
		pagenum: 1,
		nomore: false,

		event_rul: app.globalData.event_url,
    };
  },

  onLoad: function (opt) {
		this.opt = app.getopts(opt);
		this.getdata();
  },
	onPullDownRefresh: function () {
		this.getdata();
	},
  onReachBottom: function () {
    if (!this.nodata && !this.nomore) {
      this.pagenum = this.pagenum + 1;
      this.getdata(true);
    }
  },
  methods: {
	  headChange(e){
		  this.type = e;
		  this.getdata()
	  },
    getdata: function (loadmore) {
			if(!loadmore){
				this.pagenum = 1;
				this.datalist = [];
			}
      var that = this;
      var pagenum = that.pagenum;
			that.loading = true;
			that.nodata = false;
			that.nomore = false;
      app.post('ApiShop/commentlist', {type:this.type,proid: that.opt.proid,pagenum: pagenum}, function (res) {
				that.loading = false;
				var data = res.data;
				if (pagenum == 1) {
          that.datalist = data;
          if (data.length == 0) {
            that.nodata = true;
          }
					that.loaded();
        }else{
          if (data.length == 0) {
            that.nomore = true;
          } else {
						var datalist = that.datalist;
						var newdata = datalist.concat(data);
						that.datalist = newdata;
					}
				}
      });
    }
  }
};
</script>
<style lang="scss">
	
	.head_box{
		display: flex;
		padding: 20rpx 40rpx;
		// justify-content: space-between;
		.item{
			margin-right: 30rpx;
			color: #999999;
		}
		.itemz{
			font-weight: bold;
			color: #0A5D3B;
		}
	}
.container{background:#f6f6f6}
.comment{display:flex;flex-direction:column;padding:10rpx 20rpx;}
.comment .item{background-color:#fff;padding:10rpx 20rpx; margin-bottom: 20rpx; border-radius: 10rpx; box-shadow: 0 0 0 10rpx 0 #ccc; display:flex;flex-direction:column;}
.comment .item .f1{display:flex;width:100%;align-items:center;padding:10rpx 0;}
.comment .item .f1 .t1{width:70rpx;height:70rpx;border-radius:50%;}
.comment .item .f1 .t2{padding-left:10rpx;color:#333;font-weight:bold;font-size:30rpx;}
.comment .item .f1 .t3{text-align:right;}
.comment .item .f1 .t3 .img{width:24rpx;height:24rpx;margin-left:10rpx}
.comment .item .score{ font-size: 24rpx;color:#f99716;}
.comment .item .score image{ width: 140rpx; height: 50rpx; vertical-align: middle;  margin-bottom:6rpx; margin-right: 6rpx;}
.comment .item .f2{display:flex;flex-direction:column;width:100%;padding:10rpx 0;}
.comment .item .f2 .t1{color:#333;font-size:28rpx; margin-bottom: 10rpx;}
.comment .item .f2 .t2{display:flex;width:100%; margin-bottom: 10rpx;}
.comment .item .f2 .t2 image{width:100rpx;height:100rpx;}
.comment .item .f2 .t3{color:#aaa;font-size:24rpx;}
.comment .item .f2 .t3{color:#aaa;font-size:24rpx;}
.comment .item .f3{width:100%;padding:10rpx 0;position:relative}
.comment .item .f3 .arrow{width: 16rpx;height: 16rpx;background:#eee;transform: rotate(45deg);position:absolute;top:0rpx;left:36rpx}
.comment .item .f3 .t1{width:100%;border-radius:10rpx;padding:10rpx;font-size:22rpx;color:#888;background:#eee}

</style>