report.ts 2.2 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. this._load(query).then((id: string) => {
  22. if (id) this.getHealthIndex(id);
  23. });
  24. if (query.scene) {
  25. this.setData({
  26. switchType: query.scene,
  27. });
  28. }
  29. },
  30. async _load(query: Record<"id" | "scene", string>) {
  31. let id = "";
  32. wx.showLoading({ title: "加载中" });
  33. try {
  34. const { __origin__, ...dataset } = await healthReportMethod(query);
  35. id = dataset.id;
  36. const showScheme = __origin__?.isHaveConditioningProgram === "Y";
  37. const schemeId =
  38. __origin__?.isConfirmConditioningProgram === "Y" ? id : "";
  39. this.setData({
  40. showScheme,
  41. schemeId,
  42. dataset: {
  43. ...dataset,
  44. factorItems: __origin__?.factorItems,
  45. diagnoseSyndromes: __origin__?.diagnoseSyndromes,
  46. },
  47. });
  48. } catch (error) {
  49. getTickleContext.call(this).showErrorMessage(error.errMsg, 0);
  50. }
  51. wx.hideLoading();
  52. return id;
  53. },
  54. async getHealthIndex(id?: string) {
  55. this.setData({ "healthIndex.loading": true });
  56. try {
  57. const data = await healthIndexMethod(id);
  58. this.setData({
  59. "healthIndex.data": healthIndex2Progress(data),
  60. "healthIndex.loading": false,
  61. });
  62. } catch (error) {
  63. this.setData({
  64. "healthIndex.data": [],
  65. "healthIndex.loading": false,
  66. "healthIndex.message": error.errMsg,
  67. });
  68. }
  69. },
  70. toHomePage() {
  71. toHomePage(this.data.switchType as string);
  72. },
  73. toSchemePage() {
  74. toSchemePage(this.data.schemeId);
  75. },
  76. });