zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<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>