<template>
  <div class="order-comment-container">
    <vab-query-form>
      <vab-query-form-right-panel :span="24">
        <el-button icon="el-icon-refresh" type="primary" @click="queryData">
          {{ __('刷新') }}
        </el-button>
      </vab-query-form-right-panel>
    </vab-query-form>
    <el-table
      v-loading="listLoading"
      border
      :data="list"
      :height="tableConfig.height"
    >
      <el-table-column
        align="center"
        fixed="left"
        :label="__('订单编号')"
        prop="order_id"
        show-overflow-tooltip
        width="140"
      />
      <el-table-column
        align="center"
        :label="__('卖家店铺编号')"
        prop="store_id"
        show-overflow-tooltip
        width="120"
      />
      <el-table-column
        align="center"
        :label="__('店铺名称')"
        prop="store_name"
        show-overflow-tooltip
        width="120"
      />
      <el-table-column
        align="center"
        :label="__('买家编号')"
        prop="user_id"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        align="center"
        :label="__('买家姓名')"
        prop="user_name"
        show-overflow-tooltip
        width="120"
      />
      <el-table-column
        align="center"
        :label="__('获得积分')"
        prop="comment_points"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        align="center"
        :label="__('评价星级')"
        prop="comment_scores"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        align="center"
        :label="__('评价内容')"
        prop="comment_content"
        show-overflow-tooltip
        width="180"
      />
      <el-table-column
        align="center"
        :label="__('评论图片')"
        prop="comment_image"
        show-overflow-tooltip
        width="100"
      >
        <template slot-scope="scope">
          <el-popover placement="top-start" title="" trigger="hover">
            <img
              v-if="scope.row.comment_image"
              alt=""
              :src="scope.row.comment_image"
              style="width: 150px; height: 150px"
            />
            <img
              v-if="scope.row.comment_image"
              slot="reference"
              :src="scope.row.comment_image"
              style="width: 30px; height: 30px"
            />
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="__('有帮助')"
        prop="comment_helpful"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        align="center"
        :formatter="formatTime"
        :label="__('评价时间')"
        prop="comment_time"
        show-overflow-tooltip
        width="160"
      />
      <el-table-column
        align="center"
        :formatter="formatAnonymous"
        :label="__('匿名评价')"
        prop="comment_is_anonymous"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        align="center"
        :formatter="formatEnable"
        :label="__('评价信息的状态')"
        prop="comment_enable"
        show-overflow-tooltip
        width="160"
      />
      <el-table-column
        align="center"
        :label="__('描述相符评分')"
        prop="comment_store_desc_credit"
        show-overflow-tooltip
        width="120"
      />
      <el-table-column
        align="center"
        :label="__('服务态度评分')"
        prop="comment_store_service_credit"
        show-overflow-tooltip
        width="120"
      />
      <el-table-column
        align="center"
        :label="__('发货速度评分')"
        prop="comment_store_delivery_credit"
        show-overflow-tooltip
        width="120"
      />
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
  </div>
</template>

<script>
  import { translateTitle as __ } from '@/utils/i18n'
  import { getList } from '@/api/order/comment'
  import { renderTime } from '@/utils/date'

  export default {
    name: 'Comment',
    components: {},
    data() {
      return {
        tableConfig: {
          height: window.innerHeight - 220 - 90,
        },
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        queryForm: {
          pageNum: 1,
          pageSize: 20,
          title: '',
        },
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      formatTime(row) {
        const comment_time = row.comment_time
        return comment_time ? renderTime(comment_time) : ''
      },
      formatAnonymous(row) {
        return row.comment_is_anonymous ? this.__('是') : this.__('否')
      },
      formatEnable(row) {
        return row.comment_enable ? this.__('正常显示') : this.__('禁止显示')
      },
      __,
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        this.fetchData()
      },
      queryData() {
        this.queryForm.pageNum = 1
        this.fetchData()
      },
      async fetchData() {
        this.listLoading = true
        const { data } = await getList(this.queryForm)
        this.list = data.items
        this.total = data.records
        this.listLoading = false
      },
    },
  }
</script>
