254 lines
5.8 KiB
JavaScript
254 lines
5.8 KiB
JavaScript
|
// pages/book/book.js
|
||
|
const app = getApp()
|
||
|
Page({
|
||
|
|
||
|
/**
|
||
|
* 页面的初始数据
|
||
|
*/
|
||
|
data: {
|
||
|
groundInfoId: '',
|
||
|
week: '',
|
||
|
date: '',
|
||
|
venueList: [],
|
||
|
allPrice: 0,
|
||
|
selectedTime: [],
|
||
|
isSelected: false,
|
||
|
token: '',
|
||
|
requestIp: '',
|
||
|
selectedTab: 0,
|
||
|
selectedGround: [],
|
||
|
projectId: '',
|
||
|
projectName: ''
|
||
|
},
|
||
|
changeTab: function (e) {
|
||
|
var cur = parseInt(e.currentTarget.dataset.idx)
|
||
|
var arr = this.data.venueList[cur].configSplitDTOS
|
||
|
this.setData({
|
||
|
selectedTab: cur,
|
||
|
selectedGround: arr
|
||
|
})
|
||
|
},
|
||
|
toggleSelect: function (e) {
|
||
|
var event = e.currentTarget.dataset
|
||
|
console.log(event)
|
||
|
var arr = this.data.venueList
|
||
|
var price = parseInt(this.data.allPrice)
|
||
|
var list = this.data.selectedTime
|
||
|
var change = 'selectedGround[' + event.count + '].status'
|
||
|
if(list.length <= 0){
|
||
|
var newTime = [{
|
||
|
start: event.start,
|
||
|
end: event.end,
|
||
|
price: event.price,
|
||
|
ground: event.ground,
|
||
|
groundName: this.data.venueList[this.data.selectedTab].groundName,
|
||
|
itemId: event.item
|
||
|
}]
|
||
|
var resultPrice = this.data.allPrice + parseInt(event.price)
|
||
|
this.setData({
|
||
|
selectedTime: this.data.selectedTime.concat(newTime),
|
||
|
allPrice: resultPrice,
|
||
|
[change]: 'selecting',
|
||
|
isSelected: true
|
||
|
})
|
||
|
} else {
|
||
|
var isExist = false;
|
||
|
var cur = 0;
|
||
|
for (var i = 0; i < list.length; i++) {
|
||
|
if (event.ground == list[i].ground && event.start == list[i].start) {
|
||
|
isExist = true;
|
||
|
cur = i;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (isExist) {
|
||
|
var result = this.data.selectedTime.splice(cur, 1);
|
||
|
var resultPrice = this.data.allPrice - parseInt(event.price);
|
||
|
this.setData({
|
||
|
allPrice: resultPrice,
|
||
|
selectedTime: this.data.selectedTime,
|
||
|
[change]: ''
|
||
|
})
|
||
|
if(this.data.selectedTime.length == 0){
|
||
|
this.setData({
|
||
|
isSelected: false
|
||
|
})
|
||
|
}
|
||
|
} else {
|
||
|
var newTime = [{
|
||
|
start: event.start,
|
||
|
end: event.end,
|
||
|
price: event.price,
|
||
|
ground: event.ground,
|
||
|
groundName: this.data.venueList[this.data.selectedTab].groundName,
|
||
|
itemId: event.item
|
||
|
}]
|
||
|
var resultPrice = this.data.allPrice + parseInt(event.price)
|
||
|
this.setData({
|
||
|
selectedTime: this.data.selectedTime.concat(newTime),
|
||
|
allPrice: resultPrice,
|
||
|
[change]: 'selecting'
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
submitOrder: function () {
|
||
|
var self = this
|
||
|
var submitInfo = []
|
||
|
for (var i = 0; i < self.data.selectedTime.length; i++) {
|
||
|
var item = {
|
||
|
bookingOrderDate: self.data.date,
|
||
|
groundItemId: self.data.selectedTime[i].itemId
|
||
|
}
|
||
|
submitInfo.push(item)
|
||
|
}
|
||
|
var info = {
|
||
|
venuesProjectId: self.data.projectId,
|
||
|
bookingItemList: submitInfo
|
||
|
}
|
||
|
wx.request({
|
||
|
url: self.data.requestIp + 'app/wechatprogram/savebookinginfo',
|
||
|
method: 'post',
|
||
|
header: {
|
||
|
"token": self.data.token
|
||
|
},
|
||
|
data: info,
|
||
|
success: function (res) {
|
||
|
if(res.statusCode == 200){
|
||
|
wx.showToast({
|
||
|
title: '预约成功',
|
||
|
icon: 'success',
|
||
|
duration: 2000,//持续的时间
|
||
|
success: function () {
|
||
|
setTimeout(function(){
|
||
|
wx.switchTab({
|
||
|
url: '../home/home',
|
||
|
})
|
||
|
}, 2000)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
},
|
||
|
fail: function (res) {
|
||
|
wx.showToast({
|
||
|
title: res.msg,
|
||
|
duration: 2000
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
initDate: function () {
|
||
|
var date = new Date()
|
||
|
var year = date.getFullYear()
|
||
|
var month = date.getMonth() + 1
|
||
|
var day = date.getDate() + 1
|
||
|
if (month < 10) {
|
||
|
month = '0' + month
|
||
|
}
|
||
|
if (day < 10) {
|
||
|
day = '0' + day
|
||
|
}
|
||
|
var today = year + '-' + month + '-' + day
|
||
|
var weekArray = new Array("日", "一", "二", "三", "四", "五", "六");
|
||
|
var now = year + '/' + month + '/' + day;
|
||
|
var week = '星期' + weekArray[new Date(now).getDay()];
|
||
|
console.log(week)
|
||
|
this.setData({
|
||
|
date: today,
|
||
|
week: week
|
||
|
})
|
||
|
},
|
||
|
getToken: function () {
|
||
|
var self = this
|
||
|
wx.getStorage({
|
||
|
key: 'token',
|
||
|
success: function (res) {
|
||
|
self.setData({
|
||
|
token: res.data
|
||
|
})
|
||
|
self.initDate()
|
||
|
self.getGroundList()
|
||
|
},
|
||
|
})
|
||
|
},
|
||
|
getGroundList: function () {
|
||
|
var self = this
|
||
|
wx.request({
|
||
|
url: self.data.requestIp + 'app/wechatprogram/listgroundinfoanditem',
|
||
|
data: {
|
||
|
venuesProjectId: self.data.projectId,
|
||
|
},
|
||
|
header: {
|
||
|
"token": self.data.token
|
||
|
},
|
||
|
success: function (res) {
|
||
|
self.setData({
|
||
|
venueList: res.data.data,
|
||
|
selectedGround: res.data.data[0].groundItemList
|
||
|
})
|
||
|
console.log(self.data.venueList)
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
/**
|
||
|
* 生命周期函数--监听页面加载
|
||
|
*/
|
||
|
onLoad: function (options) {
|
||
|
this.setData({
|
||
|
requestIp: app.globalData.requestIp,
|
||
|
projectId: options.projectId,
|
||
|
projectName: options.name
|
||
|
})
|
||
|
console.log()
|
||
|
this.getToken()
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面初次渲染完成
|
||
|
*/
|
||
|
onReady: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面显示
|
||
|
*/
|
||
|
onShow: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面隐藏
|
||
|
*/
|
||
|
onHide: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面卸载
|
||
|
*/
|
||
|
onUnload: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面相关事件处理函数--监听用户下拉动作
|
||
|
*/
|
||
|
onPullDownRefresh: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面上拉触底事件的处理函数
|
||
|
*/
|
||
|
onReachBottom: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 用户点击右上角分享
|
||
|
*/
|
||
|
onShareAppMessage: function () {
|
||
|
|
||
|
}
|
||
|
})
|