<template>
  <el-dialog
    append-to-body
    custom-class="center-dialog"
    :title="title"
    top="0vh"
    :visible.sync="dialogFormVisible"
    width="1000px"
    @close="close"
  >
    <el-table
      v-loading="listLoading"
      border
      :data="list"
      height="500"
      width="60%"
    >
      <el-table-column
        align="center"
        :label="__('砍价编号')"
        prop="ac_id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('用户编号')"
        prop="user_id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('砍价后价格')"
        prop="ac_sale_price"
        show-overflow-tooltip
        width="150px"
      />

      <el-table-column
        align="center"
        :formatter="formatDatetime"
        :label="__('创建时间')"
        prop="ac_datetime"
        show-overflow-tooltip
        width="170px"
      />
      <el-table-column
        align="center"
        :label="__('订单号')"
        prop="order_id"
        show-overflow-tooltip
        width="160px"
      />
      <el-table-column
        align="center"
        :label="__('砍价底价')"
        prop="ac_mix_limit_price"
        show-overflow-tooltip
        width="150px"
      />
      <el-table-column
        align="center"
        :label="__('砍价名单')"
        show-overflow-tooltip
        width="150px"
      >
        <template #default="{ row }">
          <el-button type="text" @click="showTHistoryable(row)">
            {{ __('查看') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />

    <TabelHistory ref="TabelHistory" />
  </el-dialog>
</template>
<script>
  import { translateTitle as __ } from '@/utils/i18n'

  import { getList } from '@/api/activity/cutprice'

  import TabelHistory from './activityCutpriceTableHistory'
  import { renderTime } from '@/utils/date'

  export default {
    name: 'StoreActivityBuyItemTable',
    components: { TabelHistory },
    data() {
      return {
        list: [],
        form: {},

        listLoading: true,
        dialogFormVisible: false,
        title: '',
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        queryForm: {
          pageNum: 1,
          pageSize: 20,
        },
      }
    },
    created() {},
    methods: {
      __,
      showTHistoryable(row) {
        this.$refs['TabelHistory'].showTable(row)
      },
      showTable(row) {
        this.queryForm.activity_id = row.activity_id
        this.dialogFormVisible = true
        this.fetchData()
      },
      formatDatetime(row) {
        return renderTime(row.ac_datetime)
      },
      close() {
        this.queryForm = this.$options.data().queryForm
        this.dialogFormVisible = false
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        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>
