offlineTreatment.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import I18nBehavior from "../../../../i18n/behavior";
  2. import { getOfflineTreatmentListMethod } from "../../request";
  3. Page({
  4. behaviors: [I18nBehavior],
  5. data: {
  6. i18n: {
  7. offlineTreatment: { title: '线下', ing: '进行中', finish: '完成' },
  8. },
  9. currentTab: "",
  10. treatmentList: [],
  11. isLoading: false,
  12. treatmentId: "",
  13. },
  14. async onLoad(options: any) {
  15. console.log(options, '传过来的参数')
  16. if (options.id) {
  17. this.setData({
  18. treatmentId: options.id,
  19. });
  20. }
  21. await this.getOfflineTreatmentList("");
  22. },
  23. // 跳转到核销记录
  24. onRecord(e: any) {
  25. const id = e.currentTarget.dataset.id;
  26. if (id) {
  27. wx.navigateTo({
  28. url: `/module/care/pages/care/verifyRecord?id=${id}`,
  29. });
  30. }
  31. },
  32. // 去预约
  33. goAppointment(e: any) {
  34. const { item } = e.currentTarget.dataset;
  35. const { offlineId, conditioningProgramName, offlineDuration, itemImgSecond, estimatedStartDate } = item;
  36. const goodsInfo = {
  37. name: conditioningProgramName || '',
  38. duration: offlineDuration || 0,
  39. image: itemImgSecond || '',
  40. offlineId: offlineId || '',
  41. serviceTime: estimatedStartDate || '',
  42. }
  43. console.log(goodsInfo, "goodsInfo======去预约页面")
  44. if (offlineId) {
  45. // 去预约页面
  46. wx.navigateTo({
  47. url: `/module/order/pages/appointment/appointment?goodsInfo=${JSON.stringify(goodsInfo)}`,
  48. });
  49. }else{
  50. wx.showToast({
  51. title: "线下服务ID不能为空",
  52. icon: "none",
  53. });
  54. }
  55. // const id = e.currentTarget.dataset.id;
  56. // if (id) {
  57. // // 跳转到预约页面,传递项目id
  58. // wx.navigateTo({
  59. // url: `/module/care/pages/careDetail/careDetail?id=${id}`,
  60. // });
  61. // }
  62. },
  63. onTabChange(e: any) {
  64. const progress = e.detail.value;
  65. this.setData({
  66. currentTab: progress,
  67. });
  68. // 不立即清空数据,避免空状态闪烁
  69. this.getOfflineTreatmentList(progress);
  70. },
  71. // 获取线下非药物治疗记录列表
  72. async getOfflineTreatmentList(progress: string) {
  73. // 启用加载态,保留当前列表,避免空态闪烁
  74. this.setData({ isLoading: true });
  75. try {
  76. const res = await getOfflineTreatmentListMethod(progress);
  77. console.log(res.data, "res.data")
  78. // 确保 res.data 是数组,避免 undefined 或 null 导致的错误
  79. const list = Array.isArray(res?.data) ? res.data : [];
  80. // 如果传入了treatmentId,标记匹配的项目为高亮并置顶
  81. const treatmentId = this.data.treatmentId;
  82. console.log(treatmentId, "treatmentId")
  83. console.log(list, "list")
  84. if (treatmentId && list.length > 0) {
  85. const highlightedList = list.map((item: any) => ({
  86. ...item,
  87. isHighlighted: item.id === treatmentId || String(item.id) === String(treatmentId),
  88. }));
  89. // 将高亮的项目移到最前面
  90. const highlightedItem = highlightedList.find((item: any) => item.isHighlighted);
  91. const otherItems = highlightedList.filter((item: any) => !item.isHighlighted);
  92. const sortedList = highlightedItem ? [highlightedItem, ...otherItems] : highlightedList;
  93. console.log(sortedList, "sortedList")
  94. this.setData({ treatmentList: sortedList, isLoading: false });
  95. } else {
  96. // 只有在数据加载完成后才更新列表
  97. this.setData({ treatmentList: list, isLoading: false });
  98. }
  99. } catch (error: any) {
  100. console.error('获取数据失败:', error);
  101. // 只有在真正出错时才显示错误提示
  102. wx.showToast({
  103. title: error.errMsg || "获取数据失败",
  104. icon: "none",
  105. });
  106. this.setData({ treatmentList: [], isLoading: false });
  107. }
  108. },
  109. });