Files
wxapp_companion/pages/me/index.js
T
lik ff1b1664fa feat(apply): 入驻只收基本信息并新增启动页、材料后补与改服务城市
入驻表单移除身份证与证件材料(服务城市单选下拉,默认北京),只填姓名/手机/性别/城市/简介即可提交;新增 pages/launch 启动页先解析身份再跳转,无身份直接进申请页不再闪现首页;新增 pages/materials 证件材料补传页;个人资料页支持在职陪诊师修改服务城市;appId 更名为 wxapp_companion。
2026-11-10 16:34:00 +08:00

162 lines
3.9 KiB
JavaScript

// pages/me/index.js
const API = require('../../utils/api.js')
const role = require('../../utils/role.js')
const { CITY_OPTIONS, CITY_LABELS, cityIndex, cityLabel } = require('../../utils/city.js')
// 性别映射
const SEX_MAP = {
male: '男',
female: '女'
}
Page({
data: {
user: {},
identityText: '',
isAttendant: false,
serviceAreaLabels: CITY_LABELS,
serviceAreaIndex: 0,
serviceAreaText: ''
},
onShow() {
this.loadUser()
this.loadIdentity()
},
/**
* 身份文案:管理员/实习陪诊师/正式陪诊师·等级
*/
loadIdentity() {
role
.ensureRoleSafe()
.then((detail) => {
const attendant = detail.attendant || null
const isAttendant = detail.role === 'attendant'
this.setData({
isAttendant,
identityText: detail.role === 'admin' ? '管理员' : (attendant ? attendant.text : '')
})
if (isAttendant) this.loadServiceArea()
})
.catch(() => {})
},
/**
* 服务城市:以员工档案 attendantInfo.serviceAreas 为准
*/
loadServiceArea() {
API.employee
.getMe()
.then((res) => {
if (res.code !== 0 || !res.data || !res.data.employee) return
const areas = res.data.employee.attendantInfo
? res.data.employee.attendantInfo.serviceAreas || []
: []
this.applyServiceArea(areas[0])
})
.catch(() => {})
},
applyServiceArea(value) {
this.setData({
serviceAreaIndex: cityIndex(value),
serviceAreaText: value ? cityLabel(value) : '未设置'
})
},
/**
* 修改服务城市:只影响订单池可见范围
*/
onServiceAreaChange(e) {
const index = Number(e.detail.value) || 0
const option = CITY_OPTIONS[index]
if (!option) return
wx.showLoading({ title: '保存中...' })
API.employee
.setServiceArea(option.value)
.then((res) => {
wx.hideLoading()
if (res.code === 0) {
this.applyServiceArea(option.value)
wx.showToast({ title: '服务城市已更新', icon: 'success' })
return
}
wx.showToast({ title: res.msg || '保存失败', icon: 'none' })
})
.catch((err) => {
wx.hideLoading()
wx.showToast({ title: (err && err.message) || '网络错误,请重试', icon: 'none' })
})
},
/**
* 证件材料后补入口
*/
onMaterialsTap() {
wx.navigateTo({ url: '/pages/materials/index' })
},
/**
* 加载当前登录用户信息
*/
loadUser() {
const app = getApp()
app.ensureLogin()
.then(user => {
this.setUser(user)
})
.catch(() => {
wx.showToast({ title: '获取用户信息失败', icon: 'none' })
})
},
/**
* 处理并展示用户信息
*/
setUser(user) {
if (!user) return
const profile = user.profile || {}
const location = user.location || {}
const meta = user.meta || {}
const name = profile.name || '微信用户'
const locationText = [location.province, location.city, location.district]
.filter(Boolean).join(' ')
this.setData({
user: {
avatar: profile.avatar || '',
avatarText: name[0],
name,
mobile: profile.mobile || '',
sexLabel: SEX_MAP[profile.sex] || '未知',
birthText: this.formatDate(profile.birth),
email: profile.email || '',
idnumber: profile.idnumber || '',
locationText,
createText: this.formatDate(meta.createtime)
}
})
},
/**
* 格式化日期为 yyyy-MM-dd
*/
formatDate(dateStr) {
if (!dateStr) return ''
const date = new Date(dateStr)
if (isNaN(date.getTime())) return ''
const pad = (n) => String(n).padStart(2, '0')
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
},
onShareAppMessage() {
return {
title: '个人中心',
path: '/pages/me/index'
}
}
})