submit.js
5.66 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/reserve/submit.js
import util from '../../utils/util';
import App from '../../utils/api';
const _u = {
name: '',
sex: 1,
phone: '',
remark: '',
}
let dur=['morning','noon','night','midnight']
Page({
paddingBottom:0,
user: _u,
/**
* 页面的初始数据
*/
data: {
seller:null,
detail:null,
user:_u,
},
hasSubmit:true,
/**
* 生命周期函数--监听页面加载
*/
options:null,
onLoad: function (options) {
console.log(options)
options.room_demand=JSON.parse(decodeURIComponent(options.room_demand))
this.options=options
this.GetSellerDetail();
App.Customer.GetCustomerInfo().then(res=>{
if(res.data.length>0){
res.data.forEach((v,i)=>{
if(v.is_default==1){
this.user = v
v.remark='';
this.setData({
user: v,
})
return;
}
})
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
GetSellerDetail() {
let options = this.options
App.Customer.GetSellerDetail({
sid: options.sid,
}).then(res => {
if (res.ret == 200) {
let seller = res.data
this.setData({
seller: seller,
detail:options
})
}
})
},
selectconcat(){
wx.navigateTo({
url:'/pages/me/concat?action=select'
})
},
changeInput(e) {
let key = util.attr(e, 'key');
let val = ''
if (key == 'sex') {
val = util.attr(e, 'val');
} else {
if(key=='phone'){
let myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
if(!myreg.test(util.val(e))){
return util.val(e);
}
}
val = util.val(e);
}
this.user[key] = val;
if (key == 'sex') {
this.setData({
user: this.user
})
}
},
saved() {
if(!this.hasSubmit) return;
if(!this.user.name){
return util.toast('请填写姓名','none')
}
if(!this.user.phone){
return util.toast('请填写正确的手机号','none')
}
this.hasSubmit=false;
let roomids=[];
this.options.room_demand.forEach((v,i)=>{
roomids.push(v.id)
})
console.log('ceshi',roomids);
App.Customer.SetReserveInfo({
sid:this.options.sid,
ddate:this.options.ddate,
rdate:this.getRdate(),
rname:this.user.name,
sex:this.user.sex,
phone:this.user.phone,
cusdem:this.user.remark||'',
ddate_solt:dur.indexOf(this.options.section)+1,
roomids:roomids.toString(),
}).then(res=>{
console.log('ceshi',this.hasSubmit,res);
if(res.ret!=200){
this.hasSubmit=true;
return util.toast(res.msg,'none');
}
if(res.data.hasSetUserInfo){
App.Customer.GetCustomerInfo({},'clear')
}
let firstShowMsg='餐厅一般会在10分钟内为您反馈结果,请留意短信或微信通知'
if(!this.hasInWorkTime()){//非营业时间预订
firstShowMsg='商家未上班,上班后将第一时间告知您预订结果,请留意短信/微信通知(上班时间:'+this.data.seller.rec_stime+'—'+this.data.seller.rec_etime+')'
}
wx.redirectTo({
url:util.http_build_query({
id:res.data.rid,
firstShowMsg:firstShowMsg,
},'/pages/customer/detail_owner')
})
}).catch((res)=>{
this.hasSubmit=true//出错后可再次提交
if(!res.msgSecCheck){
return util.toast('提交失败,请重试','none');
}
})
},
getRdate(){
let daily=this.data.seller.daily;
let ddate=util.unixtoTime(this.options.ddate,'YYYY-MM-DD,HH:II').split(',');
let rd=['00:00','00:00'];
Object.keys(daily).forEach((k)=>{
let t=daily[k].split('-')
if(t[0]<=ddate[1] && ddate[1]<=t[1]){
rd=t;
}
})
return util.timetouUnix(ddate[0]+' '+rd[0]+':00')+'-'+util.timetouUnix(ddate[0]+' '+rd[1]+':00')
},
editorReserve(){
wx.navigateBack()
},
getphone(e){
console.log('getphone',e);
if(e.detail.ret!=200){
return util.toast('获取失败,请重新获取','none');
}
this.user.phone=e.detail.phone
this.setData({
user: this.user
})
},
hasInWorkTime(){
let stime='',etime='',time=parseInt(new Date()/1000)
let today=util.unixtoTime(time,"YYYY-MM-DD")
stime=util.timetouUnix(today+' '+this.data.seller.rec_stime+':00')
etime=util.timetouUnix(today+' '+this.data.seller.rec_etime+':00')
if(etime<=stime){
if(time<=etime){
return true
}
etime+=86400
}
if(time>=stime && time<=etime){
return true;
}
return false;
},
cardEvent(e){
this.editorReserve()
},
keyboardheight:0,
keyboardheightchange(e){
console.log(e);
if(e.detail.height==0 || e.detail.height>this.keyboardheight){
this.keyboardheight=e.detail.height
}
this.setData({
//paddingBottom:e.detail.height?(parseInt(e.detail.height)+100):0
paddingBottom:this.keyboardheight>0?(parseInt(this.keyboardheight)+20):0
})
setTimeout(()=>{
this.pageScrollToBottom()
},0)
},
pageScrollToBottom: function () {
wx.createSelectorQuery().select('.pages').boundingClientRect(function (rect) {
// 使页面滚动到底部
wx.pageScrollTo({
scrollTop: rect.bottom
})
}).exec()
},
})