quota.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <view class="header">
  4. <text class="title">我的测评额度</text>
  5. <text class="subtitle">购买测评任务模板后获得可使用次数</text>
  6. </view>
  7. <view class="quota-list" v-if="quotas.length > 0">
  8. <view class="quota-card" v-for="item in quotas" :key="item.id">
  9. <view class="card-top">
  10. <text class="product-name">{{ item.productName }}</text>
  11. <text class="status-tag" :class="item.status === 'active' ? 'active' : 'used'">
  12. {{ item.status === 'active' ? '可用' : '已用完' }}
  13. </text>
  14. </view>
  15. <view class="progress-section">
  16. <view class="progress-bar-bg">
  17. <view class="progress-bar-fill" :style="{ width: progressPercent(item) + '%' }"></view>
  18. </view>
  19. <text class="progress-text">{{ item.usedSessions }}/{{ item.totalSessions }} 次</text>
  20. </view>
  21. <view class="card-info">
  22. <view class="info-row">
  23. <text class="info-label">剩余</text>
  24. <text class="info-value highlight">{{ item.remainingSessions }} 次</text>
  25. </view>
  26. <view class="info-row" v-if="item.validityEnd">
  27. <text class="info-label">有效期至</text>
  28. <text class="info-value" :class="{ expired: item.expired }">
  29. {{ formatDate(item.validityEnd) }}
  30. <text v-if="item.expired">(已过期)</text>
  31. </text>
  32. </view>
  33. </view>
  34. <view class="card-actions" v-if="item.remainingSessions > 0 && !item.expired">
  35. <button class="btn-use" @click="goAppoint(item)">预约测评</button>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="empty" v-else>
  40. <text class="empty-icon">📋</text>
  41. <text class="empty-text">暂无可用的测评额度</text>
  42. <button class="btn-buy" @click="goBuy">去购买任务模板</button>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import { getAssessmentQuotas } from '../../utils/api.js'
  48. import { parseDate } from '../../utils/format.js'
  49. import fontScaleMixin from '@/mixins/font-scale.js'
  50. export default {
  51. mixins: [fontScaleMixin],
  52. data() {
  53. return {
  54. quotas: []
  55. }
  56. },
  57. onShow() {
  58. this.loadQuotas()
  59. },
  60. methods: {
  61. async loadQuotas() {
  62. try {
  63. uni.showLoading({ title: '加载中...' })
  64. const res = await getAssessmentQuotas()
  65. uni.hideLoading()
  66. if (res.code === 200) {
  67. this.quotas = res.data || []
  68. }
  69. } catch (e) {
  70. uni.hideLoading()
  71. console.error('加载额度失败', e)
  72. }
  73. },
  74. progressPercent(item) {
  75. if (!item.totalSessions || item.totalSessions === 0) return 0
  76. return Math.min(100, (item.usedSessions / item.totalSessions) * 100)
  77. },
  78. formatDate(dateStr) {
  79. if (!dateStr) return ''
  80. const d = parseDate(dateStr)
  81. if (!d) return ''
  82. return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate()
  83. },
  84. goAppoint(item) {
  85. uni.navigateTo({
  86. url: '/pages/assessment/apply?quotaId=' + item.id
  87. })
  88. },
  89. goBuy() {
  90. uni.navigateTo({
  91. url: '/pages/shop/index/index?type=assessment'
  92. })
  93. }
  94. }
  95. }
  96. </script>
  97. <style scoped lang="scss">
  98. .container {
  99. padding: $uni-space-page;
  100. background: $facade-fill-page;
  101. min-height: 100vh;
  102. }
  103. .header {
  104. text-align: center;
  105. padding: 40rpx 0 $uni-space-lg;
  106. }
  107. .title {
  108. font-size: calc(44rpx * var(--font-scale, 1));
  109. font-weight: bold;
  110. color: $facade-text-strong;
  111. display: block;
  112. margin-bottom: 16rpx;
  113. }
  114. .subtitle {
  115. font-size: calc(26rpx * var(--font-scale, 1));
  116. color: $facade-text-muted;
  117. }
  118. .quota-list {
  119. display: flex;
  120. flex-direction: column;
  121. gap: 24rpx;
  122. }
  123. .quota-card {
  124. background: $app-surface;
  125. border-radius: 24rpx;
  126. padding: 28rpx;
  127. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  128. }
  129. .card-top {
  130. display: flex;
  131. justify-content: space-between;
  132. align-items: center;
  133. margin-bottom: 20rpx;
  134. }
  135. .product-name {
  136. font-size: calc(30rpx * var(--font-scale, 1));
  137. font-weight: bold;
  138. color: $facade-text-strong;
  139. }
  140. .status-tag {
  141. font-size: calc(22rpx * var(--font-scale, 1));
  142. padding: 4rpx 16rpx;
  143. border-radius: 24rpx;
  144. }
  145. .status-tag.active {
  146. background: $mat-green-tint;
  147. color: $mat-green-strong;
  148. }
  149. .status-tag.used {
  150. background: $facade-fill-2;
  151. color: $facade-text-muted;
  152. }
  153. .progress-section {
  154. display: flex;
  155. align-items: center;
  156. gap: 16rpx;
  157. margin-bottom: 20rpx;
  158. }
  159. .progress-bar-bg {
  160. flex: 1;
  161. height: 12rpx;
  162. background: $facade-fill;
  163. border-radius: 8rpx;
  164. overflow: hidden;
  165. }
  166. .progress-bar-fill {
  167. height: 100%;
  168. background: linear-gradient(90deg, $accent-indigo, $accent-indigo-deep);
  169. border-radius: 8rpx;
  170. }
  171. .progress-text {
  172. font-size: calc(24rpx * var(--font-scale, 1));
  173. color: $facade-text-muted;
  174. white-space: nowrap;
  175. }
  176. .card-info {
  177. border-top: 1rpx solid $facade-fill;
  178. padding-top: 16rpx;
  179. }
  180. .info-row {
  181. display: flex;
  182. justify-content: space-between;
  183. margin-bottom: 8rpx;
  184. }
  185. .info-label {
  186. font-size: calc(26rpx * var(--font-scale, 1));
  187. color: $facade-text-body;
  188. }
  189. .info-value {
  190. font-size: calc(26rpx * var(--font-scale, 1));
  191. color: $facade-text-strong;
  192. }
  193. .info-value.highlight {
  194. color: $accent-indigo;
  195. font-weight: bold;
  196. font-size: calc(32rpx * var(--font-scale, 1));
  197. }
  198. .info-value.expired {
  199. color: $mat-red;
  200. }
  201. .card-actions {
  202. margin-top: 20rpx;
  203. }
  204. .btn-use {
  205. width: 100%;
  206. height: 76rpx;
  207. line-height: 76rpx;
  208. background: linear-gradient(135deg, $accent-indigo, $accent-indigo-deep);
  209. color: $app-surface;
  210. border-radius: 24rpx;
  211. font-size: calc(28rpx * var(--font-scale, 1));
  212. text-align: center;
  213. }
  214. .empty {
  215. display: flex;
  216. flex-direction: column;
  217. align-items: center;
  218. padding-top: 120rpx;
  219. }
  220. .empty-icon {
  221. font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
  222. margin-bottom: 20rpx;
  223. }
  224. .empty-text {
  225. font-size: calc(28rpx * var(--font-scale, 1));
  226. color: $facade-text-muted;
  227. margin-bottom: 40rpx;
  228. }
  229. .btn-buy {
  230. width: 300rpx;
  231. height: 80rpx;
  232. line-height: 80rpx;
  233. background: linear-gradient(135deg, $accent-indigo, $accent-indigo-deep);
  234. color: $app-surface;
  235. border-radius: 24rpx;
  236. font-size: calc(28rpx * var(--font-scale, 1));
  237. text-align: center;
  238. }
  239. </style>