| | |
| | | activity: null, |
| | | loading: false, |
| | | userInfo: null, // 当前用户信息 |
| | | // 报名状态控制 |
| | | submitDisabled: false, |
| | | submitText: '提交报名', |
| | | |
| | | // 表单数据 |
| | | formData: { |
| | |
| | | this.setData({ |
| | | activityId: activityId |
| | | }) |
| | | // 优先检查报名状态 |
| | | this.checkRegistrationStatus(activityId) |
| | | // 加载活动信息 |
| | | this.loadActivityInfo() |
| | | } else { |
| | | console.log('❌ 没有接收到activityId参数') |
| | |
| | | |
| | | // 加载区域数据 |
| | | this.loadRegions() |
| | | }, |
| | | |
| | | onShow() { |
| | | // 返回本页时刷新报名状态 |
| | | const { activityId } = this.data |
| | | if (activityId) { |
| | | this.checkRegistrationStatus(activityId) |
| | | } |
| | | }, |
| | | |
| | | // 加载活动信息 |
| | |
| | | console.log('📋 使用Player信息显示:', userInfo.player) |
| | | displayUserInfo.name = userInfo.player.name || userInfo.name || '' |
| | | displayUserInfo.phone = userInfo.player.phone || userInfo.phone || '' |
| | | displayUserInfo.avatarUrl = userInfo.player.avatarUrl || userInfo.avatarUrl || '' |
| | | displayUserInfo.avatarUrl = userInfo.avatarUrl || '' |
| | | |
| | | // 处理性别信息:0=男,1=女 |
| | | if (userInfo.player.gender !== undefined && userInfo.player.gender !== null) { |
| | |
| | | const updateData = { |
| | | 'formData.name': userInfo.name || '', |
| | | 'formData.phone': userInfo.phone || '', |
| | | 'formData.email': userInfo.email || '' |
| | | 'formData.email': userInfo.email || '', |
| | | 'formData.avatarUrl': userInfo.avatarUrl || '' |
| | | } |
| | | |
| | | // 如果用户有Player信息,优先使用Player的详细信息 |
| | |
| | | console.log('📋 使用Player信息预填充:', userInfo.player) |
| | | updateData['formData.name'] = userInfo.player.name || userInfo.name || '' |
| | | updateData['formData.phone'] = userInfo.player.phone || userInfo.phone || '' |
| | | updateData['formData.avatarUrl'] = userInfo.avatarUrl || '' |
| | | |
| | | // 处理性别信息:0=男,1=女 |
| | | if (userInfo.player.gender !== undefined && userInfo.player.gender !== null) { |
| | |
| | | } |
| | | |
| | | console.log('✅ 预填充数据:', updateData) |
| | | console.log('🖼️ 设置头像URL:', updateData['formData.avatarUrl']) |
| | | this.setData(updateData) |
| | | } else { |
| | | console.log('⚠️ 未找到用户信息,无法预填充') |
| | |
| | | success: (res) => { |
| | | wx.hideLoading() |
| | | if (res.statusCode === 200) { |
| | | // 根据实际文件扩展名确定文件类型 |
| | | const fileName = attachment.name || '' |
| | | const fileExt = fileName.split('.').pop().toLowerCase() |
| | | const fileTypeMap = { |
| | | 'word': 'doc', |
| | | 'excel': 'xls', |
| | | 'ppt': 'ppt' |
| | | 'doc': 'doc', |
| | | 'docx': 'docx', |
| | | 'xls': 'xls', |
| | | 'xlsx': 'xlsx', |
| | | 'ppt': 'ppt', |
| | | 'pptx': 'pptx' |
| | | } |
| | | |
| | | wx.openDocument({ |
| | | filePath: res.tempFilePath, |
| | | fileType: fileTypeMap[fileType] || 'doc', |
| | | fileType: fileTypeMap[fileExt] || 'doc', |
| | | success: () => { |
| | | console.log('文档打开成功') |
| | | }, |
| | | fail: (err) => { |
| | | console.error('文档打开失败:', err) |
| | | wx.showToast({ |
| | | title: '文档打开失败', |
| | | icon: 'none' |
| | | wx.showModal({ |
| | | title: '打开失败', |
| | | content: '文档打开失败,可能是文件格式不支持或文件损坏', |
| | | showCancel: false, |
| | | confirmText: '确定' |
| | | }) |
| | | } |
| | | }) |
| | |
| | | |
| | | async onSubmit() { |
| | | if (this.data.isSubmitting) return |
| | | if (this.data.submitDisabled) { |
| | | // 禁用态直接拦截点击 |
| | | wx.showToast({ |
| | | title: this.data.submitText, |
| | | icon: 'none' |
| | | }) |
| | | return |
| | | } |
| | | |
| | | // 表单验证 |
| | | if (!this.validateForm()) { |
| | |
| | | userId: result.userId, |
| | | activityPlayerId: result.activityPlayerId |
| | | }) |
| | | |
| | | // 第三步:报名成功后强制调用wxlogin获取新的JWT token |
| | | console.log('📱 报名成功,开始强制调用wxlogin获取新的JWT token') |
| | | try { |
| | | await app.wxLogin() |
| | | console.log('✅ 报名成功后wxlogin调用成功,已获取新的JWT token') |
| | | } catch (wxLoginError) { |
| | | console.error('❌ 报名成功后wxlogin调用失败:', wxLoginError) |
| | | // wxlogin失败不影响报名成功的提示,只记录错误 |
| | | } |
| | | |
| | | wx.showToast({ |
| | | title: '报名成功', |
| | |
| | | } |
| | | }, |
| | | |
| | | // 检查当前活动的报名状态,进入页面时调用 |
| | | async checkRegistrationStatus(activityId) { |
| | | try { |
| | | // GraphQL 查询最新报名状态(后端返回最新一条记录) |
| | | const query = ` |
| | | query GetPlayerRegistrationState($activityId: ID!) { |
| | | getPlayerRegistrationState(activityId: $activityId) { |
| | | id |
| | | status |
| | | registrationTime |
| | | reviewStatus |
| | | reviewComment |
| | | } |
| | | } |
| | | ` |
| | | const res = await app.graphqlRequest(query, { activityId: parseInt(activityId) }) |
| | | console.log('🟦 报名状态查询结果原始:', res) |
| | | |
| | | // 兼容多种返回结构 |
| | | const dataRoot = res?.getPlayerRegistrationState |
| | | || res?.playerRegistration |
| | | || res?.data?.getPlayerRegistrationState |
| | | || res?.data?.playerRegistration |
| | | |
| | | let submitDisabled = false |
| | | let submitText = '提交报名' |
| | | |
| | | if (dataRoot && dataRoot.status !== undefined && dataRoot.status !== null) { |
| | | const statusNum = Number(dataRoot.status) |
| | | console.log('🟦 解析到报名状态:', statusNum) |
| | | if (statusNum === 1) { |
| | | submitDisabled = true |
| | | submitText = '已经报名' |
| | | } else if (statusNum === 0) { |
| | | submitDisabled = true |
| | | submitText = '等待审核' |
| | | } else { |
| | | submitDisabled = false |
| | | submitText = '提交报名' |
| | | } |
| | | } else { |
| | | console.log('🟦 未找到报名记录或状态,允许提交') |
| | | } |
| | | |
| | | this.setData({ submitDisabled, submitText }) |
| | | } catch (err) { |
| | | console.warn('⚠️ 报名状态查询失败,允许用户提交:', err) |
| | | this.setData({ submitDisabled: false, submitText: '提交报名' }) |
| | | } |
| | | }, |
| | | |
| | | // 获取文件扩展名 |
| | | getFileExtension(fileName) { |
| | | if (!fileName) return '' |