223 lines
5.1 KiB
JavaScript
Raw Normal View History

2024-03-12 11:13:43 +08:00
const app = getApp()
import Notify from '@vant/weapp/notify/notify';
import {
appointmentRecordRq,
selectFreeShowRoomRq
} from "../../../../api/meeting/exhibition.js"
import {
selfFormatTimeYMDHMS,
selfFormatTimeYMDH
} from "../../../../utils/util.js"
Page({
/**
* 页面的初始数据
*/
data: {
IMG_NAME: app.IMG_NAME,
2024-03-12 11:13:43 +08:00
id: null,
minTime: null,
maxTime: null,
endMaxTime: null,
startTime: null,
endTime: null,
showTime: false,
dataList: [],
filterTime(type, options) {
if (type === 'minute') {
2024-03-18 11:49:40 +08:00
return options.filter((option) => option == '00' || option == '30');
2024-03-12 11:13:43 +08:00
}
return options;
},
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log('onLoad', options);
// 获取传递参数
this.setData({
...options
})
// 初始化时间
this.initParamTime()
},
// 初始化时间
initParamTime() {
let maxTime = new Date();
maxTime.setFullYear(maxTime.getFullYear() + 3)
this.setData({
maxTime: maxTime.getTime()
})
this.setEndMaxTime(this.data.startTime)
// 设置最小时间
this.setMinTime()
},
// 设置最小时间
setMinTime() {
let minTime = new Date(selfFormatTimeYMDH(new Date()) + ':00:00').getTime()
this.setData({
minTime,
startTime: minTime
})
},
// 指定天的最后一秒
setEndMaxTime(time) {
let endMaxTime = new Date(new Date(time).toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1;
this.setData({
endMaxTime: endMaxTime
})
},
// 选择-开始时间
onInputStartTime(event) {
this.setData({
startTime: event.detail,
});
this.setEndMaxTime(event.detail)
},
// 选择-结束时间
onInputEndTime(event) {
let _this = this;
this.setData({
endTime: event.detail,
});
},
// 预约时间
reservationTime() {
this.setData({
showTime: true
})
},
// 确认时间
confirmTime() {
let _this = this;
2024-04-07 17:00:25 +08:00
let id = _this.data.id;
2024-03-12 11:13:43 +08:00
let startTime = _this.data.startTime;
let endTime = _this.data.endTime;
let paramUrl = "?id=" + id + "&startTime=" + selfFormatTimeYMDHMS(startTime) + "&endTime=" + selfFormatTimeYMDHMS(endTime);
2024-03-18 13:39:18 +08:00
// 预约时间不能小于30分钟
if ((1000 * 60 * 30) > (endTime - startTime)) {
2024-03-12 11:13:43 +08:00
Notify({
type: 'danger',
2024-03-18 13:39:18 +08:00
message: '预约时间不能小于30分钟',
2024-03-12 11:13:43 +08:00
duration: 1000,
selector: '#notify',
});
return
}
// 查询展厅能否预约
selectFreeShowRoomRq({
"id": id,
"startTime": selfFormatTimeYMDHMS(startTime),
"endDate": selfFormatTimeYMDHMS(endTime)
}).then(res => {
console.log('selectFreeShowRoomRq', res);
// 可以预约
if (res.code == 0) {
wx.navigateTo({
url: "/pages/meeting/exhibition/order/order" + paramUrl,
})
_this.setData({
showTime: false
})
} else { // 不能预约
Notify({
type: 'danger',
message: res.msg,
duration: 1000,
selector: '#notify',
});
}
})
},
// 取消时间
cancelTime() {
this.setData({
showTime: false
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
console.log('onShow');
let _this = this;
appointmentRecordRq({
"showroomId": _this.data.id
}).then(res => {
console.log('appointmentRecordRq', res);
let dataList = res.data;
dataList.map(item => {
item.nowDate = item.nowDate.substring(0, 10);
2024-03-12 12:00:14 +08:00
item.showroomRecords = item.showroomRecords.map(record => {
2024-03-12 11:13:43 +08:00
record.startTime = record.startTime.substring(11)
record.endDate = record.endDate.substring(11)
return record;
})
return item
})
_this.setData({
dataList
})
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})