// module/article/components/science-card/science-card.ts
// import { HOST } from "../../../../app.config";
import { Get } from "../../../../lib/request/method";
Component({
  properties: {
    item: { type: Object, value: {} },
    index: { type: Number, value: 0 },
    replace: { type: Boolean, value: false },
  },
  data: {},
  methods: {
    async toInfoPage(event: WechatMiniprogram.TouchEvent) {
      const id = event.currentTarget.id;
      if (this.data.replace) {
        wx.redirectTo({ url: `/module/article/pages/science-info/science-info?id=${id}` });
      } else {
        const id = event.currentTarget.id;
        // const url = `https://${HOST}/admin/editor/preview.html?popularScienceArticleId=${id}`;
      
        try {
          const res = await Get(`/psarticle/clickPsarticle`, {
            params: { popularScienceArticleId: id },
          });
          const url = res?.data;
          const item = {
            url,
          };
          wx.navigateTo({
            url: `/module/article/pages/science-info/science-info`,
          }).then((res) => {
            res.eventChannel.emit("load", item);
          });
        } catch (error) {
          console.log(error);
        }
        // const url = `https://${HOST}/admin/editor/preview.html?popularScienceArticleId=${id}`;
        // const item = {
        //   url,
        // };
        // wx.navigateTo({
        //   url: `/module/article/pages/science-info/science-info?url=${url}`,
        // }).then((res) => {
        //   res.eventChannel.emit("load", item);
        // });
      //   wx.navigateTo({ url: `/module/article/pages/science-info/science-info?id=${id}` })
      //     .then(res => { res.eventChannel.emit('load', this.data.item) })
      }
    }
  }
})