lin
2026-04-28 3749950e6106c9622e5d6482c61b5a80dbcb31a2
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
<template>
    <view>
        <view class="" v-if="addrData.length > 0">
            <view class="addrItem" v-for="(item, index) in addrData">
                <view class="" @tap="setAddrCookie(item)">
                    <view class="addr-v">
                        <text>{{item.realname}}</text>
                        <text>{{item.phone}}</text>
                    </view>
                    <view class="addr-v">{{item.area}}({{item.addr}})</view>
                    <image class="rgt" src="/static/imgs/right.png" mode=""></image>
                </view>
                <view class="addr-c">
                    <view class="addr-df">
                        默认:
                        <switch @change="defChange" :data-id="item.id" v-if="item.isdef == 0" color="#e3b400" style="transform:scale(0.7)"/>
                        <switch @change="defChange" :data-id="item.id" v-else checked color="#e3b400" style="transform:scale(0.7)"/>
                    </view>
                    <view class="addr-c-main">
                        <view class="addr-c-c" @tap="$util.goPages('/pages/addAddr/addAddr?id=' + item.id)">
                            <image src="/static/imgs/edit.png" mode=""></image>
                            <text>编辑</text>
                        </view>
                        <view class="addr-c-c" @tap="delConfirm(item.id, index)">
                            <image src="/static/imgs/del.png" mode=""></image>
                            <text>删除</text>
                        </view>
                    </view>
                </view>
            </view>
        </view>
        <view class="noData" v-else>
            <image src="/static/imgs/noData.png" mode=""></image>
            <view class="">没有地址信息</view>
        </view>
        <view class="addrBtn" @tap="addAddr">添加地址</view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                pageIndex: 1,
                pageSize: 200,
                addrData: [],
                backUrl: '',
            }
        },
        onLoad(op) {
            this.backUrl = op.backUrl ? op.backUrl : ''
            this.getAddress()
        },
        methods: {
            //选择地址
            setAddrCookie (e) {
                if(this.backUrl != ''){
                    uni.setStorageSync('choose-address', JSON.stringify(e))
                    this.$util.goPages(this.backUrl)
                }
            },
            addAddr () {
                let url = '/pages/addAddr/addAddr'
                if(this.backUrl != ''){
                    url = url + '?backUrl=' + this.backUrl
                }
                this.$util.goPages(url)
            },
            defChange (e) {
                let id = e.currentTarget.dataset.id
                this.$util.post('Address/setDef', {id: id}).then(res => {
                    if(res.code == 1){
                        for(let i in this.addrData){
                            if(this.addrData[i].id != id){
                                this.addrData[i].isdef = 0
                            }
                        }
                    }
                })
            },
            getAddress () {
                this.$util.post('Address/getAddress', {pageIndex: this.pageIndex, pageSize: this.pageSize}).then(res => {
                    if(res.code == 1){
                        this.addrData = res.data.list
                    }
                })
            },
            delConfirm (id, idx) {
                let t = this
                uni.showModal({
                    title: '温馨提示',
                    content: '是否删除地址信息?',
                    success: function (res) {
                        if (res.confirm) {
                            t.delAddr(id, idx)
                        }
                    }
                })
            },
            delAddr(id, idx){
                let t = this
                t.$util.post('Address/delAddr', {id: id}).then(res => {
                    if(res.code == 1){
                        uni.showToast({
                            title: res.msg || '删除成功',
                            icon: 'success'
                        })
                        this.addrData.splice(idx, 1)
                    } else {
                        uni.showToast({
                            title: res.msg || '删除失败',
                            icon: 'error'
                        })
                    }
                })
            }
        }
    }
</script>
 
<style>
@import url(/static/css/address.css);
</style>