<template>
  <view class="goods">
    <template v-for="item in data">
      <view v-if="item.goods" :key="item.goodsId" :class="['card']" @click="toDetail(item.goods)">
        <view class="card__top">
          <view class="card__head">
            <image class="card__head__image" object-fit="contain" :src="item.goods.goodsImage" />
          </view>
          <p class="card__name">
            {{ item.goods.goodsName }}
          </p>
          <p v-if="item.goods.serviceTypeList" class="card__service">
            "{{ item.goods.serviceTypeList[0] }}"
          </p>
          <view class="card__tag">
            <view v-for="(tag, index) in item.goods.tagList" :key="index" class="card__tag-wrap">
              <span v-if="tag.type == 2" :key="index" class="card__tag-normal">{{ tag.name }}</span>
              <image v-if="tag.type == 1" class="card__tag-icon" :src="tag.icon" alt="" />
            </view>
          </view>
        </view>
        <view class="card__bottom">
          <view class="price">
            <p>
              <span class="price__icon">¥</span>
              <span class="price__text">{{
                item.goods.goodsSalePrice && item.goods.goodsSalePrice.replace('￥', '')
              }}</span>
            </p>
            <p class="sale">已售{{ item.goods.saleCount }}件</p>
          </view>
        </view>
      </view>
    </template>
  </view>
</template>
<script>
export default {
  props: {
    data: {
      type: Array,
      default: () => []
    }
  },
  methods: {
    toDetail(item) {
      const params = {
        count: 1,
        goodsName: item.goodsName,
        goodsimg: item.goodsImage
      };
      const query = {
        skuNo: item.goodsId
      };
      this.$router.push({ name: 'goodDetail', params, query });
    }
  }
};
</script>
<style lang="less" scoped>
.goods {
  height: 100%;
}
.card {
  // width: 49%;
  font-size: 0;
  background-color: #fff;
  border-radius: 6px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  position: relative;
  justify-content: space-between;

  &__head {
    height: 173px;
    border-radius: 6px;
    overflow: hidden;

    &__image {
      height: 100%;
      width: 100%;
    }
  }

  &__name {
    font-size: 13px;
    line-height: 18px;
    display: -webkit-box;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    margin: 8px 5px 0px 14px;

    .shop-tag {
      vertical-align: middle;
      margin-top: -2px;
    }
  }
  &__service {
    font-size: 13px;
    color: #e1a069;
    margin: 5px 14px;
  }
  &__tag {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    margin: 3px 5px 0 14px;
    &-wrap {
      margin-bottom: 5px;
    }
    &-text {
      color: #e1a069;
      font-size: 13px;
    }

    &-normal {
      display: inline-block;
      font-size: 10px;
      box-sizing: border-box;
      border: 1px solid #ff5a4b;
      color: #ff5a4b;
      padding: 0px 4px;
      border-radius: 3px;
      margin-right: 5px;
      line-height: 14px;
    }
    &-icon {
      height: 15px;
      margin-right: 5px;
    }
    &-warn {
      color: #ff4b00;
      border: 1px solid #ff4b00;
    }
  }

  &__bottom {
    padding: 5px 5px 6px 14px;
    .activity {
      display: flex;
      align-items: bottom;
      &__free {
        height: 14px;
        margin-right: 3px;
      }
    }

    .price__raw {
      float: left;
      color: #999;
      font-size: 10px;
      line-height: 14px;
      text-decoration: line-through;
    }
    .sale {
      color: #999;
      font-size: 10px;
      height: 20px;
      display: flex;
      align-items: flex-end;
      margin-left: 5px;
    }

    .price {
      display: flex;
      align-items: flex-start;
      &__icon {
        font-size: 12px;
        color: #ec3333;
      }
      &__text {
        font-size: 18px;
        line-height: 25px;
        color: #ec3333;
      }
    }
  }

  &::after {
    clear: both;
  }
}
</style>
