workbench.vue 12 KB

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