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