<template>
  <div v-loading="loading">
    <div class="white-box">
      <div class="filter-user">
        <el-input v-model="filterForm.userName" size="small" style="width:300px;">
          <template slot="prepend">会员编号</template>
        </el-input>
        <el-input v-model="filterForm.periodNum" size="small" style="width:150px;">
          <template slot="prepend">期数</template>
        </el-input>
        <el-button type="primary" size="small" @click="handleFilter">确定</el-button>
      </div>
      <el-table :data="tableData" stripe style="width: 100%;" :height="tool.getTableHeight()">
        <el-table-column v-for="(tableHeader, key) in tableHeaders" :key="key" :label="tableHeader.header" :width="tableHeader.other.width ? tableHeader.other.width : ''">
          <template slot-scope="scope">
            <template v-if="scope.row[tableHeader.index].other.tag" >
              <el-tag :type="scope.row[tableHeader.index].other.tag.type ? scope.row[tableHeader.index].other.tag.type : null" :size="scope.row[tableHeader.index].other.tag.size ? scope.row[tableHeader.index].other.tag.size : null" :class="scope.row[tableHeader.index].other.tag.class ? scope.row[tableHeader.index].other.tag.class : null" >{{scope.row[tableHeader.index].value}}</el-tag>
            </template>
            <template v-else-if="scope.row[tableHeader.index].other.progress" >
              <el-progress type="circle" :percentage="Number.parseInt(percentList['MOVE_PERCENT'][scope.row.ID])"
                           :width="50"
                           :stroke-width="3"></el-progress>
            </template>
            <template v-else>
              <div v-html="scope.row[tableHeader.index].value"></div>
            </template>
          </template>
        </el-table-column>
      </el-table>
      <div class="white-box-footer">
        <el-button type="success" size="small" @click="handleExport"
                   v-show="permission.hasPermission(`atlas/emp-user-list-export`)">导出Excel
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
import network from '@/utils/network'
import tool from '@/utils/tool'
import permission from '@/utils/permission'
import store from '@/utils/vuexStore'
import baseInfo from '@/utils/baseInfo'

export default {
  name: 'atlas_emp-user-list',
  mounted () {
    this.filterForm.periodNum = baseInfo.nowPeriodNum()
  },
  data () {
    return {
      tableHeaders: null,
      tableData: null,
      loading: false,
      tool: tool,
      permission: permission,
      filterForm: {
        userName: null,
        periodNum: null,
      },
      listPeriodNum: null,
    }
  },
  methods: {
    handleFilter () {
      this.loading = true
      this.getData()
    },
    getData () {
      network.getData('atlas/emp-user-list', this.filterForm).then((response)=>{
        this.tableData = response.list
        this.listPeriodNum = response.periodNum
        this.tableHeaders = response.columnsShow ? response.columnsShow : []
        this.loading = false
      }).catch(response => {
        this.loading = false
      })
    },
    handleExport(){
      this.$confirm(`确定要导出当前数据吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        return network.getData(`atlas/emp-user-list-export`, this.filterForm)
      }).then(response => {
        this.$message({
          message: response,
          type: 'success'
        })
      }).catch(response => {

      })
    },
  }
}

</script>

<style>
  .filter-user{font-size: 14px;margin-bottom: 20px;}
  .filter-user:after{content: '';display: table;
    clear: both;}
  .filter-user .el-input-group{position: relative;}
  .filter-user .el-input-group,.filter-user .el-button{float: left;margin-right: 15px;}
</style>