<template>
  <div class="detail-container">
    <!-- 筛选条件 -->
    <div class="screen-container">
      <Collapse :screen-form="screenForm">
        <template #right_btn>
          <el-button size="mini" @click="resetScreenForm">清空</el-button>
          <el-button size="mini" type="primary" @click="submitScreenForm">搜索</el-button>
        </template>
        <template #search>
          <el-form ref="screenForm" :model="screenForm" label-width="120px" size="mini" label-position="left">
            <el-row :gutter="20">
              <el-col :xs="24" :sm="12" :lg="6">
                <el-form-item label="账号" prop="account">
                  <el-input v-model="screenForm.account" placeholder="请输入账号"></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="12" :lg="6">
                <el-form-item label="姓名" prop="name">
                  <el-input v-model="screenForm.name" placeholder="请输入姓名"></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="12" :lg="6">
                <el-form-item label="登陆时间" prop="date">
                  <el-date-picker
                    v-model="screenForm.date"
                    type="datetimerange"
:default-time="['00:00:00','23:59:59']"
                    range-separator="至"
                    style="width: 100%"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="12" :lg="6">
                <el-form-item label="所在地区" prop="region">
                  <el-input v-model="screenForm.region" placeholder="请输入所在地区"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </template>
      </Collapse>
    </div>

    <div class="mymain-container">
      <div class="btn-group clearfix">
        <div class="fl" />
        <div class="fr">
          <el-button size="mini" type="primary" @click="handleExport">导出</el-button>
        </div>
      </div>

      <div class="table">
        <el-table
          v-loading="listLoading"
          :data="dataList"
          element-loading-text="Loading"
          border
          fit
          highlight-current-row
          stripe
        >
          <el-table-column align="center" label="账号" prop="moduleName" min-width="140"></el-table-column>
          <el-table-column align="center" label="姓名" prop="moduleName" min-width="140"></el-table-column>
          <el-table-column align="center" label="登录时间" prop="createTime" min-width="160"></el-table-column>
          <el-table-column align="center" label="终端类型" prop="ip" min-width="140"></el-table-column>
          <el-table-column align="center" label="浏览器/终端版本" prop="ip" min-width="140"></el-table-column>
          <el-table-column align="center" label="操作系统" prop="ip" min-width="140"></el-table-column>
          <el-table-column align="center" label="设备名称" prop="ip" min-width="140"></el-table-column>
          <el-table-column align="center" label="MAC地址" prop="ip" min-width="140"></el-table-column>
          <el-table-column align="center" label="登录IP" prop="ip" min-width="140"></el-table-column>
          <el-table-column align="center" label="所在地区" prop="ip" min-width="140"></el-table-column>
        </el-table>
      </div>

      <div class="pagination clearfix">
        <div class="fr">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="listTotal"
          >
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getOplogList } from '@/api/setting'
import { downloadFiles } from '@/utils/util'

export default {
  data() {
    return {
      dataList: null, // 列表数据
      listLoading: true, // 列表加载loading
      screenForm: {
        // 筛选表单数据
        account: '',
        name: '',
        date: [],
        region: ''
      },
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页数量
      listTotal: 0, // 列表总数
      isCollapse: true
    }
  },

  created() {
    this.getList()
  },

  methods: {
    // 查询按钮权限
    checkBtnRole(value) {
      // let btnRole = this.$route.meta.roles;
      // if(!btnRole) {return true}
      // let index = btnRole.indexOf(value);
      // return index >= 0 ? true : false;
      return true
    },

    getList() {
      this.listLoading = true

      let params = {
        account: this.screenForm.account,
        name: this.screenForm.name,
        region: this.screenForm.region,
        startTime: this.screenForm.date ? this.screenForm.date[0] : '',
        endTime: this.screenForm.date ? this.screenForm.date[1] : '',
        pageNo: this.currentPage,
        pageSize: this.pageSize
      }

      getOplogList(params).then(res => {
        this.dataList = res.data.records
        this.listTotal = res.data.total
        this.listLoading = false
      })
    },

    // 筛选后重新获取列表
    getListByScreen() {
      this.currentPage = 1
      this.getList()
    },

    // 更改每页数量
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
      this.getList()
    },

    // 更改当前页
    handleCurrentChange(val) {
      this.currentPage = val
      this.getList()
    },

    // 提交筛选表单
    submitScreenForm() {
      this.currentPage = 1
      this.getList()
    },

    // 重置筛选表单
    resetScreenForm() {
        this.$refs.screenForm.resetFields()
      this.currentPage = 1
      this.getList()
    },

    // 导出
    handleExport() {
      let screenData = {
        orderId: this.screenForm.orderId,
        status: this.screenForm.status
      }
      downloadFiles('tax/export', screenData)
    }
  }
}
</script>

<style></style>
