const db = wx.cloud.database();
import { formatTime, formatDate } from '../../utils/util.js';
Page({
data: {
focus: false,
inputValue: '',
startTime: '08:00',
endTime: '',
array: ['0.5h', '1.0h', '2.0h', '3.0h', '5.0h'],
objectArray: [
{
id: 0,
name: '0.5'
},
{
id: 1,
name: '1.0'
},
{
id: 2,
name: '2.0'
},
{
id: 3,
name: '3.0'
}
,
{
id: 4,
name: '5.0'
}
],
index: 0,
flag: 1,
temp: 0,
seatnow: 0,
color: [
['green', 'green', 'green', 'green', 'green'],
['green', 'green', 'green', 'green', 'green'],
['green', 'green', 'green', 'green', 'green',]
]
},
onLoad: function (options) {
const that = this;
// //获取当前时间
var TIME = formatTime(new Date());
that.setData({
TIME: TIME
})
that.setData({
nowHour: parseInt((that.data.TIME).substring(0, 2)),
nowMin: parseInt((that.data.TIME).substring(3, 5))
})
if (that.data.nowHour < 21 && that.data.nowHour >= 8) {
that.setData({
firstTime: TIME,
startTime: TIME
});
}
wx.cloud.callFunction({
name: 'get',
}).then(res => {
that.setData({
code_openid: res.result.openid
})
//根据云函数获取Student表信息
wx.cloud.callFunction({
name: "getStuInfo",
data: {
openid: that.data.code_openid
}
}).then(res => {
that.setData({
stu_id: res.result.data[0].id
})
})
//根据云函数获取我的预约信息
wx.cloud.callFunction({
name: "checkMyBookInfo",
data: {
openid: that.data.code_openid
}
}).then(res => {
that.setData({
my_seat_id: res.result.data[0].seat_id,
temp: res.result.data.length,
book_end_time: res.result.data[0].bookEndTime,
book_start_time: res.result.data[0].bookStartTime
})
}).then(res => {
var a = that.data.my_seat_id.split("-");
var x = parseInt(a[0]);
var y = parseInt(a[1]);
var col = "color[" + x + "][" + y + "]";
// if (a != undefined) {
// wx.cloud.callFunction({
// name: "checkSeatInfo",
// data: {
// openid: that.data.code_openid
// }
// }).then(res => {
// console.log(res.result.data[0].seat_x, res.result.data[0].seat_y, res.result.data[0].isCancel)
// that.setData({
// seat_x: res.result.data[0].seat_x,
// seat_y: res.result.data[0].seat_y,
// isCancel: res.result.data[0].isCancel
// })
// })
// }
that.setData({
[col]: 'blue'
})
if (that.data.color[x][y] == 'blue') {
that.setData({
seatnow: 1
})
}
})
//根据云函数获取他人预约信息
wx.cloud.callFunction({
name: "checkOthersBookInfo",
data: {
openid: that.data.code_openid,
}
}).then(res => {
that.setData({
array_length: res.result.data.length
})
for (var i = 0; i < that.data.array_length; i++) {
that.setData({
["others_seat_id[" + i + "]"]: res.result.data[i].seat_id,
["others_book_end_time[" + i + "]"]: res.result.data[i].bookEndTime,
["others_book_start_time[" + i + "]"]: res.result.data[i].bookStartTime
})
}
}).then(res => {
for (var i = 0; i < that.data.array_length; i++) {
var a = that.data.others_seat_id[i].split("-");
var x = parseInt(a[0]);
var y = parseInt(a[1]);
var col = "color[" + x + "][" + y + "]";
var oendH = parseInt((that.data.others_book_end_time[i]).substring(0, 2));
var oendM = parseInt((that.data.others_book_end_time[i]).substring(3, 5));
var ostartH = parseInt((that.data.others_book_start_time[i]).substring(0, 2));
var ostartM = parseInt((that.data.others_book_start_time[i]).substring(3, 5));
if (that.data.nowHour < ostartH) {
console.log(1);
that.setData({
[col]: 'grey',
})
}
else if (that.data.nowHour == ostartH && that.data.nowMin <= ostartM) {
console.log(11);
that.setData({
[col]: 'grey',
})
}
else if (that.data.nowHour == ostartH && that.data.nowMin >= ostartM) {
console.log(111);
that.setData({
[col]: 'red',
})
}
else if (that.data.nowHour > ostartH && that.data.nowMin<oendM) {
console.log(1111);
that.setData({
[col]: 'red',
})
}
if(that.data.nowHour>oendH ||(that.data.nowHour==oendH && that.data.nowMin>oendM)){
console.log(11111);
wx.cloud.callFunction({
name: "removeBooked",
data: {
openid: that.data.code_openid
},
success:function(){
that.setData({
[col]:'green'
})
}
})
}
}
})
})
},
bindStartTimeChange: function (e) {
console.log('picker发送选择改变,携带值为', e.detail.value)
this.setData({
startTime: e.detail.value
})
},
bindPickerChange: function (e) {
console.log('picker发送选择改变,携带值为', e.detail.value)
this.setData({
index: e.detail.value
})
},
onReady: function (options) {
//获取当前时间
var DATE = formatDate(new Date());
this.setData({
nowDate: DATE
})
var that = this;
var onload_time = formatTime(new Date());
var TIME = onload_time;
var time_flag = 0;
setInterval(function () {
that.setData({
TIME: formatTime(new Date())
})
that.setData({
nowHour: parseInt((that.data.TIME).substring(0, 2)),
nowMin: parseInt((that.data.TIME).substring(3, 5))
})
if (that.data.nowHour < 21 && that.data.nowHour >= 8) {
if (that.data.hasbook == true && time_flag == 0) {
var endH = parseInt((that.data.book_end_time).substring(0, 2));
var endM = parseInt((that.data.book_end_time).substring(3, 5));
if (endH < that.data.nowHour) {
time_flag = 1;
wx.cloud.callFunction({
name: "removeMyBook",
data: {
openid: that.data.code_openid
}
})
}
else if (endH == that.data.nowHour) {
if (endM <= that.data.nowMin) {
time_flag = 1;
wx.cloud.callFunction({
name: "removeMyBook",
data: {
openid: that.data.code_openid
}
})
}
}
}
}
}, 1000);
},
//更新endTime
setEndTime(endHour, endMin) {
if (parseInt(endHour) < 10) {
if (parseInt(endMin) < 10) {
this.setData({
endTime: "0" + endHour + ":0" + endMin
})
console.log(this.data.endTime);
}
else {
this.setData({
endTime: "0" + endHour + ":" + endMin
})
console.log(this.data.endTime);
}
}
else {
if (parseInt(endMin) < 10) {
this.setData({
endTime: endHour + ":0" + endMin
})
console.log(this.data.endTime);
}
else {
this.setData({
endTime: endHour + ":" + endMin
})
console.log(this.data.endTime);
}
}
},
//提交表单数据添加到数据库
- 1
- 2
前往页