<template>
  <div>
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="角色名称" prop="roleName">
        <el-input
          v-model="queryParams.roleName"
          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 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-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="角色名称" align="center" prop="roleName" />
      <el-table-column label="系统" align="center" prop="systemName" />
      <el-table-column label="系统id" align="center" prop="system" />
      <el-table-column label="角色描述" align="center" prop="roleDescription" :show-overflow-tooltip="true"/>
    </el-table>
    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.current"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
  </div>
</template>

<script>
import { getSystemList, getRoleList } from "../../../common/js/home";
export default {
  name: "Role",
  components: {},
  data() {
    return {
      loading: false,
      systemList: [],
      queryParams: {
        current: 1,
        pageSize: 10,
        roleName: null,
        system: null,
      },
      tableList: [],
      total: 0,
    };
  },
  computed: {},
  watch: {},
  created() {
    console.log(this.$router);
    this.init();
    this.getList();
  },
  methods: {
    init() {
      getSystemList().then(res=>{
        this.systemList = res.data
      })
    },
    getList() {
      this.loading = true;
      getRoleList(this.queryParams).then(res=>{
        this.loading = false;
        this.tableList = res.data.list;
        this.total = res.data.total
      })
    },
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },
    // 重置
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.current = 1;
      this.getList()
    },
  },
};
</script>

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