index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view class="survey-page">
  3. <view class="section-card">
  4. <text class="section-title">测评兴趣调研</text>
  5. <text class="card-desc">选择您最感兴趣的领域,提交后有机会获得测评兑换卡</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="#F97316" />
  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. <view v-if="coupons.length === 0" class="empty-text">暂无卡券</view>
  21. <view class="coupon-list">
  22. <view class="coupon-item" v-for="(c, idx) in coupons" :key="idx">
  23. <view class="coupon-type">{{ couponTypeLabel(c.type) }}</view>
  24. <view class="coupon-info">
  25. <text class="coupon-code">{{ c.code }}</text>
  26. <text class="coupon-status" :class="c.status">{{ c.status === 'unused' ? '未使用' : '已使用' }}</text>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import { submitSurvey, getMyCoupons } from '@/utils/api.js'
  35. import { guardPage } from '@/utils/guard.js'
  36. export default {
  37. data() {
  38. return {
  39. interests: [
  40. { value: 'wealth', label: '财富管理', icon: '💰', desc: '家庭财务规划与数据分析' },
  41. { value: 'health', label: '健康管理', icon: '❤️', desc: '家庭健康数据分析与管理' },
  42. { value: 'growth', label: '成长规划', icon: '🌱', desc: '家庭成长数据分析与规划' }
  43. ],
  44. selected: '',
  45. loading: false,
  46. coupons: []
  47. }
  48. },
  49. onShow() {
  50. if (!guardPage()) return
  51. this.loadCoupons()
  52. },
  53. methods: {
  54. loadCoupons() {
  55. var self = this
  56. getMyCoupons().then(function(resp) {
  57. self.coupons = resp.data || []
  58. }).catch(function() {})
  59. },
  60. handleSubmit() {
  61. if (!this.selected || this.loading) return
  62. this.loading = true
  63. var self = this
  64. var classId = this.$store.state.classId
  65. submitSurvey({ interest: this.selected, classId: classId ? parseInt(classId) : null }).then(function() {
  66. uni.showToast({ title: '提交成功', icon: 'success' })
  67. self.loadCoupons()
  68. }).catch(function(err) {
  69. uni.showToast({ title: (err && err.message) || '提交失败', icon: 'none' })
  70. }).finally(function() {
  71. self.loading = false
  72. })
  73. },
  74. couponTypeLabel(type) {
  75. var map = { etotem: '测评兑换卡' }
  76. return map[type] || type
  77. }
  78. }
  79. }
  80. </script>
  81. <style scoped>
  82. .survey-page { min-height: 100vh; background: #F5F5F5; padding: 24rpx 32rpx; }
  83. .section-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; margin-bottom: 24rpx; }
  84. .section-title { display: block; font-size: 32rpx; font-weight: 700; color: #1E293B; margin-bottom: 8rpx; border-left: 8rpx solid #F97316; padding-left: 16rpx; }
  85. .card-desc { display: block; font-size: 26rpx; color: #64748B; margin-bottom: 28rpx; }
  86. .interest-list { margin-bottom: 24rpx; }
  87. .interest-item { display: flex; align-items: center; padding: 24rpx; border: 2rpx solid #E2E8F0; border-radius: 12rpx; margin-bottom: 16rpx; }
  88. .interest-icon { font-size: 40rpx; margin: 0 16rpx; }
  89. .interest-name { display: block; font-size: 28rpx; font-weight: 600; color: #1E293B; }
  90. .interest-desc { display: block; font-size: 24rpx; color: #64748B; margin-top: 4rpx; }
  91. .submit-btn { width: 100%; height: 88rpx; line-height: 88rpx; background: #F97316; color: #FFF; font-size: 30rpx; font-weight: 600; border-radius: 44rpx; border: none; }
  92. .submit-btn:active { opacity: 0.85; }
  93. .empty-text { font-size: 26rpx; color: #94A3B8; text-align: center; padding: 24rpx 0; }
  94. .coupon-list { margin-top: 16rpx; }
  95. .coupon-item { display: flex; justify-content: space-between; align-items: center; padding: 20rpx 0; border-bottom: 1rpx solid #F1F5F9; }
  96. .coupon-type { font-size: 28rpx; font-weight: 500; color: #1E293B; }
  97. .coupon-info { display: flex; align-items: center; gap: 16rpx; }
  98. .coupon-code { font-size: 24rpx; color: #64748B; font-family: monospace; }
  99. .coupon-status { font-size: 22rpx; padding: 4rpx 12rpx; border-radius: 6rpx; }
  100. .coupon-status.unused { background: #F0FDF4; color: #22C55E; }
  101. .coupon-status.used { background: #F1F5F9; color: #94A3B8; }
  102. </style>