report-health-status.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  2. import {
  3. DraggableSheetBehavior,
  4. getDraggableSheetContext,
  5. } from "../../../../core/behavior/draggableSheet.behavior";
  6. import { getTickleContext } from "../../../../core/behavior/tickle.behavior";
  7. // module/health/components/report-health-status/report-health-status.ts
  8. import {
  9. healthAnalysisListMethod,
  10. healthAnalysisMethod,
  11. healthReportListMethod,
  12. healthReportMethod,
  13. } from "../../request";
  14. import { healthAnalysisModel, healthRecord } from "../../model/health.model";
  15. import { AnalysisModel } from "../../model/health.model";
  16. interface PanelProps {
  17. shade?: boolean;
  18. title?: string;
  19. data: AnyArray;
  20. type?: "analysis" | "report";
  21. }
  22. Component({
  23. behaviors: [
  24. PageContainerBehavior,
  25. DraggableSheetBehavior(".health-report-list"),
  26. ],
  27. lifetimes: {
  28. attached() {
  29. this._load();
  30. },
  31. },
  32. pageLifetimes: {
  33. hide() {
  34. this._hideDraggableSheet({});
  35. },
  36. },
  37. data: {
  38. dataset: {},
  39. tongue: null as unknown as AnalysisModel,
  40. face: null as unknown as AnalysisModel,
  41. analysisData: null as unknown as AnalysisModel,
  42. loading: false,
  43. message: "",
  44. panel: {
  45. shade: false,
  46. data: [],
  47. } as PanelProps,
  48. _healthReportList: { data: [], loaded: false },
  49. _healthAnalysisList: { data: [], loaded: false },
  50. },
  51. methods: {
  52. async showReportList() {
  53. if (!this.data._healthReportList.loaded) {
  54. wx.showLoading({ title: "加载中" });
  55. try {
  56. const data = await healthReportListMethod();
  57. this.setData({
  58. "_healthReportList.data": data,
  59. "_healthReportList.loaded": true,
  60. });
  61. } catch (error) {
  62. getTickleContext.call(this).showErrorMessage(error.errMsg);
  63. }
  64. wx.hideLoading();
  65. }
  66. this._showDraggableSheet({
  67. title: "健康分析报告记录",
  68. type: "report",
  69. data: this.data._healthReportList.data,
  70. });
  71. },
  72. async showAnalysisList() {
  73. if (!this.data._healthAnalysisList.loaded) {
  74. wx.showLoading({ title: "加载中" });
  75. try {
  76. const data = await healthAnalysisListMethod();
  77. this.setData({
  78. "_healthAnalysisList.data": data,
  79. "_healthAnalysisList.loaded": true,
  80. });
  81. } catch (error) {
  82. getTickleContext.call(this).showErrorMessage(error.errMsg);
  83. }
  84. wx.hideLoading();
  85. }
  86. this._showDraggableSheet({
  87. title: "舌面分析报告记录",
  88. type: "analysis",
  89. data: this.data._healthAnalysisList.data,
  90. });
  91. },
  92. showStatusList() {
  93. wx.navigateTo({
  94. url: `/module/health/pages/status-record/status-record`,
  95. });
  96. },
  97. toPreviewPage(event: WechatMiniprogram.TouchEvent) {
  98. const { id, type } = event.mark ?? {};
  99. if (!id) return;
  100. const route = `module/health/pages/${type}/${type}`;
  101. wx.navigateTo({ url: `/${route}?id=${id}` });
  102. },
  103. async _load() {
  104. this.setData({ loading: true });
  105. const params = { id: void 0, scene: void 0 };
  106. try {
  107. const report = await healthReportMethod(params);
  108. const { id: analysisId, ...analysis } = await healthAnalysisMethod(
  109. params
  110. ).catch(() => healthAnalysisModel({}));
  111. const data = healthRecord({ ...report, ...analysis, analysisId });
  112. this.setData({
  113. dataset: data,
  114. loading: false,
  115. });
  116. data.condition = data.condition.map((item:any)=>{
  117. item.value = item.value.split(',')
  118. return item
  119. })
  120. const { tongue, face, ...analysisData } = await healthAnalysisMethod(params);
  121. this.setData({ tongue, face, analysisData });
  122. } catch (error) {
  123. this.setData({
  124. dataset: null,
  125. loading: false,
  126. message: error.errMsg,
  127. });
  128. }
  129. },
  130. _showDraggableSheet(props: PanelProps) {
  131. if (props.data?.length) {
  132. getDraggableSheetContext.call(this).scrollTo({
  133. size: 0.5,
  134. pixels: 600,
  135. animated: true,
  136. duration: 300,
  137. easingFunction: "ease",
  138. });
  139. this.setData({ panel: { ...props, shade: true } });
  140. } else {
  141. wx.showToast({ title: "暂无更新记录" });
  142. }
  143. },
  144. _hideDraggableSheet(e?: any) {
  145. this.setData({ "panel.shade": false });
  146. if (!e) return;
  147. getDraggableSheetContext.call(this).scrollTo({
  148. size: 0,
  149. animated: true,
  150. duration: 300,
  151. easingFunction: "ease",
  152. });
  153. },
  154. _draggableSizeUpdate(e: any) {
  155. "worklet";
  156. if (e.pixels < 1) {
  157. wx.worklet.runOnJS(this._hideDraggableSheet.bind(this))();
  158. }
  159. },
  160. },
  161. });