address-edit.js
2.97 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
import {
getBindtapData,
getObjByListKeyValue,
checkMobile
} from '../../utils/util';
let app = getApp();
Page({
data: {
authorizeVisible: false,
value: "",
checked: false,
addressEditInfo: {
receiverCode: "",
receiverName: "",
receiverPhone: "",
receiverAddress: "",
defaultAddress: 1,
}
},
onShareAppMessage() {},
showAuth() {
this.setData({
authorizeVisible: true
})
},
onLoad(options) {
// this.setData({
// options: app.globalData.addressEditInfo
// })
this.initData();
},
initData() {
let addressEditInfo = app.globalData.addressEditInfo;
this.setData({
addressEditInfo
})
},
/**
* 显示提示
*/
showTips(tips) {
wx.showToast({
title: tips,
icon: "none"
})
},
/**
* 检查提交
*/
checkSubmit() {
return new Promise((resolve, reject) => {
let addressEditInfo = this.data.addressEditInfo;
if (!addressEditInfo.receiverName) {
this.showTips("请输入收货人姓名")
reject();
} else if (!addressEditInfo.receiverPhone) {
this.showTips("请输入收货电话")
reject();
} else if (!checkMobile(addressEditInfo.receiverPhone)) {
this.showTips("请输入正确收货电话")
reject();
} else if (!addressEditInfo.receiverAddress) {
this.showTips("请输入收货地址")
reject();
} else {
resolve()
}
});
},
/**
* 表单提交
* @param {*} evt
*/
onSubmitHandler(evt) {
this.checkSubmit().then((result) => {
let {
addressEditInfo,
checked
} = this.data;
addressEditInfo.defaultAddress = checked ? 1 : 0;
app.post({
url: app.api.receiverSave,
data: addressEditInfo
}).then((result2) => {
wx.showModal({
content: '操作成功',
showCancel: false,
success(res) {
wx.navigateBack({
delta: 1
});
}
})
})
});
},
/**
* 删除表单
* @param {*} evt
*/
onDeleteHandler(evt) {
let {
addressEditInfo,
} = this.data;
app.post({
url: app.api.receiverDelete,
data: {
receiverCode: addressEditInfo.receiverCode
}
}).then((result) => {
wx.showModal({
content: '删除成功',
showCancel: false,
success(res) {
wx.navigateBack({
delta: 1
});
}
})
})
},
bindReceiverNameInput(e) {
this.setData({
"addressEditInfo.receiverName": e.detail.value
});
},
bindReceiverPhoneInput(e) {
this.setData({
"addressEditInfo.receiverPhone": e.detail.value
});
},
bindReceiverAddressInput(e) {
this.setData({
"addressEditInfo.receiverAddress": e.detail.value
});
},
onChange(event) {
let checked = event.detail
this.setData({
checked: event.detail,
});
}
})