quota.vue 5.4 KB

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