<template>
  <div>
    <!--条件-->
    <el-form :model="listQuery" ref="queryForm" :inline="true">
      <el-form-item label="角色编码">
        <el-input
          v-model="listQuery.roleId"
          placeholder="请输入角色编码"
        ></el-input>
      </el-form-item>
      <el-form-item label="角色名称">
        <el-input
          v-model="listQuery.roleName"
          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="roleRadio" :label="scope.row.roleId"
              >&nbsp;</el-radio
            >
          </template>
        </el-table-column>
        <el-table-column type="index" label="序号" width="60"></el-table-column>
        <el-table-column label="角色编码" prop="roleId" />

        <el-table-column label="角色名称" prop="roleName" />
      </el-table>
    </div>

    <!--分页-->
    <yl-pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.current"
      :limit.sync="listQuery.size"
      @pagination="getData(query)"
    />
    <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 { getRoleData } from "@/api/system/role";
import ylPagination from "@/components/yl-pagination";

export default {
  components: {
    ylPagination
  },

  props: {
    checkRole: {
      type: Array,
      default: []
    },
    roleRadio: {
      type: String,
      default: ""
    }
  },

  data() {
    return {
      roleRadio: "",
      list: [], //列表
      total: 0, //分页
      listLoading: true,
      listQuery: {
        //条件查询
        roleName: "",
        current: 1,
        size: 10,
        roleId: ""
      }
    };
  },

  created() {
    this.getData();
  },

  methods: {
    // 关闭
    close() {
      this.$emit("rolesClose", false);
    },
    // 提交
    submit() {
      this.$emit("rolesSubmit", this.roleRadio);
    },

    //获取列表数据
    getData(query) {
      this.listLoading = true;
      getRoleData(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>
