<template>
  <div v-if="data.skus.length" class="module">
    <img class="background-image" :src="data.bakImgUrl" alt="" @click="jumpToUrl(data.jumpUrl)" />
    <div class="body">
      <div
        v-for="(item, index) in data.skus"
        :key="index"
        class="skuList"
        :style="{ 'background-image': 'url(' + data.commodityBakImgUrl + ')' }"
        @click="toDetail(item)"
      >
        <img class="skuList-left" :src="item.imageUrl" alt="" />
        <div class="skuList-right">
          <p class="skuList-right-name">{{ item.skuName }}</p>
          <p class="skuList-right-desc">{{ item.skuDesc }}</p>
          <div class="skuList-right-bottom">
            <div class="skuList-right-bottom-left">
              <div class="skuList-right-bottom-left-top">
                <p class="skuList-right-bottom-left-price">
                  <span class="skuList-right-bottom-left-price-icon">￥</span>{{ item.skuPrice }}
                </p>
                <img
                  v-if="
                    item.skuSalePrice && +item.skuSalePrice !== +item.skuPrice && item.tagImgUrl
                  "
                  class="skuList-right-bottom-left-label"
                  :src="item.tagImgUrl"
                />
              </div>
              <p
                v-if="item.skuSalePrice && +item.skuSalePrice !== +item.skuPrice"
                class="skuList-right-bottom-left-marketPrice"
              >
                日常价 ￥{{ item.skuSalePrice }}
              </p>
            </div>
            <img class="skuList-right-bottom-right" :src="data.commodityButtonImgUrl" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { isApp } from '@/service/validation.service';
export default {
  props: {
    data: {
      type: Object,
      default: () => {}
    },
    componentId: [String, Number],
    componentName: String
  },
  data() {
    return {};
  },
  methods: {
    jumpToUrl(url) {
      this.$track.registeredEvents('H5_VccNewUserPageCommoditytopicsMoreBtnClick', {
        assembly_name: this.componentName,
        assembly_id: this.componentId,
        url
      });
      if (url) {
        if (isApp) {
          this.$bridge.openNewUrl({
            data: {
              newUrl: `xyqb://openHttp?jumpUrl=${url}`
            }
          });
        } else {
          window.location.href = url;
        }
      }
    },
    toDetail(item) {
      this.$track.registeredEvents('H5_VccNewUserPageCommoditytopicsCommodityCardClick', {
        assembly_name: this.componentName,
        assembly_id: this.componentId,
        commodity_id: item.skuNo
      });
      if (isApp) {
        this.$bridge.openNewUrl({
          data: {
            newUrl: `xyqb://homepage/goodsdetail?skuNo=${item.skuNo}`
          }
        });
      } else {
        const query = {
          skuNo: item.skuNo
        };
        this.$router.push({ name: 'goodDetail', query });
      }
      // else if (isWxMp) {
      //   wx.miniProgram.navigateTo({
      //     url: `/pages/product/goodDetail?skuNo=${item.skuNo}`
      //   });
      // }
    }
  }
};
</script>
<style lang="less" scoped>
.module {
  margin: 1.1vh 3.2vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 8px;
  padding-bottom: 8px;
  // background-color: #fff;
  .background-image {
    width: 100%;
    height: auto;
  }
  .body {
    background-color: #fff;
    width: 93.6vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-radius: 0 0 8px 8px;
    padding-bottom: 8px;
  }
  .skuList {
    width: 89.3vw;
    height: 15.2vh;
    display: flex;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    margin: 0 0 8px 0;
    .skuList-left {
      width: 26vw;
      height: 13vh;
      border-radius: 8px;
      margin-bottom: 8px;
      margin: auto 0;
      margin-left: 8px;
      margin-right: 5px;
    }
    .skuList-right {
      width: 63vw;
      position: relative;
      .skuList-right-name {
        font-size: 14px;
        margin-top: 1.5vh;
        line-height: 16px;
        overflow: hidden;
        padding-right: 2.1vw;
        word-break: break-all;
        white-space: normal;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
      }
      .skuList-right-desc {
        font-size: 13px;
        margin-top: 1.1vh;
        color: rgba(211, 152, 80);
      }
      .skuList-right-bottom {
        background-size: 100% 100%;
        height: 45px;
        width: 100%;
        position: absolute;
        bottom: 1vh;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .skuList-right-bottom-left {
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          // max-height: 4.7vh;
          .skuList-right-bottom-left-top {
            display: flex;
            align-items: center;
          }
          .skuList-right-bottom-left-price {
            color: #ec1500;
            font-size: 18px;
            font-weight: bold;
            .skuList-right-bottom-left-price-icon {
              font-size: 12px;
              margin-right: -2px;
            }
          }
          .skuList-right-bottom-left-label {
            width: 40px;
            height: auto;
          }
          .skuList-right-bottom-left-marketPrice {
            font-size: 10px;
            color: #999;
            margin-top: 4px;
          }
        }
        .skuList-right-bottom-right {
          width: auto;
          height: 4vh;
          margin-right: 2.7vw;
        }
      }
    }
  }
}
</style>
