createRole.vue
6.13 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
<!--
* @Description:
* @Author: huyue
* @Date: 2022-06-10 15:36:06
* @LastEditors: huyue
* @LastEditTime: 2022-06-22 17:22:54
-->
<template>
<div>
<GLDialog :width="'1080px'" :visible="roleVisible" :close-on-click-modal="false" @close="handleClose" title="创建角色" :showClose="true">
<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="154px" class="demo-ruleForm">
<el-form-item class="aa" v-if="$globalState.session.accountLevel != 4" label="所属商户" prop="merchantId">
<el-select :size="size" style="width: 40%" v-model="ruleForm.merchantId" clearable filterable placeholder="请选择" @change="merchantChange">
<el-option v-for="item in merchantList" :key="item.id" :label="item.merchantName" :value="item.id"></el-option>
</el-select>
</el-form-item>
<el-form-item label="所属商户:" prop="merchantName" v-else>
<span>{{ $globalState.session.merchantName }}</span>
</el-form-item>
<el-form-item label="角色名称:" prop="roleName">
<el-input :size="size" maxlength="20" style="width: 40%; padding-right: 50px" @input="changeInput" v-model="ruleForm.roleName" placeholder="请输入角色名称"></el-input>
</el-form-item>
<el-form-item label="角色说明:" prop="roleDesc">
<el-input :size="size" maxlength="50" style="width: 40%; padding-right: 50px" @input="changeInput" v-model="ruleForm.roleDesc" placeholder="请输入角色说明"></el-input>
</el-form-item>
<el-form-item label="角色权限:" prop="roleAuth">
<el-checkbox-group v-model="ruleForm.roleAuth">
<el-checkbox v-for="(itm, idx) in accountListSelect" :label="itm.accounttypeName" @change="selectCurAccount(itm, idx)" :key="idx">{{ itm.accounttypeName }}</el-checkbox>
</el-checkbox-group>
<SelectProduct v-if="roleVisible" ref="productFrom" :roleType="true" title="角色权限"></SelectProduct>
</el-form-item>
</el-form>
<div slot="footer">
<el-button :size="size" @click="handleClose">取消</el-button>
<el-button :size="size" type="primary" @click="toCreateRole">提交</el-button>
</div>
</GLDialog>
</div>
</template>
<script>
import SelectProduct from './selectProduct'
export default {
name: 'CreateRole',
components: {
SelectProduct
},
data() {
return {
roleVisible: false,
ruleForm: {
merchantId: '',
roleName: '',
roleDesc: '',
roleAuth: []
},
rules: {
roleName: [{ required: true, message: '请输入角色名称', trigger: 'blur' }],
merchantId: [{ required: true, message: '请选择所属商户', trigger: 'change' }],
roleAuth: [{ required: true, message: '请选择角色权限', trigger: 'change' }]
},
//商户下拉框
merchantList: [],
accountListSelect: [],
rootList: []
}
},
methods: {
init() {
this.roleVisible = true
if (this.$refs.ruleForm) this.$refs.ruleForm.resetFields()
this.getMerchantName()
},
handleClose() {
this.roleVisible = false
},
getMerchantName() {
this.$apis.role.merchantDataList({ source: 'glsx' }).then(res => {
this.merchantList = res
if (this.$globalState.session.accountLevel == 4) {
this.ruleForm.merchantId = this.merchantList[0].id
this.selectMerchant(this.merchantList[0].id)
}
// this.filterList()
})
},
// 选择商户----获取权限
async selectMerchant(id, list) {
let res = await this.$refs.productFrom.findMenuFunTreeByMerId({ id })
this.accountListSelect = res.map(item => {
item.select = false
return item
})
},
// 选择商户权限
selectCurAccount(item, index) {
this.isChangeEdit = true
this.roleRootRules = false
this.accountListSelect[index].select = !item.select
this.curRootIndex = 0
if (this.accountListSelect[index].select) {
this.rootList.push(item)
} else {
let arr = this.rootList.filter(el => {
return item.accounttypeId != el.accounttypeId
})
this.rootList = arr
}
let accounttypeId = []
this.rootList.forEach(item => {
accounttypeId.push(item.accounttypeId)
})
this.accounttypeIds = accounttypeId
this.$refs.productFrom.findMenuFunTree(item.accounttypeId, item.select)
},
toCreateRole() {
this.$refs.ruleForm.validate(valid => {
if (valid) {
let { merchantId, roleDesc, roleName } = this.ruleForm
let product = this.$refs.productFrom.getSelectInfo()
if (product && product.every(item => item.productList.length == 0)) {
this.$message({
type: 'error',
message: '请至少选择一个产品',
customClass: 'message-z'
})
return
}
let accountTypes = JSON.stringify(this.$refs.productFrom.getSelectInfo())
let para = {
merchantId: merchantId,
roleName: roleName,
roleDescription: roleDesc,
delFlag: 0,
requestList: accountTypes
}
this.$apis.role.createRole(para).then(res => {
if (res.code == -1) {
this.$message.error(res.message)
return
}
this.$message.success('操作成功')
this.$emit('updataRole', true)
this.roleVisible = !res
this.ruleForm = {
merchantId: '',
roleName: '',
roleDesc: '',
roleAuth: ''
}
})
} else {
return false
}
})
}
}
}
</script>
<style scoped lang="scss">
/deep/ {
.el-dialog__body {
padding: 20px;
}
.el-form-item {
display: inline-block;
width: 50%;
vertical-align: text-top;
margin-bottom: 20px !important;
.el-input {
width: 360px !important;
}
&:last-child {
width: 100%;
}
.el-form-item__label,
.el-form-item__content {
line-height: 32px;
}
}
}
</style>