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() {
  8. const showGuideActive = wx.getStorageSync("showGuideActive");
  9. // 从主页点击健康评估进来的
  10. if(showGuideActive){
  11. this.handleA();
  12. wx.removeStorageSync("showGuideActive");
  13. }
  14. // 获取评估剩余次数
  15. this.setAnalysisCount();
  16. },
  17. },
  18. observers: {
  19. active(newVal,oldVal) {
  20. console.log("active=>>>",newVal,oldVal);
  21. },
  22. },
  23. properties: {
  24. id: { type: String, value: "" },
  25. active: { type: Boolean, value: false },
  26. },
  27. data: {
  28. analysisCount: 0,
  29. result: [] as string[],
  30. result2: false,
  31. patient: {} as any,
  32. },
  33. methods: {
  34. // 获取评估剩余次数
  35. async setAnalysisCount(count: number) {
  36. try {
  37. // 获取剩余次数
  38. const count = await Post(
  39. `/patientInfoManage/rechargeUseDetail`,
  40. {},
  41. {
  42. transform({ data }: any) {
  43. return data?.residuedCou;
  44. },
  45. }
  46. );
  47. this.setData({ analysisCount: count });
  48. console.log(this.data.analysisCount, "this.data.analysisCount");
  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. console.log("patient",this.data.active);
  58. if (this.data.active) {
  59. this.triggerEvent("next", { component: "questionnaire", scroll: true });
  60. this.triggerEvent("nextType", { MessageType: 2 });
  61. }
  62. }
  63. },
  64. async handleB() {
  65. const { patient } = await getPatients(/*this.data.patientId*/);
  66. if (!patient) await toCertificationPage();
  67. else {
  68. if (this.data.active)
  69. wx.navigateTo({
  70. url: "/module/health/pages/status/status",
  71. events: { update: this._update.bind(this) },
  72. });
  73. }
  74. },
  75. async handleC() {
  76. const { patient } = await getPatients(/*this.data.patientId*/);
  77. if (!patient) await toCertificationPage();
  78. else {
  79. if (this.data.active)
  80. wx.navigateTo({
  81. url: "/module/user/pages/user-edit/user-edit",
  82. events: {
  83. update2: () => {
  84. this.setData({ result2: true });
  85. this.triggerEvent("next", { component: "guide", scroll: true });
  86. },
  87. },
  88. });
  89. }
  90. },
  91. handleD() {
  92. // if (this.data.active) wx.navigateBack();
  93. if (this.data.active) {
  94. console.log("tiaohzuan1");
  95. wx.redirectTo({ url: "/pages/home/home" });
  96. }
  97. },
  98. _update(result: string[]) {
  99. if (result.length) {
  100. this.setData({ result });
  101. this.triggerEvent("next", { component: "guide", scroll: true });
  102. } else {
  103. setTimeout(
  104. () => wx.showToast({ title: `没有更改项`, icon: "none" }),
  105. 300
  106. );
  107. }
  108. },
  109. },
  110. });