Goods.js 1.89 KB
// components/Goods/Goods.js
import {componentsMixin } from '../../mixins/index'
Component({
  behaviors:[componentsMixin],
  /**
   * 组件的属性列表
   */
  properties: {
    item: {
      type: Object,
      observer(n, o) {
        if (n) {
          if (n.activityInfo) {
            n.originalPrice = ''
            n.retailPrice = n.activityInfo.activityPrice
            n.goodsStatistics.saleAmount = n.activityInfo.saleAmount
            if (n.activityInfo.specificationExtraList && n.activityInfo.specificationExtraList.length) {
              n.retailPrice = n.activityInfo.specificationExtraList[0].retailPrice
              n.up = true
            }
          } else {
            if (n.originalPrice) n.originalPrice = wx.$util.centsToyuan(n.originalPrice)
            if (n.specificationDetailList && n.specificationDetailList.length) {
              n.retailPrice = n.specificationDetailList[0].retailPrice
              n.up = true
            }
          }
          n.retailPrice = Number(wx.$util.centsToyuan(n.retailPrice)).toFixed(2)
          if (n.retailPrice > 9999) {
            n.retailPrice = Number(n.retailPrice / 10000).toFixed(2)
            n.unit = '万'
          }
          this.setData({ item: n })
        }
      }
    },
    indexStyle: Boolean
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    setWidth() {
      wx.$util.getViewInfo('.Goods', res => {
        this.setData({
          previewHeight: res.width * 2
        })
      }, this)
    },
    jump(e) {
      let { item } = e.currentTarget.dataset
      let { id, activityInfo } = item
      let isActivity = false
      if (activityInfo) {
        id = activityInfo.id
        isActivity = true
      }
      wx.$router.go('packageMall.detail', { id, isActivity, notIntercept: true })
    }
  },
  lifetimes: {
    attached() {
      this.setWidth()
    }
  }
})