addAddress.vue
9.0 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
<template>
<view class="page">
<view class="box">
<view class="item">
<view class="left">姓名</view>
<view class="right">
<input type="text" :value="name" placeholder="请输入姓名" @input="entername" />
</view>
</view>
<view class="item">
<view class="left">联系方式</view>
<view class="right">
<input type="number" :value="phone" placeholder="请输入手机号码" @input="enterphone" />
</view>
</view>
<view class="item">
<view class="left">地区</view>
<view class="right">
<picker @change="bindproChange" :value="proindex" :range="proarray" range-key="name">
<view class="uni-input">{{proname}}</view>
</picker>
<view class="uni-input" v-if="province_id==''" @click="selectcity">{{cityname}}</view>
<picker @change="bindcityChange" :value="cityindex" :range="cityarray" range-key="name" v-else>
<view class="uni-input">{{cityname}}</view>
</picker>
<view class="uni-input" v-if="city_id==''" @click="selarea">{{areaname}}</view>
<picker @change="bindareaChange" :value="areaindex" :range="arearray" range-key="name" v-else>
<view class="uni-input">{{areaname}}</view>
</picker>
<image src="../../static/right.png" mode="widthFix" />
</view>
</view>
<view class="item">
<view class="left">详细地址</view>
<view class="right">
<input type="text" :value="address" placeholder="详细地址须填写楼栋楼层或房间号信息" @input="enteraddress" />
</view>
</view>
</view>
<view class="btn" @click="sureadd">确认</view>
</view>
</template>
<script>
import app from "../../App.vue";
export default {
data() {
return {
name: '',
phone: '',
province_id: '',
city_id: '',
county_id: '',
address: '',
proarray:[],
proindex:'',
proname:'请选择省',
cityname:'请选择市',
cityindex:'',
cityarray:[],
arearray:[],
areaindex:'',
areaname:'请选择区',
type:'',
addressid:'',
item:''
}
},
onLoad(options) {
if(options.type!=undefined){
this.type=options.type;
this.addressid=options.id;
this.item=JSON.parse(options.item);
this.name=this.item.name;
this.phone=this.item.phone;
this.address=this.item.address;
this.province_id=this.item.province_id;
this.city_id=this.item.city_id;
this.county_id=this.item.county_id;
this.proname=this.item.province_name;
this.cityname=this.item.city_name;
this.areaname=this.item.county_name;
this.getprovince();
this.getcity();
this.getarea();
}
this.getprovince();
},
methods: {
// 输入姓名
entername(e) {
this.name = e.detail.value
},
// 输入电话号
enterphone(e) {
this.phone = e.detail.value
},
// 输入地址
enteraddress(e) {
this.address = e.detail.value
},
//获取省
getprovince(){
let that=this;
var url = 'user_address/get_province';
var params = {
}
console.log(params)
app.post(url, params, "post").then((res) => {
console.log(res);
that.proarray=res.data.data;
that.proarray.forEach(function(value,index,array){
if(that.province_id==value.id){
that.proindex=index
}
})
}).catch((err) => {
console.log(err)
})
},
bindproChange(e){
this.proname=this.proarray[e.target.value].name;
this.proindex=e.target.value;
this.province_id=this.proarray[e.target.value].id
this.getcity();
},
// 获取市
getcity(){
let that=this;
var url = 'user_address/get_city';
var params = {
province_id:that.province_id,
}
app.post(url, params, "post").then((res) => {
console.log(res);
that.cityarray=res.data.data;
console.log(that.cityarray);
console.log('2393883843',that.city_id);
that.cityarray.forEach(function(value,index,array){
if(that.city_id==value.id){
that.cityindex=index
}
})
}).catch((err) => {
console.log(err)
})
},
selectcity(){
if(this.province_id==''){
uni.showToast({
title:'请选择省',
icon:'none'
})
return false
}
},
//选择市
bindcityChange(e){
this.cityname=this.cityarray[e.target.value].name;
this.cityindex=e.target.value;
this.city_id=this.cityarray[e.target.value].id
this.getarea();
},
// 获取区
getarea(){
let that=this;
var url = 'user_address/get_county';
var params = {
city_id:that.city_id,
}
app.post(url, params, "post").then((res) => {
console.log(res);
that.arearray=res.data.data;
that.arearray.forEach(function(value,index,array){
if(that.county_id==value.id){
that.areaindex=index
}
})
}).catch((err) => {
console.log(err)
})
},
selarea(){
if(this.city_id==''){
uni.showToast({
title:'请选择市',
icon:'none'
})
return false
}
},
//选择区
bindareaChange(e){
this.areaname=this.arearray[e.target.value].name;
this.areaindex=e.target.value;
this.county_id=this.arearray[e.target.value].id
},
//确认添加地址
sureadd() {
let that = this;
if(that.name==''){
uni.showToast({
title:'请输入姓名',
icon:'none'
})
return false
}
if(that.phone==''){
uni.showToast({
title:'请输入联系方式',
icon:'none'
})
return false
}
if(that.phone!=''){
var reg=/^[1][3,4,5,6,,7,8,9][0-9]{9}$/;
if(!reg.test(that.phone)){
uni.showToast({
title:'请输入正确的手机号',
icon:'none'
})
return false
}
}
if(that.province_id==''){
uni.showToast({
title:'请选择省',
icon:'none'
})
return false
}
if(that.city_id==''){
uni.showToast({
title:'请选择市',
icon:'none'
})
return false
}
if(that.county_id==''){
uni.showToast({
title:'请选择区',
icon:'none'
})
return false
}
if(that.address==''){
uni.showToast({
title:'请输入详细地址',
icon:'none'
})
return false
}
if(that.type==1){
that.editaddress();
}else{
that.adddizhi()
}
},
//添加地址
adddizhi(){
let that=this;
var url = 'user_address/add_user_address';
var params = {
name: that.name,
phone: that.phone,
province_id: that.province_id,
city_id: that.city_id,
county_id: that.county_id,
address: that.address,
}
console.log(params)
app.post(url, params, "post").then((res) => {
console.log(res);
uni.showToast({
title:'添加地址成功',
icon:'none'
})
setTimeout(function(){
uni.navigateBack({
checked:true
})
},1500)
}).catch((err) => {
console.log(err)
})
},
// 编辑地址
editaddress(){
let that=this;
var url = 'user_address/edit_user_address';
var params = {
user_address_id:that.addressid,
name: that.name,
phone: that.phone,
province_id: that.province_id,
city_id: that.city_id,
county_id: that.county_id,
address: that.address,
}
console.log(params)
app.post(url, params, "post").then((res) => {
console.log(res);
uni.showToast({
title:'修改地址成功',
icon:'none'
})
setTimeout(function(){
uni.navigateBack({
checked:true
})
},1500)
}).catch((err) => {
console.log(err)
})
},
}
}
</script>
<style>
page {
background: #F7F7F7;
}
.uni-input{
margin-right:20rpx;
}
.box {
padding: 0 32rpx;
box-sizing: border-box;
background: #fff;
}
.item {
height: 108rpx;
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid #EDEDED;
}
.left {
width: calc(100% -220rpx);
display: flex;
align-items: center;
font-size: 28rpx;
font-family: PingFangHK-Regular, PingFangHK;
font-weight: 400;
color: rgba(8, 18, 31, 1);
}
.right {
width: 550rpx;
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;
text-align: right;
}
.right image {
width: 32rpx;
margin-left: 16rpx;
}
.right input {
max-width: 476rpx;
font-size: 28rpx;
font-family: PingFangHK-Regular, PingFangHK;
font-weight: 400;
color: rgba(61, 69, 76, 1);
}
.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;
/* margin: 100rpx auto; */
position: fixed;
bottom: 30rpx;
left: 32rpx;
}
</style>