// 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] || ''
|
}
|
})
|