const { graphqlRequest } = require('../../lib/utils') const DETAIL_QUERY = ` query ActivityPlayerDetail($id: ID!) { activityPlayerDetail(id: $id) { id activityName projectName description feedback state playerInfo { id name phone } submissionFiles { id name fullUrl fullThumbUrl fileExt mediaType } } } ` const APPROVE_MUTATION = ` mutation ApproveActivityPlayer($id: ID!, $feedback: String) { approveActivityPlayer(activityPlayerId: $id, feedback: $feedback) } ` const REJECT_MUTATION = ` mutation RejectActivityPlayer($id: ID!, $feedback: String) { rejectActivityPlayer(activityPlayerId: $id, feedback: $feedback) } ` Page({ data: { loading: false, submitting: false, activityPlayerId: null, detail: null, feedback: '' }, onLoad(options) { if (options && options.id) { if (typeof this.getOpenerEventChannel === 'function') { this.eventChannel = this.getOpenerEventChannel() } this.setData({ activityPlayerId: options.id }) this.loadDetail() } else { wx.showToast({ title: '缺少报名ID', icon: 'none' }) setTimeout(() => wx.navigateBack(), 800) } }, async loadDetail() { if (!this.data.activityPlayerId) { return } this.setData({ loading: true }) try { const result = await graphqlRequest(DETAIL_QUERY, { id: this.data.activityPlayerId }) const detail = result && result.activityPlayerDetail if (!detail) { wx.showToast({ title: '未找到报名信息', icon: 'none' }) return } this.setData({ detail: { ...detail, stateText: this.getStateText(detail.state), submissionFiles: (detail.submissionFiles || []).map(file => ({ id: file.id, name: file.name, url: file.fullUrl || file.fullThumbUrl || '' })) }, feedback: detail.feedback || '' }) } catch (error) { console.error('加载审核详情失败:', error) wx.showToast({ title: '加载失败', icon: 'none' }) } finally { this.setData({ loading: false }) } }, onFeedbackInput(e) { this.setData({ feedback: e.detail.value }) }, onApprove() { this.handleAudit('APPROVE') }, onReject() { this.handleAudit('REJECT') }, async handleAudit(action) { if (!this.data.activityPlayerId) { return } const mutation = action === 'APPROVE' ? APPROVE_MUTATION : REJECT_MUTATION const successText = action === 'APPROVE' ? '审核通过' : '已驳回' this.setData({ submitting: true }) try { const variables = { id: Number(this.data.activityPlayerId), feedback: this.data.feedback ? this.data.feedback.trim() : null } const result = await graphqlRequest(mutation, variables) const success = result && (action === 'APPROVE' ? result.approveActivityPlayer : result.rejectActivityPlayer) if (success) { wx.showToast({ title: successText, icon: 'success' }) if (this.eventChannel) { this.eventChannel.emit('auditUpdated', { id: this.data.activityPlayerId }) } setTimeout(() => wx.navigateBack(), 600) } else { wx.showToast({ title: '操作失败', icon: 'none' }) } } catch (error) { console.error('提交审核决策失败:', error) wx.showToast({ title: '操作失败', icon: 'none' }) } finally { this.setData({ submitting: false }) } }, previewFile(e) { const url = e.currentTarget.dataset.url if (url) { wx.navigateTo({ url: `/pages/webview/webview?url=${encodeURIComponent(url)}` }) } }, getStateText(state) { switch (state) { case 0: return '未审核' case 1: return '审核通过' case 2: return '审核驳回' default: return '未知状态' } } })