guide.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. let next: 'handleA' | 'handleB' | 'handleC';
  6. Component({
  7. lifetimes: {
  8. attached(this: any) {
  9. const showGuideActive = wx.getStorageSync("showGuideActive");
  10. // 从主页点击健康评估进来的
  11. if (showGuideActive) {
  12. this.handleA();
  13. wx.removeStorageSync("showGuideActive");
  14. }
  15. // 首次挂载时也拉取一次,避免初次渲染为 0
  16. this.setAnalysisCount();
  17. },
  18. },
  19. pageLifetimes: {
  20. show(this: any) {
  21. // 获取评估剩余次数
  22. this.setAnalysisCount().then(() => {
  23. if (next) {
  24. const patientId = wx.getStorageSync('patientId');
  25. if (patientId) this[next]();
  26. else wx.showToast({ title: '请先完善信息!', icon: 'none' });
  27. next = undefined;
  28. }
  29. });
  30. },
  31. },
  32. properties: {
  33. id: { type: String, value: "" },
  34. active: { type: Boolean, value: false },
  35. },
  36. data: {
  37. analysisCount: 0,
  38. result: [] as string[],
  39. result2: false,
  40. patient: {} as any,
  41. },
  42. methods: {
  43. // 获取评估剩余次数
  44. async setAnalysisCount(this: any) {
  45. try {
  46. // 获取剩余次数
  47. const residuedCount = await Post(
  48. `/patientInfoManage/rechargeUseDetail`,
  49. {},
  50. {
  51. transform({ data }: any) {
  52. if (data?.usedCou === 0 && data.residuedCou === 0) data.residuedCou = 3;
  53. return data?.residuedCou;
  54. },
  55. }
  56. );
  57. this.setData({ analysisCount: residuedCount });
  58. } catch (error) {
  59. console.error("获取剩余次数失败:", error);
  60. }
  61. },
  62. async handleA() {
  63. const { patient } = await getPatients(/*this.data.patientId*/);
  64. if (!patient) {
  65. await toCertificationPage();
  66. next = 'handleA';
  67. }
  68. else {
  69. if (this.data.active) {
  70. this.triggerEvent("next", {
  71. component: "questionnaire",
  72. scroll: true,
  73. });
  74. this.triggerEvent("nextType", { MessageType: 2 });
  75. }
  76. }
  77. },
  78. // 在线咨询
  79. async handleE() {
  80. const { patient } = await getPatients(/*this.data.patientId*/);
  81. if (!patient) await toCertificationPage();
  82. else {
  83. if (this.data.active) {
  84. // 清除之前的咨询结束状态,开始新咨询
  85. wx.setStorageSync("consultEnded", false);
  86. wx.setStorageSync("lastConsultTime", Date.now());
  87. wx.setStorageSync("isAnalysis", 5);
  88. this.triggerEvent("next", {
  89. component: "questionnaire",
  90. scroll: true,
  91. });
  92. this.triggerEvent("nextType", { MessageType: 3 });
  93. }
  94. }
  95. },
  96. async handleB() {
  97. const { patient } = await getPatients(/*this.data.patientId*/);
  98. if (!patient) {
  99. await toCertificationPage();
  100. next = 'handleB';
  101. }
  102. else {
  103. if (this.data.active)
  104. wx.navigateTo({
  105. url: "/module/health/pages/status/status",
  106. events: { update: this._update.bind(this) },
  107. });
  108. }
  109. },
  110. async handleC() {
  111. const { patient } = await getPatients(/*this.data.patientId*/);
  112. if (!patient){
  113. await toCertificationPage();
  114. next = 'handleC';
  115. }
  116. else {
  117. if (this.data.active)
  118. wx.navigateTo({
  119. url: "/module/user/pages/user-edit/user-edit",
  120. events: {
  121. update2: () => {
  122. this.setData({ result2: true });
  123. this.triggerEvent("next", { component: "guide", scroll: true });
  124. },
  125. },
  126. });
  127. }
  128. },
  129. handleD() {
  130. // if (this.data.active) wx.navigateBack();
  131. if (this.data.active) {
  132. wx.redirectTo({ url: "/pages/home/home" });
  133. }
  134. },
  135. _update(result: string[]) {
  136. if (result.length) {
  137. this.setData({ result });
  138. this.triggerEvent("next", { component: "guide", scroll: true });
  139. } else {
  140. setTimeout(
  141. () => wx.showToast({ title: `没有更改项`, icon: "none" }),
  142. 300
  143. );
  144. }
  145. },
  146. },
  147. });