lrj
19 小时以前 dc643ba44fd2a426263015491268a0f0d6b4671d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
<template>
  <div class="player-page">
    <div class="page-card">
      <h3 class="card-title">报名审核</h3>
      
      <!-- 搜索和操作栏 -->
      <div class="toolbar">
        <el-input
          v-model="searchForm.name"
          placeholder="请输入学员名称"
          style="width: 200px"
          clearable
          @keyup.enter="handleSearch"
        >
          <template #prefix>
            <el-icon><Search /></el-icon>
          </template>
        </el-input>
        <el-select
          v-model="searchForm.activityId"
          placeholder="选择比赛"
          style="width: 300px"
          clearable
          filterable
        >
          <el-option 
            v-for="activity in activityOptions" 
            :key="activity.id" 
            :label="activity.name" 
            :value="activity.id"
          >
            {{ activity.name }}
          </el-option>
        </el-select>
        <el-select
          v-model="searchForm.state"
          placeholder="选择状态"
          style="width: 150px"
          clearable
        >
          <el-option label="待审核" value="0" />
          <el-option label="通过" value="1" />
          <el-option label="驳回" value="2" />
        </el-select>
        <el-button type="primary" @click="handleSearch">
          <el-icon><Search /></el-icon>
          搜索
        </el-button>
        <el-button type="warning" @click="debugAPI">
          调试API
        </el-button>
        <span style="margin-left: 10px; color: #666; font-size: 12px;">
          活动选项数量: {{ activityOptions.length }}
        </span>
      </div>
 
      <!-- 学员列表 -->
      <el-table :data="tableData" style="width: 100%" v-loading="loading">
        <el-table-column label="头像" width="80" align="center">
          <template #default="{ row }">
            <el-avatar :src="row.avatar" :size="40">
              <el-icon><User /></el-icon>
            </el-avatar>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="学员名称" min-width="120" />
        <el-table-column prop="activityName" label="报名项目" min-width="200" />
        <el-table-column prop="phone" label="联系电话" width="140" />
        <el-table-column prop="applyTime" label="申请时间" width="180" />
        <el-table-column prop="state" label="状态" width="100" align="center">
          <template #default="{ row }">
            <el-tag :type="getStateType(row.state)">{{ getStateText(row.state) }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120" fixed="right">
          <template #default="{ row }">
            <div class="table-actions">
              <!-- 只保留详情按钮 -->
              <el-button type="primary" size="small" @click="handleViewDetail(row)">
                详情
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
 
      <!-- 分页 -->
      <div class="pagination">
        <el-pagination
          v-model:current-page="pagination.page"
          v-model:page-size="pagination.size"
          :page-sizes="[10, 20, 50, 100]"
          :total="pagination.total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>
 
<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { PlayerApi } from '@/api/player'
import { getAllActivities } from '@/api/activity'
 
const loading = ref(false)
const router = useRouter()
 
// 活动选项
const activityOptions = ref([])
 
// 搜索表单
const searchForm = reactive({
  name: '',
  activityId: '',
  state: ''
})
 
// 分页信息
const pagination = reactive({
  page: 1,
  size: 10,
  total: 0
})
 
// 表格数据
const tableData = ref([
  {
    id: 1,
    name: '张三',
    avatar: '',
    activityName: '2024年创新创业大赛',
    phone: '13800138001',
    applyTime: '2024-01-05 14:30:00',
    state: 0 // 0-未审核
  },
  {
    id: 2,
    name: '李四',
    avatar: '',
    activityName: '书法比赛',
    phone: '13900139002',
    applyTime: '2024-01-16 10:30:00',
    state: 1 // 1-审核通过
  },
  {
    id: 3,
    name: '王五',
    avatar: '',
    activityName: '绘画比赛',
    phone: '13900139003',
    applyTime: '2024-01-17 14:20:00',
    state: 2 // 2-审核驳回
  },
  {
    id: 4,
    name: '赵六',
    avatar: '',
    activityName: '音乐比赛',
    phone: '13900139004',
    applyTime: '2024-01-18 09:15:00',
    state: 0 // 0-未审核
  }
])
 
// 获取状态标签类型
const getStateType = (state: number | null | undefined) => {
  const typeMap: Record<number, string> = {
    0: 'warning',   // 未审核
    1: 'success',   // 审核通过
    2: 'danger',    // 审核驳回
    3: 'info'       // 已结束
  }
  return state != null ? (typeMap[state] || 'info') : 'info'
}
 
// 获取状态文本
const getStateText = (state: number | null | undefined) => {
  const textMap: Record<number, string> = {
    0: '未审核',
    1: '审核通过',
    2: '审核驳回',
    3: '已结束'
  }
  return state != null ? (textMap[state] || '未知') : '未知'
}
 
// 搜索
const handleSearch = () => {
  pagination.page = 1
  loadData()
}
 
 
 
// 查看详情(跳转到详情页面,只读模式)
const handleViewDetail = (row: any) => {
  if (!row.id) {
    ElMessage.error('无法获取报名记录ID')
    return
  }
  // 跳转到详情页面(只读模式)
  router.push(`/player/${row.id}/detail`)
}
 
// 查看详情(跳转到评分页面)
const handleView = (row: any) => {
  if (!row.id) {
    ElMessage.error('无法获取报名记录ID')
    return
  }
  router.push(`/activity-player/${row.id}/rating`)
}
 
// 分页大小改变
const handleSizeChange = (size: number) => {
  pagination.size = size
  loadData()
}
 
// 当前页改变
const handleCurrentChange = (page: number) => {
  pagination.page = page
  loadData()
}
 
// 获取比赛名称(如果是阶段,返回父比赛名称;如果是比赛,返回自己的名称)
const getActivityName = (activity: any) => {
  if (activity.pid > 0 && activity.parent) {
    return activity.parent.name
  }
  return activity.name
}
 
 
 
// 加载活动选项
const loadActivityOptions = async () => {
  try {
    console.log('=== 开始加载活动选项 ===')
    console.log('调用getAllActivities API...')
    
    const activities = await getAllActivities()
    console.log('API返回的原始数据:', activities)
    console.log('数据类型:', typeof activities)
    console.log('是否为数组:', Array.isArray(activities))
    
    if (activities && Array.isArray(activities)) {
      console.log('活动数量:', activities.length)
      activities.forEach((activity, index) => {
        console.log(`活动${index + 1}:`, {
          id: activity.id,
          name: activity.name,
          state: activity.state,
          pid: activity.pid
        })
      })
      
      // 过滤出正在进行的比赛(不是阶段)
      const filtered = activities.filter(activity => 
        activity.state === 1 && (activity.pid === 0 || activity.pid === "0")
      )
      console.log('过滤条件: state === 1 && (pid === 0 || pid === "0")')
      console.log('过滤后的活动:', filtered)
      
      activityOptions.value = filtered
      console.log('设置到activityOptions.value:', activityOptions.value)
      console.log('activityOptions.value.length:', activityOptions.value.length)
      
      // 强制触发响应式更新
      setTimeout(() => {
        console.log('延迟检查activityOptions.value:', activityOptions.value)
        console.log('延迟检查activityOptions.value.length:', activityOptions.value.length)
      }, 100)
    } else {
      console.error('API返回的数据格式不正确:', activities)
    }
  } catch (error) {
    console.error('=== 加载活动选项失败 ===')
    console.error('错误详情:', error)
    console.error('错误消息:', error.message)
    console.error('错误堆栈:', error.stack)
    ElMessage.error('加载活动选项失败: ' + error.message)
  }
}
 
// 调试API函数
const debugAPI = async () => {
  console.log('=== 开始API调试 ===')
  
  // 检查认证状态
  const token = localStorage.getItem('auth_token')
  const userInfo = localStorage.getItem('user_info')
  
  console.log('认证状态检查:')
  console.log('Token:', token ? '已存在' : '不存在')
  console.log('Token内容:', token)
  console.log('用户信息:', userInfo ? '已存在' : '不存在')
  console.log('用户信息内容:', userInfo)
  
  if (!token) {
    ElMessage.error('未找到认证token,请先登录')
    return
  }
  
  // 测试API调用
  try {
    console.log('开始测试getAllActivities API...')
    const activities = await getAllActivities()
    console.log('API调用成功,返回数据:', activities)
    ElMessage.success(`API调用成功,获取到${activities?.length || 0}个活动`)
  } catch (error) {
    console.error('API调用失败:', error)
    ElMessage.error('API调用失败: ' + error.message)
  }
}
 
// 加载数据
const loadData = async () => {
  loading.value = true
  try {
    const list = await PlayerApi.getApplications(
      searchForm.name || '', 
      searchForm.activityId || null, 
      searchForm.state !== '' ? parseInt(searchForm.state) : null,
      pagination.page, 
      pagination.size
    )
    tableData.value = (list || []).map((item: any) => ({
      id: item.id,
      name: item.playerName,
      avatar: '',
      activityName: item.activityName,
      phone: item.phone,
      applyTime: item.applyTime,
      state: item.state
    }))
    pagination.total = tableData.value.length
  } catch (e: any) {
    ElMessage.error(String(e?.message || e))
  } finally {
    loading.value = false
  }
}
 
onMounted(() => {
  console.log('=== Player页面onMounted被调用 ===')
  console.log('当前时间:', new Date().toLocaleTimeString())
  console.log('activityOptions初始值:', activityOptions.value)
  console.log('直接加载活动选项进行测试...')
  
  // 立即调用API测试
  loadActivityOptions().catch(error => {
    console.error('loadActivityOptions调用失败:', error)
  })
  
  // loadData() // 暂时注释掉,专注于活动选项加载
})
</script>
 
<style lang="scss" scoped>
.player-page {
  .card-title {
    margin-bottom: 20px;
    color: #303133;
    font-size: 16px;
    font-weight: 500;
  }
  
  .toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    align-items: center;
  }
  
  .table-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
  }
  
 
  
  .pagination {
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
  }
}
</style>