hospital.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // hospital.js
  2. const mockData = require('../../utils/mockData.js')
  3. Page({
  4. data: {
  5. hospital: null,
  6. showCaseModal: false,
  7. selectedCase: null
  8. },
  9. onLoad(options) {
  10. const hospitalId = parseInt(options.id)
  11. const hospital = mockData.hospitals.find(h => h.id === hospitalId)
  12. if (hospital) {
  13. this.setData({
  14. hospital: hospital
  15. })
  16. } else {
  17. wx.showToast({
  18. title: '医院信息不存在',
  19. icon: 'none'
  20. })
  21. setTimeout(() => {
  22. wx.navigateBack()
  23. }, 1500)
  24. }
  25. },
  26. // 返回上一页
  27. goBack() {
  28. wx.navigateBack({
  29. delta: 1
  30. })
  31. },
  32. // 查看病历单详情
  33. viewCaseDetail(e) {
  34. const selectedCase = e.currentTarget.dataset.case
  35. this.setData({
  36. selectedCase: selectedCase,
  37. showCaseModal: true
  38. })
  39. },
  40. // 关闭病历单模态框
  41. closeCaseModal() {
  42. this.setData({
  43. showCaseModal: false,
  44. selectedCase: null
  45. })
  46. },
  47. // 从病历单下单
  48. orderFromCase() {
  49. const hospitalName = this.data.hospital.name
  50. const caseInfo = this.data.selectedCase
  51. wx.showModal({
  52. title: '确认下单',
  53. content: `确认在${hospitalName}购买病历单中的药品吗?`,
  54. success: (res) => {
  55. if (res.confirm) {
  56. this.closeCaseModal()
  57. // 跳转到下单页面
  58. wx.switchTab({
  59. url: '/pages/order/order'
  60. })
  61. // 延迟设置搜索关键词
  62. setTimeout(() => {
  63. const pages = getCurrentPages()
  64. const orderPage = pages.find(page => page.route === 'pages/order/order')
  65. if (orderPage) {
  66. orderPage.setData({
  67. currentTab: 0,
  68. hospitalKeyword: hospitalName
  69. })
  70. }
  71. }, 500)
  72. }
  73. }
  74. })
  75. }
  76. })