<template lang="pug">
          div.infopage()
            el-form(:inline='true', :model='dataForm', size='mini', @keyup.enter.native='getDataList()')
              el-row
                el-col(:span='6')
                  el-form-item(label="用户名:")
                      el-input(v-model='dataForm.username', placeholder='用户名', clearable='')
                //- el-col(:span='6')
                //-   el-form-item(label="主办方:")
                //-     el-select(v-model="dataForm.orgId" placeholder="请选择"  clearable)
                //-       el-option(v-for="(item,index) in sysOrgList" :key="index" :label="item.name" :value="item.orgId")
                el-col(:span='12')
                  el-form-item(label="操作时间:")
                      el-date-picker(v-model="dataForm.startTime"  type="datetime" placeholder="选择日期时间" ,style='width:175px;')
                  el-form-item(label="至" label-width='25px' style='padding-left:10px;')
                      el-date-picker(v-model="dataForm.endTime"  type="datetime" placeholder="选择日期时间",style='width:175px;')
                el-col(:span='24' style='padding-bottom:15px;')
                      el-button(@click='getDataList()' ,type='primary',icon='el-icon-search' style="float:right;") 查询
            el-table(:data='dataList', v-loading='dataListLoading',
                  :header-cell-style="{background:'rgb(8, 109, 177)',color:'#fff'}"
                  :cell-style="{background:'rgb(2, 79, 131)',color:'#fff'}"
                @selection-change='selectionChangeHandle', style='width: 100%;')
                el-table-column(prop='username', header-align='center', align='center', label='用户名')
                //- el-table-column(prop='orgName', header-align='center', align='center', label='主办方')
                el-table-column(prop='createDate', header-align='center', align='center', label='操作时间')
                el-table-column(prop='operation', header-align='center', align='center', label='操作纪录')
            el-pagination(@size-change='sizeChangeHandle', @current-change='currentChangeHandle', :current-page='pageIndex', :page-sizes='[10, 20, 50, 100]', :page-size='pageSize', :total='totalPage', layout='total, sizes, prev, pager, next, jumper')
</template>

<script>
export default {
  data () {
    return {
      dataForm: {
        username: '',
        orgId: '',
        startTime: '',
        endTime: ''
      },
      sysOrgList: [],
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false
    }
  },
  watch: {
    totalPage() { //注意这个函数的名字必须和你监听data中的属性的名字一样，这样才能当你data中的属性发生变化时，触发这个函数
      let pages = Math.ceil(this.totalPage / this.pageSize)//新数据总页数
      //总页数小于当前页数则重新加载列表数据
      if (pages < this.pageIndex) {
          this.pageIndex = pages || 1
          this.getDataList()//获取表格数据的方法
      }
    }
  },
  created () {
    this.getDataList()
    this.initOrg()
  },
  methods: {
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/sys/log/list'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'limit': this.pageSize,
          'username': this.dataForm.username,
          'orgId': this.dataForm.orgId,
          'startTime': this.dataForm.startTime,
          'endTime': this.dataForm.endTime
        })
      }).then((data) => {
        //console.log('data', data)
        if (data && data.code === 0) {
          this.dataList = data.page.records
          this.totalPage = data.page.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    initOrg () {
        this.$http({
        url: this.$http.adornUrl('/sysOrg/list'),
        method: 'get',
        params: this.$http.adornParams()
      }).then((data) => {
        this.sysOrgList = data && data.code === 0 ? data.list : []
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    }
  }
}
</script>
<style lang='scss' scoped>
  .infopage{
    margin: 24px;
    padding:24px;
    height: 750px;
    background-color: rgba(7, 58, 116, 0.596);
    .el-button{
      background-color: rgb(2, 79, 131);
      color: #fff;
      border-color: rgb(2, 79, 131);
    }

  }
</style>
<style lang='scss'>
 .infopage{
   .el-input__inner{
      // background-color: rgba(7, 58, 116, 0.596) !important;
      border-color: rgb(2, 79, 131);
      // border-color: rgb(8, 109, 177);
      color: #fff;
    }
    .el-range-input {
      // background-color: rgba(7, 58, 116, 0.596) !important;
      color: #fff
    }
    .el-table{
      // background-color: rgba(7, 58, 116, 0.596) !important;
    }
    .el-range-separator{
      color: #fff
    }
    .el-form-item__label {
      color: #fff;
    }
    .el-dialog {
      background-color: rgb(30, 89, 139) !important;
      color: #fff;
      border-color: rgb(2, 79, 131);
    }
 }
  </style>
