xuxy
2024-07-10 98f4b7ec4164ec1c6798c8c4188b93f4ce48ec46
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
<template>
    <!-- 收获地址列表 -->
    <view class="p15 container-address">
        <no-data v-if="!list||list.length==0" style="width: 100%;"></no-data>
 
        <!-- 循环 -->
        <view v-for="(item,index) of list" :key="index" class="location-each">
            <view class="flex">
                <view class="container-info">
                    <view class="flex">
                        <view class="name">{{item.name || '-'}}</view>
                        <view class="tel">{{item.tel||'-'}}</view>
                    </view>
                    <view class="address">
                        {{item.address}}
 
                    </view>
                </view>
                <!-- <view class="h-line"></view> -->
                <view class="edit" @click="()=>{
                    this.submitForm = {
                        ...item
                    }
                    openAddressForm()
                }">
                    <uni-icons type="compose" class="icon" color="#666666"></uni-icons>
                </view>
            </view>
            <view class="v-line"></view>
            <view class="flex">
                <view class="flex" @click="changeDefaultAddress(item,index)">
                    <!-- <label class="radio flex" > -->
                    <!--         <radio value="r1" :checked="item.defaulted" disabled
                            style="transform:scale(0.6)" v-if="item.defaulted" />
                        <radio value="r1" 
                            style="transform:scale(0.6)" :checked="item.defaulted" v-if="!item.defaulted"  @change="changeDefaultAddress(item,index)"/>    
                             -->
 
                    <!-- </label> -->
                    <view class="radio m-t-2 m-r-10" :class="[item.defaulted?'select':'']">
 
                    </view>
                    <span class="desc">{{item.defaulted?'默认地址:':'当前地址:'}}{{item.schoolAreaStr||''}}
                        {{item.blockStr||''}}
                        {{item.room||''}}</span>
                    <!-- 当前地址/默认地址勾选 -->
                </view>
                <view class="desc del t-red" @click="deleteAddress(item)">
                    删除
                </view>
                <view class="desc del t-green m-l-10" v-if="source==='select'" @click="selectAddress(item)">
                    选择此地址
                </view>
            </view>
 
        </view>
        <view style="height: 92rpx;width: 690rpx;">
            &nbsp;
        </view>
        <view class="button-green button-fixed-bottom" style="width: 690rpx;line-height: 92rpx;height: 92rpx;" @click=" ()=>{
                delete this.submitForm.id
                this.submitForm['name'] = ''
                this.submitForm['tel'] = ''
                this.submitForm['tel'] = ''
                this.submitForm['area'] = ''
                
                openAddressForm()
            }">添加收货地址</view>
 
        <uni-popup ref="popup_form" type="top" :mask-click="false">
            <view class="popup-address-form">
                <view class="close-parent">
                    {{submitForm.id?'新增':'编辑'}}收货地址
                    <uni-icons class="close" type="closeempty" @click="closeAddressForm"></uni-icons>
                </view>
                <!--收货人、手机号、校区、详细地址 -->
                <view class="submit form">
                    <view class="form-item">
                        <view class="form-item-label require">
                            收货人
                        </view>
                        <view class="form-item-value">
                            <input v-model="submitForm.name" placeholder="请输入收货人" class="form-input"></input>
                        </view>
                    </view>
                    <view class="form-item">
                        <view class="form-item-label require">
                            请选择收获地址
                        </view>
                        <view class="form-item-value">
                            <input v-model="submitForm.room" placeholder="请选择收获地址" disabled class="form-input"></input>
                            <!-- todo 点击定位 -->
                        </view>
                    </view>
                    <view class="form-item">
                        <view class="form-item-label require">
                            详细地址
                        </view>
                        <view class="form-item-value">
                            <input v-model="submitForm.address" placeholder="请输入详细地址" class="form-input"></input>
 
                        </view>
                    </view>
                    <view class="form-item">
                        <view class="form-item-label">
                            是否默认
                        </view>
                        <view class="form-item-value">
                            <radio value="r1" :checked="submitForm.defaulted"
                                @click="submitForm.defaulted=!submitForm.defaulted"
                                style="transform:scale(0.6);margin-top: -8rpx;" />
                        </view>
                    </view>
                </view>
 
                <view class="button-green m-t-15" @click="saveOrUpdateAddress">保存</view>
            </view>
        </uni-popup>
 
    </view>
</template>
 
<script>
    export default {
        async onPullDownRefresh() {
            this.page.current = 0
            await this.getList()
            uni.stopPullDownRefresh()
        },
        async onLoad(options) {
            // this.list = [{}, {}]
            this.source = options.source || ''
            this.listApi = '/api/address/customer/list'
            await this.getList()
 
        },
        data() {
            return {
                source: '',
                submitForm: {
                    name: '',
                    tel: '',
                    address: '',
                    schoolArea: '',
                    block: '',
                    room: '',
                    defaulted: false
                },
            };
        },
        methods: {
            async changeDefaultAddress(item, index) {
                if (item.defaulted) {
                    return
                }
                this.$nextTick(() => {
                    // item.defaulted = false
                    // this.$set(item,'defaulted',false)
                    this.$message.confirm('确定设置此地址为默认地址吗').then(async res => {
                        this.$message.showLoading()
                        var {
                            code
                        } = await this.$http.request('post', '/api/address/customer/default/' +
                            item.id, {})
                        this.$message.hideLoading()
                        if (code == 0) {
                            for (var dto of this.list) {
                                dto.defaulted = false
                            }
                            this.$message.showToast('设置成功')
                            item.defaulted = true
                            this.$store.commit('setDefaultAddress', {
                                ...item
                            })
 
                        }
                    }, err => {
                        this.$nextTick(() => {
                            this.list[index].defaulted = false
                            this.$forceUpdate()
                            console.log('err', err, this.list[index])
                        })
 
 
                    })
                })
            },
            async selectAddress(item) {
                await this.$message.confirm('确定选择此地址作为收获地址吗')
                //携带,然后返回
                this.$store.commit('setDefaultAddress', {
                    ...item
                })
                this.backpage()
            },
            async deleteAddress(item) {
                await this.$message.confirm('确定删除此地址吗')
                this.$message.showLoading()
                var {
                    code
                } = await this.$http.request('get', '/api/address/customer/delete/' + item.id, {})
                this.$message.hideLoading()
                if (code == 0) {
                    this.$message.showToast('删除成功')
                    setTimeout(() => {
                        this.page.current = 1
                        this.getList()
                    }, 500)
                }
            },
            async openAddressForm() {
                if (this.submitForm.id) {
                    this.$message.showLoading()
                    var {
                        data
                    } = await this.$http.request('get', '/api/address/customer/get/' + this.submitForm.id, {})
 
 
                    if (data) {
                        this.submitForm = {
                            ...this.submitForm,
                            ...data
                        }
                        this.blockIndex = -1
                        this.schoolIndex = -1
                    }
                    this.$message.hideLoading()
                } else {
                    this.submitForm = {
                        name: this.currentInfo && this.currentInfo.nickName || '',
                        tel: this.currentInfo && this.currentInfo.tel || '',
                        address: '',
                        schoolArea: '',
                        block: '',
                        room: '',
                        defaulted: false
                    }
                    this.schoolIndex = -1
                    this.blockIndex = -1
                    this.blocks = []
                }
 
                this.$refs.popup_form.open()
 
            },
            closeAddressForm() {
                this.$refs.popup_form.close()
 
            },
            async saveOrUpdateAddress() {
                if (!this.checkFormValues(this.submitForm, ['tel', 'name', 'address'])) {
                    this.$message.showToast('字段未填写完整')
                    return
                }
                this.$message.showLoading()
                const {
                    code
                } = await this.$http.request('post', '/api/address/customer/' + (this.submitForm.id ? 'edit' :
                    'new'), {
                    data: this.submitForm
                })
                this.$message.hideLoading()
                if (code == 0) {
                    this.$refs.popup_form.close()
                    this.$message.showToast(this.submitForm.id ? '修改成功' : '新增成功')
 
                    setTimeout(() => {
                        this.page.current = 1
                        this.getList()
                    }, 300)
                }
            },
 
        }
    }
</script>
 
<style lang="scss" scoped>
    .container-address {
        .popup-address-form {
            background: #FFFFFF;
            border-radius: 16rpx;
            // width: 690rpx;
            height: 882rpx;
            margin-top: 120rpx;
            margin-left: 30rpx;
            margin-right: 30rpx;
            padding: 24rpx 36rpx;
 
            .submit {
                margin-top: 30rpx;
 
                .form-input {
                    height: 36rpx;
                    line-height: 36rpx;
                }
            }
        }
 
        .location-each {
            background: #FFFFFF;
            border-radius: 16rpx;
            margin-bottom: 24rpx;
            padding: 36rpx;
 
            .name {
                font-size: 32rpx;
                color: #000000;
                line-height: 44rpx;
                text-align: left;
                font-style: normal;
            }
 
            .tel {
                font-size: 28rpx;
                color: #666666;
                line-height: 40rpx;
                text-align: left;
                font-style: normal;
                padding-top: 4rpx;
                margin-left: 20rpx;
            }
 
            .address {
                font-size: 24rpx;
                color: #000000;
                line-height: 34rpx;
                text-align: left;
                font-style: normal;
            }
 
            .desc {
                font-size: 24rpx;
                color: #666666;
                line-height: 34rpx;
                text-align: left;
                font-style: normal;
            }
 
            .del {
                // vertical-align: baseline;
                margin-left: auto;
                margin-right: 6rpx;
                margin-top: 4rpx;
            }
 
            .container-info {
                max-width: 540rpx;
            }
 
            .h-line {
                width: 2rpx;
                height: 46rpx;
                background-color: #EEEEEE;
                margin-left: 28rpx;
                margin-right: 24rpx;
            }
 
            .v-line {
                width: 638rpx;
                height: 2rpx;
                // border: 2rpx solid #EEEEEE;
                background-color: #EEEEEE;
                margin-top: 24rpx;
                margin-bottom: 24rpx;
            }
 
            .edit {
                // min-width: 80rpx;
                width: fit-content;
                margin-left: auto;
                margin-right: 0rpx;
                display: flex;
                position: relative;
 
                .icon {
                    // margin: 0 auto;
                    // mar
                    margin-left: auto;
                    margin-right: auto;
                    margin-top: 20rpx;
                    display: block;
 
                }
            }
 
            .edit::before {
                content: " ";
                width: 2rpx;
                height: 46rpx;
                background-color: #EEEEEE;
                position: absolute;
                left: -24rpx;
                top: 20rpx;
            }
        }
    }
</style>