| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517 |
- <template>
- <view class="page-workbench">
- <!-- Role gate: only practitioners -->
- <view v-if="!isPractitioner" class="gate-state">
- <text class="gate-icon">🔒</text>
- <text class="gate-text">仅能量师可访问此页面</text>
- <button class="gate-back-btn" @click="goBack">返回</button>
- </view>
- <template v-else>
- <!-- Loading state: skeleton cards -->
- <view v-if="loading" class="loading-container">
- <view v-for="n in 4" :key="n" class="skeleton-card">
- <view class="skeleton-row">
- <view class="skeleton-line w-40"></view>
- <view class="skeleton-line w-20"></view>
- </view>
- <view class="skeleton-line w-90"></view>
- <view class="skeleton-line w-60"></view>
- <view class="skeleton-row">
- <view class="skeleton-line w-30"></view>
- <view class="skeleton-line w-16"></view>
- </view>
- </view>
- </view>
- <template v-else>
- <!-- Stats header: 2x2 grid -->
- <view class="stats-grid">
- <view class="stat-item pending-stat">
- <text class="stat-value">{{ stats.pending }}</text>
- <text class="stat-label">待处理</text>
- </view>
- <view class="stat-item accepted-stat">
- <text class="stat-value">{{ stats.accepted }}</text>
- <text class="stat-label">已接受</text>
- </view>
- <view class="stat-item negotiating-stat">
- <text class="stat-value">{{ stats.negotiating }}</text>
- <text class="stat-label">协商中</text>
- </view>
- <view class="stat-item completed-stat">
- <text class="stat-value">{{ stats.completed }}</text>
- <text class="stat-label">已完成</text>
- </view>
- </view>
- <!-- Section title -->
- <view class="section-header">
- <text class="section-title">方案需求</text>
- </view>
- <!-- Empty state -->
- <view v-if="requests.length === 0" class="empty-state">
- <text class="empty-icon">📋</text>
- <text class="empty-text">暂无方案需求</text>
- </view>
- <!-- Request list -->
- <view v-for="(req, idx) in requests" :key="req.id || idx" class="request-card">
- <!-- Card top: userId + requestType -->
- <view class="card-header">
- <text class="user-info">用户 {{ req.userId }}</text>
- <text class="request-type-tag">{{ requestTypeLabel(req.requestType) }}</text>
- </view>
- <!-- Description (truncated 2 lines, clickable to open monitor) -->
- <view @click.stop="goMonitor(req)">
- <text class="card-desc">{{ req.description }}</text>
- </view>
- <!-- Card bottom: budget + date + status -->
- <view class="card-meta">
- <view class="meta-left">
- <text class="budget-range">{{ req.budgetRange }}</text>
- <text class="date-text">{{ formatDate(req.createdAt) }}</text>
- </view>
- <text class="status-badge" :class="'badge-' + req.status">
- {{ statusLabel(req.status) }}
- </text>
- </view>
- <!-- Action buttons by status -->
- <view v-if="req.status === 'pending'" class="action-row" @click.stop>
- <button class="btn btn-accept" :disabled="acceptingId === req.id" @click="handleAccept(req)">
- {{ acceptingId === req.id ? '处理中...' : '接受' }}
- </button>
- <button class="btn btn-reject" :disabled="rejectingId === req.id" @click="handleReject(req)">
- {{ rejectingId === req.id ? '处理中...' : '拒绝' }}
- </button>
- </view>
- <view v-else-if="req.status === 'accepted'" class="action-row">
- <button class="btn btn-negotiate" @click="goMonitor(req)">去协商</button>
- </view>
- <view v-else class="action-row" @click.stop>
- <button class="btn btn-view" @click="goMonitor(req)">查看详情</button>
- </view>
- </view>
- </template>
- </template>
- </view>
- </template>
- <script setup>
- import { ref, computed, onMounted } from 'vue'
- import { onPullDownRefresh } from '@dcloudio/uni-app'
- import { useUserStore } from '@/stores/user'
- import { workbenchApi } from '@/utils/api'
- const userStore = useUserStore()
- const requests = ref([])
- const loading = ref(true)
- const error = ref('')
- const acceptingId = ref(null)
- const rejectingId = ref(null)
- // Role gate: only practitioners (vipType === 'practitioner')
- const isPractitioner = computed(() => userStore.vipType === 'practitioner')
- // Derived stats from request list
- const stats = computed(() => {
- const list = requests.value
- return {
- pending: list.filter(r => r.status === 'pending').length,
- accepted: list.filter(r => r.status === 'accepted').length,
- negotiating: list.filter(r => r.status === 'negotiating').length,
- completed: list.filter(r => r.status === 'completed').length
- }
- })
- // Request type labels
- const requestTypeLabels = {
- academic: '学业方向',
- career: '职业规划',
- parent_child: '亲子关系',
- other: '其他',
- // Fallback for direct Chinese values
- '学业方向': '学业方向',
- '职业规划': '职业规划',
- '亲子关系': '亲子关系',
- '其他': '其他'
- }
- function requestTypeLabel(type) {
- return requestTypeLabels[type] || type || '其他'
- }
- // Status labels (Chinese)
- const statusLabels = {
- pending: '待处理',
- accepted: '已接受',
- negotiating: '协商中',
- completed: '已完成',
- cancelled: '已取消',
- rejected: '已拒绝'
- }
- function statusLabel(status) {
- return statusLabels[status] || status || '未知'
- }
- // Lifecycle: fetch on mount
- onMounted(async () => {
- if (isPractitioner.value) {
- await fetchData()
- } else {
- loading.value = false
- }
- })
- // Pull-to-refresh
- onPullDownRefresh(async () => {
- if (isPractitioner.value) {
- await fetchData()
- }
- uni.stopPullDownRefresh()
- })
- async function fetchData() {
- error.value = ''
- loading.value = true
- try {
- const data = await workbenchApi.list()
- requests.value = data || []
- } catch (e) {
- error.value = '网络错误,请下拉刷新重试'
- uni.showToast({ title: '加载失败', icon: 'none' })
- } finally {
- loading.value = false
- }
- }
- async function handleAccept(req) {
- acceptingId.value = req.id
- try {
- await workbenchApi.accept(req.id)
- uni.showToast({ title: '已接受', icon: 'success' })
- await fetchData()
- } catch (e) {
- uni.showToast({ title: e.message || '操作失败', icon: 'none' })
- } finally {
- acceptingId.value = null
- }
- }
- async function handleReject(req) {
- uni.showModal({
- title: '确认拒绝',
- content: '确定要拒绝此方案需求吗?',
- success: async (res) => {
- if (res.confirm) {
- rejectingId.value = req.id
- try {
- await workbenchApi.reject(req.id)
- uni.showToast({ title: '已拒绝', icon: 'success' })
- await fetchData()
- } catch (e) {
- uni.showToast({ title: e.message || '操作失败', icon: 'none' })
- } finally {
- rejectingId.value = null
- }
- }
- }
- })
- }
- function goBack() {
- uni.navigateBack()
- }
- function goMonitor(req) {
- if (!req || !req.id) return
- uni.navigateTo({ url: `/pages/plan/monitor?requestId=${req.id}` })
- }
- function formatDate(dateStr) {
- if (!dateStr) return ''
- const d = new Date(dateStr)
- return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
- }
- </script>
- <style scoped lang="scss">
- .page-workbench {
- min-height: 100vh;
- padding: 16px;
- background: linear-gradient(180deg, #0c0a1a 0%, #1a1232 100%);
- }
- /* ===== Role Gate ===== */
- .gate-state {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- padding: 120px 20px;
- text-align: center;
- }
- .gate-icon {
- font-size: 48px;
- display: block;
- margin-bottom: 16px;
- }
- .gate-text {
- font-size: 15px;
- color: rgba(255,255,255,0.6);
- margin-bottom: 24px;
- display: block;
- }
- .gate-back-btn {
- width: 160px;
- padding: 12px 0;
- background: linear-gradient(135deg, #f59e0b, #d97706);
- color: #fff;
- border: none;
- border-radius: 12px;
- font-size: 15px;
- font-weight: 600;
- }
- /* ===== Loading / Skeleton ===== */
- .loading-container {
- padding-top: 8px;
- }
- .skeleton-card {
- background: rgba(255,255,255,0.02);
- border-radius: 16px;
- padding: 16px;
- margin-bottom: 14px;
- }
- .skeleton-row {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 12px;
- }
- .skeleton-line {
- height: 14px;
- background: rgba(255,255,255,0.06);
- border-radius: 6px;
- margin-bottom: 10px;
- animation: pulse 1.5s ease-in-out infinite;
- }
- .skeleton-line:last-child {
- margin-bottom: 0;
- }
- .w-16 { width: 16%; }
- .w-20 { width: 20%; }
- .w-30 { width: 30%; }
- .w-40 { width: 40%; }
- .w-60 { width: 60%; }
- .w-80 { width: 80%; }
- .w-90 { width: 90%; }
- @keyframes pulse {
- 0%, 100% { opacity: 0.3; }
- 50% { opacity: 0.6; }
- }
- /* ===== Stats Grid ===== */
- .stats-grid {
- display: grid;
- grid-template-columns: 1fr 1fr;
- gap: 10px;
- margin-bottom: 20px;
- }
- .stat-item {
- background: rgba(255,255,255,0.02);
- border-radius: 14px;
- padding: 16px 12px;
- text-align: center;
- border: 1px solid rgba(255,255,255,0.04);
- }
- .stat-value {
- font-size: 28px;
- font-weight: 700;
- display: block;
- margin-bottom: 4px;
- }
- .stat-label {
- font-size: 12px;
- color: rgba(255,255,255,0.45);
- display: block;
- }
- .pending-stat .stat-value { color: #f59e0b; }
- .accepted-stat .stat-value { color: #10b981; }
- .negotiating-stat .stat-value { color: #3b82f6; }
- .completed-stat .stat-value { color: #6b7280; }
- /* ===== Section Header ===== */
- .section-header {
- margin-bottom: 14px;
- }
- .section-title {
- font-size: 18px;
- font-weight: 700;
- color: rgba(255,255,255,0.9);
- }
- /* ===== Empty State ===== */
- .empty-state {
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 60px 20px;
- text-align: center;
- }
- .empty-icon {
- font-size: 40px;
- display: block;
- margin-bottom: 12px;
- }
- .empty-text {
- font-size: 14px;
- color: rgba(255,255,255,0.4);
- display: block;
- }
- /* ===== Request Card ===== */
- .request-card {
- background: rgba(255,255,255,0.02);
- border-radius: 16px;
- padding: 16px;
- margin-bottom: 14px;
- }
- .card-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 10px;
- }
- .user-info {
- font-size: 14px;
- font-weight: 600;
- color: rgba(255,255,255,0.85);
- }
- .request-type-tag {
- font-size: 11px;
- font-weight: 500;
- color: #f59e0b;
- background: rgba(245, 158, 11, 0.12);
- padding: 3px 10px;
- border-radius: 999px;
- }
- .card-desc {
- display: -webkit-box;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- overflow: hidden;
- text-overflow: ellipsis;
- font-size: 14px;
- line-height: 1.5;
- color: rgba(255,255,255,0.6);
- margin-bottom: 12px;
- }
- .card-meta {
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .meta-left {
- display: flex;
- flex-direction: column;
- gap: 2px;
- }
- .budget-range {
- font-size: 13px;
- font-weight: 500;
- color: rgba(255,255,255,0.7);
- }
- .date-text {
- font-size: 11px;
- color: rgba(255,255,255,0.35);
- }
- /* ===== Status Badge ===== */
- .status-badge {
- font-size: 11px;
- font-weight: 500;
- padding: 3px 12px;
- border-radius: 999px;
- flex-shrink: 0;
- }
- .badge-pending {
- background: rgba(245, 158, 11, 0.15);
- color: #f59e0b;
- }
- .badge-accepted {
- background: rgba(16, 185, 129, 0.15);
- color: #10b981;
- }
- .badge-negotiating {
- background: rgba(59, 130, 246, 0.15);
- color: #3b82f6;
- }
- .badge-completed {
- background: rgba(107, 114, 128, 0.15);
- color: #9ca3af;
- }
- .badge-cancelled {
- background: rgba(239, 68, 68, 0.15);
- color: #ef4444;
- }
- .badge-rejected {
- background: rgba(107, 114, 128, 0.15);
- color: #9ca3af;
- }
- /* ===== Action Buttons ===== */
- .action-row {
- display: flex;
- gap: 10px;
- margin-top: 14px;
- padding-top: 14px;
- border-top: 1px solid rgba(255,255,255,0.04);
- }
- .btn {
- flex: 1;
- height: 40px;
- border: none;
- border-radius: 10px;
- font-size: 14px;
- font-weight: 600;
- display: flex;
- align-items: center;
- justify-content: center;
- line-height: 1;
- }
- .btn-accept {
- background: #10b981;
- color: #fff;
- }
- .btn-accept[disabled] {
- opacity: 0.5;
- }
- .btn-reject {
- background: transparent;
- border: 1px solid #ef4444;
- color: #ef4444;
- }
- .btn-reject[disabled] {
- opacity: 0.5;
- }
- .btn-negotiate {
- background: rgba(59, 130, 246, 0.1);
- border: 1px solid rgba(59, 130, 246, 0.3);
- color: #3b82f6;
- }
- .btn-negotiate[disabled] {
- opacity: 0.4;
- }
- .btn-view {
- background: rgba(255, 255, 255, 0.06);
- border: 1px solid rgba(255, 255, 255, 0.15);
- color: rgba(255, 255, 255, 0.7);
- }
- </style>
|