123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- // active-page.js
- const { museumApi } = require('../../../utils/api.js');
- Page({
- data: {
- selectedTime: '',
- selectedDate: null,
- step: 1,
- activityId: 0, // 活动ID
- type: 1, // 预约类型:1-普通预约,2-活动预约
- activityData: {}
- },
- onLoad(options) {
- // 页面加载时的逻辑
- console.log('active-page接收到的参数:', options);
- if (options.activityId) {
- this.setData({
- activityId: parseInt(options.activityId)
- });
- }
- if (options.type) {
- this.setData({
- type: parseInt(options.type)
- });
- }
- },
- onReady() {
- // 页面初次渲染完成后获取活动详情
- if (this.data.activityId) {
- this.getActivityInfo(this.data.activityId);
- }
- },
- onShow() {
- // 页面显示时的逻辑
- },
- // 日期选择回调
- onDateChange(e) {
- console.log('选择的日期:', e.detail);
- const selectedDate = e.detail.dateString;
-
- // 只有当日期可选时才设置selectedDate
- if (selectedDate) {
- this.setData({
- selectedDate: selectedDate,
- selectedTime: '' // 清空时间选择状态
- });
- } else {
- // 如果日期不可选,清空选择状态
- this.setData({
- selectedDate: null,
- selectedTime: ''
- });
- }
- },
- // 格式化日期
- formatDate(date) {
- const year = date.getFullYear();
- const month = (date.getMonth() + 1).toString().padStart(2, '0');
- const day = date.getDate().toString().padStart(2, '0');
- return `${year}-${month}-${day}`;
- },
- // 选择时间段
- selectTime(e) {
- if (this.data.selectedDate && this.data.activityData.time) {
- this.setData({
- selectedTime: 'selected'
- });
- console.log('选择的时间段:', this.data.activityData.time);
- } else {
- wx.showToast({
- title: '请先选择日期',
- icon: 'none'
- });
- }
- },
- // 下一步
- goNext() {
- if (this.data.selectedDate && this.data.activityData.title) {
- console.log('选择的日期:', this.data.selectedDate);
- console.log('活动标题:', this.data.activityData.title);
-
- // 传递活动标题而不是appointmentSlotsId
- const title = this.data.activityData.title;
-
- wx.navigateTo({
- url: `/pages/index/active-people/active-people?date=${this.data.selectedDate}&title=${encodeURIComponent(title)}&type=2&activityId=${this.data.activityId}`
- });
- } else {
- wx.showToast({
- title: '请选择日期',
- icon: 'none'
- });
- }
- },
- onShareAppMessage() {
- return {
- title: '克拉玛依博物馆 - 开始预约',
- path: '/pages/index/start-preview/start-preview'
- };
- },
- // 获取活动详情
- getActivityInfo(activityId) {
- museumApi.getActivityInfo(activityId)
- .then(response => {
- console.log('获取活动详情成功:', response);
- if (response) {
- const activityData = response;
- console.log('活动数据:', activityData);
- // 将活动数据设置到页面data中,通过属性传递给子组件
- this.setData({
- activityData: activityData
- });
- } else {
- console.log('API响应数据为空:', response);
- }
- })
- .catch(error => {
- console.error('获取活动详情失败:', error);
- });
- }
- });
|