report.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. },
  26. observers: {
  27. 'dataset'(data) {
  28. const has = data?.isHaveConditioningProgram === 'Y' && data?.isConfirmConditioningProgram === 'Y';
  29. this.setData({ schemeId: has ? this.data.id : '' })
  30. }
  31. },
  32. methods: {
  33. async getHealthReport(id?: string) {
  34. wx.showLoading({ title: '加载中' });
  35. try {
  36. const dataset = await healthReportMethod(id);
  37. this.setData({ dataset });
  38. } catch (error) {
  39. getTickleContext.call(this).showErrorMessage(error.errMsg, 0);
  40. }
  41. wx.hideLoading();
  42. },
  43. async getHealthIndex(id?: string) {
  44. this.setData({ 'healthIndex.loading': true, })
  45. try {
  46. const data = await healthIndexMethod(id);
  47. this.setData({
  48. 'healthIndex.data': healthIndex2Progress(data),
  49. 'healthIndex.loading': false,
  50. });
  51. } catch (error) {
  52. this.setData({
  53. 'healthIndex.data': [],
  54. 'healthIndex.loading': false,
  55. 'healthIndex.message': error.errMsg,
  56. });
  57. }
  58. },
  59. toSchemePage() { toSchemePage(this.data.schemeId); }
  60. }
  61. })