report.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  2. import I18nBehavior from "../../../../i18n/behavior";
  3. import TickleBehavior, {
  4. getTickleContext,
  5. } from "../../../../core/behavior/tickle.behavior";
  6. // module/health/pages/report/report.ts
  7. import { toSchemePage, toHomePage } from "../../router";
  8. import { healthIndexMethod, healthReportMethod } from "../../request";
  9. import { healthIndex2Progress } from "../../tools/health-index";
  10. Page({
  11. behaviors: [I18nBehavior, PageContainerBehavior, TickleBehavior],
  12. data: {
  13. i18n: {
  14. common: { doctor: '', zy: '' },
  15. health: { statusTable: ['', '', '', '', '', '', ''] },
  16. scheme: { title: '方案' },
  17. report: {
  18. title: '报告',
  19. date: '',
  20. physique: '',
  21. physiqueTable: ['特征1', '特征2', '特征3', '特征4', '特征5', '特征6'],
  22. }
  23. },
  24. id: "",
  25. dataset: null as unknown as AnyObject,
  26. showScheme: false,
  27. schemeId: "",
  28. healthIndex: { data: [], loading: false, message: "" },
  29. tongueAnalysis: [] as AnyArray,
  30. switchType: "",
  31. },
  32. onLoad(query: any) {
  33. if (query.scene) {
  34. this.setData({ switchType: query.scene });
  35. wx.showLoading({ title: "加载中" });
  36. } else this._load(query);
  37. },
  38. load(event: AnyObject) { this._load(event.detail, false); },
  39. async _load(query: Record<"id" | "scene", string>, loading = true) {
  40. let id = "";
  41. if (loading) wx.showLoading({ title: "加载中" });
  42. try {
  43. const { __origin__, ...dataset } = await healthReportMethod(query);
  44. id = dataset.id;
  45. const showScheme = __origin__?.isHaveConditioningProgram === "Y";
  46. const schemeId =
  47. __origin__?.isConfirmConditioningProgram === "Y" ? id : "";
  48. this.setData({
  49. showScheme,
  50. schemeId,
  51. dataset: {
  52. ...dataset,
  53. factorItems: __origin__?.factorItems,
  54. diagnoseSyndromes: __origin__?.diagnoseSyndromes,
  55. },
  56. });
  57. } catch (error) {
  58. getTickleContext.call(this).showErrorMessage(error.errMsg, 0);
  59. }
  60. wx.hideLoading();
  61. if (id) this.getHealthIndex(id);
  62. },
  63. async getHealthIndex(id?: string) {
  64. this.setData({ "healthIndex.loading": true });
  65. try {
  66. const data = await healthIndexMethod(id);
  67. this.setData({
  68. "healthIndex.data": healthIndex2Progress(data),
  69. "healthIndex.loading": false,
  70. });
  71. } catch (error) {
  72. this.setData({
  73. "healthIndex.data": [],
  74. "healthIndex.loading": false,
  75. "healthIndex.message": error.errMsg,
  76. });
  77. }
  78. },
  79. toHomePage() {
  80. toHomePage(this.data.switchType as string);
  81. },
  82. toSchemePage() {
  83. toSchemePage(this.data.schemeId);
  84. },
  85. openMessage(event: any) {
  86. const message = event?.detail?.content;
  87. if (message) getTickleContext.call(this).showMessage(event.detail.type || 'info', message);
  88. }
  89. });