修改角色
/**
* @Author: 858834013@qq.com
* @Name: changeRole
* @Date: 2022-05-04
* @Desc: 修改角色
*/
<template>
<div>
<div @click="getShow">
<slot></slot>
</div>
<el-dialog
title="更改角色"
@close="getHide"
append-to-body
:visible.sync="show"
width="40%"
>
<el-form
:model="ruleForm"
ref="ruleForm"
label-width="70px"
:rules="rules"
class="demo-ruleForm"
>
<el-form-item label="角色名" prop="AdminRoleId">
<el-select v-model="ruleForm.AdminRoleId" placeholder="请选择角色">
<el-option
v-for="item in sysRoleList"
:key="item.roleId"
:label="item.roleName"
:value="item.roleId"
></el-option>
</el-select>
</el-form-item>
<div style="text-align:right;">
<el-button @click="getHide">取 消</el-button>
<el-button type="primary" @click="submitForm('ruleForm')">确定</el-button>
</div>
</el-form>
</el-dialog>
</div>
</template>
<script>
import { editAdminRole, getRoleList } from '@/api/user'
export default {
name: 'changeRole',
components: {},
props: {
id: {
type: String | Number,
default() {
return ''
}
}
},
data() {
return {
show: false,
sysRoleList: [],
ruleForm: {
AdminRoleId: ''
},
rules: {
AdminRoleId: [
{ required: true, message: '请选择角色', trigger: 'blur' }
]
}
}
},
watch: {
show() {
if (this.show) {
this.getsysRoleList()
}
}
},
mounted() {
},
methods: {
getHide() {
this.show = false
},
getShow() {
this.show = true
},
//获取角色数据
getsysRoleList() {
var that = this
let params = {
pageNum: 0,
pageSize: 0
}
getRoleList(params).then(function(res) {
if (res.code == 200) {
that.sysRoleList = res.data.list
} else {
console.log('查询失败')
}
})
},
// 修改角色
submitForm(formName) {
var that = this
that.$refs[formName].validate(valid => {
if (valid) {
let params = {
roleId: this.ruleForm.AdminRoleId,
userId: this.id
}
editAdminRole(params).then(function(res) {
that.$message({
type: 'success',
message: '修改成功'
})
that.show = false
that.$emit('getdata', 1)
})
} else {
console.log('error submit!!')
return false
}
})
}
}
}
</script>
<style lang="scss" scoped>
</style>