<template>
|
<a-modal
|
title='请选择部门'
|
:width='450'
|
:visible='visible'
|
:closable='false'
|
:maskClosable='false'>
|
<template slot='footer'>
|
<a-button type='primary' @click='selectOk'>确认</a-button>
|
</template>
|
<a-spin :spinning="confirmLoading">
|
<a-form-model ref="form" :model='model' :rules='validatorRules'>
|
|
|
<a-form-model-item prop='selecteddeparts' :labelCol='{span:4}' :wrapperCol='{span:20}' style='margin-bottom:10px'>
|
<div>
|
<a-tooltip placement='topLeft'>
|
<template slot='title'>
|
<span>请选择登录部门</span>
|
</template>
|
<a-avatar style='backgroundColor:rgb(104, 208, 203);' icon='gold' />
|
</a-tooltip>
|
|
|
<j-select-depart @change='departChange' style='display: inline-block;margin-left: 10px;width: 240px' v-model='model.selecteddeparts'
|
:trigger-change='true' customReturnField='id' :multi='false'></j-select-depart>
|
</div>
|
</a-form-model-item>
|
|
<a-form-model-item prop='role' :labelCol="{span:4}" :wrapperCol="{span:20}" style="margin-bottom:10px" >
|
<a-tooltip placement="topLeft" >
|
<template slot="title">
|
<span> 请选择登录部门角色</span>
|
</template>
|
<a-avatar style="backgroundColor:rgb(104, 208, 203);" icon="gold" />
|
</a-tooltip>
|
|
<a-select ref='roleSelect' @change='departRoleChange' v-model='model.role' placeholder="请选择登录部门角色" style="margin-left:10px;width: 240px" allowClear>
|
<a-icon slot="suffixIcon" type="gold" />
|
<a-select-option v-for="d in departRoleList" :key="d.id" :value="d.id">
|
{{ d.roleName }}
|
</a-select-option>
|
</a-select>
|
</a-form-model-item>
|
|
<a-form-model-item v-show='false' prop='id'>
|
<a-input v-model='model.id' readOnly/>
|
</a-form-model-item>
|
|
</a-form-model>
|
</a-spin>
|
</a-modal>
|
</template>
|
|
<script>
|
|
import Vue from 'vue'
|
import { postAction, putAction } from '@/api/manage'
|
import { USER_INFO } from '@/store/mutation-types'
|
import { editUser } from '@/api/api'
|
import { getAction } from '@/api/manage'
|
export default {
|
name: 'LoginSelectDepartment',
|
watch: {
|
model: {
|
deep: true,
|
handler() {
|
console.info(this.model)
|
}
|
}
|
},
|
data() {
|
return {
|
visible: false,
|
confirmLoading: false,
|
departRoleList:[],
|
model: {
|
role:undefined
|
},
|
validatorRules: {
|
selecteddeparts: [{ required: true, message: '部门不能为空', trigger: 'blur' }],
|
role: [{ required: false, message: '部门角色不能为空', trigger: 'blur' }],
|
id: [{ required: true, message: '用户不能为空,请退出重试', trigger: 'blur' }]
|
}
|
|
}
|
},
|
|
methods: {
|
clear() {
|
this.visible = false
|
this.model.id = null
|
},
|
selectOk() {
|
|
let that = this
|
this.$refs.form.validate((valid) => {
|
if (valid) {
|
that.confirmLoading = true;
|
editUser(this.model).then((res)=>{
|
if(res.success){
|
this.addUserDepartRole()
|
}else{
|
that.$message.warning(res.message);
|
}
|
}).finally(() => {
|
that.confirmLoading = false;
|
})
|
}
|
})
|
|
},
|
show(loginResult) {
|
this.visible = true
|
this.model.id = loginResult.userInfo.id
|
},
|
departChange(departId){
|
this.model.role = undefined
|
this.getDepartRoles(departId)
|
},
|
departRoleChange(e){
|
this.model.role = e
|
},
|
addUserDepartRole(){
|
let that = this
|
that.confirmLoading = true;
|
//添加用户角色
|
postAction("/sys/sysDepartRole/deptRoleUserAdd", { newRoleId:this.model.role,userId:this.model.id }).then(res => {
|
if(res.success){
|
that.$message.success("操作成功");
|
that.$emit('success');
|
}
|
|
}) .catch(err => {
|
|
|
}).finally(() => {
|
that.confirmLoading = false;
|
that.clear();
|
});
|
},
|
getDepartRoles(departId){
|
getAction("/sys/sysDepartRole/list", { deptId:departId }).then((res) => {
|
if (res.success) {
|
this.departRoleList = res.result.records
|
} else {
|
|
}
|
})
|
}
|
|
|
}
|
}
|
</script>
|
|
<style scoped>
|
|
</style>
|