index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import store from './store';
  2. import { getOrderDetail, getVisitDetail, queryDetail, getPayDetail } from '../../components/utils/service';
  3. import { mapToArray, replaceStar } from '../../components/utils/index';
  4. const config = {
  5. order: {
  6. title: '预约记录',
  7. service: async ({
  8. queryId
  9. }) => {
  10. const [err, result] = await getOrderDetail({
  11. orderId: queryId
  12. });
  13. return [err, { ...result,
  14. viewCardNum: replaceStar(result.cardNum, 3, 4)
  15. }];
  16. }
  17. },
  18. visit: {
  19. title: '就诊记录',
  20. service: async ({
  21. queryId
  22. }) => {
  23. const [err, result] = await getVisitDetail({
  24. visitId: queryId
  25. });
  26. return [err, { ...result,
  27. viewCardNum: replaceStar(result.cardNum, 3, 4)
  28. }];
  29. }
  30. },
  31. charge: {
  32. title: '充值记录',
  33. service: async ({
  34. queryId
  35. }) => {
  36. const [err, result] = await getPayDetail({
  37. type: 2,
  38. outTradeNo: queryId
  39. });
  40. return [err, { ...result,
  41. customInfo: mapToArray(result.customInfo),
  42. viewCardNum: replaceStar(result.cardNum, 3, 4)
  43. }];
  44. }
  45. },
  46. report: {
  47. title: '报告详情',
  48. service: ({
  49. queryId
  50. }) => queryDetail({
  51. recordId: queryId
  52. })
  53. }
  54. };
  55. Page(store.register({
  56. data: {
  57. type: '',
  58. // 根据不同的类型展示不同的页面
  59. queryId: '',
  60. detail: {},
  61. // 页面展示的数据
  62. options: {} // 兼容框架bug取不到 options 的问题
  63. },
  64. onLoad(options) {
  65. const {
  66. type
  67. } = options;
  68. const {
  69. title
  70. } = config[type]; // 只需要服务首页上报,注释掉组件内部的调用
  71. // reportCmPV_YL({ title, query: options });
  72. my.setNavigationBar({
  73. title
  74. });
  75. this.setData({
  76. options
  77. }, () => this.onFetchDetail());
  78. },
  79. // 获取数据
  80. async onFetchDetail() {
  81. const {
  82. options
  83. } = this.data;
  84. const {
  85. service
  86. } = config[options.type];
  87. const [, result] = await service(options);
  88. if (result) {
  89. this.setData({
  90. type: options.type,
  91. queryId: options.queryId,
  92. detail: result
  93. });
  94. }
  95. },
  96. navigateBack() {
  97. my.navigateBack();
  98. },
  99. onReachBottom() {},
  100. onShareAppMessage() {
  101. const {
  102. type,
  103. queryId
  104. } = this.data;
  105. return {
  106. title: this.data.pageName || '',
  107. path: `${this.route}?type=${type}&queryId=${queryId}`
  108. };
  109. }
  110. }));