<template>
  <el-dialog
    append-to-body
    :title="title"
    :visible.sync="dialogFormVisible"
    width="60%"
    @close="close"
  >
    <el-table v-loading="listLoading" border :data="list" height="400">
      <el-table-column
        align="center"
        :label="__('编号')"
        prop="amh_id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('用户编号')"
        prop="user_id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('参与人')"
        prop="user_name"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('电话')"
        prop="user_phone"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('公司')"
        prop="user_company"
        show-overflow-tooltip
      />

      <el-table-column
        align="center"
        :label="__('职位')"
        prop="user_position"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :formatter="formatTime"
        :label="__('时间')"
        prop="amh_datetime"
        show-overflow-tooltip
        width="160"
      />
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">{{ __('取消') }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { translateTitle as __ } from '@/utils/i18n'
  import { getList } from '@/api/activity/market/history'
  import { renderTime } from '@/utils/date'

  export default {
    name: 'ActivityMarketingHistoryTable',
    components: {},
    data() {
      return {
        list: [],
        listLoading: true,
        form: {},
        title: '',
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        queryForm: {
          pageNum: 1,
          pageSize: 20,
        },
        dialogFormVisible: false,
      }
    },
    mounted() {
      this.$forceUpdate()
    },
    methods: {
      __,

      showTable(row) {
        this.queryForm.activity_id = row.activity_id
        this.dialogFormVisible = true
        this.fetchData()
      },
      formatTime(row) {
        const amh_datetime = row.amh_datetime
        return amh_datetime ? renderTime(amh_datetime) : ''
      },

      close() {
        this.form = this.$options.data().form
        this.dialogFormVisible = false
      },
      async fetchData() {
        this.listLoading = true
        const { data } = await getList(this.queryForm)
        this.list = data.items
        this.tota = data.records
        this.listLoading = false
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        this.fetchData()
      },
    },
  }
</script>
