add-address.js
5.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
// pages/add-address/add-address.js
let method = require("../../utils/reuqest.js");
const util = require("../../utils/util.js");
const chooseLocation = requirePlugin('chooseLocation');
Page({
data: {
username: '',
phone: '',
value: '',
checked: 0,
show: false,
selectBox: true,
location: '',
latitude: "",
longitude: "",
latitudes: "", //传值
longitudes: "",
flag: true
},
//姓名
inputName(e) {
this.setData({
username: e.detail
})
},
//电话
inputDel(e) {
this.setData({
phone: e.detail
})
},
//电话失焦事件
blurPhone(e) {
if (this.data.phone.length == 11) {
this.sPhoneAvailable(e.detail.value);
return false;
} else {
this.isTelAvailable(e.detail.value)
}
},
//校验手机号
sPhoneAvailable(pone) {
var myreg = /^[1][3,5,7,8][0-9]{9}$/;
if (!myreg.test(pone)) {
wx.showToast({
title: '请输入正确的手机号',
icon: 'none'
})
return false;
} else {
return true;
}
},
//校验电话号码
isTelAvailable(tel) {
var myreg = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
if (!myreg.test(tel)) {
wx.showToast({
title: '请输入正确的电话号码',
icon: 'none'
})
return false;
} else {
alert("电话号校验成功");
return true;
}
},
// 弹出层
showPopup() {
this.setData({
show: true
});
},
onClose() {
this.setData({
show: false
});
},
//地区
map() {
wx.getLocation({
type: 'wgs84',
success(res) {
const latitude = res.latitude
const longitude = res.longitude
const speed = res.speed
const accuracy = res.accuracy
}
})
let that = this;
const key = 'C4QBZ-UYQLI-S45G2-5ETMC-LQYWE-L6FJU';
const referer = '春晓世纪华联超市';
const category = '房产小区,其它';
wx.getLocation({
type: 'gcj02',
success(res) {
console.log(res, 'rs')
const location = JSON.stringify({
latitude: res.latitude,
longitude: res.longitude
});
wx.navigateTo({
url: `plugin://chooseLocation/index?key=${key}&referer=${referer}&location=${location}&category=${category}`
});
}
})
},
//详细地址
inputAddress(e) {
this.setData({
value: e.detail
})
},
cancelChoose() {
this.setData({
show: false
});
},
chooseAddress(e) {
this.setData({
show: false,
selectBox: false
});
console.log(e.detail.values, '确认')
},
//开关
onChange() {
this.setData({
checked: !this.data.checked
})
},
//点击保存
save() {
if (this.data.username == '') {
wx.showToast({
title: '请输入姓名',
icon: 'none'
})
} else if (this.data.phone == '') {
wx.showToast({
title: '请输入电话',
icon: 'none'
})
} else if (this.data.value == '') {
wx.showToast({
title: '请输入详细地址',
icon: 'none'
})
} else {
let delFlags = this.data.checked == true ? 1 : 0;
let postData = {
address: this.data.value,
area: this.data.location,
delFlag: delFlags,
id: "",
location: this.data.longitudes + "," + this.data.latitudes,
name: this.data.username,
phone: this.data.phone,
zipCode: ""
}
method.postRequest("/address/create", postData, data => {
if (data.statusCode == 0) {
console.log('11')
wx.showToast({
title: '保存成功',
icon: 'none'
})
// wx.redirectTo({
// url: '/pages/select-address/select-address?edit=1',
// })
wx.navigateBack({
delta: 1,
})
} else {
wx.showToast({
title: '地址超出配送费范围请重新选择',
icon: 'none'
})
}
})
}
},
onLoad: function (options) {},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
let that = this;
const location = chooseLocation.getLocation();
console.log(location, 'location')
const address = location.address
const latitude = location.latitude
const longitude = location.longitude
this.setData({
location: address,
latitudes: latitude,
longitudes: longitude
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})