MrShi
2024-11-22 ba5f8ce99b414a89d1e21a650321bf373773e7ae
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
<template>
    <GlobalWindow
        class="menu-config-dialog"
        :visible.sync="visible"
        :confirm-working="isWorking"
        width="800px"
        title="分配服务企业"
        @confirm="confirm"
    >
        <p class="tip">为用户 <em>{{form.name || ''}}</em> 分配企业</p>
        <el-transfer
            :titles="['未分配企业', '已分配企业']"
            v-model="form.companyIds"
            :data="enterprise" />
    </GlobalWindow>
</template>
 
<script>
  import GlobalWindow from '@/components/common/GlobalWindow'
  import { allForFp } from '@/api/business/company'
  import { auth, getById } from '@/api/business/customerService'
  import { mapState } from 'vuex'
  export default {
    name: 'allocateEnterprises',
    components: { GlobalWindow },
    computed: {
      ...mapState(['userInfo'])
    },
    data () {
      return {
        visible: false,
        isWorking: false,
        form: {
          id: null,
          name: '',
          companyIds: []
        },
        enterprise: []
      }
    },
    methods: {
      open (title, id) {
        this.title = title
        this.visible = true
        this.getCompany()
        for (const key in this.form) {
          this.form[key] = ''
        }
        getById(id)
          .then(res => {
            this.form.id = res.id
            this.form.name = res.name
            this.form.companyIds = res.customerCompanyList.map(item => item.companyId)
          })
      },
      getCompany() {
        allForFp({ type: this.userInfo.type })
          .then(res => {
            this.enterprise = res.map(item => {
              return {
                key: item.id,
                label: item.name
              }
            })
          })
      },
      confirm() {
        let obj = {
          id: this.form.id,
          customerCompanyList: []
        }
        if (this.form.companyIds.length > 0) {
          obj.customerCompanyList = this.form.companyIds.map(item => {
            return {
              companyId: item
            }
          })
        }
        this.isWorking = true
        auth(obj)
          .then(() => {
            this.visible = false
            this.$tip.apiSuccess('操作成功')
            this.$emit('success')
          })
          .catch(e => {
            this.$tip.apiFailed(e)
          })
          .finally(() => {
            this.isWorking = false
          })
      }
    }
  }
</script>
<style>
    .el-transfer-panel {
        width: 300px !important;
    }
</style>
<style scoped lang="scss">
    @import "@/assets/style/variables.scss";
    .global-window {
        .tip {
            margin-bottom: 12px;
            em {
                font-style: normal;
                color: $primary-color;
                font-weight: bold;
            }
        }
    }
</style>