reserve.js
8.86 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
// pages/reserve/detail.js
import util from '../../utils/util';
import App from '../../utils/api';
const {regeneratorRuntime} = global
const zdmask='-zdmask?v=1.2'
import PubSub from '../../utils/PubSub'
const slots={'morning':1,'noon':2,'night':3}
Page({
/**
* 页面的初始数据
*/
data: {
loading:0,
seller:null,
hasFullHouse:false,//满房
lunchDinnerList:[],//日期所对应的餐段
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(wx.getStorageSync('remark')){
wx.removeStorageSync('remark')
}
console.log('onLoad', options)
console.log('初次进入详情页---小米8测试',this.data.reserveDate ? this.data.reserveDate : '没有日期','openid:',getApp().openid)
this.options=options
this.downloadImages()
this.getLocalLunchTime()
if(options.activeTab && options.activeTab!='detail'){
this.setData({
activeTab:options.activeTab||'detail',
})
}
this.setData({
reserveDate: options.date ? options.date : util.unixtoTime(new Date() / 1000, 'YYYY-MM-DD'),
})
if(options.act=='update'){//修改预订
//act=update§ion=night&time=16:00&date=2020-12-27&sid=1&ddate=1609056000&room_demand=[{"id":"30","name":"6人间"},{"id":"31","name":"10人间"},{"id":"32","name":"12人间"}]
this.setData({
reserveDate: options.date,
seletroomlist:JSON.parse(options.room_demand),
reserveSection:options.section
})
this.reserve.section=options.section;
this.reserve.time=options.time;
}
},
//获取日期对应的多时段
getLocalLunchTime(){
let options=this.options
App.Seller.getMealSectionByDay({
sellerid: options.id,
day: this.reserve.date,
}).then(res => {
let data = res.data;
let lunchDinnerList = [];
if (data.length <= 3 && !data[0].ddate_solt) {
data.forEach(i => {
if (i.mname == '早餐') {
lunchDinnerList.push({
mname: "早餐",
mdate: i.mdate,
ddate_solt: 1,
})
}
if (i.mname == '午餐') {
lunchDinnerList.push({
mname: "午餐",
mdate: i.mdate,
ddate_solt: 2,
})
}
if (i.mname == '晚餐') {
lunchDinnerList.push({
mname: "晚餐",
mdate: i.mdate,
ddate_solt: 3,
})
}
})
} else {
lunchDinnerList = data;
}
lunchDinnerList.forEach((item,index)=>{
item.section = 'ket'+index
})
this.setData({
lunchDinnerList
})
}).catch(res => {
console.log(res, '获取多时段失败');
})
},
GetSellerDetail(){
let options=this.options
App.Customer.GetSellerDetail({
sid:options.id,
}).then(res=>{
if(res.ret==200){
let seller=res.data
let obj={
seller:seller,
loading:1,
}
if(this.options.classID){
obj.seletroomlist=[{
id:this.options.classID,
name:this.options.className,
}]
delete this.options.classID
delete this.options.className
}
this.setData(obj)
}
}).catch(e=>{
util.toast('网络出错,请尝试重新进入',none)
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.GetSellerDetail();
if (this.data.reserveDate && this.data.seletroomlist){//后退进入等情况刷新时段
this.setData({
reserveDate:this.data.reserveDate
})
}
//已经完成预订的情况---清除日期、时段、选中包间
if(wx.getStorageSync('order')){
this.setData({
seletroomlist:[],
})
wx.removeStorageSync('order')
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
shareImageTmp:'',
downloadImages(){
wx.downloadFile({
url:'https://xt04.colorcun.com/sellerShare/Share_'+this.options.id+'.png?'+Math.random(),
success:res=>{
this.shareImageTmp=res.tempFilePath
},
})
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
let path=util.http_build_query({id:this.data.seller.id,fromid:getApp().openid},'/pages/reserve/shopHome')
//let imageUrl='http://sellershare.colorcun.com/Share_'+this.options.id+'.png?imageView2/2/w/180/interlace/0'
let shareParams={
title:'请客订包间,就上周到安排',
path:path,
}
if(this.shareImageTmp){
shareParams.imageUrl=this.shareImageTmp
}
console.log('shareParams==>',shareParams)
return shareParams
},
reserve:{},
selectpeople(e){//人数改变
console.log(e);
this.reserve.pnum=e.detail.people;
if(e.detail.action=='click'){
}
},
//时段改变
selectsection(e){
this.getLocalLunchTime()
setTimeout(()=>{
this.setData({
reserveSection:e.detail.section!='' ? e.detail.section : null,
seletroomlist:e.detail.action=='click' ? [] : this.data.seletroomlist,
})
},0)
this.reserve.section=e.detail.section;
this.reserve.time=e.detail.time;
},
//包间类型改变
selectroom(e){
console.log(e)
this.setData({
seletroomlist:e.detail.selectroom
})
},
complete(){
if(!this.data.reserveSection){
return util.toast('请选择可预订的时段','none');
}
if(!this.data.seletroomlist || (this.data.seletroomlist && this.data.seletroomlist.length==0)){
return util.toast('请选择包间类型','none');
}
this.reserve.sid=this.options.id
this.reserve.ddate=util.timetouUnix(this.reserve.date+' '+this.reserve.time+':00');
let num=0
this.data.seletroomlist.forEach(i=>{
num+=i.standard*1
})
this.reserve.room_demand=JSON.stringify(this.data.seletroomlist)
if(this.options.pnum){
this.reserve.pnum = this.options.pnum;
}else{
this.reserve.pnum = num;
}
let ddate_solt = '';
let obj=this.data.lunchDinnerList.filter(item=>{return item.section == this.reserve.section})
if(obj && obj[0]){
ddate_solt = obj[0].ddate_solt;
}
this.reserve.ddate_solt = ddate_solt
App.Reserve.GetReserveIsExits({sid:this.reserve.sid,ddate_solt,ddate:this.reserve.ddate}).then((json)=>{
console.log(json)
if(json.ret==200){
if(json.data==1){
wx.showModal({
content:'您在该店铺已有一个订单待处理,是否加订一间?',
confirmText:'是',
concelText:'否',
cancelColor:'#999999',
success:(res)=>{
if(res.confirm){
wx.redirectTo({
url:util.http_build_query(this.reserve,'./submit')
})
}
}
})
}else{
wx.redirectTo({
url:util.http_build_query(this.reserve,'./submit')
})
}
}
})
// wx.redirectTo({
// url:util.http_build_query(this.reserve,'./submit')
// })
},
selecttime(e){//时间改变
console.log(e);
this.getLocalLunchTime()
if(!e.detail.time){//满房
this.setData({
hasFullHouse:true,
})
return;
}
this.reserve.time=e.detail.time;
if(e.detail.action=='click'){
this.reserve.sid=this.options.id
this.reserve.ddate=util.timetouUnix(this.reserve.date+' '+this.reserve.time+':00')
//date=2019-07-25&pnum=6&time=20%3A00&sid=154&ddate=1564056000
wx.navigateTo({
url:util.http_build_query(this.reserve,'./submit')
})
}
},
selectdate(e){//日期改变
if(e.detail.action==401){//无可用桌位
return;
}
console.log('selectdate',e);
if(e.detail.overdate==1){//今天之前
return this.setData({
hasFullHouse:true,
fullHouseMsg:'请选择今天之后的日期',
})
}
this.reserve.date=e.detail.date;
this.setData({
reserveDate:e.detail.date,
seletroomlist:e.detail.action=='click' ? [] : this.data.seletroomlist,
hasFullHouse:false,
reserveSection:e.detail.action=='click' ? null : this.data.reserveSection,
fullHouseMsg:'今日所有包间已订满',
})
}
})