| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818 |
- import PageContainerBehavior from "../../core/behavior/page-container.behavior";
- import {
- DraggableSheetBehavior,
- getDraggableSheetContext,
- } from "../../core/behavior/draggableSheet.behavior";
- import { login } from "../../lib/logic";
- import { useRouteQuery } from "../../utils/route-query";
- import { appUpdate } from "../../lib/wx/update";
- import { addPatientOnlineRecordClockIn } from "./request";
- const { shared, Easing, timing } = wx.worklet;
- const offset = shared(0);
- const menus = ["shareAppMessage", "shareTimeline"];
- // pages/home/home.ts
- import {
- getPatients,
- healthReportMethod,
- healthIndexMethod,
- getSolarTerms,
- getShortScienceList,
- getPatientDescription,
- getNotDealLists,
- getCareList,
- } from "./request";
- import { toCertificationPage, toChats } from "./router";
- // import { useLocation } from "../../lib/use/use-location";
- Page({
- data: {
- isShowComplete: true,
- careList: [],
- displayList: [] as {
- id: number;
- conditioningProgramType: string;
- operateBy?: string;
- operateTime: string;
- frequencyType: string; // 频次类型
- frequencyMeasure: string; // 总用量
- arrangeDate: string; // 下一次开始日期
- finishCount: number; // 完成量
- conditioningProgramName: string; // 调养计划名称
- conditioningProgramSupplierName: string; // 调养计划供应商名称
- expanded: boolean;
- }[],
- allExpanded: false,
- fixedHeight: "370rpx",
- tabbarValue: "/pages/home/home",
- tabbarHidden: false,
- pageHeight: "100vh", // 默认值
- popupList: [] as AnyArray,
- isShowPopup: false,
- patients: [] as (App.Patient.Model & { isDefault: "Y" | "N" })[],
- patient: null as App.Patient.Model | null,
- patientDescription: "",
- healthId: "",
- healthReport: { data: null, message: "", loading: true },
- healthIndex: { data: [], message: "" },
- position: {} as AnyObject,
- location: {} as AnyObject,
- solarTerms: {} as AnyObject,
- sheet: false,
- scienceList: [] as AnyArray,
- _loaded: false,
- statusList: [] as AnyArray,
- switchType: "",
- carouselLoading: {} as Record<string | number, boolean>, // 用于跟踪每个轮播图的加载状态
- // 轮播媒体列表
- carouselMediaList: [] as Array<{
- type: "image" | "video";
- src: string;
- }>,
- },
- behaviors: [
- PageContainerBehavior,
- DraggableSheetBehavior(".draggable-sheet-wrapper"),
- ],
- // 获取调养计划
- async getCareLists() {
- // 保存当前的展开状态
- const currentExpandedStates = this.data.displayList.map((item: any) => ({
- id: item.id,
- expanded: item.expanded,
- }));
- const res = await getCareList();
- if (res && res.length > 0) {
- res.forEach((item: any) => {
- item.carouselMediaList = [];
- // 添加photo
- if (item.photo) {
- item.carouselMediaList.push({
- type: "image",
- src: item.photo,
- });
- }
- // 添加itemImgFirst
- if (item?.itemImgFirst) {
- item.carouselMediaList.push({
- type: "image",
- src: item.itemImgFirst,
- });
- }
- // 添加itemVideoFirst
- if (item?.itemVideoFirst) {
- item.carouselMediaList.push({
- type: "video",
- src: item.itemVideoFirst,
- });
- }
- });
- // 先设置 careList
- this.setData({
- careList: res,
- });
- await this.updateDisplayList(currentExpandedStates);
- setTimeout(() => {
- res.forEach((item: any, index: number) => {
- if (item.carouselMediaList && item.carouselMediaList.length > 0) {
- this.setData({
- [`careList[${index}].carouselMediaList`]: [
- ...item.carouselMediaList,
- ],
- });
- // 同时更新 displayList
- const displayIndex = this.data.displayList.findIndex(
- (displayItem: any) => displayItem.id === item.id
- );
- if (displayIndex !== -1) {
- this.setData({
- [`displayList[${displayIndex}].carouselMediaList`]: [
- ...item.carouselMediaList,
- ],
- });
- }
- }
- });
- }, 100);
- }
- },
- async onLoad(options) {
- appUpdate();
- const query = useRouteQuery(options.scene!);
- if (query.ys) wx.setStorageSync("doctorId", query.ys);
- this.initFabAnimated();
- if (options.switchType) {
- this.setData({
- switchType: options.switchType,
- });
- }
- },
- async onShow() {
- wx.showShareMenu({ withShareTicket: true, menus }).then();
- await this.load();
- // 如果是从一体机扫码进来的 有switchType值就直接跳转到注册页面
- if (
- this.data.switchType &&
- ((this.data.patient as any)?.isPerfectInfo ?? true)
- ) {
- wx.navigateTo({
- url: "/module/user/pages/user-certification/user-certification?type=home",
- });
- }
- // 如果用户没有手机号每次进入页面都提示 点击跳到注册页补充
- // todo 要先判断用户有没有手机号 isPerfectInfo是true 就出来弹窗提示用户
- // if ((this.data.patient as any)?.isPerfectInfo ?? true) {
- // wx.showModal({
- // title: "提示",
- // content: "手机号为空,请补充",
- // success: (res) => {
- // if (res.confirm) {
- // wx.navigateTo({
- // url: "/module/user/pages/user-certification/user-certification?type=home",
- // });
- // }
- // },
- // });
- // }
- },
- onHide() {
- wx.hideShareMenu({ menus }).then();
- offset.value = timing(
- 0,
- { duration: 100, easing: (<any>Easing).linear },
- () => {
- "worklet";
- }
- );
- },
- onShareAppMessage(_opts): WechatMiniprogram.Page.ICustomShareContent {
- return {
- title: `健康为基,从容赏生活之美`,
- imageUrl: `https://wx.hzliuzhi.com/media/healthManager/wx/share.jpg`,
- path: `/pages/home/home`,
- };
- },
- onShareTimeline() {
- return {
- title: `健康为基,从容赏生活之美`,
- };
- },
- async updateDisplayList(
- preserveExpandedStates?: Array<{
- id: number;
- expanded: boolean;
- }>
- ) {
- const { careList, allExpanded } = this.data;
- let newDisplayList: any[] =
- allExpanded || careList.length <= 4 ? careList : careList.slice(0, 4);
- // 如果有保存的展开状态,则恢复它们
- if (preserveExpandedStates && preserveExpandedStates.length > 0) {
- newDisplayList = newDisplayList.map((item: any) => {
- const savedState = preserveExpandedStates.find(
- (state) => state.id === item.id
- );
- if (savedState) {
- return {
- ...item,
- expanded: savedState.expanded,
- };
- }
- return item;
- });
- }
- this.setData({
- displayList: newDisplayList,
- });
- },
- toggleAll() {
- this.setData(
- { allExpanded: !this.data.allExpanded },
- this.updateDisplayList
- );
- },
- toggleItem(e: any) {
- const index = e.currentTarget.dataset.index;
- const key = `displayList[${index}].expanded`;
- this.setData({ [key]: !this.data.displayList[index].expanded });
- },
- // 核销记录
- onRecord(e: any) {
- const id = e.currentTarget.dataset.id;
- if (id) {
- wx.navigateTo({
- url: `/module/care/pages/care/verifyRecord?id=${id}`,
- });
- } else {
- wx.showToast({
- title: "暂无核销记录",
- icon: "none",
- });
- }
- },
- onClose() {
- this.setData({
- isShowPopup: false,
- });
- },
- // 打卡
- pushCard(e: any) {
- const id = e.currentTarget.dataset.id;
- wx.navigateTo({
- url: `/module/article/pages/punch-card/punch-card?id=${id}`,
- });
- },
- calculatePageHeight() {
- const systemInfo = wx.getSystemInfoSync();
- const windowHeight = systemInfo.windowHeight; // 屏幕可用高度
- // 获取 tabbar 高度
- const query = wx.createSelectorQuery();
- query
- .select(".t-tabbar")
- .boundingClientRect((rect) => {
- if (rect) {
- const tabbarHeight = rect.height;
- const contentHeight = windowHeight - tabbarHeight;
- this.setData({
- pageHeight: `${contentHeight}px`,
- });
- }
- })
- .exec();
- },
- getNotDealList() {
- getNotDealLists().then((res) => {
- if (res.length > 0) {
- this.setData({
- popupList: res,
- });
- this.setData({
- isShowPopup: true,
- });
- }
- });
- },
- showFollowPopup() {
- if (this.data.popupList.length > 0) {
- this.setData({
- isShowPopup: true,
- });
- }
- },
- onVisibleChange(e: { detail: { visible: any } }) {
- this.setData({
- isShowPopup: e.detail.visible,
- });
- },
- // 诊疗随访提醒
- goComplete(e: {
- currentTarget: { dataset: { page: string; id: number; title: string } };
- }) {
- const { title } = e.currentTarget.dataset;
- let page = e.currentTarget.dataset.page;
- let id = e.currentTarget.dataset.id;
- // let page = '/module/chats/pages/index/index';
- // let id = 1;
- if (page === "/module/chats/pages/index/index") {
- if (title === "健康评估") {
- wx.setStorageSync("isAnalysis", 4);
- toChats("questionnaire", 2);
- } else {
- wx.setStorageSync("isAnalysis", 2);
- wx.setStorageSync("workId", id);
- wx.navigateTo({
- url: `${page}?component=questionnaire&messageType=1&id=${id}`,
- });
- }
- } else {
- wx.redirectTo({ url: `${page}?id=${id}` });
- // wx.navigateTo({ url: `/module/follow/pages/evaluation/report?id=${id}` });
- }
- },
- // 随访评估报告已出
- goSeeFollowReport() {
- wx.navigateTo({ url: "/module/follow/pages/evaluation/report" });
- },
- async load(forceLogin = false) {
- try {
- await login(forceLogin);
- wx.showLoading({ title: "加载中" });
- const { patient } = await getPatients(/*this.data.patientId*/);
- // if (!patient) await toCertificationPage();
- if (!patient) {
- /*if (wx.getStorageSync("doctorId")) {
- toCertificationPage();
- }*/
- this.setData({
- "healthReport.loading": false,
- isShowComplete: true,
- });
- } else {
- this.setData({ patient });
- this.observerPatient(patient);
- }
- wx.hideLoading();
- } catch (error: any) {
- await wx
- .showModal({
- title: `加载失败`,
- content: `${error?.errMsg ?? error?.message ?? ""}`,
- showCancel: false,
- confirmText: `重新加载`,
- })
- .catch(() => {});
- await this.load(true);
- return;
- }
- if (!this.data._loaded) {
- this.loadScienceList();
- // useLocation()
- // .then((location) => {
- // this.setData({ location });
- // })
- // .catch(() => {});
- getSolarTerms()
- .then((solarTerms) => {
- this.setData({ solarTerms });
- })
- .catch(() => {});
- this.setData({ _loaded: true });
- }
- },
- async _getHealthReport() {
- wx.showLoading({ title: "加载中" });
- this.setData({ "healthReport.loading": true });
- try {
- const data = await healthReportMethod();
- if (!data) {
- this.setData({
- isShowComplete: true,
- });
- } else {
- this.setData({
- isShowComplete: false,
- });
- }
- this.setData({
- "healthReport.data": data,
- "healthReport.loading": false,
- healthId: data?.healthAnalysisReportId,
- });
- let arr2 = [
- [
- {
- title: "健康状态",
- value: data?.willillStateName ? `${data?.willillStateName}` : "",
- },
- {
- title: "程度",
- value: data?.willillDegreeName ? `${data?.willillDegreeName}` : "",
- },
- {
- title: "表现",
- value: data?.willillFunctionName
- ? `${data?.willillFunctionName}`
- : "",
- },
- ],
- [
- {
- title: "中医证素",
- value: data?.factorItemSummary ? `${data?.factorItemSummary}` : "",
- },
- ],
- [
- {
- title: "体质",
- value: data?.constitutionGroupName
- ? `${data?.constitutionGroupName}`
- : "",
- },
- ],
- ];
- this.setData({
- statusList: arr2,
- });
- // if (!data?.healthAnalysisReportId) {
- // this.setData({
- // isShowComplete: true,
- // });
- // }
- } catch (error: any) {
- wx.showToast({
- title: error.errMsg || "加载失败",
- icon: "none",
- });
- this.setData({
- "healthReport.data": [],
- "healthReport.loading": false,
- "healthReport.message": error.errMsg,
- healthId: "",
- });
- }
- wx.hideLoading();
- },
- async _getAbnormalHealthIndex() {
- this.setData({ "healthIndex.loading": true });
- try {
- const data = await healthIndexMethod();
- this.setData({
- "healthIndex.data": data
- .map((item: AnyObject) => item.abnormalDesc)
- .filter(Boolean),
- "healthIndex.loading": false,
- });
- } catch (error: any) {
- this.setData({
- "healthIndex.data": [],
- "healthIndex.loading": false,
- "healthIndex.message": error.errMsg,
- });
- }
- },
- onBodyModel(event: WechatMiniprogram.TouchEvent) {
- if (event.detail?.position === "LB") {
- this.toReportPage();
- } else if (event.detail?.position === "item0") {
- const report = this.data.healthReport.data as unknown as AnyObject;
- this.setData({
- position: {
- LT: [
- "willillState",
- "willillDegree",
- "willillSocial",
- "willillFunction",
- ]
- .map((key) => {
- const title = report[`${key}Name`];
- const description = report[`${key}Description`];
- return title || description ? { title, description } : null;
- })
- .filter(Boolean),
- },
- });
- this.showDraggableSheet();
- } else if (event.detail?.position === "item2") {
- const report = this.data.healthReport.data as unknown as AnyObject;
- const get = (key: string) => ({ [key]: report[key] });
- this.setData({
- position: {
- RT: {
- ...get("constitutionGroupName"),
- ...get("constitutionGroupDefinition"),
- ...get("faceImg"),
- ...get("faceAnalysisResult"),
- ...get("tongueAnalysisResult"),
- ...get("upImg"),
- ...get("downImg"),
- },
- },
- });
- this.showDraggableSheet();
- } else if (event.detail?.position === "item1") {
- const report = this.data.healthReport.data as unknown as AnyObject;
- const get = (key: string) => ({ [key]: report[key] });
- this.setData({
- position: {
- RB: {
- ...get("diagnoseSyndromeSummary"),
- ...get("diagnoseSyndromes"),
- ...get("factorItemSummary"),
- ...get("factorItems"),
- },
- },
- });
- this.showDraggableSheet();
- } else if (event.detail?.position === "CT") {
- this.setData({
- position: {
- CT: this.data.healthIndex.data.map(
- (item, index) => `${index + 1}、${item}`
- ),
- },
- });
- this.showDraggableSheet();
- }
- },
- tabValue() {
- this.setData({
- position: {
- CT: this.data.healthIndex.data.map(
- (item, index) => `${index + 1}、${item}`
- ),
- },
- });
- this.showDraggableSheet();
- },
- initFabAnimated() {
- (<any>this).applyAnimatedStyle(".fab-wrapper", () => {
- "worklet";
- return { right: `${Math.min(offset.value, 36) - 36}px` };
- });
- (<any>this).applyAnimatedStyle(".fab-1", () => {
- "worklet";
- return { transform: `translateY(${-offset.value}px)` };
- });
- (<any>this).applyAnimatedStyle(".fab-2", () => {
- "worklet";
- return {
- transform: `translateX(${-offset.value}px) translateY(${
- -offset.value / 2
- }px)`,
- };
- });
- (<any>this).applyAnimatedStyle(".fab-3", () => {
- "worklet";
- return {
- transform: `translateX(${-offset.value}px) translateY(${
- offset.value / 2
- }px)`,
- };
- });
- (<any>this).applyAnimatedStyle(".fab-4", () => {
- "worklet";
- return { transform: `translateY(${offset.value}px)` };
- });
- },
- onFabTap() {
- const value = Math.abs(offset.value - 72);
- offset.value = timing(
- value,
- { duration: 500, easing: (<any>Easing).linear },
- () => {
- "worklet";
- if (offset.value > 0) offset.value = 72;
- }
- );
- },
- async toChatsPage() {
- if (!this.data.patient?.patientId) {
- try {
- await this.load();
- } catch (error: any) {
- wx.showModal({
- title: "出错了",
- content: error?.errMsg ?? error?.message ?? "错误,请重试",
- showCancel: false,
- });
- return;
- }
- }
- const page = "/module/chats/pages/index/index";
- wx.navigateTo({
- url: `${page}?component=guide&isShowGuide=true`,
- });
- wx.setStorageSync("isAnalysis", 3);
- },
- toSciencePage() {
- wx.navigateTo({ url: `/module/article/pages/science-list/science-list` });
- },
- async toReportPage() {
- // const { patient } = await getPatients(/*this.data.patientId*/);
- if (!this.data.patient) await toCertificationPage();
- else {
- const id = this.data.healthId;
- if (id)
- wx.navigateTo({ url: `/module/health/pages/report/report?id=${id}` });
- else wx.showToast({ title: "暂无分析报告", icon: "none" });
- }
- },
- onDraggableSizeUpdate(e: any) {
- "worklet";
- if (e.pixels < 1) {
- wx.worklet.runOnJS(this.hideDraggableSheet.bind(this))();
- }
- },
- showDraggableSheet() {
- getDraggableSheetContext.call(this).scrollTo({
- size: 0.5,
- pixels: 600,
- animated: true,
- duration: 300,
- easingFunction: "ease",
- });
- this.setData({ sheet: true });
- },
- hideDraggableSheet(event?: any) {
- if (event) {
- getDraggableSheetContext.call(this).scrollTo({
- size: 0,
- animated: true,
- duration: 300,
- easingFunction: "ease",
- });
- }
- this.setData({ position: {}, sheet: false });
- },
- async loadScienceList() {
- try {
- const { data } = await getShortScienceList();
- this.setData({ scienceList: data });
- } catch (error) {}
- },
- observerPatient(model: { patientId: string; sex: "0" | "1" }) {
- wx.setStorageSync("patientId", model.patientId);
- this._getHealthReport();
- this._getAbnormalHealthIndex();
- const patientIcon = { 0: "gender-male", 1: "gender-female" }[model.sex];
- const patientIconColor = { 0: "#0f40f5", 1: "#E560B3" }[model.sex];
- this.setData({ patientIcon, patientIconColor });
- getPatientDescription(model).then((patientDescription) => {
- this.setData({ patientDescription });
- // wx.setStorageSync("patientPhone", patientDescription.phone);
- });
- // 获取未处理随访列表
- this.getNotDealList();
- // 获取调养计划
- this.getCareLists();
- },
- // 没有健康分析去做健康分析
- goHealthAnalyze() {
- wx.redirectTo({
- url: `/module/chats/pages/index/index?component=guide&isShowGuide=true`,
- });
- wx.setStorageSync("showGuideActive", 1);
- wx.setStorageSync("isAnalysis", 3);
- },
- async isGoPunchcard(e: any) {
- const { id, signintime } = e.currentTarget.dataset;
- // 已经打卡了
- if (signintime) {
- // 已打卡 跳转到打卡页面
- wx.navigateTo({
- url: `/module/article/pages/punch-card/punch-card?id=${id}`,
- });
- } else {
- // todo 打卡
- const cardId = e.currentTarget.dataset.id;
- await addPatientOnlineRecordClockIn(cardId);
- wx.showToast({
- title: "打卡成功",
- icon: "success",
- duration: 1500,
- });
- // 无感刷新调养计划,保持展开状态
- await this.refreshCareListsWithState();
- }
- },
- // 无感刷新调养计划,保持展开状态和媒体加载状态
- async refreshCareListsWithState() {
- // 保存当前的展开状态
- const currentExpandedStates = this.data.displayList.map((item: any) => ({
- id: item.id,
- expanded: item.expanded,
- carouselMediaList: item.carouselMediaList, // 保存媒体列表,避免重新加载
- }));
- // 获取新数据
- const res = await getCareList();
- if (res && res.length > 0) {
- res.forEach((item: any) => {
- // 查找对应的旧数据
- const oldItem = currentExpandedStates.find(
- (state) => state.id === item.id
- );
- if (oldItem && oldItem.carouselMediaList) {
- // 保持原有的媒体列表,避免重新加载
- item.carouselMediaList = oldItem.carouselMediaList;
- } else {
- item.carouselMediaList = [];
- // 添加photo
- if (item.photo) {
- item.carouselMediaList.push({
- type: "image",
- src: item.photo,
- });
- }
- // 添加itemImgFirst
- if (item?.itemImgFirst) {
- item.carouselMediaList.push({
- type: "image",
- src: item.itemImgFirst,
- });
- }
- // 添加itemVideoFirst
- if (item?.itemVideoFirst) {
- item.carouselMediaList.push({
- type: "video",
- src: item.itemVideoFirst,
- });
- }
- }
- });
- // 更新 careList
- this.setData({
- careList: res,
- });
- // 更新 displayList 并恢复展开状态
- const { allExpanded } = this.data;
- let newDisplayList: any[] =
- allExpanded || res.length <= 4 ? res : res.slice(0, 4);
- // 恢复展开状态
- newDisplayList = newDisplayList.map((item: any) => {
- const savedState = currentExpandedStates.find(
- (state) => state.id === item.id
- );
- if (savedState) {
- return {
- ...item,
- expanded: savedState.expanded,
- carouselMediaList:
- savedState.carouselMediaList || item.carouselMediaList,
- };
- }
- return item;
- });
- this.setData({
- displayList: newDisplayList,
- });
- }
- },
- /**
- * 轮播组件进入/退出全屏时,隐藏/显示底部 tabbar,防止遮挡视频进度条
- */
- onCarouselFullscreenChange(e: { detail?: { fullScreen?: boolean } }) {
- console.log(e, "全屏模式");
- const fullScreen = !!(e.detail?.fullScreen);
- this.setData({
- tabbarHidden: fullScreen,
- });
- },
- });
|