report.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  2. import TickleBehavior, { getTickleContext } from "../../../../core/behavior/tickle.behavior";
  3. import { getPatients } from "../../../../lib/request/common";
  4. // module/health/pages/report/report.ts
  5. import { toSchemePage, toHomePage } from "../../router";
  6. import { healthIndexMethod, healthReportMethod } from "../../request";
  7. import { healthIndex2Progress } from "../../tools/health-index";
  8. Page({
  9. behaviors: [PageContainerBehavior, TickleBehavior],
  10. data: {
  11. id: "",
  12. dataset: null as unknown as AnyObject,
  13. showScheme: false,
  14. schemeId: "",
  15. healthIndex: { data: [], loading: false, message: "" },
  16. tongueAnalysis: [] as AnyArray,
  17. showUserAuth: false,
  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. if (query.scene) {
  35. // 查找患者是否需要授权
  36. const { auth } = await getPatients().catch(() => ({ auth: true }));
  37. if (auth) this.setData({ showUserAuth: true });
  38. }
  39. const { __origin__, ...dataset } = await healthReportMethod(query);
  40. id = dataset.id;
  41. const showScheme = __origin__?.isHaveConditioningProgram === "Y";
  42. const schemeId =
  43. __origin__?.isConfirmConditioningProgram === "Y" ? id : "";
  44. this.setData({
  45. showScheme,
  46. schemeId,
  47. dataset: {
  48. ...dataset,
  49. factorItems: __origin__?.factorItems,
  50. diagnoseSyndromes: __origin__?.diagnoseSyndromes,
  51. },
  52. });
  53. } catch (error) {
  54. getTickleContext.call(this).showErrorMessage(error.errMsg, 0);
  55. }
  56. wx.hideLoading();
  57. return id;
  58. },
  59. async getHealthIndex(id?: string) {
  60. this.setData({ "healthIndex.loading": true });
  61. try {
  62. const data = await healthIndexMethod(id);
  63. this.setData({
  64. "healthIndex.data": healthIndex2Progress(data),
  65. "healthIndex.loading": false,
  66. });
  67. } catch (error) {
  68. this.setData({
  69. "healthIndex.data": [],
  70. "healthIndex.loading": false,
  71. "healthIndex.message": error.errMsg,
  72. });
  73. }
  74. },
  75. toHomePage() {
  76. toHomePage(this.data.switchType as string);
  77. },
  78. toSchemePage() {
  79. toSchemePage(this.data.schemeId);
  80. },
  81. openMessage(event: any) {
  82. const message = event?.detail?.content
  83. if (message) getTickleContext.call(this).showMessage(event.detail.type || 'info', message);
  84. }
  85. });