221 lines
6.3 KiB
JavaScript
221 lines
6.3 KiB
JavaScript
// pages/companion-apply/companion-apply.js
|
|
// 陪聊师申请页面 - 根据 Figma 设计重构
|
|
const api = require('../../utils/api')
|
|
|
|
Page({
|
|
data: {
|
|
statusBarHeight: 44,
|
|
navBarHeight: 44,
|
|
totalNavHeight: 88,
|
|
applyStatus: 'none', // none, pending, approved, rejected
|
|
statusTitle: '',
|
|
statusDesc: '',
|
|
showForm: true,
|
|
agreed: false,
|
|
formData: {
|
|
realName: '',
|
|
city: '',
|
|
phone: '',
|
|
remarks: ''
|
|
},
|
|
canSubmit: false
|
|
},
|
|
|
|
onLoad() {
|
|
// 获取系统信息设置导航栏高度
|
|
const systemInfo = wx.getSystemInfoSync()
|
|
const statusBarHeight = systemInfo.statusBarHeight || 44
|
|
const menuButton = wx.getMenuButtonBoundingClientRect()
|
|
const navBarHeight = menuButton.height + (menuButton.top - statusBarHeight) * 2
|
|
const totalNavHeight = statusBarHeight + navBarHeight
|
|
|
|
this.setData({
|
|
statusBarHeight,
|
|
navBarHeight,
|
|
totalNavHeight
|
|
})
|
|
|
|
this.checkApplyStatus()
|
|
},
|
|
|
|
// 返回上一页
|
|
goBack() {
|
|
wx.navigateBack()
|
|
},
|
|
|
|
// 检查申请状态
|
|
async checkApplyStatus() {
|
|
// 先检查是否已登录(通过 Token 判断)
|
|
const token = wx.getStorageSync('auth_token')
|
|
console.log('checkApplyStatus - token:', token ? '已登录' : '未登录')
|
|
|
|
if (!token) {
|
|
console.log('用户未登录,显示申请表单')
|
|
this.setData({ applyStatus: 'none' })
|
|
return
|
|
}
|
|
|
|
wx.showLoading({ title: '加载中...' })
|
|
try {
|
|
const res = await api.companion.getApplyStatus()
|
|
console.log('获取申请状态响应:', res)
|
|
|
|
// 兼容两种响应格式: { success: true, data } 或 { code: 0, data }
|
|
const isSuccess = res.success || res.code === 0
|
|
|
|
if (isSuccess && res.data) {
|
|
const data = res.data
|
|
|
|
// 使用新的状态标识字段
|
|
if (data.isApproved) {
|
|
this.setData({
|
|
applyStatus: 'approved',
|
|
statusTitle: '您的资料已审核通过',
|
|
statusDesc: '恭喜您成为陪聊师!现在可以进入工作台开始接单了'
|
|
})
|
|
} else if (data.isPending) {
|
|
this.setData({
|
|
applyStatus: 'pending',
|
|
statusTitle: '正在审核中',
|
|
statusDesc: '您已提交陪聊师申请,正在审核中,请耐心等待'
|
|
})
|
|
} else if (data.isRejected) {
|
|
this.setData({
|
|
applyStatus: 'rejected',
|
|
statusTitle: '申请未通过',
|
|
statusDesc: data.rejectReason || '很抱歉,您的申请未通过审核,您可以修改信息后重新申请'
|
|
})
|
|
} else if (data.canApply) {
|
|
// 可以申请(没有申请记录或被拒绝后可重新申请)
|
|
this.setData({ applyStatus: 'none' })
|
|
} else {
|
|
// 兼容旧格式,使用 status 字段
|
|
const status = data.status
|
|
if (status) {
|
|
this.setData({
|
|
applyStatus: status,
|
|
statusTitle: this.getStatusTitle(status),
|
|
statusDesc: this.getStatusDesc(status, data.rejectReason || data.reject_reason)
|
|
})
|
|
} else {
|
|
this.setData({ applyStatus: 'none' })
|
|
}
|
|
}
|
|
} else {
|
|
console.log('没有申请记录,显示申请表单')
|
|
this.setData({ applyStatus: 'none' })
|
|
}
|
|
} catch (err) {
|
|
console.error('获取申请状态失败:', err)
|
|
this.setData({ applyStatus: 'none' })
|
|
} finally {
|
|
wx.hideLoading()
|
|
}
|
|
},
|
|
|
|
// 获取状态标题
|
|
getStatusTitle(status) {
|
|
const titles = {
|
|
'pending': '正在审核中',
|
|
'reviewing': '正在审核中',
|
|
'approved': '您的资料已审核通过',
|
|
'rejected': '申请未通过'
|
|
}
|
|
return titles[status] || '正在审核中'
|
|
},
|
|
|
|
// 获取状态描述
|
|
getStatusDesc(status, rejectReason) {
|
|
const descs = {
|
|
'pending': '您已提交陪聊师申请,正在审核中,请耐心等待',
|
|
'reviewing': '您已提交陪聊师申请,正在审核中,请耐心等待',
|
|
'approved': '恭喜您成为陪聊师!现在可以进入工作台开始接单了',
|
|
'rejected': rejectReason || '很抱歉,您的申请未通过审核,您可以修改信息后重新申请'
|
|
}
|
|
return descs[status] || '您的申请正在处理中'
|
|
},
|
|
|
|
// 重新申请
|
|
reapply() {
|
|
this.setData({ showForm: true, applyStatus: 'none' })
|
|
},
|
|
|
|
// 输入变化
|
|
onInputChange(e) {
|
|
const field = e.currentTarget.dataset.field
|
|
const value = e.detail.value
|
|
this.setData({
|
|
[`formData.${field}`]: value
|
|
})
|
|
this.checkCanSubmit()
|
|
},
|
|
|
|
// 切换协议同意状态
|
|
toggleAgreement() {
|
|
this.setData({
|
|
agreed: !this.data.agreed
|
|
})
|
|
this.checkCanSubmit()
|
|
},
|
|
|
|
// 查看协议
|
|
viewAgreement() {
|
|
wx.navigateTo({
|
|
url: '/pages/agreement/agreement?code=cooperation_service'
|
|
})
|
|
},
|
|
|
|
// 检查是否可以提交
|
|
checkCanSubmit() {
|
|
const { formData, agreed } = this.data
|
|
|
|
const canSubmit =
|
|
formData.realName &&
|
|
formData.phone &&
|
|
formData.phone.length === 11 &&
|
|
agreed
|
|
|
|
this.setData({ canSubmit })
|
|
},
|
|
|
|
// 提交申请
|
|
async submitApply() {
|
|
if (!this.data.canSubmit) return
|
|
|
|
const { formData } = this.data
|
|
|
|
// 验证手机号
|
|
if (!/^1[3-9]\d{9}$/.test(formData.phone)) {
|
|
wx.showToast({ title: '请输入正确的手机号', icon: 'none' })
|
|
return
|
|
}
|
|
|
|
wx.showLoading({ title: '提交中...' })
|
|
try {
|
|
const res = await api.companion.apply({
|
|
realName: formData.realName,
|
|
city: formData.city,
|
|
phone: formData.phone,
|
|
remarks: formData.remarks
|
|
})
|
|
|
|
if (res.success || res.code === 0) {
|
|
wx.showToast({ title: '申请已提交', icon: 'success' })
|
|
this.setData({
|
|
applyStatus: 'pending',
|
|
statusTitle: '申请审核中',
|
|
statusDesc: '您的申请正在审核中,请耐心等待,我们会尽快处理',
|
|
showForm: false
|
|
})
|
|
} else {
|
|
wx.showToast({ title: res.message || '提交失败', icon: 'none' })
|
|
}
|
|
} catch (err) {
|
|
console.error('提交申请失败:', err)
|
|
wx.showToast({ title: err.message || '提交失败', icon: 'none' })
|
|
} finally {
|
|
wx.hideLoading()
|
|
}
|
|
}
|
|
})
|