| | |
| | | activityId: '', |
| | | activity: null, |
| | | loading: false, |
| | | userInfo: null, // 当前用户信息 |
| | | // 报名状态控制 |
| | | submitDisabled: false, |
| | | submitText: '提交报名', |
| | | |
| | | // 表单数据 |
| | | formData: { |
| | |
| | | this.setData({ |
| | | activityId: activityId |
| | | }) |
| | | // 优先检查报名状态 |
| | | this.checkRegistrationStatus(activityId) |
| | | // 加载活动信息 |
| | | this.loadActivityInfo() |
| | | } else { |
| | | console.log('❌ 没有接收到activityId参数') |
| | | } |
| | | |
| | | // 加载用户信息 |
| | | this.loadUserInfo() |
| | | |
| | | // 从全局数据获取用户信息预填充 |
| | | this.prefillUserInfo() |
| | | |
| | | // 加载区域数据 |
| | | this.loadRegions() |
| | | }, |
| | | |
| | | onShow() { |
| | | // 返回本页时刷新报名状态 |
| | | const { activityId } = this.data |
| | | if (activityId) { |
| | | this.checkRegistrationStatus(activityId) |
| | | } |
| | | }, |
| | | |
| | | // 加载活动信息 |
| | |
| | | } |
| | | }, |
| | | |
| | | // 加载用户信息 |
| | | loadUserInfo() { |
| | | const userInfo = app.globalData.userInfo |
| | | console.log('🔍 加载用户信息用于显示:', userInfo) |
| | | |
| | | if (userInfo) { |
| | | let displayUserInfo = { |
| | | name: userInfo.name || '', |
| | | phone: userInfo.phone || '', |
| | | avatarUrl: userInfo.avatarUrl || '', |
| | | gender: null, |
| | | education: '' |
| | | } |
| | | |
| | | // 如果用户有Player信息,优先使用Player的详细信息 |
| | | if (userInfo.player) { |
| | | 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 || '' |
| | | |
| | | // 处理性别信息:0=男,1=女 |
| | | if (userInfo.player.gender !== undefined && userInfo.player.gender !== null) { |
| | | displayUserInfo.gender = parseInt(userInfo.player.gender) |
| | | } |
| | | |
| | | // 处理学历信息 |
| | | if (userInfo.player.education) { |
| | | displayUserInfo.education = userInfo.player.education |
| | | } |
| | | } |
| | | |
| | | console.log('✅ 设置显示用户信息:', displayUserInfo) |
| | | this.setData({ |
| | | userInfo: displayUserInfo |
| | | }) |
| | | } else { |
| | | console.log('⚠️ 未找到用户信息') |
| | | } |
| | | }, |
| | | |
| | | // 预填充用户信息 |
| | | prefillUserInfo() { |
| | | const userInfo = app.globalData.userInfo |
| | | console.log('🔍 预填充用户信息:', userInfo) |
| | | |
| | | if (userInfo) { |
| | | this.setData({ |
| | | const updateData = { |
| | | 'formData.name': userInfo.name || '', |
| | | 'formData.phone': userInfo.phone || '', |
| | | 'formData.email': userInfo.email || '' |
| | | }) |
| | | } |
| | | |
| | | // 如果用户有Player信息,优先使用Player的详细信息 |
| | | if (userInfo.player) { |
| | | console.log('📋 使用Player信息预填充:', userInfo.player) |
| | | updateData['formData.name'] = userInfo.player.name || userInfo.name || '' |
| | | updateData['formData.phone'] = userInfo.player.phone || userInfo.phone || '' |
| | | |
| | | // 处理性别信息:0=男,1=女 |
| | | if (userInfo.player.gender !== undefined && userInfo.player.gender !== null) { |
| | | const genderIndex = parseInt(userInfo.player.gender) |
| | | if (genderIndex === 0 || genderIndex === 1) { |
| | | updateData['formData.gender'] = genderIndex |
| | | updateData['genderIndex'] = genderIndex |
| | | console.log('👤 设置性别:', genderIndex === 0 ? '男' : '女') |
| | | } |
| | | } |
| | | } |
| | | |
| | | console.log('✅ 预填充数据:', updateData) |
| | | this.setData(updateData) |
| | | } else { |
| | | console.log('⚠️ 未找到用户信息,无法预填充') |
| | | } |
| | | }, |
| | | |
| | |
| | | |
| | | async onSubmit() { |
| | | if (this.data.isSubmitting) return |
| | | if (this.data.submitDisabled) { |
| | | // 禁用态直接拦截点击 |
| | | wx.showToast({ |
| | | title: this.data.submitText, |
| | | icon: 'none' |
| | | }) |
| | | return |
| | | } |
| | | |
| | | // 表单验证 |
| | | if (!this.validateForm()) { |
| | |
| | | } |
| | | }, |
| | | |
| | | // 检查当前活动的报名状态,进入页面时调用 |
| | | 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 '' |