| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- // module/chats/components/guide/guide.ts
- import { getPatients } from "../../../../pages/home/request";
- import { toCertificationPage } from "../../../../pages/home/router";
- import { Post } from "../../../../lib/request/method";
- Component({
- lifetimes: {
- attached(this: any) {
- const showGuideActive = wx.getStorageSync("showGuideActive");
- // 从主页点击健康评估进来的
- if (showGuideActive) {
- this.handleA();
- wx.removeStorageSync("showGuideActive");
- }
- // 首次挂载时也拉取一次,避免初次渲染为 0
- this.setAnalysisCount();
- },
- },
- pageLifetimes: {
- show(this: any) {
- // 获取评估剩余次数
- this.setAnalysisCount();
- },
- },
- observers: {
- active(newVal, oldVal) {
- console.log("active=>>>", newVal, oldVal);
- },
- },
- properties: {
- id: { type: String, value: "" },
- active: { type: Boolean, value: false },
- },
- data: {
- analysisCount: 0,
- result: [] as string[],
- result2: false,
- patient: {} as any,
- },
- methods: {
- // 获取评估剩余次数
- async setAnalysisCount(this: any) {
- console.log("setAnalysisCount");
- try {
- // 获取剩余次数
- const residuedCount = await Post(
- `/patientInfoManage/rechargeUseDetail`,
- {},
- {
- transform({ data }: any) {
- return data?.residuedCou;
- },
- }
- );
- this.setData({ analysisCount: residuedCount });
- console.log(this.data.analysisCount, "this.data.analysisCount");
- } catch (error) {
- console.error("获取剩余次数失败:", error);
- }
- },
- async handleA() {
- const { patient } = await getPatients(/*this.data.patientId*/);
- if (!patient) await toCertificationPage();
- else {
- console.log("patient", this.data.active);
- if (this.data.active) {
- this.triggerEvent("next", {
- component: "questionnaire",
- scroll: true,
- });
- this.triggerEvent("nextType", { MessageType: 2 });
- }
- }
- },
- async handleB() {
- const { patient } = await getPatients(/*this.data.patientId*/);
- if (!patient) await toCertificationPage();
- else {
- if (this.data.active)
- wx.navigateTo({
- url: "/module/health/pages/status/status",
- events: { update: this._update.bind(this) },
- });
- }
- },
- async handleC() {
- const { patient } = await getPatients(/*this.data.patientId*/);
- if (!patient) await toCertificationPage();
- else {
- if (this.data.active)
- wx.navigateTo({
- url: "/module/user/pages/user-edit/user-edit",
- events: {
- update2: () => {
- this.setData({ result2: true });
- this.triggerEvent("next", { component: "guide", scroll: true });
- },
- },
- });
- }
- },
- handleD() {
- // if (this.data.active) wx.navigateBack();
- if (this.data.active) {
- console.log("tiaohzuan1");
- wx.redirectTo({ url: "/pages/home/home" });
- }
- },
- _update(result: string[]) {
- if (result.length) {
- this.setData({ result });
- this.triggerEvent("next", { component: "guide", scroll: true });
- } else {
- setTimeout(
- () => wx.showToast({ title: `没有更改项`, icon: "none" }),
- 300
- );
- }
- },
- },
- });
|