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
  | <template> 
 |      <GlobalWindow 
 |          :visible.sync="visible" 
 |          :confirm-working="isWorking" 
 |          width="582px" 
 |          title="配置用户角色" 
 |          @confirm="confirm" 
 |      > 
 |          <p class="tip" v-if="user != null">为用户 <em>{{user.realname}}</em> 分配企业</p> 
 |          <el-transfer 
 |              v-if="company" 
 |              v-model="selectedIds" 
 |              :titles="['未分配企业', '已分配企业']" 
 |              :props="{ 
 |                  key: 'id', 
 |                  label: 'name' 
 |              }" 
 |              :data="company"> 
 |          </el-transfer> 
 |      </GlobalWindow> 
 |  </template> 
 |    
 |  <script> 
 |      import BasePage from '@/components/base/BasePage' 
 |      import GlobalWindow from '@/components/common/GlobalWindow' 
 |      import { allForFp } from '@/api/business/company' 
 |      import { create } from '@/api/business/companyPermission' 
 |      export default { 
 |          name: 'allocationEnterprises', 
 |          extends: BasePage, 
 |          components: { GlobalWindow }, 
 |          data () { 
 |              return { 
 |                  visible: false, 
 |                  isWorking: false, 
 |                  // 用户 
 |                  user: null, 
 |                  // 企业列表 
 |                  company: null, 
 |                  // 已选中的角色ID 
 |                  selectedIds: [] 
 |              } 
 |          }, 
 |          methods: { 
 |              open (title, target) { 
 |                  this.selectedIds = [] 
 |                  this.visible = true 
 |                  this.title = title 
 |                  this.user = target 
 |                allForFp({ userId: target.id }) 
 |                      .then(res => { 
 |                          this.company = res.map(r => { 
 |                              return { 
 |                                  name: r.name, 
 |                                  id: r.id 
 |                              } 
 |                          }) 
 |                          res.forEach(item => { 
 |                              if (item.hasPerimission === 1) { 
 |                                  this.selectedIds.push(item.id) 
 |                              } 
 |                          }) 
 |                      }) 
 |              }, 
 |              // 确认选择角色 
 |              confirm () { 
 |                  if (this.isWorking) { 
 |                      return 
 |                  } 
 |                  this.isWorking = true 
 |                  create({ 
 |                      userId: this.user.id, 
 |                      companyIdList: this.selectedIds 
 |                  }) 
 |                      .then(() => { 
 |                          this.$tip.apiSuccess('企业分配成功,用户重新登录后生效') 
 |                          this.visible = false 
 |                          this.$emit('success') 
 |                      }) 
 |                      .catch(e => { 
 |                          this.$tip.apiFailed(e) 
 |                      }) 
 |                      .finally(() => { 
 |                          this.isWorking = false 
 |                      }) 
 |              }, 
 |              // 关闭 
 |              close () { 
 |                  this.$emit('update:visible', false) 
 |              } 
 |          } 
 |      } 
 |  </script> 
 |    
 |  <style scoped lang="scss"> 
 |      @import "@/assets/style/variables.scss"; 
 |      // 角色配置 
 |      .global-window { 
 |          .tip { 
 |              em { 
 |                  font-style: normal; 
 |                  color: $primary-color; 
 |                  font-weight: bold; 
 |              } 
 |          } 
 |          .tip-warn { 
 |              margin: 4px 0 12px 0; 
 |              font-size: 12px; 
 |              color: #999; 
 |              i { 
 |                  color: orange; 
 |                  margin-right: 4px; 
 |                  font-size: 14px; 
 |                  position: relative; 
 |                  top: 1px; 
 |              } 
 |          } 
 |      } 
 |  </style> 
 |  
  |