| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- const app = getApp();
- const {
- inArray
- } = require("../../../common/js/common.js");
- let self;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- id: 0,
- TabCur: 0,
- scrollLeft: 0,
- dateList: [],
- timeList: [],
- today: '',
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- self = this;
- self.data.today = self.getToday();
- self.setData({
- id: options.id
- });
- self.calcData();
- app.post('teahouse/teahouse/getTimeByDate',{date:self.data.dateList[self.data.TabCur].fullname,lock_id:self.data.id},function(res) {
- self.calcTime(res);
- wx.hideLoading();
- });
- },
- getToday() {
- const today = new Date();
- const year = today.getFullYear();;
- const month = String(today.getMonth() + 1).padStart(2, '0');
- const day = String(today.getDate()).padStart(2, '0');
- return `${year}年${month}月${day}日`;
- },
- calcData() {
- const dates = [];
- const today = new Date();
- for (let i = 0; i <= 9; i++) {
- const futureDate = new Date(today);
- futureDate.setDate(today.getDate() + i);
- const year = futureDate.getFullYear();
- const month = String(futureDate.getMonth() + 1).padStart(2, '0');
- const day = String(futureDate.getDate()).padStart(2, '0');
- dates.push({fullname:`${year}年${month}月${day}日`,name:`${month}月${day}日`});
- }
- self.setData({
- dateList: dates
- });
- },
- calcTime(selected = []) {
- const now = new Date();
- const currentHour = now.getHours();
- let times = [];
- for (let i = 0; i < 24; i++) {
- let item = {name:self.formatNumber(i) + ':00 - ' + self.formatNumber(i + 1) + ':00',select:false,disabled:false};
- if (self.data.dateList[self.data.TabCur].fullname == self.data.today && i < currentHour) {
- item.disabled = true;
- } else if (inArray(item.name,selected)) {
- item.disabled = true;
- }
-
- times.push(item);
- }
- self.setData({
- timeList: times
- });
- },
- formatNumber(n) {
- n = n.toString()
- return n[1] ? n : '0' + n
- },
- selectTime(e) {
- let disabled = e.currentTarget.dataset.disabled;
- if (!disabled) {
- let index = e.currentTarget.dataset.index;
- let timeList = self.data.timeList;
- timeList[index].select = !timeList[index].select;
- self.setData({timeList:timeList});
- }
- },
- tabSelect(e) {
- wx.showLoading()
- self.setData({
- TabCur: e.currentTarget.dataset.id,
- scrollLeft: (e.currentTarget.dataset.id - 1) * 60
- })
- app.post('teahouse/teahouse/getTimeByDate',{date:self.data.dateList[self.data.TabCur].fullname,lock_id:self.data.id},function(res) {
- self.calcTime(res);
- wx.hideLoading();
- });
- },
- onSubmit() {
- let date = self.data.dateList[self.data.TabCur].fullname;
- let time = [];
- for (let item of self.data.timeList) {
- if (item.select) {
- time.push(item.name);
- }
- }
- if (time.length == 0) {
- wx.showToast({
- title: '请选择预约时间',
- icon: 'none',
- })
- return false;
- }
- app.post('teahouse/teahouse/reservation',{lock_id:self.data.id,date:date,time:time},function(){
- wx.showToast({
- title: '预约成功',
- success: function() {
- wx.navigateBack();
- },
- })
- });
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- return {
- title: "晋爱人才",
- path: "/pages/home/home/home",
- };
- }
- })
|