<template>
  <div>
    <!--条件-->
    <el-form :model="listQuery" ref="queryForm" :inline="true">
      <el-form-item label="用户编码">
        <el-input
          v-model="listQuery.loginId"
          placeholder="请输入用户编码"
        ></el-input>
      </el-form-item>
      <el-form-item label="用户名称">
        <el-input
          v-model="listQuery.userName"
          placeholder="请输入用户名称"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getData(true)"
          >查询
        </el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <div>
      <el-table
        ref="multipleTable"
        row-key="id"
        v-loading="listLoading"
        element-loading-text="加载中"
        :data="list"
        fit
        stripe
      >
        <template slot="empty">
          <img src="@/assets/nopage.png" alt />
          <p>暂无数据</p>
        </template>
        <el-table-column width="50">
          <template slot-scope="scope">
            <el-radio v-model="userRadio" :label="scope.row.loginId"
              >&nbsp;</el-radio
            >
          </template>
        </el-table-column>
        <el-table-column type="index" label="序号" width="60"></el-table-column>
        <el-table-column label="用户编码" prop="loginId" />
        <el-table-column label="用户名称" prop="userName" />
      </el-table>
    </div>

    <!--分页-->
    <yl-pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.current"
      :limit.sync="listQuery.size"
      @pagination="getData(true)"
    />

    <div slot="footer" class="dialog-footer" style="text-align: right">
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="submit">确定</el-button>
    </div>
  </div>
</template>

<script>
import { getUserData } from "@/api/system/users";
import ylPagination from "@/components/yl-pagination";

export default {
  components: {
    ylPagination
  },
  props: {
    checkUser: {
      type: Array,
      default: []
    },
    userRadio: {
      type: String,
      default: ""
    }
  },

  watch: {},

  data() {
    return {
      userRadio: "",
      list: [], //列表
      total: 0, //分页
      listLoading: false,
      listQuery: {
        //条件查询
        userName: "",
        current: 1,
        size: 10,
        loginId: ""
      }
    };
  },
  created() {
    this.getData();
  },
  methods: {
    // 关闭
    close() {
      this.$emit("usersClose", false);
    },

    // 提交
    submit() {
      this.$emit("usersSubmit", this.userRadio);
    },

    //获取列表数据
    getData(query) {
      this.listLoading = true;
      getUserData(this.listQuery)
        .then((response) => {
          this.list = response.data.records;
          this.total = response.data.total;
          this.listLoading = false;
        })
        .catch((err) => {
          this.listLoading = false;
        });
    }
  }
};
</script>

<style scoped>
</style>
