| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <template>
- <view class="survey-page">
- <view class="section-card">
- <text class="section-title">{{ pageTitle }}</text>
- <text class="card-desc">{{ pageDesc }}</text>
- <view class="interest-list">
- <label class="interest-item" v-for="(item, idx) in interests" :key="idx">
- <radio :value="item.value" :checked="selected === item.value" @tap="selected = item.value" color="#2E6FA8" />
- <text class="interest-icon">{{ item.icon }}</text>
- <view class="interest-info">
- <text class="interest-name">{{ item.label }}</text>
- <text class="interest-desc">{{ item.desc }}</text>
- </view>
- </label>
- </view>
- <button class="submit-btn" @click="handleSubmit" :loading="loading" :disabled="loading || !selected">提交调研</button>
- </view>
- <view class="section-card">
- <text class="section-title">我的卡券</text>
- <LoadingSkeleton v-if="couponLoading" :rows="2" />
- <ErrorState v-else-if="couponError" message="卡券加载失败" @retry="loadCoupons" />
- <EmptyState v-else-if="coupons.length === 0" icon="🎟️" title="暂无卡券" desc="暂无可用卡券" />
- <view v-else class="coupon-list">
- <view class="coupon-item" v-for="(c, idx) in coupons" :key="idx">
- <view class="coupon-type">{{ couponTypeLabel(c.type) }}</view>
- <view class="coupon-info">
- <text class="coupon-code">{{ c.code }}</text>
- <text class="coupon-status" :class="c.status">{{ c.status === 'unused' ? '未使用' : '已使用' }}</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { submitSurvey, getMyCoupons } from '@/utils/api.js'
- import { guardPage } from '@/utils/guard.js'
- import LoadingSkeleton from '@/components/loading-skeleton.vue'
- import ErrorState from '@/components/error-state.vue'
- import EmptyState from '@/components/empty-state.vue'
- export default {
- components: { LoadingSkeleton, ErrorState, EmptyState },
- data() {
- return {
- interests: [
- { value: 'wealth', label: '财富管理', icon: '💰', desc: '家庭财务规划与数据分析' },
- { value: 'health', label: '健康管理', icon: '❤️', desc: '家庭健康数据分析与管理' },
- { value: 'growth', label: '成长规划', icon: '🌱', desc: '家庭成长数据分析与规划' }
- ],
- selected: '',
- loading: false,
- coupons: [],
- couponLoading: false,
- couponError: false,
- courseId: '',
- pageTitle: '测评兴趣调研',
- pageDesc: '选择您最感兴趣的领域,提交后有机会获得测评兑换卡'
- }
- },
- onLoad(options) {
- this.courseId = (options && options.courseId) ? options.courseId : ''
- if (this.courseId) {
- this.pageTitle = '课程调研'
- this.pageDesc = '完成本次课程调研,帮助我们将课程调整得更贴合您的需求'
- }
- },
- onShow() {
- if (!guardPage()) return
- this.loadCoupons()
- },
- methods: {
- loadCoupons() {
- var self = this
- self.couponLoading = true
- self.couponError = false
- getMyCoupons().then(function(resp) {
- self.coupons = resp.data || []
- }).catch(function() {
- self.couponError = true
- }).finally(function() {
- self.couponLoading = false
- })
- },
- handleSubmit() {
- if (!this.selected || this.loading) return
- this.loading = true
- var self = this
- var classId = this.$store.state.classId
- var payload = { interest: this.selected, classId: classId ? parseInt(classId) : null }
- if (this.courseId) payload.courseId = parseInt(this.courseId)
- submitSurvey(payload).then(function() {
- uni.showToast({ title: '提交成功', icon: 'success' })
- self.loadCoupons()
- }).catch(function(err) {
- uni.showToast({ title: (err && err.message) || '提交失败', icon: 'none' })
- }).finally(function() {
- self.loading = false
- })
- },
- couponTypeLabel(type) {
- var map = { etotem: '测评兑换卡' }
- return map[type] || type
- }
- }
- }
- </script>
- <style scoped>
- .survey-page { min-height: 100vh; background: #F5FAFE; padding: 24rpx 32rpx; }
- .section-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; margin-bottom: 24rpx; }
- .section-title { display: block; font-size: 32rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 8rpx; border-left: 8rpx solid #2E6FA8; padding-left: 16rpx; }
- .card-desc { display: block; font-size: 26rpx; color: #3B5A78; margin-bottom: 28rpx; }
- .interest-list { margin-bottom: 24rpx; }
- .interest-item { display: flex; align-items: center; padding: 24rpx; border: 2rpx solid #E3ECF4; border-radius: 12rpx; margin-bottom: 16rpx; }
- .interest-icon { font-size: 40rpx; margin: 0 16rpx; }
- .interest-name { display: block; font-size: 28rpx; font-weight: 600; color: #1E3A5F; }
- .interest-desc { display: block; font-size: 24rpx; color: #3B5A78; margin-top: 4rpx; }
- .submit-btn { width: 100%; height: 88rpx; line-height: 88rpx; background: #2E6FA8; color: #FFF; font-size: 30rpx; font-weight: 600; border-radius: 44rpx; border: none; }
- .submit-btn:active { opacity: 0.85; }
- .empty-text { font-size: 26rpx; color: #6B7B8C; text-align: center; padding: 24rpx 0; }
- .coupon-list { margin-top: 16rpx; }
- .coupon-item { display: flex; justify-content: space-between; align-items: center; padding: 20rpx 0; border-bottom: 1rpx solid #E3ECF4; }
- .coupon-type { font-size: 28rpx; font-weight: 500; color: #1E3A5F; }
- .coupon-info { display: flex; align-items: center; gap: 16rpx; }
- .coupon-code { font-size: 24rpx; color: #3B5A78; font-family: monospace; }
- .coupon-status { font-size: 22rpx; padding: 4rpx 12rpx; border-radius: 6rpx; }
- .coupon-status.unused { background: #E6F6EE; color: #0E8A4F; }
- .coupon-status.used { background: #E3ECF4; color: #6B7B8C; }
- </style>
|