form.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view class="form-page">
  3. <EmptyState
  4. v-if="invalid"
  5. icon="🎪"
  6. title="未找到对应沙龙"
  7. desc="缺少沙龙信息,请返回活动列表重新选择"
  8. action-text="返回列表"
  9. @action="goBackList"
  10. />
  11. <view v-else class="section-card">
  12. <text class="section-title">{{ memberMode ? '会员免费报名' : '沙龙报名' }}</text>
  13. <text class="card-desc">{{ memberMode ? '使用会员免费沙龙次数,报名成功即锁定名额' : '填写联系方式,完成支付后即可锁定名额' }}</text>
  14. <view class="summary-box" v-if="salonTitle">
  15. <view class="summary-row">
  16. <text class="summary-label">活动主题</text>
  17. <text class="summary-value">{{ salonTheme }} - {{ salonTitle }}</text>
  18. </view>
  19. </view>
  20. <view class="form-item">
  21. <text class="form-label">姓名</text>
  22. <input class="form-input" v-model="form.name" placeholder="请输入真实姓名" />
  23. </view>
  24. <view class="form-item">
  25. <text class="form-label">手机号</text>
  26. <input class="form-input" v-model="form.phone" type="number" maxlength="11" placeholder="请输入手机号" />
  27. </view>
  28. <view class="form-item" v-if="!memberMode">
  29. <text class="form-label">邀请码(选填)</text>
  30. <input class="form-input" v-model="form.inviteCode" placeholder="邀请码(选填)" />
  31. </view>
  32. <button class="submit-btn" @click="handleSubmit" :loading="loading" :disabled="loading">提交报名</button>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import { createSalonEnroll, memberSalonRegister } from '@/utils/api.js'
  38. import { guardPage } from '@/utils/guard.js'
  39. import { captureInviteCode, getPendingInviteCode, consumeInviteCode } from '@/utils/invite.js'
  40. import EmptyState from '@/components/empty-state.vue'
  41. export default {
  42. components: { EmptyState },
  43. data() {
  44. return {
  45. form: {
  46. salonId: '',
  47. name: '',
  48. phone: '',
  49. inviteCode: ''
  50. },
  51. salonTheme: '',
  52. salonTitle: '',
  53. memberMode: false,
  54. loading: false,
  55. invalid: false
  56. }
  57. },
  58. onLoad(options) {
  59. if (!guardPage()) return
  60. // 邀请链:先捕获本页 URL 邀请码;无则回填分享链路存下的 pending 邀请码(跨页/跨登录保持)
  61. captureInviteCode(options)
  62. this.form.salonId = options && options.salonId ? options.salonId : ''
  63. this.form.inviteCode = options && options.inviteCode ? decodeURIComponent(options.inviteCode) : getPendingInviteCode()
  64. this.salonTheme = options && options.theme ? decodeURIComponent(options.theme) : ''
  65. this.salonTitle = options && options.title ? decodeURIComponent(options.title) : ''
  66. this.form.name = options && options.name ? decodeURIComponent(options.name) : ''
  67. this.form.phone = options && options.phone ? decodeURIComponent(options.phone) : ''
  68. this.memberMode = options && options.member === '1'
  69. if (!this.form.salonId) {
  70. this.invalid = true
  71. }
  72. },
  73. methods: {
  74. goBackList() {
  75. var pages = getCurrentPages()
  76. if (pages.length > 1) {
  77. uni.navigateBack()
  78. } else {
  79. uni.redirectTo({ url: '/pages/salon/list' })
  80. }
  81. },
  82. handleSubmit() {
  83. var name = (this.form.name || '').trim()
  84. var phone = (this.form.phone || '').trim()
  85. if (!name) {
  86. uni.showToast({ title: '请填写姓名', icon: 'none' })
  87. return
  88. }
  89. if (!/^1\d{10}$/.test(phone)) {
  90. uni.showToast({ title: '请填写正确的手机号', icon: 'none' })
  91. return
  92. }
  93. if (this.loading) return
  94. this.loading = true
  95. var self = this
  96. var payload = {
  97. salonId: self.form.salonId,
  98. name: name,
  99. phone: phone,
  100. inviteCode: (self.form.inviteCode || '').trim()
  101. }
  102. if (self.memberMode) {
  103. memberSalonRegister(payload).then(function(resp) {
  104. // 邀请链成单即消费 pending 邀请码(一次邀请链接对应首个报名转化)
  105. consumeInviteCode()
  106. uni.showToast({ title: '报名成功', icon: 'success' })
  107. setTimeout(function() {
  108. uni.redirectTo({ url: '/pages/salon/list' })
  109. }, 1200)
  110. }).catch(function(err) {
  111. uni.showToast({ title: (err && err.message) || '报名失败', icon: 'none' })
  112. }).finally(function() {
  113. self.loading = false
  114. })
  115. return
  116. }
  117. createSalonEnroll(payload).then(function(resp) {
  118. // 邀请链成单即消费 pending 邀请码(一次邀请链接对应首个报名转化)
  119. consumeInviteCode()
  120. uni.showToast({ title: '报名成功', icon: 'success' })
  121. setTimeout(function() {
  122. var enrollmentId = resp.data && resp.data.id ? resp.data.id : ''
  123. if (enrollmentId) {
  124. uni.redirectTo({ url: '/pages/pay/index?enrollmentId=' + enrollmentId })
  125. } else {
  126. uni.redirectTo({ url: '/pages/salon/list' })
  127. }
  128. }, 1200)
  129. }).catch(function(err) {
  130. uni.showToast({ title: (err && err.message) || '报名失败', icon: 'none' })
  131. }).finally(function() {
  132. self.loading = false
  133. })
  134. }
  135. }
  136. }
  137. </script>
  138. <style scoped>
  139. .form-page { min-height: 100vh; background: #F5FAFE; padding: 32rpx; }
  140. .section-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; }
  141. .section-title { display: block; font-size: 32rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 8rpx; border-left: 8rpx solid #2E6FA8; padding-left: 16rpx; }
  142. .card-desc { display: block; font-size: 26rpx; color: #3B5A78; margin-bottom: 32rpx; }
  143. .summary-box { background: #E8F3FC; border-radius: 8rpx; padding: 20rpx 24rpx; margin-bottom: 24rpx; border: 2rpx solid #C3D2DF; }
  144. .summary-row { display: flex; align-items: center; margin-bottom: 8rpx; }
  145. .summary-row:last-child { margin-bottom: 0; }
  146. .summary-label { font-size: 24rpx; color: #3B5A78; width: 140rpx; flex-shrink: 0; }
  147. .summary-value { font-size: 26rpx; color: #1E3A5F; font-weight: 600; flex: 1; }
  148. .form-item { margin-bottom: 24rpx; }
  149. .form-label { display: block; font-size: 26rpx; color: #3B5A78; font-weight: 500; margin-bottom: 12rpx; }
  150. .form-input { height: 72rpx; border: 2rpx solid #E3ECF4; border-radius: 8rpx; padding: 0 16rpx; font-size: 28rpx; color: #1E3A5F; background: #F5FAFE; }
  151. .submit-btn { width: 100%; height: 88rpx; line-height: 88rpx; background: #2E6FA8; color: #FFF; font-size: 30rpx; font-weight: 600; border-radius: 44rpx; border: none; margin-top: 24rpx; }
  152. .submit-btn:active { opacity: 0.85; }
  153. </style>