workbench.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <template>
  2. <view class="page-workbench">
  3. <!-- Role gate: only practitioners -->
  4. <view v-if="!isPractitioner" class="gate-state">
  5. <text class="gate-icon">🔒</text>
  6. <text class="gate-text">仅能量师可访问此页面</text>
  7. <button class="gate-back-btn" @click="goBack">返回</button>
  8. </view>
  9. <template v-else>
  10. <!-- Loading state: skeleton cards -->
  11. <view v-if="loading" class="loading-container">
  12. <view v-for="n in 4" :key="n" class="skeleton-card">
  13. <view class="skeleton-row">
  14. <view class="skeleton-line w-40"></view>
  15. <view class="skeleton-line w-20"></view>
  16. </view>
  17. <view class="skeleton-line w-90"></view>
  18. <view class="skeleton-line w-60"></view>
  19. <view class="skeleton-row">
  20. <view class="skeleton-line w-30"></view>
  21. <view class="skeleton-line w-16"></view>
  22. </view>
  23. </view>
  24. </view>
  25. <template v-else>
  26. <!-- Stats header: 2x2 grid -->
  27. <view class="stats-grid">
  28. <view class="stat-item pending-stat">
  29. <text class="stat-value">{{ stats.pending }}</text>
  30. <text class="stat-label">待处理</text>
  31. </view>
  32. <view class="stat-item accepted-stat">
  33. <text class="stat-value">{{ stats.accepted }}</text>
  34. <text class="stat-label">已接受</text>
  35. </view>
  36. <view class="stat-item negotiating-stat">
  37. <text class="stat-value">{{ stats.negotiating }}</text>
  38. <text class="stat-label">协商中</text>
  39. </view>
  40. <view class="stat-item completed-stat">
  41. <text class="stat-value">{{ stats.completed }}</text>
  42. <text class="stat-label">已完成</text>
  43. </view>
  44. </view>
  45. <!-- Section title -->
  46. <view class="section-header">
  47. <text class="section-title">方案需求</text>
  48. </view>
  49. <!-- Empty state -->
  50. <view v-if="requests.length === 0" class="empty-state">
  51. <text class="empty-icon">📋</text>
  52. <text class="empty-text">暂无方案需求</text>
  53. </view>
  54. <!-- Request list -->
  55. <view v-for="(req, idx) in requests" :key="req.id || idx" class="request-card">
  56. <!-- Card top: userId + requestType -->
  57. <view class="card-header">
  58. <text class="user-info">用户 {{ req.userId }}</text>
  59. <text class="request-type-tag">{{ requestTypeLabel(req.requestType) }}</text>
  60. </view>
  61. <!-- Description (truncated 2 lines, clickable to open monitor) -->
  62. <view @click.stop="goMonitor(req)">
  63. <text class="card-desc">{{ req.description }}</text>
  64. </view>
  65. <!-- Card bottom: budget + date + status -->
  66. <view class="card-meta">
  67. <view class="meta-left">
  68. <text class="budget-range">{{ req.budgetRange }}</text>
  69. <text class="date-text">{{ formatDate(req.createdAt) }}</text>
  70. </view>
  71. <text class="status-badge" :class="'badge-' + req.status">
  72. {{ statusLabel(req.status) }}
  73. </text>
  74. </view>
  75. <!-- Action buttons by status -->
  76. <view v-if="req.status === 'pending'" class="action-row" @click.stop>
  77. <button class="btn btn-accept" :disabled="acceptingId === req.id" @click="handleAccept(req)">
  78. {{ acceptingId === req.id ? '处理中...' : '接受' }}
  79. </button>
  80. <button class="btn btn-reject" :disabled="rejectingId === req.id" @click="handleReject(req)">
  81. {{ rejectingId === req.id ? '处理中...' : '拒绝' }}
  82. </button>
  83. </view>
  84. <view v-else-if="req.status === 'accepted'" class="action-row">
  85. <button class="btn btn-negotiate" @click="goMonitor(req)">去协商</button>
  86. </view>
  87. <view v-else class="action-row" @click.stop>
  88. <button class="btn btn-view" @click="goMonitor(req)">查看详情</button>
  89. </view>
  90. </view>
  91. </template>
  92. </template>
  93. </view>
  94. </template>
  95. <script setup>
  96. import { ref, computed, onMounted } from 'vue'
  97. import { onPullDownRefresh } from '@dcloudio/uni-app'
  98. import { useUserStore } from '@/stores/user'
  99. import { workbenchApi } from '@/utils/api'
  100. const userStore = useUserStore()
  101. const requests = ref([])
  102. const loading = ref(true)
  103. const error = ref('')
  104. const acceptingId = ref(null)
  105. const rejectingId = ref(null)
  106. // Role gate: only practitioners (vipType === 'practitioner')
  107. const isPractitioner = computed(() => userStore.vipType === 'practitioner')
  108. // Derived stats from request list
  109. const stats = computed(() => {
  110. const list = requests.value
  111. return {
  112. pending: list.filter(r => r.status === 'pending').length,
  113. accepted: list.filter(r => r.status === 'accepted').length,
  114. negotiating: list.filter(r => r.status === 'negotiating').length,
  115. completed: list.filter(r => r.status === 'completed').length
  116. }
  117. })
  118. // Request type labels
  119. const requestTypeLabels = {
  120. academic: '学业方向',
  121. career: '职业规划',
  122. parent_child: '亲子关系',
  123. other: '其他',
  124. // Fallback for direct Chinese values
  125. '学业方向': '学业方向',
  126. '职业规划': '职业规划',
  127. '亲子关系': '亲子关系',
  128. '其他': '其他'
  129. }
  130. function requestTypeLabel(type) {
  131. return requestTypeLabels[type] || type || '其他'
  132. }
  133. // Status labels (Chinese)
  134. const statusLabels = {
  135. pending: '待处理',
  136. accepted: '已接受',
  137. negotiating: '协商中',
  138. completed: '已完成',
  139. cancelled: '已取消',
  140. rejected: '已拒绝'
  141. }
  142. function statusLabel(status) {
  143. return statusLabels[status] || status || '未知'
  144. }
  145. // Lifecycle: fetch on mount
  146. onMounted(async () => {
  147. if (isPractitioner.value) {
  148. await fetchData()
  149. } else {
  150. loading.value = false
  151. }
  152. })
  153. // Pull-to-refresh
  154. onPullDownRefresh(async () => {
  155. if (isPractitioner.value) {
  156. await fetchData()
  157. }
  158. uni.stopPullDownRefresh()
  159. })
  160. async function fetchData() {
  161. error.value = ''
  162. loading.value = true
  163. try {
  164. const data = await workbenchApi.list()
  165. requests.value = data || []
  166. } catch (e) {
  167. error.value = '网络错误,请下拉刷新重试'
  168. uni.showToast({ title: '加载失败', icon: 'none' })
  169. } finally {
  170. loading.value = false
  171. }
  172. }
  173. async function handleAccept(req) {
  174. acceptingId.value = req.id
  175. try {
  176. await workbenchApi.accept(req.id)
  177. uni.showToast({ title: '已接受', icon: 'success' })
  178. await fetchData()
  179. } catch (e) {
  180. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  181. } finally {
  182. acceptingId.value = null
  183. }
  184. }
  185. async function handleReject(req) {
  186. uni.showModal({
  187. title: '确认拒绝',
  188. content: '确定要拒绝此方案需求吗?',
  189. success: async (res) => {
  190. if (res.confirm) {
  191. rejectingId.value = req.id
  192. try {
  193. await workbenchApi.reject(req.id)
  194. uni.showToast({ title: '已拒绝', icon: 'success' })
  195. await fetchData()
  196. } catch (e) {
  197. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  198. } finally {
  199. rejectingId.value = null
  200. }
  201. }
  202. }
  203. })
  204. }
  205. function goBack() {
  206. uni.navigateBack()
  207. }
  208. function goMonitor(req) {
  209. if (!req || !req.id) return
  210. uni.navigateTo({ url: `/pages/plan/monitor?requestId=${req.id}` })
  211. }
  212. function formatDate(dateStr) {
  213. if (!dateStr) return ''
  214. const d = new Date(dateStr)
  215. return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
  216. }
  217. </script>
  218. <style scoped lang="scss">
  219. .page-workbench {
  220. min-height: 100vh;
  221. padding: 16px;
  222. background: linear-gradient(180deg, #0c0a1a 0%, #1a1232 100%);
  223. }
  224. /* ===== Role Gate ===== */
  225. .gate-state {
  226. display: flex;
  227. flex-direction: column;
  228. align-items: center;
  229. justify-content: center;
  230. padding: 120px 20px;
  231. text-align: center;
  232. }
  233. .gate-icon {
  234. font-size: 48px;
  235. display: block;
  236. margin-bottom: 16px;
  237. }
  238. .gate-text {
  239. font-size: 15px;
  240. color: rgba(255,255,255,0.6);
  241. margin-bottom: 24px;
  242. display: block;
  243. }
  244. .gate-back-btn {
  245. width: 160px;
  246. padding: 12px 0;
  247. background: linear-gradient(135deg, #f59e0b, #d97706);
  248. color: #fff;
  249. border: none;
  250. border-radius: 12px;
  251. font-size: 15px;
  252. font-weight: 600;
  253. }
  254. /* ===== Loading / Skeleton ===== */
  255. .loading-container {
  256. padding-top: 8px;
  257. }
  258. .skeleton-card {
  259. background: rgba(255,255,255,0.02);
  260. border-radius: 16px;
  261. padding: 16px;
  262. margin-bottom: 14px;
  263. }
  264. .skeleton-row {
  265. display: flex;
  266. justify-content: space-between;
  267. align-items: center;
  268. margin-bottom: 12px;
  269. }
  270. .skeleton-line {
  271. height: 14px;
  272. background: rgba(255,255,255,0.06);
  273. border-radius: 6px;
  274. margin-bottom: 10px;
  275. animation: pulse 1.5s ease-in-out infinite;
  276. }
  277. .skeleton-line:last-child {
  278. margin-bottom: 0;
  279. }
  280. .w-16 { width: 16%; }
  281. .w-20 { width: 20%; }
  282. .w-30 { width: 30%; }
  283. .w-40 { width: 40%; }
  284. .w-60 { width: 60%; }
  285. .w-80 { width: 80%; }
  286. .w-90 { width: 90%; }
  287. @keyframes pulse {
  288. 0%, 100% { opacity: 0.3; }
  289. 50% { opacity: 0.6; }
  290. }
  291. /* ===== Stats Grid ===== */
  292. .stats-grid {
  293. display: grid;
  294. grid-template-columns: 1fr 1fr;
  295. gap: 10px;
  296. margin-bottom: 20px;
  297. }
  298. .stat-item {
  299. background: rgba(255,255,255,0.02);
  300. border-radius: 14px;
  301. padding: 16px 12px;
  302. text-align: center;
  303. border: 1px solid rgba(255,255,255,0.04);
  304. }
  305. .stat-value {
  306. font-size: 28px;
  307. font-weight: 700;
  308. display: block;
  309. margin-bottom: 4px;
  310. }
  311. .stat-label {
  312. font-size: 12px;
  313. color: rgba(255,255,255,0.45);
  314. display: block;
  315. }
  316. .pending-stat .stat-value { color: #f59e0b; }
  317. .accepted-stat .stat-value { color: #10b981; }
  318. .negotiating-stat .stat-value { color: #3b82f6; }
  319. .completed-stat .stat-value { color: #6b7280; }
  320. /* ===== Section Header ===== */
  321. .section-header {
  322. margin-bottom: 14px;
  323. }
  324. .section-title {
  325. font-size: 18px;
  326. font-weight: 700;
  327. color: rgba(255,255,255,0.9);
  328. }
  329. /* ===== Empty State ===== */
  330. .empty-state {
  331. display: flex;
  332. flex-direction: column;
  333. align-items: center;
  334. padding: 60px 20px;
  335. text-align: center;
  336. }
  337. .empty-icon {
  338. font-size: 40px;
  339. display: block;
  340. margin-bottom: 12px;
  341. }
  342. .empty-text {
  343. font-size: 14px;
  344. color: rgba(255,255,255,0.4);
  345. display: block;
  346. }
  347. /* ===== Request Card ===== */
  348. .request-card {
  349. background: rgba(255,255,255,0.02);
  350. border-radius: 16px;
  351. padding: 16px;
  352. margin-bottom: 14px;
  353. }
  354. .card-header {
  355. display: flex;
  356. justify-content: space-between;
  357. align-items: center;
  358. margin-bottom: 10px;
  359. }
  360. .user-info {
  361. font-size: 14px;
  362. font-weight: 600;
  363. color: rgba(255,255,255,0.85);
  364. }
  365. .request-type-tag {
  366. font-size: 11px;
  367. font-weight: 500;
  368. color: #f59e0b;
  369. background: rgba(245, 158, 11, 0.12);
  370. padding: 3px 10px;
  371. border-radius: 999px;
  372. }
  373. .card-desc {
  374. display: -webkit-box;
  375. -webkit-line-clamp: 2;
  376. -webkit-box-orient: vertical;
  377. overflow: hidden;
  378. text-overflow: ellipsis;
  379. font-size: 14px;
  380. line-height: 1.5;
  381. color: rgba(255,255,255,0.6);
  382. margin-bottom: 12px;
  383. }
  384. .card-meta {
  385. display: flex;
  386. justify-content: space-between;
  387. align-items: center;
  388. }
  389. .meta-left {
  390. display: flex;
  391. flex-direction: column;
  392. gap: 2px;
  393. }
  394. .budget-range {
  395. font-size: 13px;
  396. font-weight: 500;
  397. color: rgba(255,255,255,0.7);
  398. }
  399. .date-text {
  400. font-size: 11px;
  401. color: rgba(255,255,255,0.35);
  402. }
  403. /* ===== Status Badge ===== */
  404. .status-badge {
  405. font-size: 11px;
  406. font-weight: 500;
  407. padding: 3px 12px;
  408. border-radius: 999px;
  409. flex-shrink: 0;
  410. }
  411. .badge-pending {
  412. background: rgba(245, 158, 11, 0.15);
  413. color: #f59e0b;
  414. }
  415. .badge-accepted {
  416. background: rgba(16, 185, 129, 0.15);
  417. color: #10b981;
  418. }
  419. .badge-negotiating {
  420. background: rgba(59, 130, 246, 0.15);
  421. color: #3b82f6;
  422. }
  423. .badge-completed {
  424. background: rgba(107, 114, 128, 0.15);
  425. color: #9ca3af;
  426. }
  427. .badge-cancelled {
  428. background: rgba(239, 68, 68, 0.15);
  429. color: #ef4444;
  430. }
  431. .badge-rejected {
  432. background: rgba(107, 114, 128, 0.15);
  433. color: #9ca3af;
  434. }
  435. /* ===== Action Buttons ===== */
  436. .action-row {
  437. display: flex;
  438. gap: 10px;
  439. margin-top: 14px;
  440. padding-top: 14px;
  441. border-top: 1px solid rgba(255,255,255,0.04);
  442. }
  443. .btn {
  444. flex: 1;
  445. height: 40px;
  446. border: none;
  447. border-radius: 10px;
  448. font-size: 14px;
  449. font-weight: 600;
  450. display: flex;
  451. align-items: center;
  452. justify-content: center;
  453. line-height: 1;
  454. }
  455. .btn-accept {
  456. background: #10b981;
  457. color: #fff;
  458. }
  459. .btn-accept[disabled] {
  460. opacity: 0.5;
  461. }
  462. .btn-reject {
  463. background: transparent;
  464. border: 1px solid #ef4444;
  465. color: #ef4444;
  466. }
  467. .btn-reject[disabled] {
  468. opacity: 0.5;
  469. }
  470. .btn-negotiate {
  471. background: rgba(59, 130, 246, 0.1);
  472. border: 1px solid rgba(59, 130, 246, 0.3);
  473. color: #3b82f6;
  474. }
  475. .btn-negotiate[disabled] {
  476. opacity: 0.4;
  477. }
  478. .btn-view {
  479. background: rgba(255, 255, 255, 0.06);
  480. border: 1px solid rgba(255, 255, 255, 0.15);
  481. color: rgba(255, 255, 255, 0.7);
  482. }
  483. </style>