product-group-item.vue 3.84 KB
<template>
  <div
    class="product-item"
    :class="{single}">
    <div class="product-content" @click="onClick">
      <div class="product-image">
        <ImageFormat class="image" :lazy="lazy" :src="product.productImage" :width="136" :height="180"></ImageFormat>
      </div>
      <div class="product-info">
        <p class="product-name">{{product.productName}}</p>
        <div class="price">
          <span>¥{{product.salesPrice}}</span>
          <div class="btn-right btn-buy hover-opacity">
            <span class="iconfont icon-cart"></span>购买
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import YAS from 'utils/yas-constants';

export default {
  name: 'ProductGroupItem',
  props: {
    single: Boolean,
    lazy: Boolean,
    product: Object,
    share: Boolean,
    thumb: Boolean,
    posId: Number,
    articleId: [String, Number],
    index: Number
  },
  data() {
    return {
      posting: false,
      favorite: this.product.favorite
    };
  },
  watch: {
    'product.favorite'(val) {
      this.favorite = val;
    }
  },
  computed: {
    favClass() {
      return {
        'btn-is-fav': this.favorite,
        loading: this.posting,
        invisible: this.thumb
      };
    },
    favText() {
      return this.favorite ? '已收藏' : '收藏';
    },
  },
  methods: {
    onClick(e) {
      if (this.share) {
        return this.$links.toDownloadApp();
      }

      if (e.timeStamp - this._lastTime < 1200) {
        return;
      }

      this._lastTime = e.timeStamp;

      let skn = this.product.productSkn;

      if (!skn) {
        return;
      }

      let name = this.$yoho.isiOS ? 'iFP_ArticleList' : 'aFP_ArticleList';

      if (this.product.productType === 1) {
        this.$yoho.goProductDetail({skn, name, articleId: this.articleId});
      } else if (this.product.productType === 2) {
        this.$yoho.goUfoProductDetail({skn, name, articleId: this.articleId});
      }

      this.reportProduct(skn);
    },
    reportProduct(skn) {
      this.$store.dispatch('reportYas', {
        params: {
          appop: YAS.eventName.productClick,
          param: {
            POS_ID: this.posId,
            ARTICLE_ID: this.articleId,
            PRD_SKN: skn,
          }
        }
      });
    },
  }
};
</script>

<style lang="scss" scoped>
.product-item {
  margin-right: 20px;
  margin-left: 30px;
  height: 180px;
  width: 580px;
  background-color: #fff;
  display: inline-block;
  white-space: initial;
  overflow: hidden;
  vertical-align: top;

  &:last-child {
    margin-right: 50px;
  }

  &.single {
    width: 690px;
    margin-right: 0;
  }
}

.product-content {
  display: flex;
  align-items: center;
  width: 100%;
  height: 100%;
  border: 1px solid #f0f0f0;
}

.product-image {
  width: 136px;
  height: 100%;
  display: flex;
  align-items: center;

  .image {
    max-width: 100%;
    max-height: 100%;
  }
}

.product-info {
  padding-left: 20px;
  flex: 1;

  .product-name {
    font-size: 24px;
    line-height: 36px;
    color: #9b9b9b;
    height: 72px;
    padding-right: 10px;
    margin-bottom: 26px;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .price {
    font-size: 28px;
    color: #222;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}

.btn-right {
  width: 120px;
  height: 50px;
  font-size: 24px;
  background-size: contain;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  letter-spacing: 0.2PX;
  margin-right: -1px;
}

.btn-buy {
  background-color: #222;

  .iconfont {
    font-size: 30px;
    margin-right: 5px;
  }
}

.btn-fav {
  background-color: #444;

  &.btn-is-fav {
    background-color: #b0b0b0;
  }

  & /deep/ .iconfont {
    margin: 0;
  }
}
</style>