foot-print.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  2. import tickleBehavior, {
  3. getTickleContext,
  4. } from "../../../../core/behavior/tickle.behavior";
  5. import { getFootPrintListMethod } from "../../request";
  6. import { Get } from "../../../../lib/request/method";
  7. import { getFullImageUrl } from "../../../../utils/util";
  8. Page({
  9. behaviors: [PageContainerBehavior, tickleBehavior],
  10. lifetimes: {
  11. attached() {},
  12. },
  13. properties: {},
  14. data: {
  15. articleList: [] as any[],
  16. },
  17. async goDetail(e: any) {
  18. const type = e.currentTarget.dataset.type;
  19. const item = e.currentTarget.dataset.item;
  20. // type ,1-健康宣教 2-药膳 3-膳食 4-茶饮
  21. // 药膳详情
  22. if (type === "1") {
  23. try {
  24. const res: any = await Get(`/psarticle/clickPsarticle`, {
  25. params: { popularScienceArticleId: item.sourceId },
  26. });
  27. const url = res?.data;
  28. const detailPayload = {
  29. url,
  30. };
  31. wx.navigateTo({
  32. url: `/module/article/pages/science-info/science-info`,
  33. }).then((res) => {
  34. res.eventChannel.emit("load", detailPayload);
  35. });
  36. } catch (error) {
  37. console.log(error);
  38. }
  39. } else if (type === "2" || type === "4") {
  40. wx.navigateTo({
  41. url: `/module/article/pages/diet-info/diet-info?id=${item.sourceId}`,
  42. }).then((res) => {
  43. res.eventChannel.emit("load", item);
  44. });
  45. }
  46. },
  47. async load() {
  48. wx.showLoading({ title: "加载中" });
  49. try {
  50. const res = await getFootPrintListMethod();
  51. const list = res?.data?.data ?? [];
  52. if (Array.isArray(list)) {
  53. list.forEach((item: any) => {
  54. item.briefImg = getFullImageUrl(item.briefImg);
  55. });
  56. }
  57. this.setData({ articleList: Array.isArray(list) ? list : [] });
  58. } catch (error: any) {
  59. getTickleContext.call(this).showWarnMessage(error.errMsg);
  60. }
  61. wx.hideLoading();
  62. },
  63. onShow() {
  64. this.load();
  65. },
  66. });