form.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view class="form-page">
  3. <view class="section-card">
  4. <text class="section-title">{{ memberMode ? '会员免费报名' : '沙龙报名' }}</text>
  5. <text class="card-desc">{{ memberMode ? '使用会员免费沙龙次数,报名成功即锁定名额' : '填写联系方式,完成支付后即可锁定名额' }}</text>
  6. <view class="summary-box" v-if="salonTitle">
  7. <view class="summary-row">
  8. <text class="summary-label">活动主题</text>
  9. <text class="summary-value">{{ salonTheme }} - {{ salonTitle }}</text>
  10. </view>
  11. </view>
  12. <view class="form-item">
  13. <text class="form-label">姓名</text>
  14. <input class="form-input" v-model="form.name" placeholder="请输入真实姓名" />
  15. </view>
  16. <view class="form-item">
  17. <text class="form-label">手机号</text>
  18. <input class="form-input" v-model="form.phone" type="number" maxlength="11" placeholder="请输入手机号" />
  19. </view>
  20. <view class="form-item" v-if="!memberMode">
  21. <text class="form-label">邀请码(选填)</text>
  22. <input class="form-input" v-model="form.inviteCode" placeholder="邀请码(选填)" />
  23. </view>
  24. <button class="submit-btn" @click="handleSubmit" :loading="loading" :disabled="loading">提交报名</button>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import { createSalonEnroll, memberSalonRegister } from '@/utils/api.js'
  30. import { guardPage } from '@/utils/guard.js'
  31. export default {
  32. data() {
  33. return {
  34. form: {
  35. salonId: '',
  36. name: '',
  37. phone: '',
  38. inviteCode: ''
  39. },
  40. salonTheme: '',
  41. salonTitle: '',
  42. memberMode: false,
  43. loading: false
  44. }
  45. },
  46. onLoad(options) {
  47. if (!guardPage()) return
  48. this.form.salonId = options && options.salonId ? options.salonId : ''
  49. this.salonTheme = options && options.theme ? decodeURIComponent(options.theme) : ''
  50. this.salonTitle = options && options.title ? decodeURIComponent(options.title) : ''
  51. this.form.name = options && options.name ? decodeURIComponent(options.name) : ''
  52. this.form.phone = options && options.phone ? decodeURIComponent(options.phone) : ''
  53. this.memberMode = options && options.member === '1'
  54. if (!this.form.salonId) {
  55. uni.showToast({ title: '参数错误', icon: 'none' })
  56. setTimeout(function() {
  57. uni.navigateBack({ delta: 1 })
  58. }, 1500)
  59. }
  60. },
  61. methods: {
  62. handleSubmit() {
  63. var name = (this.form.name || '').trim()
  64. var phone = (this.form.phone || '').trim()
  65. if (!name) {
  66. uni.showToast({ title: '请填写姓名', icon: 'none' })
  67. return
  68. }
  69. if (!/^1\d{10}$/.test(phone)) {
  70. uni.showToast({ title: '请填写正确的手机号', icon: 'none' })
  71. return
  72. }
  73. if (this.loading) return
  74. this.loading = true
  75. var self = this
  76. var payload = {
  77. salonId: self.form.salonId,
  78. name: name,
  79. phone: phone,
  80. inviteCode: (self.form.inviteCode || '').trim()
  81. }
  82. if (self.memberMode) {
  83. memberSalonRegister(payload).then(function(resp) {
  84. uni.showToast({ title: '报名成功', icon: 'success' })
  85. setTimeout(function() {
  86. uni.redirectTo({ url: '/pages/salon/list' })
  87. }, 1200)
  88. }).catch(function(err) {
  89. uni.showToast({ title: (err && err.message) || '报名失败', icon: 'none' })
  90. }).finally(function() {
  91. self.loading = false
  92. })
  93. return
  94. }
  95. createSalonEnroll(payload).then(function(resp) {
  96. uni.showToast({ title: '报名成功', icon: 'success' })
  97. setTimeout(function() {
  98. var enrollmentId = resp.data && resp.data.id ? resp.data.id : ''
  99. if (enrollmentId) {
  100. uni.redirectTo({ url: '/pages/pay/index?enrollmentId=' + enrollmentId })
  101. } else {
  102. uni.redirectTo({ url: '/pages/salon/list' })
  103. }
  104. }, 1200)
  105. }).catch(function(err) {
  106. uni.showToast({ title: (err && err.message) || '报名失败', icon: 'none' })
  107. }).finally(function() {
  108. self.loading = false
  109. })
  110. }
  111. }
  112. }
  113. </script>
  114. <style scoped>
  115. .form-page { min-height: 100vh; background: #F5F5F5; padding: 32rpx; }
  116. .section-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; }
  117. .section-title { display: block; font-size: 32rpx; font-weight: 700; color: #2A2326; margin-bottom: 8rpx; border-left: 8rpx solid #FC7A57; padding-left: 16rpx; }
  118. .card-desc { display: block; font-size: 26rpx; color: #5A4F4B; margin-bottom: 32rpx; }
  119. .summary-box { background: #FFF0E8; border-radius: 8rpx; padding: 20rpx 24rpx; margin-bottom: 24rpx; border: 2rpx solid #FED7AA; }
  120. .summary-row { display: flex; align-items: center; margin-bottom: 8rpx; }
  121. .summary-row:last-child { margin-bottom: 0; }
  122. .summary-label { font-size: 24rpx; color: #5A4F4B; width: 140rpx; flex-shrink: 0; }
  123. .summary-value { font-size: 26rpx; color: #2A2326; font-weight: 600; flex: 1; }
  124. .form-item { margin-bottom: 24rpx; }
  125. .form-label { display: block; font-size: 26rpx; color: #475569; font-weight: 500; margin-bottom: 12rpx; }
  126. .form-input { height: 72rpx; border: 2rpx solid #E2E8F0; border-radius: 8rpx; padding: 0 16rpx; font-size: 28rpx; color: #2A2326; background: #F8FAFC; }
  127. .submit-btn { width: 100%; height: 88rpx; line-height: 88rpx; background: #FC7A57; color: #FFF; font-size: 30rpx; font-weight: 600; border-radius: 44rpx; border: none; margin-top: 24rpx; }
  128. .submit-btn:active { opacity: 0.85; }
  129. </style>