<template>
  <div>
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="100px"
    >
      <el-form-item label="账号" prop="loginName">
        <el-input
          v-model="queryParams.loginName"
          placeholder="请输入账号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="登录系统" prop="system">
        <el-select
          v-model="queryParams.system"
          placeholder="请选择登录系统"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in systemList"
            :key="dict.system"
            :label="dict.systemName"
            :value="dict.system"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="用户id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地区" prop="cityId">
        <el-cascader
          v-model="queryParams.cityId"
          placeholder="请选择省份/地市/区县"
          :options="cityList"
          @change="areaIdChange"
          clearable
          size="small"
        ></el-cascader>
      </el-form-item>
      <el-form-item label="时间范围" prop="value">
        <el-date-picker
          v-model="queryParams.value"
          size="small"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          range-separator="至"
          @change="timeChange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item style="float: right">
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          @click="handleDownload"
          >导出</el-button
        >
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="tableList" border style="width: 100%">
      <el-table-column type="index" width="50" label="序号" />
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="用户名" align="center" prop="userName" />
      <el-table-column label="账号" align="center" prop="loginName" />
      <el-table-column label="地市" align="center" prop="cityName" />
      <el-table-column label="登录系统" align="center" prop="systemName" />
      <el-table-column label="登录时间" align="center" prop="loginTime" />
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  getSystemList,
  getCityAreaList,
  getVerificationLogList,
  getVerificationLogExport,
} from "../../../common/js/home";
export default {
  name: "Login",
  components: {},
  data() {
    return {
      loading: false,
      systemList: [],
      cityList: [],
      queryParams: {
        current: 1,
        pageSize: 10,
        loginName: null,
        userName: null,
        system: null,
        userId: null,
        cityId: null,
        startTime: null,
        endTime: null,
        value: [],
      },
      tableList: [],
      total: 0,
    };
  },
  computed: {},
  watch: {},
  created() {
    this.init();
    this.getList();
  },
  methods: {
    init() {
      getSystemList().then((res) => {
        this.systemList = res.data;
      });
      getCityAreaList().then((res2) => {
        this.cityList = res2.data;
      });
    },
    getList() {
      this.loading = true;
      getVerificationLogList(this.queryParams).then(res=>{
        this.loading = false;
        this.tableList = res.data.list;
        this.total = res.data.total
      })
    },
    timeChange(val) {
      this.queryParams.startTime = val[0];
      this.queryParams.endTime = val[1];
    },
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },
    // 查询条件地区选择
    areaIdChange(val) {
      this.queryParams.cityId = val[val.length - 1];
    },
    // 重置
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.startTime = "";
      this.queryParams.endTime = "";
      this.queryParams.current = 1;
      this.getList();
    },
    // 导出
    handleDownload() {
      getVerificationLogExport(this.queryParams).then(res=>{
        if(res.code == '1'){
          window.open(res.data.url,'_self')
        }else{
          this.$message({
            type: "error",
            message: res.message,
          });
        }
      })
    },
  },
};
</script>

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