careDetail.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. import { Post } from "../../../../lib/request/method";
  2. import { fromHealthReportSymptom } from "../../../../utils/util";
  3. Page({
  4. onLoad(options) {
  5. if (options.id) {
  6. wx.setStorageSync("careId", Number(options.id));
  7. this.getCareDetail(Number(options.id));
  8. }
  9. // 设置页面标题
  10. if (options.name && options.name !== "null") {
  11. this.setData({
  12. name: options.name,
  13. });
  14. }
  15. },
  16. data: {
  17. address: "",
  18. name: "服务包详情",
  19. // patientName: "",
  20. showAddress: false,
  21. careDetail: {},
  22. healthReports: [] as any[],
  23. symptomCellWidth: "300rpx",
  24. statusText: "未知状态",
  25. loading: true,
  26. isShowDelivery: false,
  27. carouselLoading: {} as Record<string | number, boolean>, // 用于跟踪每个轮播图的加载状态
  28. },
  29. // 处理症状数据,按症状名称分组,使相同症状在同一列显示
  30. processSymptomData(healthReports: any[]) {
  31. // 收集所有唯一的症状名称
  32. const symptomSet = new Set<string>();
  33. healthReports.forEach((report) => {
  34. if (report.symptoms && Array.isArray(report.symptoms)) {
  35. report.symptoms.forEach((symptom: any) => {
  36. symptomSet.add(symptom.name);
  37. });
  38. }
  39. });
  40. const allSymptomNames = Array.from(symptomSet);
  41. // 重新组织每个报告的症状数据,确保症状顺序一致
  42. const processedReports = healthReports.map((report) => {
  43. const orderedSymptoms: any[] = [];
  44. // 按照所有症状名称的顺序,为每个报告创建症状数组
  45. allSymptomNames.forEach((symptomName) => {
  46. // 查找当前报告中是否有这个症状
  47. const existingSymptom = report.symptoms?.find(
  48. (s: any) => s.name === symptomName
  49. );
  50. if (existingSymptom) {
  51. // 如果存在,添加症状信息
  52. orderedSymptoms.push({
  53. name: existingSymptom.name,
  54. label: existingSymptom.label ? `(${existingSymptom.label})` : "",
  55. value: existingSymptom.value,
  56. });
  57. } else {
  58. // 如果不存在,添加空占位符
  59. orderedSymptoms.push({
  60. name: "",
  61. label: "",
  62. value: 0,
  63. });
  64. }
  65. });
  66. return {
  67. ...report,
  68. symptoms: orderedSymptoms,
  69. };
  70. });
  71. // 计算每条报告相对于上一条的趋势(上升/下降)
  72. for (let i = 0; i < processedReports.length; i++) {
  73. const previousReport = i > 0 ? processedReports[i - 1] : null;
  74. const currentReport = processedReports[i];
  75. currentReport.symptoms = currentReport.symptoms.map(
  76. (sym: any, idx: number) => {
  77. const previousSymptom = previousReport
  78. ? previousReport.symptoms[idx]
  79. : null;
  80. let trend: "" | "up" | "down" = "";
  81. if (previousReport && sym && sym.name) {
  82. const currentValue = Number(sym.value) || 0;
  83. const previousValue = previousSymptom
  84. ? Number(previousSymptom.value) || 0
  85. : 0;
  86. if (currentValue > previousValue) trend = "up";
  87. else if (currentValue < previousValue) trend = "down";
  88. }
  89. return { ...sym, trend };
  90. }
  91. );
  92. }
  93. return processedReports;
  94. },
  95. //健康咨询记录
  96. onChatRecord(e: any) {
  97. const item = e.currentTarget.dataset.item;
  98. if (item) {
  99. wx.navigateTo({
  100. url: `/module/chats/pages/consultation-record/consultation-record?item=${encodeURIComponent(JSON.stringify(item))}`,
  101. });
  102. }
  103. },
  104. onCardRecord(e: any) {
  105. const id = e.currentTarget.dataset.id;
  106. wx.navigateTo({
  107. url: `/module/article/pages/punch-card/punch-card?id=${id}`,
  108. });
  109. },
  110. // 轮播图加载完成
  111. onCarouselLoaded(e: any) {
  112. const { itemId } = e.detail;
  113. if (itemId) {
  114. this.setData({
  115. [`carouselLoading.${itemId}`]: false,
  116. });
  117. }
  118. },
  119. // 图片加载失败
  120. onImageError(e: any) {
  121. const { itemId } = e.detail;
  122. // 图片加载失败时也要隐藏加载状态
  123. if (itemId) {
  124. this.setData({
  125. [`carouselLoading.${itemId}`]: false,
  126. });
  127. }
  128. },
  129. // 视频播放错误
  130. onVideoError(e: any) {
  131. const { itemId } = e.detail;
  132. // 视频播放错误时也要隐藏加载状态
  133. if (itemId) {
  134. this.setData({
  135. [`carouselLoading.${itemId}`]: false,
  136. });
  137. }
  138. },
  139. // 测试图片加载
  140. testImageLoading(mediaList: any[], itemId: string | number) {
  141. mediaList.forEach((media) => {
  142. if (media.type === "image") {
  143. wx.getImageInfo({
  144. src: media.src,
  145. success: () => {
  146. // 图片加载成功,隐藏加载状态
  147. this.setData({
  148. [`carouselLoading.${itemId}`]: false,
  149. });
  150. },
  151. fail: () => {
  152. // 图片加载失败,也要隐藏加载状态
  153. this.setData({
  154. [`carouselLoading.${itemId}`]: false,
  155. });
  156. },
  157. });
  158. } else if (media.type === "video") {
  159. // 视频不进行预加载测试
  160. }
  161. });
  162. },
  163. // 获取调理详情
  164. async getCareDetail(id: number) {
  165. wx.showLoading({
  166. title: "加载中",
  167. mask: true,
  168. });
  169. // 获取调理详情
  170. try {
  171. const res = await Post(
  172. `/patientCrManage/getPcrProcessById/${id}`,
  173. {},
  174. {
  175. transform({ data }: any) {
  176. return data;
  177. },
  178. }
  179. );
  180. if (res) {
  181. wx.hideLoading();
  182. this.setData({
  183. address: `${res?.provinceName ?? ""}${res?.cityName ?? ""}${
  184. res?.areaName ?? ""
  185. }${res?.detailAddress ?? ""}`,
  186. });
  187. if (
  188. !res?.provinceName &&
  189. !res?.cityName &&
  190. !res?.areaName &&
  191. !res?.detailAddress &&
  192. (!res?.liaison || !res.patientName) &&
  193. !res?.phone
  194. ) {
  195. this.setData({
  196. showAddress: false,
  197. });
  198. } else {
  199. this.setData({
  200. showAddress: true,
  201. });
  202. }
  203. // 设置状态文本
  204. const statusMap: Record<string, string> = {
  205. "0": "待付款",
  206. "1": "已作废",
  207. "2": "用户取消",
  208. "3": "未开始",
  209. "4": "调理中",
  210. "5": "已完结",
  211. };
  212. const statusText = statusMap[res.progress] || "未知状态";
  213. let isShowDelivery = false;
  214. if (res && res.items && res.items.length > 0) {
  215. res.items.forEach((item: any) => {
  216. item.carouselMediaList = [];
  217. // 添加photo
  218. if (item.conditioningProgramDetail?.photo) {
  219. item.carouselMediaList.push({
  220. type: "image",
  221. src: item.conditioningProgramDetail?.photo,
  222. });
  223. }
  224. // 添加itemImgFirst
  225. if (item?.conditioningProgramDetail?.itemImgFirst) {
  226. item.carouselMediaList.push({
  227. type: "image",
  228. src: item.conditioningProgramDetail?.itemImgFirst,
  229. });
  230. }
  231. // 添加itemVideoFirst
  232. if (item?.conditioningProgramDetail?.itemVideoFirst) {
  233. item.carouselMediaList.push({
  234. type: "video",
  235. src: item.conditioningProgramDetail?.itemVideoFirst,
  236. });
  237. }
  238. // 如果有轮播图内容,设置加载状态
  239. if (item.carouselMediaList.length > 0) {
  240. this.setData({
  241. [`carouselLoading.${item.id}`]: true,
  242. });
  243. // 测试图片是否可以正常加载
  244. this.testImageLoading(item.carouselMediaList, item.id);
  245. // 设置超时,防止一直显示加载中
  246. setTimeout(() => {
  247. // 检查是否还在加载状态,如果是则自动隐藏
  248. const currentLoading = this.data.carouselLoading;
  249. if (currentLoading && currentLoading[item.id]) {
  250. this.setData({
  251. [`carouselLoading.${item.id}`]: false,
  252. });
  253. }
  254. }, 10000); // 10秒后自动隐藏加载状态
  255. } else {
  256. // 如果没有轮播图内容,确保不显示加载状态
  257. this.setData({
  258. [`carouselLoading.${item.id}`]: false,
  259. });
  260. }
  261. });
  262. // 是否显示配送
  263. isShowDelivery = res.items.some((item: any) => {
  264. return item.conditioningProgramDetail?.isDelivery === "Y";
  265. });
  266. var data = res.items.find(
  267. (item: any) =>
  268. Array.isArray(item.healthAnalysisReports) &&
  269. item.healthAnalysisReports.length > 0
  270. );
  271. if (data) {
  272. const items = data.healthAnalysisReports.map((report: any) => {
  273. return {
  274. ...report,
  275. symptoms: fromHealthReportSymptom(report).items,
  276. };
  277. });
  278. // 处理症状数据,按症状名称分组,使相同症状在同一列显示
  279. const processedReports = this.processSymptomData(items);
  280. this.setData({
  281. healthReports: processedReports,
  282. });
  283. }
  284. }
  285. this.setData({
  286. loading: false,
  287. careDetail: res,
  288. statusText,
  289. isShowDelivery,
  290. });
  291. // 设置页面标题
  292. if (res.conditioningWrapName) {
  293. wx.setNavigationBarTitle({
  294. title: res.conditioningWrapName,
  295. });
  296. }
  297. } else {
  298. wx.hideLoading();
  299. this.setData({
  300. loading: false,
  301. careDetail: {},
  302. });
  303. }
  304. } catch (error: any) {
  305. wx.showToast({
  306. title: error.message,
  307. icon: "none",
  308. });
  309. wx.hideLoading();
  310. this.setData({
  311. isShow: false,
  312. loading: false,
  313. });
  314. }
  315. },
  316. onRecord(e: any) {
  317. const id = e.currentTarget.dataset.id;
  318. // 跳转核销记录
  319. wx.navigateTo({
  320. url: `/module/care/pages/care/verifyRecord?id=${id}`,
  321. success: () => {},
  322. fail: (error) => {
  323. console.error("跳转失败:", error);
  324. },
  325. });
  326. },
  327. onOffline(e: any) {
  328. // 跳转线下操作
  329. },
  330. onReport(e: WechatMiniprogram.TouchEvent) {
  331. wx.navigateTo({
  332. url: "/module/care/pages/reportRecord/reportRecord",
  333. });
  334. },
  335. onSeeReport(e: WechatMiniprogram.TouchEvent) {
  336. const id = e.currentTarget.dataset.id;
  337. if (id) {
  338. wx.navigateTo({ url: `/module/health/pages/report/report?id=${id}` });
  339. } else {
  340. wx.showToast({
  341. title: "暂无数据",
  342. icon: "none",
  343. });
  344. }
  345. },
  346. onPreviewImage(e: WechatMiniprogram.TouchEvent) {
  347. const url = e.currentTarget.dataset.url;
  348. wx.previewImage({
  349. current: url,
  350. urls: [url],
  351. showmenu: true,
  352. });
  353. },
  354. onHide() {
  355. wx.removeStorageSync("careId");
  356. },
  357. });