<!--商家-拼团报表-->
<template>
  <el-dialog
    append-to-body
    custom-class="center-dialog"
    :title="title"
    top="0vh"
    :visible.sync="dialogFormVisible"
    width="70%"
    @close="close"
  >
    <el-table
      v-loading="listLoading"
      border
      :data="list"
      height="500"
      width="60%"
    >
      <el-table-column align="center" :label="__('操作')" width="125">
        <template #default="{ row }">
          <el-button type="text" @click="showActivityTable(row)">
            {{ __('查看') }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="__('拼团编号')"
        prop="gb_id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('创建团用户编号')"
        prop="user_id"
        show-overflow-tooltip
        width="150"
      />
      <el-table-column
        align="center"
        :formatter="formatStarttime"
        :label="__('开团时间')"
        prop="gb_datetime"
        show-overflow-tooltip
        width="160px"
      />
      <el-table-column
        align="center"
        :formatter="formatEndtime"
        :label="__('团结算时间')"
        prop="gb_endtime"
        show-overflow-tooltip
        width="160px"
      />
      <el-table-column
        align="center"
        :formatter="formatEnable"
        :label="__('拼团状态')"
        prop="gb_enable"
        show-overflow-tooltip
        width="150px"
      />
      <el-table-column
        align="center"
        :label="__('参团总人数')"
        prop="gb_amount_quantity"
        show-overflow-tooltip
        width="150px"
      />
      <el-table-column
        align="center"
        :label="__('成员有效数量')"
        prop="gb_quantity"
        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"
    />
    <Table ref="Table" />
  </el-dialog>
</template>
<script>
  import { translateTitle as __ } from '@/utils/i18n'
  import { doDelete, getList } from '@/api/activity/groupbooking'
  import Table from './activityTable'
  import { renderTime } from '@/utils/date'
  export default {
    name: 'ActivityGroupbookingTable',
    components: { Table },
    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: {
      __,
      formatStarttime(row) {
        return renderTime(row.gb_datetime)
      },
      formatEndtime(row) {
        return renderTime(row.gb_endtime)
      },
      showTable(row) {
        this.queryForm.activity_id = row.activity_id
        this.dialogFormVisible = true
        this.fetchData()
      },
      formatEnable(row) {
        return row.gb_enable === 1
          ? this.__('成功')
          : row.gb_enable === 0
          ? this.__('失败')
          : this.__('进程中')
      },
      showActivityTable(row) {
        this.$refs['Table'].showTable(row)
      },
      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()
        })
      },

      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()
      },
      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>
