<!-- 商家-拼团历史报表 -->
<template>
  <el-dialog
    append-to-body
    custom-class="center-dialog"
    :title="title"
    top="0vh"
    :visible.sync="dialogFormVisible"
    width="65%"
    @close="close"
  >
    <el-table
      v-loading="listLoading"
      border
      :data="list"
      height="500"
      width="60%"
    >
      <el-table-column
        align="center"
        :label="__('拼团记录编号')"
        prop="gbh_id"
        show-overflow-tooltip
        width="140"
      />
      <el-table-column
        align="center"
        :label="__('创建团用户编号')"
        prop="user_id"
        show-overflow-tooltip
        width="150"
      />
      <el-table-column
        align="center"
        :label="__('团购活动编号')"
        prop="activity_id"
        show-overflow-tooltip
        width="140"
      />
      <el-table-column
        align="center"
        :formatter="formatStarttime"
        :label="__('参加团购时间')"
        prop="gbh_time"
        show-overflow-tooltip
        width="170px"
      />
      <el-table-column
        align="center"
        :label="__('拼团订单')"
        prop="order_id"
        show-overflow-tooltip
        width="170px"
      />
      <el-table-column
        align="center"
        :label="__('参团编号')"
        prop="gb_id"
        show-overflow-tooltip
        width="150px"
      />
      <el-table-column
        align="center"
        :formatter="formatFlag"
        :label="__('是否已支付')"
        prop="gbh_flag"
        show-overflow-tooltip
        width="150px"
      />
      <el-table-column
        align="center"
        :formatter="formatEnable"
        :label="__('拼团状态')"
        prop="gb_enable"
        show-overflow-tooltip
        width="150px"
      />
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
  </el-dialog>
</template>
<script>
  import { translateTitle as __ } from '@/utils/i18n'
  import { doDelete, getList } from '@/api/activity/groupbooking/history'
  import { renderTime } from '@/utils/date'
  export default {
    name: 'ActivityTable',
    components: {},
    data() {
      return {
        list: [],
        form: {},
        listLoading: true,
        dialogFormVisible: false,
        title: '',
        total: 0,
        layout: 'total, sizes, prev, pager, next, jumper',
        queryForm: {
          pageNum: 1,
          pageSize: 20,
        },
      }
    },
    created() {},
    methods: {
      __,
      showTable(row) {
        this.queryForm.gb_id = row.gb_id
        this.dialogFormVisible = true
        this.fetchData()
      },
      formatStarttime(row) {
        return renderTime(row.gbh_time)
      },
      handleDelete(row) {
        this.$baseConfirm(this.__('你确定要删除当前项吗'), null, async () => {
          const { msg, status } = await doDelete({ gb_id: row.gb_id })
          if (200 == status) {
            this.$baseMessage(msg, 'success')
          } else {
            this.$baseMessage(msg, 'error')
          }
          await this.refresh()
        })
      },
      formatEnable(row) {
        return row.gb_enable === 1
          ? this.__('成功')
          : row.gb_enable === 0
          ? this.__('失败')
          : this.__('进程中')
      },
      close() {
        this.queryForm = this.$options.data().queryForm
        this.dialogFormVisible = false
      },
      formatFlag(row) {
        return row.gbh_flag === 1 ? 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;
        debugger;
      },
    },
  }
</script>
