index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <view class="assignment-page">
  3. <view class="page-header">
  4. <text class="page-title">三本账认领</text>
  5. <text class="page-desc">认领一本账,成为做账专家或通用支援</text>
  6. </view>
  7. <LoadingSkeleton v-if="loading" :rows="3" />
  8. <ErrorState v-else-if="error" message="我的认领记录加载失败" @retry="loadAssignments" />
  9. <EmptyState v-else-if="books.length === 0" icon="📚" title="暂无可认领账本" desc="请刷新页面后重试" action-text="重新加载" @action="loadAssignments" />
  10. <view v-else class="book-list">
  11. <view class="book-card" v-for="(book, idx) in books" :key="idx">
  12. <view class="book-header">
  13. <text class="book-icon">{{ book.icon }}</text>
  14. <view class="book-info">
  15. <text class="book-name">{{ book.label }}</text>
  16. <text class="book-desc">{{ book.desc }}</text>
  17. </view>
  18. </view>
  19. <view v-if="isClaimed(book.type)" class="claimed-badge">已认领</view>
  20. <view v-else class="claim-actions">
  21. <view class="role-select">
  22. <text class="role-label">角色:</text>
  23. <radio-group @change="onRoleChange($event, book.type)">
  24. <label class="role-option"><radio value="expert" :checked="selectedRole[book.type] === 'expert'" color="#2E6FA8" />做账专家</label>
  25. <label class="role-option"><radio value="support" :checked="selectedRole[book.type] === 'support'" color="#2E6FA8" />通用支援</label>
  26. </radio-group>
  27. </view>
  28. <button class="claim-btn" @click="handleClaim(book.type)" :loading="claiming[book.type]">认领</button>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import { claimAssignment, getMyAssignments } from '@/utils/api.js'
  36. import { guardPage } from '@/utils/guard.js'
  37. import LoadingSkeleton from '@/components/loading-skeleton.vue'
  38. import ErrorState from '@/components/error-state.vue'
  39. import EmptyState from '@/components/empty-state.vue'
  40. export default {
  41. components: { LoadingSkeleton, ErrorState, EmptyState },
  42. data() {
  43. return {
  44. books: [
  45. { type: 'wealth', label: '财富账', icon: '💰', desc: '记录家庭财务数据与分析' },
  46. { type: 'health', label: '健康账', icon: '❤️', desc: '记录家庭健康数据与管理' },
  47. { type: 'growth', label: '成长账', icon: '🌱', desc: '记录家庭成长数据与规划' }
  48. ],
  49. myAssignments: [],
  50. selectedRole: { wealth: 'expert', health: 'expert', growth: 'expert' },
  51. claiming: { wealth: false, health: false, growth: false },
  52. loading: false,
  53. error: false
  54. }
  55. },
  56. onShow() {
  57. if (!guardPage()) return
  58. this.loadAssignments()
  59. },
  60. methods: {
  61. loadAssignments() {
  62. var self = this
  63. self.loading = true
  64. self.error = false
  65. getMyAssignments().then(function(resp) {
  66. self.myAssignments = resp.data || []
  67. }).catch(function() {
  68. self.error = true
  69. }).finally(function() {
  70. self.loading = false
  71. })
  72. },
  73. isClaimed(type) {
  74. return this.myAssignments.some(function(a) { return a.bookType === type })
  75. },
  76. onRoleChange(e, type) {
  77. this.$set(this.selectedRole, type, e.detail.value)
  78. },
  79. handleClaim(type) {
  80. if (this.claiming[type]) return
  81. this.$set(this.claiming, type, true)
  82. var self = this
  83. claimAssignment({
  84. bookType: type,
  85. role: this.selectedRole[type],
  86. useSample: 0
  87. }).then(function() {
  88. uni.showToast({ title: '认领成功', icon: 'success' })
  89. self.loadAssignments()
  90. }).catch(function(err) {
  91. uni.showToast({ title: (err && err.message) || '认领失败', icon: 'none' })
  92. }).finally(function() {
  93. self.$set(self.claiming, type, false)
  94. })
  95. }
  96. }
  97. }
  98. </script>
  99. <style scoped>
  100. .assignment-page { min-height: 100vh; background: #F5FAFE; padding: 32rpx; }
  101. .page-header { margin-bottom: 32rpx; }
  102. .page-title { display: block; font-size: 40rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 8rpx; }
  103. .page-desc { display: block; font-size: 26rpx; color: #3B5A78; }
  104. .book-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; margin-bottom: 24rpx; }
  105. .book-header { display: flex; align-items: center; margin-bottom: 20rpx; }
  106. .book-icon { font-size: 48rpx; margin-right: 20rpx; }
  107. .book-name { display: block; font-size: 30rpx; font-weight: 600; color: #1E3A5F; }
  108. .book-desc { display: block; font-size: 24rpx; color: #3B5A78; margin-top: 4rpx; }
  109. .claimed-badge { background: #E6F6EE; color: #0E8A4F; font-size: 26rpx; font-weight: 500; padding: 12rpx 24rpx; border-radius: 8rpx; text-align: center; }
  110. .claim-actions { border-top: 1rpx solid #E3ECF4; padding-top: 20rpx; }
  111. .role-select { margin-bottom: 16rpx; }
  112. .role-label { font-size: 26rpx; color: #3B5A78; }
  113. .role-option { font-size: 26rpx; color: #1E3A5F; margin-right: 24rpx; }
  114. .claim-btn { width: 100%; height: 76rpx; line-height: 76rpx; background: #2E6FA8; color: #FFF; font-size: 28rpx; font-weight: 500; border-radius: 38rpx; border: none; }
  115. .claim-btn:active { opacity: 0.85; }
  116. </style>