mine.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { getPatients, getPatientPhone } from "../home/request";
  2. import { toCertificationPage } from "../home/router";
  3. Page({
  4. data: {
  5. patients: [] as (App.Patient.Model & { isDefault: "Y" | "N" })[],
  6. patient: null as App.Patient.Model | null,
  7. patientDescription: "",
  8. userInfo: null,
  9. tabbarValue: "/pages/mine/mine",
  10. phone: "",
  11. },
  12. async load(retry = false) {
  13. if (retry) {
  14. await wx.showModal({
  15. title: '提示',
  16. content: '数据加载失败,是否重试?',
  17. showCancel: true,
  18. }).then(res => {
  19. if (res.confirm) {
  20. this.load();
  21. }
  22. });
  23. return;
  24. }
  25. try {
  26. wx.showLoading({ title: "加载中" });
  27. const { patient } = await getPatients();
  28. const { phone } = await getPatientPhone();
  29. wx.setStorageSync("patientName", patient?.name);
  30. this.setData({
  31. patient: patient || null,
  32. phone
  33. });
  34. } catch (error) {
  35. console.error('加载失败:', error);
  36. wx.showToast({
  37. title: '加载失败',
  38. icon: 'none',
  39. duration: 2000
  40. });
  41. } finally {
  42. wx.hideLoading();
  43. }
  44. },
  45. // 健康档案
  46. toHealthPage() {
  47. if (!this.data.patient?.patientId) {
  48. wx.showToast({
  49. title: '请先登录',
  50. icon: 'none'
  51. });
  52. toCertificationPage();
  53. }else {
  54. wx.navigateTo({ url: `/module/health/pages/home/home` });
  55. }
  56. },
  57. // 药膳
  58. toDietTonicPage() {
  59. wx.navigateTo({
  60. url: `/module/article/pages/diet-list/diet-list?classify=tonic`,
  61. });
  62. },
  63. // 茶饮
  64. toDietTeaPage() {
  65. wx.navigateTo({
  66. url: `/module/article/pages/diet-list/diet-list?classify=tea`,
  67. });
  68. },
  69. onLoad() {
  70. this.load();
  71. },
  72. onShow() {
  73. // 如果需要每次显示页面时刷新数据,可以在这里调用 load
  74. // this.load();
  75. },
  76. });