<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="手机号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" v-loading="loading">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <span style="color: red">请输入手机号可以查询单日的最近10条原始登录记录，请勿一直查询，查询比较慢</span>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ipRecordList" @selection-change="handleSelectionChange">
      <el-table-column label="详情" align="left" prop="info" />
    </el-table>
  </div>
</template>

<script>
import {listLoginLog} from "@/api/cai/loginLog";

export default {
  name: "IpRecord",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // ip访问记录表格数据
      ipRecordList: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        mobile: undefined
      },
    };
  },
  created() {
  },
  methods: {
    /** 查询ip访问记录列表 */
    getList() {
      this.loading = true;
      listLoginLog(this.queryParams).then(response => {
        this.ipRecordList = response.data;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
  }
};
</script>
