Просмотр исходного кода

健康分析报告添加扫小程序逻辑

cc12458 1 год назад
Родитель
Сommit
8888603793

+ 61 - 62
miniprogram/module/health/pages/report/report.ts

@@ -2,83 +2,82 @@ import PageContainerBehavior from "../../../../core/behavior/page-container.beha
 import TickleBehavior, { getTickleContext } from "../../../../core/behavior/tickle.behavior";
 
 // module/health/pages/report/report.ts
-import { toSchemePage } from '../../router';
+import { toSchemePage, toHomePage } from '../../router';
 import { healthIndexMethod, healthReportMethod } from "../../request";
 import { healthIndex2Progress } from "../../tools/health-index";
-Component({
+
+
+Page({
   behaviors: [
     PageContainerBehavior,
     TickleBehavior
   ],
-  lifetimes: {
-    attached() {
-      this.getHealthReport(this.data.id);
-      this.getHealthIndex(this.data.id);
-    }
-  },
-  properties: {
-    id: { type: String, value: '' },
-  },
   data: {
+    id: '',
     dataset: null,
     schemeId: '',
     healthIndex: { data: [], loading: false, message: '' },
     tongueAnalysis: [] as AnyArray,
   },
-  observers: {
-    'dataset'(data) {
-      const has = data?.isHaveConditioningProgram === 'Y' && data?.isConfirmConditioningProgram === 'Y';
+  onLoad(query: any) {
+    this.getHealthReport(query).then(() => this.getHealthIndex(this.data.id));
+  },
+
+  async getHealthReport(query: Record<'id' | 'scene', string>) {
+    console.log('[log] getHealthReport: load -->', query);
+    wx.showLoading({ title: '加载中' });
+    try {
+      const dataset = await healthReportMethod(query);
+      this.setData({ dataset, id: dataset.healthAnalysisReportId });
 
-      const keys = [
-        'tongueColor', 'tongueCoatingColor',
-        'tongueShape', 'tongueCoating',
-        'bodyFluid', 'sublingualVein'
-      ]
-      const tongueAnalysis = [] as AnyObject[];
-      for (const key of keys) {
-        const actualList = data?.[key]?.['actualList'] ?? []
-        tongueAnalysis.push(...actualList.filter((item: AnyObject) => item.contrast !== 's'))
-      }
+      this._update(dataset);
+    } catch (error) {
+      getTickleContext.call(this).showErrorMessage(error.errMsg, 0);
+    }
+    wx.hideLoading();
+  },
 
+  async getHealthIndex(id?: string) {
+    this.setData({ 'healthIndex.loading': true, })
+    try {
+      const data = await healthIndexMethod(id);
       this.setData({
-        schemeId: has ? this.data.id : '',
-        tongueAnalysis
-      })
+        'healthIndex.data': healthIndex2Progress(data),
+        'healthIndex.loading': false,
+      });
+    } catch (error) {
+      this.setData({
+        'healthIndex.data': [],
+        'healthIndex.loading': false,
+        'healthIndex.message': error.errMsg,
+      });
     }
   },
-  methods: {
-    async getHealthReport(id?: string) {
-      wx.showLoading({ title: '加载中' });
-      try {
-        const dataset = await healthReportMethod(id);
-        this.setData({ dataset });
-      } catch (error) {
-        getTickleContext.call(this).showErrorMessage(error.errMsg, 0);
-      }
-      wx.hideLoading();
-    },
-    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,
-        });
-      }
-    },
-    toSchemePage() { toSchemePage(this.data.schemeId); },
-    toTongueAnalysisResult() {
-      wx.navigateTo({ url: `/module/health/pages/tongue-analysis/tongue-analysis` })
-        .then(res => {
-          res.eventChannel.emit('load', { dataset: this.data.tongueAnalysis });
-        });
+  toHomePage() { toHomePage(); },
+  toSchemePage() { toSchemePage(this.data.schemeId); },
+  toTongueAnalysisResult() {
+    wx.navigateTo({ url: `/module/health/pages/tongue-analysis/tongue-analysis` })
+      .then(res => {
+        res.eventChannel.emit('load', { dataset: this.data.tongueAnalysis });
+      });
+  },
+
+  _update(data: any) {
+    const has = data?.isHaveConditioningProgram === 'Y' && data?.isConfirmConditioningProgram === 'Y';
+    const keys = [
+      'tongueColor', 'tongueCoatingColor',
+      'tongueShape', 'tongueCoating',
+      'bodyFluid', 'sublingualVein'
+    ]
+    const tongueAnalysis = [] as AnyObject[];
+    for (const key of keys) {
+      const actualList = data?.[key]?.['actualList'] ?? []
+      tongueAnalysis.push(...actualList.filter((item: AnyObject) => item.contrast !== 's'))
     }
-  }
-})
+
+    this.setData({
+      schemeId: has ? this.data.id : '',
+      tongueAnalysis
+    })
+  },
+});

+ 1 - 1
miniprogram/module/health/pages/report/report.wxml

@@ -1,5 +1,5 @@
 <!--module/health/pages/report/report.wxml-->
-<t-navbar title="健康分析报告" left-arrow />
+<t-navbar title="健康分析报告" left-arrow bind:fail="toHomePage"/>
 
 <scroll-view class="page-scroll__container" type="list" scroll-y style="{{containerStyle}}">
   <view class="card-wrapper">

+ 10 - 5
miniprogram/module/health/request.ts

@@ -19,7 +19,7 @@ export function healthReportListMethod() {
   return Get(`/analysisManage/getHarsTid`, { transform })
 }
 
-export function healthReportMethod(id?: string) {
+export function healthReportMethod({id, ...query}: Record<'id' | 'scene', string>) {
   const transform = ({ data }: AnyObject) => {
     if (Array.isArray(data?.conditProgram?.types)) {
       data.conditProgram.types = data.conditProgram.types.map((item: AnyObject) => (item.summary = item.summary?.replace(/null/g, '') || '', item))
@@ -27,9 +27,14 @@ export function healthReportMethod(id?: string) {
     return data;
   };
 
+  let params = { ...query } as any;
+  if (id) { params.healthAnalysisReportId = id; }
+
+  if (query.scene) { return Get(`/analysisManage/getHealRepDetailByScene`, { params, transform }); }
+
   return id
-    ? Get(`/analysisManage/getHealRepDetailById`, { params: { healthAnalysisReportId: id }, transform })
-    : Post(`/analysisManage/getLastHealRepDetail`, {}, { transform })
+    ? Get(`/analysisManage/getHealRepDetailById`, { params, transform })
+    : Post(`/analysisManage/getLastHealRepDetail`, {}, { params, transform })
 }
 
 /**
@@ -55,8 +60,8 @@ export function healthSchemeMethod(id: string) {
             return {
               title: item?.name || '',
               descriptions: item?.attrs?.map((attr: AnyArray, k: number) => {
-                return {...attr, id: `description-${i}-${j}-${k}`,}
-              }) ?? [], 
+                return { ...attr, id: `description-${i}-${j}-${k}`, }
+              }) ?? [],
               children: item?.items?.map((item: AnyObject, k: number) => {
                 switch (item?.type) {
                   case 'img':

+ 4 - 1
miniprogram/module/health/router.ts

@@ -1,4 +1,7 @@
-export function toSchemePage(id?: string) { 
+export function toHomePage() {
+  wx.reLaunch({ url: '/pages/home/home' })
+}
+export function toSchemePage(id?: string) {
   if (!id) {
     wx.showToast({ title: '暂无调理方案', icon: 'none' });
     return