| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051 |
- <template>
- <view class="page" :style="{ '--font-scale': fontScale }">
- <!-- 审核状态展示 -->
- <view v-if="showStatusView" class="status-view">
- <view class="status-card" :class="'status-' + applyStatus">
- <view class="status-icon">{{ statusIcon }}</view>
- <text class="status-title">{{ statusTitle }}</text>
- <text class="status-desc">{{ statusDesc }}</text>
- </view>
- <view v-if="applyStatus === 'pending'" class="status-tip">
- <text>预计 1-3 个工作日内完成审核,请耐心等待</text>
- </view>
- <view v-if="applyStatus === 'rejected'" class="reject-info">
- <text class="reject-label">拒绝原因</text>
- <text class="reject-reason">{{ applyRecord && applyRecord.rejectReason }}</text>
- </view>
- <!-- P1 补绑入口:记录已存在(status 0/1/2)、表单隐藏后,绑定失败时唯一可达的就地补绑路径。
- @click 直连 bindUserReferral,绝不接 handleSubmit/doSubmit(表单隐藏 + 后端查重 ServiceImpl:74-76 会拒)。 -->
- <view v-if="!userRefBound && inviteRefCode" class="rebind-section">
- <text class="rebind-desc">推荐人尚未绑定成功,请在网络稳定后补绑</text>
- <button class="btn-rebind" :disabled="bindingRef" @click="bindUserReferral">补绑推荐人</button>
- </view>
- <view class="action-buttons">
- <button v-if="applyStatus === 'rejected'" class="btn-reapply" @click="handleReapply">
- 重新申请
- </button>
- <button v-if="applyStatus === 'approved'" class="btn-center" @click="goToCenter">
- 进入服务商中心
- </button>
- <button v-if="applyStatus === 'approved'" class="btn-add-role" @click="handleAddRole">
- 申请其他角色
- </button>
- <button class="btn-back" @click="goBack">返回首页</button>
- </view>
- </view>
- <!-- 申请表单 -->
- <view v-else class="form-wrap">
- <view v-if="hasApprovedRole" class="multi-role-hint">
- <text>📌 您当前已是 {{ approvedRoleLabel }},可勾选下方新增其他角色</text>
- </view>
- <view class="header">
- <text class="title">服务角色申请</text>
- <text class="subtitle">选择申请角色,提交资质信息</text>
- </view>
- <view class="section">
- <view class="section-title">选择申请角色 <text class="required">*</text></view>
- <!-- 严格三列:roleRows 每行固定 3 个单元格,flex:1 等分,不依赖 calc/gap -->
- <view class="role-grid">
- <view
- v-for="(row, rowIdx) in roleRows"
- :key="getRoleRowKey(rowIdx)"
- class="role-row"
- >
- <view
- v-for="role in row"
- :key="role.key"
- class="role-cell"
- >
- <view
- v-if="!role.placeholder"
- class="role-card"
- :class="{ selected: selectedRoles.indexOf(role.key) > -1, approved: isApprovedRole(role.key) }"
- @click="toggleRole(role.key)"
- >
- <text class="role-icon">{{ role.icon }}</text>
- <text class="role-name">{{ role.name }}</text>
- <view v-if="isApprovedRole(role.key)" class="approved-badge">已通过</view>
- <view v-else-if="selectedRoles.indexOf(role.key) > -1" class="check-mark">✓</view>
- </view>
- </view>
- </view>
- </view>
- </view>
- <view class="section">
- <view class="section-title">身份证信息</view>
- <input class="input" v-model="form.idCard" placeholder="请输入身份证号码" maxlength="18" />
- <view class="upload-row">
- <view class="upload-item" @click="chooseIdCardImage('front')">
- <image v-if="form.idCardFront" :src="form.idCardFront" mode="aspectFill" class="upload-preview" />
- <view v-else class="upload-placeholder">
- <text class="upload-icon">+</text>
- <text class="upload-label">身份证正面</text>
- </view>
- </view>
- <view class="upload-item" @click="chooseIdCardImage('back')">
- <image v-if="form.idCardBack" :src="form.idCardBack" mode="aspectFill" class="upload-preview" />
- <view v-else class="upload-placeholder">
- <text class="upload-icon">+</text>
- <text class="upload-label">身份证反面</text>
- </view>
- </view>
- </view>
- </view>
- <view class="section">
- <view class="section-title">资质证书</view>
- <view class="cert-list">
- <view v-for="(img, idx) in form.certificateImages" :key="getCertKey(idx)" class="cert-item">
- <image :src="img" mode="aspectFill" class="cert-preview" />
- <text class="cert-del" @click="removeCert(idx)">×</text>
- </view>
- <view class="cert-add" @click="chooseCertificate">
- <text class="upload-icon">+</text>
- <text class="upload-label">添加证书</text>
- </view>
- </view>
- </view>
- <view class="section">
- <view class="section-title">联系地址 <text class="required">*</text></view>
- <view class="address-row" @click="openAddressPicker">
- <text class="address-label">所在地区</text>
- <view class="address-value-wrap">
- <text v-if="addressText" class="address-value">{{ addressText }}</text>
- <text v-else class="address-placeholder">请选择省市区街道</text>
- <text class="address-arrow">›</text>
- </view>
- </view>
- <input class="input" v-model="form.addressDetail" placeholder="详细地址(门牌号等)" />
- <!-- 与收件人地址共用同一组件 components/address-picker.vue -->
- <AddressPicker ref="addressPicker" :show-trigger="false" @change="onAddressChange" />
- </view>
- <button class="submit-btn" :disabled="submitting" @click="handleSubmit">
- {{ submitting ? '提交中...' : '提交申请' }}
- </button>
- <view class="footer-hint">
- <text>提交后将在 1-3 个工作日内完成审核</text>
- </view>
- </view>
- <!-- 团队邀请:未登录提交时就地弹出登录浮层,登录后自动续提交。
- 用本地浮层而非 401 → reLaunch 整页登录,是为了不销毁本组件:
- 表单已填数据、inviteRefCode 均保留,登录后回到表单且不丢码。
- login-sheet 由 main.js 全局注册;全局 loginSheetMixin 的 openLoginSheet 会命中本 ref。 -->
- <login-sheet ref="loginSheet" @success="onInviteLoginSuccess" @close="onInviteLoginClose" />
- </view>
- </template>
- <script>
- import { submitServiceRoleApply, getMyServiceRoleApply, uploadServiceRoleImage, bindReferralIfNotSelf } from '../../utils/api'
- import { pickImage } from '../../utils/image-picker.js'
- import AddressPicker from '@/components/address-picker.vue'
- import fontScaleMixin from '@/mixins/font-scale.js'
- export default {
- mixins: [fontScaleMixin],
- components: { AddressPicker },
- data() {
- return {
- roleList: [
- { key: 'planner', name: '规划师', icon: '📋' },
- { key: 'nutritionist', name: '营养师', icon: '🥗' },
- { key: 'butler', name: '管家', icon: '🔔' },
- { key: 'vendor', name: '服务商', icon: '🏪' },
- { key: 'article_admin', name: '文章管理员', icon: '📝' },
- { key: 'activity_provider', name: '活动提供商', icon: '🎪' }
- ],
- selectedRoles: [],
- addressText: '',
- form: {
- idCard: '',
- idCardFront: '',
- idCardBack: '',
- certificateImages: [],
- province: '',
- city: '',
- district: '',
- street: '',
- addressDetail: ''
- },
- submitting: false,
- applyRecord: null,
- showStatusView: false,
- // 团队邀请:直达链接 /pages/profile/service-role-apply?refCode=xxx 携带的邀请码(记录级归属)。
- // 用户级推荐人链路的 storage.refCode 会被 user-edit.vue:733 消费并清除,绝不能复用;
- // 故记录级另存独立 key 'serviceRoleApplyRefCode',与用户级彻底解耦、并存互不覆盖。
- // 本组件字段用于常规提交;若未登录触发整页登录导致组件销毁,登录后回跳无参时由
- // onLoad 从独立 key 恢复本字段,保证 refCode 端到端不丢。
- inviteRefCode: '',
- // 独立 storage key:记录级归属专用,不会被 user-edit 的用户级消费逻辑清除
- inviteRefCodeStorageKey: 'serviceRoleApplyRefCode',
- // 未登录点提交后挂起:浮层登录成功回调里续跑提交,避免用户二次点击
- pendingSubmitAfterLogin: false,
- // 用户级推荐人绑定幂等标记(资产一致性):整个流程至多成功绑定一次。
- // bindReferralIfNotSelf 成功(含自邀 skipped:true)才置 true;首次失败保持 false 以便重试补绑。
- // handleReapply/handleAddRole 多次提交不重置它,避免重复走 /api/invite/bind 重复发 F24 CF 资产、
- // 或触发后端 CommissionService:140「已绑定推荐人,不可修改」误报错。
- userRefBound: false,
- // 绑定请求防重入锁:避免失败重试弹窗连点「重试绑定」导致并发 bind 请求
- bindingRef: false
- }
- },
- computed: {
- // 按每行 3 个拆分行;最后一行不足 3 个用空占位单元格补齐,保证各行严格三列等宽
- roleRows() {
- const rows = []
- const list = this.roleList || []
- const total = Math.ceil(list.length / 3) * 3
- for (let i = 0; i < total; i += 3) {
- const row = []
- for (let j = 0; j < 3; j++) {
- const item = list[i + j]
- row.push(
- item
- ? item
- : { key: 'role-placeholder-' + i + '-' + j, name: '', icon: '', placeholder: true }
- )
- }
- rows.push(row)
- }
- return rows
- },
- applyStatus() {
- if (!this.applyRecord) return 'none'
- const s = this.applyRecord.status
- return s === 0 ? 'pending' : s === 1 ? 'approved' : 'rejected'
- },
- hasApprovedRole() {
- return this.applyRecord && this.applyRecord.status === 1
- },
- // 已通过审核的角色集合(key 数组)——这些角色已开通,不可重复勾选
- approvedRoles() {
- if (!this.applyRecord || this.applyRecord.status !== 1 || !this.applyRecord.roles) return []
- try {
- const roles = JSON.parse(this.applyRecord.roles)
- return Array.isArray(roles) ? roles : []
- } catch (e) { return [] }
- },
- approvedRoleLabel() {
- if (!this.applyRecord || !this.applyRecord.roles) return ''
- try {
- const roles = JSON.parse(this.applyRecord.roles)
- // 取第一个角色名称作为展示
- const roleMap = { planner: '规划师', nutritionist: '营养师', butler: '管家', vendor: '服务商', article_admin: '文章管理员', activity_provider: '活动提供商' }
- return roles.map(r => roleMap[r] || r).join('、') || '服务商'
- } catch (e) { return '服务商' }
- },
- statusIcon() {
- return { pending: '⏳', approved: '✅', rejected: '❌' }[this.applyStatus] || '📋'
- },
- statusTitle() {
- return { pending: '审核中', approved: '申请已通过', rejected: '申请被驳回' }[this.applyStatus] || ''
- },
- statusDesc() {
- return {
- pending: '您的申请正在审核中,请留意消息通知',
- approved: '已开通服务商身份,可继续申请其他服务角色',
- rejected: '您的申请未通过审核,可查看原因后重新提交'
- }[this.applyStatus] || ''
- }
- },
- onLoad(options) {
- // 团队邀请:解析直达链接的邀请码,存组件字段 + 独立 storage key(记录级归属专用)。
- // 不用 storage.refCode:那是「用户级推荐人」链路(App.vue 捕获→user-edit.vue:733 消费并清除),
- // 与记录级彻底解耦、互不覆盖。
- if (options && options.refCode) {
- this.inviteRefCode = options.refCode
- uni.setStorageSync(this.inviteRefCodeStorageKey, options.refCode)
- } else {
- // 未登录提交触发整页登录 / 401 reLaunch 时组件会被销毁;登录成功回跳若不带 refCode 参数,
- // 从独立 key 恢复,确保「登录后回到表单且 inviteRefCode 不丢」。
- var cached = uni.getStorageSync(this.inviteRefCodeStorageKey)
- if (cached) this.inviteRefCode = cached
- }
- this.checkExistingApply()
- },
- methods: {
- // 模板里不能直接调用 uni.*(渲染时实例上没有 uni,会报
- // "Property or method uni is not defined"),统一收进方法
- goBack() {
- var pages = getCurrentPages()
- if (pages && pages.length > 1) {
- uni.navigateBack()
- } else {
- uni.switchTab({ url: '/pages/index/index' })
- }
- },
- async checkExistingApply() {
- try {
- const res = await getMyServiceRoleApply()
- if (res.code === 200 && res.data) {
- this.applyRecord = res.data
- // 身份证预填:原申请记录里已上传的身份证不再要求重传
- this.prefillIdCard(this.applyRecord)
- const status = res.data.status
- if (status === 0) {
- // 审核中,展示进度
- this.showStatusView = true
- } else if (status === 1) {
- // 已通过:不再强制跳转,显示当前身份卡片 + 允许申请其他角色
- this.showStatusView = true
- } else if (status === 2) {
- // 已拒绝,显示原因
- this.showStatusView = true
- }
- }
- } catch (e) {
- // 无申请记录,显示表单
- }
- },
- // 从历史申请记录回填身份证号码与正反面图片(已上传过则不再要求重传)
- prefillIdCard(record) {
- if (!record) return
- if (record.idCard) this.form.idCard = record.idCard
- if (record.idCardImages) {
- try {
- const imgs = JSON.parse(record.idCardImages)
- if (Array.isArray(imgs) && imgs.length) {
- if (imgs[0]) this.form.idCardFront = imgs[0]
- if (imgs[1]) this.form.idCardBack = imgs[1]
- }
- } catch (e) {}
- }
- },
- toggleRole(key) {
- // 已通过审核的角色不可重复申请(不可勾选)
- if (this.approvedRoles.indexOf(key) > -1) {
- uni.showToast({ title: '该角色已开通,无需重复申请', icon: 'none' })
- return
- }
- const idx = this.selectedRoles.indexOf(key)
- if (idx > -1) {
- this.selectedRoles.splice(idx, 1)
- } else {
- this.selectedRoles.push(key)
- }
- },
- isApprovedRole(key) {
- return this.approvedRoles.indexOf(key) > -1
- },
- chooseIdCardImage(side) {
- pickImage({
- count: 1,
- sizeType: ['compressed'],
- sourceType: ['album', 'camera'],
- success: async (res) => {
- uni.showLoading({ title: '上传中...' })
- try {
- const uploadRes = await uploadServiceRoleImage(res.tempFilePaths[0])
- uni.hideLoading()
- if (uploadRes.code === 200) {
- if (side === 'front') {
- this.form.idCardFront = uploadRes.data.url
- } else {
- this.form.idCardBack = uploadRes.data.url
- }
- uni.showToast({ title: '上传成功', icon: 'success' })
- } else {
- uni.showToast({ title: uploadRes.message || '上传失败', icon: 'none' })
- }
- } catch (e) {
- uni.hideLoading()
- uni.showToast({ title: '上传失败', icon: 'none' })
- }
- }
- })
- },
- async chooseCertificate() {
- pickImage({
- count: 9 - this.form.certificateImages.length,
- sizeType: ['compressed'],
- sourceType: ['album', 'camera'],
- success: async (res) => {
- uni.showLoading({ title: '上传中...' })
- try {
- for (const filePath of res.tempFilePaths) {
- const uploadRes = await uploadServiceRoleImage(filePath)
- if (uploadRes.code === 200) {
- this.form.certificateImages.push(uploadRes.data.url)
- }
- }
- uni.hideLoading()
- uni.showToast({ title: '上传成功', icon: 'success' })
- } catch (e) {
- uni.hideLoading()
- uni.showToast({ title: '上传失败', icon: 'none' })
- }
- }
- })
- },
- removeCert(idx) {
- this.form.certificateImages.splice(idx, 1)
- },
- getCertKey(idx) {
- return 'cert-' + idx
- },
- getRoleRowKey(rowIdx) {
- return 'role-row-' + rowIdx
- },
- openAddressPicker() {
- if (this.$refs.addressPicker) {
- this.$refs.addressPicker.open()
- }
- },
- onAddressChange(e) {
- this.form.province = e.province || ''
- this.form.city = e.city || ''
- this.form.district = e.district || ''
- this.form.street = e.street || ''
- this.addressText = e.fullName || ''
- },
- async handleSubmit() {
- // 提交前过滤已通过角色(防御:仅提交新增角色,不重复申请已开通角色)
- const newRoles = (this.selectedRoles || []).filter(r => this.approvedRoles.indexOf(r) === -1)
- if (newRoles.length === 0) {
- uni.showToast({ title: '请至少选择一个新增角色', icon: 'none' })
- return
- }
- if (!this.form.idCardFront || !this.form.idCardBack) {
- uni.showToast({ title: '请上传身份证正反面照片', icon: 'none' })
- return
- }
- if (!this.form.province) {
- uni.showToast({ title: '请选择联系地址', icon: 'none' })
- return
- }
- // 团队邀请:未登录时先就地弹登录浮层,登录后自动续提交。
- // 不走接口层 401 → reLaunch 整页登录的原因:那会销毁本组件、丢失已填表单与 inviteRefCode,
- // 且登录成功后回不到本表单。就地浮层由本页 <login-sheet> 承载,组件不销毁。
- if (!uni.getStorageSync('token')) {
- this.pendingSubmitAfterLogin = true
- // refCode 一并透传给浮层:未登录态 App.vue 已把分享码存入用户级 storage.refCode,
- // 这里再以 options.refCode 覆盖同源值(互不冲突),用户级 referrerId 仍由现状链路消费。
- this.openLoginSheet({ refCode: this.inviteRefCode })
- return
- }
- // 资产一致性(P0,串行):记录级 doSubmit 必须先执行并确认成功,之后才触发用户级绑定。
- // doSubmit 失败(邀请码无效/查重拒绝/网络失败)会返回 false 并自行 toast,绝不进入绑定、
- // 绝不给邀请人发 F24 CF 资产;也绝不让绑定链路的空 catch 吞掉 doSubmit 的失败。
- var submitted = await this.doSubmit(newRoles)
- if (submitted) {
- await this.bindUserReferral()
- }
- },
- // 就地浮层登录成功回调:自动续跑被挂起的提交(此时 token 已写入 storage)。
- // 就地浮层登录不走 user-edit.vue:714 的推荐人消费点、也不触发 App.vue onShow 带参补绑,
- // 故本页在「记录级申请成功」后主动补绑一次用户级推荐人(product 裁决:用户级走完整分销链路、
- // 发 F24 CF 值是接受的语义)。绑定制约:①仅在 doSubmit 成功后串行触发,失败绝不发资产;
- // ②与 user-edit 路径互斥受 userRefBound 幂等标记保护,整个流程至多成功一次,不重复发资产。
- async onInviteLoginSuccess() {
- if (!this.pendingSubmitAfterLogin) return
- this.pendingSubmitAfterLogin = false
- const newRoles = (this.selectedRoles || []).filter(r => this.approvedRoles.indexOf(r) === -1)
- // 资产一致性(P0,串行):与已登录路径完全同构。先确认记录级申请成功,再绑定用户级推荐人。
- // doSubmit 失败返回 false 并自行 toast,绝不进入绑定、绝不给邀请人发 CF 资产。
- var submitted = await this.doSubmit(newRoles)
- if (submitted) {
- await this.bindUserReferral()
- }
- },
- // 浮层关闭(含「暂不登录先逛逛」handleSkipLogin):复位挂起标记,
- // 避免用户放弃登录后标记残留,导致下次提交误走自动续提交分支。
- onInviteLoginClose() {
- this.pendingSubmitAfterLogin = false
- },
- // 用户级推荐人绑定(资产一致性核心 P0/P1)。
- // 前置:仅由「记录级 doSubmit 成功」后的调用方触发;申请失败/无码绝不进这里,确保绝不误发 CF 资产。
- // 语义:走完整分销链路 bindReferralIfNotSelf → /api/invite/bind → CommissionService.bindReferral
- // → applyReferralSideEffects(发 F24 CF 值、directCount+1、排行榜)——用户裁决接受的语义。
- // 两级隔离:记录级零副作用、强校验;用户级才发资产。两者同源于组件字段 inviteRefCode。
- // 幂等:userRefBound 成功(含自邀 skipped)置 true,整个流程(含 handleReapply/handleAddRole
- // 多次提交)至多成功一次,避免重复发资产 / 触发后端 CommissionService:140「已绑定推荐人」误报错。
- // 失败可恢复:绑定源 this.inviteRefCode 组件字段全程未清、userRefBound 与 bindingRef 均保持 false,
- // 配合 modal「重试绑定」回调即可就地重新发起绑定(真实可达的恢复路径)。
- // 注意:storage.refCode 已成僵尸字段(不参与绑定、清不清都不影响),可重试不依赖它;
- // 「从邀请链接重新进入」也不是补绑路径——重进会命中 checkExistingApply 的 status=0 记录进入审核态、无补绑入口,
- // 故离开本页后只能联系邀请人/客服补绑,modal 文案据实说明、不承诺走不通的路径。
- async bindUserReferral() {
- if (this.userRefBound) return // 幂等:已成功绑定过,不重复发资产
- if (this.bindingRef) return // 防重入:重试连点/异常时序不并发
- // 防错配(P0):与记录级同源于组件字段 inviteRefCode(onLoad 解析的那份),
- // 绝不从 uni.getStorageSync('refCode') 读,消除「storage 残留旧码 → 用户级绑到旧人」的窄边界;码空不绑定。
- var code = this.inviteRefCode
- if (!code) return
- this.bindingRef = true
- try {
- // await 串行:绑定结果 settle 后才决定置标记/清僵尸码/提示,绝不 fire-and-forget
- var bindRes = await bindReferralIfNotSelf(code)
- if (bindRes && (bindRes.code === 200 || bindRes.skipped)) {
- // 仅成功(含自邀 skipped:true)才置幂等标记,并清掉僵尸字段 storage.refCode(不参与绑定,仅为避免残留)。
- // 可重试的真正保证是 this.inviteRefCode 组件字段未清 + userRefBound=false + modal 回调,与 storage.refCode 无关。
- this.userRefBound = true
- uni.removeStorageSync('refCode')
- return
- }
- // 非 200 且非 skipped 理论上由 request() reject 走 catch,此处防御性兜底按失败处理
- // P2 幂等抛错误报循环收敛:后端已绑定成功但响应丢失、重试命中「已绑定推荐人」时按实质成功收敛。
- var retryMsg = bindRes && bindRes.message
- if (retryMsg && String(retryMsg).indexOf('已绑定推荐人') > -1) {
- this.userRefBound = true
- uni.removeStorageSync('refCode')
- uni.showToast({ title: '推荐人已绑定', icon: 'none' })
- return
- }
- this.showBindRetryHint(retryMsg)
- } catch (e) {
- // 401 由 request() 统一 reLaunch 登录页,不在这里叠加 modal
- if (e && e.code === 401) return
- // P2 幂等抛错误报循环收敛(在 401 检查之后、showBindRetryHint 之前):
- // 后端已实际绑定成功(CF 资产已发)但响应在传输中丢失 → 重试命中「已绑定推荐人,不可修改」,
- // 此时按实质成功收敛:置幂等标记 + 清僵尸码 + toast,不弹失败 modal,
- // 避免 userRefBound 永远 false、流程无法收敛为成功态。
- if (e && e.message && String(e.message).indexOf('已绑定推荐人') > -1) {
- this.userRefBound = true
- uni.removeStorageSync('refCode')
- uni.showToast({ title: '推荐人已绑定', icon: 'none' })
- return
- }
- // 失败:userRefBound 保持 false、inviteRefCode 未清,故可就地重试(不依赖 storage.refCode)。
- // request() 拦截器已对非 200 业务响应 toast 后端具体 message(如「邀请码无效」「已有推荐人」),
- // 这里用 modal 同时承载后端原文 + 明确重试引导:既不覆盖具体错误,又给出可见的重试入口。
- this.showBindRetryHint(e && e.message)
- } finally {
- this.bindingRef = false
- }
- },
- // 绑定失败提示 + 就地重试入口。申请已成功,故措辞不泛化「提交失败」;
- // 后端具体 message 放 content 保留可见(request() toast 可能被 modal 盖住,原文不丢)。
- showBindRetryHint(serverMsg) {
- uni.showModal({
- title: '推荐人绑定失败',
- content: (serverMsg ? serverMsg + '\n' : '') + '申请已提交成功,但推荐人绑定未成功。请点击「重试绑定」;若已离开本页,请联系邀请人或客服补绑。',
- confirmText: '重试绑定',
- cancelText: '稍后',
- success: (res) => {
- if (res.confirm) {
- // 幂等标记仍为 false、bindingRef 已归 false、inviteRefCode 未清,重试重新发起绑定;成功即置位
- this.bindUserReferral()
- }
- }
- })
- },
- // 返回 boolean:仅当记录级申请真正落库成功(res.code===200)才返回 true。
- // 调用方据此决定是否触发用户级绑定——这是「资产一致性」的唯一闸门:申请失败绝不发 CF 资产。
- async doSubmit(newRoles) {
- this.submitting = true
- uni.showLoading({ title: '提交中...' })
- try {
- const res = await submitServiceRoleApply({
- roles: newRoles,
- idCard: this.form.idCard,
- idCardImages: [this.form.idCardFront, this.form.idCardBack],
- certificateImages: this.form.certificateImages,
- province: this.form.province,
- city: this.form.city,
- district: this.form.district,
- street: this.form.street,
- addressDetail: this.form.addressDetail,
- // 团队邀请记录级归属:透传直达链接的 refCode,由后端服务端反查邀请人 userId 写
- // inviter_user_id。不传前端自算 inviterUserId(防冒领),不触发任何分销副作用。
- refCode: this.inviteRefCode
- })
- uni.hideLoading()
- if (res.code === 200) {
- // 提交成功,刷新状态。此刻邀请归属已落库,清除独立 key 防止下次无码进入时误挂旧邀请人。
- uni.removeStorageSync(this.inviteRefCodeStorageKey)
- await this.checkExistingApply()
- if (!this.showStatusView) this.showStatusView = true
- return true
- }
- // 少数业务码(如 5001 无家庭)会被 request() resolve 而非 reject,此时 request 未弹提示,需在此兜底
- uni.showToast({ title: res.message || '提交失败', icon: 'none' })
- return false
- } catch (e) {
- uni.hideLoading()
- // 邀请码无效/自邀请等后端业务错误:request() 已 showToast(e.message),这里用同一 message
- // 再弹一次作双保险(同内容覆盖,不会泛化),确保「邀请码绑定失败必须有可见错误反馈」。
- // 绝不用「提交失败,请重试」覆盖后端具体原因;401/纯网络异常由 request() 统一提示,此处静默。
- if (e && e.message && e.code !== 401) {
- uni.showToast({ title: e.message, icon: 'none' })
- }
- return false
- } finally {
- this.submitting = false
- }
- },
- handleReapply() {
- this.applyRecord = null
- this.showStatusView = false
- this.selectedRoles = []
- this.addressText = ''
- this.form = {
- idCard: '',
- idCardFront: '',
- idCardBack: '',
- certificateImages: [],
- province: '',
- city: '',
- district: '',
- street: '',
- addressDetail: ''
- }
- },
- goToCenter() {
- // 活动服务商 → 活动管理页(管理 Tab 由权限控制);其余角色 → 供应商中心
- if (this.approvedRoles.indexOf('activity_provider') > -1) {
- uni.redirectTo({ url: '/pages/activity/index' })
- } else {
- uni.redirectTo({ url: '/pages/vendor/center' })
- }
- },
- handleAddRole() {
- // 保留 applyRecord(用于标记已通过角色),仅切到表单视图;身份证沿用历史预填不重传
- this.showStatusView = false
- this.selectedRoles = []
- uni.showToast({ title: '可多选新增角色', icon: 'none', duration: 2000 })
- }
- }
- }
- </script>
- <style lang="scss">
- .page {
- min-height: 100vh;
- background: linear-gradient(180deg, $uni-primary-pale 0%, $facade-fill-page 30%);
- padding: 0 $uni-space-page 120rpx;
- }
- /* ===== 状态展示区 ===== */
- .status-view {
- padding-top: 60rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- .status-card {
- width: 100%;
- border-radius: 24rpx;
- padding: 60rpx 40rpx;
- text-align: center;
- margin-bottom: $uni-space-lg;
- }
- .status-card.status-pending {
- background: linear-gradient(135deg, $dim-wealth-tint, $status-warning-soft);
- border: 2rpx solid $status-warning-light;
- }
- .status-card.status-approved {
- background: linear-gradient(135deg, $status-success-tint-2, $status-success-soft-2);
- border: 2rpx solid #86EFAC;
- }
- .status-card.status-rejected {
- background: linear-gradient(135deg, $status-danger-tint-2, $status-danger-soft);
- border: 2rpx solid $status-danger-light-2;
- }
- .status-icon {
- font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
- display: block;
- margin-bottom: 20rpx;
- }
- .status-title {
- font-size: calc(36rpx * var(--font-scale, 1));
- font-weight: bold;
- color: $facade-text-gray-800;
- display: block;
- margin-bottom: 12rpx;
- }
- .status-desc {
- font-size: calc(26rpx * var(--font-scale, 1));
- color: $facade-text-slate;
- line-height: 1.6;
- display: block;
- }
- .status-tip {
- background: $app-surface;
- border-radius: 16rpx;
- padding: 20rpx 28rpx;
- margin-bottom: 40rpx;
- width: 100%;
- box-sizing: border-box;
- }
- .status-tip text {
- font-size: calc(24rpx * var(--font-scale, 1));
- color: $status-warning-strong;
- }
- .reject-info {
- background: $app-surface;
- border-radius: 16rpx;
- padding: 28rpx;
- margin-bottom: 40rpx;
- width: 100%;
- box-sizing: border-box;
- }
- .reject-label {
- font-size: calc(24rpx * var(--font-scale, 1));
- color: $facade-text-gray-400;
- display: block;
- margin-bottom: 12rpx;
- }
- .reject-reason {
- font-size: calc(28rpx * var(--font-scale, 1));
- color: $status-danger-deep;
- line-height: 1.6;
- display: block;
- }
- /* P1 推荐人补绑区:与 status-tip 同款卡片,按钮沿用 .btn-reapply 尺寸与品牌渐变,视觉同体系 */
- .rebind-section {
- background: $app-surface;
- border-radius: 16rpx;
- padding: 24rpx 28rpx;
- margin-bottom: 40rpx;
- width: 100%;
- box-sizing: border-box;
- }
- .rebind-desc {
- font-size: calc(24rpx * var(--font-scale, 1));
- color: $status-warning-strong;
- display: block;
- margin-bottom: 20rpx;
- }
- .btn-rebind {
- width: 100%;
- height: 88rpx;
- line-height: 88rpx;
- border-radius: 24rpx;
- font-size: calc(30rpx * var(--font-scale, 1));
- text-align: center;
- border: none;
- background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
- color: $app-surface;
- }
- .btn-rebind[disabled] {
- opacity: 0.5;
- }
- .action-buttons {
- width: 100%;
- display: flex;
- flex-direction: column;
- gap: 20rpx;
- }
- .btn-reapply, .btn-center, .btn-back {
- width: 100%;
- height: 88rpx;
- line-height: 88rpx;
- border-radius: 24rpx;
- font-size: calc(30rpx * var(--font-scale, 1));
- text-align: center;
- border: none;
- }
- .btn-reapply {
- background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
- color: $app-surface;
- }
- .btn-center {
- background: linear-gradient(135deg, $status-success, $status-success-light-3);
- color: $app-surface;
- }
- .btn-back {
- background: $facade-fill-gray-100;
- color: $facade-text-slate;
- }
- /* ===== 表单区 ===== */
- .header {
- text-align: center;
- padding: 50rpx 0 $uni-space-lg;
- }
- .title {
- font-size: calc(40rpx * var(--font-scale, 1));
- font-weight: bold;
- color: $facade-text-gray-800;
- display: block;
- }
- .subtitle {
- font-size: calc(26rpx * var(--font-scale, 1));
- color: $facade-text-gray-400;
- margin-top: 10rpx;
- display: block;
- }
- .section {
- background: $app-surface;
- border-radius: 24rpx;
- padding: $uni-space-lg;
- margin-bottom: 24rpx;
- box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.04);
- }
- .section-title {
- font-size: calc(28rpx * var(--font-scale, 1));
- font-weight: bold;
- margin-bottom: 24rpx;
- color: $facade-text-gray-700;
- }
- .required {
- color: $status-danger;
- margin-left: 4rpx;
- }
- /* 角色网格:固定三列
- 不使用 calc() 与 flex gap(旧版 iOS WebView 不支持 gap,calc 除法在不同机型上
- 会出现取整偏差导致换行)——改用「每行 3 个 flex:1 单元格 + 固定 rpx 间距」,
- 所有机型/分辨率下都严格等分三列 */
- .role-grid {
- display: flex;
- flex-direction: column;
- }
- .role-row {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- }
- .role-cell {
- /* flex:1 + 可收缩,保证同一行三等分,长文案不撑破列宽 */
- flex: 1;
- min-width: 0;
- box-sizing: border-box;
- }
- /* 单元格之间留白:左右各 8rpx,首尾行视情况抵消,保证总宽不溢出 */
- .role-cell:not(:first-child) {
- margin-left: 16rpx;
- }
- .role-row:not(:first-child) {
- margin-top: 20rpx;
- }
- .role-card {
- width: 100%;
- box-sizing: border-box;
- background: $facade-fill-gray-50;
- border-radius: 16rpx;
- padding: $uni-space-lg 0;
- display: flex;
- flex-direction: column;
- align-items: center;
- position: relative;
- border: 3rpx solid transparent;
- transition: border-color 0.2s, background-color 0.2s;
- }
- .role-card.selected {
- background: $uni-primary-pale;
- border-color: $brand-primary;
- }
- /* 已通过角色:置灰锁定,显示"已通过"徽标,不可勾选 */
- .role-card.approved {
- background: #f0f7f0;
- border-color: #7cc576;
- opacity: 0.85;
- }
- .approved-badge {
- position: absolute;
- top: 8rpx;
- right: 12rpx;
- color: #4a9b4a;
- font-size: calc(20rpx * var(--font-scale, 1));
- font-weight: bold;
- background: rgba(124, 197, 118, 0.18);
- border-radius: 8rpx;
- padding: 4rpx 10rpx;
- }
- .role-icon {
- font-size: calc(44rpx * var(--font-scale, 1));
- margin-bottom: 10rpx;
- }
- .role-name {
- font-size: calc(24rpx * var(--font-scale, 1));
- color: $facade-text-gray-700;
- font-weight: 500;
- /* 保证长角色名不换行撑高导致行高不一致 */
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- max-width: 100%;
- }
- .check-mark {
- position: absolute;
- top: 8rpx;
- right: 12rpx;
- color: $brand-primary;
- font-size: calc(32rpx * var(--font-scale, 1));
- font-weight: bold;
- }
- /* 联系地址入口行(与收件人地址页保持同一套视觉) */
- .address-row {
- display: flex;
- align-items: center;
- padding: 24rpx 24rpx;
- background: $facade-fill-ghost;
- border: 2rpx solid $facade-gray-200;
- border-radius: 16rpx;
- margin-bottom: 16rpx;
- }
- .address-label {
- font-size: calc(26rpx * var(--font-scale, 1));
- color: $facade-text-gray-700;
- width: 140rpx;
- flex-shrink: 0;
- }
- .address-value-wrap {
- flex: 1;
- display: flex;
- align-items: center;
- justify-content: flex-end;
- min-width: 0;
- }
- .address-value {
- font-size: calc(26rpx * var(--font-scale, 1));
- color: $facade-text-gray-700;
- text-align: right;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- .address-placeholder {
- font-size: calc(26rpx * var(--font-scale, 1));
- color: $facade-text-gray-400;
- text-align: right;
- }
- .address-arrow {
- font-size: calc(34rpx * var(--font-scale, 1));
- color: $facade-text-gray-400;
- margin-left: 8rpx;
- flex-shrink: 0;
- }
- /* 输入框 */
- .input {
- width: 100%;
- height: 72rpx;
- border: 2rpx solid $facade-gray-200;
- border-radius: 16rpx;
- padding: 0 24rpx;
- font-size: calc(26rpx * var(--font-scale, 1));
- box-sizing: border-box;
- margin-bottom: 16rpx;
- background: $facade-fill-ghost;
- }
- /* 图片上传 */
- .upload-row {
- display: flex;
- gap: 20rpx;
- }
- .upload-item {
- flex: 1;
- height: 200rpx;
- border: 3rpx dashed $app-border-strong;
- border-radius: 16rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- overflow: hidden;
- background: $facade-fill-ghost;
- }
- .upload-placeholder {
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- .upload-icon {
- font-size: calc(48rpx * var(--font-scale, 1));
- color: $facade-text-gray-400;
- }
- .upload-label {
- font-size: calc(22rpx * var(--font-scale, 1));
- color: $facade-text-gray-400;
- margin-top: 8rpx;
- }
- .upload-preview {
- width: 100%;
- height: 100%;
- }
- /* 证书列表 */
- .cert-list {
- display: flex;
- flex-wrap: wrap;
- gap: 16rpx;
- }
- .cert-item {
- width: 160rpx;
- height: 160rpx;
- position: relative;
- border-radius: 16rpx;
- overflow: hidden;
- }
- .cert-preview {
- width: 100%;
- height: 100%;
- }
- .cert-del {
- position: absolute;
- top: 4rpx;
- right: 4rpx;
- width: 36rpx;
- height: 36rpx;
- background: rgba(0,0,0,0.55);
- color: $app-surface;
- border-radius: 50%;
- text-align: center;
- line-height: 36rpx;
- font-size: calc(28rpx * var(--font-scale, 1));
- }
- .cert-add {
- width: 160rpx;
- height: 160rpx;
- border: 3rpx dashed $app-border-strong;
- border-radius: 16rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- background: $facade-fill-ghost;
- }
- /* 提交按钮 */
- .submit-btn {
- width: 100%;
- height: 96rpx;
- line-height: 96rpx;
- background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
- color: $app-surface;
- border-radius: 24rpx;
- font-size: calc(32rpx * var(--font-scale, 1));
- font-weight: 600;
- margin-top: 16rpx;
- border: none;
- box-shadow: 0 8rpx 24rpx rgba(249, 115, 22, 0.3);
- }
- .submit-btn[disabled] {
- opacity: 0.6;
- box-shadow: none;
- }
- .footer-hint {
- text-align: center;
- margin-top: 24rpx;
- }
- .footer-hint text {
- font-size: calc(24rpx * var(--font-scale, 1));
- color: $facade-text-gray-400;
- }
- .multi-role-hint {
- background: linear-gradient(135deg, $status-info-tint, $status-info-soft);
- border: 2rpx solid $tint-blue-line;
- border-radius: 16rpx;
- padding: 18rpx 24rpx;
- margin-bottom: 20rpx;
- }
- .multi-role-hint text {
- font-size: calc(26rpx * var(--font-scale, 1));
- color: $status-info-deep-3;
- }
- .btn-add-role {
- background: linear-gradient(135deg, $dim-wisdom, $dim-wisdom-light);
- color: $app-surface;
- }
- </style>
|