product-group-item.vue 6.67 KB
<template>
  <div
    class="product-item"
    :class="itemClass">
    <div class="product-content" @click="onClick">
      <div class="product-image">
        <div v-if="!hasStock" class="no-stock-cover">
          <span>已售罄</span>
        </div>
        <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-wrap">
          <div class="price-left">
            <label v-if="priceTag" class="price-tag" :class="priceTag"></label>
            <span v-show="salesPrice" class="price">¥{{salesPrice}}</span>
          </div>
          <div class="btn-right btn-buy hover-opacity" :class="{'btn-disable': !hasStock}">
            <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,
    model: String,
    name: String
  },
  data() {
    return {
      posting: false,
      favorite: this.product.favorite
    };
  },
  watch: {
    'product.favorite'(val) {
      this.favorite = val;
    }
  },
  computed: {
    itemClass() {
      return {
        single: this.single,
        [`product-model-${this.model}`]: this.model
      };
    },
    favClass() {
      return {
        'btn-is-fav': this.favorite,
        loading: this.posting,
        invisible: this.thumb
      };
    },
    favText() {
      return this.favorite ? '已收藏' : '收藏';
    },
    hasStock() {
      return this.product.has_stock !== 'N';
    },
    priceTag() {
      let className = '';

      if (+this.product.productType === 2) {
        className = 'ufo-tag';
      } else if (this.product.collage_activity_id) {
        className = 'collage-tag';
      }

      return className;
    },
    salesPrice() {
      return this.product.collage_activity_id ? this.product.collage_price : this.product.salesPrice;
    }
  },
  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;
      }
      const defaultName = 'ArticleDetail';

      let name = this.$yoho.isiOS ? `iFP_${this.name || defaultName}` : `aFP_${this.name || defaultName}`;

      if (this.product.productType === 1) {
        this.$yoho.goProductDetail({skn, name, articleId: this.articleId, collageActivityId: this.product.collage_activity_id});
      } 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;
  position: relative;

  .no-stock-cover {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    color: #fff;
    font-weight: 300;
    line-height: 1;
    background-color: rgba(34, 34, 34, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;

    > span {
      display: inline-block;
      font-size: 24px;
      transform: scale(0.85, 0.85);
    }
  }

  .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-wrap {
    font-size: 28px;
    color: #222;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .price-left {
    display: flex;
    align-items: center;
  }

  .price-tag {
    width: 94px;
    height: 28px;
    margin-right: 10px;
    background-size: 100%;
  }

  .collage-tag {
    background-image: url("~statics/image/article/pt-price.png");
  }

  .ufo-tag {
    background-image: url("~statics/image/article/ufo-price.png");
  }

  .price {
    line-height: 1;
  }
}

.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;
  }
}

.btn-disable {
  background-color: #b0b0b0;
}

.product-model-2 {
  width: 170px;
  height: auto;
  overflow: visible;
  margin-left: 20px;
  margin-right: 0;

  .product-content {
    display: block;
    border: 0;
    position: relative;
  }

  .product-image {
    width: 100%;
    height: 226px;
  }

  .product-info {
    padding: 0;
    margin-top: 12px;

    .product-name {
      height: 66px;
      font-size: 25px;
      line-height: 1.4;
      padding-right: 0;
      margin-bottom: 0;
      color: #444;
      letter-spacing: 1PX;
      width: 213px;
      transform: translateX(-21px) scale(0.8);
    }

    .price {
      width: 126px;
      height: 50px;
      color: #fff;
      font-size: 25px;
      line-height: 1;
      font-weight: 300;
      position: absolute;
      top: 166px;
      right: -22px;
      background-color: #444;
      display: flex;
      justify-content: center;
      align-items: center;
      transform: scale(0.8);

      > * {
        display: none;
      }

      > span {
        display: inline;
      }
    }
  }
}
</style>