service-role-apply.vue 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  1. <template>
  2. <view class="page" :style="{ '--font-scale': fontScale }">
  3. <!-- 审核状态展示 -->
  4. <view v-if="showStatusView" class="status-view">
  5. <view class="status-card" :class="'status-' + applyStatus">
  6. <view class="status-icon">{{ statusIcon }}</view>
  7. <text class="status-title">{{ statusTitle }}</text>
  8. <text class="status-desc">{{ statusDesc }}</text>
  9. </view>
  10. <view v-if="applyStatus === 'pending'" class="status-tip">
  11. <text>预计 1-3 个工作日内完成审核,请耐心等待</text>
  12. </view>
  13. <view v-if="applyStatus === 'rejected'" class="reject-info">
  14. <text class="reject-label">拒绝原因</text>
  15. <text class="reject-reason">{{ applyRecord && applyRecord.rejectReason }}</text>
  16. </view>
  17. <!-- P1 补绑入口:记录已存在(status 0/1/2)、表单隐藏后,绑定失败时唯一可达的就地补绑路径。
  18. @click 直连 bindUserReferral,绝不接 handleSubmit/doSubmit(表单隐藏 + 后端查重 ServiceImpl:74-76 会拒)。 -->
  19. <view v-if="!userRefBound && inviteRefCode" class="rebind-section">
  20. <text class="rebind-desc">推荐人尚未绑定成功,请在网络稳定后补绑</text>
  21. <button class="btn-rebind" :disabled="bindingRef" @click="bindUserReferral">补绑推荐人</button>
  22. </view>
  23. <view class="action-buttons">
  24. <button v-if="applyStatus === 'rejected'" class="btn-reapply" @click="handleReapply">
  25. 重新申请
  26. </button>
  27. <button v-if="applyStatus === 'approved'" class="btn-center" @click="goToCenter">
  28. 进入服务商中心
  29. </button>
  30. <button v-if="applyStatus === 'approved'" class="btn-add-role" @click="handleAddRole">
  31. 申请其他角色
  32. </button>
  33. <button class="btn-back" @click="goBack">返回首页</button>
  34. </view>
  35. </view>
  36. <!-- 申请表单 -->
  37. <view v-else class="form-wrap">
  38. <view v-if="hasApprovedRole" class="multi-role-hint">
  39. <text>📌 您当前已是 {{ approvedRoleLabel }},可勾选下方新增其他角色</text>
  40. </view>
  41. <view class="header">
  42. <text class="title">服务角色申请</text>
  43. <text class="subtitle">选择申请角色,提交资质信息</text>
  44. </view>
  45. <view class="section">
  46. <view class="section-title">选择申请角色 <text class="required">*</text></view>
  47. <!-- 严格三列:roleRows 每行固定 3 个单元格,flex:1 等分,不依赖 calc/gap -->
  48. <view class="role-grid">
  49. <view
  50. v-for="(row, rowIdx) in roleRows"
  51. :key="getRoleRowKey(rowIdx)"
  52. class="role-row"
  53. >
  54. <view
  55. v-for="role in row"
  56. :key="role.key"
  57. class="role-cell"
  58. >
  59. <view
  60. v-if="!role.placeholder"
  61. class="role-card"
  62. :class="{ selected: selectedRoles.indexOf(role.key) > -1, approved: isApprovedRole(role.key) }"
  63. @click="toggleRole(role.key)"
  64. >
  65. <text class="role-icon">{{ role.icon }}</text>
  66. <text class="role-name">{{ role.name }}</text>
  67. <view v-if="isApprovedRole(role.key)" class="approved-badge">已通过</view>
  68. <view v-else-if="selectedRoles.indexOf(role.key) > -1" class="check-mark">✓</view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. <view class="section">
  75. <view class="section-title">身份证信息</view>
  76. <input class="input" v-model="form.idCard" placeholder="请输入身份证号码" maxlength="18" />
  77. <view class="upload-row">
  78. <view class="upload-item" @click="chooseIdCardImage('front')">
  79. <image v-if="form.idCardFront" :src="form.idCardFront" mode="aspectFill" class="upload-preview" />
  80. <view v-else class="upload-placeholder">
  81. <text class="upload-icon">+</text>
  82. <text class="upload-label">身份证正面</text>
  83. </view>
  84. </view>
  85. <view class="upload-item" @click="chooseIdCardImage('back')">
  86. <image v-if="form.idCardBack" :src="form.idCardBack" mode="aspectFill" class="upload-preview" />
  87. <view v-else class="upload-placeholder">
  88. <text class="upload-icon">+</text>
  89. <text class="upload-label">身份证反面</text>
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. <view class="section">
  95. <view class="section-title">资质证书</view>
  96. <view class="cert-list">
  97. <view v-for="(img, idx) in form.certificateImages" :key="getCertKey(idx)" class="cert-item">
  98. <image :src="img" mode="aspectFill" class="cert-preview" />
  99. <text class="cert-del" @click="removeCert(idx)">×</text>
  100. </view>
  101. <view class="cert-add" @click="chooseCertificate">
  102. <text class="upload-icon">+</text>
  103. <text class="upload-label">添加证书</text>
  104. </view>
  105. </view>
  106. </view>
  107. <view class="section">
  108. <view class="section-title">联系地址 <text class="required">*</text></view>
  109. <view class="address-row" @click="openAddressPicker">
  110. <text class="address-label">所在地区</text>
  111. <view class="address-value-wrap">
  112. <text v-if="addressText" class="address-value">{{ addressText }}</text>
  113. <text v-else class="address-placeholder">请选择省市区街道</text>
  114. <text class="address-arrow">›</text>
  115. </view>
  116. </view>
  117. <input class="input" v-model="form.addressDetail" placeholder="详细地址(门牌号等)" />
  118. <!-- 与收件人地址共用同一组件 components/address-picker.vue -->
  119. <AddressPicker ref="addressPicker" :show-trigger="false" @change="onAddressChange" />
  120. </view>
  121. <button class="submit-btn" :disabled="submitting" @click="handleSubmit">
  122. {{ submitting ? '提交中...' : '提交申请' }}
  123. </button>
  124. <view class="footer-hint">
  125. <text>提交后将在 1-3 个工作日内完成审核</text>
  126. </view>
  127. </view>
  128. <!-- 团队邀请:未登录提交时就地弹出登录浮层,登录后自动续提交。
  129. 用本地浮层而非 401 → reLaunch 整页登录,是为了不销毁本组件:
  130. 表单已填数据、inviteRefCode 均保留,登录后回到表单且不丢码。
  131. login-sheet 由 main.js 全局注册;全局 loginSheetMixin 的 openLoginSheet 会命中本 ref。 -->
  132. <login-sheet ref="loginSheet" @success="onInviteLoginSuccess" @close="onInviteLoginClose" />
  133. </view>
  134. </template>
  135. <script>
  136. import { submitServiceRoleApply, getMyServiceRoleApply, uploadServiceRoleImage, bindReferralIfNotSelf } from '../../utils/api'
  137. import { pickImage } from '../../utils/image-picker.js'
  138. import AddressPicker from '@/components/address-picker.vue'
  139. import fontScaleMixin from '@/mixins/font-scale.js'
  140. export default {
  141. mixins: [fontScaleMixin],
  142. components: { AddressPicker },
  143. data() {
  144. return {
  145. roleList: [
  146. { key: 'planner', name: '规划师', icon: '📋' },
  147. { key: 'nutritionist', name: '营养师', icon: '🥗' },
  148. { key: 'butler', name: '管家', icon: '🔔' },
  149. { key: 'vendor', name: '服务商', icon: '🏪' },
  150. { key: 'article_admin', name: '文章管理员', icon: '📝' },
  151. { key: 'activity_provider', name: '活动提供商', icon: '🎪' }
  152. ],
  153. selectedRoles: [],
  154. addressText: '',
  155. form: {
  156. idCard: '',
  157. idCardFront: '',
  158. idCardBack: '',
  159. certificateImages: [],
  160. province: '',
  161. city: '',
  162. district: '',
  163. street: '',
  164. addressDetail: ''
  165. },
  166. submitting: false,
  167. applyRecord: null,
  168. showStatusView: false,
  169. // 团队邀请:直达链接 /pages/profile/service-role-apply?refCode=xxx 携带的邀请码(记录级归属)。
  170. // 用户级推荐人链路的 storage.refCode 会被 user-edit.vue:733 消费并清除,绝不能复用;
  171. // 故记录级另存独立 key 'serviceRoleApplyRefCode',与用户级彻底解耦、并存互不覆盖。
  172. // 本组件字段用于常规提交;若未登录触发整页登录导致组件销毁,登录后回跳无参时由
  173. // onLoad 从独立 key 恢复本字段,保证 refCode 端到端不丢。
  174. inviteRefCode: '',
  175. // 独立 storage key:记录级归属专用,不会被 user-edit 的用户级消费逻辑清除
  176. inviteRefCodeStorageKey: 'serviceRoleApplyRefCode',
  177. // 未登录点提交后挂起:浮层登录成功回调里续跑提交,避免用户二次点击
  178. pendingSubmitAfterLogin: false,
  179. // 用户级推荐人绑定幂等标记(资产一致性):整个流程至多成功绑定一次。
  180. // bindReferralIfNotSelf 成功(含自邀 skipped:true)才置 true;首次失败保持 false 以便重试补绑。
  181. // handleReapply/handleAddRole 多次提交不重置它,避免重复走 /api/invite/bind 重复发 F24 CF 资产、
  182. // 或触发后端 CommissionService:140「已绑定推荐人,不可修改」误报错。
  183. userRefBound: false,
  184. // 绑定请求防重入锁:避免失败重试弹窗连点「重试绑定」导致并发 bind 请求
  185. bindingRef: false
  186. }
  187. },
  188. computed: {
  189. // 按每行 3 个拆分行;最后一行不足 3 个用空占位单元格补齐,保证各行严格三列等宽
  190. roleRows() {
  191. const rows = []
  192. const list = this.roleList || []
  193. const total = Math.ceil(list.length / 3) * 3
  194. for (let i = 0; i < total; i += 3) {
  195. const row = []
  196. for (let j = 0; j < 3; j++) {
  197. const item = list[i + j]
  198. row.push(
  199. item
  200. ? item
  201. : { key: 'role-placeholder-' + i + '-' + j, name: '', icon: '', placeholder: true }
  202. )
  203. }
  204. rows.push(row)
  205. }
  206. return rows
  207. },
  208. applyStatus() {
  209. if (!this.applyRecord) return 'none'
  210. const s = this.applyRecord.status
  211. return s === 0 ? 'pending' : s === 1 ? 'approved' : 'rejected'
  212. },
  213. hasApprovedRole() {
  214. return this.applyRecord && this.applyRecord.status === 1
  215. },
  216. // 已通过审核的角色集合(key 数组)——这些角色已开通,不可重复勾选
  217. approvedRoles() {
  218. if (!this.applyRecord || this.applyRecord.status !== 1 || !this.applyRecord.roles) return []
  219. try {
  220. const roles = JSON.parse(this.applyRecord.roles)
  221. return Array.isArray(roles) ? roles : []
  222. } catch (e) { return [] }
  223. },
  224. approvedRoleLabel() {
  225. if (!this.applyRecord || !this.applyRecord.roles) return ''
  226. try {
  227. const roles = JSON.parse(this.applyRecord.roles)
  228. // 取第一个角色名称作为展示
  229. const roleMap = { planner: '规划师', nutritionist: '营养师', butler: '管家', vendor: '服务商', article_admin: '文章管理员', activity_provider: '活动提供商' }
  230. return roles.map(r => roleMap[r] || r).join('、') || '服务商'
  231. } catch (e) { return '服务商' }
  232. },
  233. statusIcon() {
  234. return { pending: '⏳', approved: '✅', rejected: '❌' }[this.applyStatus] || '📋'
  235. },
  236. statusTitle() {
  237. return { pending: '审核中', approved: '申请已通过', rejected: '申请被驳回' }[this.applyStatus] || ''
  238. },
  239. statusDesc() {
  240. return {
  241. pending: '您的申请正在审核中,请留意消息通知',
  242. approved: '已开通服务商身份,可继续申请其他服务角色',
  243. rejected: '您的申请未通过审核,可查看原因后重新提交'
  244. }[this.applyStatus] || ''
  245. }
  246. },
  247. onLoad(options) {
  248. // 团队邀请:解析直达链接的邀请码,存组件字段 + 独立 storage key(记录级归属专用)。
  249. // 不用 storage.refCode:那是「用户级推荐人」链路(App.vue 捕获→user-edit.vue:733 消费并清除),
  250. // 与记录级彻底解耦、互不覆盖。
  251. if (options && options.refCode) {
  252. this.inviteRefCode = options.refCode
  253. uni.setStorageSync(this.inviteRefCodeStorageKey, options.refCode)
  254. } else {
  255. // 未登录提交触发整页登录 / 401 reLaunch 时组件会被销毁;登录成功回跳若不带 refCode 参数,
  256. // 从独立 key 恢复,确保「登录后回到表单且 inviteRefCode 不丢」。
  257. var cached = uni.getStorageSync(this.inviteRefCodeStorageKey)
  258. if (cached) this.inviteRefCode = cached
  259. }
  260. this.checkExistingApply()
  261. },
  262. methods: {
  263. // 模板里不能直接调用 uni.*(渲染时实例上没有 uni,会报
  264. // "Property or method uni is not defined"),统一收进方法
  265. goBack() {
  266. var pages = getCurrentPages()
  267. if (pages && pages.length > 1) {
  268. uni.navigateBack()
  269. } else {
  270. uni.switchTab({ url: '/pages/index/index' })
  271. }
  272. },
  273. async checkExistingApply() {
  274. try {
  275. const res = await getMyServiceRoleApply()
  276. if (res.code === 200 && res.data) {
  277. this.applyRecord = res.data
  278. // 身份证预填:原申请记录里已上传的身份证不再要求重传
  279. this.prefillIdCard(this.applyRecord)
  280. const status = res.data.status
  281. if (status === 0) {
  282. // 审核中,展示进度
  283. this.showStatusView = true
  284. } else if (status === 1) {
  285. // 已通过:不再强制跳转,显示当前身份卡片 + 允许申请其他角色
  286. this.showStatusView = true
  287. } else if (status === 2) {
  288. // 已拒绝,显示原因
  289. this.showStatusView = true
  290. }
  291. }
  292. } catch (e) {
  293. // 无申请记录,显示表单
  294. }
  295. },
  296. // 从历史申请记录回填身份证号码与正反面图片(已上传过则不再要求重传)
  297. prefillIdCard(record) {
  298. if (!record) return
  299. if (record.idCard) this.form.idCard = record.idCard
  300. if (record.idCardImages) {
  301. try {
  302. const imgs = JSON.parse(record.idCardImages)
  303. if (Array.isArray(imgs) && imgs.length) {
  304. if (imgs[0]) this.form.idCardFront = imgs[0]
  305. if (imgs[1]) this.form.idCardBack = imgs[1]
  306. }
  307. } catch (e) {}
  308. }
  309. },
  310. toggleRole(key) {
  311. // 已通过审核的角色不可重复申请(不可勾选)
  312. if (this.approvedRoles.indexOf(key) > -1) {
  313. uni.showToast({ title: '该角色已开通,无需重复申请', icon: 'none' })
  314. return
  315. }
  316. const idx = this.selectedRoles.indexOf(key)
  317. if (idx > -1) {
  318. this.selectedRoles.splice(idx, 1)
  319. } else {
  320. this.selectedRoles.push(key)
  321. }
  322. },
  323. isApprovedRole(key) {
  324. return this.approvedRoles.indexOf(key) > -1
  325. },
  326. chooseIdCardImage(side) {
  327. pickImage({
  328. count: 1,
  329. sizeType: ['compressed'],
  330. sourceType: ['album', 'camera'],
  331. success: async (res) => {
  332. uni.showLoading({ title: '上传中...' })
  333. try {
  334. const uploadRes = await uploadServiceRoleImage(res.tempFilePaths[0])
  335. uni.hideLoading()
  336. if (uploadRes.code === 200) {
  337. if (side === 'front') {
  338. this.form.idCardFront = uploadRes.data.url
  339. } else {
  340. this.form.idCardBack = uploadRes.data.url
  341. }
  342. uni.showToast({ title: '上传成功', icon: 'success' })
  343. } else {
  344. uni.showToast({ title: uploadRes.message || '上传失败', icon: 'none' })
  345. }
  346. } catch (e) {
  347. uni.hideLoading()
  348. uni.showToast({ title: '上传失败', icon: 'none' })
  349. }
  350. }
  351. })
  352. },
  353. async chooseCertificate() {
  354. pickImage({
  355. count: 9 - this.form.certificateImages.length,
  356. sizeType: ['compressed'],
  357. sourceType: ['album', 'camera'],
  358. success: async (res) => {
  359. uni.showLoading({ title: '上传中...' })
  360. try {
  361. for (const filePath of res.tempFilePaths) {
  362. const uploadRes = await uploadServiceRoleImage(filePath)
  363. if (uploadRes.code === 200) {
  364. this.form.certificateImages.push(uploadRes.data.url)
  365. }
  366. }
  367. uni.hideLoading()
  368. uni.showToast({ title: '上传成功', icon: 'success' })
  369. } catch (e) {
  370. uni.hideLoading()
  371. uni.showToast({ title: '上传失败', icon: 'none' })
  372. }
  373. }
  374. })
  375. },
  376. removeCert(idx) {
  377. this.form.certificateImages.splice(idx, 1)
  378. },
  379. getCertKey(idx) {
  380. return 'cert-' + idx
  381. },
  382. getRoleRowKey(rowIdx) {
  383. return 'role-row-' + rowIdx
  384. },
  385. openAddressPicker() {
  386. if (this.$refs.addressPicker) {
  387. this.$refs.addressPicker.open()
  388. }
  389. },
  390. onAddressChange(e) {
  391. this.form.province = e.province || ''
  392. this.form.city = e.city || ''
  393. this.form.district = e.district || ''
  394. this.form.street = e.street || ''
  395. this.addressText = e.fullName || ''
  396. },
  397. async handleSubmit() {
  398. // 提交前过滤已通过角色(防御:仅提交新增角色,不重复申请已开通角色)
  399. const newRoles = (this.selectedRoles || []).filter(r => this.approvedRoles.indexOf(r) === -1)
  400. if (newRoles.length === 0) {
  401. uni.showToast({ title: '请至少选择一个新增角色', icon: 'none' })
  402. return
  403. }
  404. if (!this.form.idCardFront || !this.form.idCardBack) {
  405. uni.showToast({ title: '请上传身份证正反面照片', icon: 'none' })
  406. return
  407. }
  408. if (!this.form.province) {
  409. uni.showToast({ title: '请选择联系地址', icon: 'none' })
  410. return
  411. }
  412. // 团队邀请:未登录时先就地弹登录浮层,登录后自动续提交。
  413. // 不走接口层 401 → reLaunch 整页登录的原因:那会销毁本组件、丢失已填表单与 inviteRefCode,
  414. // 且登录成功后回不到本表单。就地浮层由本页 <login-sheet> 承载,组件不销毁。
  415. if (!uni.getStorageSync('token')) {
  416. this.pendingSubmitAfterLogin = true
  417. // refCode 一并透传给浮层:未登录态 App.vue 已把分享码存入用户级 storage.refCode,
  418. // 这里再以 options.refCode 覆盖同源值(互不冲突),用户级 referrerId 仍由现状链路消费。
  419. this.openLoginSheet({ refCode: this.inviteRefCode })
  420. return
  421. }
  422. // 资产一致性(P0,串行):记录级 doSubmit 必须先执行并确认成功,之后才触发用户级绑定。
  423. // doSubmit 失败(邀请码无效/查重拒绝/网络失败)会返回 false 并自行 toast,绝不进入绑定、
  424. // 绝不给邀请人发 F24 CF 资产;也绝不让绑定链路的空 catch 吞掉 doSubmit 的失败。
  425. var submitted = await this.doSubmit(newRoles)
  426. if (submitted) {
  427. await this.bindUserReferral()
  428. }
  429. },
  430. // 就地浮层登录成功回调:自动续跑被挂起的提交(此时 token 已写入 storage)。
  431. // 就地浮层登录不走 user-edit.vue:714 的推荐人消费点、也不触发 App.vue onShow 带参补绑,
  432. // 故本页在「记录级申请成功」后主动补绑一次用户级推荐人(product 裁决:用户级走完整分销链路、
  433. // 发 F24 CF 值是接受的语义)。绑定制约:①仅在 doSubmit 成功后串行触发,失败绝不发资产;
  434. // ②与 user-edit 路径互斥受 userRefBound 幂等标记保护,整个流程至多成功一次,不重复发资产。
  435. async onInviteLoginSuccess() {
  436. if (!this.pendingSubmitAfterLogin) return
  437. this.pendingSubmitAfterLogin = false
  438. const newRoles = (this.selectedRoles || []).filter(r => this.approvedRoles.indexOf(r) === -1)
  439. // 资产一致性(P0,串行):与已登录路径完全同构。先确认记录级申请成功,再绑定用户级推荐人。
  440. // doSubmit 失败返回 false 并自行 toast,绝不进入绑定、绝不给邀请人发 CF 资产。
  441. var submitted = await this.doSubmit(newRoles)
  442. if (submitted) {
  443. await this.bindUserReferral()
  444. }
  445. },
  446. // 浮层关闭(含「暂不登录先逛逛」handleSkipLogin):复位挂起标记,
  447. // 避免用户放弃登录后标记残留,导致下次提交误走自动续提交分支。
  448. onInviteLoginClose() {
  449. this.pendingSubmitAfterLogin = false
  450. },
  451. // 用户级推荐人绑定(资产一致性核心 P0/P1)。
  452. // 前置:仅由「记录级 doSubmit 成功」后的调用方触发;申请失败/无码绝不进这里,确保绝不误发 CF 资产。
  453. // 语义:走完整分销链路 bindReferralIfNotSelf → /api/invite/bind → CommissionService.bindReferral
  454. // → applyReferralSideEffects(发 F24 CF 值、directCount+1、排行榜)——用户裁决接受的语义。
  455. // 两级隔离:记录级零副作用、强校验;用户级才发资产。两者同源于组件字段 inviteRefCode。
  456. // 幂等:userRefBound 成功(含自邀 skipped)置 true,整个流程(含 handleReapply/handleAddRole
  457. // 多次提交)至多成功一次,避免重复发资产 / 触发后端 CommissionService:140「已绑定推荐人」误报错。
  458. // 失败可恢复:绑定源 this.inviteRefCode 组件字段全程未清、userRefBound 与 bindingRef 均保持 false,
  459. // 配合 modal「重试绑定」回调即可就地重新发起绑定(真实可达的恢复路径)。
  460. // 注意:storage.refCode 已成僵尸字段(不参与绑定、清不清都不影响),可重试不依赖它;
  461. // 「从邀请链接重新进入」也不是补绑路径——重进会命中 checkExistingApply 的 status=0 记录进入审核态、无补绑入口,
  462. // 故离开本页后只能联系邀请人/客服补绑,modal 文案据实说明、不承诺走不通的路径。
  463. async bindUserReferral() {
  464. if (this.userRefBound) return // 幂等:已成功绑定过,不重复发资产
  465. if (this.bindingRef) return // 防重入:重试连点/异常时序不并发
  466. // 防错配(P0):与记录级同源于组件字段 inviteRefCode(onLoad 解析的那份),
  467. // 绝不从 uni.getStorageSync('refCode') 读,消除「storage 残留旧码 → 用户级绑到旧人」的窄边界;码空不绑定。
  468. var code = this.inviteRefCode
  469. if (!code) return
  470. this.bindingRef = true
  471. try {
  472. // await 串行:绑定结果 settle 后才决定置标记/清僵尸码/提示,绝不 fire-and-forget
  473. var bindRes = await bindReferralIfNotSelf(code)
  474. if (bindRes && (bindRes.code === 200 || bindRes.skipped)) {
  475. // 仅成功(含自邀 skipped:true)才置幂等标记,并清掉僵尸字段 storage.refCode(不参与绑定,仅为避免残留)。
  476. // 可重试的真正保证是 this.inviteRefCode 组件字段未清 + userRefBound=false + modal 回调,与 storage.refCode 无关。
  477. this.userRefBound = true
  478. uni.removeStorageSync('refCode')
  479. return
  480. }
  481. // 非 200 且非 skipped 理论上由 request() reject 走 catch,此处防御性兜底按失败处理
  482. // P2 幂等抛错误报循环收敛:后端已绑定成功但响应丢失、重试命中「已绑定推荐人」时按实质成功收敛。
  483. var retryMsg = bindRes && bindRes.message
  484. if (retryMsg && String(retryMsg).indexOf('已绑定推荐人') > -1) {
  485. this.userRefBound = true
  486. uni.removeStorageSync('refCode')
  487. uni.showToast({ title: '推荐人已绑定', icon: 'none' })
  488. return
  489. }
  490. this.showBindRetryHint(retryMsg)
  491. } catch (e) {
  492. // 401 由 request() 统一 reLaunch 登录页,不在这里叠加 modal
  493. if (e && e.code === 401) return
  494. // P2 幂等抛错误报循环收敛(在 401 检查之后、showBindRetryHint 之前):
  495. // 后端已实际绑定成功(CF 资产已发)但响应在传输中丢失 → 重试命中「已绑定推荐人,不可修改」,
  496. // 此时按实质成功收敛:置幂等标记 + 清僵尸码 + toast,不弹失败 modal,
  497. // 避免 userRefBound 永远 false、流程无法收敛为成功态。
  498. if (e && e.message && String(e.message).indexOf('已绑定推荐人') > -1) {
  499. this.userRefBound = true
  500. uni.removeStorageSync('refCode')
  501. uni.showToast({ title: '推荐人已绑定', icon: 'none' })
  502. return
  503. }
  504. // 失败:userRefBound 保持 false、inviteRefCode 未清,故可就地重试(不依赖 storage.refCode)。
  505. // request() 拦截器已对非 200 业务响应 toast 后端具体 message(如「邀请码无效」「已有推荐人」),
  506. // 这里用 modal 同时承载后端原文 + 明确重试引导:既不覆盖具体错误,又给出可见的重试入口。
  507. this.showBindRetryHint(e && e.message)
  508. } finally {
  509. this.bindingRef = false
  510. }
  511. },
  512. // 绑定失败提示 + 就地重试入口。申请已成功,故措辞不泛化「提交失败」;
  513. // 后端具体 message 放 content 保留可见(request() toast 可能被 modal 盖住,原文不丢)。
  514. showBindRetryHint(serverMsg) {
  515. uni.showModal({
  516. title: '推荐人绑定失败',
  517. content: (serverMsg ? serverMsg + '\n' : '') + '申请已提交成功,但推荐人绑定未成功。请点击「重试绑定」;若已离开本页,请联系邀请人或客服补绑。',
  518. confirmText: '重试绑定',
  519. cancelText: '稍后',
  520. success: (res) => {
  521. if (res.confirm) {
  522. // 幂等标记仍为 false、bindingRef 已归 false、inviteRefCode 未清,重试重新发起绑定;成功即置位
  523. this.bindUserReferral()
  524. }
  525. }
  526. })
  527. },
  528. // 返回 boolean:仅当记录级申请真正落库成功(res.code===200)才返回 true。
  529. // 调用方据此决定是否触发用户级绑定——这是「资产一致性」的唯一闸门:申请失败绝不发 CF 资产。
  530. async doSubmit(newRoles) {
  531. this.submitting = true
  532. uni.showLoading({ title: '提交中...' })
  533. try {
  534. const res = await submitServiceRoleApply({
  535. roles: newRoles,
  536. idCard: this.form.idCard,
  537. idCardImages: [this.form.idCardFront, this.form.idCardBack],
  538. certificateImages: this.form.certificateImages,
  539. province: this.form.province,
  540. city: this.form.city,
  541. district: this.form.district,
  542. street: this.form.street,
  543. addressDetail: this.form.addressDetail,
  544. // 团队邀请记录级归属:透传直达链接的 refCode,由后端服务端反查邀请人 userId 写
  545. // inviter_user_id。不传前端自算 inviterUserId(防冒领),不触发任何分销副作用。
  546. refCode: this.inviteRefCode
  547. })
  548. uni.hideLoading()
  549. if (res.code === 200) {
  550. // 提交成功,刷新状态。此刻邀请归属已落库,清除独立 key 防止下次无码进入时误挂旧邀请人。
  551. uni.removeStorageSync(this.inviteRefCodeStorageKey)
  552. await this.checkExistingApply()
  553. if (!this.showStatusView) this.showStatusView = true
  554. return true
  555. }
  556. // 少数业务码(如 5001 无家庭)会被 request() resolve 而非 reject,此时 request 未弹提示,需在此兜底
  557. uni.showToast({ title: res.message || '提交失败', icon: 'none' })
  558. return false
  559. } catch (e) {
  560. uni.hideLoading()
  561. // 邀请码无效/自邀请等后端业务错误:request() 已 showToast(e.message),这里用同一 message
  562. // 再弹一次作双保险(同内容覆盖,不会泛化),确保「邀请码绑定失败必须有可见错误反馈」。
  563. // 绝不用「提交失败,请重试」覆盖后端具体原因;401/纯网络异常由 request() 统一提示,此处静默。
  564. if (e && e.message && e.code !== 401) {
  565. uni.showToast({ title: e.message, icon: 'none' })
  566. }
  567. return false
  568. } finally {
  569. this.submitting = false
  570. }
  571. },
  572. handleReapply() {
  573. this.applyRecord = null
  574. this.showStatusView = false
  575. this.selectedRoles = []
  576. this.addressText = ''
  577. this.form = {
  578. idCard: '',
  579. idCardFront: '',
  580. idCardBack: '',
  581. certificateImages: [],
  582. province: '',
  583. city: '',
  584. district: '',
  585. street: '',
  586. addressDetail: ''
  587. }
  588. },
  589. goToCenter() {
  590. // 活动服务商 → 活动管理页(管理 Tab 由权限控制);其余角色 → 供应商中心
  591. if (this.approvedRoles.indexOf('activity_provider') > -1) {
  592. uni.redirectTo({ url: '/pages/activity/index' })
  593. } else {
  594. uni.redirectTo({ url: '/pages/vendor/center' })
  595. }
  596. },
  597. handleAddRole() {
  598. // 保留 applyRecord(用于标记已通过角色),仅切到表单视图;身份证沿用历史预填不重传
  599. this.showStatusView = false
  600. this.selectedRoles = []
  601. uni.showToast({ title: '可多选新增角色', icon: 'none', duration: 2000 })
  602. }
  603. }
  604. }
  605. </script>
  606. <style lang="scss">
  607. .page {
  608. min-height: 100vh;
  609. background: linear-gradient(180deg, $uni-primary-pale 0%, $facade-fill-page 30%);
  610. padding: 0 $uni-space-page 120rpx;
  611. }
  612. /* ===== 状态展示区 ===== */
  613. .status-view {
  614. padding-top: 60rpx;
  615. display: flex;
  616. flex-direction: column;
  617. align-items: center;
  618. }
  619. .status-card {
  620. width: 100%;
  621. border-radius: 24rpx;
  622. padding: 60rpx 40rpx;
  623. text-align: center;
  624. margin-bottom: $uni-space-lg;
  625. }
  626. .status-card.status-pending {
  627. background: linear-gradient(135deg, $dim-wealth-tint, $status-warning-soft);
  628. border: 2rpx solid $status-warning-light;
  629. }
  630. .status-card.status-approved {
  631. background: linear-gradient(135deg, $status-success-tint-2, $status-success-soft-2);
  632. border: 2rpx solid #86EFAC;
  633. }
  634. .status-card.status-rejected {
  635. background: linear-gradient(135deg, $status-danger-tint-2, $status-danger-soft);
  636. border: 2rpx solid $status-danger-light-2;
  637. }
  638. .status-icon {
  639. font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
  640. display: block;
  641. margin-bottom: 20rpx;
  642. }
  643. .status-title {
  644. font-size: calc(36rpx * var(--font-scale, 1));
  645. font-weight: bold;
  646. color: $facade-text-gray-800;
  647. display: block;
  648. margin-bottom: 12rpx;
  649. }
  650. .status-desc {
  651. font-size: calc(26rpx * var(--font-scale, 1));
  652. color: $facade-text-slate;
  653. line-height: 1.6;
  654. display: block;
  655. }
  656. .status-tip {
  657. background: $app-surface;
  658. border-radius: 16rpx;
  659. padding: 20rpx 28rpx;
  660. margin-bottom: 40rpx;
  661. width: 100%;
  662. box-sizing: border-box;
  663. }
  664. .status-tip text {
  665. font-size: calc(24rpx * var(--font-scale, 1));
  666. color: $status-warning-strong;
  667. }
  668. .reject-info {
  669. background: $app-surface;
  670. border-radius: 16rpx;
  671. padding: 28rpx;
  672. margin-bottom: 40rpx;
  673. width: 100%;
  674. box-sizing: border-box;
  675. }
  676. .reject-label {
  677. font-size: calc(24rpx * var(--font-scale, 1));
  678. color: $facade-text-gray-400;
  679. display: block;
  680. margin-bottom: 12rpx;
  681. }
  682. .reject-reason {
  683. font-size: calc(28rpx * var(--font-scale, 1));
  684. color: $status-danger-deep;
  685. line-height: 1.6;
  686. display: block;
  687. }
  688. /* P1 推荐人补绑区:与 status-tip 同款卡片,按钮沿用 .btn-reapply 尺寸与品牌渐变,视觉同体系 */
  689. .rebind-section {
  690. background: $app-surface;
  691. border-radius: 16rpx;
  692. padding: 24rpx 28rpx;
  693. margin-bottom: 40rpx;
  694. width: 100%;
  695. box-sizing: border-box;
  696. }
  697. .rebind-desc {
  698. font-size: calc(24rpx * var(--font-scale, 1));
  699. color: $status-warning-strong;
  700. display: block;
  701. margin-bottom: 20rpx;
  702. }
  703. .btn-rebind {
  704. width: 100%;
  705. height: 88rpx;
  706. line-height: 88rpx;
  707. border-radius: 24rpx;
  708. font-size: calc(30rpx * var(--font-scale, 1));
  709. text-align: center;
  710. border: none;
  711. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  712. color: $app-surface;
  713. }
  714. .btn-rebind[disabled] {
  715. opacity: 0.5;
  716. }
  717. .action-buttons {
  718. width: 100%;
  719. display: flex;
  720. flex-direction: column;
  721. gap: 20rpx;
  722. }
  723. .btn-reapply, .btn-center, .btn-back {
  724. width: 100%;
  725. height: 88rpx;
  726. line-height: 88rpx;
  727. border-radius: 24rpx;
  728. font-size: calc(30rpx * var(--font-scale, 1));
  729. text-align: center;
  730. border: none;
  731. }
  732. .btn-reapply {
  733. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  734. color: $app-surface;
  735. }
  736. .btn-center {
  737. background: linear-gradient(135deg, $status-success, $status-success-light-3);
  738. color: $app-surface;
  739. }
  740. .btn-back {
  741. background: $facade-fill-gray-100;
  742. color: $facade-text-slate;
  743. }
  744. /* ===== 表单区 ===== */
  745. .header {
  746. text-align: center;
  747. padding: 50rpx 0 $uni-space-lg;
  748. }
  749. .title {
  750. font-size: calc(40rpx * var(--font-scale, 1));
  751. font-weight: bold;
  752. color: $facade-text-gray-800;
  753. display: block;
  754. }
  755. .subtitle {
  756. font-size: calc(26rpx * var(--font-scale, 1));
  757. color: $facade-text-gray-400;
  758. margin-top: 10rpx;
  759. display: block;
  760. }
  761. .section {
  762. background: $app-surface;
  763. border-radius: 24rpx;
  764. padding: $uni-space-lg;
  765. margin-bottom: 24rpx;
  766. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.04);
  767. }
  768. .section-title {
  769. font-size: calc(28rpx * var(--font-scale, 1));
  770. font-weight: bold;
  771. margin-bottom: 24rpx;
  772. color: $facade-text-gray-700;
  773. }
  774. .required {
  775. color: $status-danger;
  776. margin-left: 4rpx;
  777. }
  778. /* 角色网格:固定三列
  779. 不使用 calc() 与 flex gap(旧版 iOS WebView 不支持 gap,calc 除法在不同机型上
  780. 会出现取整偏差导致换行)——改用「每行 3 个 flex:1 单元格 + 固定 rpx 间距」,
  781. 所有机型/分辨率下都严格等分三列 */
  782. .role-grid {
  783. display: flex;
  784. flex-direction: column;
  785. }
  786. .role-row {
  787. display: flex;
  788. flex-direction: row;
  789. justify-content: space-between;
  790. }
  791. .role-cell {
  792. /* flex:1 + 可收缩,保证同一行三等分,长文案不撑破列宽 */
  793. flex: 1;
  794. min-width: 0;
  795. box-sizing: border-box;
  796. }
  797. /* 单元格之间留白:左右各 8rpx,首尾行视情况抵消,保证总宽不溢出 */
  798. .role-cell:not(:first-child) {
  799. margin-left: 16rpx;
  800. }
  801. .role-row:not(:first-child) {
  802. margin-top: 20rpx;
  803. }
  804. .role-card {
  805. width: 100%;
  806. box-sizing: border-box;
  807. background: $facade-fill-gray-50;
  808. border-radius: 16rpx;
  809. padding: $uni-space-lg 0;
  810. display: flex;
  811. flex-direction: column;
  812. align-items: center;
  813. position: relative;
  814. border: 3rpx solid transparent;
  815. transition: border-color 0.2s, background-color 0.2s;
  816. }
  817. .role-card.selected {
  818. background: $uni-primary-pale;
  819. border-color: $brand-primary;
  820. }
  821. /* 已通过角色:置灰锁定,显示"已通过"徽标,不可勾选 */
  822. .role-card.approved {
  823. background: #f0f7f0;
  824. border-color: #7cc576;
  825. opacity: 0.85;
  826. }
  827. .approved-badge {
  828. position: absolute;
  829. top: 8rpx;
  830. right: 12rpx;
  831. color: #4a9b4a;
  832. font-size: calc(20rpx * var(--font-scale, 1));
  833. font-weight: bold;
  834. background: rgba(124, 197, 118, 0.18);
  835. border-radius: 8rpx;
  836. padding: 4rpx 10rpx;
  837. }
  838. .role-icon {
  839. font-size: calc(44rpx * var(--font-scale, 1));
  840. margin-bottom: 10rpx;
  841. }
  842. .role-name {
  843. font-size: calc(24rpx * var(--font-scale, 1));
  844. color: $facade-text-gray-700;
  845. font-weight: 500;
  846. /* 保证长角色名不换行撑高导致行高不一致 */
  847. white-space: nowrap;
  848. overflow: hidden;
  849. text-overflow: ellipsis;
  850. max-width: 100%;
  851. }
  852. .check-mark {
  853. position: absolute;
  854. top: 8rpx;
  855. right: 12rpx;
  856. color: $brand-primary;
  857. font-size: calc(32rpx * var(--font-scale, 1));
  858. font-weight: bold;
  859. }
  860. /* 联系地址入口行(与收件人地址页保持同一套视觉) */
  861. .address-row {
  862. display: flex;
  863. align-items: center;
  864. padding: 24rpx 24rpx;
  865. background: $facade-fill-ghost;
  866. border: 2rpx solid $facade-gray-200;
  867. border-radius: 16rpx;
  868. margin-bottom: 16rpx;
  869. }
  870. .address-label {
  871. font-size: calc(26rpx * var(--font-scale, 1));
  872. color: $facade-text-gray-700;
  873. width: 140rpx;
  874. flex-shrink: 0;
  875. }
  876. .address-value-wrap {
  877. flex: 1;
  878. display: flex;
  879. align-items: center;
  880. justify-content: flex-end;
  881. min-width: 0;
  882. }
  883. .address-value {
  884. font-size: calc(26rpx * var(--font-scale, 1));
  885. color: $facade-text-gray-700;
  886. text-align: right;
  887. overflow: hidden;
  888. text-overflow: ellipsis;
  889. white-space: nowrap;
  890. }
  891. .address-placeholder {
  892. font-size: calc(26rpx * var(--font-scale, 1));
  893. color: $facade-text-gray-400;
  894. text-align: right;
  895. }
  896. .address-arrow {
  897. font-size: calc(34rpx * var(--font-scale, 1));
  898. color: $facade-text-gray-400;
  899. margin-left: 8rpx;
  900. flex-shrink: 0;
  901. }
  902. /* 输入框 */
  903. .input {
  904. width: 100%;
  905. height: 72rpx;
  906. border: 2rpx solid $facade-gray-200;
  907. border-radius: 16rpx;
  908. padding: 0 24rpx;
  909. font-size: calc(26rpx * var(--font-scale, 1));
  910. box-sizing: border-box;
  911. margin-bottom: 16rpx;
  912. background: $facade-fill-ghost;
  913. }
  914. /* 图片上传 */
  915. .upload-row {
  916. display: flex;
  917. gap: 20rpx;
  918. }
  919. .upload-item {
  920. flex: 1;
  921. height: 200rpx;
  922. border: 3rpx dashed $app-border-strong;
  923. border-radius: 16rpx;
  924. display: flex;
  925. align-items: center;
  926. justify-content: center;
  927. overflow: hidden;
  928. background: $facade-fill-ghost;
  929. }
  930. .upload-placeholder {
  931. display: flex;
  932. flex-direction: column;
  933. align-items: center;
  934. }
  935. .upload-icon {
  936. font-size: calc(48rpx * var(--font-scale, 1));
  937. color: $facade-text-gray-400;
  938. }
  939. .upload-label {
  940. font-size: calc(22rpx * var(--font-scale, 1));
  941. color: $facade-text-gray-400;
  942. margin-top: 8rpx;
  943. }
  944. .upload-preview {
  945. width: 100%;
  946. height: 100%;
  947. }
  948. /* 证书列表 */
  949. .cert-list {
  950. display: flex;
  951. flex-wrap: wrap;
  952. gap: 16rpx;
  953. }
  954. .cert-item {
  955. width: 160rpx;
  956. height: 160rpx;
  957. position: relative;
  958. border-radius: 16rpx;
  959. overflow: hidden;
  960. }
  961. .cert-preview {
  962. width: 100%;
  963. height: 100%;
  964. }
  965. .cert-del {
  966. position: absolute;
  967. top: 4rpx;
  968. right: 4rpx;
  969. width: 36rpx;
  970. height: 36rpx;
  971. background: rgba(0,0,0,0.55);
  972. color: $app-surface;
  973. border-radius: 50%;
  974. text-align: center;
  975. line-height: 36rpx;
  976. font-size: calc(28rpx * var(--font-scale, 1));
  977. }
  978. .cert-add {
  979. width: 160rpx;
  980. height: 160rpx;
  981. border: 3rpx dashed $app-border-strong;
  982. border-radius: 16rpx;
  983. display: flex;
  984. flex-direction: column;
  985. align-items: center;
  986. justify-content: center;
  987. background: $facade-fill-ghost;
  988. }
  989. /* 提交按钮 */
  990. .submit-btn {
  991. width: 100%;
  992. height: 96rpx;
  993. line-height: 96rpx;
  994. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  995. color: $app-surface;
  996. border-radius: 24rpx;
  997. font-size: calc(32rpx * var(--font-scale, 1));
  998. font-weight: 600;
  999. margin-top: 16rpx;
  1000. border: none;
  1001. box-shadow: 0 8rpx 24rpx rgba(249, 115, 22, 0.3);
  1002. }
  1003. .submit-btn[disabled] {
  1004. opacity: 0.6;
  1005. box-shadow: none;
  1006. }
  1007. .footer-hint {
  1008. text-align: center;
  1009. margin-top: 24rpx;
  1010. }
  1011. .footer-hint text {
  1012. font-size: calc(24rpx * var(--font-scale, 1));
  1013. color: $facade-text-gray-400;
  1014. }
  1015. .multi-role-hint {
  1016. background: linear-gradient(135deg, $status-info-tint, $status-info-soft);
  1017. border: 2rpx solid $tint-blue-line;
  1018. border-radius: 16rpx;
  1019. padding: 18rpx 24rpx;
  1020. margin-bottom: 20rpx;
  1021. }
  1022. .multi-role-hint text {
  1023. font-size: calc(26rpx * var(--font-scale, 1));
  1024. color: $status-info-deep-3;
  1025. }
  1026. .btn-add-role {
  1027. background: linear-gradient(135deg, $dim-wisdom, $dim-wisdom-light);
  1028. color: $app-surface;
  1029. }
  1030. </style>