| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <template>
- <view class="assignment-page">
- <view class="page-header">
- <text class="page-title">三本账认领</text>
- <text class="page-desc">认领一本账,成为做账专家或通用支援</text>
- </view>
- <LoadingSkeleton v-if="loading" :rows="3" />
- <ErrorState v-else-if="error" message="我的认领记录加载失败" @retry="loadAssignments" />
- <EmptyState v-else-if="books.length === 0" icon="📚" title="暂无可认领账本" desc="请刷新页面后重试" action-text="重新加载" @action="loadAssignments" />
- <view v-else class="book-list">
- <view class="book-card" v-for="(book, idx) in books" :key="idx">
- <view class="book-header">
- <text class="book-icon">{{ book.icon }}</text>
- <view class="book-info">
- <text class="book-name">{{ book.label }}</text>
- <text class="book-desc">{{ book.desc }}</text>
- </view>
- </view>
- <view v-if="isClaimed(book.type)" class="claimed-badge">已认领</view>
- <view v-else class="claim-actions">
- <view class="role-select">
- <text class="role-label">角色:</text>
- <radio-group @change="onRoleChange($event, book.type)">
- <label class="role-option"><radio value="expert" :checked="selectedRole[book.type] === 'expert'" color="#2E6FA8" />做账专家</label>
- <label class="role-option"><radio value="support" :checked="selectedRole[book.type] === 'support'" color="#2E6FA8" />通用支援</label>
- </radio-group>
- </view>
- <button class="claim-btn" @click="handleClaim(book.type)" :loading="claiming[book.type]">认领</button>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { claimAssignment, getMyAssignments } from '@/utils/api.js'
- import { guardPage } from '@/utils/guard.js'
- import LoadingSkeleton from '@/components/loading-skeleton.vue'
- import ErrorState from '@/components/error-state.vue'
- import EmptyState from '@/components/empty-state.vue'
- export default {
- components: { LoadingSkeleton, ErrorState, EmptyState },
- data() {
- return {
- books: [
- { type: 'wealth', label: '财富账', icon: '💰', desc: '记录家庭财务数据与分析' },
- { type: 'health', label: '健康账', icon: '❤️', desc: '记录家庭健康数据与管理' },
- { type: 'growth', label: '成长账', icon: '🌱', desc: '记录家庭成长数据与规划' }
- ],
- myAssignments: [],
- selectedRole: { wealth: 'expert', health: 'expert', growth: 'expert' },
- claiming: { wealth: false, health: false, growth: false },
- loading: false,
- error: false
- }
- },
- onShow() {
- if (!guardPage()) return
- this.loadAssignments()
- },
- methods: {
- loadAssignments() {
- var self = this
- self.loading = true
- self.error = false
- getMyAssignments().then(function(resp) {
- self.myAssignments = resp.data || []
- }).catch(function() {
- self.error = true
- }).finally(function() {
- self.loading = false
- })
- },
- isClaimed(type) {
- return this.myAssignments.some(function(a) { return a.bookType === type })
- },
- onRoleChange(e, type) {
- this.$set(this.selectedRole, type, e.detail.value)
- },
- handleClaim(type) {
- if (this.claiming[type]) return
- this.$set(this.claiming, type, true)
- var self = this
- claimAssignment({
- bookType: type,
- role: this.selectedRole[type],
- useSample: 0
- }).then(function() {
- uni.showToast({ title: '认领成功', icon: 'success' })
- self.loadAssignments()
- }).catch(function(err) {
- uni.showToast({ title: (err && err.message) || '认领失败', icon: 'none' })
- }).finally(function() {
- self.$set(self.claiming, type, false)
- })
- }
- }
- }
- </script>
- <style scoped>
- .assignment-page { min-height: 100vh; background: #F5FAFE; padding: 32rpx; }
- .page-header { margin-bottom: 32rpx; }
- .page-title { display: block; font-size: 40rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 8rpx; }
- .page-desc { display: block; font-size: 26rpx; color: #3B5A78; }
- .book-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; margin-bottom: 24rpx; }
- .book-header { display: flex; align-items: center; margin-bottom: 20rpx; }
- .book-icon { font-size: 48rpx; margin-right: 20rpx; }
- .book-name { display: block; font-size: 30rpx; font-weight: 600; color: #1E3A5F; }
- .book-desc { display: block; font-size: 24rpx; color: #3B5A78; margin-top: 4rpx; }
- .claimed-badge { background: #E6F6EE; color: #0E8A4F; font-size: 26rpx; font-weight: 500; padding: 12rpx 24rpx; border-radius: 8rpx; text-align: center; }
- .claim-actions { border-top: 1rpx solid #E3ECF4; padding-top: 20rpx; }
- .role-select { margin-bottom: 16rpx; }
- .role-label { font-size: 26rpx; color: #3B5A78; }
- .role-option { font-size: 26rpx; color: #1E3A5F; margin-right: 24rpx; }
- .claim-btn { width: 100%; height: 76rpx; line-height: 76rpx; background: #2E6FA8; color: #FFF; font-size: 28rpx; font-weight: 500; border-radius: 38rpx; border: none; }
- .claim-btn:active { opacity: 0.85; }
- </style>
|