-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwxtaroProplem.js
596 lines (552 loc) · 15.4 KB
/
wxtaroProplem.js
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
var commenValue = require('../../../utils/commonValue.js')
var util = require('../../../utils/util.js')
var request = require('../../../utils/request.js')
var wxPromise = require('../../../utils/wxPromise.js')
var app = getApp()
var fullPrice = 0
var selectStop = {}
const dispalyCoupn = '不使用优惠券'
var disCoupnCode = ''
var payMoney = 0
var timeOut = 0
var selectIndPrice = 0
var indIndex = 0
var isHasChild = false
var selectSchedule = {}
var token = ''
Page({
data: {
noTicketSum: 0,
halfTicketSum: 0,
fullTicketSum: 1,
disValue: 0,
sum: 0,
date: '',
maxTicketCount: 0,
toastStatus: true,
mImgPath: '../../../image/SetOrder/path_up.png',
selectInd: -1,
selectIndPrice: 0,
insurance: '',
widowsHeight: app.globalData.widowsHeight,
widowsWidth: app.globalData.widowsWidth,
screenHeight: app.globalData.screenHeight
},
onUnload(e) {
disCoupnCode = ''
payMoney = 0
timeOut = 0
selectIndPrice = 0
indIndex = 0
selectStop = null
selectSchedule = null
},
onLoad(options) {
token = app.globalData.token
if (token == '') {
util.redirect('../../../pages/Login/index')
return
}
wx.showLoading({
title: '加载中'
})
selectStop = wx.getStorageSync(commenValue.selectStop)
selectSchedule = wx.getStorageSync(commenValue.selectSchedule)
payMoney = fullPrice = wx.getStorageSync(commenValue.schedulePrice)
this.getCoupons()
var InsOs = []
var o1 = {}
o1.id = 1
o1.Name = '三元保险'
o1.Price = 3
o1.Des = '100000出行保障'
var o2 = {}
o2.id = 2
o2.Name = '五元保险'
o2.Price = 5
o2.Des = '500000出行保障'
InsOs.push(o1)
InsOs.push(o2)
var isShowHalf = selectSchedule.canSaleHalfTicketCount > 0
var isShowTake = selectSchedule.canSaleTakeChildTicketCount > 0
this.setData({
detailAddress: selectStop.startDes,
issShowHalf: isShowHalf,
issShowTake: isShowTake,
startStop: selectStop.startName,
endStop: selectStop.endName,
schduleDate: util.formateDay(wx.getStorageSync(commenValue.serverTime).split('T')[0]) + ' ' + util.getWeek(wx.getStorageSync(commenValue.serverTime).split('T')[0]).split('(')[0],
schduleTime: selectSchedule.scheduleTime,
ticketPrice: fullPrice,
carNumber: selectSchedule.vehicleNumber,
time: selectSchedule.scheduleTime,
date: util.formateDay(wx.getStorageSync(commenValue.serverTime).split('T')[0]),
})
},
powerDrawer(e) {
console.log(e)
if (this.data.showModalStatus == true) {
if (e.currentTarget.dataset.type == '1') {
this.setSelectContact()
} else if (e.currentTarget.dataset.type == '2') {
this.setData({
showSumModalStatus: false,
mImgPath: '../../../image/SetOrder/path_up.png'
})
} else if (e.currentTarget.dataset.type == '4') {
this.setData({
showInsurance: false,
insurance: ''
})
} else {
this.setData({
showDisModalStatus: false
})
}
}
if (e == "undefined" || e == undefined) {
// this.util("close", "3", "0")
} else
this.util(e.currentTarget.dataset.statu, e.currentTarget.dataset.type, e.currentTarget.dataset.id)
},
util(currentStatu, currentType, id) {
var that=this
setTimeout(function() {
if (currentStatu == 'close') {
this.setData({
showModalStatus: false,
showSumModalStatus: false,
showDisModalStatus: false,
showInsurance: false,
mImgPath: '../../../image/SetOrder/path_up.png'
})
if (currentType == '4') {
var f = ''
var price = 0
for (var i = 0; i < that.data.insurances.length; i++) {
if (that.data.insurances[i].id == id) {
f = that.data.insurances[i].Name
price = that.data.insurances[i].Price
}
}
that.setData({
insurance: f,
selectInd: id,
selectIndPrice: price
})
selectIndPrice = price
that.bindManual()
}
}
}, 100)
if (currentStatu == 'open') {
if (currentType == '1') {
this.setData({
showModalStatus: true
})
}
if (currentType == '3') {
if(this.data.disList.length==0){ return}
this.setData({
showDisModalStatus: true
})
}
if (currentType == '4') {
this.setData({
showInsurance: true
})
}
if (currentType == '2') {
if (this.data.showSumModalStatus){
this.setData({
showSumModalStatus: false,
mImgPath: '../../../image/SetOrder/path_up.png'
})
return
}
this.setData({
showSumModalStatus: true,
mImgPath: '../../../image/SetOrder/path_down.png'
})
}
}
},
showPic() {
util.navigate('../OrderInMap/ShowPic/index?url=' + selectStop.startStopImg + '&code=' + selectStop.startStopCode)
},
showMap() {
util.navigate('../../../pages/Common/Map/index?Code=' + selectSchedule.scheduleCode + '&LineCode=' + selectSchedule.lineCode)
},
showNotice() {
util.navigate('../Order/Notice/index')
},
openPay() {
if (app.globalData.token == '') {
util.redirect('../../../pages/Login/index')
return
}
var max = this.data.maxTicketCount
var now = this.data.fullTicketSum + this.data.halfTicketSum + this.data.noTicketSum
if (now > max) {
wx.showModal({
title: '温馨提示',
content: "每个订单最多允许" + max + "张订单!",
showCancel:false
})
return
}
var remainSeatCount = this.data.remainSeatCount
if (now > remainSeatCount) {
wx.showModal({
title: '温馨提示',
content: "还剩" + remainSeatCount + "座位,请重新下单!",
showCancel:false
})
return
}
if (this.data.fullTicketSum < this.data.noTicketSum) {
wx.showModal({
title: '温馨提示',
content: "全票数不能少于携童票数!",
showCancel:false
})
return
}
var that = this
var departDate = util.getCurrentDate().getFullDate().split('-')[0] + '-' + this.data.date.split(' ')[0].replace('月', '-').replace('日', '')
var time1 = new Date(util.getCurrentDate().getFullDate() + ' ' + util.getNowTime(timeOut))
var time2 = new Date(departDate + ' ' + this.data.time)
if (time2 < time1) {
wx.showModal({
title: '确认信息',
content: '接近发车时间,请确认能及时到达上车点,点击确定购买?',
success: function(res) {
if (res.confirm) {
that.getNowXY()
}
}
})
return
}
wx.showLoading({
title: '正在下单...'
})
this.getNowXY()
},
getNowXY() {
var that = this
var getLocationPromisified = wxPromise.wxPromisify(wx.getLocation)
getLocationPromisified({
type: 'wgs84'
}).then(function(res) {
that.addOrder(res.longitude, res.latitude)
}).catch(function(e) {
that.addOrder("", "")
});
},
addOrder(longitude, latitude) {
var order = {}
order.SellerCode = commenValue.sellerCode
order.DistributorCode = commenValue.WMCX
order.TerminalCode = commenValue.terminalCode
order.ScheduleCode = selectSchedule.scheduleCode
order.BeginStopCode = selectStop.startStopCode
order.EndStopCode = selectStop.endStopCode
order.Longitude = longitude
order.Latitude = latitude
var booker = {}
var user = wx.getStorageSync(commenValue.user)
// booker.Name = user.userName
// booker.IdCard = user.userIDCard
booker.Mobile = user.userMobile
booker.OpenId = user.openid
var riders = []
for (var i = 0; i < this.data.fullTicketSum; i++) {
var rider = {}
rider.Name = ""
rider.IdCard = ""
rider.Mobile = ""
rider.TicketTypeCode = 'FullTicket'
if (this.data.noTicketSum >= 1 && !isHasChild) {
rider.TicketTypeCode = 'TakeChildTicket'
isHasChild = true
}
riders.push(rider)
}
for (var i = 0; i < this.data.halfTicketSum; i++) {
var rider = {}
rider.Name = ""
rider.IdCard = ""
rider.Mobile = ""
rider.TicketTypeCode = 'HalfTicket'
riders.push(rider)
}
this.postOrderBook(order, booker, riders)
},
postOrderBook(order, booker, riders) {
var that = this
request(commenValue.POST, commenValue.orderBookUrl, {
Order: order,
Booker: booker,
Riders: riders
})
.then(res => {
wx.hideLoading()
if (res.Error == 1) {
wx.showModal({
title: '温馨提示',
content: res.Message,
showCancel:false
})
return
}
if (res.Data.StateCode == 'BookSuccess') {
that.setStorage(res)
util.redirect('../Pay/index')
} else {
wx.showModal({
title: '温馨提示',
content: "下单失败,座位已售完!",
showCancel:false
})
}
})
},
setStorage(res) {
var obj = {}
obj.orderCode = res.Data.OrderCode
obj.payMoney = payMoney
obj.coupnValue = this.data.disValue
obj.coupnCode = disCoupnCode
obj.insurancePrice = this.data.selectIndPrice,
obj.sum = this.data.oldSum
wx.setStorage({
key: commenValue.orderInfo,
data: obj
})
},
getSaleMinute() {
var that = this
request(commenValue.POST, commenValue.getConfigUrl, {
configCode: commenValue.StopSaleMinuteBeforeScheduleStart
})
.then(res => {
if (res.Error == 1) return
if (res.Data.hasOwnProperty('Value')) {
timeOut = res.Data.Value
}
that.getMaxTicketCount()
}).catch(function(e) {
console.info(e)
})
},
getMaxTicketCount() {
var that = this
request(commenValue.POST, commenValue.getConfigUrl, {
configCode: commenValue.MaxTicketCountPerOrder
})
.then(res => {
if (res.Error == 1) return
if (res.Data.hasOwnProperty('Value')) {
that.setData({
maxTicketCount: res.Data.Value
})
}
that.getTicketNum()
wx.hideLoading()
}).catch(function(e) {
console.error(e)
})
},
checkInsurance(e) {
var that = this
if (indIndex == 0 && this.data.selectIndPrice > 0) {
that.setData({
selectIndPrice: 0
})
}
if (indIndex % 2 == 0) {
that.setData({
selectIndPrice: 0
})
} else {
that.setData({
selectIndPrice: selectIndPrice
})
}
indIndex++
setTimeout(function() {
that.bindManual()
}, 100)
},
/* 点击减号 */
bindMinus: function(e) {
var num = 0;
var minusStatus = "";
if (e.currentTarget.id == 'fullAdd') {
num = this.data.fullTicketSum;
if (num > 1) {
num--;
}
minusStatus = num <= 1 ? commenValue.disabled : commenValue.normal;
} else {
if (e.currentTarget.id == 'halfAdd')
num = this.data.halfTicketSum;
if (e.currentTarget.id == 'noAdd')
num = this.data.noTicketSum;
if (num > 0) {
num--;
}
minusStatus = num <= 0 ? commenValue.disabled : commenValue.normal;
}
if (e.currentTarget.id == 'fullAdd') {
this.setData({
fullTicketSum: num,
fullMinusStatus: minusStatus
});
}
if (e.currentTarget.id == 'halfAdd') {
this.setData({
halfTicketSum: num,
halfMinusStatus: minusStatus
});
}
if (e.currentTarget.id == 'noAdd') {
this.setData({
noTicketSum: num,
noMinusStatus: minusStatus
});
}
this.bindManual();
},
/* 点击加号 */
bindPlus: function(e) {
var num = 0;
if (e.currentTarget.id == 'fullDel')
num = this.data.fullTicketSum;
if (e.currentTarget.id == 'halfDel')
num = this.data.halfTicketSum;
if (e.currentTarget.id == 'noDel') {
num = this.data.noTicketSum;
if (num >= 1) return
}
num++;
var minusStatus = num < 1 ? commenValue.disabled : commenValue.normal;
if (e.currentTarget.id == 'fullDel') {
this.setData({
fullTicketSum: num,
fullMinusStatus: minusStatus
});
}
if (e.currentTarget.id == 'halfDel') {
this.setData({
halfTicketSum: num,
halfMinusStatus: minusStatus
});
}
if (e.currentTarget.id == 'noDel') {
this.setData({
noTicketSum: num,
noMinusStatus: minusStatus
});
}
this.bindManual();
},
/* 输入框事件 */
bindManual: function() {
const price = this.data.ticketPrice;
var oldSum = price * this.data.fullTicketSum + price * this.data.halfTicketSum / 2 + this.data.selectIndPrice * (this.data.fullTicketSum + this.data.halfTicketSum)
var disVs = this.data.disValue * (this.data.fullTicketSum + Math.floor(this.data.halfTicketSum / 2))
var sum = oldSum - disVs
this.setData({
sum: sum,
oldSum: oldSum,
disVs: disVs
})
payMoney = sum
},
toastHide(event) {
this.setData({
toastStatus: true
})
},
getTicketNum() {
var selectStop = wx.getStorageSync(commenValue.selectStop)
var beigin = selectStop.startStopCode
var end = selectStop.endStopCode
if (selectSchedule.scheduleCode == null) return
request(commenValue.POST, commenValue.getStopTicketCountUrl, {
ScheduleCode: selectSchedule.scheduleCode,
BeginStopCode: beigin,
endStopCode: end
}).then(res => {
this.setData({
remainSeatCount: res.Data.RemainSeats[0].RemainSeatCount,
})
this.bindManual()
})
},
getCoupons() {
var that = this
if (selectSchedule.scheduleCode == null) return
request(commenValue.POST, commenValue.getCouponsUrl, {
MemberCode: wx.getStorageSync(commenValue.memberCode),
ScheduleCode: selectSchedule.scheduleCode,
TerminalCode: commenValue.terminalCode,
TotalPrice: payMoney
}).then(res => {
console.log(res)
if (res.Error == 1) {
wx.hideLoading()
wx.showToast({
title: res.Message
})
return
}
console.log(res)
if (res.Data.hasOwnProperty('Coupons')) {
var disList = []
for (var i = 0; i < res.Data.Coupons.length; i++) {
var obj = {}
obj.id = i
obj.couponsCode = res.Data.Coupons[i].Code
obj.discount = res.Data.Coupons[i].ActivityName
obj.disValue = res.Data.Coupons[i].Amount
obj.disDate = res.Data.Coupons[i].ExpireTime.split('T')[0]
disList.push(obj)
}
that.setData({
disList: disList
})
if (disList.length > 0){
that.setCoupons()
}else{
that.setData({
disCoupe:0
})
}
}
that.getSaleMinute()
})
},
setCoupons(e) {
var id = 0;
if (e != null)
id = e.currentTarget.dataset.id;
if (id == -1) {
this.setData({
disCoupe: dispalyCoupn,
disValue: 0
})
} else {
disCoupnCode = this.data.disList[id].couponsCode
this.setData({
disCoupe: this.data.disList[id].discount,
disValue: this.data.disList[id].disValue
})
}
console.log(this.data.disCoupe)
//this.bindManual()
// if (id > 0)
this.powerDrawer(e)
},