<template>
  <div class="app-container">
    <el-form label-width="130px">
      <el-row>
        <el-col :span="6">
          <el-form-item label="用户名">
            <el-input v-model="KEYWORDS" placeholder="请输入用户名"/>
          </el-form-item>
        </el-col>
        <el-col v-if="false" :span="6">
          <el-form-item label="培训状态">
            <el-select v-model="STATUS" placeholder="请选择培训状态" style="width: 100%;" clearable>
              <el-option v-for="item in statusList" :key="item.value" :label="item.label" :value="item.value"/>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label-width="10px">
            <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="getQuery">
              搜索
            </el-button>
            <el-button v-waves class="filter-item" type="success" icon="el-icon-refresh" @click="goKeyReset">
              重置
            </el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table
      ref="multipleTable"
      :data="varList"
      :header-cell-style="{'font-weight': 'bold','color': '#000'}"
      tooltip-effect="dark"
      border
      fit
      highlight-current-row>
      <el-table-column :selectable="handleSelectWithDifferentStatus" type="selection" width="55" align="center"/>
      <el-table-column type="index" label="序号" width="50" align="center"/>
      <el-table-column prop="typeName" label="映射类型" align="center"/>
      <el-table-column prop="userName" label="姓名" align="center"/>
      <el-table-column prop="departmentName" label="部门名称" align="center"/>
      <el-table-column prop="userPhone" label="用户手机号" align="center"/>
      <el-table-column prop="deviceId" label="设备id" align="center"/>
      <el-table-column prop="deviceName" label="设备名称" align="center"/>
      <el-table-column prop="id" label="其他系统编号" align="center"/>
      <el-table-column prop="idRemark" label="其他系统备注" align="center"/>
      <el-table-column prop="createdTime" label="创建时间" align="center"/>
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="{row}">
          <el-button type="danger" icon="el-icon-edit" size="mini" @click="handleDelete(row)">删除</el-button>
          <el-button type="primary" icon="el-icon-edit" size="mini" @click="handleEdit(row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page-btn-group">
      <div>
        <el-button type="primary" icon="el-icon-plus" @click="handleAdd">新增</el-button>
      </div>
      <pagination :total="listQuery.total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList"/>
    </div>
    <info ref="info" @flush="getList"/>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' // waves directive
import info from './info.vue'
import vueQr from 'vue-qr'

export default {
  components: { Pagination, vueQr, info },
  directives: { waves },
  data() {
    return {
      config: config,
      listQuery: {
        page: 0,
        limit: 10,
        total: 0
      },
      listLoading: false,
      KEYWORDS: '',
      varList: [],
      add: false,		// 新增按钮
      del: false,		// 删除按钮
      edit: false	// 修改按钮
    }
  },
  created() {
    this.getList()
    this.hasButton()
  },
  methods: {
    handleSelectWithDifferentStatus(row, rowIndex) {
      return true
    },
    getQuery() {
      if (this.$refs.multipleTable) {
        this.$refs.multipleTable.clearSelection()
      }
      this.listQuery = {
        page: 1,
        limit: 10
      }
      this.getList()
    },
    goKeyReset() {
      this.STATUS = ''
      this.getQuery()
    },
    getList() {
      this.listLoading = true
      requestFN(
        '/dingWei/getMapList?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page, {}
      ).then((data) => {
        this.listLoading = false
        this.varList = data.list
        this.listQuery.total = Number(data.page.total)
      }).catch((e) => {
        this.listLoading = false
      })
    },
    handleAdd() {
      this.$refs.info.init()
    },
    hasButton() {
      var keys = 'trainingbatch:add,trainingbatch:del,trainingbatch:edit,fhSms,email,fromExcel,toExcel'
      requestFN(
        '/head/hasButton',
        {
          keys: keys, tm: new Date().getTime()
        }
      ).then((data) => {
        if (data.result == 'success') {
          this.add = data.trainingbatchfhadminadd	// 增
          this.del = data.trainingbatchfhadmindel	// 删
          this.edit = data.trainingbatchfhadminedit	// 改
          this.fromExcel = data.fromExcel	// 从excel导入权限
          this.toExcel = data.toExcel		// 导出到excel权限
        } else if (data.result == 'exception') {
          // showException('按钮权限', data.exception)// 显示异常
          console.info('按钮权限:', data.exception)
        }
      })
        .catch((e) => {
          this.listLoading = false
        })
    },
    getDict: function() {
      requestFN('dingWei/getDictionary').then((data) => {
        this.wenhuachengduList = data.list
      }).catch((e) => {
        this.listLoading = false
      })
    },
    handleDelete(row) {
      this.$confirm('是否删除该条数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.listLoading = true
        requestFN(
          '/dingWei/deleteMap', { id: row.dwUserMapId }
        ).then((data) => {
          this.listLoading = false
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.getList()
        }).catch((e) => {
          this.listLoading = false
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    handleEdit(row) {
      this.$refs.info.init(row)
    }

  }
}
</script>

