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