| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
- import TickleBehavior, { getTickleContext } from "../../../../core/behavior/tickle.behavior";
- import { getPatients } from "../../../../lib/request/common";
- // module/health/pages/report/report.ts
- import { toSchemePage, toHomePage } from "../../router";
- import { healthIndexMethod, healthReportMethod } from "../../request";
- import { healthIndex2Progress } from "../../tools/health-index";
- Page({
- behaviors: [PageContainerBehavior, TickleBehavior],
- data: {
- id: "",
- dataset: null as unknown as AnyObject,
- showScheme: false,
- schemeId: "",
- healthIndex: { data: [], loading: false, message: "" },
- tongueAnalysis: [] as AnyArray,
- showUserAuth: false,
- switchType: "",
- },
- onLoad(query: any) {
- this._load(query).then((id: string) => {
- if (id) this.getHealthIndex(id);
- });
- if (query.scene) {
- this.setData({
- switchType: query.scene,
- });
- }
- },
- async _load(query: Record<"id" | "scene", string>) {
- let id = "";
- wx.showLoading({ title: "加载中" });
- try {
- if (query.scene) {
- // 查找患者是否需要授权
- const { auth } = await getPatients().catch(() => ({ auth: true }));
- if (auth) this.setData({ showUserAuth: true });
- }
- const { __origin__, ...dataset } = await healthReportMethod(query);
- id = dataset.id;
- const showScheme = __origin__?.isHaveConditioningProgram === "Y";
- const schemeId =
- __origin__?.isConfirmConditioningProgram === "Y" ? id : "";
- this.setData({
- showScheme,
- schemeId,
- dataset: {
- ...dataset,
- factorItems: __origin__?.factorItems,
- diagnoseSyndromes: __origin__?.diagnoseSyndromes,
- },
- });
- } catch (error) {
- getTickleContext.call(this).showErrorMessage(error.errMsg, 0);
- }
- wx.hideLoading();
- return id;
- },
- async getHealthIndex(id?: string) {
- this.setData({ "healthIndex.loading": true });
- try {
- const data = await healthIndexMethod(id);
- this.setData({
- "healthIndex.data": healthIndex2Progress(data),
- "healthIndex.loading": false,
- });
- } catch (error) {
- this.setData({
- "healthIndex.data": [],
- "healthIndex.loading": false,
- "healthIndex.message": error.errMsg,
- });
- }
- },
- toHomePage() {
- toHomePage(this.data.switchType as string);
- },
- toSchemePage() {
- toSchemePage(this.data.schemeId);
- },
- openMessage(event: any) {
- const message = event?.detail?.content
- if (message) getTickleContext.call(this).showMessage(event.detail.type || 'info', message);
- }
- });
|