index.js 3.91 KB
Newer Older
李嘉林 committed
1
const app = getApp();
李嘉林 committed
2
const { goodsApi, DFSImg, $themeToLink, $themeAddToCard } = app;
李嘉林 committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
const componentOptions = {
  // 组件选项
  options: {
    multipleSlots: true
  },
  behaviors: [],
  properties: {
    datas: {
      type: Object
    },
    items: {
      type: Object
    },
    indexs: {
      type: Number
    }
  },
  // 组件数据
  data: {
李嘉林 committed
22
    isPageHidden: false, // 页面是否处于隐藏状态
李嘉林 committed
23
    timeData: {}
李嘉林 committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
  },
  // 数据监听器
  observers: {},
  // 组件方法
  methods: {
    init() {},
    getSaleTime(val) {
      return new Date(val.replace(/-/g, "/")).getTime() - new Date().getTime();
    },
    showVipPrice(index) {
      // 索引 0 显示价格 1显示名称
      let showFlag = false;
      let vipPrice = this.items["minPriceAfterRecommendedCardPriceTable"];
      if (vipPrice && Number(vipPrice) < Number(this.items["minPrice"])) {
        showFlag = true;
      }
      console.log(showFlag, "------------760");
      return showFlag;
    },
    showVipTag(index) {
      // 索引 0 显示价格 1显示名称
      let showFlag = false;
      let vipPrice = this.items["minPriceAfterRecommendedCardPriceTable"];
      let showTag = this.items["recommendedCardMinPricePriceTableName"];
      if (
        vipPrice &&
        showTag &&
        Number(vipPrice) <= Number(this.items["minPrice"])
      ) {
        showFlag = true;
      }
      return showFlag;
李嘉林 committed
56 57 58
    },
    onChange(e) {
      this.setData({ timeData: e.detail });
李嘉林 committed
59
    },
侯体倬 committed
60
    onclickProduct(e) {
李嘉林 committed
61 62
      let { goodsType } = this.data.datas.componentData;
      let {
侯体倬 committed
63
        shopName,
李嘉林 committed
64
        productId,
侯体倬 committed
65
        productName,
李嘉林 committed
66 67 68 69 70 71 72 73 74
        terminalProductId,
        terminalGoodsMixId
      } = this.data.items;
      let linkVal = "";
      if (goodsType == 0) {
        linkVal = `/goods/${productId}?terminalProductId=${terminalProductId}`;
      } else if (goodsType == 1) {
        linkVal = `/pointShop/goodsDetail?productId${productId}&terminalProductId=${terminalProductId}&terminalGoodsMixId=${terminalGoodsMixId}`;
      }
侯体倬 committed
75 76 77
      app.trackCpn(e, this.data.datas.componentName, {
        shopName,productId,productName,terminalProductId,terminalGoodsMixId
      })
李嘉林 committed
78 79 80 81 82
      $themeToLink({
        type: 1,
        link: linkVal
      });
    },
侯体倬 committed
83
    onclickBuynow(e) {
李嘉林 committed
84 85 86 87
      let { btnType } = this.data.datas.componentData;
      let {
        minProductGoodsMixid,
        minProductGoodsId,
侯体倬 committed
88 89 90
        productName,
        minGoodsId,
        shopName
李嘉林 committed
91 92 93 94 95
      } = this.data.items;
      let linkVal = "";
      if (btnType < 6) {
        // 加入购物车
        console.log("加入购物车");
李嘉林 committed
96
        $themeAddToCard(this.data.items);
李嘉林 committed
97 98 99 100 101
      } else {
        // 进入确认订单
        linkVal = `/order/orderConfirm?productGoodsMixId=${minProductGoodsMixid}&productGoodsId=${minProductGoodsId}&goodsId=${minGoodsId}&qty=1&goodsString=null&source=3`;
      }
      console.log(linkVal, "-------90");
侯体倬 committed
102 103 104
      app.trackCpn(e, this.data.datas.componentName, {
        shopName,minGoodsId,productName,minProductGoodsId,minProductGoodsMixid
      })
李嘉林 committed
105 106
      $themeToLink({ type: 1, link: linkVal });
    },
侯体倬 committed
107
    toMerchants(e) {
李嘉林 committed
108
      let { orgId } = this.data.items;
侯体倬 committed
109
      app.trackCpn(e, this.data.datas.componentName, 'toMerchants')
李嘉林 committed
110 111 112
       $themeToLink({ type: 1, link: `/merchantsDetail/${orgId}` });

    },
李嘉林 committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
  },
  // 组件生命周期
  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)