shikeying
2023-04-07 c192f834c4e092bc7c0f2722c343c25c1be619ab
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
<template>
  <win2 :title="title" @close="close">
    <el-form :model="formData" label-width="120px">
      <el-form-item label="已授权用户:">
        <span v-for="(item ,idx) in formData.userNames" :key="idx">
          {{ idx == 0?'':'、' }}
          <el-tag type="success">
            {{ item }}
          </el-tag>
        </span>
      </el-form-item>
      <el-form-item label="授权用户:">
        <el-button size="mini" type="primary" @click="authShow=true">选择...</el-button>
      </el-form-item>
    </el-form>
    <div slot="footer" align="center" class="dialog-footer">
      <my-button-v2 name="取消" site="form" @click="close" />
      <my-button-v2 name="保存" site="form" @click="save" />
    </div>
    <!--用户选择弹窗-->
    <auth v-if="authShow" :setting="setting" @close="authShow=false" @saveUser="saveUser" />
  </win2>
</template>
 
<script>
import win2 from '@/views/components/win2'
import myButtonV2 from '@/views/components/myButtonV2'
import { getAuthUser, saveUserAuth } from '@/api/common.js'
import auth from './auth'
export default {
  components: { win2, myButtonV2, auth },
  props: {
    setting: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      title: '授权用户',
      formData: {
        userIds: [],
        userNames: []
      },
      authShow: false
    }
  },
  created() {
    this.getInfo()
  },
  methods: {
    getInfo() {
      if (this.setting.businessType && this.setting.businessId) {
        getAuthUser(this.setting).then(res => {
          const data = res.data
          data.forEach(item => {
            this.formData.userIds.push(item.userId)
            this.formData.userNames.push(item.userName)
          })
        })
      }
    },
    saveUser(checkedNodes) {
      const userIds = []
      const userNames = []
      checkedNodes.forEach(item => {
        userIds.push(item.id)
        userNames.push(item.name)
      })
      this.formData.userIds = userIds
      this.formData.userNames = userNames
    },
    close() {
      this.$emit('close')
    },
    save() {
      const params = {
        businessType: this.setting.businessType,
        businessId: this.setting.businessId,
        userIds: this.formData.userIds.join(',')
      }
      if (!params.businessType || !params.businessId) {
        this.$message.error('缺少业务ID,业务类型。')
        return false
      }
      saveUserAuth(params).then(response => {
        debugger
        if (response.code == 10000 && response.data > 0) {
          this.$message.success('保存成功!')
          this.close()
        } else {
          this.$message.error(response.description || '保存失败!')
        }
      })
    }
  }
}
</script>