| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- <template>
- <view class="container">
- <view class="header">
- <text class="title">我的测评额度</text>
- <text class="subtitle">购买测评任务模板后获得可使用次数</text>
- </view>
- <view class="quota-list" v-if="quotas.length > 0">
- <view class="quota-card" v-for="item in quotas" :key="item.id">
- <view class="card-top">
- <text class="product-name">{{ item.productName }}</text>
- <text class="status-tag" :class="item.status === 'active' ? 'active' : 'used'">
- {{ item.status === 'active' ? '可用' : '已用完' }}
- </text>
- </view>
- <view class="progress-section">
- <view class="progress-bar-bg">
- <view class="progress-bar-fill" :style="{ width: progressPercent(item) + '%' }"></view>
- </view>
- <text class="progress-text">{{ item.usedSessions }}/{{ item.totalSessions }} 次</text>
- </view>
- <view class="card-info">
- <view class="info-row">
- <text class="info-label">剩余</text>
- <text class="info-value highlight">{{ item.remainingSessions }} 次</text>
- </view>
- <view class="info-row" v-if="item.validityEnd">
- <text class="info-label">有效期至</text>
- <text class="info-value" :class="{ expired: item.expired }">
- {{ formatDate(item.validityEnd) }}
- <text v-if="item.expired">(已过期)</text>
- </text>
- </view>
- </view>
- <view class="card-actions" v-if="item.remainingSessions > 0 && !item.expired">
- <button class="btn-use" @click="goAppoint(item)">预约测评</button>
- </view>
- </view>
- </view>
- <view class="empty" v-else>
- <text class="empty-icon">📋</text>
- <text class="empty-text">暂无可用的测评额度</text>
- <button class="btn-buy" @click="goBuy">去购买任务模板</button>
- </view>
- </view>
- </template>
- <script>
- import { getAssessmentQuotas } from '../../utils/api.js'
- import { parseDate } from '../../utils/format.js'
- export default {
- data() {
- return {
- quotas: []
- }
- },
- onShow() {
- this.loadQuotas()
- },
- methods: {
- async loadQuotas() {
- try {
- uni.showLoading({ title: '加载中...' })
- const res = await getAssessmentQuotas()
- uni.hideLoading()
- if (res.code === 200) {
- this.quotas = res.data || []
- }
- } catch (e) {
- uni.hideLoading()
- console.error('加载额度失败', e)
- }
- },
- progressPercent(item) {
- if (!item.totalSessions || item.totalSessions === 0) return 0
- return Math.min(100, (item.usedSessions / item.totalSessions) * 100)
- },
- formatDate(dateStr) {
- if (!dateStr) return ''
- const d = parseDate(dateStr)
- if (!d) return ''
- return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate()
- },
- goAppoint(item) {
- uni.navigateTo({
- url: '/pages/assessment/apply?quotaId=' + item.id
- })
- },
- goBuy() {
- uni.navigateTo({
- url: '/pages/shop/index/index?type=assessment'
- })
- }
- }
- }
- </script>
- <style scoped>
- .container {
- padding: 30rpx;
- background: #F8F8F8;
- min-height: 100vh;
- }
- .header {
- text-align: center;
- padding: 40rpx 0 30rpx;
- }
- .title {
- font-size: 44rpx;
- font-weight: bold;
- color: #333;
- display: block;
- margin-bottom: 16rpx;
- }
- .subtitle {
- font-size: 26rpx;
- color: #999;
- }
- .quota-list {
- display: flex;
- flex-direction: column;
- gap: 24rpx;
- }
- .quota-card {
- background: #fff;
- border-radius: 20rpx;
- padding: 28rpx;
- box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
- }
- .card-top {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 20rpx;
- }
- .product-name {
- font-size: 30rpx;
- font-weight: bold;
- color: #333;
- }
- .status-tag {
- font-size: 22rpx;
- padding: 4rpx 16rpx;
- border-radius: 20rpx;
- }
- .status-tag.active {
- background: #E8F5E9;
- color: #2E7D32;
- }
- .status-tag.used {
- background: #F5F5F5;
- color: #999;
- }
- .progress-section {
- display: flex;
- align-items: center;
- gap: 16rpx;
- margin-bottom: 20rpx;
- }
- .progress-bar-bg {
- flex: 1;
- height: 12rpx;
- background: #F0F0F0;
- border-radius: 6rpx;
- overflow: hidden;
- }
- .progress-bar-fill {
- height: 100%;
- background: linear-gradient(90deg, #667eea, #764ba2);
- border-radius: 6rpx;
- }
- .progress-text {
- font-size: 24rpx;
- color: #999;
- white-space: nowrap;
- }
- .card-info {
- border-top: 1rpx solid #F0F0F0;
- padding-top: 16rpx;
- }
- .info-row {
- display: flex;
- justify-content: space-between;
- margin-bottom: 8rpx;
- }
- .info-label {
- font-size: 26rpx;
- color: #666;
- }
- .info-value {
- font-size: 26rpx;
- color: #333;
- }
- .info-value.highlight {
- color: #667eea;
- font-weight: bold;
- font-size: 32rpx;
- }
- .info-value.expired {
- color: #F44336;
- }
- .card-actions {
- margin-top: 20rpx;
- }
- .btn-use {
- width: 100%;
- height: 76rpx;
- line-height: 76rpx;
- background: linear-gradient(135deg, #667eea, #764ba2);
- color: #fff;
- border-radius: 38rpx;
- font-size: 28rpx;
- text-align: center;
- }
- .empty {
- display: flex;
- flex-direction: column;
- align-items: center;
- padding-top: 120rpx;
- }
- .empty-icon {
- font-size: 80rpx;
- margin-bottom: 20rpx;
- }
- .empty-text {
- font-size: 28rpx;
- color: #999;
- margin-bottom: 40rpx;
- }
- .btn-buy {
- width: 300rpx;
- height: 80rpx;
- line-height: 80rpx;
- background: linear-gradient(135deg, #667eea, #764ba2);
- color: #fff;
- border-radius: 40rpx;
- font-size: 28rpx;
- text-align: center;
- }
- </style>
|