<template>
  <div>
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="100px"
    >
      <el-form-item label="账号" prop="operatorAccount">
        <el-input
          v-model="queryParams.operatorAccount"
          placeholder="请输入账号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户名" prop="operatorName">
        <el-input
          v-model="queryParams.operatorName"
          placeholder="请输入用户名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户id" prop="operatorId">
        <el-input
          v-model="queryParams.operatorId"
          placeholder="请输入用户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作名称" prop="operationName">
        <el-input
          v-model="queryParams.operationName"
          placeholder="请输入操作名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="时间范围" prop="value">
        <el-date-picker
          v-model="queryParams.value"
          size="small"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          range-separator="至"
          @change="timeChange"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
    
      <el-form-item style="float:right">
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          @click="handleDownload"
          >导出</el-button
        >
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="tableList"  border style="width: 100%">
      <el-table-column type="index" width="50" label="序号"/>
      <el-table-column label="操作名称" align="center" prop="operationName" />
      <el-table-column label="操作内容" align="center" prop="operationContent" :show-overflow-tooltip="true"/>
      <el-table-column label="用户id" align="center" prop="operatorId" width="100"/>
      <el-table-column label="用户名称" align="center" prop="operatorName" />
      <el-table-column label="账号" align="center" prop="operatorAccount" />
      <el-table-column label="操作时间" align="center" prop="operationTime" />
    </el-table>
    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.current"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
  </div>
</template>

<script>
import { getOperationLogList, getOperationLogExport } from "../../../common/js/home";
export default {
  name: "Operate",
  components: {},
  data() {
    return {
      loading: false,
      systemList: [],
      queryParams: {
        current: 1,
        pageSize: 10,
        operatorAccount: null,
        operatorName: null,
        operatorId: null,
        operationName: null,
        startTime: null,
        endTime: null,
        value:[],
      },
      tableList: [],
      total: 0,
    };
  },
  computed: {},
  watch: {},
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true
      getOperationLogList(this.queryParams).then(res=>{
        this.loading = false;
        this.tableList = res.data.list;
        this.total = res.data.total
      })
    },
    timeChange(val) {
      this.queryParams.startTime = val[0]
      this.queryParams.endTime = val[1]

    },
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },
    // 重置
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.startTime = ''
      this.queryParams.endTime = ''
      this.queryParams.current = 1;
      this.getList();
    },
    // 导出
    handleDownload() {
      getOperationLogExport(this.queryParams).then(res=>{
        if(res.code == '1'){
          window.open(res.data.url,'_self')
        }else{
          this.$message({
            type: "error",
            message: res.message,
          });
        }
      })
    },
  },
};
</script>

<style lang="less" scoped>
</style>
