<template>
  <div class="role-manage">
    <div class="part-box part-box-pad">
      <el-table ref="TableList" :data="roles" border stripe>
        <el-table-column
          type="index"
          label="序号"
          width="70"
          align="center"
          :index="indexMethod"
        ></el-table-column>
        <el-table-column prop="name" label="角色名称"></el-table-column>
        <el-table-column
          class-name="action-column"
          label="操作"
          align="center"
          width="120px"
        >
          <template slot-scope="scope">
            <el-button
              class="btn-table-icon"
              type="text"
              icon="icon icon-edit"
              @click="toEdit(scope.row)"
              title="编辑"
            ></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();
    }
  }
};
</script>
