address.vue
4.8 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
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
<template>
<view class="page">
<view class="box">
<view class="item" v-for="(item,index) in addresslist" :key="index" @click="selectaddress(item)">
<view class="left">
<view class="top">
<text class="name">{{item.name}}</text>
<text class="tel">{{item.phone}}</text>
</view>
<view class="address">{{item.province_name}}{{item.city_name}}{{item.county_name}}{{item.address}}</view>
</view>
<view class="flexone">
<view class="delimg" @click.stop="deleteaddress(item)">
<image src="../../static/del.png" mode=""></image>
</view>
<view class="right" @click.stop="editaddress(item)">
<image src="../../static/edit.png" mode="widthFix" />
</view>
</view>
</view>
</view>
<view class="btn" @click="addaddress">新增收货地址</view>
</view>
</template>
<script>
import app from "../../App.vue";
export default {
data() {
return {
addresslist: [],
showaddress: []
}
},
onLoad() {
},
methods: {
addaddress() {
uni.navigateTo({
url: "/pages/usercenter/addAddress"
})
},
// 获取地址列表
getaddresslist() {
let that = this;
var url = 'user_address/get_list';
var params = {
page: that.page,
pageNum: 10
}
console.log(params)
app.post(url, params, "post").then((res) => {
console.log(res);
this.addresslist = this.addresslist.concat(res.data.data);
this.showaddress = res.data.data;
console.log(that.addresslist)
}).catch((err) => {
console.log(err)
})
},
// 删除地址
deleteaddress(item){
let that = this;
uni.showModal({
title: '提示',
content: '是否删除该地址',
success: function (res) {
if (res.confirm) {
var url = 'user_address/delete';
var params = {
user_address_id:item.id
}
console.log(params)
app.post(url, params, "post").then((res) => {
uni.showToast({
title:"删除成功",
icon:"none"
})
that.page=1;
that.addresslist=[]
that.getaddresslist()
}).catch((err) => {
console.log(err)
})
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
},
// 选择地址
selectaddress(item) {
uni.setStorageSync("addressitem",item)
uni.navigateBack({
checked:true
})
},
// 编辑地址
editaddress(item) {
var newitem = JSON.stringify(item);
console.log(item)
uni.navigateTo({
url: '/pages/usercenter/addAddress?id=' + item.id + '&type=' + 1 + '&item=' + newitem
})
},
},
onShow() {
this.page = 1;
this.addresslist = []
this.getaddresslist();
},
onReachBottom: function() {
let newpage = this.data.page;
newpage++;
this.setData({
page: newpage
})
if (this.showaddress.length == 0) {
uni.showToast({
title: '没有更多了~',
icon: "none"
})
} else {
this.getaddresslist();
}
},
}
</script>
<style>
page {
background: #F7F7F7;
}
.box {
background: #fff;
margin-top: 16rpx;
padding: 0 32rpx;
box-sizing: border-box;
}
.delimg{
width:32rpx;
height:32rpx;
font-size: 0;
margin-right:10rpx;
}
.item {
padding: 34rpx 0;
box-sizing: border-box;
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid #EDEDED;
}
.left {
width: 590rpx;
display: flex;
flex-wrap: wrap;
align-items: center;
font-size: 28rpx;
font-family: PingFangHK-Regular, PingFangHK;
font-weight: 400;
color: rgba(8, 18, 31, 1);
}
.top {
width: 100%;
display: flex;
align-items: center;
}
.name {
font-size: 32rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: rgba(6, 18, 32, 1);
}
.tel {
font-size: 28rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: rgba(61, 69, 76, 1);
margin-left: 48rpx;
}
.address {
width: 100%;
font-size: 28rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: rgba(61, 69, 76, 1);
margin-top: 20rpx;
}
.right {
width: 90rpx;
font-size: 28rpx;
font-family: PingFangHK-Regular, PingFangHK;
font-weight: 400;
color: rgba(61, 69, 76, 1);
display: flex;
align-items: center;
justify-content: flex-end;
}
.right image {
width: 32rpx;
}
.btn {
width: 686rpx;
height: 84rpx;
background: rgba(194, 148, 69, 1);
border-radius: 8rpx;
font-size: 32rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: rgba(255, 255, 255, 1);
display: flex;
justify-content: center;
align-items: center;
position: fixed;
bottom: 30rpx;
left: 32rpx;
/* margin: 300rpx auto; */
}
</style>