lrj
11 小时以前 ae3349d2ff53767b5bc9cb30e1bf7e15f9e814ee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// pages/activity/detail.js
const app = getApp()
const utils = require('../../lib/utils.js')
 
Page({
  data: {
    activityId: null,
    activity: null,
    myApplication: null,
    buttonDisabled: false,
    buttonText: '我要报名',
    loading: true,
    error: null
  },
 
  onLoad(options) {
    if (options.id) {
      this.setData({ activityId: options.id });
      this.loadActivityDetail(options.id);
    } else {
      this.setData({ loading: false, error: '无效的比赛ID' });
    }
  },
 
  onPullDownRefresh() {
    if (this.data.activityId) {
      this.loadActivityDetail(this.data.activityId).finally(() => {
        wx.stopPullDownRefresh();
      });
    } else {
      wx.stopPullDownRefresh();
    }
  },
 
  loadActivityDetail(id) {
    this.setData({ loading: true, error: null });
    const query = `
      query GetActivityDetailAndStatus($id: ID!) {
        activity(id: $id) {
          id
          name
          description
          signupDeadline
          matchTime
          address
          state
          stateName
          playerCount
          playerMax
          coverImage { fullUrl }
          images { fullUrl }
          videos { fullUrl, fullThumbUrl }
          stages {
            id
            name
            matchTime
            description
          }
        }
        myActivityPlayer(activityId: $id) {
          id
          state
        }
      }
    `;
 
    return app.graphqlRequest(query, { id: id })
      .then(res => {
        if (res.activity) {
          let buttonDisabled = false;
          let buttonText = '我要报名';
          const myApplication = res.myActivityPlayer;
 
          if (myApplication) {
            if (myApplication.state === 0) {
              buttonDisabled = true;
              buttonText = '等待审核';
            } else if (myApplication.state === 1) {
              buttonDisabled = true;
              buttonText = '已报名';
            }
          }
 
          if (!buttonDisabled) {
            if (new Date() > new Date(res.activity.signupDeadline)) {
              buttonDisabled = true;
              buttonText = '报名已截止';
            }
          }
 
          this.setData({
            activity: res.activity,
            myApplication: myApplication,
            loading: false,
            buttonDisabled: buttonDisabled,
            buttonText: buttonText
          });
        } else {
          throw new Error('未找到比赛信息');
        }
      })
      .catch(err => {
        this.setData({
          loading: false,
          error: '加载失败,请稍后重试'
        });
        console.error('加载比赛详情或报名状态失败:', err);
      });
  },
 
  handleRegister() {
    if (!this.data.activityId) {
      wx.showToast({
        title: '无效的活动ID',
        icon: 'none'
      });
      return;
    }
    wx.navigateTo({
      url: `/pages/registration/registration?id=${this.data.activityId}`
    });
  },
 
  // 格式化日期和时间
  formatDateTime(dateStr) {
    return utils.formatDate(dateStr, 'YYYY-MM-DD HH:mm');
  },
  
  // 格式化日期范围
  formatDateRange(start, end) {
    if (!start && !end) return '待定';
    const startDate = start ? utils.formatDate(start, 'YYYY-MM-DD') : '';
    const endDate = end ? utils.formatDate(end, 'YYYY-MM-DD') : '';
    if (startDate && endDate && startDate !== endDate) {
      return `${startDate} - ${endDate}`;
    }
    return startDate || endDate;
  }
});