Component({
  properties: {
    product: {
      type: Object,
      value: {},
      observer: 'updatePrice'
    },
    showTag: {
      type: Boolean,
      value: true
    }
  },

  data: {
    price: '0.00',
    origPrice: '0.00'
  },

  methods: {
    updatePrice(product) {
      if (product && product.price !== undefined) {
        this.setData({
          price: parseFloat(product.price).toFixed(2),
          origPrice: product.original_price ? parseFloat(product.original_price).toFixed(2) : '0.00'
        });
      }
    },

    onTap() {
      if (this.properties.product.id) {
        wx.navigateTo({
          url: '/pages/product/product?id=' + this.properties.product.id
        });
      }
    },

    onImageError(e) {
      // 图片加载失败处理
    }
  },

  lifetimes: {
    attached() {
      this.updatePrice(this.properties.product);
    }
  }
});
