add-address.vue
5.6 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
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
<template>
<view class="content">
<view class="outerBox">
<view class="itemBox" @click="goMap">
定位
</view>
<view class="itemBox">
<view class="itemBtn">姓名</view>
<input type="text" :value="nameVlaue" placeholder="请输入收件人姓名" @input="nameInput" />
</view>
<view class="itemBox">
<view class="itemBtn">手机号</view>
<input type="number" maxlength="11" :value="numVlaue" placeholder="请输入手机号" @input="numInput" />
</view>
<view class="itemBox">
<view class="itemBtn">所在地区</view>
<picker mode="region" @change="bindRegionChange" :value="AreaList">
<view class="choose-item">
<text class="picker-text">{{addVlaue}}</text>
</view>
</picker>
</view>
<view class="itemBox">
<view class="itemBtn">小区大厦</view>
<input type="text" :value="detailSmall" placeholder="请填写你的小区" @input="smallPlotInput" />
</view>
<view class="itemBox">
<view class="itemBtn">门牌号</view>
<input type="text" :value="detailAdd" placeholder="街道门牌、楼层房间号等信息" @input="detailInput" />
</view>
</view>
<view class="defalutAddBox">
<view class="defalutAdd">
设为默认收货地址
</view>
<switch :checked="checked" @change="onSelCheck" style="transform: scale(0.7);" />
</view>
<view class="saveBtn" @click="save">
添加
</view>
</view>
</template>
<script>
import request from '../../utils/request.js'
export default {
data() {
return {
//收件人
nameVlaue: '',
//手机号
numVlaue: '',
//所在地区
addVlaue: '请选择所在地区',
//小区
detailSmall: '',
//详细地址
detailAdd: '',
checked: true,
//区号
QuHao: '',
//地址id
address:'', //选取地址
id: '',
lat:'', //经纬度
lot:'',
AreaList: [
[],
[],
[]
]
}
},
onLoad(options) {
console.log(options)
this.id = options.id
this.GetArea()
},
onShow() {
if (this.id) {
this.GetAddress()
}
},
methods: {
//跳转地图
goMap() {
let that = this
uni.chooseLocation({
success: function(res) {
console.log(res,'res')
that.address = res.name
that.lat = res.latitude
that.lot = res.longitude
that.detailSmall=res.name
}
});
},
//删除地址
del() {
request.postRequest('/api/address/del', {
id: this.id
}, data => {
if (data.code == 1) {
uni.showToast({
title: '删除成功',
duration: 2000,
icon: 'success'
})
setTimeout(() => {
uni.navigateBack({
delta: 1
})
}, 1500)
}
})
},
bindRegionChange(e) {
this.QuHao = e.mp.detail.code[2]
this.addVlaue = e.detail.value[0] + '' + e.detail.value[1] + '' + e.detail.value[2]
},
//获取省市区
GetArea() {
request.get('/api/address/area', {}).then(res => {
if (res.code == 1) {
this.AreaList[0] = res.data.provinceData
this.AreaList[1] = res.data.cityData
this.AreaList[2] = res.data.areaData
}
}).catch(err => {})
},
//获取地址详情
GetAddress() {
request.get('/api/address/info', {
id: this.id
}).then(res => {
if (res.code == 1) {
this.nameVlaue = res.data.consignee
this.numVlaue = res.data.phone
this.detailAdd = res.data.address
this.addVlaue = res.data.province_name + res.data.city_name + res.data.area_name
}
}).catch(err => {
})
},
//是否默认地址
onSelCheck() {
this.checked = !this.checked
},
nameInput(e) {
this.nameVlaue = e.detail.value
},
numInput(e) {
this.numVlaue = e.detail.value
},
addInput(e) {
this.addVlaue = e.detail.value
},
detailInput(e) {
this.detailAdd = e.detail.value
},
smallPlotInput(e) {
this.detailSmall = e.detail.value
},
save() {
let postData = {
consignee: this.nameVlaue,
phone: this.numVlaue,
area_id: this.QuHao,
is_default: this.checked ? 1 : 0,
address: this.detailAdd,
id: this.id,
latitude:this.lat,
longitude:this.lot
}
request.post('/api/address/edit', postData).then(res => {
if (res.code == 1) {
uni.showToast({
title: '操作成功',
duration: 2000,
icon: 'success'
})
setTimeout(() => {
uni.navigateBack({
delta: 1
})
}, 1500)
}
}).catch(err => {
})
}
}
}
</script>
<style>
.choose-item {
width: 100%;
}
.picker-text {
color: #808080;
font-size: 28rpx;
}
.content {
padding: 32rpx;
box-sizing: border-box;
background: #fafafb;
min-height: 100vh;
}
.outerBox {
background-color: #fff;
}
.itemBox {
display: flex;
padding: 26rpx 32rpx;
box-sizing: border-box;
border-bottom: 2rpx solid #F7F8FA;
}
.itemBtn {
font-size: 28rpx;
color: #323233;
width: 180rpx;
}
input {
font-size: 28rpx;
}
.defalutAddBox {
padding: 26rpx 32rpx;
box-sizing: border-box;
margin-top: 26rpx;
background-color: #fff;
border-radius: 16rpx;
display: flex;
font-size: 28rpx;
justify-content: space-between;
align-items: center;
}
.saveBtn {
width: 686rpx;
height: 88rpx;
opacity: 1;
background: #FF2F2F;
border-radius: 8rpx;
line-height: 88rpx;
text-align: center;
font-size: 28rpx;
color: #fff;
margin-top: 128rpx;
}
.delBtn {
width: 686rpx;
height: 88rpx;
opacity: 1;
border: 2rpx solid #c8c9cc;
border-radius: 88rpx;
color: #323233;
font-size: 28rpx;
line-height: 88rpx;
text-align: center;
margin-top: 26rpx;
}
</style>