/*
 * @Descripttion: HJ
 * @Company: 思宏科技
 * @version: v1.0
 * @Author: HJ
 * @Date: 2021-05-26 10:15:33
 * @LastEditors: HJ
 * @LastEditTime: 2021-06-03 15:56:09
 */
const componentOptions = {
  // 组件选项
  options: {
    multipleSlots: true,
  },
  behaviors: [],
  properties: {
    foods: {
      type: Array,
      value: [],
    },
  },
  // 组件数据
  data: {
    isPageHidden: false, // 页面是否处于隐藏状态
  },
  // 数据监听器
  observers: {},
  // 组件方法
  methods: {
    init() {},
    nav({ currentTarget: { dataset } }) {
      const { info } = dataset;

      const { store, ...foodInfo } = info || {};
      const { id: storeId } = store || {};
      const { foodId, merchantId } = foodInfo;

      if (!info || this.data.foods.length >= 4) {
        wx.navigateTo({
          url: `/activity/pages/preferential/index?foodId=${foodId}`,
        });
        return;
      }

      if (this.data.foods.length < 4) {
        wx.setStorageSync("storeid", storeId);
        wx.setStorageSync("merchantid", merchantId);
        const tempFoodInfo = wx.$urlEncode(foodInfo);
        wx.nextTick(() => {
          wx.navigateTo({
            url: `/store/pages/lunch/index?foodId=${foodId}&foodInfo=${tempFoodInfo}&from=preferential`,
          });
        });
      }
    },
  },
  // 组件生命周期
  lifetimes: {
    created() {},
    attached() {
      this.init();
    },
    ready() {},
    moved() {},
    detached() {},
  },
  definitionFilter() {},
  // 页面生命周期
  pageLifetimes: {
    // 页面被展示
    show() {
      const { isPageHidden } = this.data;

      // show事件发生前，页面不是处于隐藏状态时
      if (!isPageHidden) {
        return;
      }

      // 重新执行定时器等操作
    },
    // 页面被隐藏
    hide() {
      this.setData({
        isPageHidden: true,
      });

      // 清除定时器等操作
    },
    // 页面尺寸变化时
    resize() {},
  },
};

Component(componentOptions);
