myAddress.vue
4.2 KB
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
<template>
<!-- 我的地址列表 -->
<view>
<u-navbar placeholder title="我的地址" bgColor="#fff" :autoBack="true"></u-navbar>
<view class="mainBox">
<view class="addressBox" v-for="item in addressList" :key="item.id" @click="checkAddress(item)">
<view class="topBox flexJ">
<view class="nameBox flexA">
<image src="/static/mineIc/redAddress.png" mode=""></image>
<view class="name">{{ item.name }}</view>
<text>{{ item.mobile }}</text>
</view>
<view class="rightIc flexA">
<image @click.stop="del(item.id)" src="/static/mineIc/delAddress.png" mode=""></image>
<image @click.stop="newAdd(0, item.id)" src="/static/mineIc/edit.png" mode=""></image>
</view>
</view>
<view class="area">
{{ item.diqu }}
<test>{{ item.address }}</test>
</view>
</view>
</view>
<!-- 地址列表为空 -->
<view class="addressNull flexV" v-if="!addressList">
<image src="/static/mineIc/addressNull.png" mode=""></image>
<text>暂无收货地址</text>
</view>
<view class="btnBox iosAuto">
<view class="btn flexC" @click="newAdd(1)">新建收货地址</view>
</view>
</view>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { onShow, onLoad } from '@dcloudio/uni-app'
import { getAdressList, getDelAdres } from '@/api/'
const addressList = ref([])
onShow(() => {
addressList.value.splice(0)
getAdressLists() //地址列表
})
onLoad(e => {
isCheck.value = e.isCheck //是否选这地址
})
//type==0 修改地址 - 新建地址
const newAdd = (type, id) => {
console.log(type, id, 'type id是什么')
uni.navigateTo({
url: `/pages/mine/newAddress?id=${type == 0 ? id : ''}`
})
}
let isCheck = ref(0)
// 选这地址
const checkAddress = item => {
if (isCheck.value == 1) {
const pop = getCurrentPages().pop()
pop.$vm.getOpenerEventChannel().emit('steBack', item)
uni.navigateBack()
}
}
const del = id => {
uni.showModal({
title: '提示',
content: '确认删除此地址吗',
success: function (res) {
if (res.confirm) {
getDelAdress(id)
}
}
})
}
// 删除地址
const getDelAdress = async ids => {
try {
const res = await getDelAdres(ids)
uni.showToast({ title: '删除成功!', icon: 'none' })
getAdressLists()
console.log('getDelAdres', res)
// 保存数据
} catch (err) {
console.log('getDelAdres', err)
}
}
// 获取地址列表
const getAdressLists = async () => {
try {
const res = await getAdressList()
addressList.value = res
let defaultAdres = res.find(item => item.is_default == 1) //默认地址
uni.setStorageSync('defaultAdres', defaultAdres)
console.log('getAdressList', res)
// 保存数据
} catch (err) {
uni.showToast({ title: err, icon: 'none' })
console.log('getAdressList', err)
}
}
</script>
<style lang="scss">
.mainBox {
background: #f8f9feff;
.addressBox {
width: 100%;
padding: 44rpx 32rpx;
box-sizing: border-box;
background: #fff;
margin-bottom: 12rpx;
.topBox {
margin-bottom: 18rpx;
.nameBox {
image {
width: 32rpx;
height: 32rpx;
}
.name {
color: #000000cc;
font-size: 32rpx;
font-weight: 700;
margin: 0 20rpx;
}
text {
color: #000000cc;
font-size: 28rpx;
font-weight: 700;
}
}
.rightIc {
image {
margin-left: 32rpx;
width: 36rpx;
height: 36rpx;
}
}
}
.area {
color: #00000066;
font-size: 26rpx;
text {
margin-left: 8rpx;
}
}
}
}
.addressNull {
margin-top: 266rpx;
image {
width: 266rpx;
height: 266rpx;
}
text {
color: #00000066;
font-size: 26rpx;
}
}
.btnBox {
position: fixed;
left: 0;
bottom: 0;
background: #fff;
width: 100%;
height: 120rpx;
.btn {
width: 686rpx;
height: 88rpx;
border-radius: 12rpx;
color: #ffffffff;
font-size: 32rpx;
font-weight: 700;
margin: 0 auto;
background: linear-gradient(139deg, #fb753cff 0%, #fb3e3cff 100%);
}
}
</style>