“dzb”
2022-10-21 a598d935a61fea27312fc57becd80e23bf09f788
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<template>
    <div class="createUser">
        <main>
            <div class="mainContent">
                <el-form ref="user" label-width="140px" autoComplete="on" :model="store" :rules="createUserRules"
                    label-position="right">
                    <!-- 店铺类型 -->
                    <el-form-item class="optionItem" label="店铺类型:" prop="storetype">
                        <el-select v-model="store.storetype" placeholder="请选择店铺类型">
                            <el-option value="1">
                                <el-tree ref="tree" :check-strictly="true" :data="shopTypeList" :props="defaultProps"
                                    show-checkbox @check-change="handleCheck" default-expand-all node-key="id">
                                </el-tree>
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <!-- 店铺名称 -->
                    <el-form-item class="optionItems" label="店铺名称:" prop="storename">
                        <el-input v-model="store.storename" placeholder="请填写店铺名称"></el-input>
                    </el-form-item>
                    <!-- 负责人 -->
                    <el-form-item class="optionItem" label="负责人:" prop="owner">
                        <el-input v-model="store.owner" placeholder="请填写店铺负责人名字"></el-input>
                    </el-form-item>
                    <!-- 店铺描述 -->
                    <el-form-item class="optionItem" label="店铺描述:" prop="storedesc">
                        <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" maxlength="300" show-word-limit
                            v-model="store.storedesc" placeholder="输入店铺描述"></el-input>
                        <!-- <el-input type="textarea" v-model="user.storedesc" placeholder="输入部门描述"></el-input> -->
                    </el-form-item>
                    <!-- 联系方式 -->
                    <el-form-item class="optionItem" label="联系方式:" prop="contact">
                        <el-input v-model="store.contact" placeholder="请填写店铺联系方式"></el-input>
                    </el-form-item>
                    <!-- 店铺地址 -->
                    <el-form-item class="optionItem" label="店铺地址:" prop="storeaddr">
                        <el-input v-model="store.storeaddr" placeholder="请填写店铺详细地址"></el-input>
                    </el-form-item>
                </el-form>
            </div>
        </main>
        <footer>
            <div class="optionBtn">
                <el-button class="btn reset" @click="handleBack">取消</el-button>
                <el-button type="primary" class="btn submit" @click="handleStore">确定</el-button>
            </div>
        </footer>
    </div>
</template>
<script>
import { getCodeList } from '@/utils/helper'
export default {
    data() {
        const validateNickname = (rule, value, callback) => {
            if (!value) {
                callback(new Error("负责人不能为空"));
            } else {
                callback();
            }
        };
        const validatePass = (rule, value, callback) => {
            if (!value) {
                callback();
            } else {
                callback();
            }
        };
        const validateTruename = (rule, value, callback) => {
            if (!value) {
                callback(new Error('店铺地址不能为空'));
            } else {
                callback()
            }
        };
        const validatePhone = (rule, value, callback) => {
            if (!value) {
                callback(new Error("请填写手机号码"));
            } else {
                const rep = /(^1[3|4|5|7|8|9]\d{9}$)|(^09\d{8}$)/
                if (!rep.test(value)) {
                    callback("请输入正确的手机号码");
                } else {
                    callback();
                }
            }
        };
        const validateMail = (rule, value, callback) => {
            if (value) {
                callback();
            } else {
                callback(new Error('店铺名称不能为空'))
            }
        };
        const validateType = (rule, value, callback) => {
            if (!value) {
                callback(new Error('门店类型不能为空'));
            } else {
                callback();
            }
        };
        const validateDesc = (rule, value, callback) => {
            if (!value) {
                callback();
            } else {
                callback();
            }
        };
        return {
            store: {
                contact: '',
                idcardinfo: '',
                owner: '',
                storeaddr: '',
                storename: '',
                storedesc: '',
                storetype: '',
            },
            createUserRules: {
                owner: [
                    { required: true, trigger: "blur", validator: validateNickname },
                ],
                storetype: [
                    {
                        required: true, trigger: 'change', validator: validateType,
                    }
                ],
                idcardinfo: [
                    { required: true, trigger: "blur", validator: validatePass },
                ],
                storeaddr: [
                    { required: true, trigger: "blur", validator: validateTruename },
                ],
                contact: [
                    { required: true, trigger: "blur", validator: validatePhone },
                ],
                storename: [
                    { required: true, trigger: "blur", validator: validateMail },
                ],
                storedesc: [
                    { required: false, trigger: "blur", validator: validateDesc },
                ],
            },
            shopTypeList: [
                { name: '类型1', value: 1 }, { name: '类型2', value: 2 }
            ],
            defaultProps: {
                children: 'children', 
                label: 'name',
                disabled: (data, node) => {
                    if (node.level === 1 && node.childNodes.length !== 0) {
                        return !data.leaf
                    }
                }
            },
            selectOrg: {
                orgsid: []
            },
        }
    },
    created() {
        this.getShopTypeList();
    },
    methods: {
        handleStore() {
            const { store } = this;
            this.$refs.user.validate((valid) => {
                console.log(valid);
                if (valid) {
                    this.$axios({
                        method: 'post',
                        url: 'sccg/store/storeinfo/add',
                        data: {
                            contact: store.contact,
                            idcardinfo: '511025184612310215',
                            owner: store.owner,
                            storeaddr: store.storeaddr,
                            storename: store.storename,
                        }
                    })
                        .then(res => {
                            console.log(res);
                            if (res.code === 200) {
                                this.$message({
                                    type: 'success',
                                    message: '添加成功',
                                })
                                this.$emit('sendDialog', { flag: false });
                            } else {
                                this.$message({
                                    type: 'error',
                                    message: res.message,
                                })
                            }
                        })
                } else {
                    return false;
                }
            })
        },
        handleBack() {
            this.$emit('sendDialog', { flag: false })
        },
        // 获取字典
        async getShopTypeList() {
            let arr = await getCodeList('16');
            this.shopTypeList = this.createShopTypeTree(arr);
        },
        // 创建商铺类型树
        createShopTypeTree(arr) {
            if (arr.length && arr.length !== 0) {
                // 获取顶级菜单
                let treeRoot = arr.filter(item => {
                    return item.parentId === 0
                })
                console.log(treeRoot);
                // 添加child
                treeRoot.forEach(item => {
                    item.children = []
                    arr.forEach(child => {
                        if (child.parentId === item.id) {
                            item.children.push(child)
                        }
                    })
                })
                return treeRoot;
            }
        },
        handleCheck(data, checked) {
            this.store.storetype = data.name;
            // 获取当前选择的id在数组中的索引
            const indexs = this.selectOrg.orgsid.indexOf(data.id)
            // 如果不存在数组中,并且数组中已经有一个id并且checked为true的时候,代表不能再次选择。
            if (indexs < 0 && this.selectOrg.orgsid.length === 1 && checked) {
                this.$message({
                    message: '只能选择一个部门!',
                    type: 'warning',
                    showClose: true
                })
                // 设置已选择的节点为false 很重要
                this.$refs.tree.setChecked(data, false)
            } else if (this.selectOrg.orgsid.length === 0 && checked) {
                // 发现数组为空 并且是已选择
                // 防止数组有值,首先清空,再push
                this.selectOrg.orgsid = []
                this.selectOrg.orgsid.push(data.id)
            } else if (
                indexs >= 0 &&
                this.selectOrg.orgsid.length === 1 &&
                !checked
            ) {
                // 再次直接进行赋值为空操作
                this.selectOrg.orgsid = []
                this.store.storetype = ''
            }
        },
    },
    props: ['sendDialog']
}
</script>
<style lang="scss" scoped>
.createUser {
    border-radius: 1px;
    background-color: #09152f;
    padding-bottom: 50px;
 
    main {
        text-align: left;
        padding: 0 55px;
        background-color: #09152f;
        padding-top: 20px;
 
        .mainContent {
            display: flex;
            justify-content: center;
            margin-top: 50px;
 
            &::v-deep .el-form-item__label {
                color: #4b9bb7;
            }
 
            &::v-deep .el-input__inner {
                background-color: #09152f;
                border: 1px solid #17324c;
            }
 
            &::v-deep .el-textarea__inner {
                background-color: #09152f;
                border: 1px solid #17324c;
            }
 
            .el-form-item__content {
                width: 400px;
 
                .el-select {
                    width: 100%;
                }
            }
 
            .optionHandleSp {
                display: flex;
 
                .areaNumber,
                .moreNumber {
                    flex: 1;
                }
 
                .telNumber {
                    flex: 2;
                }
            }
 
        }
    }
 
    footer {
        border-top: 1px solid #4b9bb7;
        display: flex;
        justify-content: flex-end;
        padding: 0 20px;
 
        .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-input__count {
        background-color: #09152f;
    }
}
</style>