<template>
  <div class="detail-container">
    <!-- 筛选条件 -->
    <div class="screen-container">
      <el-form ref="screenForm" :model="screenForm" label-width="70px" size="small" 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="obj">
              <el-input v-model="screenForm.obj" 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"
                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="24" class="tr">
            <el-form-item label="">
              <el-button size="small" @click="resetScreenForm">清空</el-button>
              <el-button size="small" type="primary" @click="submitScreenForm">搜索</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <div class="mymain-container">
      <div class="btn-group clearfix">
        <div class="fl" />
        <div class="fr">
          <el-button size="small" 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="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>
      </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: '',
        obj: '',
      },
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页数量
      listTotal: 0, // 列表总数

    }
  },

  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,
        obj: this.screenForm.obj,
        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>