top-list.vue 1.93 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="product-item" v-for="(product, idx) in list" :key="idx" @click="onItemClick(product)">
      <square-img :src="product.default_images" :width="300" :height="300" />
      <div class="name"><span>{{product.product_name}}</span></div>
      <div class="price"><i>¥</i>{{product.price}}</div>
    </div>
  </div>
</template>

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

export default {
  name: 'TopList',
  components: {
    SquareImg,
  },
  props: {
    list: {
      type: Array,
      default: [],
    },
  },
  methods: {
    onItemClick(item) {
      this.$emit('itemClick', item);
    },
    onAllClick() {
      this.$emit('allClick');
    },
  },
};
</script>

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

  .associated-products {
    margin-top: 30px;
    display: flex;
    flex-flow: wrap;
    justify-content: space-between;

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

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

    .product-item {
      margin-top: 10px;
      width: 30%;
      text-align: center;
      overflow: hidden;
    }

    .name {
      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 {
      font-weight: bold;
      font-size: 24px;
      color: #d0021b;

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