|
@@ -1,113 +1,302 @@
|
1
|
1
|
<template>
|
2
|
|
- <el-dialog title='新增角色' width="600px" :visible.sync="visible" :before-close="_close">
|
3
|
|
- <el-form :model="form" :rules="rules" ref="form" label-width="90px">
|
|
2
|
+ <el-dialog
|
|
3
|
+ title="新增用户"
|
|
4
|
+ width="660px"
|
|
5
|
+ :visible.sync="visible"
|
|
6
|
+ :before-close="_close"
|
|
7
|
+ >
|
|
8
|
+ <!-- <el-form :model="form" :rules="rules" ref="form" label-width="90px">
|
4
|
9
|
<el-form-item label="角色名称 : " prop="name">
|
5
|
10
|
<el-input v-model="form.name" placeholder="" maxlength="30" ></el-input>
|
6
|
11
|
</el-form-item>
|
7
|
12
|
<el-form-item label="角色描述 : " prop="intro">
|
8
|
13
|
<el-input type="textarea" v-model="form.intro" placeholder="" resize="none" rows="4" ></el-input>
|
9
|
14
|
</el-form-item>
|
10
|
|
- </el-form>
|
11
|
|
- <div slot="footer" class="dialog-footer">
|
12
|
|
- <el-button @click="hide">取 消</el-button>
|
13
|
|
- <el-button type="primary" @click="submitAction()">保 存</el-button>
|
|
15
|
+ </el-form>-->
|
|
16
|
+ <div class="chooseuser">
|
|
17
|
+ <span style="color:#303133">选择用户:</span>
|
|
18
|
+ <el-radio v-model="checked" label="1">从已有员工中选择</el-radio>
|
|
19
|
+ <el-radio v-model="checked" label="2">新增员工</el-radio>
|
|
20
|
+ </div>
|
|
21
|
+ <div v-if="checked == '1'" class="roleContent">
|
|
22
|
+ <div class="roleContentLeft">
|
|
23
|
+ <p style="color:#303133">选择:</p>
|
|
24
|
+ <div class="chooseBox">
|
|
25
|
+ <div>
|
|
26
|
+ <el-checkbox
|
|
27
|
+ :indeterminate="isIndeterminate"
|
|
28
|
+ v-model="checkAll"
|
|
29
|
+ @change="handleCheckAllChange"
|
|
30
|
+ >全选</el-checkbox
|
|
31
|
+ >
|
|
32
|
+ </div>
|
|
33
|
+ <el-checkbox-group
|
|
34
|
+ v-model="checkedCities"
|
|
35
|
+ @change="handleCheckedCitiesChange"
|
|
36
|
+ >
|
|
37
|
+ <!-- <el-checkbox v-for="city in cities" :label="city" :key="city">{{city}}</el-checkbox> -->
|
|
38
|
+ <div class="checkone" v-for="city in cities" :key="city">
|
|
39
|
+ <el-checkbox :label="city">
|
|
40
|
+ <img src="https://kuyi.shengws.com/S1.png" alt />
|
|
41
|
+ <span>名字</span>
|
|
42
|
+ </el-checkbox>
|
|
43
|
+ </div>
|
|
44
|
+ </el-checkbox-group>
|
14
|
45
|
</div>
|
15
|
|
- </el-dialog>
|
|
46
|
+ </div>
|
|
47
|
+ <div class="roleContentRight">
|
|
48
|
+ <p style="color:#303133">已选:</p>
|
|
49
|
+ <div class="chooseBox">
|
|
50
|
+ <div class="hasChoosedOne">
|
|
51
|
+ <img src="https://kuyi.shengws.com/S1.png" alt />
|
|
52
|
+ <span>名字</span>
|
|
53
|
+ </div>
|
|
54
|
+ </div>
|
|
55
|
+ </div>
|
|
56
|
+ </div>
|
|
57
|
+ <div v-if="checked == '2'" class="newStaff">
|
|
58
|
+ <el-form
|
|
59
|
+ :model="ruleForm"
|
|
60
|
+ :rules="newrules"
|
|
61
|
+ label-position="right"
|
|
62
|
+ label-width="80px"
|
|
63
|
+ style="width:40%"
|
|
64
|
+ >
|
|
65
|
+ <el-form-item label="姓名" prop="name">
|
|
66
|
+ <el-input v-model="ruleForm.name"></el-input>
|
|
67
|
+ </el-form-item>
|
|
68
|
+ <el-form-item label="手机号" prop="phone">
|
|
69
|
+ <el-input v-model="ruleForm.phone"></el-input>
|
|
70
|
+ </el-form-item>
|
|
71
|
+ <el-form-item label="职位">
|
|
72
|
+ <el-input></el-input>
|
|
73
|
+ </el-form-item>
|
|
74
|
+ </el-form>
|
|
75
|
+ <div class="newItem">
|
|
76
|
+ <p style="width:80px;text-align:right;padding-right:8px">
|
|
77
|
+ <i
|
|
78
|
+ class="el-icon-circle-plus"
|
|
79
|
+ style="font-size:20px;color:#338AFB"
|
|
80
|
+ ></i>
|
|
81
|
+ </p>
|
|
82
|
+ <p style="color:#409FFF">继续新增员工</p>
|
|
83
|
+ </div>
|
|
84
|
+ </div>
|
|
85
|
+ <div slot="footer" class="dialog-footer">
|
|
86
|
+ <el-button @click="hide">取 消</el-button>
|
|
87
|
+ <el-button type="primary" @click="submitAction()">保 存</el-button>
|
|
88
|
+ </div>
|
|
89
|
+ </el-dialog>
|
16
|
90
|
</template>
|
17
|
91
|
|
18
|
92
|
<script>
|
19
|
|
-import {addRole, modifyRole} from '@/api/role/role'
|
|
93
|
+import { addRole, modifyRole } from "@/api/role/role";
|
20
|
94
|
|
21
|
95
|
export default {
|
22
|
|
- name: 'EditRole',
|
23
|
|
- data() {
|
24
|
|
- return {
|
25
|
|
- form: {
|
26
|
|
- id: 0,
|
27
|
|
- name: '',
|
28
|
|
- intro: ''
|
29
|
|
- },
|
30
|
|
- 'visible': false,
|
31
|
|
- rules: {
|
32
|
|
- name: [
|
33
|
|
- {required: true, message: '请输入角色名称', trigger: 'blur'},
|
34
|
|
- {max: 10, message: '10个字以内', trigger: 'blur'}
|
35
|
|
- ],
|
36
|
|
- intro: [
|
37
|
|
- {required: true, message: '请输入角色说明', trigger: 'blur'},
|
38
|
|
- ]
|
39
|
|
- }
|
40
|
|
- }
|
|
96
|
+ name: "EditRole",
|
|
97
|
+ data() {
|
|
98
|
+ return {
|
|
99
|
+ form: {
|
|
100
|
+ id: 0,
|
|
101
|
+ name: "",
|
|
102
|
+ intro: ""
|
|
103
|
+ },
|
|
104
|
+ visible: false,
|
|
105
|
+ rules: {
|
|
106
|
+ name: [
|
|
107
|
+ { required: true, message: "请输入角色名称", trigger: "blur" },
|
|
108
|
+ { max: 10, message: "10个字以内", trigger: "blur" }
|
|
109
|
+ ],
|
|
110
|
+ intro: [{ required: true, message: "请输入角色说明", trigger: "blur" }]
|
|
111
|
+ },
|
|
112
|
+
|
|
113
|
+ //
|
|
114
|
+ checked: "1",
|
|
115
|
+ checkAll: false,
|
|
116
|
+ checkedCities: [],
|
|
117
|
+ cities: ["上海", "北京", "广州", "深圳"],
|
|
118
|
+ isIndeterminate: true,
|
|
119
|
+ ruleForm: {
|
|
120
|
+ name: "",
|
|
121
|
+ phone: "",
|
|
122
|
+ position: ""
|
|
123
|
+ },
|
|
124
|
+ newrules: {
|
|
125
|
+ name: [
|
|
126
|
+ { required: true, message: "请输入角色名称", trigger: "blur" },
|
|
127
|
+ { max: 10, message: "10个字以内", trigger: "blur" }
|
|
128
|
+ ],
|
|
129
|
+ phone: [{ required: true, message: "请输入手机号", trigger: "blur" }]
|
|
130
|
+ }
|
|
131
|
+ };
|
|
132
|
+ },
|
|
133
|
+ methods: {
|
|
134
|
+ _close: function(done) {
|
|
135
|
+ this.clear();
|
|
136
|
+ done();
|
|
137
|
+ },
|
|
138
|
+ clear: function() {
|
|
139
|
+ this.form.id = 0;
|
|
140
|
+ this.form.name = "";
|
|
141
|
+ this.form.intro = "";
|
|
142
|
+ },
|
|
143
|
+ show() {
|
|
144
|
+ this.clear();
|
|
145
|
+ this.visible = true;
|
41
|
146
|
},
|
42
|
|
- methods: {
|
43
|
|
- _close: function(done) {
|
44
|
|
- this.clear()
|
45
|
|
- done()
|
46
|
|
- },
|
47
|
|
- clear: function() {
|
48
|
|
- this.form.id = 0
|
49
|
|
- this.form.name = ''
|
50
|
|
- this.form.intro = ''
|
51
|
|
- },
|
52
|
|
- show() {
|
53
|
|
- this.clear()
|
54
|
|
- this.visible = true
|
55
|
|
- },
|
56
|
|
- hide() {
|
57
|
|
- this.clear()
|
58
|
|
- this.visible = false
|
59
|
|
- },
|
60
|
|
- modify(id, name, intro) {
|
61
|
|
- this.form.id = id
|
62
|
|
- this.form.name = name
|
63
|
|
- this.form.intro = intro
|
64
|
|
- this.visible = true
|
65
|
|
- },
|
66
|
|
- submitAction() {
|
67
|
|
- this.$refs.form.validate((valid) => {
|
68
|
|
- if (valid) { // 验证通过
|
69
|
|
- if (this.form.id === 0) { // 新增 role
|
70
|
|
- addRole(this.form.name, this.form.intro).then(rs => {
|
71
|
|
- var resp = rs.data
|
72
|
|
- if (resp.state === 1) {
|
73
|
|
- var new_id = resp.data.id
|
74
|
|
- var new_name = resp.data.name
|
75
|
|
- var new_intro = resp.data.intro
|
76
|
|
- var new_status = resp.data.status
|
77
|
|
- this.$emit('did-add-role', new_id, new_name, new_intro, new_status)
|
|
147
|
+ hide() {
|
|
148
|
+ this.clear();
|
|
149
|
+ this.visible = false;
|
|
150
|
+ },
|
|
151
|
+ modify(id, name, intro) {
|
|
152
|
+ this.form.id = id;
|
|
153
|
+ this.form.name = name;
|
|
154
|
+ this.form.intro = intro;
|
|
155
|
+ this.visible = true;
|
|
156
|
+ },
|
|
157
|
+ submitAction() {
|
|
158
|
+ this.$refs.form.validate(valid => {
|
|
159
|
+ if (valid) {
|
|
160
|
+ // 验证通过
|
|
161
|
+ if (this.form.id === 0) {
|
|
162
|
+ // 新增 role
|
|
163
|
+ addRole(this.form.name, this.form.intro)
|
|
164
|
+ .then(rs => {
|
|
165
|
+ var resp = rs.data;
|
|
166
|
+ if (resp.state === 1) {
|
|
167
|
+ var new_id = resp.data.id;
|
|
168
|
+ var new_name = resp.data.name;
|
|
169
|
+ var new_intro = resp.data.intro;
|
|
170
|
+ var new_status = resp.data.status;
|
|
171
|
+ this.$emit(
|
|
172
|
+ "did-add-role",
|
|
173
|
+ new_id,
|
|
174
|
+ new_name,
|
|
175
|
+ new_intro,
|
|
176
|
+ new_status
|
|
177
|
+ );
|
78
|
178
|
|
79
|
|
- this.hide()
|
80
|
|
-
|
81
|
|
- } else {
|
82
|
|
- this.$message.error(resp.msg)
|
83
|
|
- }
|
84
|
|
-
|
85
|
|
- }).catch(err => {
|
86
|
|
- this.$message.error(err)
|
87
|
|
- })
|
88
|
|
-
|
89
|
|
- } else { // 修改 role
|
90
|
|
- modifyRole(this.form.id, this.form.name, this.form.intro).then(rs => {
|
91
|
|
- var resp = rs.data
|
92
|
|
- if (resp.state === 1) {
|
93
|
|
- this.$emit('did-edit-role', this.form.id, this.form.name, this.form.intro)
|
94
|
|
- this.hide()
|
95
|
|
-
|
96
|
|
- } else {
|
97
|
|
- this.$message.error(resp.msg)
|
98
|
|
- }
|
99
|
|
-
|
100
|
|
- }).catch(err => {
|
101
|
|
- this.$message.error(err)
|
102
|
|
- })
|
103
|
|
- }
|
104
|
|
-
|
105
|
|
- } else { // 验证失败
|
106
|
|
- return false
|
|
179
|
+ this.hide();
|
|
180
|
+ } else {
|
|
181
|
+ this.$message.error(resp.msg);
|
|
182
|
+ }
|
|
183
|
+ })
|
|
184
|
+ .catch(err => {
|
|
185
|
+ this.$message.error(err);
|
|
186
|
+ });
|
|
187
|
+ } else {
|
|
188
|
+ // 修改 role
|
|
189
|
+ modifyRole(this.form.id, this.form.name, this.form.intro)
|
|
190
|
+ .then(rs => {
|
|
191
|
+ var resp = rs.data;
|
|
192
|
+ if (resp.state === 1) {
|
|
193
|
+ this.$emit(
|
|
194
|
+ "did-edit-role",
|
|
195
|
+ this.form.id,
|
|
196
|
+ this.form.name,
|
|
197
|
+ this.form.intro
|
|
198
|
+ );
|
|
199
|
+ this.hide();
|
|
200
|
+ } else {
|
|
201
|
+ this.$message.error(resp.msg);
|
107
|
202
|
}
|
108
|
|
- })
|
|
203
|
+ })
|
|
204
|
+ .catch(err => {
|
|
205
|
+ this.$message.error(err);
|
|
206
|
+ });
|
|
207
|
+ }
|
|
208
|
+ } else {
|
|
209
|
+ // 验证失败
|
|
210
|
+ return false;
|
|
211
|
+ }
|
|
212
|
+ });
|
|
213
|
+ },
|
|
214
|
+ handleCheckAllChange(val) {
|
|
215
|
+ this.checkedCities = val ? this.cities : [];
|
|
216
|
+ this.isIndeterminate = false;
|
|
217
|
+ },
|
|
218
|
+ handleCheckedCitiesChange(value) {
|
|
219
|
+ let checkedCount = value.length;
|
|
220
|
+ this.checkAll = checkedCount === this.cities.length;
|
|
221
|
+ this.isIndeterminate =
|
|
222
|
+ checkedCount > 0 && checkedCount < this.cities.length;
|
|
223
|
+ }
|
|
224
|
+ }
|
|
225
|
+};
|
|
226
|
+</script>
|
|
227
|
+
|
|
228
|
+<style lang="scss" scoped>
|
|
229
|
+.roleContent {
|
|
230
|
+ margin-top: 20px;
|
|
231
|
+ display: flex;
|
|
232
|
+ justify-content: space-between;
|
|
233
|
+ .roleContentLeft {
|
|
234
|
+ .chooseBox {
|
|
235
|
+ width: 280px;
|
|
236
|
+ height: 320px;
|
|
237
|
+ overflow-y: auto;
|
|
238
|
+ border: 1px solid rgba(235, 238, 240, 1);
|
|
239
|
+ margin-top: 26px;
|
|
240
|
+ padding: 20px;
|
|
241
|
+ .checkone {
|
|
242
|
+ display: flex;
|
|
243
|
+ align-items: center;
|
|
244
|
+ height: 50px;
|
|
245
|
+ }
|
|
246
|
+ .el-checkbox__label {
|
|
247
|
+ display: flex;
|
|
248
|
+ align-items: center;
|
|
249
|
+ img {
|
|
250
|
+ width: 30px;
|
|
251
|
+ height: 30px;
|
|
252
|
+ margin-right: 10px;
|
|
253
|
+ }
|
|
254
|
+ }
|
|
255
|
+ }
|
|
256
|
+ }
|
|
257
|
+ .roleContentRight {
|
|
258
|
+ .chooseBox {
|
|
259
|
+ width: 280px;
|
|
260
|
+ height: 320px;
|
|
261
|
+ overflow-y: auto;
|
|
262
|
+ border: 1px solid rgba(235, 238, 240, 1);
|
|
263
|
+ margin-top: 26px;
|
|
264
|
+ padding: 20px;
|
|
265
|
+ .hasChoosedOne {
|
|
266
|
+ display: flex;
|
|
267
|
+ align-items: center;
|
|
268
|
+ height: 50px;
|
|
269
|
+ img {
|
|
270
|
+ width: 30px;
|
|
271
|
+ height: 30px;
|
|
272
|
+ margin-right: 10px;
|
109
|
273
|
}
|
|
274
|
+ }
|
110
|
275
|
}
|
|
276
|
+ }
|
111
|
277
|
}
|
112
|
|
-</script>
|
|
278
|
+.newStaff {
|
|
279
|
+ margin-top: 26px;
|
|
280
|
+ .newItem {
|
|
281
|
+ display: flex;
|
|
282
|
+ align-items: center;
|
|
283
|
+ }
|
|
284
|
+}
|
|
285
|
+</style>
|
113
|
286
|
|
|
287
|
+<style lang="scss">
|
|
288
|
+.roleContent {
|
|
289
|
+ .roleContentLeft {
|
|
290
|
+ .chooseBox {
|
|
291
|
+ .el-checkbox {
|
|
292
|
+ display: flex;
|
|
293
|
+ align-items: center;
|
|
294
|
+ }
|
|
295
|
+ .el-checkbox__label {
|
|
296
|
+ display: flex;
|
|
297
|
+ align-items: center;
|
|
298
|
+ }
|
|
299
|
+ }
|
|
300
|
+ }
|
|
301
|
+}
|
|
302
|
+</style>
|