<template>
  <a-card :bordered="false">
    <!--导航区域-->
    <div>
      <a-tabs defaultActiveKey="1" @change="callback">
        <a-tab-pane tab="登录日志" key="1"></a-tab-pane>
        <a-tab-pane tab="操作日志" key="2"></a-tab-pane>
      </a-tabs>
    </div>

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper search_box">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :span="6">
            <a-form-item label="搜索日志">
              <a-input placeholder="请输入搜索关键词" v-model="queryParam.keyWord"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="5">
            <a-form-item label="创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-range-picker
                style="width: 210px"
                v-model="queryParam.createTimeRange"
                format="YYYY-MM-DD"
                :placeholder="['开始时间', '结束时间']"
                @change="onDateChange"
                @ok="onDateOk"
                popupClassName="picker"
                :getPopupContainer="(triggerNode) => triggerNode.parentNode"
                dropdownClassName="timeCom"
              />
            </a-form-item>
          </a-col>
          <a-col :span="7">
            <a-form-item label="操作类型">
              <j-dict-select-tag
                v-model="queryParam.operateType"
                placeholder="请选择操作类型"
                dictCode="operate_type"
              />
            </a-form-item>
          </a-col>
          <a-col :span="2">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" class="searchBut">查询</a-button>
              <a-button @click="searchReset" class="resetBut">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- table区域-begin -->
    <a-table
      ref="table"
      size="middle"
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="false"
      :loading="loading"
      @change="handleTableChange"
    >
      <div v-show="queryParam.logType == 2" slot="expandedRowRender" slot-scope="record" style="margin: 0">
        <div style="margin-bottom: 5px">
          <a-badge status="success" style="vertical-align: middle" /><span style="vertical-align: middle"
            >请求方法:{{ record.method }}</span
          >
        </div>
        <div>
          <a-badge status="processing" style="vertical-align: middle" /><span style="vertical-align: middle"
            >请求参数:{{ record.requestParam }}</span
          >
        </div>
      </div>
      <!-- 字符串超长截取省略号显示-->
      <span slot="logContent" slot-scope="text">
        <j-ellipsis :value="text" :length="40" />
      </span>
    </a-table>
    <!-- table区域-end -->
    <div class="myPagination">
      <el-pagination
        ref="elpagination"
        @current-change="changeNum"
        :current-page="ipagination.current"
        background
        :page-size="ipagination.pageSize"
        layout="prev, pager, next,jumper, slot ,total "
        :total="ipagination.total"
      >
        <el-button class="btn-sure" size="mini">确定</el-button>
      </el-pagination>
    </div>
  </a-card>
</template>

<script>
import { filterObj } from '@/utils/util'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JEllipsis from '@/components/jeecg/JEllipsis'

export default {
  name: 'LogList',
  mixins: [JeecgListMixin],
  components: {
    JEllipsis,
  },
  data() {
    return {
      description: '这是日志管理页面',
      // 查询条件
      queryParam: {
        ipInfo: '',
        createTimeRange: [],
        logType: '1',
        keyWord: '',
      },
      tabKey: '1',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '日志内容',
          align: 'left',
          dataIndex: 'logContent',
          scopedSlots: { customRender: 'logContent' },
          sorter: true,
        },
        {
          title: '操作人ID',
          dataIndex: 'userid',
          align: 'center',
          sorter: true,
        },
        {
          title: '操作人名称',
          dataIndex: 'username',
          align: 'center',
          sorter: true,
        },
        {
          title: 'IP',
          dataIndex: 'ip',
          align: 'center',
          sorter: true,
        },
        {
          title: '耗时(毫秒)',
          dataIndex: 'costTime',
          align: 'center',
          sorter: true,
        },
        {
          title: '日志类型',
          dataIndex: 'logType_dictText',
          /*customRender:function (text) {
              if(text==1){
                return "登录日志";
              }else if(text==2){
                return "操作日志";
              }else{
                return text;
              }
            },*/
          align: 'center',
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          align: 'center',
          sorter: true,
        },
      ],
      operateColumn: {
        title: '操作类型',
        dataIndex: 'operateType_dictText',
        align: 'center',
      },
      labelCol: {
        xs: { span: 1 },
        sm: { span: 2 },
      },
      wrapperCol: {
        xs: { span: 10 },
        sm: { span: 16 },
      },
      url: {
        list: '/sys/log/list',
      },
    }
  },
  methods: {
    getQueryParams() {
      var param = Object.assign({}, this.queryParam, this.isorter)
      param.field = this.getQueryField()
      param.pageNo = this.ipagination.current
      param.pageSize = this.ipagination.pageSize
      delete param.createTimeRange // 时间参数不传递后台
      if (this.superQueryParams) {
        param['superQueryParams'] = encodeURI(this.superQueryParams)
        param['superQueryMatchType'] = this.superQueryMatchType
      }
      return filterObj(param)
    },

    // 重置
    searchReset() {
      var that = this
      var logType = that.queryParam.logType
      that.queryParam = {} //清空查询区域参数
      that.queryParam.logType = logType
      that.loadData(this.ipagination.current)
    },
    // 日志类型
    callback(key) {
      // 动态添加操作类型列
      if (key == 2) {
        this.tabKey = '2'
        this.columns.splice(7, 0, this.operateColumn)
      } else if (this.columns.length == 9) {
        this.tabKey = '1'
        this.columns.splice(7, 1)
      }

      let that = this
      that.queryParam.logType = key
      that.loadData()
    },
    onDateChange: function (value, dateString) {
      console.log(dateString[0], dateString[1])
      this.queryParam.createTime_begin = dateString[0]
      this.queryParam.createTime_end = dateString[1]
    },
    onDateOk(value) {
      console.log(value)
    },
    changeNum(val) {
      this.ipagination.current = val
      this.loadData()
    },
  },
}
</script>
<style scoped lang="less">
@import '~@assets/less/common.less';
@import '~@assets/less/shaDow.less';
@import '~@assets/less/tableCommon.less';
// ::v-deep .ant-table-row-expand-icon {
//   &:hover,&:focus {
    
//   }
// }
// 搜索框
.search_box {
  ::v-deep .ant-input-group .ant-input {
    height: 38px;
    line-height: 38px;
    font-size: 14px;
    border-radius: 2px;
  }

  .searchBut {
    
    border-radius: 0px 2px 2px 0px;
    opacity: 1;
    

    height: 38px;
    line-height: 38px;
    font-size: 14px;
  }

  .resetBut {
    width: 60px;
    height: 38px;
    line-height: 38px;
    background: #dbdbdb;
    border-radius: 2px;
    color: #000;
    opacity: 1;
    padding: 0;
    border: 1px solid #b6b6b6;
  }
}

// ::v-deep
//   .ant-table-thead
//   > tr
//   > th
//   .ant-table-column-sorter
//   .ant-table-column-sorter-inner
//   .ant-table-column-sorter-up.on,
// ::v-deep
//   .ant-table-thead
//   > tr
//   > th
//   .ant-table-column-sorter
//   .ant-table-column-sorter-inner
//   .ant-table-column-sorter-down.on {
  
// }

// 下拉框
::v-deep.ant-select {
  .ant-select-selection--single {
    height: 38px;

    .ant-select-selection__rendered {
      line-height: 38px;
    }
  }

  // .ant-select-dropdown-menu-item-active:not(.ant-select-dropdown-menu-item-disabled) {
    
  // }
}

::v-deep.table-page-search-wrapper {
  .ant-form-item,
  .table-page-search-submitButtons {
    margin-bottom: 12px;

    & > button:first-child {
      margin-right: 20px;
    }
  }
}

.table-page-search-wrapper ::v-deep.search_box .ant-form-item-children {
  display: flex;
  align-items: center;
}

.search_box .ant-form-inline .ant-form-item > .ant-form-item-label {
  padding-right: 8px;
}

.ant-alert-info {
  background-color: #fff;
  border: none;

  .clearBut {
    height: 38px;
    background: #ffffff;
    border-radius: 2px 2px 2px 2px;
    opacity: 1;
    
    letter-spacing: 0px;
    padding: 0 16px;
    margin-left: 6px;
  }
}

.ant-alert {
  padding: 0;
}

// /deep/.ant-tabs-nav .ant-tabs-tab-active {
  
// }

// /deep/.ant-tabs-ink-bar {
  
// }

// ::v-deep .ant-table-row-expand-icon:hover {
  
// }

// ::v-deep .ant-table-row-expand-icon:focus {
  

// }

::v-deep .ant-dropdown-menu-item:hover {
  background: #f2f5f965;
}

// 日期选择
/deep/.ant-col .ant-input {
  height: 38px;
}

// /deep/.ant-calendar-today .ant-calendar-date {
  
  
// }

// 分页器
.myPagination {
  margin-top: 40px;
  display: flex;
  justify-content: end;

  ::v-deep .el-pagination {
    font-weight: 600;

    .btn-sure {
      background: #dbdbdb;
      border-radius: 2px 2px 2px 2px;
      opacity: 1;
      border: 1px solid #b6b6b6;
      padding: 0;
      color: #000;
      margin: 0 20px 0 10px;
      width: 50px;
    }

    .el-select .el-input .el-input__inner {
      color: #000;
      font-size: 14px;
      padding-right: 17px;
      font-weight: 400;
      border-radius: 2px;
    }

    .el-pager li {
      font-size: 16px;
      color: #888888;
      width: 34px;

      &:hover {
        opacity: 0.9;
      }
    }

    .el-pagination span:not([class*='suffix']) {
      font-size: 14px;
      color: #888888;
    }

    .el-pager li:not(.disabled).active {
      color: #fff;
    }
  }

  .ant-pagination {
    color: #888888;
  }

  ::v-deep .ant-select-selection--single {
    height: 28px !important;
  }

  ::v-deep .ant-select-selection__rendered {
    line-height: 28px !important;
  }

  ::v-deep .ant-pagination.mini .ant-pagination-options-quick-jumper input {
    height: 28px;
  }

  ::v-deep .ant-pagination.mini .ant-pagination-item {
    font-size: 16px;
    height: 28px;
    line-height: 28px;
    width: 34px;
  }
}

::v-deep ::-webkit-scrollbar-thumb {
  
  border-radius: 9px 9px 9px 9px;
}
</style>