import PageContainerBehavior from "../../../../core/behavior/page-container.behavior"; import TickleBehavior, { getTickleContext } from "../../../../core/behavior/tickle.behavior"; // module/health/pages/scheme/scheme.ts import { healthSchemeMethod } from "../../request"; import { toReportPage } from "../../router"; Component({ behaviors: [ PageContainerBehavior, TickleBehavior ], lifetimes: { attached() { this.getHealthScheme(this.data.id); } }, properties: { id: { type: String, value: '' }, }, data: { dataset: null, schemeId: '', healthIndex: { data: [], loading: false, message: '' }, }, observers: {}, methods: { async getHealthScheme(id: string) { wx.showLoading({ title: '加载中' }); try { const dataset = await healthSchemeMethod(id); console.log(dataset, '1-->'); this.setData({ dataset }); } catch (error) { console.log(error); getTickleContext.call(this).showErrorMessage(error.errMsg || error.message, 0); } wx.hideLoading(); }, toReportPage() { toReportPage(this.data.id); }, // 去购买 goBuy(this: any, e: any) { const item = e.currentTarget.dataset.item || {}; const type: string = (item.buyType || '').toLowerCase(); const appId: string = item.appId || item.appID || item.appid || ''; const miniPath: string = item.path || item.miniPath || ''; const url: string = item.buyUrl || ''; console.log(item, 'item',type); // 优先按显式类型判断 if (type === 'miniprogram' || (!!appId && !type)) { wx.navigateToMiniProgram({ appId, path: miniPath, envVersion: 'release', fail: (err) => { getTickleContext.call(this).showWarnMessage(err.errMsg || '跳转小程序失败'); } }); return; } if (type === 'url' || (!!url && !type)) { if (!url) { getTickleContext.call(this).showWarnMessage('无有效链接'); return; } wx.navigateTo({ url: '/module/article/pages/science-info/science-info', success: (res) => { res.eventChannel?.emit?.('load', { title: item.title || '详情', url }); }, fail: (err) => { getTickleContext.call(this).showWarnMessage(err.errMsg || '打开页面失败'); } }); return; } // 无法识别 getTickleContext.call(this).showWarnMessage('未识别的跳转类型'); } } })