scheme.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/scheme/scheme.ts
  4. import { healthSchemeMethod } from "../../request";
  5. import { toReportPage } from "../../router";
  6. Component({
  7. behaviors: [
  8. PageContainerBehavior,
  9. TickleBehavior
  10. ],
  11. lifetimes: {
  12. attached() {
  13. this.getHealthScheme(this.data.id);
  14. }
  15. },
  16. properties: {
  17. id: { type: String, value: '' },
  18. },
  19. data: {
  20. dataset: null,
  21. schemeId: '',
  22. healthIndex: { data: [], loading: false, message: '' },
  23. },
  24. observers: {},
  25. methods: {
  26. async getHealthScheme(id: string) {
  27. wx.showLoading({ title: '加载中' });
  28. try {
  29. const dataset = await healthSchemeMethod(id);
  30. console.log(dataset, '1-->');
  31. this.setData({ dataset });
  32. } catch (error) {
  33. console.log(error);
  34. getTickleContext.call(this).showErrorMessage(error.errMsg || error.message, 0);
  35. }
  36. wx.hideLoading();
  37. },
  38. toReportPage() { toReportPage(this.data.id); },
  39. // 去购买
  40. goBuy(this: any, e: any) {
  41. const item = e.currentTarget.dataset.item || {};
  42. const type: string = (item.buyType || '').toLowerCase();
  43. const appId: string = item.appId || item.appID || item.appid || '';
  44. const miniPath: string = item.path || item.miniPath || '';
  45. const url: string = item.buyUrl || '';
  46. console.log(item, 'item',type);
  47. // 优先按显式类型判断
  48. if (type === 'miniprogram' || (!!appId && !type)) {
  49. wx.navigateToMiniProgram({
  50. appId,
  51. path: miniPath,
  52. envVersion: 'release',
  53. fail: (err) => {
  54. getTickleContext.call(this).showWarnMessage(err.errMsg || '跳转小程序失败');
  55. }
  56. });
  57. return;
  58. }
  59. if (type === 'url' || (!!url && !type)) {
  60. if (!url) {
  61. getTickleContext.call(this).showWarnMessage('无有效链接');
  62. return;
  63. }
  64. wx.navigateTo({
  65. url: '/module/article/pages/science-info/science-info',
  66. success: (res) => {
  67. res.eventChannel?.emit?.('load', { title: item.title || '详情', url });
  68. },
  69. fail: (err) => {
  70. getTickleContext.call(this).showWarnMessage(err.errMsg || '打开页面失败');
  71. }
  72. });
  73. return;
  74. }
  75. // 无法识别
  76. getTickleContext.call(this).showWarnMessage('未识别的跳转类型');
  77. }
  78. }
  79. })