index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <template>
  2. <view class="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">
  8. <!-- 邀请码输入 -->
  9. <view class="form-item">
  10. <text class="label">邀请码(可选)</text>
  11. <input
  12. class="input"
  13. v-model="formData.inviteCode"
  14. placeholder="输入邀请码可关联上级成长规划师"
  15. @blur="validateInviteCode"
  16. />
  17. <text class="hint" v-if="inviteCodeInfo">关联成长规划师:{{ inviteCodeInfo.guideName }}</text>
  18. </view>
  19. <!-- 真实姓名 -->
  20. <view class="form-item">
  21. <text class="label">真实姓名</text>
  22. <input
  23. class="input"
  24. v-model="formData.realName"
  25. placeholder="请输入真实姓名"
  26. />
  27. </view>
  28. <!-- 手机号 -->
  29. <view class="form-item">
  30. <text class="label">手机号</text>
  31. <input
  32. class="input"
  33. v-model="formData.phone"
  34. type="number"
  35. placeholder="请输入手机号"
  36. maxlength="11"
  37. />
  38. </view>
  39. <!-- 身份证号 -->
  40. <view class="form-item">
  41. <text class="label">身份证号</text>
  42. <input
  43. class="input"
  44. v-model="formData.idCard"
  45. placeholder="请输入身份证号"
  46. maxlength="18"
  47. />
  48. </view>
  49. <!-- 地址 -->
  50. <view class="form-item">
  51. <text class="label">联系地址</text>
  52. <input
  53. class="input"
  54. v-model="formData.address"
  55. placeholder="请输入联系地址"
  56. />
  57. </view>
  58. <!-- 银行卡号(选填) -->
  59. <view class="form-item">
  60. <text class="label">银行卡号 <text class="optional">(选填,用于佣金结算)</text></text>
  61. <input
  62. class="input"
  63. v-model="formData.bankCard"
  64. placeholder="请输入银行卡号"
  65. maxlength="30"
  66. />
  67. </view>
  68. <!-- 开户行(选填) -->
  69. <view class="form-item">
  70. <text class="label">开户行 <text class="optional">(选填)</text></text>
  71. <input
  72. class="input"
  73. v-model="formData.bankName"
  74. placeholder="请输入开户行名称,如:中国工商银行广州天河支行"
  75. />
  76. </view>
  77. <!-- 成长规划师认证信息(选填) -->
  78. <view class="section-divider">
  79. <text class="divider-text">成长规划师认证信息(选填)</text>
  80. </view>
  81. <!-- 成长规划师证书号 -->
  82. <view class="form-item">
  83. <text class="label">成长规划师证书号 <text class="optional">(选填)</text></text>
  84. <input
  85. class="input"
  86. v-model="formData.teacherNo"
  87. placeholder="如有成长规划师证书,请填写证书号"
  88. />
  89. </view>
  90. <!-- 成长规划师照片 -->
  91. <view class="form-item">
  92. <text class="label">成长规划师照片 <text class="optional">(选填)</text></text>
  93. <view class="upload-section">
  94. <image
  95. v-if="formData.teacherPhoto"
  96. :src="formData.teacherPhoto"
  97. class="preview-image"
  98. mode="aspectFill"
  99. @click="chooseImage('teacherPhoto')"
  100. />
  101. <view v-else class="upload-placeholder" @click="chooseImage('teacherPhoto')">
  102. <text class="upload-icon">📷</text>
  103. <text class="upload-text">上传照片</text>
  104. </view>
  105. </view>
  106. </view>
  107. <!-- 证书照片 -->
  108. <view class="form-item">
  109. <text class="label">证书照片 <text class="optional">(选填)</text></text>
  110. <view class="upload-section">
  111. <image
  112. v-if="formData.certificateImage"
  113. :src="formData.certificateImage"
  114. class="preview-image"
  115. mode="aspectFit"
  116. @click="chooseImage('certificateImage')"
  117. />
  118. <view v-else class="upload-placeholder" @click="chooseImage('certificateImage')">
  119. <text class="upload-icon">📷</text>
  120. <text class="upload-text">上传证书</text>
  121. </view>
  122. </view>
  123. </view>
  124. <!-- 提交按钮 -->
  125. <button class="btn-submit" :loading="submitting" :disabled="submitting" @click="submit">提交申请</button>
  126. </view>
  127. </view>
  128. </template>
  129. <script>
  130. import { registerGuide, validateInviteCode } from '../../../utils/api.js'
  131. import { pickImage } from '@/utils/image-picker.js'
  132. import fontScaleMixin from '@/mixins/font-scale.js'
  133. export default {
  134. mixins: [fontScaleMixin],
  135. onLoad() {
  136. uni.redirectTo({ url: '/pages/profile/service-role-apply' })
  137. },
  138. data() {
  139. return {
  140. formData: {
  141. inviteCode: '',
  142. realName: '',
  143. phone: '',
  144. idCard: '',
  145. address: '',
  146. bankCard: '',
  147. bankName: '',
  148. teacherNo: '',
  149. teacherPhoto: '',
  150. certificateImage: ''
  151. },
  152. inviteCodeInfo: null,
  153. submitting: false
  154. }
  155. },
  156. onLoad(options) {
  157. // 如果有邀请码参数,自动填充
  158. if (options.inviteCode) {
  159. this.formData.inviteCode = options.inviteCode
  160. this.validateInviteCode()
  161. }
  162. },
  163. methods: {
  164. async validateInviteCode() {
  165. if (!this.formData.inviteCode) {
  166. this.inviteCodeInfo = null
  167. return
  168. }
  169. try {
  170. const res = await validateInviteCode(this.formData.inviteCode)
  171. if (res.code === 200) {
  172. this.inviteCodeInfo = res.data
  173. uni.showToast({
  174. title: '邀请码有效',
  175. icon: 'success'
  176. })
  177. } else {
  178. this.inviteCodeInfo = null
  179. uni.showToast({
  180. title: '邀请码无效',
  181. icon: 'none'
  182. })
  183. }
  184. } catch (e) {
  185. this.inviteCodeInfo = null
  186. uni.showToast({
  187. title: '验证失败',
  188. icon: 'none'
  189. })
  190. }
  191. },
  192. chooseImage(field) {
  193. pickImage({
  194. count: 1,
  195. sizeType: ['compressed'],
  196. sourceType: ['album', 'camera'],
  197. success: (res) => {
  198. const tempFilePath = res.tempFilePaths[0]
  199. this.uploadImage(field, tempFilePath)
  200. }
  201. })
  202. },
  203. uploadImage(field, filePath) {
  204. uni.showLoading({ title: '上传中...' })
  205. // TODO: 实际应该上传到服务器
  206. // 这里简化处理,直接使用本地路径
  207. setTimeout(() => {
  208. this.formData[field] = filePath
  209. uni.hideLoading()
  210. uni.showToast({
  211. title: '上传成功',
  212. icon: 'success'
  213. })
  214. }, 1000)
  215. },
  216. async submit() {
  217. if (this.submitting) return
  218. // 验证表单
  219. if (!this.formData.realName) {
  220. uni.showToast({ title: '请输入真实姓名', icon: 'none' })
  221. return
  222. }
  223. if (!this.formData.phone) {
  224. uni.showToast({ title: '请输入手机号', icon: 'none' })
  225. return
  226. }
  227. if (!this.formData.idCard) {
  228. uni.showToast({ title: '请输入身份证号', icon: 'none' })
  229. return
  230. }
  231. this.submitting = true
  232. uni.showLoading({ title: '提交中...' })
  233. try {
  234. const userId = uni.getStorageSync('userId')
  235. const res = await registerGuide({
  236. userId: userId,
  237. ...this.formData
  238. })
  239. if (res.code === 200) {
  240. uni.showModal({
  241. title: '申请成功',
  242. content: '您的成长规划师申请已提交,请等待审核',
  243. showCancel: false,
  244. success: () => {
  245. uni.navigateBack()
  246. }
  247. })
  248. } else {
  249. uni.showToast({
  250. title: res.message || '提交失败',
  251. icon: 'none'
  252. })
  253. }
  254. } catch (e) {
  255. uni.showToast({
  256. title: '提交失败',
  257. icon: 'none'
  258. })
  259. } finally {
  260. this.submitting = false
  261. uni.hideLoading()
  262. }
  263. }
  264. }
  265. }
  266. </script>
  267. <style scoped lang="scss">
  268. .container {
  269. padding: $uni-space-page;
  270. background: $facade-fill-page;
  271. min-height: 100vh;
  272. }
  273. .header {
  274. text-align: center;
  275. padding: 60rpx 0 40rpx;
  276. }
  277. .title {
  278. font-size: calc(48rpx * var(--font-scale, 1));
  279. font-weight: bold;
  280. color: $facade-text-strong;
  281. display: block;
  282. margin-bottom: 20rpx;
  283. }
  284. .subtitle {
  285. font-size: calc(28rpx * var(--font-scale, 1));
  286. color: $facade-text-body;
  287. }
  288. .form {
  289. background: $app-surface;
  290. border-radius: 24rpx;
  291. padding: 40rpx;
  292. }
  293. .form-item {
  294. margin-bottom: 40rpx;
  295. }
  296. .label {
  297. font-size: calc(28rpx * var(--font-scale, 1));
  298. color: $facade-text-strong;
  299. display: block;
  300. margin-bottom: 20rpx;
  301. font-weight: bold;
  302. }
  303. .input {
  304. width: 100%;
  305. height: 80rpx;
  306. border: 1rpx solid $facade-hairline;
  307. border-radius: 8rpx;
  308. padding: 0 20rpx;
  309. font-size: calc(28rpx * var(--font-scale, 1));
  310. }
  311. .hint {
  312. font-size: calc(24rpx * var(--font-scale, 1));
  313. color: $brand-primary;
  314. margin-top: 10rpx;
  315. display: block;
  316. }
  317. .optional {
  318. font-size: calc(24rpx * var(--font-scale, 1));
  319. color: $facade-text-muted;
  320. font-weight: normal;
  321. }
  322. .section-divider {
  323. margin: 20rpx 0 $uni-space-lg;
  324. padding: 20rpx 0;
  325. border-top: 1rpx solid $facade-fill;
  326. }
  327. .divider-text {
  328. font-size: calc(26rpx * var(--font-scale, 1));
  329. color: $facade-text-muted;
  330. }
  331. .upload-section {
  332. display: flex;
  333. align-items: center;
  334. }
  335. .preview-image {
  336. width: 200rpx;
  337. height: 200rpx;
  338. border-radius: 8rpx;
  339. object-fit: cover;
  340. }
  341. .upload-placeholder {
  342. width: 200rpx;
  343. height: 200rpx;
  344. border: 2rpx dashed $facade-hairline;
  345. border-radius: 8rpx;
  346. display: flex;
  347. flex-direction: column;
  348. align-items: center;
  349. justify-content: center;
  350. background: $facade-fill-page;
  351. }
  352. .upload-icon {
  353. font-size: calc($uni-font-size-4xl * var(--font-scale, 1));
  354. margin-bottom: 10rpx;
  355. }
  356. .upload-text {
  357. font-size: calc(24rpx * var(--font-scale, 1));
  358. color: $facade-text-muted;
  359. }
  360. .btn-submit {
  361. width: 100%;
  362. height: 90rpx;
  363. background: linear-gradient(135deg, $accent-indigo 0%, $accent-indigo-deep 100%);
  364. color: $app-surface;
  365. border-radius: 24rpx;
  366. font-size: calc(32rpx * var(--font-scale, 1));
  367. font-weight: bold;
  368. margin-top: 40rpx;
  369. }
  370. </style>