my-doctor.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. <template>
  2. <CustomNav title="我的医生" leftType="back" />
  3. <view class="page-container">
  4. <view class="doctor-card" v-if="doctorInfo">
  5. <view class="doctor-header">
  6. <view class="avatar-section">
  7. <view class="avatar-frame">
  8. <image class="avatar-img" :src="doctorAvatar" mode="aspectFill" />
  9. </view>
  10. </view>
  11. <view class="doctor-info">
  12. <text class="doctor-name">{{ doctorInfo.name }}</text>
  13. <!-- 根据当前API返回数据,只显示姓名和电话 -->
  14. <text class="doctor-phone" v-if="doctorInfo.phone">联系电话: {{ doctorInfo.phone }}</text>
  15. <text class="doctor-phone" v-else>联系电话: 未提供</text>
  16. </view>
  17. </view>
  18. <!-- 复诊记录 -->
  19. <view class="followup-section" v-show="followUps.length > 0">
  20. <view class="section-title">我的复诊记录</view>
  21. <view class="followup-list">
  22. <view class="followup-card" v-for="followUp in followUps" :key="followUp.id">
  23. <view class="card-header">
  24. <view class="status-badge" :class="followUp.status">
  25. {{ getFollowUpStatusText(followUp.status) }}
  26. </view>
  27. </view>
  28. <view class="card-content">
  29. <view class="info-row">
  30. <text class="info-label">预约时间:</text>
  31. <text class="info-value">{{ formatDate(followUp.appointmentTime) }}</text>
  32. </view>
  33. <view class="info-row" v-if="followUp.reason">
  34. <text class="info-label">复诊原因:</text>
  35. <text class="info-value reason-text">{{ followUp.reason }}</text>
  36. </view>
  37. <!-- 操作按钮:仅对PENDING和CONFIRMED状态显示 -->
  38. <view class="action-row" v-if="followUp.status === 'PENDING' || followUp.status === 'CONFIRMED'">
  39. <button class="action-btn secondary" @click="editFollowUp(followUp)">编辑</button>
  40. <button class="action-btn cancel" @click="cancelFollowUp(followUp.id)">取消</button>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="action-buttons" v-if="!hasPendingOrConfirmedFollowUp">
  47. <button class="action-btn primary" @click="makeAppointment">预约复诊</button>
  48. </view>
  49. </view>
  50. <view class="empty-state" v-else>
  51. <image class="empty-icon" src="/static/icons/remixicon/account-circle-line.svg" />
  52. <text class="empty-text">暂无绑定的医生</text>
  53. <button class="bind-btn" @click="bindDoctor">绑定医生</button>
  54. </view>
  55. </view>
  56. </template>
  57. <script setup lang="ts">
  58. import { ref, computed, onMounted } from 'vue'
  59. import { onLoad, onShow } from '@dcloudio/uni-app'
  60. import CustomNav from '@/components/custom-nav.vue'
  61. import { listUserBindingsByPatient, type UserBindingResponse, type UserBindingPageResponse } from '@/api/userBinding'
  62. import { downloadAvatar } from '@/api/user'
  63. import { getFollowUpList, updateFollowUp, deleteFollowUp } from '@/api/followUp'
  64. import type { FollowUp } from '@/api/followUp'
  65. import { formatDate } from '@/utils/date'
  66. // 简化医生信息接口,只包含API实际返回的字段
  67. interface LocalDoctorInfo {
  68. id: string
  69. name: string
  70. phone?: string
  71. avatar?: string
  72. }
  73. const doctorInfo = ref<LocalDoctorInfo | null>(null)
  74. const userBindings = ref<UserBindingResponse[]>([])
  75. const pageData = ref({
  76. pageNum: 1,
  77. pageSize: 10,
  78. total: 0,
  79. pages: 0
  80. })
  81. // 复诊记录相关
  82. const followUps = ref<FollowUp[]>([])
  83. // 计算是否有待处理或已确认的复诊请求
  84. const hasPendingOrConfirmedFollowUp = computed(() => {
  85. return followUps.value.some(followUp =>
  86. followUp.status === 'PENDING' || followUp.status === 'CONFIRMED'
  87. )
  88. })
  89. // 调试信息
  90. const debugInfo = ref('')
  91. const defaultAvatar = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
  92. // 下载后本地临时保存的图片路径(uni.downloadFile 会产出 tempFilePath)
  93. const downloadedAvatar = ref<string | null>(null)
  94. // 优先使用已下载的本地头像,若无则使用后端返回的 avatar 字段,再次 fallback 到默认头像
  95. const doctorAvatar = computed(() => {
  96. if (downloadedAvatar.value) {
  97. return downloadedAvatar.value
  98. }
  99. if (doctorInfo.value?.avatar) {
  100. return doctorInfo.value.avatar
  101. }
  102. return defaultAvatar
  103. })
  104. // 获取医生信息
  105. const fetchDoctorInfo = async () => {
  106. uni.showLoading({ title: '加载中...' })
  107. try {
  108. const token = uni.getStorageSync('token')
  109. if (!token) {
  110. uni.hideLoading()
  111. uni.showToast({
  112. title: '未登录',
  113. icon: 'none'
  114. })
  115. return
  116. }
  117. // 获取当前用户ID
  118. const userInfo = uni.getStorageSync('user_info')
  119. const patientUserId = userInfo?.id
  120. if (!patientUserId) {
  121. uni.hideLoading()
  122. uni.showToast({
  123. title: '获取用户信息失败',
  124. icon: 'none'
  125. })
  126. return
  127. }
  128. // 查询患者绑定的医生列表
  129. const doctorResponse = await listUserBindingsByPatient(
  130. patientUserId,
  131. 'DOCTOR',
  132. {
  133. pageNum: pageData.value.pageNum,
  134. pageSize: pageData.value.pageSize
  135. }
  136. )
  137. uni.hideLoading()
  138. const resp = doctorResponse.data as any
  139. if (resp && resp.code === 200 && resp.data) {
  140. const pageResult = resp.data as UserBindingPageResponse
  141. userBindings.value = pageResult.records
  142. pageData.value.total = pageResult.total
  143. pageData.value.pages = pageResult.pages
  144. // 如果有绑定的医生,获取第一个医生的详细信息
  145. if (pageResult.records && pageResult.records.length > 0) {
  146. const boundDoctor = pageResult.records[0]
  147. // 直接使用绑定接口返回的信息,不再调用额外的用户详情接口
  148. doctorInfo.value = {
  149. id: boundDoctor.id,
  150. name: boundDoctor.boundUserNickname || '未知医生',
  151. phone: boundDoctor.boundUserPhone || '未提供', // 当电话为null时显示"未提供"
  152. }
  153. // 尝试下载头像(绑定接口返回的数据中可能没有 avatar)
  154. try {
  155. if (boundDoctor.boundUserId) {
  156. const dlRes: any = await downloadAvatar(String(boundDoctor.boundUserId))
  157. if (dlRes && dlRes.statusCode === 200 && dlRes.tempFilePath) {
  158. downloadedAvatar.value = dlRes.tempFilePath
  159. }
  160. }
  161. } catch (err) {
  162. console.warn('下载医生头像失败:', err)
  163. }
  164. } else {
  165. doctorInfo.value = null
  166. }
  167. } else {
  168. uni.showToast({
  169. title: '获取医生信息失败',
  170. icon: 'none'
  171. })
  172. }
  173. } catch (error) {
  174. uni.hideLoading()
  175. console.error('获取医生信息失败:', error)
  176. uni.showToast({
  177. title: '获取医生信息失败',
  178. icon: 'none'
  179. })
  180. }
  181. }
  182. // 获取复诊记录
  183. const fetchFollowUpRecords = async () => {
  184. try {
  185. const followUpResponse: any = await getFollowUpList({
  186. pageNum: 1,
  187. pageSize: 10
  188. })
  189. // 检查响应结构
  190. if (!followUpResponse) {
  191. return
  192. }
  193. if (!followUpResponse.data) {
  194. return
  195. }
  196. // 注意:这里需要访问 followUpResponse.data.data 才是真正的数据
  197. const apiResponse = followUpResponse.data
  198. if (apiResponse.code !== 200) {
  199. return
  200. }
  201. // 检查实际数据字段
  202. const data = apiResponse.data
  203. if (!data) {
  204. return
  205. }
  206. if (!data.records) {
  207. return
  208. }
  209. if (!Array.isArray(data.records)) {
  210. return
  211. }
  212. // 正常处理records
  213. followUps.value = data.records || []
  214. // 隐藏加载提示(如果有)
  215. uni.hideLoading()
  216. } catch (error) {
  217. console.error('获取复诊记录失败:', error)
  218. uni.showToast({
  219. title: '获取复诊记录失败',
  220. icon: 'none'
  221. })
  222. // 隐藏加载提示(如果有)
  223. uni.hideLoading()
  224. }
  225. }
  226. const makeAppointment = () => {
  227. // 跳转到复诊申请页面,传递医生信息
  228. if (doctorInfo.value) {
  229. uni.navigateTo({
  230. url: `/pages/patient/profile/infos/followup-request?doctorId=${doctorInfo.value.id}&doctorName=${encodeURIComponent(doctorInfo.value.name)}&boundUserId=${userBindings.value[0]?.boundUserId || ''}`
  231. })
  232. } else {
  233. uni.showToast({
  234. title: '未获取到医生信息',
  235. icon: 'none'
  236. })
  237. }
  238. }
  239. const bindDoctor = () => {
  240. uni.showToast({
  241. title: '绑定医生功能开发中',
  242. icon: 'none'
  243. })
  244. }
  245. // 编辑复诊记录
  246. const editFollowUp = (followUp: FollowUp) => {
  247. // 跳转到复诊编辑页面,传递复诊记录信息
  248. uni.navigateTo({
  249. url: `/pages/patient/profile/infos/followup-edit?id=${followUp.id}&doctorId=${doctorInfo.value?.id}&doctorName=${encodeURIComponent(doctorInfo.value?.name || '')}&appointmentTime=${encodeURIComponent(followUp.appointmentTime)}&reason=${encodeURIComponent(followUp.reason || '')}&boundUserId=${userBindings.value[0]?.boundUserId || ''}`
  250. })
  251. }
  252. // 取消复诊记录
  253. const cancelFollowUp = (id: string) => {
  254. uni.showModal({
  255. title: '确认取消',
  256. content: '确定要取消这个复诊预约吗?',
  257. success: (res) => {
  258. if (res.confirm) {
  259. // 调用接口取消复诊记录
  260. updateFollowUp(id, { status: 'CANCELLED' })
  261. .then((res: any) => {
  262. if (res && res.data && res.data.code === 200) {
  263. uni.showToast({
  264. title: '取消成功',
  265. icon: 'success'
  266. })
  267. // 重新获取复诊记录列表
  268. fetchFollowUpRecords()
  269. } else {
  270. uni.showToast({
  271. title: '取消失败',
  272. icon: 'none'
  273. })
  274. }
  275. })
  276. .catch((error) => {
  277. console.error('取消复诊记录失败:', error)
  278. uni.showToast({
  279. title: '取消失败',
  280. icon: 'none'
  281. })
  282. })
  283. }
  284. }
  285. })
  286. }
  287. onLoad(() => {
  288. fetchDoctorInfo()
  289. fetchFollowUpRecords()
  290. })
  291. onShow(() => {
  292. // 页面每次显示时都刷新复诊记录列表
  293. // 这样从创建或编辑页面返回时能获取最新数据
  294. fetchFollowUpRecords()
  295. })
  296. // 获取复诊状态文本
  297. const getFollowUpStatusText = (status: string) => {
  298. switch (status) {
  299. case 'PENDING': return '待处理'
  300. case 'CONFIRMED': return '已确认'
  301. case 'CANCELLED': return '已取消'
  302. case 'COMPLETED': return '已完成'
  303. default: return status
  304. }
  305. }
  306. </script>
  307. <style scoped>
  308. .page-container {
  309. min-height: 100vh;
  310. background-color: #f5f5f5;
  311. padding-top: calc(var(--status-bar-height) + 44px);
  312. padding-bottom: 40rpx;
  313. }
  314. .doctor-card {
  315. background-color: #fff;
  316. margin: 20rpx;
  317. border-radius: 20rpx;
  318. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  319. overflow: hidden;
  320. }
  321. .doctor-header {
  322. display: flex;
  323. padding: 40rpx;
  324. border-bottom: 1rpx solid #eee;
  325. }
  326. .avatar-section {
  327. margin-right: 30rpx;
  328. }
  329. .avatar-frame {
  330. width: 120rpx;
  331. height: 120rpx;
  332. border-radius: 50%;
  333. overflow: hidden;
  334. border: 1px solid rgba(128, 128, 128, 0.5);
  335. }
  336. .avatar-img {
  337. width: 100%;
  338. height: 100%;
  339. object-fit: cover;
  340. }
  341. .doctor-info {
  342. flex: 1;
  343. display: flex;
  344. flex-direction: column;
  345. justify-content: center;
  346. }
  347. .doctor-name {
  348. font-size: 36rpx;
  349. font-weight: bold;
  350. color: #333;
  351. margin-bottom: 10rpx;
  352. }
  353. .doctor-phone {
  354. font-size: 28rpx;
  355. color: #666;
  356. }
  357. .action-buttons {
  358. display: flex;
  359. padding: 30rpx 40rpx;
  360. gap: 20rpx;
  361. }
  362. .action-btn {
  363. flex: 1;
  364. border-radius: 10rpx;
  365. font-size: 32rpx;
  366. line-height: 80rpx;
  367. }
  368. .primary {
  369. background-color: #3742fa;
  370. color: #fff;
  371. }
  372. .secondary {
  373. background-color: #f0f0f0;
  374. color: #333;
  375. }
  376. .empty-state {
  377. display: flex;
  378. flex-direction: column;
  379. align-items: center;
  380. justify-content: center;
  381. padding: 100rpx 40rpx;
  382. }
  383. .empty-icon {
  384. width: 120rpx;
  385. height: 120rpx;
  386. margin-bottom: 30rpx;
  387. opacity: 0.5;
  388. }
  389. .empty-text {
  390. font-size: 32rpx;
  391. color: #666;
  392. margin-bottom: 40rpx;
  393. }
  394. .bind-btn {
  395. background-color: #3742fa;
  396. color: #fff;
  397. border-radius: 10rpx;
  398. font-size: 32rpx;
  399. line-height: 80rpx;
  400. width: 80%;
  401. }
  402. .followup-section {
  403. margin: 0 20rpx 20rpx;
  404. background-color: #fff;
  405. border-radius: 16rpx;
  406. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  407. overflow: hidden;
  408. border: 1rpx solid #eee;
  409. }
  410. .section-title {
  411. padding: 24rpx 30rpx;
  412. font-size: 32rpx;
  413. font-weight: 500;
  414. color: #333;
  415. border-bottom: 1rpx solid #eee;
  416. }
  417. .followup-list {
  418. padding: 20rpx;
  419. }
  420. .followup-card {
  421. background: #fff;
  422. border-radius: 12rpx;
  423. box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.05);
  424. margin-bottom: 20rpx;
  425. overflow: hidden;
  426. border: 1rpx solid #eee;
  427. }
  428. .followup-card:last-child {
  429. margin-bottom: 0;
  430. }
  431. .card-header {
  432. display: flex;
  433. justify-content: space-between;
  434. align-items: center;
  435. padding: 20rpx 24rpx;
  436. background-color: #f8f9fa;
  437. border-bottom: 1rpx solid #eee;
  438. }
  439. .status-badge {
  440. font-size: 24rpx;
  441. padding: 6rpx 20rpx;
  442. border-radius: 30rpx;
  443. color: #fff;
  444. font-weight: normal;
  445. }
  446. .status-badge.PENDING {
  447. background-color: #ff9500;
  448. }
  449. .status-badge.CONFIRMED {
  450. background-color: #007aff;
  451. }
  452. .status-badge.COMPLETED {
  453. background-color: #34c759;
  454. }
  455. .status-badge.CANCELLED {
  456. background-color: #8e8e93;
  457. }
  458. .appointment-time {
  459. font-size: 24rpx;
  460. color: #666;
  461. }
  462. .card-content {
  463. padding: 24rpx;
  464. }
  465. .info-row {
  466. display: flex;
  467. margin-bottom: 16rpx;
  468. align-items: flex-start;
  469. }
  470. .info-row:last-child {
  471. margin-bottom: 0;
  472. }
  473. .info-label {
  474. color: #888;
  475. font-size: 26rpx;
  476. width: 140rpx;
  477. flex-shrink: 0;
  478. }
  479. .info-value {
  480. flex: 1;
  481. color: #333;
  482. font-size: 26rpx;
  483. line-height: 1.5;
  484. }
  485. .reason-text {
  486. color: #555;
  487. }
  488. .action-row {
  489. display: flex;
  490. gap: 20rpx;
  491. margin-top: 20rpx;
  492. padding-top: 20rpx;
  493. border-top: 1rpx solid #eee;
  494. }
  495. .action-btn {
  496. flex: 1;
  497. border-radius: 10rpx;
  498. font-size: 28rpx;
  499. line-height: 70rpx;
  500. }
  501. .primary {
  502. background-color: #3742fa;
  503. color: #fff;
  504. }
  505. .secondary {
  506. background-color: #f0f0f0;
  507. color: #333;
  508. }
  509. .cancel {
  510. background-color: #ff4757;
  511. color: #fff;
  512. }
  513. .debug-info {
  514. padding: 20rpx;
  515. background-color: #ffeb3b;
  516. color: #333;
  517. font-size: 28rpx;
  518. margin: 20rpx;
  519. border-radius: 10rpx;
  520. white-space: pre-wrap;
  521. }
  522. </style>