<template>
  <view class="page" :style="themeColor">
    <view class="flex benben-position-layout flex flex-wrap align-center allEvaluations_flex_0"
      :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
      <view class='flex flex-wrap align-center justify-between flex-sub allEvaluations_fd0_0'>
        <view class='flex flex-wrap align-center' @tap.stop="handleJumpDiy" data-type="back" data-url="1">
          <text class='fu-iconfont2  allEvaluations_fd0_0_c0_c0' @tap.stop="handleJumpDiy" data-type="back"
            data-url="1">&#xE794;</text>
        </view>
        <view class='flex flex-wrap align-stretch justify-center flex-sub'>
          <text class='allEvaluations_fd0_0_c1_c0'>全部评价</text>
        </view>
        <view class='flex flex-wrap align-center allEvaluations_fd0_0_c2'>
        </view>
      </view>

    </view>
    <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
    <!---flex布局flex布局开始-->
    <view class="flex benben-flex-layout flex-wrap align-center">
      <view class='flex flex-wrap align-center flex-sub allEvaluations_fd1_0'>
        <!-- <benben-select-diy ref="showSelectPopup1684722326514" class-name='flex flex-wrap flex'
          :items.sync="evaluate_List" v-model="evaluate_id" default-type="value" default-label="name"
          :allow-cancel='false' type="radio" :disabled='false'> -->
          <template v-for='(item,key0) in evaluate_List'>
            <view v-if="evaluate_id == item.value" class='flex align-center flex allEvaluations_fd1_0_c0_c0' :key="key0"
              @tap="handleCommentTypeChange(item.value)">
              <text>{{item.name}}</text>
              <text class='allEvaluations_fd1_0_c0_c0_c1'>{{item.num}}</text>
            </view>
            <view v-else class='flex align-center flex allEvaluations_fd1_0_c0_c1' :key="key0"
              @tap="handleCommentTypeChange(item.value)">
              <text>{{item.name}}</text>
              <text class='allEvaluations_fd1_0_c0_c1_c1'>{{item.num}}</text>
            </view>
          </template>
        <!-- </benben-select-diy> -->
      </view>
    </view>

    <!---flex布局flex布局结束-->
    <!---flex布局flex布局开始-->
    <fu-loading v-if="isShowLoading"></fu-loading>
    <fu-empty-ui v-if="commentList.length === 0 && isInit"></fu-empty-ui>
    <view class="flex benben-flex-layout flex-wrap align-center">
      <view class='flex flex-direction flex-wrap align-stretch allEvaluations_fd2_0' v-for="(item, index) in commentList" :key="index">
        <view class='flex flex-wrap align-center justify-between allEvaluations_fd2_0_c0'>
          <view class='flex flex-wrap align-center'>
            <view class='flex flex-wrap align-center allEvaluations_fd2_0_c0_c0_c0'>
              <image class='allEvaluations_fd2_0_c0_c0_c0_c0' mode="aspectFill" :src='item.avatar'></image>
            </view>
            <view class='flex flex-direction flex-wrap align-start'>
              <text class='allEvaluations_fd2_0_c0_c0_c1_c0'>{{item.user_nickname}}</text>
              <view class='flex flex-wrap align-center allEvaluations_fd2_0_c0_c0_c1_c1'>
                <template v-for="starNum in [1,2,3,4,5]">
                  <image v-if="item.score >= starNum" :key="starNum"
                    class='allEvaluations_star1fd2_0_c0_c0_c1_c1' mode="aspectFit" :src='STATIC_URL+"31.png"'></image>
                  <image v-else :key="starNum" class='allEvaluations_star1fd2_0_c0_c0_c1_c1' mode="aspectFit"
                    :src='STATIC_URL+"164.png"'></image>
                </template>
              </view>
            </view>
          </view>
          <view class='flex flex-wrap align-center'>
            <text class='allEvaluations_fd2_0_c0_c1_c0'>{{item.create_time}}</text>
          </view>
        </view>
        <view class='flex flex-wrap align-center allEvaluations_fd2_0_c1'>
          <text class='allEvaluations_fd2_0_c1_c0'>{{item.content}}</text>
        </view>
        <view class='flex flex-wrap align-center'>
          <image @tap.stop="ViewImage(item.images,i)" class='allEvaluations_fd2_0_c2_c0' v-for="(img, i) in item.images" :key="i" mode="aspectFill" :src='img'></image>

        </view>
      </view>
    </view>
    <uni-load-more v-if="commentList.length !=0 " :status="status"></uni-load-more>
    <!---flex布局flex布局结束-->


  </view>
</template>
<script>
  export default {
    components: {},


    data() {
      return {
        "fd2_0_c0_c0_c1_c1": "4",
        "tabls": "1",
        "evaluate_List": [],
        "evaluate_id": "1",
        commentList: [],
        isShowLoading: false,
        isInit: false,
        status: 'more', // 表示是否有数据可以请求
        page: 1,
        lists: [],
        id: '',
        sid: ''
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },

    },
    watch: {},
    onLoad(options) {
      this.id = options.goods_id || ''
      this.sid = options.sid || ''
      this.getShopCommentNums();
    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {

    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {
			this.status = 'more';
			this.page = 1;
			this.isInit = false;
			this.commentList = [];
			this.getShopCommentList(true);
			this.getShopCommentNums();
    },
    onReachBottom(e) {
			this.getShopCommentList();
    },
    onPageScroll(e) {

    },
    methods: {
			ViewImage(list, index) {
			  uni.previewImage({
			    urls: list,
			    current: index
			  });
			},
      /**
       * 切换评论状态
       */
      handleCommentTypeChange(value) {
        this.evaluate_id = value;
        this.status = 'more';
        this.page = 1;
        this.isInit = false;
        this.commentList = [];
        this.getShopCommentList(true);
      },

      /**
       * 获取店铺评论数量
       */
      getShopCommentList(value) {
        if (this.status != 'more') return;
        this.status = 'loading';
        let data = {
          store_id: this.sid,
          type: this.evaluate_id,
          list_rows: 20,
          page: this.page,
          goods_id: this.id
        };
        // console.log('请求的数据', data);
        if (this.page == 1 && value) {
          this.isShowLoading = true;
        }
        this.$api
          .post(global.apiUrls.getShopCommentList, data)
          .then(res => {
            console.log('订单列表', res);
            this.isShowLoading = false;
            if (res.data.code == 1) {
              var curPageData = res.data.data.data;
              if (this.page == 1) this.commentList = [];
              this.commentList = this.commentList.concat(curPageData);
              console.log('上拉加载', curPageData.length, this.size);
              if (res.data.data.last_page > this.page) {
                this.status = 'more';
                this.page++;
              } else {
                this.status = 'noMore';
              }
            } else {
              this.$message.info(res.data.msg);
            }
            this.isInit = true;
            uni.stopPullDownRefresh();
          })
          .catch(err => {
            this.isShowLoading = false;
            uni.stopPullDownRefresh();
          });
      },
      /**
       * 获取评论数量
       */
      getShopCommentNums() {
        this.$api.post(global.apiUrls.getShopCommentNums, {
            store_id: this.sid,
            goods_id: this.id
          }).then(res => {
            if (res.data.code == 1) {
              this.evaluate_List = [{
                name: "全部 ",
                value: "1",
                image: "",
                num: res.data.data.all
              }, {
                name: "好评",
                value: "2",
                image: "",
                num: res.data.data.good
              }, {
                name: "有图",
                value: "3",
                image: "",
                num: res.data.data.img
              }, {
                name: "差评",
                value: "4",
                image: "",
                num: res.data.data.bad
              }, {
                name: "中评",
                value: "5",
                image: "",
                num: res.data.data.center
              }]
              this.getShopCommentList();
            }
          })
          .catch(err => {
            console.log(err);
          });
      }
    }
  };
</script>
<style lang="scss" scoped>
  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: rgba(255, 255, 255, 1);
    background-size: 100% auto !important;
  }

  .allEvaluations_flex_0 {
    background: #fff;
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto !important;
  }

  .allEvaluations_fd0_0_c2 {
    width: 32rpx;
    height: 32rpx;
  }

  .allEvaluations_fd0_0_c1_c0 {
    font-size: 36rpx;
    font-weight: 500;
    color: #333;
    line-height: 88rpx;
  }

  .allEvaluations_fd0_0_c0_c0 {
    font-size: 32rpx;
    font-weight: 500;
    color: #333;
    line-height: 88rpx;
  }

  .allEvaluations_fd0_0 {
    margin: 0rpx 32rpx 0rpx 32rpx;
  }

  .allEvaluations_fd1_0_c0_c1_c1 {
    margin: 0rpx 0rpx 0rpx 8rpx;
  }

  .allEvaluations_fd1_0_c0_c1 {
    background: rgba(246, 247, 249, 1);
    margin: 24rpx 20rpx 0rpx 20rpx;
    padding: 8rpx 24rpx 8rpx 24rpx;
    border-radius: 28rpx 28rpx 28rpx 28rpx;
    background-size: 100% auto !important;
    color: rgba(51, 51, 51, 1);
  }

  .allEvaluations_fd1_0_c0_c0_c1 {
    margin: 0rpx 0rpx 0rpx 8rpx;
  }

  .allEvaluations_fd1_0_c0_c0 {
    border: 1px solid rgba(255, 147, 0, 1);
    background: rgba(255, 246, 234, 1);
    padding: 8rpx 24rpx 8rpx 24rpx;
    border-radius: 28rpx 28rpx 28rpx 28rpx;
    background-size: 100% auto !important;
    margin: 24rpx 20rpx 0rpx 20rpx;
    color: rgba(255, 147, 0, 1);
    font-size: 28rpx;
  }

  .allEvaluations_fd1_0 {
    margin: 0rpx 12rpx 0rpx 12rpx;
    padding: 0rpx 0rpx 24rpx 0rpx;
  }

  .allEvaluations_fd2_0_c2_c2 {
    width: 226rpx;
    height: 226rpx;
    border-radius: 8rpx 8rpx 8rpx 8rpx;
    margin: 0rpx 0rpx 5rpx 0rpx;
  }

  .allEvaluations_fd2_0_c2_c1 {
    width: 226rpx;
    height: 226rpx;
    border-radius: 8rpx 8rpx 8rpx 8rpx;
    margin: 0rpx 0rpx 5rpx 0rpx;
  }

  .allEvaluations_fd2_0_c2_c0 {
    width: 226rpx;
    height: 226rpx;
    border-radius: 8rpx 8rpx 8rpx 8rpx;
    margin: 0rpx 4rpx 8rpx 0rpx;
    &:nth-child(3n) {
      margin-right: 0;
    }
  }

  .allEvaluations_fd2_0_c1_c0 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 500;
    line-height: 40rpx;
  }

  .allEvaluations_fd2_0_c1 {
    margin: 0rpx 0rpx 24rpx 0rpx;
  }

  .allEvaluations_fd2_0_c0_c1_c0 {
    color: #999999;
    font-size: 24rpx;
    font-weight: 400;
    line-height: 24rpx;
  }

  .allEvaluations_star1fd2_0_c0_c0_c1_c1 {
    height: 18rpx;
    margin: 0rpx 5rpx 0rpx 5rpx;
    width: 18rpx;
  }

  .allEvaluations_star1fd2_0_c0_c0_c1_c1 {
    width: 18rpx;
    height: 18rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: 0rpx 5rpx 0rpx 5rpx;
  }

  .allEvaluations_fd2_0_c0_c0_c1_c1 {
    margin: 8rpx 0rpx 0rpx 0rpx;
  }

  .allEvaluations_fd2_0_c0_c0_c1_c0 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 400;
    line-height: 30rpx;
  }

  .allEvaluations_fd2_0_c0_c0_c0_c0 {
    width: 56rpx;
    height: 56rpx;
    border-radius: 100rpx 100rpx 100rpx 100rpx;
  }

  .allEvaluations_fd2_0_c0_c0_c0 {
    margin: 0rpx 16rpx 0rpx 0rpx;
  }

  .allEvaluations_fd2_0_c0 {
    margin: 0rpx 0rpx 24rpx 0rpx;
  }

  .allEvaluations_fd2_0 {
    border-bottom: 1px solid #eee;
    margin: 0rpx 32rpx 0rpx 32rpx;
    padding: 0rpx 0rpx 32rpx 0rpx;
  }
</style>
