<template>
  <div v-loading="loading">
    <div class="white-box">
      <div class="filter-box">
        <filter-user :filter-types.sync="filterTypes" filter-btn-name="screen"
                     @select-value="handleFilterUser"></filter-user><!-- 筛选 -->
      </div>
      <el-table ref="multipleTable" :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 : ''" :prop="tableHeader.other.prop ? tableHeader.other.prop : null">
          <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>
              <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(`log/user-login-export`)">Export Excel<!-- 导出Excel --></el-button>
        <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"></pagination>
      </div>
    </div>
  </div>
</template>

<script>
  import network from '@/utils/network'
  import tool from '@/utils/tool'
  import FilterUser from '@/components/FilterUser'
  import Pagination from '@/components/Pagination'
  import permission from '@/utils/permission'
  import filterHelper from '@/utils/filterHelper'

  export default {
    name: 'log_user-login',
    components: {FilterUser, Pagination},
    mounted() {
      this.getData()
    },
    data() {
      return {
        tableHeaders: null,
        allData: null,
        tableData: null,
        loading: true,
        currentPage: 1,
        totalPages: 1,
        totalCount: 1,
        pageSize: 20,
        tool: tool,
        permission: permission,
        filterTypes: null,
        filterModel: {},
      }
    },
    methods: {
      handleCurrentChange(page) {
        this.getData(page, this.pageSize)
      },
      handleSizeChange(pageSize) {
        this.getData(this.currentPage, pageSize)
      },
      handleFilterUser(filterData) {
        filterHelper.handleFilterUser(this, filterData)
      },
      handleFilter() {
        this.getData()
      },
      getData(page, pageSize) {
        let filterData = this.filterModel
        let vueObj = this
        network.getPageData(this, 'log/user-login', page, pageSize, filterData, function (response) {
          vueObj.filterTypes = response.filterTypes
          vueObj.allData = response
        })
      },
      handleExport(){
        this.$confirm(`Are you sure you want to export the current data？`, 'Hint', {//`确定要导出当前数据吗？`, '提示',
          confirmButtonText: 'confirm',//确定
          cancelButtonText: 'cancel',//取消
          type: 'warning'
        }).then(() => {
          return network.getData(`log/user-login-export`, this.filterModel)
        }).then(response => {
          this.$message({
            message: response,
            type: 'success'
          })
        }).catch(response => {

        })
      },
    }
  }

</script>

<style scoped>

</style>
