<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-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 label="活动时间：">
        <el-date-picker v-model="date" type="datetimerange" range-separator="至" start-placeholder="开始日期"
          end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss">
        </el-date-picker>
      </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" show-overflow-tooltip />
      <el-table-column label="用户手机号" prop="userPhone" align="center" />
      <el-table-column label="消耗积分" prop="goodConsumePoint" align="center" />
      <el-table-column label="活动时间" prop="createTime" align="center" />
      <el-table-column label="奖品类型" prop="goodType" align="center" :formatter="goodFormatter" />
      <el-table-column label="奖品" prop="goodName" 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/lotteryStat'
export default {
  data() {
    return {
      // 遮罩层
      loading: false,
      // 表单
      form: {
        pageNum: 1,
        pageSize: 10
      },
      // 活动时间
      date: [],
      // 列表
      tableData: [],
      // 总数据
      total: 0,
      // 奖品类型
      rewardOptions: [{
        value: 3,
        label: '音响实物'
      }, {
        value: 4,
        label: '积分'
      }, {
        value: 5,
        label: '谢谢参与'
      }]
    }
  },
  watch: {
    date(val) {
      if (val) {
        this.form.startTime = val[0]
        this.form.endTime = val[1]
      }else{
        delete this.form.startTime
        delete this.form.endTime
      }
    }
  },
  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.date = []
      this.getList()
    },

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

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

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