quota.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view class="container">
  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. export default {
  50. data() {
  51. return {
  52. quotas: []
  53. }
  54. },
  55. onShow() {
  56. this.loadQuotas()
  57. },
  58. methods: {
  59. async loadQuotas() {
  60. try {
  61. uni.showLoading({ title: '加载中...' })
  62. const res = await getAssessmentQuotas()
  63. uni.hideLoading()
  64. if (res.code === 200) {
  65. this.quotas = res.data || []
  66. }
  67. } catch (e) {
  68. uni.hideLoading()
  69. console.error('加载额度失败', e)
  70. }
  71. },
  72. progressPercent(item) {
  73. if (!item.totalSessions || item.totalSessions === 0) return 0
  74. return Math.min(100, (item.usedSessions / item.totalSessions) * 100)
  75. },
  76. formatDate(dateStr) {
  77. if (!dateStr) return ''
  78. const d = parseDate(dateStr)
  79. if (!d) return ''
  80. return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate()
  81. },
  82. goAppoint(item) {
  83. uni.navigateTo({
  84. url: '/pages/assessment/apply?quotaId=' + item.id
  85. })
  86. },
  87. goBuy() {
  88. uni.navigateTo({
  89. url: '/pages/shop/index/index?type=assessment'
  90. })
  91. }
  92. }
  93. }
  94. </script>
  95. <style scoped>
  96. .container {
  97. padding: 30rpx;
  98. background: #F8F8F8;
  99. min-height: 100vh;
  100. }
  101. .header {
  102. text-align: center;
  103. padding: 40rpx 0 30rpx;
  104. }
  105. .title {
  106. font-size: 44rpx;
  107. font-weight: bold;
  108. color: #333;
  109. display: block;
  110. margin-bottom: 16rpx;
  111. }
  112. .subtitle {
  113. font-size: 26rpx;
  114. color: #999;
  115. }
  116. .quota-list {
  117. display: flex;
  118. flex-direction: column;
  119. gap: 24rpx;
  120. }
  121. .quota-card {
  122. background: #fff;
  123. border-radius: 20rpx;
  124. padding: 28rpx;
  125. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  126. }
  127. .card-top {
  128. display: flex;
  129. justify-content: space-between;
  130. align-items: center;
  131. margin-bottom: 20rpx;
  132. }
  133. .product-name {
  134. font-size: 30rpx;
  135. font-weight: bold;
  136. color: #333;
  137. }
  138. .status-tag {
  139. font-size: 22rpx;
  140. padding: 4rpx 16rpx;
  141. border-radius: 20rpx;
  142. }
  143. .status-tag.active {
  144. background: #E8F5E9;
  145. color: #2E7D32;
  146. }
  147. .status-tag.used {
  148. background: #F5F5F5;
  149. color: #999;
  150. }
  151. .progress-section {
  152. display: flex;
  153. align-items: center;
  154. gap: 16rpx;
  155. margin-bottom: 20rpx;
  156. }
  157. .progress-bar-bg {
  158. flex: 1;
  159. height: 12rpx;
  160. background: #F0F0F0;
  161. border-radius: 6rpx;
  162. overflow: hidden;
  163. }
  164. .progress-bar-fill {
  165. height: 100%;
  166. background: linear-gradient(90deg, #667eea, #764ba2);
  167. border-radius: 6rpx;
  168. }
  169. .progress-text {
  170. font-size: 24rpx;
  171. color: #999;
  172. white-space: nowrap;
  173. }
  174. .card-info {
  175. border-top: 1rpx solid #F0F0F0;
  176. padding-top: 16rpx;
  177. }
  178. .info-row {
  179. display: flex;
  180. justify-content: space-between;
  181. margin-bottom: 8rpx;
  182. }
  183. .info-label {
  184. font-size: 26rpx;
  185. color: #666;
  186. }
  187. .info-value {
  188. font-size: 26rpx;
  189. color: #333;
  190. }
  191. .info-value.highlight {
  192. color: #667eea;
  193. font-weight: bold;
  194. font-size: 32rpx;
  195. }
  196. .info-value.expired {
  197. color: #F44336;
  198. }
  199. .card-actions {
  200. margin-top: 20rpx;
  201. }
  202. .btn-use {
  203. width: 100%;
  204. height: 76rpx;
  205. line-height: 76rpx;
  206. background: linear-gradient(135deg, #667eea, #764ba2);
  207. color: #fff;
  208. border-radius: 38rpx;
  209. font-size: 28rpx;
  210. text-align: center;
  211. }
  212. .empty {
  213. display: flex;
  214. flex-direction: column;
  215. align-items: center;
  216. padding-top: 120rpx;
  217. }
  218. .empty-icon {
  219. font-size: 80rpx;
  220. margin-bottom: 20rpx;
  221. }
  222. .empty-text {
  223. font-size: 28rpx;
  224. color: #999;
  225. margin-bottom: 40rpx;
  226. }
  227. .btn-buy {
  228. width: 300rpx;
  229. height: 80rpx;
  230. line-height: 80rpx;
  231. background: linear-gradient(135deg, #667eea, #764ba2);
  232. color: #fff;
  233. border-radius: 40rpx;
  234. font-size: 28rpx;
  235. text-align: center;
  236. }
  237. </style>