diff --git a/_verify.ps1 b/_verify.ps1 new file mode 100644 index 0000000..fa65c5a --- /dev/null +++ b/_verify.ps1 @@ -0,0 +1,7 @@ +Add-Type -AssemblyName System.Drawing +$bmp = [System.Drawing.Bitmap]::FromFile('d:\work\health\code\ws_health\ui\wxapp_escort\images\home-green.png') +$p = $bmp.GetPixel(64, 64) +Write-Host "home-green center: $($p.R),$($p.G),$($p.B)" +$bmp.Dispose() +Remove-Item 'd:\work\health\code\ws_health\ui\wxapp_escort\_reicon.ps1', 'd:\work\health\code\ws_health\ui\wxapp_escort\_sample.ps1' -ErrorAction SilentlyContinue +Write-Host 'temp scripts cleaned' \ No newline at end of file diff --git a/_verify2.ps1 b/_verify2.ps1 new file mode 100644 index 0000000..848a73c --- /dev/null +++ b/_verify2.ps1 @@ -0,0 +1,17 @@ +Add-Type -AssemblyName System.Drawing +foreach ($n in 'home-green', 'ai-green', 'mine-green') { + $bmp = [System.Drawing.Bitmap]::FromFile("d:\work\health\code\ws_health\ui\wxapp_escort\images\$n.png") + $counts = @{} + for ($x = 0; $x -lt $bmp.Width; $x += 2) { + for ($y = 0; $y -lt $bmp.Height; $y += 2) { + $p = $bmp.GetPixel($x, $y) + if ($p.A -lt 128) { continue } + $key = '{0},{1},{2}' -f $p.R, $p.G, $p.B + $counts[$key] = [int]$counts[$key] + 1 + } + } + $top = $counts.GetEnumerator() | Sort-Object Value -Descending | Select-Object -First 2 + $line = ($top | ForEach-Object { "$($_.Key)=$($_.Value)" }) -join ' ' + Write-Host "$n : $line" + $bmp.Dispose() +} \ No newline at end of file diff --git a/app.json b/app.json index 963839f..69bba56 100644 --- a/app.json +++ b/app.json @@ -7,21 +7,26 @@ "pages/escort/recordlist", "pages/escort/agreement", "pages/escort/recorddetail", + "pages/escort/guide", + "pages/health/profilelist", + "pages/health/profileedit", "pages/mine/mine", "pages/mine/about", + "pages/mine/contact", "pages/hospital/contact", "pages/hospital/ranking", "pages/home/webview" ], "window": { "backgroundTextStyle": "light", - "navigationBarBackgroundColor": "#FFFFFF", + "navigationBarBackgroundColor": "#FAFAF9", "navigationBarTitleText": "暖橙陪诊", "navigationBarTextStyle": "black" }, "tabBar": { + "custom": true, "color": "#999999", - "selectedColor": "#2D6A4F", + "selectedColor": "#C2410C", "backgroundColor": "#FFFFFF", "borderStyle": "black", "list": [ diff --git a/app.wxss b/app.wxss index 6dd876b..f7113ed 100644 --- a/app.wxss +++ b/app.wxss @@ -1,22 +1,29 @@ /**app.wxss**/ page { - --td-brand-color-1: #fff8f0; - --td-brand-color-2: #ffe8d4; - --td-brand-color-3: #ffd4a8; - --td-brand-color-4: #ffbb72; - --td-brand-color-5: #ff9b33; - --td-brand-color-6: #ff8500; - --td-brand-color-7: #FF9B33; - --td-brand-color-8: #e68600; - --td-brand-color-9: #cc6e00; - --td-brand-color-10: #a35700; + /* 品牌翠绿:#22A45D 为基准色(第 7 档),向浅/深各展开数档。 + 首页主视觉已确定该绿为品牌主色,全站令牌与之对齐, + 避免二级页沿用旧橙色造成首页与内页两套配色。 */ + --td-brand-color-1: #f0faf3; + --td-brand-color-2: #dcf3e3; + --td-brand-color-3: #bce6cb; + --td-brand-color-4: #8ed6a9; + --td-brand-color-5: #5cc387; + --td-brand-color-6: #3bb471; + --td-brand-color-7: #22a45d; + --td-brand-color-8: #1b8550; + --td-brand-color-9: #166940; + --td-brand-color-10: #114f31; --td-brand-color: var(--td-brand-color-7); --td-brand-color-active: var(--td-brand-color-8); --td-brand-color-disabled: var(--td-brand-color-3); --td-brand-color-light: var(--td-brand-color-1); --td-brand-color-light-active: var(--td-brand-color-2); - background-color: #FAF6F1; + + /* 深锚点:用于标题、Logo 文字等需要"分量"的地方,压住整页的重心 */ + --c-ink: #1c1917; + + background-color: #ffffff; font-family: -apple-system, PingFang SC, Microsoft YaHei, sans-serif; } diff --git a/custom-tab-bar/index.js b/custom-tab-bar/index.js new file mode 100644 index 0000000..2eb27f7 --- /dev/null +++ b/custom-tab-bar/index.js @@ -0,0 +1,39 @@ +// 自定义 tabBar:原生 tabBar 只能放 PNG 位图,三个图标分别是 +// 实心"手托心" / 气泡里塞"AI"字 / 线框人形,风格互相打架。 +// 改用 TDesign 图标字体后,三个 tab 走同一套线性笔触,只靠颜色区分选中态。 +Component({ + data: { + selected: 0, // 当前选中项,由各 tab 页在 onShow 里同步 + activeColor: '#C2410C', // 选中:暖橙深一档,白底 4.69:1,过 WCAG AA 正文标准 + inactiveColor: '#7A7068', // 未选中:暖灰,白底 4.83:1,过 WCAG AA 正文标准 + list: [{ + pagePath: '/pages/home/index', + text: '首页', + icon: 'home' + }, { + pagePath: '/pages/ai/aichat', + text: 'AI客服', + icon: 'chat' + }, { + pagePath: '/pages/mine/mine', + text: '我的', + icon: 'user' + }] + }, + + methods: { + onTap(e) { + const { + index, + path + } = e.currentTarget.dataset + // 重复点击当前 tab 不做跳转,避免页面被重置 + if (index === this.data.selected) { + return + } + wx.switchTab({ + url: path + }) + } + } +}) diff --git a/custom-tab-bar/index.json b/custom-tab-bar/index.json new file mode 100644 index 0000000..3fb9848 --- /dev/null +++ b/custom-tab-bar/index.json @@ -0,0 +1,6 @@ +{ + "component": true, + "usingComponents": { + "t-icon": "tdesign-miniprogram/icon/icon" + } +} diff --git a/custom-tab-bar/index.wxml b/custom-tab-bar/index.wxml new file mode 100644 index 0000000..ba2c2c5 --- /dev/null +++ b/custom-tab-bar/index.wxml @@ -0,0 +1,18 @@ + + + + + {{ item.text }} + + diff --git a/custom-tab-bar/index.wxss b/custom-tab-bar/index.wxss new file mode 100644 index 0000000..9a62334 --- /dev/null +++ b/custom-tab-bar/index.wxss @@ -0,0 +1,33 @@ +/* 自定义 tabBar 脱离文档流,fixed 在底部; + 各 tab 页需自备底部占位(见 home / aichat / mine 的底部留白),否则内容会被盖住 */ +.tab-bar { + position: fixed; + left: 0; + right: 0; + bottom: 0; + z-index: 100; + display: flex; + padding: 12rpx 0 calc(12rpx + env(safe-area-inset-bottom)); + background: #FFFFFF; + border-top: 2rpx solid #F0E9E0; +} + +.tab-item { + flex: 1; + display: flex; + flex-direction: column; + align-items: center; +} + +.tab-text { + margin-top: 6rpx; + /* 与全局约束一致:中文正文不小于 24rpx(12px) */ + font-size: 24rpx; + line-height: 1; + color: #7A7068; +} + +.tab-item.is-active .tab-text { + color: #C2410C; + font-weight: 600; +} diff --git a/images/ai-green.png b/images/ai-green.png index 1c9a811..310f335 100644 Binary files a/images/ai-green.png and b/images/ai-green.png differ diff --git a/images/ai-ink.png b/images/ai-ink.png new file mode 100644 index 0000000..51b9e15 Binary files /dev/null and b/images/ai-ink.png differ diff --git a/images/home-green.png b/images/home-green.png index 246243a..50c67b5 100644 Binary files a/images/home-green.png and b/images/home-green.png differ diff --git a/images/mine-green.png b/images/mine-green.png index 57d8297..a0468d0 100644 Binary files a/images/mine-green.png and b/images/mine-green.png differ diff --git a/pages/ai/aichat.js b/pages/ai/aichat.js index 89ca034..7e186c6 100644 --- a/pages/ai/aichat.js +++ b/pages/ai/aichat.js @@ -28,6 +28,12 @@ Page({ onShow() { this.getAiQuickQuestions() this.setData({ inputFocus: true }) + // 同步自定义 tabBar 选中态(AI客服为第 1 项) + if (typeof this.getTabBar === 'function' && this.getTabBar()) { + this.getTabBar().setData({ + selected: 1 + }) + } }, // 获取陪诊服务问题 diff --git a/pages/ai/aichat.wxss b/pages/ai/aichat.wxss index 3f9dfda..1139f12 100644 --- a/pages/ai/aichat.wxss +++ b/pages/ai/aichat.wxss @@ -2,6 +2,9 @@ display: flex; flex-direction: column; height: 100vh; + box-sizing: border-box; + /* 给 fixed 的自定义 tabBar 留位;安全区由这里统一承担,输入区不再重复加 */ + padding-bottom: calc(140rpx + env(safe-area-inset-bottom)); background-color: #F5F5F5; position: relative; } @@ -289,7 +292,6 @@ .input-area { background-color: #FFFFFF; padding: 20rpx 24rpx; - padding-bottom: calc(20rpx + env(safe-area-inset-bottom)); border-top: 1rpx solid #EEEEEE; } @@ -337,7 +339,6 @@ /* AI声明 */ .ai-disclaimer { padding: 12rpx 24rpx; - padding-bottom: calc(12rpx + env(safe-area-inset-bottom)); text-align: center; background-color: #F5F5F5; } diff --git a/pages/escort/guide.js b/pages/escort/guide.js new file mode 100644 index 0000000..8ef3526 --- /dev/null +++ b/pages/escort/guide.js @@ -0,0 +1,72 @@ +// pages/escort/guide.js + +// 人工客服电话:与首页、关于我们保持一致 +const SERVICE_PHONE = '18618162956' + +Page({ + data: { + // 服务流程:与 itemdetail 的「服务流程」同构,这里只描述通用环节 + steps: [{ + title: '线上预约', + desc: '选择服务项目,填写就诊医院、科室与时间' + }, + { + title: '需求确认', + desc: '客服电话核对就诊信息与特殊需求' + }, + { + title: '陪诊师接单', + desc: '按需求匹配陪诊师,出发前与您联系' + }, + { + title: '全程陪同', + desc: '取号、缴费、检查、取药全程有人陪' + }, + { + title: '服务完成', + desc: '确认服务结果,客服回访并处理售后' + } + ], + // 就诊前准备:到院前建议提前备齐的材料 + preparations: [ + '就诊人身份证、医保卡(或电子医保凭证)', + '既往病历、检查报告与影像资料', + '需要空腹的项目,就诊当天请勿进食进水', + '长期服用的药物清单,方便医生了解用药情况', + '提前与陪诊师确认医院、院区与集合地点' + ], + // 温馨提示:通用提醒,不涉及具体退款或收费规则 + tips: [ + '建议比预约时间提前 10-15 分钟到达集合点', + '贵重物品与重要证件请自行随身保管', + '就诊时间或需求有变化,请尽早联系客服调整' + ] + }, + + // 下一步:进入陪诊服务列表 + goToServiceList() { + wx.navigateTo({ + url: '/pages/escort/itemlist' + }) + }, + + // 兜底出口:仍有疑问可直接拨打客服电话 + goToContact() { + wx.makePhoneCall({ + phoneNumber: SERVICE_PHONE + }) + }, + + onShareAppMessage() { + return { + title: '暖橙陪诊 · 陪诊指南', // 转发标题 + path: '/pages/escort/guide' + } + }, + + onShareTimeline() { + return { + title: '暖橙陪诊 · 陪诊指南' + } + } +}) diff --git a/pages/escort/guide.json b/pages/escort/guide.json new file mode 100644 index 0000000..316990a --- /dev/null +++ b/pages/escort/guide.json @@ -0,0 +1,6 @@ +{ + "navigationBarTitleText": "陪诊指南", + "usingComponents": { + "t-icon": "tdesign-miniprogram/icon/icon" + } +} diff --git a/pages/escort/guide.wxml b/pages/escort/guide.wxml new file mode 100644 index 0000000..55c7efe --- /dev/null +++ b/pages/escort/guide.wxml @@ -0,0 +1,75 @@ + + + + + + + + 陪诊指南 + 第一次用陪诊?三分钟看懂全流程 + + + + + + + + + 服务流程 + + + + {{ index + 1 }} + + {{ item.title }} + {{ item.desc }} + + + + + + + + + + + + 就诊前准备 + + + + + {{ item }} + + + + + + + + + + + 温馨提示 + + + + + {{ item }} + + + + + + + 查看陪诊服务 + + + + + 还有疑问?联系人工客服 + + + + + diff --git a/pages/escort/guide.wxss b/pages/escort/guide.wxss new file mode 100644 index 0000000..d04059a --- /dev/null +++ b/pages/escort/guide.wxss @@ -0,0 +1,207 @@ +/* pages/escort/guide.wxss + 内页规范:小色带 + 白底,不用整块主色面板; + 卡片沿用首页「发丝边 + 紧阴影」,与首页保持同一套视觉语言 */ +page { + --brand-strong: #C2410C; /* 实心块/按钮:白字 4.69:1,过 AA 正文 */ + --brand-soft: #FFF4E8; /* 图标衬底、标签底 */ + --brand-line: #FFE0C2; /* 浅橙衬底描边 */ + --brand-ink: #9A3412; /* 浅橙衬底上的文字/图标:6.8:1,过 AA */ + + --ink: #2B2521; + --ink-2: #4A4038; + --muted: #7A7068; /* 白底 4.8:1,过 AA 正文 */ + --line: #F0E9E0; /* 米色发丝边 */ + --paper: #FAF6F0; /* 暖白纸面 */ + --white: #FFFFFF; + + --shadow-card: 0 2rpx 10rpx rgba(63, 43, 25, 0.04); + + background-color: var(--paper); +} + +.page-bg { + min-height: 100vh; + background: var(--paper); +} + +.container { + padding: 32rpx 32rpx 0; +} + +/* ===== 头部:小色带 + 深墨标题 ===== */ +.page-header { + padding: 24rpx 0 8rpx; +} + +.header-accent { + width: 64rpx; + height: 8rpx; + border-radius: 4rpx; + background: var(--brand-strong); +} + +.header-title { + display: block; + margin-top: 20rpx; + font-size: 46rpx; + font-weight: 700; + color: var(--ink); + letter-spacing: 1rpx; +} + +.header-subtitle { + display: block; + margin-top: 12rpx; + font-size: 26rpx; + color: var(--muted); + letter-spacing: 1rpx; +} + +/* ===== 通用白卡 ===== */ +.card { + margin-top: 32rpx; + padding: 28rpx 26rpx; + border-radius: 28rpx; + background: var(--white); + border: 2rpx solid var(--line); + box-shadow: var(--shadow-card); +} + +.card-head { + display: flex; + align-items: center; + margin-bottom: 20rpx; +} + +.card-mark { + width: 44rpx; + height: 44rpx; + border-radius: 12rpx; + background: var(--brand-strong); + display: flex; + align-items: center; + justify-content: center; + flex-shrink: 0; +} + +.card-title { + margin-left: 14rpx; + font-size: 32rpx; + font-weight: 700; + color: var(--ink); + letter-spacing: 1rpx; +} + +/* ===== 服务流程:左侧序号 + 递进条目 ===== */ +.step-item { + display: flex; + padding: 18rpx 0; +} + +.step-index { + width: 44rpx; + height: 44rpx; + border-radius: 50%; + background: var(--brand-soft); + color: var(--brand-ink); + font-size: 26rpx; + font-weight: 700; + display: flex; + align-items: center; + justify-content: center; + flex-shrink: 0; + margin-right: 20rpx; +} + +.step-body { + display: flex; + flex-direction: column; + flex: 1; + min-width: 0; +} + +.step-title { + font-size: 30rpx; + font-weight: 600; + color: var(--ink); +} + +.step-desc { + margin-top: 8rpx; + font-size: 26rpx; + color: var(--muted); + line-height: 1.6; +} + +/* ===== 要点列表 ===== */ +.dot-item { + display: flex; + padding: 12rpx 0; +} + +.dot { + width: 10rpx; + height: 10rpx; + border-radius: 50%; + background: var(--brand-strong); + margin: 16rpx 18rpx 0 4rpx; + flex-shrink: 0; +} + +.dot-text { + flex: 1; + font-size: 28rpx; + color: var(--ink-2); + line-height: 1.7; +} + +/* ===== 底部出口 ===== */ +.guide-cta { + display: flex; + align-items: center; + justify-content: center; + margin-top: 48rpx; + padding: 26rpx; + border-radius: 999rpx; + background: var(--brand-strong); + box-shadow: 0 6rpx 16rpx rgba(194, 65, 12, 0.22); + transition: transform 0.15s ease; +} + +.guide-cta:active { + transform: scale(0.98); +} + +.guide-cta-text { + font-size: 30rpx; + font-weight: 600; + color: var(--white); + letter-spacing: 2rpx; + margin-right: 6rpx; +} + +.guide-help { + display: flex; + align-items: center; + justify-content: center; + margin-top: 24rpx; + padding: 22rpx; + border-radius: 20rpx; + background: var(--brand-soft); + border: 2rpx solid var(--brand-line); +} + +.guide-help:active { + opacity: 0.75; +} + +.guide-help-text { + margin-left: 12rpx; + font-size: 26rpx; + font-weight: 600; + color: var(--brand-ink); +} + +.footer-space { + height: 60rpx; +} diff --git a/pages/escort/itemdetail.js b/pages/escort/itemdetail.js index 05e6120..ac9a374 100644 --- a/pages/escort/itemdetail.js +++ b/pages/escort/itemdetail.js @@ -15,6 +15,8 @@ Page({ }, totalPrice: '0.00', showOrderPopup: false, + profiles: [], // 健康档案里已保存的就诊人 + selectedProfileId: '', // 当前选中的就诊人档案 ID,为空表示手动填写 patientName: '', patientPhone: '', province: '', @@ -48,6 +50,13 @@ Page({ this.loadServiceDetail(serviceId) }, + onShow() { + // 从"新增就诊人"页面返回时,弹窗还开着就刷新一次可选的就诊人 + if (this.data.showOrderPopup) { + this.loadProfiles() + } + }, + loadServiceDetail(id) { const app = getApp() let service = null @@ -86,8 +95,57 @@ Page({ this.setData({ patientName: user.profile?.name || '', patientPhone: user.profile?.mobile || '', + selectedProfileId: '', showOrderPopup: true }) + + this.loadProfiles() + }, + + // 读取已保存的就诊人,供弹窗内一键选择 + loadProfiles() { + API.healthProfile.getMyProfiles({ + page: 1, + pageSize: 20 + }) + .then((res) => { + if (res.code !== 0) { + return + } + const list = ((res.data && res.data.list) || []).map((item) => ({ + _id: item._id, + name: item.profile?.name || '', + mobile: item.profile?.mobile || '' + })) + this.setData({ + profiles: list + }) + }) + .catch((err) => { + console.log('获取就诊人列表失败', err) + }) + }, + + // 选择就诊人:自动带入姓名与联系电话 + onSelectProfile(e) { + const id = e.currentTarget.dataset.id + const profile = this.data.profiles.find((item) => item._id === id) + if (!profile) { + return + } + + this.setData({ + selectedProfileId: id, + patientName: profile.name, + patientPhone: profile.mobile + }) + }, + + // 跳转到健康档案新增就诊人 + goToAddProfile() { + wx.navigateTo({ + url: '/pages/health/profileedit' + }) }, closeOrderPopup() { @@ -96,15 +154,18 @@ Page({ }) }, + // 手动修改姓名/电话后,不再与所选档案对应,清空选择避免存档信息不一致 onPatientNameChange(e) { this.setData({ - patientName: e.detail.value + patientName: e.detail.value, + selectedProfileId: '' }) }, onPatientPhoneChange(e) { this.setData({ - patientPhone: e.detail.value + patientPhone: e.detail.value, + selectedProfileId: '' }) }, @@ -256,6 +317,11 @@ Page({ } } + // 选择了已保存的就诊人时,一并记录档案 ID + if (this.data.selectedProfileId) { + orderData.healthProfileId = this.data.selectedProfileId + } + wx.showLoading({ title: '提交中...' }) @@ -292,6 +358,7 @@ Page({ resetForm() { this.setData({ + selectedProfileId: '', patientName: '', patientPhone: '', province: '', diff --git a/pages/escort/itemdetail.wxml b/pages/escort/itemdetail.wxml index 6b00284..a746d47 100644 --- a/pages/escort/itemdetail.wxml +++ b/pages/escort/itemdetail.wxml @@ -96,6 +96,26 @@ + + + 选择就诊人 + + + + {{item.name}} + {{item.mobile}} + + + + 添加就诊人 + + + + + 还没有就诊人,去添加后可一键带入 › + + + 就诊人姓名 diff --git a/pages/escort/itemdetail.wxss b/pages/escort/itemdetail.wxss index d82ea61..1e459b2 100644 --- a/pages/escort/itemdetail.wxss +++ b/pages/escort/itemdetail.wxss @@ -493,3 +493,63 @@ page { .popup-submit-btn::after { border: none; } + +/* 就诊人选择 */ +.patient-scroll { + width: 100%; + white-space: nowrap; +} + +.patient-chips { + display: inline-flex; + gap: 16rpx; +} + +.patient-chip { + display: inline-flex; + flex-direction: column; + min-width: 160rpx; + padding: 14rpx 24rpx; + border-radius: 16rpx; + background: #F9FAFB; + border: 2rpx solid #F3F4F6; + box-sizing: border-box; +} + +.patient-chip.active { + background: #FDF8EE; + border-color: #D4A853; +} + +.patient-chip-name { + font-size: 26rpx; + color: #374151; + font-weight: 600; +} + +.patient-chip.active .patient-chip-name { + color: #D4A853; +} + +.patient-chip-phone { + font-size: 22rpx; + color: #9CA3AF; + margin-top: 6rpx; +} + +.patient-chip-add { + justify-content: center; +} + +.add-profile-tip { + width: 100%; + padding: 18rpx 24rpx; + border-radius: 16rpx; + background: #FDF8EE; + box-sizing: border-box; +} + +.add-profile-tip-text { + font-size: 24rpx; + color: #A1864B; +} diff --git a/pages/escort/itemlist.json b/pages/escort/itemlist.json index 9172073..fb6ae7f 100644 --- a/pages/escort/itemlist.json +++ b/pages/escort/itemlist.json @@ -1,4 +1,4 @@ { "usingComponents": {}, - "navigationBarTitleText": "助诊服务" + "navigationBarTitleText": "陪诊服务" } \ No newline at end of file diff --git a/pages/health/profileedit.js b/pages/health/profileedit.js new file mode 100644 index 0000000..67e1986 --- /dev/null +++ b/pages/health/profileedit.js @@ -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 + }) + }) + } +}) diff --git a/pages/health/profileedit.json b/pages/health/profileedit.json new file mode 100644 index 0000000..b623dbf --- /dev/null +++ b/pages/health/profileedit.json @@ -0,0 +1,6 @@ +{ + "navigationBarTitleText": "新增就诊人", + "usingComponents": { + "t-icon": "tdesign-miniprogram/icon/icon" + } +} diff --git a/pages/health/profileedit.wxml b/pages/health/profileedit.wxml new file mode 100644 index 0000000..e114b2f --- /dev/null +++ b/pages/health/profileedit.wxml @@ -0,0 +1,62 @@ + + + + + 姓名* + + + + + 性别 + + + {{item.label}} + + + + + + 出生年月 + + + {{form.birth || '请选择出生年月'}} + + + + + + 联系电话* + + + + + 证件号 + + + + + + + 健康备注 +