create.vue
7.24 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<template>
<div class="role-create-page">
<div class="top_title_widget">
<span class="title">{{ pageName }}</span>
</div>
<div class="main_widget">
<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
<el-form-item v-if="pageType == 'create'" label="所属商户" prop="merchantId">
<el-select size="small" style="width: 40%" v-model="ruleForm.merchantId" :filter-method="filterList" clearable filterable placeholder="请选择" @change="selectMerchant">
<el-option v-for="item in list" :key="item.id" :label="item.merchantName" :value="item.id"></el-option>
</el-select>
</el-form-item>
<el-form-item label="所属商户" prop="merchantName" v-if="pageType == 'edit'">
<el-input disabled style="width: 40%" v-model="ruleForm.merchantName"></el-input>
</el-form-item>
<el-form-item label="角色名称" prop="roleName">
<el-input style="width: 40%" v-model="ruleForm.roleName"></el-input>
</el-form-item>
<el-form-item label="角色说明" prop="roleDesc">
<el-input style="width: 40%" v-model="ruleForm.roleDesc"></el-input>
</el-form-item>
<el-form-item label="角色权限" prop="roleRoot">
<div class="custom_element">
<template v-for="(item, index) in accountList">
<div :key="index" class="wrap">
<AutoButton @getBtnStatus="selectCurAccount(item, index)" :typeStatus="item.select" :btnLabel="item.accounttypeName"></AutoButton>
</div>
</template>
</div>
</el-form-item>
</el-form>
<SelectProduct ref="productFrom" :roleType="true" :parentId="41712" :accountlevel="2" :pId="41713"></SelectProduct>
</div>
<div style="height: 84px"></div>
<div class="fixed_bottom">
<el-button v-if="pageType == 'create'" type="primary" @click="toCreateRole(1)">草稿</el-button>
<div class="wrap_driver">
<el-button type="primary" @click="toCreateRole(0)">确定</el-button>
</div>
<el-button type="primary" @click="toBack">取消</el-button>
</div>
</div>
</template>
<script>
import AutoButton from '../../components/auto-button/index.vue'
import SelectProduct from '../account/components/selectProduct.vue'
export default {
name: '',
components: {
AutoButton,
SelectProduct
},
data() {
return {
ruleForm: {
merchantId: '',
roleName: '',
roleDesc: ''
},
rules: {
roleName: [{ required: true, message: '请输入角色名称', trigger: 'blur' }],
merchantId: [{ required: true, message: '请选择所属商户', trigger: 'change' }],
roleRoot: [{ required: true, message: '请选择角色权限', trigger: 'change' }]
},
rootList: [],
curRootIndex: 0,
pageName: '新增角色',
roleInfo: null,
pageType: 'create',
accountList: [],
//商户
list: [],
// tree数据
treeDataList: []
}
},
created() {
let id = Number(this.$route.params.id);
if (!id) {
this.pageName = '新增角色'
this.pageType ='create'
this.getMerchantName()
} else {
this.pageName = '修改角色'
this.pageType ='edit'
this.getRoleData(id)
this.editId = id
}
},
methods: {
// 获取角色信息
getRoleData(id) {
this.$apis.role.roleInfoData({ id }).then(res => {
this.roleInfo = res
this.ruleForm = {
merchantName: res.merchantName,
roleName: res.roleName,
roleDesc: res.roleDescription,
merchantId:res.merchantId
}
this.getMerchantTree(id, res.responseList)
})
},
// 获取商户树
getMerchantTree(id, list) {
this.$apis.role.roleTreeDataById({ id }).then(res => {
for (let i = 0; i < list.length; i++) {
for (let j = 0; j < res.length; j++) {
if (res[j].accounttypeId == list[i].accounttypeId) {
res[j].select = true
}
}
}
this.accountList = res
})
},
getMerchantName() {
this.$apis.role.merchantDataList({ source: 'glsx' }).then(res => {
this.merchantList = res
this.filterList()
})
},
// 过滤数据
filterList(query = '') {
let arr = this.merchantList.filter(item => {
return item.merchantName.includes(query)
})
if (arr.length > 100) {
this.list = arr.slice(0, 100)
} else {
this.list = arr
}
},
// 选择商户----获取权限
selectMerchant(id) {
this.$apis.role.merchantRootById({ id }).then(res => {
this.accountList = res.map(item => {
item.select = false
return item
})
})
},
// 选择商户权限
selectCurAccount(item, index) {
this.accountList[index].select = !item.select
this.curRootIndex = 0
if (this.accountList[index].select) {
this.rootList.push(item)
} else {
let arr = this.rootList.filter(el => {
return item.accounttypeId != el.accounttypeId
})
this.rootList = arr
}
},
// 确定按钮---处理参数---提交数据---创建为0---草稿为1
toCreateRole(delFlag) {
let { merchantId, roleDesc, roleName } = this.ruleForm
if(!merchantId){
this.$message.error("请选择所属商户");
return
}
if(!roleName){
this.$message.error("请输入角色名称");
return
}
if (this.$refs.productFrom.getSelectInfo().length == 0) {
this.$message.error("请选择产品");
return;
}
let accountTypes = JSON.stringify(this.$refs.productFrom.getSelectInfo())
let para = {
merchantId: merchantId,
roleName: roleName,
roleDescription: roleDesc,
delFlag,
requestList: accountTypes,
}
if(this.pageType=='edit'){
para.id = this.editId
this.updateRole(para)
}else{
this.insertRole(para)
}
},
insertRole(para) {
this.$apis.role.createRole(para).then(res => {
if (res) {
this.toBack()
}
})
},
updateRole(para) {
this.$apis.role.updateRole(para).then(res => {
if (res) {
this.toBack()
}
})
},
toBack() {
this.$router.push("/role/index");
}
}
}
</script>
<style lang="scss" scoped>
.role-create-page {
height: 100%;
width: 100%;
background: #ffffff;
}
.top_title_widget {
width: 100%;
height: 58px;
box-sizing: border-box;
padding: 0 20px;
border-bottom: 1px solid #d8d8d8;
display: flex;
align-items: center;
.title {
font-size: 16px;
font-weight: 500;
color: #424242;
}
}
.main_widget {
box-sizing: border-box;
padding: 32px 0;
background: #ffffff;
}
.fixed_bottom {
position: fixed;
left: 0;
right: 0;
bottom: 0;
// width: calc(100% - 60px);
width: 100%;
height: 64px;
background: #ffffff;
display: flex;
align-items: center;
justify-content: center;
.wrap_driver {
margin: 0 40px;
}
}
// 角色权限按钮样式
.custom_element {
display: flex;
align-items: center;
.wrap {
margin-right: 15px;
}
}
</style>