receiptAddress.js
3.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
import {
request
} from "../../request/index.js"
const a = getApp()
Page({
data: {
imagesUrl: a.globalData.baseUrl,
name: '',
phone: '',
ajxtrue: false,
address2: '',
msg: '',
address: '',
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
async formSubmit(e) {
// console.log('form发生了submit事件,携带数据为:', e.detail.value)
let that = this
// console.log(that.data.name, that.data.phone, that.data.address, that.data.address2);
try {
let ajxtrue = this.data.ajxtrue
if (ajxtrue == true) {
//表单提交进行
const {
data
} = await request({
method: 'get',
url: 'api/address/addAddress',
data: {
name: e.detail.value.name,
phone: e.detail.value.phone,
address: that.data.address,
address2: e.detail.value.address2
}
})
// console.log(data);
if (data.code == 411) {
this.setData({
msg: data.msg
})
this.popFailTest()
} else if (data.code == 0) {
this.setData({
msg: data.msg
})
this.popFailTest()
} else {
this.setData({
msg: data.msg
})
this.popSuccessTest()
setTimeout(function () {
wx.navigateBack()
}, 2000)
}
} else {
wx.showToast({
title: '手机号有误',
icon: 'success',
duration: 2000
})
}
} catch (err) {
this.setData({
msg: err.msg
})
this.popFailTest()
}
},
// 手机号验证
blurPhone: function (e) {
var phone = e.detail.value;
let that = this
if (!(/^1[3456789]\d{9}$/.test(phone))) {
this.setData({
ajxtrue: false
})
if (phone.length >= 11) {
wx.showToast({
title: '手机号有误',
icon: 'success',
duration: 2000
})
}
} else {
this.setData({
ajxtrue: true
})
// console.log('验证成功', that.data.ajxtrue)
}
},
bindRegionChange: function (e) {
// console.log('picker发送选择改变,携带值为', e.detail.value)
this.setData({
address: e.detail.value.toString()
})
// console.log(this.data.address);
},
// 弹窗
popSuccessTest() {
wx.showToast({
title: this.data.msg,
icon: '', //默认值是success,就算没有icon这个值,就算有其他值最终也显示success
duration: 2000, //停留时间
})
},
popFailTest() {
wx.showToast({
title: this.data.msg,
icon: '{{imagesUrl}}assets/static/img/cuowu.png',
duration: 2000, //停留时间
})
},
})