report.ts 2.5 KB

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