/*
 * @Descripttion: HJ
 * @Company: 思宏科技
 * @version: v1.0
 * @Author: HJ
 * @Date: 2021-04-05 21:33:31
 * @LastEditors: HJ
 * @LastEditTime: 2021-05-21 10:33:53
 */
const componentOptions = {
  // 组件选项
  options: {
    multipleSlots: true,
  },
  properties: {
    storeInfo: {
      type: Object,
      value: {},
      observer(v) {
        if (v) {
          let { environmentImages = null, deliveryList } = v || {};
          if (typeof environmentImages === "string" && environmentImages) {
            environmentImages = environmentImages.split(",");
            this.setData({
              environmentImages,
            });
          }

          if (Array.isArray(deliveryList) && deliveryList.length > 0) {
            const tempDelivery = deliveryList.filter((i) => i.status);
            const { deliveryName } = tempDelivery[0] || {};
            this.setData({
              deliveryName,
            });
          }
        }
      },
    },
  },
  // 组件数据
  data: {
    isPageHidden: false, // 页面是否处于隐藏状态
    // 环境图片
    environmentImages: [],
    // 配送方式
    deliveryName: "",
  },
  // 组件方法
  methods: {
    nav() {
      const storeId = wx.getStorageSync("storeid");
      wx.navigateTo({
        url: `/package/security-archive/index?storeId=${storeId}`,
      });
    },
    // 快捷电话
    ringUp({ currentTarget: { dataset } }) {
      const { phone } = dataset;
      wx.makePhoneCall({
        phoneNumber: phone,
      });
    },
    // 预览图片
    previewImg({ currentTarget: { dataset } }) {
      const { src } = dataset;
      wx.previewImage({
        current: src,
        urls: this.data.environmentImages,
      });
    },
  },
  // 页面生命周期
  pageLifetimes: {
    // 页面被展示
    show() {
      const { isPageHidden } = this.data;

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

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

      // 清除定时器等操作
    },
  },
};

Component(componentOptions);
