mine.ts 1.8 KB

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