offlineTreatment.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. if (options.id) {
  16. this.setData({
  17. treatmentId: options.id,
  18. });
  19. }
  20. // await this.getOfflineTreatmentList("");
  21. },
  22. async onShow() {
  23. // 返回本页时要沿用当前 Tab 的筛选条件
  24. await this.getOfflineTreatmentList(this.data.currentTab ?? "");
  25. },
  26. // 跳转到核销记录
  27. onRecord(e: any) {
  28. const { item } = e.currentTarget.dataset;
  29. const { id, offlineId, conditioningProgramName, offlineDuration, itemImgSecond, estimatedStartDate } = item;
  30. const goodsInfo = {
  31. name: conditioningProgramName || '',
  32. duration: offlineDuration || 0,
  33. image: itemImgSecond || '',
  34. offlineId: offlineId || '',
  35. serviceTime: estimatedStartDate || '',
  36. }
  37. wx.setStorageSync('goodsInfo', JSON.stringify(goodsInfo));
  38. if (id) {
  39. wx.navigateTo({
  40. url: `/module/care/pages/care/verifyRecord?id=${id}`,
  41. });
  42. }
  43. },
  44. // 去预约
  45. goAppointment(e: any) {
  46. const { item } = e.currentTarget.dataset;
  47. const { offlineId, conditioningProgramName, offlineDuration, itemImgSecond, estimatedStartDate } = item;
  48. const goodsInfo = {
  49. name: conditioningProgramName || '',
  50. duration: offlineDuration || 0,
  51. image: itemImgSecond || '',
  52. offlineId: offlineId || '',
  53. serviceTime: estimatedStartDate || '',
  54. }
  55. if (offlineId) {
  56. wx.setStorageSync('goodsInfo', JSON.stringify(goodsInfo));
  57. // 去预约页面
  58. wx.navigateTo({
  59. url: `/module/order/pages/appointment/appointment`,
  60. });
  61. } else {
  62. wx.showToast({
  63. title: "线下服务ID不能为空",
  64. icon: "none",
  65. });
  66. }
  67. },
  68. onTabChange(e: any) {
  69. const progress = e.detail.value;
  70. this.setData({
  71. currentTab: progress,
  72. });
  73. this.getOfflineTreatmentList(progress);
  74. },
  75. // 获取线下非药物治疗记录列表
  76. async getOfflineTreatmentList(progress: string) {
  77. this.setData({ isLoading: true });
  78. try {
  79. const res = await getOfflineTreatmentListMethod(progress);
  80. const list = Array.isArray(res?.data) ? res.data : [];
  81. const treatmentId = this.data.treatmentId;
  82. if (treatmentId && list.length > 0) {
  83. const highlightedList = list.map((item: any) => ({
  84. ...item,
  85. isHighlighted: item.id === treatmentId || String(item.id) === String(treatmentId),
  86. }));
  87. // 将高亮的项目移到最前面
  88. const highlightedItem = highlightedList.find((item: any) => item.isHighlighted);
  89. const otherItems = highlightedList.filter((item: any) => !item.isHighlighted);
  90. const sortedList = highlightedItem ? [highlightedItem, ...otherItems] : highlightedList;
  91. this.setData({ treatmentList: sortedList, isLoading: false });
  92. } else {
  93. // 只有在数据加载完成后才更新列表
  94. this.setData({ treatmentList: list, isLoading: false });
  95. }
  96. } catch (error: any) {
  97. wx.showToast({
  98. title: error.errMsg || "获取数据失败",
  99. icon: "none",
  100. });
  101. this.setData({ treatmentList: [], isLoading: false });
  102. }
  103. },
  104. });