cart-item.js 941 Bytes
Component({
  properties: {
    item: {
      type: Object,
      value: {},
      observer: '_itemChange'
    },
    index: {
      type: Number,
      value: 0
    }
  },
  methods: {
    _itemChange(item) {
      if (item) {
        item.mark_price = item.sales_price;

        switch (item.goods_type) {
          case 'price_gift':
            item.sales_price = +item.last_price;
            break;
          case 'gift':
            item.sales_price = 0;
            break;
          default:
            if (item.last_vip_price < item.sales_price) {
              item.sales_price = item.last_vip_price;
            }
            break;
        }

        if (item.mark_price <= item.sales_price) {
          delete item.mark_price;
        }

        item.isVipPrice = item.vip_discount_money > 0;

        this.setData({item});
      }
    },
    itemTapped() {
      this.triggerEvent('itemTapped', this.data.item);
    }
  }
});