<template>
  <div class="choose-goods">
    <!-- <evue-table  :data="list" :option="option" @currentRowChange="currentRowChange"></evue-table> -->
    <el-table :data="list" style="width: 100%"
     highlight-current-row
     @current-change="handleCurrentChange">
      <el-table-column
        prop="buyerShowId"
        label="买家秀ID">
      </el-table-column>
       <el-table-column
         prop="coverUrl"
         label="评论图片">
         <template slot-scope="scope">
           <el-image style="width: 60px; height: 60px" :src="scope.row.coverUrl? ((scope.row.coverUrl.split(',')[0].indexOf('.jpg') > 0)? resourcesUrl + scope.row.coverUrl.split(',')[0]: ''): ''"></el-image>
         </template>
      </el-table-column>
      <el-table-column
        prop="userAvatarUrl"
        label="用户头像">
        <template slot-scope="scope">
          <el-image style="width: 60px; height: 60px" :src="scope.row.userAvatarUrl"></el-image>
        </template>
      </el-table-column>
      <el-table-column
        prop="userNickName"
        label="用户昵称">
      </el-table-column>
      <el-table-column
        prop="content"
        label="评论内容">
      </el-table-column>
      <el-table-column
        prop="likeCount"
        label="点赞数">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间">
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentPageChange"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalPage">
    </el-pagination>
  </div>
</template>
<script>
export default {
  name: 'choose-feature',
  props: {
    isGetChooseData: {// 是否开始返回数据
      type: Boolean,
      default: false
    }
  },
  watch: {
    isGetChooseData () {
      if (!this.currentBuyerShow.buyerShowId) {
        this.$message.error("请选择买家秀记录")
        return
      }
      this.$emit('chooseBuyerShowFun', {
        data: this.currentBuyerShow
      })
    }
  },
  data () {
    return {
      defaultAvatarUrl: "https://ecard-oss.58for.com/2023/04/784e3594731c4982a964913acc652e72.png",
      resourcesUrl: process.env.VUE_APP_RESOURCES_URL,
      shopId: this.$store.state.user.shopId,
      list: [],
      currentBuyerShow: {}, // 当前选择的
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0
    }
  },
  mounted () {
    this.getBuyerShowPagesList()
  },
  methods: {
    /**
     * 获取买家秀列表
     */
    getBuyerShowPagesList () {
      this.$http({
        url: this.$http.adornUrl('/prod/buyerShow/page'),
        method: 'get',
        params: this.$http.adornParams(
          Object.assign(
            {
              current: this.pageIndex,
              size: this.pageSize,
              shopId: this.shopId
            }
          )
        )
      }).then(({ data }) => {
        this.list = data.records
        this.list.forEach(item =>{
          if(!item.userAvatarUrl){
            item.userAvatarUrl = this.defaultAvatarUrl
          }
        })
        this.totalPage = data.total
      }).catch((error) => {
        console.log('err', error)
      })
    },
    // 每页数
    handleSizeChange (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getMiniPagesList()
    },
    // 当前页
    handleCurrentPageChange (val) {
      this.pageIndex = val
      this.getBuyerShowPagesList()
    },
    /**
     * 选择买家秀
     */
    handleCurrentChange (ev) {
      this.currentBuyerShow =
        {
          buyerShowId: ev.buyerShowId,
          userNickName: ev.userNickName,
          userAvatarUrl: ev.userAvatarUrl,
          likeCount: ev.likeCount,
          content: ev.content,
          coverUrl: ev.coverUrl? (ev.coverUrl.split(',')[0].indexOf('.jpg') > 0 ? ev.coverUrl.split(',')[0] : '') : ''
        }
    }
  }
}
</script>

<style lang="scss" scoped>
.choose-goods {
  .goods {
    display: flex;

    img {
      width: 60px;
      height: 60px;
      object-fit: cover;
      object-position: center;
    }

    .goodsName {
      flex: 1;
      padding-top: 5px;
      padding-left: 5px;

      p {
        color: #38f;
        cursor: pointer;
      }

      span {
        color: #f60;
      }
    }
  }
}
</style>
