| | |
| | | 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) |
| | | } |
| | | }, |
| | | |
| | | // 加载活动信息 |
| | | async loadActivityInfo() { |
| | |
| | | }, |
| | | |
| | | // 加载用户信息 |
| | | loadUserInfo() { |
| | | const userInfo = app.globalData.userInfo |
| | | console.log('🔍 加载用户信息用于显示:', userInfo) |
| | | async loadUserInfo() { |
| | | console.log('🔄 开始加载用户信息') |
| | | const app = getApp() |
| | | let userInfo = app.globalData.userInfo |
| | | console.log('🔍 本地用户数据:', JSON.stringify(userInfo, null, 2)) |
| | | |
| | | // 尝试从后端获取完整的用户信息 |
| | | try { |
| | | const query = ` |
| | | query GetUserProfile { |
| | | userProfile { |
| | | id |
| | | name |
| | | avatar |
| | | phone |
| | | gender |
| | | birthday |
| | | } |
| | | } |
| | | ` |
| | | |
| | | const result = await graphqlRequest(query) |
| | | if (result && result.userProfile) { |
| | | console.log('🔍 从后端获取的完整用户数据:', JSON.stringify(result.userProfile, null, 2)) |
| | | userInfo = result.userProfile |
| | | // 更新全局数据 |
| | | app.globalData.userInfo = { ...app.globalData.userInfo, ...userInfo } |
| | | } |
| | | } catch (error) { |
| | | console.log('⚠️ 从后端获取用户信息失败,使用本地数据:', error) |
| | | } |
| | | |
| | | if (userInfo) { |
| | | let displayUserInfo = { |
| | | name: userInfo.name || '', |
| | | phone: userInfo.phone || '', |
| | | avatarUrl: userInfo.avatarUrl || '', |
| | | avatarUrl: userInfo.avatar || userInfo.avatarUrl || '', |
| | | gender: null, |
| | | education: '' |
| | | education: '', |
| | | birthDate: '' |
| | | } |
| | | |
| | | // 如果用户有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 |
| | | // 处理性别信息 |
| | | if (userInfo.gender !== undefined && userInfo.gender !== null) { |
| | | console.log('👤 发现性别字段:', userInfo.gender, '类型:', typeof userInfo.gender) |
| | | // 如果是字符串格式,转换为数字 |
| | | if (typeof userInfo.gender === 'string') { |
| | | displayUserInfo.gender = userInfo.gender === 'MALE' ? 1 : 0 // 修复:MALE=1(男), FEMALE=0(女) |
| | | console.log('👤 处理后的性别:', displayUserInfo.gender) |
| | | } else { |
| | | displayUserInfo.gender = parseInt(userInfo.gender) |
| | | } |
| | | } |
| | | |
| | | console.log('✅ 设置显示用户信息:', displayUserInfo) |
| | | // 处理生日信息 |
| | | if (userInfo.birthday || userInfo.birthDate) { |
| | | displayUserInfo.birthDate = userInfo.birthday || userInfo.birthDate |
| | | console.log('🎂 发现生日字段:', displayUserInfo.birthDate) |
| | | } |
| | | |
| | | this.setData({ |
| | | userInfo: displayUserInfo |
| | | displayUserInfo: displayUserInfo |
| | | }) |
| | | |
| | | console.log('✅ 最终 displayUserInfo:', JSON.stringify(displayUserInfo, null, 2)) |
| | | } else { |
| | | console.log('⚠️ 未找到用户信息') |
| | | } |
| | |
| | | |
| | | // 预填充用户信息 |
| | | prefillUserInfo() { |
| | | const app = getApp() |
| | | const userInfo = app.globalData.userInfo |
| | | console.log('🔍 预填充用户信息:', userInfo) |
| | | |
| | |
| | | const updateData = { |
| | | 'formData.name': userInfo.name || '', |
| | | 'formData.phone': userInfo.phone || '', |
| | | 'formData.email': userInfo.email || '' |
| | | 'formData.email': userInfo.email || '', |
| | | 'formData.avatarUrl': userInfo.avatar || userInfo.avatarUrl || '' |
| | | } |
| | | |
| | | // 如果用户有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 ? '男' : '女') |
| | | } |
| | | // 处理性别信息 - 直接从userInfo获取 |
| | | if (userInfo.gender !== undefined && userInfo.gender !== null) { |
| | | let genderValue, genderIndex |
| | | // 如果是字符串格式,转换为数字 |
| | | if (typeof userInfo.gender === 'string') { |
| | | genderValue = userInfo.gender === 'MALE' ? 1 : 0 // 修复:MALE=1(男), FEMALE=0(女) |
| | | genderIndex = userInfo.gender === 'MALE' ? 0 : 1 // 界面索引:0=男,1=女 |
| | | } else { |
| | | genderValue = parseInt(userInfo.gender) |
| | | genderIndex = genderValue === 1 ? 0 : 1 // 数据库值1(男)->界面索引0,数据库值0(女)->界面索引1 |
| | | } |
| | | updateData['formData.gender'] = genderValue |
| | | updateData['genderIndex'] = genderIndex |
| | | console.log('👤 设置性别:', genderValue === 1 ? '男' : '女', '界面索引:', genderIndex) |
| | | } |
| | | |
| | | // 处理生日信息 - 直接从userInfo获取 |
| | | if (userInfo.birthday || userInfo.birthDate) { |
| | | const birthDate = userInfo.birthday || userInfo.birthDate |
| | | updateData['formData.birthDate'] = birthDate |
| | | console.log('🎂 设置生日:', birthDate) |
| | | } |
| | | |
| | | console.log('✅ 预填充数据:', updateData) |
| | | console.log('🖼️ 设置头像URL:', updateData['formData.avatarUrl']) |
| | | |
| | | this.setData(updateData) |
| | | console.log('✅ 用户信息预填充完成') |
| | | } else { |
| | | console.log('⚠️ 未找到用户信息,无法预填充') |
| | | console.log('⚠️ 未找到用户信息,跳过预填充') |
| | | } |
| | | }, |
| | | |
| | |
| | | // 性别选择 |
| | | onGenderChange(e) { |
| | | const index = e.detail.value |
| | | // 修复性别映射:genderOptions[0]='男' 应该对应数据库值1,genderOptions[1]='女' 应该对应数据库值0 |
| | | const genderValue = index === 0 ? 1 : 0 // 0(男) -> 1, 1(女) -> 0 |
| | | this.setData({ |
| | | genderIndex: index, |
| | | 'formData.gender': index |
| | | 'formData.gender': genderValue |
| | | }) |
| | | }, |
| | | |
| | |
| | | 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: '确定' |
| | | }) |
| | | } |
| | | }) |
| | |
| | | errors.name = '请输入姓名'; |
| | | } |
| | | |
| | | if (!formData.phone.trim()) { |
| | | errors.phone = '请输入手机号'; |
| | | if (!formData.phone || !formData.phone.trim()) { |
| | | errors.phone = '请先授权获取手机号'; |
| | | } else if (!/^1[3-9]\d{9}$/.test(formData.phone)) { |
| | | errors.phone = '请输入正确的手机号'; |
| | | } |
| | |
| | | |
| | | async onSubmit() { |
| | | if (this.data.isSubmitting) return |
| | | if (this.data.submitDisabled) { |
| | | // 禁用态直接拦截点击 |
| | | wx.showToast({ |
| | | title: this.data.submitText, |
| | | icon: 'none' |
| | | }) |
| | | return |
| | | } |
| | | |
| | | // 表单验证 |
| | | if (!this.validateForm()) { |
| | | wx.showToast({ |
| | | title: '请检查表单信息', |
| | | icon: 'none' |
| | | }) |
| | | return |
| | | } |
| | | |
| | | // 额外检查:确保必须授权电话号码 |
| | | if (!this.data.formData.phone || !this.data.formData.phone.trim()) { |
| | | wx.showModal({ |
| | | title: '需要授权手机号', |
| | | content: '根据平台规定,必须授权手机号码才能报名参赛。请先获取手机号码授权。', |
| | | showCancel: false, |
| | | confirmText: '我知道了' |
| | | }) |
| | | return |
| | | } |
| | |
| | | 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 '' |