From 3714621173c606c4c58439ed8941100ce9ddea14 Mon Sep 17 00:00:00 2001
From: Codex Assistant <codex@example.com>
Date: 星期三, 05 十一月 2025 15:10:49 +0800
Subject: [PATCH] bug
---
wx/pages/activity/detail.js | 536 ++++++++++------------------------------------------------
1 files changed, 98 insertions(+), 438 deletions(-)
diff --git a/wx/pages/activity/detail.js b/wx/pages/activity/detail.js
index 24d7b1c..9e18865 100644
--- a/wx/pages/activity/detail.js
+++ b/wx/pages/activity/detail.js
@@ -4,68 +4,38 @@
Page({
data: {
- // 娲诲姩ID
activityId: null,
- // 娲诲姩璇︽儏
activity: null,
- // 鍔犺浇鐘舵��
+ myApplication: null,
+ buttonDisabled: false,
+ buttonText: '鎴戣鎶ュ悕',
loading: true,
- // 鐢ㄦ埛鎶ュ悕鐘舵��
- registrationStatus: null,
- // 鏄惁宸叉姤鍚�
- isRegistered: false,
- // 濯掍綋鏂囦欢鍒楄〃
- mediaFiles: [],
- // 褰撳墠濯掍綋绱㈠紩
- currentMediaIndex: 0,
- // 鏄惁鏄剧ず濯掍綋棰勮
- showMediaPreview: false,
- // 鎶ュ悕浜烘暟锛堝疄鏃舵洿鏂帮級
- currentParticipants: 0,
- // 鏄惁鍙互鎶ュ悕
- canRegisterStatus: false,
- // 鎶ュ悕鎸夐挳鏂囨湰
- registerButtonText: '绔嬪嵆鎶ュ悕',
- // 鎶ュ悕鎸夐挳鏄惁绂佺敤
- registerButtonDisabled: false
+ error: null
},
onLoad(options) {
- console.log('娲诲姩璇︽儏椤靛姞杞�', options)
-
if (options.id) {
- this.setData({ activityId: options.id })
- this.loadActivityDetail()
- this.checkRegistrationStatus()
+ this.setData({ activityId: options.id });
+ this.loadActivityDetail(options.id);
} else {
- utils.showError('鍙傛暟閿欒')
- utils.navigateBack()
+ this.setData({ loading: false, error: '鏃犳晥鐨勬瘮璧汭D' });
}
},
- onShow() {
- console.log('娲诲姩璇︽儏椤垫樉绀�')
- // 鍒锋柊鎶ュ悕浜烘暟
+ onPullDownRefresh() {
if (this.data.activityId) {
- this.refreshParticipantCount()
+ this.loadActivityDetail(this.data.activityId).finally(() => {
+ wx.stopPullDownRefresh();
+ });
+ } else {
+ wx.stopPullDownRefresh();
}
},
- onShareAppMessage() {
- const activity = this.data.activity
- return {
- title: activity ? activity.name : '绮惧僵璧涗簨',
- path: `/pages/activity/detail?id=${this.data.activityId}`,
- imageUrl: activity && activity.coverImage ? activity.coverImage.fullUrl : ''
- }
- },
-
- // 鍔犺浇璧涗簨璇︽儏
- loadActivityDetail() {
- this.setData({ loading: true })
-
- app.graphqlRequest(`
- query getActivityDetail($id: ID!) {
+ loadActivityDetail(id) {
+ this.setData({ loading: true, error: null });
+ const query = `
+ query GetActivityDetailAndStatus($id: ID!) {
activity(id: $id) {
id
name
@@ -73,407 +43,97 @@
signupDeadline
matchTime
address
- playerMax
state
- createTime
- updateTime
- playerCount
stateName
- coverImage {
- id
- name
- path
- fullUrl
- fullThumbUrl
- mediaType
- }
- images {
- id
- name
- path
- fullUrl
- fullThumbUrl
- mediaType
- }
- videos {
- id
- name
- path
- fullUrl
- fullThumbUrl
- mediaType
- }
- }
- }
- `, {
- id: this.data.activityId
- }).then(data => {
- if (data.activity) {
- const activity = data.activity
-
- // 澶勭悊濯掍綋鏂囦欢
- const mediaFiles = []
-
- // 娣诲姞灏侀潰鍥�
- if (activity.coverImage) {
- mediaFiles.push({
- type: 'image',
- url: activity.coverImage.fullUrl,
- title: '灏侀潰鍥剧墖'
- })
- }
-
- // 娣诲姞鍏朵粬鍥剧墖
- if (activity.images && activity.images.length > 0) {
- activity.images.forEach((image, index) => {
- mediaFiles.push({
- type: 'image',
- url: image.fullUrl,
- title: `鍥剧墖 ${index + 1}`
- })
- })
- }
-
- // 娣诲姞瑙嗛
- if (activity.videos && activity.videos.length > 0) {
- activity.videos.forEach((video, index) => {
- mediaFiles.push({
- type: 'video',
- url: video.fullUrl,
- title: `瑙嗛 ${index + 1}`
- })
- })
- }
-
- // 棰勫鐞嗘椂闂村瓧娈�
- if (activity.signupDeadline) {
- activity.formattedSignupDeadline = this.formatDate(activity.signupDeadline)
- }
- if (activity.matchTime) {
- activity.formattedMatchTime = this.formatDate(activity.matchTime)
- }
-
- this.setData({
- activity: activity,
- mediaFiles: mediaFiles,
- currentParticipants: activity.playerCount,
- loading: false
- }, () => {
- // 鍦ㄦ暟鎹缃畬鎴愬悗锛屾鏌ユ姤鍚嶇姸鎬�
- this.checkRegistrationStatus()
- this.updateCanRegisterStatus()
- })
- } else {
- utils.showError('璧涗簨涓嶅瓨鍦�')
- utils.navigateBack()
- }
- }).catch(err => {
- console.error('鍔犺浇璧涗簨璇︽儏澶辫触:', err)
- utils.showError('鍔犺浇澶辫触锛岃閲嶈瘯')
- this.setData({ loading: false })
- })
- },
-
- // 妫�鏌ユ姤鍚嶇姸鎬�
- checkRegistrationStatus() {
- if (!app.globalData.token) {
- return
- }
-
- app.graphqlRequest(`
- query checkRegistrationStatus($activityId: ID!) {
- playerRegistration(activityId: $activityId) {
- id
- status
- registrationTime
- reviewStatus
- reviewComment
- }
- }
- `, {
- activityId: this.data.activityId
- }).then(data => {
- if (data.playerRegistration) {
- this.setData({
- registrationStatus: data.playerRegistration,
- isRegistered: true
- }, () => {
- this.updateCanRegisterStatus()
- })
- } else {
- this.setData({
- isRegistered: false
- }, () => {
- this.updateCanRegisterStatus()
- })
- }
- }).catch(err => {
- console.error('妫�鏌ユ姤鍚嶇姸鎬佸け璐�:', err)
- })
- },
-
- // 鍒锋柊鎶ュ悕浜烘暟
- refreshParticipantCount() {
- app.graphqlRequest(`
- query getParticipantCount($id: ID!) {
- activity(id: $id) {
playerCount
- }
- }
- `, {
- id: this.data.activityId
- }).then(data => {
- if (data.activity) {
- this.setData({
- currentParticipants: data.activity.playerCount
- }, () => {
- this.updateCanRegisterStatus()
- })
- }
- }).catch(err => {
- console.error('鍒锋柊鎶ュ悕浜烘暟澶辫触:', err)
- })
- },
-
- // 濯掍綋鏂囦欢鐐瑰嚮
- onMediaTap(e) {
- const index = e.currentTarget.dataset.index
- const media = this.data.mediaFiles[index]
-
- if (media.type === 'image') {
- // 棰勮鍥剧墖
- const imageUrls = this.data.mediaFiles
- .filter(item => item.type === 'image')
- .map(item => item.url)
-
- wx.previewImage({
- current: media.url,
- urls: imageUrls
- })
- } else if (media.type === 'video') {
- // 鎾斁瑙嗛
- this.setData({
- currentMediaIndex: index,
- showMediaPreview: true
- })
- }
- },
-
- // 鍏抽棴濯掍綋棰勮
- closeMediaPreview() {
- this.setData({
- showMediaPreview: false
- })
- },
-
- // 鎶ュ悕鎸夐挳鐐瑰嚮
- onRegisterTap() {
- // 濡傛灉鎸夐挳琚鐢紝涓嶆墽琛屼换浣曟搷浣�
- if (this.data.registerButtonDisabled) {
- return
- }
-
- // 濡傛灉宸叉姤鍚嶏紝鏌ョ湅鎶ュ悕鐘舵��
- if (this.data.isRegistered) {
- this.onViewRegistrationStatus()
- return
- }
-
- // 妫�鏌ョ櫥褰曠姸鎬�
- if (!app.globalData.token) {
- utils.showToast('璇峰厛鐧诲綍')
- app.login()
- return
- }
-
- const activity = this.data.activity
-
- // 妫�鏌ユ姤鍚嶆椂闂�
- const now = new Date()
- const regEnd = new Date(activity.signupDeadline)
-
- if (now > regEnd) {
- utils.showToast('鎶ュ悕宸茬粨鏉�')
- return
- }
-
- // 妫�鏌ユ姤鍚嶄汉鏁�
- if (activity.playerMax && this.data.currentParticipants >= activity.playerMax) {
- utils.showToast('鎶ュ悕浜烘暟宸叉弧')
- return
- }
-
- // 璺宠浆鍒版姤鍚嶉〉闈�
- utils.navigateTo('/pages/registration/registration', {
- activityId: this.data.activityId
- })
- },
-
- // 鏌ョ湅鎶ュ悕鐘舵��
- onViewRegistrationStatus() {
- const status = this.data.registrationStatus
- let statusText = ''
-
- switch (status.status) {
- case 'PENDING':
- statusText = '寰呭鏍�'
- break
- case 'APPROVED':
- statusText = '宸查�氳繃'
- break
- case 'REJECTED':
- statusText = '宸叉嫆缁�'
- break
- case 'CANCELLED':
- statusText = '宸插彇娑�'
- break
- default:
- statusText = status.status
- }
-
- let content = `鎶ュ悕鐘舵�侊細${statusText}\n鎶ュ悕鏃堕棿锛�${utils.formatDate(status.registrationTime)}`
-
- if (status.reviewComment) {
- content += `\n瀹℃牳鎰忚锛�${status.reviewComment}`
- }
-
- wx.showModal({
- title: '鎶ュ悕鐘舵��',
- content: content,
- showCancel: false
- })
- },
-
- // 鑱旂郴涓诲姙鏂�
- onContactTap() {
- const activity = this.data.activity
-
- if (activity.contactPhone) {
- wx.showActionSheet({
- itemList: ['鎷ㄦ墦鐢佃瘽', '澶嶅埗鍙风爜'],
- success: (res) => {
- if (res.tapIndex === 0) {
- wx.makePhoneCall({
- phoneNumber: activity.contactPhone
- })
- } else if (res.tapIndex === 1) {
- wx.setClipboardData({
- data: activity.contactPhone,
- success: () => {
- utils.showSuccess('鍙风爜宸插鍒�')
- }
- })
+ 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('鏈壘鍒版瘮璧涗俊鎭�');
+ }
})
- } else {
- utils.showToast('鏆傛棤鑱旂郴鏂瑰紡')
- }
+ .catch(err => {
+ this.setData({
+ loading: false,
+ error: '鍔犺浇澶辫触锛岃绋嶅悗閲嶈瘯'
+ });
+ console.error('鍔犺浇姣旇禌璇︽儏鎴栨姤鍚嶇姸鎬佸け璐�:', err);
+ });
},
- // 鍒嗕韩璧涗簨
- onShareTap() {
- wx.showShareMenu({
- withShareTicket: true,
- menus: ['shareAppMessage', 'shareTimeline']
- })
+ handleRegister() {
+ if (!this.data.activityId) {
+ wx.showToast({
+ title: '鏃犳晥鐨勬椿鍔↖D',
+ icon: 'none'
+ });
+ return;
+ }
+ wx.navigateTo({
+ url: `/pages/registration/registration?id=${this.data.activityId}`
+ });
},
- // 鏍煎紡鍖栨棩鏈�
- formatDate(date) {
- return utils.formatDate(date, 'YYYY-MM-DD HH:mm')
+ // 鏍煎紡鍖栨棩鏈熷拰鏃堕棿
+ formatDateTime(dateStr) {
+ return utils.formatDate(dateStr, 'YYYY-MM-DD HH:mm');
},
-
- // 鑾峰彇鐘舵�佹枃鏈�
- getStatusText(state) {
- const statusMap = {
- 0: '鑽夌',
- 1: '宸插彂甯�',
- 2: '鎶ュ悕缁撴潫',
- 3: '杩涜涓�',
- 4: '宸茬粨鏉�',
- 5: '宸插彇娑�'
+
+ // 鏍煎紡鍖栨棩鏈熻寖鍥�
+ 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 statusMap[state] || '鏈煡鐘舵��'
- },
-
- // 鑾峰彇鐘舵�佹牱寮忕被
- getStatusClass(state) {
- const classMap = {
- 0: 'text-muted',
- 1: 'text-success',
- 2: 'text-warning',
- 3: 'text-primary',
- 4: 'text-muted',
- 5: 'text-danger'
- }
- return classMap[state] || 'text-muted'
- },
-
- // 鑾峰彇鎶ュ悕杩涘害鐧惧垎姣�
- getRegistrationProgress() {
- const activity = this.data.activity
- if (!activity || !activity.playerMax || activity.playerMax <= 0) {
- return 0
- }
- return Math.min((this.data.currentParticipants / activity.playerMax) * 100, 100)
- },
-
- // 鍒ゆ柇鏄惁鍙互鎶ュ悕
- canRegister() {
- const activity = this.data.activity
- if (!activity) return false
-
- const now = new Date()
- const regEnd = new Date(activity.signupDeadline)
-
- return now <= regEnd &&
- activity.state === 1 &&
- (!activity.playerMax || this.data.currentParticipants < activity.playerMax) &&
- !this.data.isRegistered
- },
-
- // 鑾峰彇鎶ュ悕鎸夐挳鐘舵�佸拰鏂囨湰
- getRegisterButtonStatus() {
- const activity = this.data.activity
- if (!activity) {
- return { canRegister: false, buttonText: '鏆備笉鍙姤鍚�', disabled: true }
- }
-
- // 濡傛灉宸叉姤鍚�
- if (this.data.isRegistered) {
- return { canRegister: false, buttonText: '鏌ョ湅鎶ュ悕鐘舵��', disabled: false }
- }
-
- const now = new Date()
- const regEnd = new Date(activity.signupDeadline)
-
- // 妫�鏌ユ姤鍚嶆埅姝㈡椂闂�
- if (now > regEnd) {
- return { canRegister: false, buttonText: '鎶ュ悕宸茬粨鏉�', disabled: true }
- }
-
- // 妫�鏌ユ姤鍚嶄汉鏁版槸鍚﹀凡婊�
- if (activity.playerMax && this.data.currentParticipants >= activity.playerMax) {
- return { canRegister: false, buttonText: '浜烘暟宸叉弧', disabled: true }
- }
-
- // 妫�鏌ユ椿鍔ㄧ姸鎬�
- if (activity.state !== 1) {
- return { canRegister: false, buttonText: '鏆備笉鍙姤鍚�', disabled: true }
- }
-
- // 鍙互鎶ュ悕
- return { canRegister: true, buttonText: '绔嬪嵆鎶ュ悕', disabled: false }
- },
-
- // 鏇存柊鎶ュ悕鐘舵��
- updateCanRegisterStatus() {
- const buttonStatus = this.getRegisterButtonStatus()
- this.setData({
- canRegisterStatus: buttonStatus.canRegister,
- registerButtonText: buttonStatus.buttonText,
- registerButtonDisabled: buttonStatus.disabled
- })
+ return startDate || endDate;
}
-})
\ No newline at end of file
+});
\ No newline at end of file
--
Gitblit v1.8.0