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
// pages/review/index.js
const app = getApp()
const { graphqlRequest, formatDate } = require('../../lib/utils')
 
Page({
  data: {
    loading: false,
    loadingMore: false,
    hasMore: true,
    
    // 当前选项卡 0:我未评审 1:我已评审 2:学员未评审
    currentTab: 0,
    
    // 搜索关键词
    searchKeyword: '',
    
    // 项目列表
    projectList: [],
    
    // 统计数据
    unReviewedCount: 0,
    reviewedCount: 0,
    studentUnReviewedCount: 0,
    
    // 分页参数
    pageSize: 10,
    currentPage: 1
  },
 
  onLoad(options) {
    // 如果有传入的tab参数,设置当前选项卡
    if (options.tab) {
      this.setData({
        currentTab: parseInt(options.tab) || 0
      })
    }
    
    this.loadData()
  },
 
  onShow() {
    // 页面显示时刷新数据
    this.loadData()
  },
 
  onPullDownRefresh() {
    this.loadData()
  },
 
  onReachBottom() {
    if (this.data.hasMore && !this.data.loadingMore) {
      this.loadMoreData()
    }
  },
 
  // 切换选项卡
  switchTab(e) {
    const index = e.currentTarget.dataset.index
    if (index === this.data.currentTab) return
    
    this.setData({
      currentTab: index,
      projectList: [],
      currentPage: 1,
      hasMore: true,
      searchKeyword: ''
    })
    
    this.loadData()
  },
 
  // 搜索输入
  onSearchInput(e) {
    this.setData({
      searchKeyword: e.detail.value
    })
  },
 
  // 搜索确认
  onSearch() {
    this.setData({
      projectList: [],
      currentPage: 1,
      hasMore: true
    })
    this.loadData()
  },
 
  // 清除搜索
  clearSearch() {
    this.setData({
      searchKeyword: '',
      projectList: [],
      currentPage: 1,
      hasMore: true
    })
    this.loadData()
  },
 
  // 加载数据
  async loadData() {
    if (this.data.loading) return
    
    this.setData({ loading: true })
    
    try {
      await Promise.all([
        this.loadProjectList(),
        this.loadStatistics()
      ])
    } catch (error) {
      console.error('加载数据失败:', error)
      wx.showToast({
        title: '加载失败',
        icon: 'none'
      })
    } finally {
      this.setData({ loading: false })
      wx.stopPullDownRefresh()
    }
  },
 
  // 加载更多数据
  async loadMoreData() {
    if (this.data.loadingMore || !this.data.hasMore) return
    
    this.setData({ loadingMore: true })
    
    try {
      await this.loadProjectList(true)
    } catch (error) {
      console.error('加载更多失败:', error)
    } finally {
      this.setData({ loadingMore: false })
    }
  },
 
  // 加载项目列表
  async loadProjectList(isLoadMore = false) {
    const { currentTab, searchKeyword, pageSize, currentPage } = this.data
    
    let query = ''
    let variables = {
      page: isLoadMore ? currentPage + 1 : 1,
      pageSize: pageSize,
      searchKeyword: searchKeyword || null
    }
 
    // 根据当前选项卡构建不同的查询
    switch (currentTab) {
      case 0: // 我未评审
        query = `
          query GetUnReviewedProjects($page: Int!, $pageSize: Int!, $searchKeyword: String) {
            unReviewedProjects(page: $page, pageSize: $pageSize, searchKeyword: $searchKeyword) {
              items {
                id
                projectName
                activityName
                stageName
                studentName
                submitTime
                status
              }
              total
              hasMore
            }
          }
        `
        break
      case 1: // 我已评审
        query = `
          query GetReviewedProjects($page: Int!, $pageSize: Int!, $searchKeyword: String) {
            reviewedProjects(page: $page, pageSize: $pageSize, searchKeyword: $searchKeyword) {
              items {
                id
                projectName
                activityName
                stageName
                studentName
                submitTime
                reviewTime
                score
                status
              }
              total
              hasMore
            }
          }
        `
        break
      case 2: // 学员未评审
        query = `
          query GetStudentUnReviewedProjects($page: Int!, $pageSize: Int!, $searchKeyword: String) {
            studentUnReviewedProjects(page: $page, pageSize: $pageSize, searchKeyword: $searchKeyword) {
              items {
                id
                projectName
                activityName
                stageName
                studentName
                submitTime
                status
              }
              total
              hasMore
            }
          }
        `
        break
    }
 
    const result = await graphqlRequest(query, variables)
    
    if (result) {
      const dataKey = currentTab === 0 ? 'unReviewedProjects' : 
                     currentTab === 1 ? 'reviewedProjects' : 
                     'studentUnReviewedProjects'
      
      const data = result[dataKey]
      
      if (data && data.items) {
        // 处理项目数据
        const projects = data.items.map(item => ({
          ...item,
          submitTime: item.submitTime ? formatDate(item.submitTime) : '',
          reviewTime: item.reviewTime ? formatDate(item.reviewTime) : '',
          statusText: this.getStatusText(item.status),
          statusType: this.getStatusType(item.status)
        }))
 
        this.setData({
          projectList: isLoadMore ? [...this.data.projectList, ...projects] : projects,
          hasMore: data.hasMore || false,
          currentPage: variables.page
        })
      }
    }
  },
 
  // 加载统计数据
  async loadStatistics() {
    try {
      const query = `
        query GetReviewStatistics {
          reviewStatistics {
            unReviewedCount
            reviewedCount
            studentUnReviewedCount
          }
        }
      `
      
      const result = await graphqlRequest(query)
      
      if (result && result.reviewStatistics) {
        this.setData({
          unReviewedCount: result.reviewStatistics.unReviewedCount || 0,
          reviewedCount: result.reviewStatistics.reviewedCount || 0,
          studentUnReviewedCount: result.reviewStatistics.studentUnReviewedCount || 0
        })
      }
    } catch (error) {
      console.error('加载统计数据失败:', error)
    }
  },
 
  // 跳转到评审详情页面
  goToReviewDetail(e) {
    const { activityPlayerId } = e.currentTarget.dataset
    if (activityPlayerId) {
      wx.navigateTo({
        url: `/pages/judge/review?id=${activityPlayerId}`
      })
    }
  },
 
  // 获取状态文本
  getStatusText(status) {
    const statusMap = {
      'SUBMITTED': '已提交',
      'UNDER_REVIEW': '评审中',
      'REVIEWED': '已评审',
      'REJECTED': '已拒绝'
    }
    return statusMap[status] || status
  },
 
  // 获取状态类型
  getStatusType(status) {
    const typeMap = {
      'SUBMITTED': 'info',
      'UNDER_REVIEW': 'warning',
      'REVIEWED': 'success',
      'REJECTED': 'danger'
    }
    return typeMap[status] || 'info'
  },
 
  // 获取空状态文本
  getEmptyText() {
    const { currentTab, searchKeyword } = this.data
    
    if (searchKeyword) {
      return '未找到相关项目'
    }
    
    const emptyTexts = ['暂无待评审项目', '暂无已评审项目', '暂无学员未评审项目']
    return emptyTexts[currentTab] || '暂无数据'
  },
 
  // 获取空状态描述
  getEmptyDesc() {
    const { currentTab, searchKeyword } = this.data
    
    if (searchKeyword) {
      return '请尝试其他关键词搜索'
    }
    
    const emptyDescs = [
      '当前没有需要您评审的项目',
      '您还没有完成任何评审',
      '当前没有学员未评审的项目'
    ]
    return emptyDescs[currentTab] || ''
  }
})