修改界面中,临时提交

This commit is contained in:
lik
2026-10-02 10:28:44 +08:00
parent 089e0eb081
commit 55a9c7e3e8
41 changed files with 2458 additions and 451 deletions
+221
View File
@@ -0,0 +1,221 @@
const API = require('../../utils/api.js')
// 性别选项,与后端 schema 的 male / female 对应
const SEX_OPTIONS = [{
value: 'male',
label: '男'
},
{
value: 'female',
label: '女'
}
]
const MOBILE_REGEX = /^1[3-9]\d{9}$/
Page({
data: {
id: '',
isEdit: false,
saving: false,
today: '',
sexOptions: SEX_OPTIONS,
form: {
name: '',
sex: '',
birth: '',
mobile: '',
idnumber: '',
remark: ''
}
},
onLoad(options) {
const id = options.id || ''
this.setData({
id,
isEdit: !!id,
today: this.formatDate(new Date())
})
wx.setNavigationBarTitle({
title: id ? '编辑就诊人' : '新增就诊人'
})
if (id) {
this.loadProfile(id)
}
},
formatDate(date) {
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
},
// 编辑模式:读取档案详情回填表单
loadProfile(id) {
API.healthProfile.getMyProfileById(id)
.then((res) => {
if (res.code !== 0) {
wx.showToast({
title: res.msg || '加载失败',
icon: 'none'
})
return
}
const detail = (res.data && res.data.profile) || {}
const profile = detail.profile || {}
const health = detail.health || {}
this.setData({
form: {
name: profile.name || '',
sex: profile.sex || '',
birth: profile.birth || '',
mobile: profile.mobile || '',
idnumber: profile.idnumber || '',
remark: health.remark || ''
}
})
})
.catch((err) => {
console.log('获取就诊人信息失败', err)
wx.showToast({
title: '网络请求失败',
icon: 'none'
})
})
},
onFieldInput(e) {
const field = e.currentTarget.dataset.field
this.setData({
[`form.${field}`]: e.detail.value
})
},
onSexSelect(e) {
const sex = e.currentTarget.dataset.sex
// 再次点击已选中的性别则取消选择
this.setData({
'form.sex': this.data.form.sex === sex ? '' : sex
})
},
onBirthChange(e) {
this.setData({
'form.birth': e.detail.value
})
},
// 表单校验,返回错误提示文案;通过校验返回空字符串
validate() {
const {
name,
mobile
} = this.data.form
if (!name.trim()) {
return '请输入就诊人姓名'
}
if (!mobile.trim()) {
return '请输入联系电话'
}
if (!MOBILE_REGEX.test(mobile.trim())) {
return '请输入正确的手机号'
}
return ''
},
onSave() {
if (this.data.saving) {
return
}
const errorMessage = this.validate()
if (errorMessage) {
wx.showToast({
title: errorMessage,
icon: 'none'
})
return
}
const {
name,
sex,
birth,
mobile,
idnumber,
remark
} = this.data.form
// 新增用嵌套对象(schema 的 new Model 需要嵌套结构);
// 更新用点号路径(schema 更新姓名时会额外写 profile.pinyin,整体替换 profile 会冲突)
const payload = this.data.isEdit ? {
'profile.name': name.trim(),
'profile.sex': sex,
'profile.birth': birth,
'profile.mobile': mobile.trim(),
'profile.idnumber': idnumber.trim(),
'health.remark': remark.trim()
} : {
profile: {
name: name.trim(),
sex: sex,
birth: birth,
mobile: mobile.trim(),
idnumber: idnumber.trim()
},
health: {
remark: remark.trim()
}
}
this.setData({
saving: true
})
wx.showLoading({
title: '保存中...'
})
const request = this.data.isEdit ?
API.healthProfile.updateMyProfile(this.data.id, payload) :
API.healthProfile.createMyProfile(payload)
request
.then((res) => {
wx.hideLoading()
if (res.code !== 0) {
wx.showToast({
title: res.msg || '保存失败',
icon: 'none'
})
return
}
wx.showToast({
title: '保存成功',
icon: 'success'
})
setTimeout(() => {
wx.navigateBack()
}, 800)
})
.catch((err) => {
wx.hideLoading()
console.log('保存就诊人失败', err)
wx.showToast({
title: '网络请求失败',
icon: 'none'
})
})
.finally(() => {
this.setData({
saving: false
})
})
}
})
+6
View File
@@ -0,0 +1,6 @@
{
"navigationBarTitleText": "新增就诊人",
"usingComponents": {
"t-icon": "tdesign-miniprogram/icon/icon"
}
}
+62
View File
@@ -0,0 +1,62 @@
<view class="container">
<view class="form-card">
<view class="form-item">
<text class="form-label">姓名<text class="required">*</text></text>
<input class="form-input" value="{{form.name}}" placeholder="请输入就诊人姓名" placeholder-class="input-placeholder"
maxlength="20" data-field="name" bindinput="onFieldInput" />
</view>
<view class="form-item">
<text class="form-label">性别</text>
<view class="sex-wrap">
<view class="sex-tag {{form.sex === item.value ? 'sex-tag-active' : ''}}" wx:for="{{sexOptions}}" wx:key="value"
data-sex="{{item.value}}" bindtap="onSexSelect">
<text class="sex-text">{{item.label}}</text>
</view>
</view>
</view>
<view class="form-item">
<text class="form-label">出生年月</text>
<picker mode="date" value="{{form.birth}}" start="1900-01-01" end="{{today}}" bindchange="onBirthChange">
<view class="picker-value {{form.birth ? '' : 'picker-placeholder'}}">
{{form.birth || '请选择出生年月'}}
</view>
</picker>
</view>
<view class="form-item">
<text class="form-label">联系电话<text class="required">*</text></text>
<input class="form-input" value="{{form.mobile}}" type="number" placeholder="用于陪诊师联系您" placeholder-class="input-placeholder"
maxlength="11" data-field="mobile" bindinput="onFieldInput" />
</view>
<view class="form-item">
<text class="form-label">证件号</text>
<input class="form-input" value="{{form.idnumber}}" placeholder="选填,用于医院建档取号" placeholder-class="input-placeholder"
maxlength="30" data-field="idnumber" bindinput="onFieldInput" />
</view>
</view>
<view class="form-card">
<view class="form-item form-item-remark">
<text class="form-label">健康备注</text>
<textarea class="form-textarea" value="{{form.remark}}" placeholder="选填,如过敏史、慢病、行动不便等情况,便于陪诊师提前准备"
placeholder-class="input-placeholder" maxlength="200" data-field="remark" bindinput="onFieldInput" />
<text class="remark-count">{{form.remark.length}}/200</text>
</view>
</view>
<view class="tips">
<t-icon name="lock-on" size="26rpx" color="#B0B7C3" />
<text class="tips-text">信息仅用于陪诊服务,我们会严格保密</text>
</view>
<view class="footer-bar">
<view class="submit-btn {{saving ? 'submit-btn-disabled' : ''}}" bindtap="onSave">
<text class="submit-btn-text">保存</text>
</view>
</view>
</view>
+165
View File
@@ -0,0 +1,165 @@
page {
background-color: #FAF6F1;
}
.container {
min-height: 100vh;
padding: 24rpx 24rpx 200rpx;
box-sizing: border-box;
}
.form-card {
background: #FFFFFF;
border-radius: 20rpx;
padding: 8rpx 28rpx;
margin-bottom: 24rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.04);
}
.form-item {
display: flex;
align-items: center;
min-height: 108rpx;
border-bottom: 1rpx solid #F3F4F6;
}
.form-item:last-child {
border-bottom: none;
}
.form-item-remark {
flex-direction: column;
align-items: stretch;
padding: 28rpx 0;
}
.form-label {
width: 160rpx;
flex-shrink: 0;
font-size: 28rpx;
color: #374151;
}
.required {
color: #EF4444;
margin-left: 4rpx;
}
.form-input {
flex: 1;
font-size: 28rpx;
color: #1F2937;
text-align: right;
}
.input-placeholder {
color: #C4C9D2;
}
.picker-value {
flex: 1;
font-size: 28rpx;
color: #1F2937;
text-align: right;
}
.picker-placeholder {
color: #C4C9D2;
}
/* 性别选择 */
.sex-wrap {
flex: 1;
display: flex;
justify-content: flex-end;
gap: 20rpx;
}
.sex-tag {
display: flex;
align-items: center;
justify-content: center;
width: 120rpx;
height: 64rpx;
border-radius: 32rpx;
background: #F3F4F6;
transition: all 0.2s;
}
.sex-tag-active {
background: #FDF8EE;
border: 2rpx solid #D4A853;
}
.sex-text {
font-size: 28rpx;
color: #6B7280;
}
.sex-tag-active .sex-text {
color: #D4A853;
font-weight: 600;
}
/* 健康备注 */
.form-textarea {
width: 100%;
height: 160rpx;
margin-top: 16rpx;
font-size: 28rpx;
color: #1F2937;
line-height: 1.6;
}
.remark-count {
align-self: flex-end;
font-size: 22rpx;
color: #C4C9D2;
}
/* 隐私提示 */
.tips {
display: flex;
align-items: center;
padding: 0 12rpx;
}
.tips-text {
margin-left: 10rpx;
font-size: 24rpx;
color: #B0B7C3;
}
/* 底部固定保存按钮 */
.footer-bar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
padding: 20rpx 24rpx calc(20rpx + env(safe-area-inset-bottom));
background: rgba(255, 255, 255, 0.96);
box-shadow: 0 -2rpx 16rpx rgba(0, 0, 0, 0.05);
}
.submit-btn {
display: flex;
align-items: center;
justify-content: center;
height: 88rpx;
border-radius: 44rpx;
background: #D4A853;
}
.submit-btn:active {
opacity: 0.85;
}
.submit-btn-disabled {
opacity: 0.6;
}
.submit-btn-text {
font-size: 30rpx;
font-weight: 600;
color: #FFFFFF;
}
+134
View File
@@ -0,0 +1,134 @@
const API = require('../../utils/api.js')
Page({
data: {
profiles: [],
loading: false
},
// 用 onShow 而不是 onLoad:从新增/编辑页返回后需要刷新列表
onShow() {
this.loadProfiles()
},
onPullDownRefresh() {
this.loadProfiles().finally(() => {
wx.stopPullDownRefresh()
})
},
// 拉取当前登录用户的健康档案(就诊人)列表
loadProfiles() {
this.setData({
loading: true
})
return API.healthProfile.getMyProfiles({
page: 1,
pageSize: 50
})
.then((res) => {
if (res.code !== 0) {
wx.showToast({
title: res.msg || '加载失败',
icon: 'none'
})
return
}
const list = (res.data && res.data.list) || []
this.setData({
profiles: list.map((item) => this.formatProfile(item))
})
})
.catch((err) => {
console.log('获取健康档案失败', err)
wx.showToast({
title: '网络请求失败',
icon: 'none'
})
})
.finally(() => {
this.setData({
loading: false
})
})
},
// 后端返回的是嵌套结构,这里拍平成卡片展示需要的字段
formatProfile(item) {
const profile = item.profile || {}
const health = item.health || {}
return {
_id: item._id,
name: profile.name || '未命名',
sexText: profile.sex === 'male' ? '男' : (profile.sex === 'female' ? '女' : ''),
birth: profile.birth || '',
mobile: profile.mobile || '',
idnumberText: this.maskIdNumber(profile.idnumber),
remark: health.remark || ''
}
},
// 证件号脱敏:仅保留前 4 位与后 4 位
maskIdNumber(idnumber) {
const value = String(idnumber || '')
if (!value) {
return '未填写'
}
if (value.length <= 8) {
return value
}
return `${value.slice(0, 4)}********${value.slice(-4)}`
},
onAdd() {
wx.navigateTo({
url: '/pages/health/profileedit'
})
},
onEdit(e) {
const id = e.currentTarget.dataset.id
wx.navigateTo({
url: `/pages/health/profileedit?id=${id}`
})
},
onDelete(e) {
const id = e.currentTarget.dataset.id
wx.showModal({
title: '删除确认',
content: '删除后该就诊人信息将无法恢复,确定删除吗?',
confirmColor: '#D4A853',
success: (res) => {
if (!res.confirm) {
return
}
API.healthProfile.deleteMyProfile(id)
.then((result) => {
if (result.code !== 0) {
wx.showToast({
title: result.msg || '删除失败',
icon: 'none'
})
return
}
wx.showToast({
title: '已删除',
icon: 'success'
})
this.loadProfiles()
})
.catch((err) => {
console.log('删除健康档案失败', err)
wx.showToast({
title: '网络请求失败',
icon: 'none'
})
})
}
})
}
})
+8
View File
@@ -0,0 +1,8 @@
{
"navigationBarTitleText": "健康档案",
"usingComponents": {
"t-icon": "tdesign-miniprogram/icon/icon"
},
"enablePullDownRefresh": true,
"backgroundTextStyle": "dark"
}
+66
View File
@@ -0,0 +1,66 @@
<view class="container">
<!-- 顶部说明 -->
<view class="page-tip" wx:if="{{profiles.length > 0}}">
<t-icon name="info-circle" size="28rpx" color="#D4A853" />
<text class="page-tip-text">下单时可直接选择已保存的就诊人,无需重复填写</text>
</view>
<!-- 就诊人列表 -->
<view class="profile-list" wx:if="{{profiles.length > 0}}">
<view class="profile-card" wx:for="{{profiles}}" wx:key="_id" data-id="{{item._id}}" bindtap="onEdit">
<view class="card-header">
<view class="name-wrap">
<text class="profile-name">{{item.name}}</text>
<text class="sex-tag" wx:if="{{item.sexText}}">{{item.sexText}}</text>
</view>
<view class="delete-btn" data-id="{{item._id}}" catchtap="onDelete">
<t-icon name="delete" size="32rpx" color="#9CA3AF" />
</view>
</view>
<view class="card-body">
<view class="info-row">
<text class="info-label">出生年月</text>
<text class="info-value">{{item.birth || '未填写'}}</text>
</view>
<view class="info-row">
<text class="info-label">联系电话</text>
<text class="info-value">{{item.mobile || '未填写'}}</text>
</view>
<view class="info-row">
<text class="info-label">证件号</text>
<text class="info-value">{{item.idnumberText}}</text>
</view>
<view class="info-row" wx:if="{{item.remark}}">
<text class="info-label">健康备注</text>
<text class="info-value">{{item.remark}}</text>
</view>
</view>
</view>
</view>
<!-- 空状态 -->
<view class="empty-state" wx:if="{{!loading && profiles.length === 0}}">
<t-icon name="file-safety" size="120rpx" color="#D1D5DB" />
<text class="empty-text">还没有健康档案</text>
<text class="empty-subtext">添加就诊人后,下单时可一键带入信息</text>
</view>
<!-- 加载中 -->
<view class="loading-wrap" wx:if="{{loading}}">
<t-loading theme="circular" size="40rpx" text="加载中..." />
</view>
<!-- 底部留白,避免被固定按钮遮挡 -->
<view class="bottom-space"></view>
<!-- 新增按钮 -->
<view class="footer-bar">
<view class="add-btn" bindtap="onAdd">
<t-icon name="add" size="34rpx" color="#FFFFFF" />
<text class="add-btn-text">新增就诊人</text>
</view>
</view>
</view>
+166
View File
@@ -0,0 +1,166 @@
page {
background-color: #FAF6F1;
}
.container {
min-height: 100vh;
}
/* 顶部说明条 */
.page-tip {
display: flex;
align-items: center;
margin: 24rpx 24rpx 0;
padding: 20rpx 24rpx;
border-radius: 16rpx;
background: #FDF8EE;
}
.page-tip-text {
margin-left: 12rpx;
font-size: 24rpx;
color: #A1864B;
line-height: 1.5;
}
/* 就诊人列表 */
.profile-list {
padding: 20rpx 24rpx;
display: flex;
flex-direction: column;
gap: 20rpx;
}
.profile-card {
background: #FFFFFF;
border-radius: 20rpx;
padding: 28rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.04);
}
.profile-card:active {
background: #FDFCFA;
}
.card-header {
display: flex;
align-items: center;
justify-content: space-between;
padding-bottom: 20rpx;
margin-bottom: 20rpx;
border-bottom: 1rpx solid #F3F4F6;
}
.name-wrap {
display: flex;
align-items: center;
}
.profile-name {
font-size: 32rpx;
font-weight: 600;
color: #1F2937;
}
.sex-tag {
margin-left: 16rpx;
padding: 2rpx 14rpx;
border-radius: 8rpx;
background: #FDF8EE;
color: #D4A853;
font-size: 22rpx;
font-weight: 600;
}
.delete-btn {
padding: 8rpx 0 8rpx 24rpx;
}
.card-body {
display: flex;
flex-direction: column;
gap: 16rpx;
}
.info-row {
display: flex;
align-items: flex-start;
}
.info-label {
font-size: 26rpx;
color: #9CA3AF;
width: 140rpx;
flex-shrink: 0;
}
.info-value {
font-size: 26rpx;
color: #374151;
flex: 1;
word-break: break-all;
}
/* 空状态 */
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding-top: 200rpx;
}
.empty-text {
font-size: 30rpx;
color: #9CA3AF;
margin-top: 24rpx;
}
.empty-subtext {
font-size: 26rpx;
color: #D1D5DB;
margin-top: 12rpx;
}
/* 加载中 */
.loading-wrap {
display: flex;
align-items: center;
justify-content: center;
padding: 40rpx;
}
.bottom-space {
height: 180rpx;
}
/* 底部固定新增按钮 */
.footer-bar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
padding: 20rpx 24rpx calc(20rpx + env(safe-area-inset-bottom));
background: rgba(255, 255, 255, 0.96);
box-shadow: 0 -2rpx 16rpx rgba(0, 0, 0, 0.05);
}
.add-btn {
display: flex;
align-items: center;
justify-content: center;
height: 88rpx;
border-radius: 44rpx;
background: #D4A853;
}
.add-btn:active {
opacity: 0.85;
}
.add-btn-text {
margin-left: 8rpx;
font-size: 30rpx;
font-weight: 600;
color: #FFFFFF;
}