<template>
  <ai-list class="AppLoginLog">
    <template slot="title">
      <ai-title title="登录日志" isShowBottomBorder></ai-title>
    </template>
    <template slot="content">
      <ai-search-bar class="search-bar">
        <template #left>
        </template>
        <template slot="right">
          <el-input
            v-model="search.userName"
            size="small"
            v-throttle="() => { search.current = 1, getList() }"
            placeholder="请输入姓名/部门"
            clearable
            @clear="search.current = 1, search.userName = '', getList()"
            suffix-icon="iconfont iconSearch">
          </el-input>
        </template>
      </ai-search-bar>
      <ai-table
        :tableData="tableData"
        :col-configs="colConfigs"
        :total="total"
        style="margin-top: 6px; width: 100%;"
        :current.sync="search.current"
        :size.sync="search.size"
        @getList="getList">
        <el-table-column slot="user" width="140px" label="创建人" align="center">
          <template slot-scope="{ row }">
            <div class="userinfo">
              <span>{{ row.createUserName }}</span>
              <span style="color: #999">{{ row.createUserDeptName }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column slot="options" width="140px" fixed="right" label="操作" align="center">
          <template slot-scope="{ row }">
            <div class="table-options">
              <el-button type="text" @click="remindExamine(row.id)" v-if="['0'].includes(row.status)">催办</el-button>
              <el-button type="text" @click="close(row.id)" v-if="['4'].includes(row.status)">关闭</el-button>
              <el-button type="text" @click="cancel(row.id)" v-if="['0'].includes(row.status)">撤回</el-button>
              <el-button type="text" @click="toDetail(row.id)">详情</el-button>
              <el-button type="text" @click="toAdd(row.id)" v-if="['1', '3'].includes(row.status)">编辑</el-button>
            </div>
          </template>
        </el-table-column>
      </ai-table>
    </template>
  </ai-list>
</template>

<script>
  export default {
    name: 'AppLoginLog',
    label: '登录日志',

    props: {
      instance: Function,
      dict: Object
    },

    data() {
      return {
        search: {
          current: 1,
          size: 10,
          userName: ''
        },
        tableData: [],
        total: 0,
        colConfigs: [
          { prop: 'userName', label: '姓名' },
          { prop: 'departFullName', label: '部门', align: 'center' },
          { slot: 'ip', label: 'IP', align: 'center' },
          { prop: 'clientId', label: '客户端', align: 'center' },
          { prop: 'createTime', label: '登录时间', align: 'center' }
        ]
      }
    },

    created () {
      this.getList()
    },

    methods: {
      getList() {
        this.instance.post(`/app/sysuserloginlog/list`, null, {
          params: {
            ...this.search
          }
        }).then(res => {
          if (res.code == 0) {
            this.tableData = res.data.records
            this.total = res.data.total
          }
        })
      }
    }
  }
</script>

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