index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <view class="survey-page">
  3. <view class="section-card">
  4. <text class="section-title">{{ pageTitle }}</text>
  5. <text class="card-desc">{{ pageDesc }}</text>
  6. <view class="interest-list">
  7. <label class="interest-item" v-for="(item, idx) in interests" :key="idx">
  8. <radio :value="item.value" :checked="selected === item.value" @tap="selected = item.value" color="#2E6FA8" />
  9. <text class="interest-icon">{{ item.icon }}</text>
  10. <view class="interest-info">
  11. <text class="interest-name">{{ item.label }}</text>
  12. <text class="interest-desc">{{ item.desc }}</text>
  13. </view>
  14. </label>
  15. </view>
  16. <button class="submit-btn" @click="handleSubmit" :loading="loading" :disabled="loading || !selected">提交调研</button>
  17. </view>
  18. <view class="section-card">
  19. <text class="section-title">我的卡券</text>
  20. <LoadingSkeleton v-if="couponLoading" :rows="2" />
  21. <ErrorState v-else-if="couponError" message="卡券加载失败" @retry="loadCoupons" />
  22. <EmptyState v-else-if="coupons.length === 0" icon="🎟️" title="暂无卡券" desc="暂无可用卡券" />
  23. <view v-else class="coupon-list">
  24. <view class="coupon-item" v-for="(c, idx) in coupons" :key="idx">
  25. <view class="coupon-type">{{ couponTypeLabel(c.type) }}</view>
  26. <view class="coupon-info">
  27. <text class="coupon-code">{{ c.code }}</text>
  28. <text class="coupon-status" :class="c.status">{{ c.status === 'unused' ? '未使用' : '已使用' }}</text>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import { submitSurvey, getMyCoupons } from '@/utils/api.js'
  37. import { guardPage } from '@/utils/guard.js'
  38. import LoadingSkeleton from '@/components/loading-skeleton.vue'
  39. import ErrorState from '@/components/error-state.vue'
  40. import EmptyState from '@/components/empty-state.vue'
  41. export default {
  42. components: { LoadingSkeleton, ErrorState, EmptyState },
  43. data() {
  44. return {
  45. interests: [
  46. { value: 'wealth', label: '财富管理', icon: '💰', desc: '家庭财务规划与数据分析' },
  47. { value: 'health', label: '健康管理', icon: '❤️', desc: '家庭健康数据分析与管理' },
  48. { value: 'growth', label: '成长规划', icon: '🌱', desc: '家庭成长数据分析与规划' }
  49. ],
  50. selected: '',
  51. loading: false,
  52. coupons: [],
  53. couponLoading: false,
  54. couponError: false,
  55. courseId: '',
  56. pageTitle: '测评兴趣调研',
  57. pageDesc: '选择您最感兴趣的领域,提交后有机会获得测评兑换卡'
  58. }
  59. },
  60. onLoad(options) {
  61. this.courseId = (options && options.courseId) ? options.courseId : ''
  62. if (this.courseId) {
  63. this.pageTitle = '课程调研'
  64. this.pageDesc = '完成本次课程调研,帮助我们将课程调整得更贴合您的需求'
  65. }
  66. },
  67. onShow() {
  68. if (!guardPage()) return
  69. this.loadCoupons()
  70. },
  71. methods: {
  72. loadCoupons() {
  73. var self = this
  74. self.couponLoading = true
  75. self.couponError = false
  76. getMyCoupons().then(function(resp) {
  77. self.coupons = resp.data || []
  78. }).catch(function() {
  79. self.couponError = true
  80. }).finally(function() {
  81. self.couponLoading = false
  82. })
  83. },
  84. handleSubmit() {
  85. if (!this.selected || this.loading) return
  86. this.loading = true
  87. var self = this
  88. var classId = this.$store.state.classId
  89. var payload = { interest: this.selected, classId: classId ? parseInt(classId) : null }
  90. if (this.courseId) payload.courseId = parseInt(this.courseId)
  91. submitSurvey(payload).then(function() {
  92. uni.showToast({ title: '提交成功', icon: 'success' })
  93. self.loadCoupons()
  94. }).catch(function(err) {
  95. uni.showToast({ title: (err && err.message) || '提交失败', icon: 'none' })
  96. }).finally(function() {
  97. self.loading = false
  98. })
  99. },
  100. couponTypeLabel(type) {
  101. var map = { etotem: '测评兑换卡' }
  102. return map[type] || type
  103. }
  104. }
  105. }
  106. </script>
  107. <style scoped>
  108. .survey-page { min-height: 100vh; background: #F5FAFE; padding: 24rpx 32rpx; }
  109. .section-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; margin-bottom: 24rpx; }
  110. .section-title { display: block; font-size: 32rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 8rpx; border-left: 8rpx solid #2E6FA8; padding-left: 16rpx; }
  111. .card-desc { display: block; font-size: 26rpx; color: #3B5A78; margin-bottom: 28rpx; }
  112. .interest-list { margin-bottom: 24rpx; }
  113. .interest-item { display: flex; align-items: center; padding: 24rpx; border: 2rpx solid #E3ECF4; border-radius: 12rpx; margin-bottom: 16rpx; }
  114. .interest-icon { font-size: 40rpx; margin: 0 16rpx; }
  115. .interest-name { display: block; font-size: 28rpx; font-weight: 600; color: #1E3A5F; }
  116. .interest-desc { display: block; font-size: 24rpx; color: #3B5A78; margin-top: 4rpx; }
  117. .submit-btn { width: 100%; height: 88rpx; line-height: 88rpx; background: #2E6FA8; color: #FFF; font-size: 30rpx; font-weight: 600; border-radius: 44rpx; border: none; }
  118. .submit-btn:active { opacity: 0.85; }
  119. .empty-text { font-size: 26rpx; color: #6B7B8C; text-align: center; padding: 24rpx 0; }
  120. .coupon-list { margin-top: 16rpx; }
  121. .coupon-item { display: flex; justify-content: space-between; align-items: center; padding: 20rpx 0; border-bottom: 1rpx solid #E3ECF4; }
  122. .coupon-type { font-size: 28rpx; font-weight: 500; color: #1E3A5F; }
  123. .coupon-info { display: flex; align-items: center; gap: 16rpx; }
  124. .coupon-code { font-size: 24rpx; color: #3B5A78; font-family: monospace; }
  125. .coupon-status { font-size: 22rpx; padding: 4rpx 12rpx; border-radius: 6rpx; }
  126. .coupon-status.unused { background: #E6F6EE; color: #0E8A4F; }
  127. .coupon-status.used { background: #E3ECF4; color: #6B7B8C; }
  128. </style>