<template>
  <div class="role" v-if="tool.checkAuth($route.name,'read')">
    <div class="top">
      <p>角色管理</p>
      <el-button type="primary" @click="addRole()" v-if="tool.checkAuth($route.name,'insert')">
        <img src="@/assets/add.png" alt="" style="vertical-align:middle">
        新建角色
      </el-button>
    </div>
    <role-item :roleData="roleData">
      <template v-slot:icon="scope">
        <img src="@/assets/edit.png" alt="" @click="roleEdit(scope.data)" v-if="tool.checkAuth($route.name,'update')">
      </template>
      <template v-slot:remove="scope">
        <remove-role :roleData="scope.data" v-if="tool.checkAuth($route.name,'delete')"></remove-role>
      </template>
    </role-item>
  </div>
</template>

<script>
import RoleItem from '@/SManagement/user/role-manage/components/RoleItem'
import removeRole from '@/SManagement/user/role-manage/components/removeRole'
export default {
  name: 'RoleManage',
  data () {
    return {
      param: {
        "accesstoken": "86cf5a6b5314094f4b412da2b0445ac1",
        "classname": "sale.role.role",
        "method": "query_roleList",
        "content": {
          "pageNumber": 1,
          "pageSize": 10,
          "where": {
            "condition": ""
          }
        }
      },
      roleData: []
    };
  },
  props: [],
  components: {
    RoleItem,
    removeRole
  },
  computed: {
  },
  watch: {
  },
  created () {
    this.getRoleData()
  },
  methods: {
    getRoleData () {
      this.$api.requested(this.param).then(res => {
        this.roleData = res.data
        console.log(this.roleData);
      })
    },
    //角色编辑
    roleEdit (data) {
      window.sessionStorage.setItem('currentEditRole',JSON.stringify(data))
      this.$router.push({
        name: 'roleEdit',
        params: {
          data
        }
      })
    },
    addRole () {
      window.sessionStorage.setItem('currentEditRole',0)
      window.sessionStorage.setItem('currentPath','/role_managent')
      this.$router.push({
        path:'role_edit',
        query: {
          id:0
        }
      })
    },
    //删除未提交角色角色
    // deleteNoRole () {
    //   let result = this.roleData
    //     .filter(item => item.remarks == false && item.rolename == false)
    //     .map(item => item.roleid)
    //   if(!result) return 
    //   result.forEach(item => {
    //     this.$api.requested({
    //       "classname": "sale.role.role",
    //       "method": "delete_role",
    //       "content": {
    //         "roleid": item
    //       }
    //     }).then(res => {
    //       if(res.code == 1) {
    //         this.getRoleData()
    //         console.log(111);
            
    //       }
    //     })
    //   })

    // }
  },
};
</script>

<style scoped>
*{
  box-sizing: border-box;
}
.role {
  width: 100%;
  min-height: 100%;
  background: #ffffff;
}
.role .top {
  display: flex;
  justify-content: space-between;
  padding: 16px 16px 9px 0;
  margin-left: 16px;
  border-bottom: 1px solid #dddddd;
  align-items: center;
}
.role .top p {
  font-size: 16px;
  font-weight: bold;
  color: #333333;
}
</style>
