<template>
  <el-dialog
    append-to-body
    custom-class="center-dialog"
    :title="title"
    top="0vh"
    :visible.sync="dialogFormVisible"
    width="80%"
    @close="close"
  >
    <el-table
      v-loading="listLoading"
      border
      :data="list"
      height="500"
      width="60%"
    >
      <el-table-column
        align="center"
        :label="__('编号')"
        prop="alh_id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('用户编号')"
        prop="user_id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('用户昵称')"
        prop="user_nickname"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('奖品名称')"
        prop="awards_name"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('奖品图片')"
        prop="awards_image"
        show-overflow-tooltip
        width="150px"
      >
        <template slot-scope="scope">
          <el-image
            v-show="scope.row.awards_image"
            :preview-src-list="[scope.row.awards_image]"
            :src="scope.row.awards_image"
            style="width: 35px; height: 35px"
          />
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="__('是否已发送')"
        prop="alh_is_send"
        width="120"
      >
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.alh_is_send"

            :active-value="1"

            :inactive-value="0"
            @change="sChange(scope.row)"
          />
        </template>
      </el-table-column>

      <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_address"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('中奖时间')"
        prop="alh_datetime"
        show-overflow-tooltip
        width="160"
      />
      <el-table-column
        align="center"
        :formatter="formatEnble"
        :label="__('是否中奖')"
        prop="alh_award_flag"
        show-overflow-tooltip
      />
    </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 { getActivityLotteryHistorys } from '@/api/store/activity/base'
  import { doEdit } from '@/api/activity/lottery/history'

  export default {
    name: 'AdventuresTable',
    components: {},
    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: {
      __,
      showTable(row) {
        this.queryForm.activity_id = row.activity_id
        this.dialogFormVisible = true
        this.fetchData()
      },
      close() {
        this.dialogFormVisible = false
      },

      // 获取规格数据
      formatEnble(row) {
        return row.alh_award_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 sChange(row) {
        const param = {
          alh_is_send: row.alh_is_send,
          alh_id: row.alh_id,
        }

        const { msg, status } = await doEdit(param)
        this.$baseMessage(msg, 'success', false, 'vab-hey-message-success')
      },
      async fetchData() {
        this.listLoading = true
        const { data } = await getActivityLotteryHistorys(this.queryForm)
        this.list = data.items
        this.total = data.records
        this.listLoading = false
      },
    },
  }
</script>
