<!-- 角色管理 -->
<template>
  <view class="rolemenage">
    <view class="btn-add">
      <image
        src="../../../static/images/addicon.png"
        class="addicon"
        @tap="edit('add')"
      ></image>
    </view>
    <view class="content">

      <view class="item" v-for="(item,index) in roleList" :key="index">
        <view class="top">
          <view class="expression">
            <text class="title">角色名:</text><text class="msg">{{ item.name }}</text>
          </view>
          <view class="expression name">
            <text class="title">描述:</text><text class="msg">{{ item.description }}</text>
          </view>
        </view>
        <view class="bottom">
          <view class="btns">
            <view class="btn edit" @tap="edit(item)">编辑</view>
            <view class="btn dele" @tap="dele(item.id)">删除</view>
          </view>
        </view>
      </view>
    </view>

		<rf-loading v-if="isloading"></rf-loading>

  </view>
</template>

<script>

export default {
  name: 'rolemenage',
  components: {},
  data () {
    //这里存放数据
    return {
      isloading: false,
      roleList:[],
      mid: uni.getStorageSync('scenicMessage').id
    };
  },
  onShow () {
    this.getRoleList()
    uni.removeStorageSync('hasMenuList')
    uni.removeStorageSync('menuList')
  },
  onLoad () {
  },
  //方法集合
  methods: {
    dele(id) {
      console.log(id);
      let _self = this
      uni.showModal({
        content: '是否删除该角色？',
        success: confirmres =>{
          if (confirmres.confirm) {
            _self.isloading = true
            _self.$http.post('/mrole/delete/'+id).then(res=>{
              console.log(res);
              if (res.code === 200) {
                _self.$mHelper.toast('删除成功')
                _self.getRoleList().then( ()=>{
                  _self.isloading = false
                })
              }
            }).catch ((error)=>{
             _self.isloading = false
            })
          }
        }
      })
     
    },
    // 跳转编辑
    edit(data) {
      this.$mRouter.push({route: '/pages/index/userinfo/roleedit', query: {roledata:JSON.stringify(data)}})
    },
    // 角色列表
    async getRoleList () {
      await this.$http.get('/mrole/getList',{
        mid:this.mid
      }).then( res=>{
        if (res.code === 200 && res.msg==='OK') {
          this.roleList = res.data
        }
      })
    }
  }
}
</script>
<style lang='scss' scoped>
.rolemenage {
  padding: 24upx 32upx 0;
  .btn-add {
    position: fixed;
    right: 33upx;
    top: 20upx;
    z-index: 100;
    .addicon {
      width: 48upx;
      height: 48upx;
    }
  }
  .content{
    background-color: #f1f1f1;
    .item{
      padding: 24upx 24upx 0;
      background-color: #fff;
      border-radius: 8upx;
      .top{
        border-bottom: 1px solid #e7e7e7;
        padding: 15upx 9upx 30upx;
        .expression {
          .title{
            color: #7a7c7c;
          }
          .msg {
            margin-left: 15upx;
            color: #202020;
          }
        }
        .name {
          margin-top: 24upx;
        }
      }
      .bottom{
        padding: 17upx 0;
        .btns{
          display: flex;
          justify-content : flex-end;
          .btn {
            width: 158upx;
            height: 58upx;
            border-radius: 6upx;
            font-size: 30upx;
            color: #7a7c7c;
            border: 1px solid #e7e7e7;
            text-align: center;
            line-height: 58upx;
          }
          .dele {
            margin-left:23upx;
            background-color: #ff6a5e;
            color: #fff;
            border: none;
          }
        }
      }
    }
  }
}
</style>