index.vue 9.7 KB

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