<!--系统日志-->
<template>
  <div class="app-container systemLogs">
    <div class="page-container systemLogsPage" v-if="pageType == 1">
      <div class="title-max-big-box">
        <div :class="queryParams.logType == 1?'checkTitle':''" @click="titleButton(1)">
          <p>登录日志</p>
          <p></p>
        </div>
        <div :class="queryParams.logType == 2?'checkTitle':''" @click="titleButton(2)">
          <p>操作日志</p>
          <p></p>
        </div>
      </div>
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm" :inline="true">
          <!--<el-form-item label="日志类型" prop="logType" label-width="90px">-->
            <!--<el-select v-model="queryParams.logType" clearable placeholder="请选择" style="width: 200px">-->
              <!--<el-option label="登录" :value="1"></el-option>-->
              <!--<el-option label="操作" :value="2"></el-option>-->
            <!--</el-select>-->
          <!--</el-form-item>-->
          <el-form-item label="" prop="ipAddr" label-width="60px">
            <el-input
              maxLength="30"
              v-model="queryParams.ipAddr"
              placeholder="请输入请求IP"
              clearable
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="state">
            <el-select v-model="queryParams.state" clearable placeholder="请选择状态" style="width: 200px">
              <el-option label="成功" :value="true"></el-option>
              <el-option label="失败" :value="false"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="dateRange">
            <el-date-picker
              :clearable="false"
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="请求时间"
              end-placeholder="请求时间"
            ></el-date-picker>
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="tableList" ref="multipleTable">
          <el-table-column label="标题" align="center" prop="title" show-overflow-tooltip width="180"/>
          <el-table-column label="操作类型" align="center" prop="businessType" show-overflow-tooltip/>
          <el-table-column label="请求IP" align="center" prop="ipAddr" show-overflow-tooltip width="120"/>
          <el-table-column label="IP所属地" align="center" prop="ipDesc" show-overflow-tooltip width="110"/>
          <el-table-column label="用户代理" align="center" prop="userAgent" show-overflow-tooltip width="200"/>
          <el-table-column label="请求接口" align="center" prop="reqUri" show-overflow-tooltip width="200"/>
          <el-table-column label="请求时间" align="center" prop="reqTime" show-overflow-tooltip width="170">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.reqTime,"{y}-{m}-{d} {h}:{i}:{s}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="耗时（ms）" align="center" prop="costTime" show-overflow-tooltip width="100">
            <template slot-scope="scope">
              <span>{{ scope.row.costTime }}ms</span>
            </template>
          </el-table-column>
          <el-table-column label="状态" align="center" prop="state" show-overflow-tooltip width="80">
            <template slot-scope="scope">
              {{scope.row.state?'成功':'失败'}}
            </template>
          </el-table-column>
          <el-table-column label="操作人" align="center" prop="operator" show-overflow-tooltip width="110"/>
          <el-table-column label="操作" align="center" prop="deptName" width="170" v-if="tableButtonType">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="tableButton(scope.row)"
                   v-hasPermiRouter="['system:log:detail']"
                >详情</p>
                <p class="table-button-null"></p>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <infoPage v-if="pageType == 2" :propsData="propsData"></infoPage>
  </div>
</template>

<script>
  import { syslogList,syslogDetail } from "@/api/serviceCenter/index";
  import infoPage from "./infoPage.vue";
  export default {
    name: 'systemLogs',
    components: {
      infoPage
    },
    data(){
      return{
        tableButtonType:this.hasPermiDom(['system:log:detail']),
        pageType:1,
        loading:false,
        dateRange:[],
        queryParams:{
          page:1,
          pageSize:20,
          logType:"1",
          ipAddr:"",
          state:"",
        },
        tableList:[],
        total:0,
        propsData:{},
      }
    },
    created(){

    },
    mounted(){
      this.getList();
    },
    methods:{
      titleButton(type){
        if(type != this.queryParams.logType){
          this.$set(this,'dateRange',[])
          this.$set(this,'queryParams',{
            page:1,
            pageSize:20,
            logType:type,
            ipAddr:"",
            state:"",
          });
          this.getList();
        }
      },
      goPage(type){
        if(this.pageType!=type){
          this.$set(this,'pageType',type)
          this.getList();
        }
      },
      //详情按钮
      tableButton(row){
        syslogDetail({logId:row.logId}).then(response => {
          this.$set(this,'propsData',response.data);
          this.$set(this,'pageType',2);
        });
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          logType:"1",
          state:"",
          ipAddr:"",
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        if(this.dateRange[0]){
          obj.startTime = this.dateRange[0]+'T00:00:00'
          obj.endTime = this.dateRange[1]+'T23:59:59'
        }else{
          obj.startTime = "";
          obj.endTime = "";
        }
        syslogList(obj).then(response => {
          this.$set(this,'loading',false);
          this.$set(this,'tableList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
    }
  }
</script>

<style scoped lang="scss">
  .systemLogs{
    .systemLogsPage{
      .title-max-big-box{
        border-bottom:1px solid #dedede;
        display: flex;
        div{
          width:80px;
          height:80px;
          margin-left:70px;
          cursor: pointer;
          p{
            line-height:76px;
          }
          p:nth-child(1){
            text-align: center;
          }
          p:nth-child(2){
            width:80px;
            height:4px;
            border-radius:2px;
          }
        }
        .checkTitle{
          p:nth-child(1){
            color:#0045AF;
          }
          p:nth-child(2){
            background-color: #0045AF;
          }
        }
      }
      .page-form-title-box{
        border:none;
      }
      .page-content-box{
        padding-top:0;
      }
    }
  }
</style>
