Liuyi
2024-11-12 0ed8e370659ad4e0582301ae31cfa155da114590
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
<script setup>
    import { ref ,onMounted } from 'vue'
    import { searchAddress,editAddress,setAddressDefaultApi,deleteAddressApi } from '../../api/index.js';
    import { onShow } from "@dcloudio/uni-app"
    const addressList = ref([])
    async function getAddressList(){
        await searchAddress({limit:100,page:1}).then((res) =>{
            if(res.code == 200){
                res.data.list.forEach((item) =>{
                     res.data.list.forEach((item) =>{
                         item.isDefault = item.isDefault == 1 ? true : false
                        item.addressWhole = item.regionName.replace(/[,#]/g,' ') + item.address
                     })
                })
                addressList.value = res.data.list
            }
        })
    }
    async function setDefault(isDefault,id,index1){
        if(isDefault == true){
            console.log('true')
        }else{
            console.log('false')
            await setAddressDefaultApi(id).then((res) =>{
                if(res.code == 200){
                    getAddressList()
                }else{
                    uni.showToast({
                        title: '设置失败',
                        image: '../../static/images/other/success.svg',
                        duration:500     
                    })
                }
            })
        }
    }
    async function deleteAddress(id){
        await deleteAddressApi(id).then((res) =>{
            if(res.code == 200){
                uni.showToast({
                    title: '删除成功',
                    image: '../../static/images/other/success.svg',
                    duration:500     
                })
                getAddressList()
            }
        })
    }
    
    function navToModify(id){
        uni.navigateTo({
            url:`/pages/addressAdd/index?id=${id}`
        })
    }
    function navToAdd(){
        let id = ''
        uni.navigateTo({
            url:`/pages/addressAdd/index?id=${id}`
        })
    }
    onShow(async() =>{
        getAddressList()
    })
</script>
<template>
    <view class="container">
        <navbar title = '地址管理'></navbar>
        <view class="content">
            <view class="main">
                <block v-for="(item,index) in addressList">
                    <view class="address-item">
                        <view class="user-info">
                            <text>{{item.userName}}</text>
                            <text>{{item.userPhone}}</text>
                        </view>
                        <view class="address-info">{{item.addressWhole}}</view>
                        <view class="address-divide"></view>
                        <view class="handel">
                            <view class="handel-left">
                                 <radio color = "#4996E3" :value="item.id" :checked="item.isDefault" @click="setDefault(item.isDefault,item.id,index)"></radio>
                                <text>设为默认</text>
                            </view>
                            <view class="handel-right">
                                <view @click="navToModify(item.id)">
                                    <image src="../../static/images/address/edit.png" alt=""></image>
                                    <text>编辑</text>
                                </view>
                                <view @click="deleteAddress(item.id)">
                                    <image src="../../static/images/address/delete.png" alt=""></image>
                                    <text>删除</text>
                                </view>
                            </view>
                        </view>
                    </view>
                </block>
            </view>
            <!-- <view class="subBtn" @click="navToAdd()">新增收货地址</view> -->
            <view class="subBtn">新增收货地址</view>
        </view>
    </view>
</template>
 
<style lang="scss">
    .container{
        width: 100%;
        height: 100vh;
        .content{
            width: 100%;
            height:calc(100vh - 176rpx - 20rpx);
            background:linear-gradient(to top,#FFFFFF,#E8EFFF);
            padding-top:20rpx;
            .main{
                width: 686rpx;
                height:1162rpx;
                margin:0 auto;
                overflow-y: scroll;
                // background-color: #a6ffd3;
                .address-item{
                    width:100%;
                    height:254rpx;
                    padding:20rpx 0 26rpx;
                    box-sizing: border-box;
                    margin-bottom:20rpx;
                    background: #FFFFFF;
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;
                    align-items:flex-start;
                    .user-info{
                        width:100%;
                        padding: 0 65rpx;
                        box-sizing: border-box;
                        display: flex;
                        justify-content: space-between;
                        font-weight: 300;
                        font-size: 32rpx;
                        color: #000000;
                    }
                    .address-info{
                        padding: 0 65rpx;
                        box-sizing: border-box;
                        font-weight: 300;
                        font-size: 28rpx;
                        color: #646464;
                    }
                    .address-divide{
                        width: 100%;
                        height: 1rpx;
                        border-bottom:2rpx dashed #D5DDE0;
                    }
                    .handel{
                        width: 100%;
                        padding: 0 65rpx;
                        box-sizing: border-box;
                        display: flex;
                        justify-content: space-between;
                        align-items:flex-start;
                        .handel-left{
                            radio{
                                color: #000000;
                            }
                            text{
                                font-weight: 300;
                                font-size: 32rpx;
                                color: #0088FF;
                                line-height:28rpx;
                            }
                        }
                        .handel-right{
                            width:35%;
                            height:48rpx;
                            display: flex;
                            justify-content:space-between;
                            align-items:center;
                            view{
                                display: flex;
                                align-items:center;
                                image{
                                    width:28rpx;
                                    height:28rpx;
                                    margin-right:10rpx;
                                }
                                text{
                                    font-weight: 300;
                                    font-size: 24rpx;
                                    color: #373737;
                                }
                            }
                        }
                    }
                }
            }
       .subBtn{
           width:686rpx;
           height: 98rpx;
           // margin-top:100rpx;
           padding:0 26rpx;
           box-sizing:border-box;
           background-color:#5EA1FA;
           border-radius:50rpx;
           font-weight: 300;
           font-size: 36rpx;
           color: #FFFFFF;
           line-height:98rpx;
           text-align: center;
           letter-spacing: 2rpx;
           margin: 100rpx auto 0;
       }
       }
   }
</style>