careDetail.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. console.log(item,"咨询记录数据",e)
  99. if (item) {
  100. wx.navigateTo({
  101. url: `/module/chats/pages/consultation-record/consultation-record?item=${encodeURIComponent(JSON.stringify(item))}`,
  102. });
  103. }
  104. },
  105. onCardRecord(e: any) {
  106. const id = e.currentTarget.dataset.id;
  107. wx.navigateTo({
  108. url: `/module/article/pages/punch-card/punch-card?id=${id}`,
  109. });
  110. },
  111. // 轮播图加载完成
  112. onCarouselLoaded(e: any) {
  113. const { itemId } = e.detail;
  114. if (itemId) {
  115. this.setData({
  116. [`carouselLoading.${itemId}`]: false,
  117. });
  118. }
  119. },
  120. // 图片加载失败
  121. onImageError(e: any) {
  122. const { itemId } = e.detail;
  123. // 图片加载失败时也要隐藏加载状态
  124. if (itemId) {
  125. this.setData({
  126. [`carouselLoading.${itemId}`]: false,
  127. });
  128. }
  129. },
  130. // 视频播放错误
  131. onVideoError(e: any) {
  132. const { itemId } = e.detail;
  133. // 视频播放错误时也要隐藏加载状态
  134. if (itemId) {
  135. this.setData({
  136. [`carouselLoading.${itemId}`]: false,
  137. });
  138. }
  139. },
  140. // 测试图片加载
  141. testImageLoading(mediaList: any[], itemId: string | number) {
  142. mediaList.forEach((media) => {
  143. if (media.type === "image") {
  144. wx.getImageInfo({
  145. src: media.src,
  146. success: () => {
  147. // 图片加载成功,隐藏加载状态
  148. this.setData({
  149. [`carouselLoading.${itemId}`]: false,
  150. });
  151. },
  152. fail: () => {
  153. // 图片加载失败,也要隐藏加载状态
  154. this.setData({
  155. [`carouselLoading.${itemId}`]: false,
  156. });
  157. },
  158. });
  159. } else if (media.type === "video") {
  160. // 视频不进行预加载测试
  161. }
  162. });
  163. },
  164. // 获取调理详情
  165. async getCareDetail(id: number) {
  166. wx.showLoading({
  167. title: "加载中",
  168. mask: true,
  169. });
  170. // 获取调理详情
  171. try {
  172. const res = await Post(
  173. `/patientCrManage/getPcrProcessById/${id}`,
  174. {},
  175. {
  176. transform({ data }: any) {
  177. return data;
  178. },
  179. }
  180. );
  181. if (res) {
  182. wx.hideLoading();
  183. this.setData({
  184. address: `${res?.provinceName ?? ""}${res?.cityName ?? ""}${
  185. res?.areaName ?? ""
  186. }${res?.detailAddress ?? ""}`,
  187. });
  188. if (
  189. !res?.provinceName &&
  190. !res?.cityName &&
  191. !res?.areaName &&
  192. !res?.detailAddress &&
  193. (!res?.liaison || !res.patientName) &&
  194. !res?.phone
  195. ) {
  196. this.setData({
  197. showAddress: false,
  198. });
  199. } else {
  200. this.setData({
  201. showAddress: true,
  202. });
  203. }
  204. // 设置状态文本
  205. const statusMap: Record<string, string> = {
  206. "0": "待付款",
  207. "1": "已作废",
  208. "2": "用户取消",
  209. "3": "未开始",
  210. "4": "调理中",
  211. "5": "已完结",
  212. };
  213. const statusText = statusMap[res.progress] || "未知状态";
  214. let isShowDelivery = false;
  215. if (res && res.items && res.items.length > 0) {
  216. res.items.forEach((item: any) => {
  217. item.carouselMediaList = [];
  218. // 添加photo
  219. if (item.conditioningProgramDetail?.photo) {
  220. item.carouselMediaList.push({
  221. type: "image",
  222. src: item.conditioningProgramDetail?.photo,
  223. });
  224. }
  225. // 添加itemImgFirst
  226. if (item?.conditioningProgramDetail?.itemImgFirst) {
  227. item.carouselMediaList.push({
  228. type: "image",
  229. src: item.conditioningProgramDetail?.itemImgFirst,
  230. });
  231. }
  232. // 添加itemVideoFirst
  233. if (item?.conditioningProgramDetail?.itemVideoFirst) {
  234. item.carouselMediaList.push({
  235. type: "video",
  236. src: item.conditioningProgramDetail?.itemVideoFirst,
  237. });
  238. }
  239. // 如果有轮播图内容,设置加载状态
  240. if (item.carouselMediaList.length > 0) {
  241. this.setData({
  242. [`carouselLoading.${item.id}`]: true,
  243. });
  244. // 测试图片是否可以正常加载
  245. this.testImageLoading(item.carouselMediaList, item.id);
  246. // 设置超时,防止一直显示加载中
  247. setTimeout(() => {
  248. // 检查是否还在加载状态,如果是则自动隐藏
  249. const currentLoading = this.data.carouselLoading;
  250. if (currentLoading && currentLoading[item.id]) {
  251. this.setData({
  252. [`carouselLoading.${item.id}`]: false,
  253. });
  254. }
  255. }, 10000); // 10秒后自动隐藏加载状态
  256. } else {
  257. // 如果没有轮播图内容,确保不显示加载状态
  258. this.setData({
  259. [`carouselLoading.${item.id}`]: false,
  260. });
  261. }
  262. });
  263. // 是否显示配送
  264. isShowDelivery = res.items.some((item: any) => {
  265. return item.conditioningProgramDetail?.isDelivery === "Y";
  266. });
  267. var data = res.items.find(
  268. (item: any) =>
  269. Array.isArray(item.healthAnalysisReports) &&
  270. item.healthAnalysisReports.length > 0
  271. );
  272. if (data) {
  273. const items = data.healthAnalysisReports.map((report: any) => {
  274. return {
  275. ...report,
  276. symptoms: fromHealthReportSymptom(report).items,
  277. };
  278. });
  279. // 处理症状数据,按症状名称分组,使相同症状在同一列显示
  280. const processedReports = this.processSymptomData(items);
  281. this.setData({
  282. healthReports: processedReports,
  283. });
  284. }
  285. }
  286. this.setData({
  287. loading: false,
  288. careDetail: res,
  289. statusText,
  290. isShowDelivery,
  291. });
  292. // 设置页面标题
  293. if (res.conditioningWrapName) {
  294. wx.setNavigationBarTitle({
  295. title: res.conditioningWrapName,
  296. });
  297. }
  298. } else {
  299. wx.hideLoading();
  300. this.setData({
  301. loading: false,
  302. careDetail: {},
  303. });
  304. }
  305. } catch (error: any) {
  306. wx.showToast({
  307. title: error.message,
  308. icon: "none",
  309. });
  310. wx.hideLoading();
  311. this.setData({
  312. isShow: false,
  313. loading: false,
  314. });
  315. }
  316. },
  317. onRecord(e: any) {
  318. const id = e.currentTarget.dataset.id;
  319. // 跳转核销记录
  320. wx.navigateTo({
  321. url: `/module/care/pages/care/verifyRecord?id=${id}`,
  322. success: () => {},
  323. fail: (error) => {
  324. console.error("跳转失败:", error);
  325. },
  326. });
  327. },
  328. onOffline(e: any) {
  329. // 跳转线下操作
  330. },
  331. onReport(e: WechatMiniprogram.TouchEvent) {
  332. wx.navigateTo({
  333. url: "/module/care/pages/reportRecord/reportRecord",
  334. });
  335. },
  336. onSeeReport(e: WechatMiniprogram.TouchEvent) {
  337. const id = e.currentTarget.dataset.id;
  338. if (id) {
  339. wx.navigateTo({ url: `/module/health/pages/report/report?id=${id}` });
  340. } else {
  341. wx.showToast({
  342. title: "暂无数据",
  343. icon: "none",
  344. });
  345. }
  346. },
  347. onPreviewImage(e: WechatMiniprogram.TouchEvent) {
  348. const url = e.currentTarget.dataset.url;
  349. wx.previewImage({
  350. current: url,
  351. urls: [url],
  352. showmenu: true,
  353. });
  354. },
  355. onHide() {
  356. wx.removeStorageSync("careId");
  357. },
  358. });