“dzb”
2022-09-27 80e0b9da4d4da98452f8930b148750763d85f090
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
<template>
    <div class="updateUser">
        <main>
            <div class="mainContent">
                <el-form ref="user" label-width="140px" autoComplete="on" :model="role" :rules="createRoleRules"
                    label-position="right">
                    <!-- 角色名称 -->
                    <el-form-item class="optionItem" label="角色名称:" prop="name">
                        <el-input v-model="role.name" placeholder="请填写角色名称" :disabled="!updateFlag"></el-input>
                    </el-form-item>
                    <!-- 角色类型 -->
                    <el-form-item class="optionItems" label="角色类型:" prop="sort">
                        <!-- <el-input v-model="role.sort" placeholder="请选择角色类型" :disabled="!updateFlag"></el-input> -->
                        <el-select v-model="role.sort" placeholder="请选择角色类型">
                            <!-- v-for="item in roleList" :key="item.id" :label="item.departName"
                                :value="item.id" -->
                            <el-option :value="treeId" :label="treeLabel">
                                <el-tree :data="roleList" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <!-- 角色描述 -->
                    <el-form-item class="optionItem" label="角色描述:" prop="description">
                        <el-input type="textarea" v-model="role.description" placeholder="请输入描述内容200字以内"
                            :disabled="!updateFlag"></el-input>
                    </el-form-item>
                    <el-form-item v-if="updateFlag">
                        <div class="optionBtn">
                            <el-button type="primary" class="btn submit" @click.native.prevent="handleUser">确认
                            </el-button>
                        </div>
                    </el-form-item>
                </el-form>
 
            </div>
        </main>
    </div>
</template>
<script>
export default {
    data() {
        const validateNickname = (rule, value, callback) => {
            if (!value) {
                callback(new Error("请填写角色名称"));
            } else {
                callback();
            }
        };
        const validatePass = (rule, value, callback) => {
            if (!value) {
                callback();
            } else {
                // const rep = /^\w+$/;
                // if (!rep.test(value)) {
                //     callback(new Error("密码只能是以数字、26个英文字母或者下划线组成的字符串"));
                // }
                callback();
            }
        };
        const validateTruename = (rule, value, callback) => {
            if (value) {
                callback();
            } else {
                // const rep = /^[\u4E00-\u9FA5]{2,4}$/;
                // if (!rep.test(value)) {
                //     callback("请输入正确的用户姓名");
                // }
                callback();
            }
        };
        return {
            role: {
                name: '',
                sort: '',
                description: '',
            },
            createRoleRules: {
                name: [
                    { required: true, trigger: "blur", validator: validateNickname },
                ],
                sort: [
                    { required: false, trigger: "blur", validator: validatePass },
                ],
                description: [
                    { required: false, trigger: "blur", validator: validateTruename },
                ],
            },
            roleList: [],
            defaultProps: {
                children: 'children',
                label: 'title'
            },
            treeLabel:'',
            treeId:23
        }
    },
    created() {
        const that = this;
        this.userInfo.status ? this.userInfo.status = 1 : this.userInfo.status = 0;
        this.role = JSON.parse(JSON.stringify(that.userInfo));
        this.getMenuList();
    },
    methods: {
        handleUser() {
            this.$refs.user.validate((valid) => {
                if (valid) {
                    const { role } = this;
                    console.log(role);
                    this.$axios.post('/sccg/role/update/' + role.id, {
                        id: role.id,
                        status: role.status,
                        description: role.description,
                        name: role.name,
                        sort: 0
                    }).then(res => {
                        this.$emit('changeDialog', { dialogUpdate: false });
                        this.getUserList();
                    })
                } else {
                    return false;
                }
            })
        },
        // 获取系统菜单
        getMenuList() {
            this.$axios({
                method: 'get',
                url: 'sccg/menu/treeList',
            })
                .then(res => {
                    this.roleList = res.data;
                    console.log(res);
                })
        },
        // 点击树节点
        handleNodeClick({title,id}) {
            // console.log(obj);
            this.role.sort = title;
            this.treeLabel = title;
            this.treeId = id;
 
        }
    },
    props: ['userInfo', 'updateFlag', 'getUserList', 'changeDialog']
}
</script>
<style lang="scss" scoped>
.updateUser {
    border-radius: 1px;
    background-color: #09152f;
 
    main {
        // border: 1px solid #fff;
        text-align: left;
        padding: 0 55px;
        background-color: #09152f;
        padding-bottom: 50px;
 
        .mainContent {
            display: flex;
            justify-content: center;
            padding-top: 50px;
 
            .el-form-item__content {
                width: 400px;
 
                .el-select {
                    width: 100%;
                }
            }
 
            .optionHandleSp {
                display: flex;
 
                .areaNumber,
                .moreNumber {
                    flex: 1;
                }
 
                .telNumber {
                    flex: 2;
                }
            }
 
            .optionBtn {
                display: flex;
                margin-top: 20px;
 
                .btn {
                    padding: 12px 50px;
                }
            }
 
        }
    }
 
    &::v-deep .el-textarea__inner {
        background-color: #09152f;
        border: 1px solid #17324c;
    }
 
    ::v-deep .el-form-item__label {
        color: #4b9bb7;
    }
 
    ::v-deep .el-input__inner {
        background-color: #09152f;
        border: 1px solid #17324c;
    }
}
 
</style>