report.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  2. import TickleBehavior, { getTickleContext } from "../../../../core/behavior/tickle.behavior";
  3. // module/health/pages/report/report.ts
  4. import { toSchemePage, toHomePage } from '../../router';
  5. import { healthIndexMethod, healthReportMethod } from "../../request";
  6. import { healthIndex2Progress } from "../../tools/health-index";
  7. Page({
  8. behaviors: [
  9. PageContainerBehavior,
  10. TickleBehavior
  11. ],
  12. data: {
  13. id: '',
  14. dataset: null,
  15. schemeId: '',
  16. healthIndex: { data: [], loading: false, message: '' },
  17. tongueAnalysis: [] as AnyArray,
  18. },
  19. onLoad(query: any) {
  20. this.getHealthReport(query).then(() => this.getHealthIndex(this.data.id));
  21. },
  22. async getHealthReport(query: Record<'id' | 'scene', string>) {
  23. console.log('[log] getHealthReport: load -->', query);
  24. wx.showLoading({ title: '加载中' });
  25. try {
  26. const dataset = await healthReportMethod(query);
  27. this.setData({ dataset, id: dataset.healthAnalysisReportId });
  28. this._update(dataset);
  29. } catch (error) {
  30. getTickleContext.call(this).showErrorMessage(error.errMsg, 0);
  31. }
  32. wx.hideLoading();
  33. },
  34. async getHealthIndex(id?: string) {
  35. this.setData({ 'healthIndex.loading': true, })
  36. try {
  37. const data = await healthIndexMethod(id);
  38. this.setData({
  39. 'healthIndex.data': healthIndex2Progress(data),
  40. 'healthIndex.loading': false,
  41. });
  42. } catch (error) {
  43. this.setData({
  44. 'healthIndex.data': [],
  45. 'healthIndex.loading': false,
  46. 'healthIndex.message': error.errMsg,
  47. });
  48. }
  49. },
  50. toHomePage() { toHomePage(); },
  51. toSchemePage() { toSchemePage(this.data.schemeId); },
  52. toTongueAnalysisResult() {
  53. wx.navigateTo({ url: `/module/health/pages/tongue-analysis/tongue-analysis` })
  54. .then(res => {
  55. res.eventChannel.emit('load', { dataset: this.data.tongueAnalysis });
  56. });
  57. },
  58. _update(data: any) {
  59. const has = data?.isHaveConditioningProgram === 'Y' && data?.isConfirmConditioningProgram === 'Y';
  60. const keys = [
  61. 'tongueColor', 'tongueCoatingColor',
  62. 'tongueShape', 'tongueCoating',
  63. 'bodyFluid', 'sublingualVein'
  64. ]
  65. const tongueAnalysis = [] as AnyObject[];
  66. for (const key of keys) {
  67. const actualList = data?.[key]?.['actualList'] ?? []
  68. tongueAnalysis.push(...actualList.filter((item: AnyObject) => item.contrast !== 's'))
  69. }
  70. this.setData({
  71. schemeId: has ? this.data.id : '',
  72. tongueAnalysis
  73. })
  74. },
  75. });