report-health-status.ts 5.0 KB

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