<template>
  <view class="home-list">
    <view class="home-list-container">
      <view
        v-for="(item, index) in goodsList"
        :key="index"
        class="Hl-container-item"
        @click="goDetail(item, index)"
      >
        <image lazy-load class="Hlc-item-img" mode="aspectFit" :src="item.goods.goodsImage" />
        <!-- <image :src="item." -->
        <view class="Hlc-item-info">
          <view>
            <view class="Hlc-item-info-title">
              <text>{{ item.goods.goodsName }}</text>
            </view>
            <!-- <img
            v-if="item.goods.userBenefitsLabelImgUrl"
            :src="item.goods.userBenefitsLabelImgUrl"
            class="memberImg"
          /> -->
            <!-- 商品列表商品标签 -->
            <view class="Hlc-item-tag">
              <view v-for="(tag, i) in item.goods.tagList" :key="i" class="Hlc-item-tag-wrap">
                <span v-if="tag.type == 2" :key="i" class="Hlc-item-tag-normal">{{
                  tag.name
                }}</span>
                <img
                  v-if="tag.type == 1"
                  mode="heightFix"
                  class="Hlc-item-tag-icon"
                  :src="tag.icon"
                  alt=""
                />
              </view>
            </view>
          </view>
          <!-- 商品列表商品标签 -->
          <view class="Hlc-item-info-count">
            <view class="Hlc-item-info-count-left">
              <text>¥{{ item.goods.goodsSalePrice }}</text>
              <!-- <text v-if="item.goods.goodsPrice">¥{{ item.goods.goodsPrice }}</text> -->
            </view>
            <view class="Hlc-item-info-count-right">
              <text v-if="item.goods.saleCount">已售{{ item.goods.saleCount }}件</text>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>
<script>
import { saTrackEvent } from "@/utils/sa.js";
import { debounce } from "@/utils";
export default {
  name: "GoodsCard",
  props: {
    goodsList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {};
  },
  methods: {
    goDetail(good, index) {
      const currentPage = getCurrentPages();
      saTrackEvent("PD_YXMMAEC_UserClickProductlistPageCommodityCard", {
        page_id: currentPage[currentPage.length - 1].route,
        commodity_id: good.goods.goodsId,
        position_number: index,
        is_landingpage: uni.getStorageSync("is_landingpage") || 0
      });
      uni.reportAnalytics("c_productlistpagecommoditycard", {
        page_id: currentPage[currentPage.length - 1].route,
        commodity_id: good.goods.goodsId,
        position_number: index
      });
      debounce(
        uni.navigateTo({
          url: `/pages/product/goodDetail?skuNo=${
            good.goods.goodsId
          }&count=1&receiverId=&goodsName=${encodeURIComponent(good.goods.goodsName)}&goodsImage=${
            good.goods.goodsImage
          }`
        }),
        300
      );
    }
  }
};
</script>
<style lang="scss" scoped>
.home-list {
  background: $white;
  padding: 0 $space-md * 2;
  &-container {
    .Hl-container-item {
      display: flex;
      margin: 40rpx 0;
      .Hlc-item-img {
        width: 270rpx;
        height: 270rpx;
        border-radius: 12rpx;
        // background: #aaa;
      }
      .Hlc-item-info {
        width: 450rpx;
        height: 260rpx;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        margin-left: 20rpx;
        &-title {
          text {
            font-size: 26rpx;
            line-height: 36rpx;
            color: #333333;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
          }
        }
        &-count {
          &-left {
            color: #ec3333;
            margin: 1px;
            text {
              &:nth-child(1) {
                margin-right: 10rpx;
                font-size: $uni-font-size-lg;
                line-height: 34rpx;
                color: #ec3333;
                font-weight: bold;
              }
              &:nth-child(2) {
                font-size: $uni-font-size-tiny;
                line-height: 24rpx;
                color: #999999;
                text-align: right;
                text-decoration: line-through;
              }
            }
          }
          &-right {
            font-size: $uni-font-size-tiny;
            line-height: 24rpx;
            color: #999999;
          }
        }
      }
      .Hlc-item-tag {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-start;
        align-items: flex-start;
        height: 60rpx;
        // margin-top: -40rpx;

        &-normal {
          display: inline-block;
          font-size: 22rpx;
          box-sizing: border-box;
          border: none;
          color: #ec1500;
          padding: 0px 4px;
          // border-radius: 3px;
          margin-right: 5px;
          position: relative;
          &::after {
            display: flex;
            box-sizing: border-box;
            align-items: center;
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 200%;
            height: 200%;
            transform: scale(0.5);
            transform-origin: 0 0;
            /* #ifndef MP-ALIPAY */
            border: 1rpx solid #ff5a4b;
            /* #endif */
            /* #ifdef MP-ALIPAY */
            border: 1px solid #ff5a4b;
            /* #endif */
            border-radius: 14rpx;
            pointer-events: none;
          }

          // line-height: 14px;
        }
        &-icon {
          height: 28rpx;
          margin-right: 5px;
          vertical-align: middle;
        }
      }
    }
  }
}
</style>
