join-form.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <view class="join-form-container" :style="{ '--font-scale': fontScale }">
  3. <view class="header">
  4. <text class="title">加入家庭</text>
  5. <text class="subtitle">请填写您的真实姓名,提交后等待邀请人确认</text>
  6. </view>
  7. <view class="form-section">
  8. <!-- 真实姓名(必填) -->
  9. <view class="form-item">
  10. <text class="label">真实姓名 <text class="required">*</text></text>
  11. <input type="text" v-model="form.realName" placeholder="请输入真实姓名" class="input" maxlength="20" />
  12. </view>
  13. <!-- 昵称(选填,默认用户+手机尾号) -->
  14. <view class="form-item">
  15. <text class="label">昵称</text>
  16. <input type="text" v-model="form.nickname" placeholder="选填,默认:用户+手机尾号" class="input" maxlength="20" />
  17. </view>
  18. <!-- 头像(选填) -->
  19. <view class="form-item">
  20. <text class="label">头像</text>
  21. <view class="avatar-upload" @click="chooseAvatar">
  22. <image v-if="form.avatar" :src="form.avatar" class="avatar-preview" mode="aspectFill"></image>
  23. <view v-else class="avatar-placeholder">
  24. <text class="plus-icon">+</text>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="actions">
  30. <button class="btn-primary" @click="submit" :loading="submitting" :disabled="submitting">
  31. <text v-if="submitting">提交中...</text>
  32. <text v-else>提交加入申请</text>
  33. </button>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import { updateUserInfo, requestJoinByCode } from '@/utils/api.js'
  39. import { pickImage } from '@/utils/image-picker.js'
  40. import fontScaleMixin from '@/mixins/font-scale.js'
  41. export default {
  42. mixins: [fontScaleMixin],
  43. data() {
  44. return {
  45. familyInviteCode: '',
  46. form: {
  47. realName: '',
  48. nickname: '',
  49. avatar: ''
  50. },
  51. submitting: false
  52. }
  53. },
  54. onLoad(options) {
  55. // 接收家庭邀请码:join.vue 传 familyInviteCode;登录页衔接传 pendingFamilyInviteCode 对应值
  56. var code = (options && options.familyInviteCode) || uni.getStorageSync('pendingFamilyInviteCode') || ''
  57. this.familyInviteCode = code
  58. if (code) {
  59. uni.setStorageSync('pendingFamilyInviteCode', code)
  60. }
  61. // 已有资料预填(如有昵称/头像/真实姓名则带出)
  62. this.prefill()
  63. },
  64. methods: {
  65. prefill() {
  66. var userInfo = uni.getStorageSync('userInfo') || {}
  67. if (userInfo.realName) this.form.realName = userInfo.realName
  68. if (userInfo.nickname) this.form.nickname = userInfo.nickname
  69. if (userInfo.avatar) this.form.avatar = userInfo.avatar
  70. },
  71. chooseAvatar() {
  72. var self = this
  73. pickImage({
  74. count: 1,
  75. success: function(res) {
  76. self.form.avatar = res.tempFilePaths[0]
  77. }
  78. })
  79. },
  80. async submit() {
  81. if (this.submitting) return
  82. if (!this.form.realName || !this.form.realName.trim()) {
  83. uni.showToast({ title: '请输入真实姓名', icon: 'none' })
  84. return
  85. }
  86. if (!this.familyInviteCode) {
  87. uni.showToast({ title: '缺少家庭邀请码', icon: 'none' })
  88. return
  89. }
  90. this.submitting = true
  91. try {
  92. // 先保存基本信息(真实姓名/昵称/头像),失败不阻塞加入申请
  93. try {
  94. await updateUserInfo({
  95. realName: this.form.realName.trim(),
  96. nickname: this.form.nickname ? this.form.nickname.trim() : '',
  97. avatar: this.form.avatar
  98. })
  99. } catch (e) {
  100. console.log('[join-form] 保存基本信息失败,继续提交加入申请', e)
  101. }
  102. // 提交加入家庭申请(身份由邀请人审批时指定,不再自填)
  103. await requestJoinByCode(this.familyInviteCode)
  104. uni.removeStorageSync('pendingFamilyInviteCode')
  105. uni.showToast({ title: '加入家庭申请已提交,等待邀请人确认', icon: 'success' })
  106. setTimeout(function() {
  107. uni.reLaunch({ url: '/pages/index-home/index' })
  108. }, 1500)
  109. } catch (e) {
  110. uni.showToast({ title: (e && e.message) || '提交失败', icon: 'none' })
  111. } finally {
  112. this.submitting = false
  113. }
  114. }
  115. }
  116. }
  117. </script>
  118. <style scoped lang="scss">
  119. .join-form-container {
  120. min-height: 100vh;
  121. background: $facade-fill-2;
  122. padding: $uni-space-page;
  123. box-sizing: border-box;
  124. }
  125. .header {
  126. margin-bottom: 40rpx;
  127. text-align: center;
  128. }
  129. .title {
  130. font-size: calc(40rpx * var(--font-scale, 1));
  131. font-weight: bold;
  132. color: $facade-text-strong;
  133. display: block;
  134. margin-bottom: 10rpx;
  135. }
  136. .subtitle {
  137. font-size: calc(26rpx * var(--font-scale, 1));
  138. color: $facade-text-muted;
  139. line-height: 1.6;
  140. display: block;
  141. }
  142. .form-section {
  143. background: $app-surface;
  144. border-radius: 16rpx;
  145. padding: $uni-space-page;
  146. margin-bottom: $uni-space-lg;
  147. }
  148. .form-item {
  149. margin-bottom: 40rpx;
  150. }
  151. .form-item:last-child {
  152. margin-bottom: 0;
  153. }
  154. .label {
  155. display: block;
  156. font-size: calc(28rpx * var(--font-scale, 1));
  157. color: $facade-text-strong;
  158. margin-bottom: 16rpx;
  159. }
  160. .required {
  161. color: $mat-red;
  162. }
  163. .input, .picker-input {
  164. padding: 28rpx 24rpx;
  165. background: $facade-fill-2;
  166. border-radius: 16rpx;
  167. font-size: calc(30rpx * var(--font-scale, 1));
  168. box-sizing: border-box;
  169. width: 100%;
  170. min-height: 96rpx;
  171. line-height: 1.4;
  172. }
  173. .avatar-upload {
  174. width: 150rpx;
  175. height: 150rpx;
  176. }
  177. .avatar-preview {
  178. width: 150rpx;
  179. height: 150rpx;
  180. border-radius: 50%;
  181. }
  182. .avatar-placeholder {
  183. width: 150rpx;
  184. height: 150rpx;
  185. background: $facade-fill-2;
  186. border-radius: 50%;
  187. display: flex;
  188. align-items: center;
  189. justify-content: center;
  190. }
  191. .plus-icon {
  192. font-size: calc($uni-font-size-4xl * var(--font-scale, 1));
  193. color: $facade-text-ghost;
  194. }
  195. .actions {
  196. padding-bottom: 40rpx;
  197. }
  198. .btn-primary {
  199. background: $mat-green;
  200. color: $app-surface;
  201. border-radius: 24rpx;
  202. font-size: calc(30rpx * var(--font-scale, 1));
  203. display: flex;
  204. align-items: center;
  205. justify-content: center;
  206. padding: 24rpx 0;
  207. }
  208. </style>