address.js
2.26 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
var util = require('../../../utils/util.js')
import App from '../../../utils/api.js'
Page({
data:{
},
onLoad(opt){
this.opt=opt;
if(opt.id){
this.getaddress();
}else{
this.setData({
user:{
sex:1,
openid:util.cache('openid')
}
})
}
},
selectsex(e){
this.setData({
'user.sex':e.currentTarget.dataset.sex
})
},
inputval(e){
let setkey='user.'+e.currentTarget.dataset.key;
this.setData({
[setkey]:util.trim(e.detail.value)
})
},
save(){
if(!this.data.user.phone){
return wx.showToast({
title:'请输入收货人手机号',
icon:'none',
mask:true,
duration:1500
})
}
if(this.data.user.phone){
var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
if (!myreg.test(this.data.user.phone)) {
return wx.showToast({
title:'手机格式不正确',
icon:'none',
mask:true,
duration:1500
})
}
}
if(!this.data.user.uname){
return wx.showToast({
title:'请输入收货姓名',
icon:'none',
mask:true,
duration:1500
})
}
if(!this.data.user.address){
return wx.showToast({
title:'请输入收货地址',
icon:'none',
mask:true,
duration:1500
})
}
this.adduser();
},
adduser(){
App.User.AddAddress(this.data.user).then((json)=>{
if(json.ret==200){
util.cache('user',json.data);
wx.showToast({
title:'保存成功',
mask:true,
duration:2000,
success:()=>{
setTimeout(()=>{
wx.navigateBack()
},2000)
}
})
}
})
},
getaddress(){
App.User.getOpenidAddress({id:this.opt.id}).then((json)=>{
if(json.ret==200){
this.setData({
user:json.data
})
}
})
},
selectaddress(){
wx.chooseLocation({
success:(res)=>{
console.log(res,'success')
this.setData({
'user.address':res.name,
'user.lat':res.latitude,
'user.long':res.longitude
})
},
fail:(fail)=>{
console.log(fail,'fail')
wx.showModal({
title:'位置授权',
content:'您的位置信息需授权给飞鸭外卖用于位置的展示',
confirmColor:'#F0242E',
cancelColor:'#999999',
success:function(res){
console.log(res)
if(res.confirm){
util.setting();
}
}
})
}
})
}
})