report.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 as unknown as AnyObject,
  15. showScheme: false,
  16. schemeId: '',
  17. healthIndex: { data: [], loading: false, message: '' },
  18. tongueAnalysis: [] as AnyArray,
  19. },
  20. onLoad(query: any) {
  21. this._load(query).then((id: string) => { if (id) this.getHealthIndex(id); });
  22. },
  23. async _load(query: Record<'id' | 'scene', string>) {
  24. let id = '';
  25. wx.showLoading({ title: '加载中' });
  26. try {
  27. const { __origin__, ...dataset } = await healthReportMethod(query);
  28. id = dataset.id;
  29. const showScheme = __origin__?.isHaveConditioningProgram === 'Y';
  30. const schemeId = __origin__?.isConfirmConditioningProgram === 'Y' ? id : '';
  31. this.setData({
  32. showScheme, schemeId,
  33. dataset: {
  34. ...dataset,
  35. factorItems: __origin__?.factorItems,
  36. diagnoseSyndromes: __origin__?.diagnoseSyndromes,
  37. }
  38. });
  39. } catch (error) {
  40. getTickleContext.call(this).showErrorMessage(error.errMsg, 0);
  41. }
  42. wx.hideLoading();
  43. return id;
  44. },
  45. async getHealthIndex(id?: string) {
  46. this.setData({ 'healthIndex.loading': true, })
  47. try {
  48. const data = await healthIndexMethod(id);
  49. this.setData({
  50. 'healthIndex.data': healthIndex2Progress(data),
  51. 'healthIndex.loading': false,
  52. });
  53. } catch (error) {
  54. this.setData({
  55. 'healthIndex.data': [],
  56. 'healthIndex.loading': false,
  57. 'healthIndex.message': error.errMsg,
  58. });
  59. }
  60. },
  61. toHomePage() { toHomePage(); },
  62. toSchemePage() { toSchemePage(this.data.schemeId); },
  63. });