home.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  2. import { DraggableSheetBehavior, getDraggableSheetContext } from "../../../../core/behavior/draggableSheet.behavior";
  3. // module/health/pages/home/home.ts
  4. import { toPatientPage, toReportPage, toSchemePage } from "../../router";
  5. import { healthIndexMethod, healthPatientMethod, healthReportListMethod, healthReportMethod } from "../../request";
  6. import { healthIndex2Progress } from "../../tools/health-index";
  7. import { getTickleContext } from "../../../../core/behavior/tickle.behavior";
  8. Component({
  9. behaviors: [
  10. PageContainerBehavior,
  11. DraggableSheetBehavior('.health-report-list'),
  12. ],
  13. lifetimes: {
  14. attached() {
  15. this.getHealthPatient();
  16. this.getHealthReport();
  17. this.getHealthIndex();
  18. }
  19. },
  20. pageLifetimes: {
  21. hide() { this.hideDraggableSheet({}); }
  22. },
  23. properties: {},
  24. observers: {
  25. 'healthReport.data'(data) {
  26. this.setData({ healthId: data?.healthAnalysisReportId })
  27. }
  28. },
  29. data: {
  30. healthId: '',
  31. healthPatient: { data: null, loading: false, message: '' },
  32. healthIndex: { data: [], loading: false, message: '' },
  33. healthReport: { data: null, loading: false, message: '' },
  34. healthReportList: { data: [], loaded: false },
  35. },
  36. methods: {
  37. async getHealthPatient() {
  38. this.setData({ 'healthPatient.loading': true, })
  39. try {
  40. const data = await healthPatientMethod();
  41. this.setData({
  42. 'healthPatient.data': data,
  43. 'healthPatient.loading': false,
  44. });
  45. } catch (error) {
  46. this.setData({
  47. 'healthPatient.data': [],
  48. 'healthPatient.loading': false,
  49. 'healthPatient.message': error.errMsg,
  50. });
  51. }
  52. },
  53. async getHealthReport(id?: string) {
  54. this.setData({ 'healthReport.loading': true, })
  55. try {
  56. const data = await healthReportMethod(id);
  57. this.setData({
  58. 'healthReport.data': data,
  59. 'healthReport.loading': false,
  60. });
  61. } catch (error) {
  62. this.setData({
  63. 'healthReport.data': null,
  64. 'healthReport.loading': false,
  65. 'healthReport.message': error.errMsg,
  66. });
  67. }
  68. },
  69. async getHealthIndex(id?: string) {
  70. this.setData({ 'healthIndex.loading': true, })
  71. try {
  72. const data = await healthIndexMethod(id);
  73. this.setData({
  74. 'healthIndex.data': healthIndex2Progress(data),
  75. 'healthIndex.loading': false,
  76. });
  77. } catch (error) {
  78. this.setData({
  79. 'healthIndex.data': [],
  80. 'healthIndex.loading': false,
  81. 'healthIndex.message': error.errMsg,
  82. });
  83. }
  84. },
  85. onDraggableSizeUpdate(e) {
  86. 'worklet'
  87. if (e.pixels < 1) {
  88. wx.worklet.runOnJS(this.hideDraggableSheet.bind(this))()
  89. }
  90. },
  91. async showReportList() {
  92. if (!this.data.healthReportList.loaded) {
  93. wx.showLoading({ title: '加载中' })
  94. try {
  95. const data = await healthReportListMethod();
  96. this.setData({
  97. 'healthReportList.data': data,
  98. 'healthReportList.loaded': true,
  99. })
  100. } catch (error) {
  101. getTickleContext.call(this).showErrorMessage(error.errMsg);
  102. }
  103. wx.hideLoading();
  104. }
  105. if (this.data.healthReportList.data.length) {
  106. getDraggableSheetContext.call(this).scrollTo({
  107. size: 0.5,
  108. pixels: 600,
  109. animated: true,
  110. duration: 300,
  111. easingFunction: 'ease'
  112. });
  113. this.setData({ shade: 'shade' });
  114. } else {
  115. wx.showToast({ title: '暂无更新记录' })
  116. }
  117. },
  118. hideDraggableSheet(e?: any) {
  119. if (e) {
  120. getDraggableSheetContext.call(this).scrollTo({
  121. size: 0,
  122. animated: true,
  123. duration: 300,
  124. easingFunction: 'ease'
  125. });
  126. }
  127. this.setData({ shade: '' });
  128. },
  129. toSchemePage(event: WechatMiniprogram.TouchEvent) { toSchemePage(event.mark?.id); },
  130. toReportPage(event: WechatMiniprogram.TouchEvent) { toReportPage(event.mark?.id); },
  131. toPatientPage: toPatientPage,
  132. toHealthIndexListPage() {
  133. wx.navigateTo({ url: `/module/charts/record-index/record-index` })
  134. },
  135. toHealthStatusListPage() {
  136. wx.navigateTo({ url: `/module/health/pages/status-record/status-record` })
  137. },
  138. }
  139. })