<template>
<div class="system-log-list">
  <div class="ytbd-search">
    <el-form :model="searchForm" ref="searchForm" :inline="true" label-width="80px">
      <el-form-item :label="$t('page.system.systemLog.czr')" prop="nickName">
        <el-input v-model="searchForm.nickName" :placeholder="$t('form.placeholderInput')" clearable
          style="width: 120px" />
      </el-form-item>
      <el-form-item :label="$t('page.system.systemLog.czsj')">
          <el-date-picker v-model="daterange" clearable type="daterange" range-separator="-" :start-placeholder="$t('page.business.study.study.startDate')"
            :end-placeholder="$t('page.business.study.study.endDate')" value-format="yyyy-MM-dd" @change="search" style="width: 200px" />
        </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="search">{{ $t('page.business.study.study.search') }}</el-button>
        <el-button icon="el-icon-refresh" @click="reset">{{ $t('form.reset') }}</el-button>
        <el-button type="warning" plain icon="el-icon-download" @click="handleExport" v-hasPermi="['business:systemLog:operate:export']">{{$t('form.export')}}</el-button>
      </el-form-item>
    </el-form>
  </div>
  <div class="ytbd-content">
    <el-table v-loading="loading" :data="list">
      <el-table-column :label="$t('page.system.systemLog.czr')" prop="nickName" width="200" />
      <el-table-column :label="$t('page.system.systemLog.czlx')" width="200">
        <template slot-scope="scope">
          <span>{{$t('login.logIn')}}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('page.system.systemLog.czxq')">
        <template slot-scope="scope">
          <span>{{$i18n.locale === 'zh_CN' ? scope.row.msg : scope.row.msgEn}}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('page.business.archive.czsj')" align="center" prop="accessTime" width="200" />
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="searchForm.pageNum" :limit.sync="searchForm.pageSize"
      @pagination="getList" />
  </div>
</div>

</template>

<script>
import { list} from "@/api/system/logininfor"
export default {
  name: 'Dlrz',
  props: {
  },
  computed: {
  },
  data() {
    return {
      daterange:[],
      searchForm: {
        pageNum: 1,
        pageSize: 10,
        nickName: '',
        startDate:'',
        endDate:'',
      },
      loading: false,
      total: 0,
      list: [],
    }
  },
  created() {
    this.getList()
  },
  methods: {
    search() {
      this.searchForm.pageNum = 1
      this.getList()
    },
    reset() {
      this.searchForm.nickName = ''
      this.searchForm.startDate = ''
      this.searchForm.endDate = ''
      
      this.daterange = []
      this.search()
    },
    getList() {
      this.loading = true
      this.searchForm.startDate = this.daterange && this.daterange.length > 0 ? this.daterange[0] : ''
      this.searchForm.endDate = this.daterange && this.daterange.length > 1 ? this.daterange[1] : ''

      list(this.searchForm).then(response => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    handleExport(){
      this.saveSimpleLog({name:'',nameEn:'',jcmc:'登录日志导出',jcmcEn:'User Login Log Export'})
      this.searchForm.startDate = this.daterange && this.daterange.length > 0 ? this.daterange[0] : ''
      this.searchForm.endDate = this.daterange && this.daterange.length > 1 ? this.daterange[1] : ''
      this.download('system/logininfor/export', this.searchForm, `userLoginLog_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
<style lang="scss" scoped>
.system-log-list {
  .ytbd-search {
    background: #fff;
    padding: 20px;
    padding-bottom: 0;
    margin-bottom: 10px;

    .right-btn {
      text-align: right
    }
  }

  .ytbd-content {
    padding: 20px;
    background: #fff;

    .add-box {
      margin-bottom: 10px;
    }
  }
}
</style>
