<template>
  <div class='app-container'>
    <!-- 搜索 -->
    <el-form inline size="mini">
      <el-form-item label="兑换编码：">
        <el-input v-model="form.code" placeholder="请输入兑换编码" />
      </el-form-item>
      <el-form-item label="设备标识：">
        <el-input v-model="form.deviceMac" placeholder="请输入设备标识" />
      </el-form-item>
      <el-form-item label="dsn状态：">
        <el-select v-model="form.dsnStatus" placeholder="请选择dsn状态" clearable>
          <el-option v-for="item in statusOptions" :key="item.value" :value="item.value" :label="item.label" />
        </el-select>
      </el-form-item>
      <el-form-item label="音乐VIP状态：">
        <el-select v-model="form.vipStatus" placeholder="请选择音乐VIP状态" clearable>
          <el-option v-for="item in statusOptions" :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="创建时间" align="center" prop="createTime"></el-table-column>
      <el-table-column label="兑换码编码" align="center" prop="code"></el-table-column>
      <el-table-column label="设备标识" align="center" prop="deviceMac"></el-table-column>
      <el-table-column label="设备型号" align="center" prop="clientType"></el-table-column>
      <el-table-column label="用户账号" align="center" prop="userName"></el-table-column>
      <el-table-column label="用户手机号" align="center" prop="phone"></el-table-column>
      <el-table-column label="服务时长" align="center" prop="serviceTime" :formatter="timeFormatter"></el-table-column>
      <el-table-column label="VIP领取时间" align="center" prop="vipReceiveTime"></el-table-column>
      <el-table-column label="音乐VIP状态" align="center" prop="vipStatus" :formatter="statusFormatter"></el-table-column>
      <el-table-column label="dsn激活时间" align="center" prop="dsnActiveTime"></el-table-column>
      <el-table-column label="dsn状态" align="center" prop="dsnStatus" :formatter="statusFormatter"></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/service/recovery'
import { serviceTimeMixin } from '@/mixin/index'
export default {
  mixins: [serviceTimeMixin],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 表单
      form: {
        pageNum: 1,
        pageSize: 10
      },
      // 总数据
      total: 0,
      // 列表
      tableData: [],
      // dsn vip
      statusOptions: [{
        value: 0,
        label: '回收成功'
      }, {
        value: 1,
        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()
    },

    // 字典翻译
    statusFormatter(row, column, cellValue) {
      return this.selectDictLabel(this.statusOptions, cellValue)
    },

    timeFormatter(row) {
      return this.selectDictLabel(this.serviceTimeOptions, row.serviceTime)
    }
  }
}
</script>