guide.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. observers: {
  25. active(newVal, oldVal) {
  26. console.log("active=>>>", newVal, oldVal);
  27. },
  28. },
  29. properties: {
  30. id: { type: String, value: "" },
  31. active: { type: Boolean, value: false },
  32. },
  33. data: {
  34. analysisCount: 0,
  35. result: [] as string[],
  36. result2: false,
  37. patient: {} as any,
  38. },
  39. methods: {
  40. // 获取评估剩余次数
  41. async setAnalysisCount(this: any) {
  42. console.log("setAnalysisCount");
  43. try {
  44. // 获取剩余次数
  45. const residuedCount = await Post(
  46. `/patientInfoManage/rechargeUseDetail`,
  47. {},
  48. {
  49. transform({ data }: any) {
  50. return data?.residuedCou;
  51. },
  52. }
  53. );
  54. this.setData({ analysisCount: residuedCount });
  55. console.log(this.data.analysisCount, "this.data.analysisCount");
  56. } catch (error) {
  57. console.error("获取剩余次数失败:", error);
  58. }
  59. },
  60. async handleA() {
  61. const { patient } = await getPatients(/*this.data.patientId*/);
  62. if (!patient) await toCertificationPage();
  63. else {
  64. console.log("patient", this.data.active);
  65. if (this.data.active) {
  66. this.triggerEvent("next", {
  67. component: "questionnaire",
  68. scroll: true,
  69. });
  70. this.triggerEvent("nextType", { MessageType: 2 });
  71. }
  72. }
  73. },
  74. async handleB() {
  75. const { patient } = await getPatients(/*this.data.patientId*/);
  76. if (!patient) await toCertificationPage();
  77. else {
  78. if (this.data.active)
  79. wx.navigateTo({
  80. url: "/module/health/pages/status/status",
  81. events: { update: this._update.bind(this) },
  82. });
  83. }
  84. },
  85. async handleC() {
  86. const { patient } = await getPatients(/*this.data.patientId*/);
  87. if (!patient) await toCertificationPage();
  88. else {
  89. if (this.data.active)
  90. wx.navigateTo({
  91. url: "/module/user/pages/user-edit/user-edit",
  92. events: {
  93. update2: () => {
  94. this.setData({ result2: true });
  95. this.triggerEvent("next", { component: "guide", scroll: true });
  96. },
  97. },
  98. });
  99. }
  100. },
  101. handleD() {
  102. // if (this.data.active) wx.navigateBack();
  103. if (this.data.active) {
  104. console.log("tiaohzuan1");
  105. wx.redirectTo({ url: "/pages/home/home" });
  106. }
  107. },
  108. _update(result: string[]) {
  109. if (result.length) {
  110. this.setData({ result });
  111. this.triggerEvent("next", { component: "guide", scroll: true });
  112. } else {
  113. setTimeout(
  114. () => wx.showToast({ title: `没有更改项`, icon: "none" }),
  115. 300
  116. );
  117. }
  118. },
  119. },
  120. });