陶杰
2024-08-22 4aa0bd47801606b4d0e0a6a2ed8fe92a7e5f2444
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
<template>
    <view class="container-page">
        <view>
            <view class="form-item">
                <view class="label required">店铺类型</view>
                <view class="m-l-a m-r-0 flex " :class="[!dto.typeId?'desc-gray':'']" @click="()=>{
                    if(!id){
                        show_select_type=true
                    }
                }">
                    <view>{{dto.typeName || '请选择'}}</view>
                    <u-icon class="m-l-a" name="arrow-right"></u-icon>
                </view>
                <!--     <view class="m-l-a m-r-0 flex " :class="[!dto.typeId?'desc-gray':'']">
                    <uni-data-picker @change="(e)=>{PickData('typeId','typeStr',e)}" placeholder="请选择"
                        :localdata="columns_types">
                        {{dto.typeStr || '请选择'}}
                    </uni-data-picker>
                    <u-icon class="m-l-a" name="arrow-right"></u-icon>
                </view> -->
            </view>
            <view class="form-item before-line">
                <view class="label required">店铺名称</view>
                <view class="m-l-a m-r-0 flex">
                    <input v-model="dto.name" placeholder="请输入店铺名称" style="margin-top: 16px;text-align: right;"></input>
 
                </view>
            </view>
            <view class="form-item bottom-border-no">
                <view class="label required" style="width: 360rpx;min-width: 360rpx;font-size: 28rpx;">店铺头像(推荐80*80px)
                </view>
                <view class="m-l-a m-r-0 flex m-t-20 m-b-20">
                    <view class="component-button-upload" @click="uploadIcon('cover')">
 
                    </view>
                </view>
            </view>
            <view v-if="dto.cover">
                <view class="flex p20 form-item bottom-border-no" style="padding-top: 0rpx;padding-bottom: 10rpx">
                    <view class="m-r-10 ">
                        <image class="banner-img" :src="dto.cover" @click.stop="previewImg(dto.cover)">
 
                        </image>
                        <view class="t-red text-center" @click.stop="deleteImg('cover','')">删除</view>
                    </view>
                </view>
            </view>
            <u-divider></u-divider>
 
            <view class="form-item before-line">
                <view class="label required">联系人姓名</view>
                <view class="m-l-a m-r-0 flex">
                    <input v-model="dto.contactName" placeholder="请输入联系人姓名"
                        style="margin-top: 16px;text-align: right;"></input>
 
                </view>
            </view>
            <view class="form-item before-line">
                <view class="label required">联系方式</view>
                <view class="m-l-a m-r-0 flex">
                    <input v-model="dto.contactTel" placeholder="请输入联系方式"
                        style="margin-top: 16px;text-align: right;"></input>
 
                </view>
            </view>
            <view class="form-item before-line">
                <view class="label required">集货站</view>
                <view class="m-l-a m-r-0 flex " :class="[!dto.stationId?'desc-gray':'']" @click="()=>{
                    if(!id){
                        show_select_station=true
                    }
                }">
                    <view>{{dto.stationName || '请选择'}}</view>
                    <u-icon class="m-l-a" name="arrow-right"></u-icon>
                </view>
            </view>
            <view class="form-item before-line">
                <view class="label required">地区</view>
                <!--             <view class="m-l-a m-r-0 flex " :class="[!dto.applicationType?'desc-gray':'']" @click="()=>{
                    if(!id){
                        show_select_type=true
                    }
                }">
                    <view>{{dto.applicationTypeStr||dto.applicationType || '请选择'}}</view>
                    
                    
                    <u-icon class="m-l-a" name="arrow-right"></u-icon>
                </view> -->
                <view class="m-l-a m-r-0 flex " :class="[!dto['province']?'desc-gray':'']">
                    <uni-data-picker :area="true" @change="(e)=>{PickArea(dto,e)}" placeholder=""
                        :localdata="regionDataPlus">
                        {{ dto['province'] || '请选择' }}{{ dto['city'] && ('/' + dto['city']) || '' }}{{
                                                  dto['region'] && ('/' + dto['region']) || ''
                                                }}
                    </uni-data-picker>
                    <u-icon class="m-l-a" name="arrow-right"></u-icon>
                </view>
 
            </view>
            <view class="form-item before-line">
                <view class="label required">地址</view>
                <view class="m-l-a m-r-0 flex">
                    <input v-model="dto.address" placeholder="请输入地址"
                        style="margin-top: 16px;text-align: right;"></input>
 
                </view>
            </view>
            <view class="form-item before-line">
                <view class="label required">店铺简介</view>
            </view>
            <view class="flex">
                <u--textarea v-model="dto.description" placeholder="请输入店铺简介"></u--textarea>
            </view>
            <view class="form-item before-line m-t-20">
                <view class="label required">选择审核方式</view>
                <view class="m-l-a m-r-0 flex">
 
                    <!--     <u-radio-group v-model="dto.idcardType" placement="row">
                        <u-radio :customStyle="{'margin-bottom': '8px','margin-right': '8px','font-size':'28rpx'}"
                            v-for="(item, index) in shTypeList" :key="index" :label="item.name" :name="item.name">
                        </u-radio>
                    </u-radio-group> -->
                    <!--                    <view>-->
                    <!--                        <radio :checked="dto.idcardType==='身份证'" @click="()=>{-->
                    <!--                            dto.idcardType='身份证';-->
                    <!--                            $forceUpdate()-->
                    <!--                        }">-->
                    <!--                        </radio>身份证-->
                    <!--                    </view>-->
                    <!--                    <view class="m-l-10">-->
                    <!--                        <radio :checked="dto.idcardType==='营业执照'" @click="()=>{-->
                    <!--                            dto.idcardType='营业执照';-->
                    <!--                            $forceUpdate()-->
                    <!--                        }">-->
                    <!--                        </radio>营业执照-->
                    <!--                    </view>-->
                    <evan-radio-group v-model="dto.idcardType">
                        <evan-radio v-for="item in shTypeList" :key="item.value"
                            :label="item.value">{{item.label}}</evan-radio>
                    </evan-radio-group>
                </view>
            </view>
            <view class="form-item bottom-border-no before-line m-t-20 p-b-20" v-if="dto.idcardType=='1'">
                <view class="label required">身份证正反面</view>
                <view class="m-l-a m-r-0 flex">
                    <view class="component-button-upload" @click="uploadIcon('idCards')">
 
                    </view>
                </view>
            </view>
            <view class="flex p20" style="padding-top: 0rpx;padding-bottom: 10rpx"
                v-if="dto.idcardType==='1'&&dto.idCards&&dto.idCards.length>0">
                <view class="m-t-12 m-r-10 " v-for="(tBanner,index) of dto.idCards" :key="index">
                    <image class="banner-img" :src="tBanner.url" @click.stop="previewImg(tBanner.url)">
 
                    </image>
                    <view class="t-red text-center" @click.stop="deleteImg('idCards',index)">删除</view>
                </view>
            </view>
            <view class="form-item bottom-border-no before-line m-t-20 p-b-20" v-if="dto.idcardType=='2'">
                <view class="label required">营业执照</view>
                <view class="m-l-a m-r-0 flex">
                    <view class="component-button-upload m-r-15" @click="uploadIcon('pictures')">
 
                    </view>
 
                </view>
            </view>
            <view class="flex p20" style="padding-top: 0rpx;padding-bottom: 10rpx"
                v-if="dto.idcardType==='2'&&dto.pictures&&dto.pictures.length>0">
                <view class="m-t-12 m-r-10 " v-for="(tBanner,index) of dto.pictures" :key="index">
                    <image class="banner-img" :src="tBanner.url" @click.stop="previewImg(tBanner.url)">
 
                    </image>
                    <view class="t-red text-center" @click.stop="deleteImg('pictures',index)">删除</view>
                </view>
            </view>
 
 
 
            <view class="button-green-1 m-t-20 button-fixed-bottom before-line " style="font-size: 22rpx;"
                v-if="currentInfo.supplierDTO&&currentInfo.supplierDTO.status==='P'">
                审核已通过,部分信息请前往个人资料修改
            </view>
 
            <view class="button-green-1 m-t-20 button-fixed-bottom before-line " v-else @click="submit">
                提交审核
            </view>
 
 
 
        </view>
 
        <view style="min-height: 200rpx;">
            &nbsp;
        </view>
        <u-picker @confirm="select_type" keyName="name" @cancel="show_select_type=false" :show="show_select_type"
            :columns="columns_types"></u-picker>
 
        <u-picker @confirm="select_station" keyName="name" @cancel="show_select_station=false"
            :show="show_select_station" :columns="columns_station"></u-picker>
 
 
    </view>
</template>
 
<script>
    import environments from '@/environments'
 
    import {
        mapState
    } from 'vuex'
    import EvanRadio from "../components/evan-radio/evan-radio.vue";
    import EvanRadioGroup from "../components/evan-radio-group/evan-radio-group.vue";
 
    export default {
 
        components: {
            EvanRadioGroup,
            EvanRadio
        },
 
        data() {
            return {
                id: '',
                refresh: false,
                api: '',
                dto: {
                    id: '',
                    pictures: [],
                    idCards: [],
                    cover: '',
                    idcardType: '1',
                    description: '',
                    address: '',
                    stationId: '',
                    stationName: '',
                    id: '',
                    userId: '',
                    name: '',
                    typeId: '',
                    typeName: '',
                    contactName: '',
                    contactTel: '',
                    province: '',
                    city: '',
                    region: '',
                },
                requireFields: [{
                        name: '店铺类型',
                        key: 'typeId'
                    },
                    {
                        name: '店铺名称',
                        key: 'name'
                    },
                    {
                        name: '店铺头像',
                        key: 'cover'
                    },
                    {
                        name: '联系人姓名',
                        key: 'contactName'
                    },
                    {
                        name: '联系方式',
                        key: 'contactTel'
                    },
                    {
                        name: '集货站',
                        key: 'stationId'
                    },
                    {
                        name: '地区',
                        key: 'province'
                    },
                    {
                        name: '地址',
                        key: 'address'
                    },
                    {
                        name: '店铺简介',
                        key: 'description'
                    },
                ],
                show_select_type: false,
                show_select_station: false,
                columns_types: [],
                columns_station: [],
 
                //审核方式
                shTypeList: [{
                        label: '身份证',
                        value: '1'
                    },
                    {
                        label: '营业执照',
                        value: '2'
                    }
                ],
                regionDataPlus: [],
            }
        },
        onLoad(options) {
            if (options.id) {
                this.id = options.id
                this.getDetail()
            } else {
                this.getCurrentInfo()
                //类型和集火站
                this.$http.request('get', '/api/station/list', {
                    params: {}
                }).then(res => {
                    var data = res.data
                    this.columns_station = [data || []]
                })
                //类型和集火站
                this.$http.request('get', '/api/supplier/type/list', {
                    params: {}
                }).then(res => {
                    var data = res.data
                    this.columns_types = [data || []]
                    // this.columns_types = (data || []).map(item => {
                    //     return {
                    //         ...item,
                    //         code: item.id,
                    //         text: item.name,
                    //     }
                    // })
                    // console.log('columns_types', this.columns_types)
                })
                this.init_area()
            }
 
        },
 
        methods: {
            PickArea(item, e) {
                console.log('PickArea', item, e)
                if (e.detail.value) {
                    this.dto.province = ''
                    this.dto.city = ''
                    this.dto.region = ''
                    if (e.detail.value.length == 2) {
                        if (!!e.detail.value[0])
                            this.dto.province = e.detail.value[0].value
                        if (!!e.detail.value[0])
                            this.dto.city = e.detail.value[0].value
                        if (!!e.detail.value[1])
                            this.dto.region = e.detail.value[1].value
                    } else if (e.detail.value.length <= 3) {
                        if (!!e.detail.value[0])
                            this.dto.province = e.detail.value[0].value
                        if (!!e.detail.value[1])
                            this.dto.city = e.detail.value[1].value
                        if (!!e.detail.value[2])
                            this.dto.region = e.detail.value[2].value
                    } else {
                        //说明有重复的
                        var plusnum = e.detail.value.length - 3
                        if (!!e.detail.value[plusnum + 0])
                            this.dto.province = e.detail.value[plusnum + 0].value
                        if (!!e.detail.value[plusnum + 1])
                            this.dto.city = e.detail.value[plusnum + 1].value
                        if (!!e.detail.value[plusnum + 2])
                            this.dto.region = e.detail.value[plusnum + 2].value
                    }
 
                    this.$forceUpdate()
 
                }
            },
            PickData(valueKey, nameKey, e) {
                // console.log('PickArea', item, e)
                if (e.detail.value) {
                    if (!!e.detail.value[0])
                        this.dto[valueKey] = e.detail.value[0].value || e.detail.value[0].id
                    if (nameKey) {
                        this.dto[nameKey] = e.detail.value[0].label || e.detail.value[0].name || e.detail.value[0].value
                    }
                    this.$forceUpdate()
 
                }
            },
            async init_area() {
                var a = this.$storage.getItem('cache_area')
                if (a) {
                    this.regionDataPlus = JSON.parse(a) || []
                } else {
                    const res = await this.$http.request('get', '/api/pub/china/area/json')
                    // console.log('area', JSON.parse(res.data))
                    this.regionDataPlus = res.data && JSON.parse(res.data.replaceAll('code', 'value').replaceAll(
                        'name',
                        'text')) || []
                    this.$storage.setItem('cache_area', JSON.stringify(this.regionDataPlus))
                }
 
            },
 
            select_type(e) {
                this.show_select_type = false
                this.dto.typeName = e.value[0].name
                this.dto.typeId = e.value[0].id
            },
            select_station(e) {
                this.show_select_station = false
                this.dto.stationName = e.value[0].name
                this.dto.stationId = e.value[0].id
            },
            async getCurrentInfo() {
                this.$message.showLoading()
                const {
                    code,
                    data
                } = await this.$http.request('get', "/api/current/supplier", {})
                if (code == 0) {
                    const dto = {
                        ...data,
 
                    }
                    if (!dto.pictures) {
                        dto.pictures = []
                    } else if (typeof dto.pictures == 'string') {
                        dto.pictures = JSON.parse(dto.pictures)
                    }
                    if (!dto.idCards) {
                        dto.idCards = []
                    } else if (typeof dto.idCards == 'string') {
                        dto.idCards = JSON.parse(dto.idCards)
                    }
                    if (!dto.idcardType) {
                        dto.idcardType = '1'
                    }
                    dto.userId = this.currentInfo.id
                    this.dto = dto
                }
 
                this.$message.hideLoading()
            },
            async getDetail() {
                this.$message.showLoading()
                const {
                    code,
                    data
                } = await this.$http.request('get', "/api/supplier/addOrUpdate/detail/" + this.id, {})
                if (code == 0) {
                    this.dto = {
                        ...data,
 
                    }
                    if (!this.dto.pictures) {
                        this.dto.pictures = []
                    } else if (typeof this.dto.pictures == 'string') {
                        this.dto.pictures = JSON.parse(this.dto.pictures)
                    }
                    if (!this.dto.idCards) {
                        this.dto.idCards = []
                    } else if (typeof this.dto.idCards == 'string') {
                        this.dto.idCards = JSON.parse(this.dto.idCards)
                    }
                }
 
                this.$message.hideLoading()
 
            },
            async submit() {
                for (var field of this.requireFields) {
                    if (!this.dto[field.key]) {
                        this.$message.showToast(`${field.name}信息未填写`)
                        return
                    }
                }
                if (this.dto.contactTel.length !== 11 && !this.dto.contactTel.startsWith('1')) {
                    this.$message.showToast(`联系方式需要为11位,且开头为1`)
                    return
                }
                if (isNaN(parseInt(this.dto.contactTel))) {
                    this.$message.showToast(`联系方式需要为11位手机号,格式错误`)
                    return
                }
                if (this.dto.idcardType == '1' && this.dto.idCards.length == 0) {
                    this.$message.showToast(`身份证信息未填写`)
                    return
                }
                if (this.dto.idcardType == '1' && this.dto.idCards.length < 2) {
                    this.$message.showToast(`身份证信息未填写完整,至少上传两张图片(正反面)`)
                    return
                }
                if (this.dto.idcardType == '2' && this.dto.pictures.length == 0) {
                    this.$message.showToast(`营业执照信息未填写`)
                    return
 
                }
 
                await this.$message.confirm(`是否确定提交/修改店铺信息`)
 
 
                var dto = {
                    ...this.dto,
                }
                this.$message.showLoading()
                const re = await this.$http.request('post', '/api/supplier/addOrUpdate', {
                    data: dto
                })
                this.$message.hideLoading()
                if (re.code == 2000 || re.code == 0) {
                    this.$message.showToast('操作成功')
                    //需要标记加一下
                    this.$store.dispatch('sign_add', 'info');
                    this.$store.dispatch('getCurrentInfo')
 
                    this.backpage()
                } else {
                    console.log('error re', re)
                    if (re.code === 30000 && Array.isArray(re.msg)) {
                        this.$message.showToast('字段未填写完整')
 
                    }
                }
            },
 
            async deleteImg(key, index) {
                await this.$message.confirm('是否确认删除此图片')
                if (Array.isArray(this.dto[key])) {
                    this.dto[key].splice(index, 1)
 
                } else {
                    this.dto[key] = ''
                }
                this.$forceUpdate()
            },
            uploadIcon(key) {
                const that = this
                uni.chooseImage({
                    count: 1, // 最多可以选择的图片张数,默认9
                    sizeType: ['original', 'compressed'], //original 原图,compressed 压缩图,默认二者都有
                    sourceType: ['camera', 'album'], //album 从相册选图,camera 使用相机,默认二者都有。如需直接开相机或直接选相册,请只使用一个选项
                    success: function({
                        errMsg,
                        tempFiles
                    }) {
                        if (errMsg === 'chooseImage:ok') {
                            // console.log(tempFiles[0])
                            if (tempFiles[0].size > 1024 * 1024 * 5) {
                                that.$message.confirm('图片最多支持5M大小,超出大小限制')
                                return
                            }
                            that.$message.showLoading()
                            that.$http.upload(tempFiles[0].path).then(async res => {
                                var pic = res.data && res.data.length > 0 && res.data[
                                    0] || {}
                                that.$message.hideLoading()
                                if (Array.isArray(that.dto[key])) {
                                    that.dto[key].push(pic || '')
 
                                } else {
                                    that.dto[key] = (pic || {}).url || ''
 
                                }
                                that.$forceUpdate()
                            }).catch(res => {
                                that.$message.hideLoading()
 
                            })
                        }
                    }
                })
            },
 
        },
        computed: {
            ...mapState(['currentInfo'])
        },
    }
</script>
 
<style lang="scss" scoped>
    .banner-img {
        width: 96rpx;
        height: 96rpx;
        border-radius: 4rpx;
        border: 2rpx dashed #CECECE;
    }
 
    .form-item {
        // padding: 40rpx;
        border-bottom: 2rpx solid #F3F3F3;
        display: flex;
        // height: 100px;
 
        .label {
            width: 300rpx;
            line-height: 60px;
 
        }
 
        .flex {
            line-height: 60px;
 
            .flex1 {
                flex: 1;
                text-align: center;
                color: var(--selfblue)
            }
 
 
        }
    }
 
    .form-item.bottom-border-no {
        border-bottom: none;
    }
 
    .container-page {
        padding: 40rpx;
        background-color: #FFFFFF;
        // min-height: calc(100vh - 80rpx);
        min-height: 100vh;
    }
 
    .style {
        width: fit-content;
        margin: 0 auto;
        line-height: 64rpx;
        border-radius: 8rpx;
        padding-left: 20rpx;
        padding-right: 20rpx;
        // padding-top: 5rpx;
        // padding-bottom: 5rpx;
        border: 2rpx solid var(--selfblue);
        background-color: var(--selfbluebg);
        min-width: 100rpx;
    }
 
 
    .style-1 {
        border: 1px solid rgb(122, 187, 255);
        border: 1px solid #409EFF;
        color: #409EFF;
        background-color: rgb(240, 247, 255);
    }
 
    .style-2 {
        border: 1px solid rgb(255, 184, 78);
        border: 1px solid #FE9044;
        color: #FE9044;
        background-color: rgb(255, 247, 235);
    }
 
    .style-3 {
        border: 1px solid #19be6b;
        color: #19be6b;
        background-color: rgb(231, 244, 238);
    }
 
    .style-4 {
        border: 1px solid #F56c6c;
        color: #F56c6c;
        background-color: rgb(254, 243, 243);
    }
 
    /deep/ {
        .evan-radio-group {
            display: flex;
        }
 
        .evan-radio {
            margin-right: 12rpx;
        }
    }
</style>