active-page.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // active-page.js
  2. const { museumApi } = require('../../../utils/api.js');
  3. Page({
  4. data: {
  5. selectedTime: '',
  6. selectedDate: null,
  7. step: 1,
  8. activityId: 0, // 活动ID
  9. type: 1, // 预约类型:1-普通预约,2-活动预约
  10. activityData: {}
  11. },
  12. onLoad(options) {
  13. // 页面加载时的逻辑
  14. console.log('active-page接收到的参数:', options);
  15. if (options.activityId) {
  16. this.setData({
  17. activityId: parseInt(options.activityId)
  18. });
  19. }
  20. if (options.type) {
  21. this.setData({
  22. type: parseInt(options.type)
  23. });
  24. }
  25. },
  26. onReady() {
  27. // 页面初次渲染完成后获取活动详情
  28. if (this.data.activityId) {
  29. this.getActivityInfo(this.data.activityId);
  30. }
  31. },
  32. onShow() {
  33. // 页面显示时的逻辑
  34. },
  35. // 日期选择回调
  36. onDateChange(e) {
  37. console.log('选择的日期:', e.detail);
  38. const selectedDate = e.detail.dateString;
  39. // 只有当日期可选时才设置selectedDate
  40. if (selectedDate) {
  41. this.setData({
  42. selectedDate: selectedDate,
  43. selectedTime: '' // 清空时间选择状态
  44. });
  45. } else {
  46. // 如果日期不可选,清空选择状态
  47. this.setData({
  48. selectedDate: null,
  49. selectedTime: ''
  50. });
  51. }
  52. },
  53. // 格式化日期
  54. formatDate(date) {
  55. const year = date.getFullYear();
  56. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  57. const day = date.getDate().toString().padStart(2, '0');
  58. return `${year}-${month}-${day}`;
  59. },
  60. // 选择时间段
  61. selectTime(e) {
  62. if (this.data.selectedDate && this.data.activityData.time) {
  63. this.setData({
  64. selectedTime: 'selected'
  65. });
  66. console.log('选择的时间段:', this.data.activityData.time);
  67. } else {
  68. wx.showToast({
  69. title: '请先选择日期',
  70. icon: 'none'
  71. });
  72. }
  73. },
  74. // 下一步
  75. goNext() {
  76. if (this.data.selectedDate && this.data.activityData.title) {
  77. console.log('选择的日期:', this.data.selectedDate);
  78. console.log('活动标题:', this.data.activityData.title);
  79. // 传递活动标题而不是appointmentSlotsId
  80. const title = this.data.activityData.title;
  81. wx.navigateTo({
  82. url: `/pages/index/active-people/active-people?date=${this.data.selectedDate}&title=${encodeURIComponent(title)}&type=2&activityId=${this.data.activityId}`
  83. });
  84. } else {
  85. wx.showToast({
  86. title: '请选择日期',
  87. icon: 'none'
  88. });
  89. }
  90. },
  91. onShareAppMessage() {
  92. return {
  93. title: '克拉玛依博物馆 - 开始预约',
  94. path: '/pages/index/start-preview/start-preview'
  95. };
  96. },
  97. // 获取活动详情
  98. getActivityInfo(activityId) {
  99. museumApi.getActivityInfo(activityId)
  100. .then(response => {
  101. console.log('获取活动详情成功:', response);
  102. if (response) {
  103. const activityData = response;
  104. console.log('活动数据:', activityData);
  105. // 将活动数据设置到页面data中,通过属性传递给子组件
  106. this.setData({
  107. activityData: activityData
  108. });
  109. } else {
  110. console.log('API响应数据为空:', response);
  111. }
  112. })
  113. .catch(error => {
  114. console.error('获取活动详情失败:', error);
  115. });
  116. }
  117. });