import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
import tickleBehavior, { getTickleContext } from "../../../../core/behavior/tickle.behavior";
import { getScienceMethod } from "../../request";
// module/diet/pages/science-info/science-info.ts
Component({
  behaviors: [
    PageContainerBehavior,
    tickleBehavior,
  ],
  lifetimes: {
    attached() {
      const channel = this.getOpenerEventChannel();
      channel.on?.('load', (data: AnyObject) => {
        this.setData({ title: data?.title ?? '' });
      })
      this.load();
    }
  },
  properties: {
    id: { type: String, value: '' },
  },
  data: {
    title: ''
  },
  methods: {
    async load() {
      wx.showLoading({ title: '加载中' });
      try {
        const dataset = await getScienceMethod(this.data.id);
        this.setData({ dataset, title: dataset.name });
      } catch (error) {
        getTickleContext.call(this).showWarnMessage(error.errMsg);
      }
      wx.hideLoading();
    }
  }
})