const { graphqlRequest } = require('../../lib/utils') function formatTime(dateString) { if (!dateString) return '-' const date = new Date(dateString) const year = date.getFullYear() const month = String(date.getMonth() + 1).padStart(2, '0') const day = String(date.getDate()).padStart(2, '0') const hours = String(date.getHours()).padStart(2, '0') const minutes = String(date.getMinutes()).padStart(2, '0') return `${year}-${month}-${day} ${hours}:${minutes}` } const LIST_QUERY = ` query EmployeeReviewApplications($keyword: String, $state: Int, $page: Int, $size: Int) { employeeReviewApplications(keyword: $keyword, state: $state, page: $page, size: $size) { content { id playerName projectName activityName state stateText stateType applyTime } totalElements page size } } ` const STATS_QUERY = ` query EmployeeReviewStats($keyword: String) { employeeReviewStats(keyword: $keyword) { pendingCount approvedCount rejectedCount } } ` Page({ data: { loading: false, loadingMore: false, hasMore: true, tabs: [ { label: '待审核', value: 0 }, { label: '已审核', value: 1 }, { label: '驳回', value: 2 } ], currentTab: 0, searchKeyword: '', list: [], page: 1, pageSize: 10, stats: { pendingCount: 0, approvedCount: 0, rejectedCount: 0 }, employeeReviewStats: { pendingCount: 0, approvedCount: 0, rejectedCount: 0 }, needRefresh: false }, onLoad() { this.initializeReviewData() }, onShow() { if (this.data.needRefresh) { this.initializeReviewData() this.setData({ needRefresh: false }) } }, onPullDownRefresh() { this.initializeReviewData().finally(() => { wx.stopPullDownRefresh() }) }, onReachBottom() { if (this.data.hasMore && !this.data.loadingMore) { this.loadList(false) } }, async initializeReviewData() { this.setData({ loading: true, page: 1, list: [], hasMore: true }) try { await Promise.all([ this.loadList(true), this.loadStats(this.data.searchKeyword) ]) } catch (error) { console.error('初始化审核数据失败:', error) } finally { this.setData({ loading: false }) } }, async loadStats(keyword) { try { const variables = {} const trimmed = keyword && typeof keyword === 'string' ? keyword.trim() : '' if (trimmed) { variables.keyword = trimmed } const result = await graphqlRequest(STATS_QUERY, variables) if (result && result.employeeReviewStats) { this.setData({ stats: result.employeeReviewStats, employeeReviewStats: result.employeeReviewStats }) } } catch (error) { console.error('加载审核统计失败:', error) } }, async loadList(reset = false) { if (reset) { this.setData({ loading: true }) } else { this.setData({ loadingMore: true }) } const nextPage = reset ? 1 : this.data.page + 1 const keywordInput = this.data.searchKeyword || '' const trimmedKeyword = keywordInput.trim() const variables = { keyword: trimmedKeyword ? trimmedKeyword : null, state: this.getStateByTab(this.data.currentTab), page: nextPage, size: this.data.pageSize } try { const result = await graphqlRequest(LIST_QUERY, variables) const pageData = result && result.employeeReviewApplications const items = pageData && Array.isArray(pageData.content) ? pageData.content : [] items.forEach(item => { item.applyTime = formatTime(item.applyTime) }) const list = reset ? items : this.data.list.concat(items) const total = pageData && typeof pageData.totalElements === 'number' ? pageData.totalElements : 0 const hasMore = nextPage * this.data.pageSize < total this.setData({ list, page: nextPage, hasMore }) } catch (error) { console.error('加载审核列表失败:', error) wx.showToast({ title: '加载失败', icon: 'none' }) } finally { if (reset) { this.setData({ loading: false }) } else { this.setData({ loadingMore: false }) } } }, onSearchInput(e) { this.setData({ searchKeyword: e.detail.value || '' }) }, onSearch() { this.initializeReviewData() }, clearSearch() { if (!this.data.searchKeyword) return this.setData({ searchKeyword: '' }) this.initializeReviewData() }, switchTab(e) { const index = Number(e.currentTarget.dataset.index || 0) if (index === this.data.currentTab) { return } this.setData({ currentTab: index, page: 1, list: [], hasMore: true }) this.initializeReviewData() }, getStateByTab(index) { switch (index) { case 0: return 0 case 1: return 1 case 2: return 2 default: return null } }, goToDetail(e) { const id = e.currentTarget.dataset.id if (!id) { wx.showToast({ title: '报名ID无效', icon: 'none' }) return } wx.navigateTo({ url: `/pages/profile/employee-review-detail?id=${id}`, events: { auditUpdated: () => { this.setData({ needRefresh: true }) } } }) } })