wente
2023-12-19 dd5c0e7704a9ed729492b328e42d22014067b0b4
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
<template>
  <zt-dialog ref="dialog" :title="$t('user.setRole')" @confirm="formSubmit" append-to-body>
    <el-form :model="dataForm" ref="dataForm">
      <zt-tree-selector ref="tree" v-model="dataForm.roleIdList" :datas="roleList" multiple/>
    </el-form>
  </zt-dialog>
</template>
 
<script>
  export default {
    data() {
      return {
        companyId: '',
        roleList: [],
        dataForm: {
          userId: '',
          roleIdList: []
        }
      }
    },
    methods: {
      init(userId, row) {
        this.dataForm.userId = userId
        this.companyId = row.companyId
        this.getRoleList()
      },
      // 获取信息
      async getInfo() {
        let res = await this.$http.get(`/sys/user/${this.dataForm.userId}/role`)
        if (res.success) {
          this.dataForm.roleIdList = res.data
        }
      },
      // 获取角色列表
      async getRoleList() {
        let res = await this.$http.get('/sys/role/list?companyId=' + this.companyId)
        if (res.success) {
          this.roleList = res.data
        }
      },
      // 表单提交
      async formSubmit() {
        let res = await this.$http.post(`/sys/user/role`, this.dataForm)
        if (res.success) {
          this.$tip.success()
          this.$refs.dialog.close()
          this.$emit('renovate')
        }
      }
    }
  }
</script>