guide.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // module/chats/components/guide/guide.ts
  2. import { getPatients } from "../../../../pages/home/request";
  3. import { toCertificationPage } from "../../../../pages/home/router";
  4. import { Post } from "../../../../lib/request/method";
  5. Component({
  6. lifetimes: {
  7. attached(this: any) {
  8. const showGuideActive = wx.getStorageSync("showGuideActive");
  9. // 从主页点击健康评估进来的
  10. if (showGuideActive) {
  11. this.handleA();
  12. wx.removeStorageSync("showGuideActive");
  13. }
  14. // 首次挂载时也拉取一次,避免初次渲染为 0
  15. this.setAnalysisCount();
  16. },
  17. },
  18. pageLifetimes: {
  19. show(this: any) {
  20. // 获取评估剩余次数
  21. this.setAnalysisCount();
  22. },
  23. },
  24. properties: {
  25. id: { type: String, value: "" },
  26. active: { type: Boolean, value: false },
  27. },
  28. data: {
  29. analysisCount: 0,
  30. result: [] as string[],
  31. result2: false,
  32. patient: {} as any,
  33. },
  34. methods: {
  35. // 获取评估剩余次数
  36. async setAnalysisCount(this: any) {
  37. try {
  38. // 获取剩余次数
  39. const residuedCount = await Post(
  40. `/patientInfoManage/rechargeUseDetail`,
  41. {},
  42. {
  43. transform({ data }: any) {
  44. return data?.residuedCou;
  45. },
  46. }
  47. );
  48. this.setData({ analysisCount: residuedCount });
  49. } catch (error) {
  50. console.error("获取剩余次数失败:", error);
  51. }
  52. },
  53. async handleA() {
  54. const { patient } = await getPatients(/*this.data.patientId*/);
  55. if (!patient) await toCertificationPage();
  56. else {
  57. if (this.data.active) {
  58. this.triggerEvent("next", {
  59. component: "questionnaire",
  60. scroll: true,
  61. });
  62. this.triggerEvent("nextType", { MessageType: 2 });
  63. }
  64. }
  65. },
  66. async handleB() {
  67. const { patient } = await getPatients(/*this.data.patientId*/);
  68. if (!patient) await toCertificationPage();
  69. else {
  70. if (this.data.active)
  71. wx.navigateTo({
  72. url: "/module/health/pages/status/status",
  73. events: { update: this._update.bind(this) },
  74. });
  75. }
  76. },
  77. async handleC() {
  78. const { patient } = await getPatients(/*this.data.patientId*/);
  79. if (!patient) await toCertificationPage();
  80. else {
  81. if (this.data.active)
  82. wx.navigateTo({
  83. url: "/module/user/pages/user-edit/user-edit",
  84. events: {
  85. update2: () => {
  86. this.setData({ result2: true });
  87. this.triggerEvent("next", { component: "guide", scroll: true });
  88. },
  89. },
  90. });
  91. }
  92. },
  93. handleD() {
  94. // if (this.data.active) wx.navigateBack();
  95. if (this.data.active) {
  96. wx.redirectTo({ url: "/pages/home/home" });
  97. }
  98. },
  99. _update(result: string[]) {
  100. if (result.length) {
  101. this.setData({ result });
  102. this.triggerEvent("next", { component: "guide", scroll: true });
  103. } else {
  104. setTimeout(
  105. () => wx.showToast({ title: `没有更改项`, icon: "none" }),
  106. 300
  107. );
  108. }
  109. },
  110. },
  111. });