<template>
  <div class="role-manage">
    <div class="part-box part-box-pad part-box-flex">
      <div></div>
      <el-button
        type="primary"
        icon="el-icon-circle-plus-outline"
        @click="toAdd"
        >添加角色</el-button
      >
    </div>
    <div class="part-box part-box-pad">
      <el-table ref="TableList" :data="roles">
        <el-table-column
          type="index"
          label="序号"
          width="70"
          :index="indexMethod"
        ></el-table-column>
        <el-table-column prop="name" label="角色名称"></el-table-column>
        <el-table-column class-name="action-column" label="操作" width="120px">
          <template slot-scope="scope">
            <el-button
              v-if="!scope.row.defaultRole"
              class="btn-primary"
              type="text"
              @click="toEdit(scope.row)"
              >编辑</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- ModifySystemRole -->
    <modify-system-role
      ref="ModifySystemRole"
      :instance="curRole"
      @modified="getList"
    ></modify-system-role>
  </div>
</template>

<script>
import { ABLE_TYPE } from "@/constants/enumerate";
import { userRoleListPage } from "../api";
import ModifySystemRole from "../components/ModifySystemRole";

export default {
  name: "role-manage",
  components: {
    ModifySystemRole
  },
  data() {
    return {
      roles: [],
      curRole: {},
      ABLE_TYPE,
      ROLE_TYPE: {}
    };
  },
  created() {
    this.toPage(1);
  },
  methods: {
    async getList() {
      const data = await userRoleListPage();
      this.roles = data || [];
      this.roles = this.roles.filter(item => item.type !== "ADMIN");
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    toEdit(row) {
      this.curRole = row;
      this.$refs.ModifySystemRole.open();
    },
    toAdd() {
      this.curRole = {};
      this.$refs.ModifySystemRole.open();
    }
  }
};
</script>
