home.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. import PageContainerBehavior from "../../core/behavior/page-container.behavior";
  2. import {
  3. DraggableSheetBehavior,
  4. getDraggableSheetContext,
  5. } from "../../core/behavior/draggableSheet.behavior";
  6. import { login } from "../../lib/logic";
  7. import { useRouteQuery } from "../../utils/route-query";
  8. import { appUpdate } from "../../lib/wx/update";
  9. import { addPatientOnlineRecordClockIn } from "./request";
  10. const { shared, Easing, timing } = wx.worklet;
  11. const offset = shared(0);
  12. const menus = ["shareAppMessage", "shareTimeline"];
  13. // pages/home/home.ts
  14. import {
  15. getPatients,
  16. healthReportMethod,
  17. healthIndexMethod,
  18. getSolarTerms,
  19. getShortScienceList,
  20. getPatientDescription,
  21. getNotDealLists,
  22. getCareList,
  23. } from "./request";
  24. import { toCertificationPage, toChats } from "./router";
  25. // import { useLocation } from "../../lib/use/use-location";
  26. Page({
  27. data: {
  28. isShowComplete: true,
  29. careList: [],
  30. displayList: [] as {
  31. id: number;
  32. conditioningProgramType: string;
  33. operateBy?: string;
  34. operateTime: string;
  35. frequencyType: string; // 频次类型
  36. frequencyMeasure: string; // 总用量
  37. arrangeDate: string; // 下一次开始日期
  38. finishCount: number; // 完成量
  39. conditioningProgramName: string; // 调养计划名称
  40. conditioningProgramSupplierName: string; // 调养计划供应商名称
  41. expanded: boolean;
  42. }[],
  43. allExpanded: false,
  44. fixedHeight: "370rpx",
  45. tabbarValue: "/pages/home/home",
  46. tabbarHidden: false,
  47. pageHeight: "100vh", // 默认值
  48. popupList: [] as AnyArray,
  49. isShowPopup: false,
  50. patients: [] as (App.Patient.Model & { isDefault: "Y" | "N" })[],
  51. patient: null as App.Patient.Model | null,
  52. patientDescription: "",
  53. healthId: "",
  54. healthReport: { data: null, message: "", loading: true },
  55. healthIndex: { data: [], message: "" },
  56. position: {} as AnyObject,
  57. location: {} as AnyObject,
  58. solarTerms: {} as AnyObject,
  59. sheet: false,
  60. scienceList: [] as AnyArray,
  61. _loaded: false,
  62. statusList: [] as AnyArray,
  63. switchType: "",
  64. carouselLoading: {} as Record<string | number, boolean>, // 用于跟踪每个轮播图的加载状态
  65. // 轮播媒体列表
  66. carouselMediaList: [] as Array<{
  67. type: "image" | "video";
  68. src: string;
  69. }>,
  70. },
  71. behaviors: [
  72. PageContainerBehavior,
  73. DraggableSheetBehavior(".draggable-sheet-wrapper"),
  74. ],
  75. // 获取调养计划
  76. async getCareLists() {
  77. // 保存当前的展开状态
  78. const currentExpandedStates = this.data.displayList.map((item: any) => ({
  79. id: item.id,
  80. expanded: item.expanded,
  81. }));
  82. const res = await getCareList();
  83. if (res && res.length > 0) {
  84. res.forEach((item: any) => {
  85. item.carouselMediaList = [];
  86. // 添加photo
  87. if (item.photo) {
  88. item.carouselMediaList.push({
  89. type: "image",
  90. src: item.photo,
  91. });
  92. }
  93. // 添加itemImgFirst
  94. if (item?.itemImgFirst) {
  95. item.carouselMediaList.push({
  96. type: "image",
  97. src: item.itemImgFirst,
  98. });
  99. }
  100. // 添加itemVideoFirst
  101. if (item?.itemVideoFirst) {
  102. item.carouselMediaList.push({
  103. type: "video",
  104. src: item.itemVideoFirst,
  105. });
  106. }
  107. });
  108. // 先设置 careList
  109. this.setData({
  110. careList: res,
  111. });
  112. await this.updateDisplayList(currentExpandedStates);
  113. setTimeout(() => {
  114. res.forEach((item: any, index: number) => {
  115. if (item.carouselMediaList && item.carouselMediaList.length > 0) {
  116. this.setData({
  117. [`careList[${index}].carouselMediaList`]: [
  118. ...item.carouselMediaList,
  119. ],
  120. });
  121. // 同时更新 displayList
  122. const displayIndex = this.data.displayList.findIndex(
  123. (displayItem: any) => displayItem.id === item.id
  124. );
  125. if (displayIndex !== -1) {
  126. this.setData({
  127. [`displayList[${displayIndex}].carouselMediaList`]: [
  128. ...item.carouselMediaList,
  129. ],
  130. });
  131. }
  132. }
  133. });
  134. }, 100);
  135. }
  136. },
  137. async onLoad(options) {
  138. appUpdate();
  139. const query = useRouteQuery(options.scene!);
  140. if (query.ys) wx.setStorageSync("doctorId", query.ys);
  141. this.initFabAnimated();
  142. if (options.switchType) {
  143. this.setData({
  144. switchType: options.switchType,
  145. });
  146. }
  147. },
  148. async onShow() {
  149. wx.showShareMenu({ withShareTicket: true, menus }).then();
  150. await this.load();
  151. // 如果是从一体机扫码进来的 有switchType值就直接跳转到注册页面
  152. if (
  153. this.data.switchType &&
  154. ((this.data.patient as any)?.isPerfectInfo ?? true)
  155. ) {
  156. wx.navigateTo({
  157. url: "/module/user/pages/user-certification/user-certification?type=home",
  158. });
  159. }
  160. // 如果用户没有手机号每次进入页面都提示 点击跳到注册页补充
  161. // todo 要先判断用户有没有手机号 isPerfectInfo是true 就出来弹窗提示用户
  162. // if ((this.data.patient as any)?.isPerfectInfo ?? true) {
  163. // wx.showModal({
  164. // title: "提示",
  165. // content: "手机号为空,请补充",
  166. // success: (res) => {
  167. // if (res.confirm) {
  168. // wx.navigateTo({
  169. // url: "/module/user/pages/user-certification/user-certification?type=home",
  170. // });
  171. // }
  172. // },
  173. // });
  174. // }
  175. },
  176. onHide() {
  177. wx.hideShareMenu({ menus }).then();
  178. offset.value = timing(
  179. 0,
  180. { duration: 100, easing: (<any>Easing).linear },
  181. () => {
  182. "worklet";
  183. }
  184. );
  185. },
  186. onShareAppMessage(_opts): WechatMiniprogram.Page.ICustomShareContent {
  187. return {
  188. title: `健康为基,从容赏生活之美`,
  189. imageUrl: `https://wx.hzliuzhi.com/media/healthManager/wx/share.jpg`,
  190. path: `/pages/home/home`,
  191. };
  192. },
  193. onShareTimeline() {
  194. return {
  195. title: `健康为基,从容赏生活之美`,
  196. };
  197. },
  198. async updateDisplayList(
  199. preserveExpandedStates?: Array<{
  200. id: number;
  201. expanded: boolean;
  202. }>
  203. ) {
  204. const { careList, allExpanded } = this.data;
  205. let newDisplayList: any[] =
  206. allExpanded || careList.length <= 4 ? careList : careList.slice(0, 4);
  207. // 如果有保存的展开状态,则恢复它们
  208. if (preserveExpandedStates && preserveExpandedStates.length > 0) {
  209. newDisplayList = newDisplayList.map((item: any) => {
  210. const savedState = preserveExpandedStates.find(
  211. (state) => state.id === item.id
  212. );
  213. if (savedState) {
  214. return {
  215. ...item,
  216. expanded: savedState.expanded,
  217. };
  218. }
  219. return item;
  220. });
  221. }
  222. this.setData({
  223. displayList: newDisplayList,
  224. });
  225. },
  226. toggleAll() {
  227. this.setData(
  228. { allExpanded: !this.data.allExpanded },
  229. this.updateDisplayList
  230. );
  231. },
  232. toggleItem(e: any) {
  233. const index = e.currentTarget.dataset.index;
  234. const key = `displayList[${index}].expanded`;
  235. this.setData({ [key]: !this.data.displayList[index].expanded });
  236. },
  237. // 核销记录
  238. onRecord(e: any) {
  239. const id = e.currentTarget.dataset.id;
  240. if (id) {
  241. wx.navigateTo({
  242. url: `/module/care/pages/care/verifyRecord?id=${id}`,
  243. });
  244. } else {
  245. wx.showToast({
  246. title: "暂无核销记录",
  247. icon: "none",
  248. });
  249. }
  250. },
  251. onClose() {
  252. this.setData({
  253. isShowPopup: false,
  254. });
  255. },
  256. // 打卡
  257. pushCard(e: any) {
  258. const id = e.currentTarget.dataset.id;
  259. wx.navigateTo({
  260. url: `/module/article/pages/punch-card/punch-card?id=${id}`,
  261. });
  262. },
  263. calculatePageHeight() {
  264. const systemInfo = wx.getSystemInfoSync();
  265. const windowHeight = systemInfo.windowHeight; // 屏幕可用高度
  266. // 获取 tabbar 高度
  267. const query = wx.createSelectorQuery();
  268. query
  269. .select(".t-tabbar")
  270. .boundingClientRect((rect) => {
  271. if (rect) {
  272. const tabbarHeight = rect.height;
  273. const contentHeight = windowHeight - tabbarHeight;
  274. this.setData({
  275. pageHeight: `${contentHeight}px`,
  276. });
  277. }
  278. })
  279. .exec();
  280. },
  281. getNotDealList() {
  282. getNotDealLists().then((res) => {
  283. if (res.length > 0) {
  284. this.setData({
  285. popupList: res,
  286. });
  287. this.setData({
  288. isShowPopup: true,
  289. });
  290. }
  291. });
  292. },
  293. showFollowPopup() {
  294. if (this.data.popupList.length > 0) {
  295. this.setData({
  296. isShowPopup: true,
  297. });
  298. }
  299. },
  300. onVisibleChange(e: { detail: { visible: any } }) {
  301. this.setData({
  302. isShowPopup: e.detail.visible,
  303. });
  304. },
  305. // 诊疗随访提醒
  306. goComplete(e: {
  307. currentTarget: { dataset: { page: string; id: number; title: string } };
  308. }) {
  309. const { title } = e.currentTarget.dataset;
  310. let page = e.currentTarget.dataset.page;
  311. let id = e.currentTarget.dataset.id;
  312. // let page = '/module/chats/pages/index/index';
  313. // let id = 1;
  314. if (page === "/module/chats/pages/index/index") {
  315. if (title === "健康评估") {
  316. wx.setStorageSync("isAnalysis", 4);
  317. toChats("questionnaire", 2);
  318. } else {
  319. wx.setStorageSync("isAnalysis", 2);
  320. wx.setStorageSync("workId", id);
  321. wx.navigateTo({
  322. url: `${page}?component=questionnaire&messageType=1&id=${id}`,
  323. });
  324. }
  325. } else {
  326. wx.redirectTo({ url: `${page}?id=${id}` });
  327. // wx.navigateTo({ url: `/module/follow/pages/evaluation/report?id=${id}` });
  328. }
  329. },
  330. // 随访评估报告已出
  331. goSeeFollowReport() {
  332. wx.navigateTo({ url: "/module/follow/pages/evaluation/report" });
  333. },
  334. async load(forceLogin = false) {
  335. try {
  336. await login(forceLogin);
  337. wx.showLoading({ title: "加载中" });
  338. const { patient } = await getPatients(/*this.data.patientId*/);
  339. // if (!patient) await toCertificationPage();
  340. if (!patient) {
  341. /*if (wx.getStorageSync("doctorId")) {
  342. toCertificationPage();
  343. }*/
  344. this.setData({
  345. "healthReport.loading": false,
  346. isShowComplete: true,
  347. });
  348. } else {
  349. this.setData({ patient });
  350. this.observerPatient(patient);
  351. }
  352. wx.hideLoading();
  353. } catch (error: any) {
  354. await wx
  355. .showModal({
  356. title: `加载失败`,
  357. content: `${error?.errMsg ?? error?.message ?? ""}`,
  358. showCancel: false,
  359. confirmText: `重新加载`,
  360. })
  361. .catch(() => {});
  362. await this.load(true);
  363. return;
  364. }
  365. if (!this.data._loaded) {
  366. this.loadScienceList();
  367. // useLocation()
  368. // .then((location) => {
  369. // this.setData({ location });
  370. // })
  371. // .catch(() => {});
  372. getSolarTerms()
  373. .then((solarTerms) => {
  374. this.setData({ solarTerms });
  375. })
  376. .catch(() => {});
  377. this.setData({ _loaded: true });
  378. }
  379. },
  380. async _getHealthReport() {
  381. wx.showLoading({ title: "加载中" });
  382. this.setData({ "healthReport.loading": true });
  383. try {
  384. const data = await healthReportMethod();
  385. if (!data) {
  386. this.setData({
  387. isShowComplete: true,
  388. });
  389. } else {
  390. this.setData({
  391. isShowComplete: false,
  392. });
  393. }
  394. this.setData({
  395. "healthReport.data": data,
  396. "healthReport.loading": false,
  397. healthId: data?.healthAnalysisReportId,
  398. });
  399. let arr2 = [
  400. [
  401. {
  402. title: "健康状态",
  403. value: data?.willillStateName ? `${data?.willillStateName}` : "",
  404. },
  405. {
  406. title: "程度",
  407. value: data?.willillDegreeName ? `${data?.willillDegreeName}` : "",
  408. },
  409. {
  410. title: "表现",
  411. value: data?.willillFunctionName
  412. ? `${data?.willillFunctionName}`
  413. : "",
  414. },
  415. ],
  416. [
  417. {
  418. title: "中医证素",
  419. value: data?.factorItemSummary ? `${data?.factorItemSummary}` : "",
  420. },
  421. ],
  422. [
  423. {
  424. title: "体质",
  425. value: data?.constitutionGroupName
  426. ? `${data?.constitutionGroupName}`
  427. : "",
  428. },
  429. ],
  430. ];
  431. this.setData({
  432. statusList: arr2,
  433. });
  434. // if (!data?.healthAnalysisReportId) {
  435. // this.setData({
  436. // isShowComplete: true,
  437. // });
  438. // }
  439. } catch (error: any) {
  440. wx.showToast({
  441. title: error.errMsg || "加载失败",
  442. icon: "none",
  443. });
  444. this.setData({
  445. "healthReport.data": [],
  446. "healthReport.loading": false,
  447. "healthReport.message": error.errMsg,
  448. healthId: "",
  449. });
  450. }
  451. wx.hideLoading();
  452. },
  453. async _getAbnormalHealthIndex() {
  454. this.setData({ "healthIndex.loading": true });
  455. try {
  456. const data = await healthIndexMethod();
  457. this.setData({
  458. "healthIndex.data": data
  459. .map((item: AnyObject) => item.abnormalDesc)
  460. .filter(Boolean),
  461. "healthIndex.loading": false,
  462. });
  463. } catch (error: any) {
  464. this.setData({
  465. "healthIndex.data": [],
  466. "healthIndex.loading": false,
  467. "healthIndex.message": error.errMsg,
  468. });
  469. }
  470. },
  471. onBodyModel(event: WechatMiniprogram.TouchEvent) {
  472. if (event.detail?.position === "LB") {
  473. this.toReportPage();
  474. } else if (event.detail?.position === "item0") {
  475. const report = this.data.healthReport.data as unknown as AnyObject;
  476. this.setData({
  477. position: {
  478. LT: [
  479. "willillState",
  480. "willillDegree",
  481. "willillSocial",
  482. "willillFunction",
  483. ]
  484. .map((key) => {
  485. const title = report[`${key}Name`];
  486. const description = report[`${key}Description`];
  487. return title || description ? { title, description } : null;
  488. })
  489. .filter(Boolean),
  490. },
  491. });
  492. this.showDraggableSheet();
  493. } else if (event.detail?.position === "item2") {
  494. const report = this.data.healthReport.data as unknown as AnyObject;
  495. const get = (key: string) => ({ [key]: report[key] });
  496. this.setData({
  497. position: {
  498. RT: {
  499. ...get("constitutionGroupName"),
  500. ...get("constitutionGroupDefinition"),
  501. ...get("faceImg"),
  502. ...get("faceAnalysisResult"),
  503. ...get("tongueAnalysisResult"),
  504. ...get("upImg"),
  505. ...get("downImg"),
  506. },
  507. },
  508. });
  509. this.showDraggableSheet();
  510. } else if (event.detail?.position === "item1") {
  511. const report = this.data.healthReport.data as unknown as AnyObject;
  512. const get = (key: string) => ({ [key]: report[key] });
  513. this.setData({
  514. position: {
  515. RB: {
  516. ...get("diagnoseSyndromeSummary"),
  517. ...get("diagnoseSyndromes"),
  518. ...get("factorItemSummary"),
  519. ...get("factorItems"),
  520. },
  521. },
  522. });
  523. this.showDraggableSheet();
  524. } else if (event.detail?.position === "CT") {
  525. this.setData({
  526. position: {
  527. CT: this.data.healthIndex.data.map(
  528. (item, index) => `${index + 1}、${item}`
  529. ),
  530. },
  531. });
  532. this.showDraggableSheet();
  533. }
  534. },
  535. tabValue() {
  536. this.setData({
  537. position: {
  538. CT: this.data.healthIndex.data.map(
  539. (item, index) => `${index + 1}、${item}`
  540. ),
  541. },
  542. });
  543. this.showDraggableSheet();
  544. },
  545. initFabAnimated() {
  546. (<any>this).applyAnimatedStyle(".fab-wrapper", () => {
  547. "worklet";
  548. return { right: `${Math.min(offset.value, 36) - 36}px` };
  549. });
  550. (<any>this).applyAnimatedStyle(".fab-1", () => {
  551. "worklet";
  552. return { transform: `translateY(${-offset.value}px)` };
  553. });
  554. (<any>this).applyAnimatedStyle(".fab-2", () => {
  555. "worklet";
  556. return {
  557. transform: `translateX(${-offset.value}px) translateY(${
  558. -offset.value / 2
  559. }px)`,
  560. };
  561. });
  562. (<any>this).applyAnimatedStyle(".fab-3", () => {
  563. "worklet";
  564. return {
  565. transform: `translateX(${-offset.value}px) translateY(${
  566. offset.value / 2
  567. }px)`,
  568. };
  569. });
  570. (<any>this).applyAnimatedStyle(".fab-4", () => {
  571. "worklet";
  572. return { transform: `translateY(${offset.value}px)` };
  573. });
  574. },
  575. onFabTap() {
  576. const value = Math.abs(offset.value - 72);
  577. offset.value = timing(
  578. value,
  579. { duration: 500, easing: (<any>Easing).linear },
  580. () => {
  581. "worklet";
  582. if (offset.value > 0) offset.value = 72;
  583. }
  584. );
  585. },
  586. async toChatsPage() {
  587. if (!this.data.patient?.patientId) {
  588. try {
  589. await this.load();
  590. } catch (error: any) {
  591. wx.showModal({
  592. title: "出错了",
  593. content: error?.errMsg ?? error?.message ?? "错误,请重试",
  594. showCancel: false,
  595. });
  596. return;
  597. }
  598. }
  599. const page = "/module/chats/pages/index/index";
  600. wx.navigateTo({
  601. url: `${page}?component=guide&isShowGuide=true`,
  602. });
  603. wx.setStorageSync("isAnalysis", 3);
  604. },
  605. toSciencePage() {
  606. wx.navigateTo({ url: `/module/article/pages/science-list/science-list` });
  607. },
  608. async toReportPage() {
  609. // const { patient } = await getPatients(/*this.data.patientId*/);
  610. if (!this.data.patient) await toCertificationPage();
  611. else {
  612. const id = this.data.healthId;
  613. if (id)
  614. wx.navigateTo({ url: `/module/health/pages/report/report?id=${id}` });
  615. else wx.showToast({ title: "暂无分析报告", icon: "none" });
  616. }
  617. },
  618. onDraggableSizeUpdate(e: any) {
  619. "worklet";
  620. if (e.pixels < 1) {
  621. wx.worklet.runOnJS(this.hideDraggableSheet.bind(this))();
  622. }
  623. },
  624. showDraggableSheet() {
  625. getDraggableSheetContext.call(this).scrollTo({
  626. size: 0.5,
  627. pixels: 600,
  628. animated: true,
  629. duration: 300,
  630. easingFunction: "ease",
  631. });
  632. this.setData({ sheet: true });
  633. },
  634. hideDraggableSheet(event?: any) {
  635. if (event) {
  636. getDraggableSheetContext.call(this).scrollTo({
  637. size: 0,
  638. animated: true,
  639. duration: 300,
  640. easingFunction: "ease",
  641. });
  642. }
  643. this.setData({ position: {}, sheet: false });
  644. },
  645. async loadScienceList() {
  646. try {
  647. const { data } = await getShortScienceList();
  648. this.setData({ scienceList: data });
  649. } catch (error) {}
  650. },
  651. observerPatient(model: { patientId: string; sex: "0" | "1" }) {
  652. wx.setStorageSync("patientId", model.patientId);
  653. this._getHealthReport();
  654. this._getAbnormalHealthIndex();
  655. const patientIcon = { 0: "gender-male", 1: "gender-female" }[model.sex];
  656. const patientIconColor = { 0: "#0f40f5", 1: "#E560B3" }[model.sex];
  657. this.setData({ patientIcon, patientIconColor });
  658. getPatientDescription(model).then((patientDescription) => {
  659. this.setData({ patientDescription });
  660. // wx.setStorageSync("patientPhone", patientDescription.phone);
  661. });
  662. // 获取未处理随访列表
  663. this.getNotDealList();
  664. // 获取调养计划
  665. this.getCareLists();
  666. },
  667. // 没有健康分析去做健康分析
  668. goHealthAnalyze() {
  669. wx.redirectTo({
  670. url: `/module/chats/pages/index/index?component=guide&isShowGuide=true`,
  671. });
  672. wx.setStorageSync("showGuideActive", 1);
  673. wx.setStorageSync("isAnalysis", 3);
  674. },
  675. async isGoPunchcard(e: any) {
  676. const { id, signintime } = e.currentTarget.dataset;
  677. // 已经打卡了
  678. if (signintime) {
  679. // 已打卡 跳转到打卡页面
  680. wx.navigateTo({
  681. url: `/module/article/pages/punch-card/punch-card?id=${id}`,
  682. });
  683. } else {
  684. // todo 打卡
  685. const cardId = e.currentTarget.dataset.id;
  686. await addPatientOnlineRecordClockIn(cardId);
  687. wx.showToast({
  688. title: "打卡成功",
  689. icon: "success",
  690. duration: 1500,
  691. });
  692. // 无感刷新调养计划,保持展开状态
  693. await this.refreshCareListsWithState();
  694. }
  695. },
  696. // 无感刷新调养计划,保持展开状态和媒体加载状态
  697. async refreshCareListsWithState() {
  698. // 保存当前的展开状态
  699. const currentExpandedStates = this.data.displayList.map((item: any) => ({
  700. id: item.id,
  701. expanded: item.expanded,
  702. carouselMediaList: item.carouselMediaList, // 保存媒体列表,避免重新加载
  703. }));
  704. // 获取新数据
  705. const res = await getCareList();
  706. if (res && res.length > 0) {
  707. res.forEach((item: any) => {
  708. // 查找对应的旧数据
  709. const oldItem = currentExpandedStates.find(
  710. (state) => state.id === item.id
  711. );
  712. if (oldItem && oldItem.carouselMediaList) {
  713. // 保持原有的媒体列表,避免重新加载
  714. item.carouselMediaList = oldItem.carouselMediaList;
  715. } else {
  716. item.carouselMediaList = [];
  717. // 添加photo
  718. if (item.photo) {
  719. item.carouselMediaList.push({
  720. type: "image",
  721. src: item.photo,
  722. });
  723. }
  724. // 添加itemImgFirst
  725. if (item?.itemImgFirst) {
  726. item.carouselMediaList.push({
  727. type: "image",
  728. src: item.itemImgFirst,
  729. });
  730. }
  731. // 添加itemVideoFirst
  732. if (item?.itemVideoFirst) {
  733. item.carouselMediaList.push({
  734. type: "video",
  735. src: item.itemVideoFirst,
  736. });
  737. }
  738. }
  739. });
  740. // 更新 careList
  741. this.setData({
  742. careList: res,
  743. });
  744. // 更新 displayList 并恢复展开状态
  745. const { allExpanded } = this.data;
  746. let newDisplayList: any[] =
  747. allExpanded || res.length <= 4 ? res : res.slice(0, 4);
  748. // 恢复展开状态
  749. newDisplayList = newDisplayList.map((item: any) => {
  750. const savedState = currentExpandedStates.find(
  751. (state) => state.id === item.id
  752. );
  753. if (savedState) {
  754. return {
  755. ...item,
  756. expanded: savedState.expanded,
  757. carouselMediaList:
  758. savedState.carouselMediaList || item.carouselMediaList,
  759. };
  760. }
  761. return item;
  762. });
  763. this.setData({
  764. displayList: newDisplayList,
  765. });
  766. }
  767. },
  768. /**
  769. * 轮播组件进入/退出全屏时,隐藏/显示底部 tabbar,防止遮挡视频进度条
  770. */
  771. onCarouselFullscreenChange(e: { detail?: { fullScreen?: boolean } }) {
  772. console.log(e, "全屏模式");
  773. const fullScreen = !!(e.detail?.fullScreen);
  774. this.setData({
  775. tabbarHidden: fullScreen,
  776. });
  777. },
  778. });