top-list.vue 2.59 KB
<template>
  <div class="associated-products">
    <div class="header">
      <div class="title">相关商品</div>
      <div @click="onAllClick">全部 <i class="cubeic-arrow"></i></div>
    </div>
    <div class="row">
      <div class="col" v-for="(product, idx) in viewList" :key="idx" @click="onItemClick(product, idx)">
        <div class="product-item">
          <square-img :src="product.default_images" :width="600" :height="600" />
        </div>
        <div class="name"><span>{{product.product_name}}</span></div>
        <div class="price"><i>¥</i>{{product.price}}</div>
      </div>
    </div>
  </div>
</template>

<script>
import SquareImg from './square-img';

export default {
  name: 'TopList',
  components: {
    SquareImg
  },
  props: {
    list: {
      type: Array,
      default: [],
    },
  },
  computed: {
    viewList() {
      return this.list && this.list.slice(0, 3) || [];
    },
  },
  methods: {
    onItemClick(item, index) {
      this.$emit('itemClick', { product:item, index });
    },
    onAllClick() {
      this.$emit('allClick');
    },
  },
};
</script>

<style lang="scss" scoped>
  @import "../product-detail";

  .associated-products {
    margin-top: 30px;

    .header {
      padding: 20px 0;
      display: flex;
      justify-content: space-between;
      width: 100%;
      font-size: 24px;
      color: #999;
      line-height: 50px;
    }

    .title {
      font-size: 36px;
      font-weight: bold;
      color: #000;
    }

    .row {
      overflow: hidden;
      margin: 0 -6px;

      .col {
        width: 222px;
        padding: 0 8px;
        float: left;
        position: relative;

        &:before {
          content: "";
          position: absolute;
          left: 0;
          right: 0;
          top: 0;
          bottom: 0;
          z-index: 1;
        }
      }
    }

    .product-item {
      margin: 10px auto 0;
      width: 180px;
      text-align: center;
      overflow: hidden;
    }

    .name {
      width: 200px;
      margin: 0 auto 8px;
      height: 64px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      text-align: center;

      span {
        display: block;
        font-size: 20px;
        line-height: 32px;
        max-height: 64px;
        word-break: break-all;
        overflow: hidden;
      }
    }

    .price {
      @include num;

      font-weight: bold;
      font-size: 32px;
      line-height: 38px;
      height: 38px;
      color: #d0021b;
      text-align: center;

      i {
        font-style: normal;
        font-size: 24px;
        vertical-align: baseline;
      }
    }
  }
</style>