config-role.vue 3.22 KB
Newer Older
葛齐林's avatar
葛齐林 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
<template lang='pug'>
  el-dialog( width="50%", :visible.sync="visible", append-to-body, :before-close="handleClose" )
    .title-bold(slot="title") 配置角色
    el-card(shadow="never")
      el-checkbox-group( v-model="checkedList", @change="handleCheckedCitiesChange" )
        //- el-row.my_row(:gutter="50")
          el-col(:span="6", v-for="item in roleList", :key="item.roleId")
            el-checkbox(:label="item.roleId") {{ item.roleName }}
        div(style='display: flex;flex-flow: wrap;')
          div(style="width:25%;margin-bottom: 10px;" v-for="item in roleList" :key="item.roleId")
            el-checkbox(:label="item.roleId") {{ item.roleName }}
    div(slot='footer' align='center')
      el-button(type="primary", size="medium", @click="cancel") 取 消
      el-button(type="primary", size="medium", @click="addsave" v-prevent-re-click) 保存
</template>

<script>
export default {
  data() {
    return {
      clickFlag: false,
      visible: false,
      userId: '', //用户id
      checkedList: [],
      roleList: [],
      roleIds: ''
    }
  },
  methods: {
    init(row) {
      this.clickFlag = false
      this.visible = true
      this.userId = row.user_id
      this.checkedList = []
      this.getRoleList()
    },
    // 获取权限列表
    getRoleList() {
      this.$http({
        url: this.$http.adornUrl('/sys/role/select'),
        method: 'GET',
        params: {
          stationId: localStorage.getItem('stationId')
        }
      }).then((data) => {
        if (data && data.code === 0) {
          this.roleList = data.list
        }
      })
      this.getRole()
    },
    // 获取用户权限配置
    getRole() {
      this.$http({
        url: this.$http.adornUrl('/sys/role/getUserRoleByUserId'),
        method: 'get',
        params: { userId: this.userId }
      }).then((res) => {
        this.checkedList = res.data.map((item) => {
          return item.roleId
        })
      })
    },
    handleCheckedCitiesChange(value) {
      this.roleIds = value
    },
    // 提交
    addsave() {
      this.clickFlag = true
      this.$http({
        url: this.$http.adornUrl('/sys/role/updateRoleList'),
        method: 'post',
        data: { userId: this.userId, roleIds: this.checkedList.toString(), stationId: localStorage.getItem('stationId') }
      }).then((data) => {
        if (data && data.code === 0) {
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500
          })
        }
        this.clickFlag = false
        this.handleClose()
      })
    },
    //取消
    cancel() {
      this.$confirm('确认取消?', '配置角色', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
          .then(() => {
            this.visible = false
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消退出'
            })
          })
    },
    //关闭前
    handleClose() {
      this.visible = false
    }
  }
}
</script>

<style lang="scss">
.my_row {
  .el-col {
    margin-bottom: 10px;
  }
}
</style>