detail.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. const app = getApp();
  2. const {
  3. inArray
  4. } = require("../../../common/js/common.js");
  5. let self;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. id: 0,
  12. TabCur: 0,
  13. scrollLeft: 0,
  14. dateList: [],
  15. timeList: [],
  16. today: '',
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad(options) {
  22. self = this;
  23. self.data.today = self.getToday();
  24. self.setData({
  25. id: options.id
  26. });
  27. self.calcData();
  28. app.post('teahouse/teahouse/getTimeByDate',{date:self.data.dateList[self.data.TabCur].fullname,lock_id:self.data.id},function(res) {
  29. self.calcTime(res);
  30. wx.hideLoading();
  31. });
  32. },
  33. getToday() {
  34. const today = new Date();
  35. const year = today.getFullYear();;
  36. const month = String(today.getMonth() + 1).padStart(2, '0');
  37. const day = String(today.getDate()).padStart(2, '0');
  38. return `${year}年${month}月${day}日`;
  39. },
  40. calcData() {
  41. const dates = [];
  42. const today = new Date();
  43. for (let i = 0; i <= 9; i++) {
  44. const futureDate = new Date(today);
  45. futureDate.setDate(today.getDate() + i);
  46. const year = futureDate.getFullYear();
  47. const month = String(futureDate.getMonth() + 1).padStart(2, '0');
  48. const day = String(futureDate.getDate()).padStart(2, '0');
  49. dates.push({fullname:`${year}年${month}月${day}日`,name:`${month}月${day}日`});
  50. }
  51. self.setData({
  52. dateList: dates
  53. });
  54. },
  55. calcTime(selected = []) {
  56. const now = new Date();
  57. const currentHour = now.getHours();
  58. let times = [];
  59. for (let i = 0; i < 24; i++) {
  60. let item = {name:self.formatNumber(i) + ':00 - ' + self.formatNumber(i + 1) + ':00',select:false,disabled:false};
  61. if (self.data.dateList[self.data.TabCur].fullname == self.data.today && i < currentHour) {
  62. item.disabled = true;
  63. } else if (inArray(item.name,selected)) {
  64. item.disabled = true;
  65. }
  66. times.push(item);
  67. }
  68. self.setData({
  69. timeList: times
  70. });
  71. },
  72. formatNumber(n) {
  73. n = n.toString()
  74. return n[1] ? n : '0' + n
  75. },
  76. selectTime(e) {
  77. let disabled = e.currentTarget.dataset.disabled;
  78. if (!disabled) {
  79. let index = e.currentTarget.dataset.index;
  80. let timeList = self.data.timeList;
  81. timeList[index].select = !timeList[index].select;
  82. self.setData({timeList:timeList});
  83. }
  84. },
  85. tabSelect(e) {
  86. wx.showLoading()
  87. self.setData({
  88. TabCur: e.currentTarget.dataset.id,
  89. scrollLeft: (e.currentTarget.dataset.id - 1) * 60
  90. })
  91. app.post('teahouse/teahouse/getTimeByDate',{date:self.data.dateList[self.data.TabCur].fullname,lock_id:self.data.id},function(res) {
  92. self.calcTime(res);
  93. wx.hideLoading();
  94. });
  95. },
  96. onSubmit() {
  97. let date = self.data.dateList[self.data.TabCur].fullname;
  98. let time = [];
  99. for (let item of self.data.timeList) {
  100. if (item.select) {
  101. time.push(item.name);
  102. }
  103. }
  104. if (time.length == 0) {
  105. wx.showToast({
  106. title: '请选择预约时间',
  107. icon: 'none',
  108. })
  109. return false;
  110. }
  111. app.post('teahouse/teahouse/reservation',{lock_id:self.data.id,date:date,time:time},function(){
  112. wx.showToast({
  113. title: '预约成功',
  114. success: function() {
  115. wx.navigateBack();
  116. },
  117. })
  118. });
  119. },
  120. /**
  121. * 用户点击右上角分享
  122. */
  123. onShareAppMessage() {
  124. return {
  125. title: "晋爱人才",
  126. path: "/pages/home/home/home",
  127. };
  128. }
  129. })