<template>
  <div class="app-container">
    <!-- 表单 -->
    <el-form inline size="mini">
      <el-form-item label="用户昵称：">
        <el-input v-model="form.userName" placeholder="请输入用户昵称" clearable />
      </el-form-item>
      <el-form-item label="用户手机号：">
        <el-input v-model="form.userPhone" placeholder="请输入用户手机号" clearable />
      </el-form-item>
      <el-form-item label="兑换标题：">
        <el-input v-model="form.goodName" placeholder="请输入兑换标题" clearable />
      </el-form-item>
      <el-form-item label="兑换类型：">
        <el-select v-model="form.goodType" placeholder="请输入兑换类型" clearable>
          <el-option v-for="item in rewardOptions" :key="item.value" :value="item.value"
            :label="item.label" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getSearch">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="getRefresh">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-table :data="tableData" v-loading="loading">
      <el-table-column label="序号" type="index" align="center" />
      <el-table-column label="用户昵称" prop="userName" align="center" />
      <el-table-column label="用户手机号" prop="receivePhone" align="center" />
      <el-table-column label="兑换类型" prop="goodType" align="center" :formatter="typeFormatter" />
      <el-table-column label="兑换标题" prop="goodName" align="center" />
      <el-table-column label="兑换积分" prop="goodConsumePoint" align="center" />
      <el-table-column label="兑换时间" prop="createTime" align="center" />
      <el-table-column label="收货信息" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-button type="text" v-clipboard:copy="scope.row.addressInfo" v-clipboard:success="copeSuccess">
            {{ scope.row.addressInfo }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="form.pageNum" :limit.sync="form.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { list } from '@/api/registration/order'
export default {
  data() {
    return {
      // 遮罩层
      loading: false,
      // 表单
      form: {
        pageNum: 1,
        pageSize: 10
      },
      // 总数据
      total: 0,
      // 列表
      tableData: [],
      // 奖品类型
      rewardOptions: [{
        value: 0,
        label: '音乐套餐'
      }, {
        value: 1,
        label: '流量套餐'
      }, {
        value: 3,
        label: '音响实物'
      }]
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    // 列表
    getList() {
      this.loading = true
      list(this.form).then(res => {
        if (res.code === 0) {
          this.tableData = res.data.records
          this.total = res.data.total
          this.loading = false
        }
      })
    },

    // 搜索
    getSearch() {
      this.form.pageNum = 1
      this.getList()
    },

    // 重置
    getRefresh() {
      this.form = {
        pageNum: 1,
        pageSize: 10
      }
      this.getList()
    },

    // 复制
    copeSuccess() {
      this.$message.success('复制成功！')
    },

    // 字典翻译
    typeFormatter(row) {
      return this.selectDictLabel(this.rewardOptions, row.goodType)
    }
  }
}
</script>

<style lang="scss" scoped>
</style>