report.ts 2.5 KB

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