<template>
  <view class="hot">
    <view
      class="head-item"
      @click="goDetail('/pages/tabtar/goodsType', false, true)"
      :style="{ backgroundImage: `url(${bgImage || ''})` }"
    >
      <view class="top-left">
        <view class="top-left-title">热门推荐</view>
        <view class="top-left-tip">精选好物推荐</view>
      </view>
      <view class="top-right" style="color: #db7d75">
        查看更多
        <!-- <text class="iconfont u-font24">&#xe6c7;</text> -->
        <uv-icon name="arrow-right" size="24rpx" color="#db7d75"></uv-icon>
      </view>
    </view>
    <view
      class="hot-item u-skeleton-fillet"
      v-if="(recommendList && recommendList.length > 0) || skeletonShow"
    >
      <view
        class="item"
        v-for="item in recommendList.length > 0 ? recommendList : 2"
        :key="item.id"
        @click="
          goProductDetails('/pages/shop/goodsDetails?id=' + item.productId)
        "
      >
        <!-- ?x-oss-process=style/w_350 -->
        <image
          v-if="item && item.coverImage"
          :src="`${item.coverImage}`"
          mode="aspectFill"
        ></image>
        <div class="title-price">
          <view class="hot-introduce" v-if="item && item.title">{{
            item.title
          }}</view>
          <view class="hot-number">
            <view class="hot-large">
              <rich-text
                :nodes="$mUtil.priceBigSmall(item.minSalePrice)"
              ></rich-text>
            </view>
            <view class="hot-small">￥{{ item.maxSalePrice }}</view>
          </view>
        </div>
      </view>
    </view>
    <noData v-else :config="{ top: 1, content: '暂无商品~' }"></noData>
  </view>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { shopProductList_Api } from "@/api/shop";


const props = defineProps({
  skeletonShow: {
    type: Boolean,
    default: false
  },
  bgImage: {
    type: String,
    default: ''
  }
});

const emit = defineEmits(['goDetail', 'goProductDetails']);
const recommendList = ref([]); //推荐

const goDetail = (url, isNeedLogin, tabShow) => {
  emit('goDetail', url, isNeedLogin, tabShow);
};

const goProductDetails = (url) => {
  emit('goProductDetails', url);
};

/**热门推荐 */
const recommend = () => {
  shopProductList_Api({
    limit: 6,
    recommendStatus: 1,
  }).then((res) => {
    if (res && res.code == 200) {
      recommendList.value = res.data;
    }
  });
};

onMounted(() => {
  recommend();
});

defineExpose({
  init: recommend,
});
</script>

<style scoped lang="scss">
.hot {
  background: #ffe7e7;
  box-sizing: border-box;
  border-radius: 10rpx;
  overflow: hidden;

  .hot-item {
    display: flex;
    overflow: scroll;
    white-space: nowrap;
    padding: 0 30rpx 40rpx 30rpx;
    box-sizing: border-box;
    margin-top: 27rpx;

    .hot-number {
      display: flex;
      align-items: flex-end;
      margin-top: 20rpx;
    }

    .hot-large {
      color: #fa6138;
      font-size: 36rpx;
      font-weight: Bold;
      line-height: 24rpx;
    }

    .hot-small {
      font-size: 22rpx;
      font-weight: Medium;
      line-height: 24rpx;
      color: #cccccc;
      margin-left: 16rpx;
      text-decoration: line-through;
    }

    .title-price {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      height: 140rpx;
    }

    .hot-introduce {
      overflow: hidden;
      word-break: break-all;
      margin-top: 24rpx;
      font-size: 24rpx;
      font-weight: Regular;
      line-height: 34rpx;
      color: #333333;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      word-wrap: break-word;
      white-space: normal !important;
      width: 252rpx;
    }

    .item {
      padding: 20rpx;
      background-color: #ffffff;
      border-radius: 16rpx;
      margin-right: 20rpx;

      image {
        width: 252rpx;
        height: 252rpx;
        border-radius: 16rpx;
      }
    }
  }
}

.head-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 27rpx 30rpx;
  box-sizing: border-box;
  overflow: hidden;
  background-size: 100% 100%;
  background-repeat: no-repeat;

  .top-left {
    .top-left-title {
      font-size: 36rpx;
      font-family: PingFang SC, PingFang SC-Bold;
      font-weight: 700;
    }
    .top-left-tip {
      font-size: 24rpx;
      font-family: PingFang SC, PingFang SC-Regular;
      font-weight: 400;
      margin-top: 5rpx;
    }
  }

  .top-right {
    width: 165rpx;
    height: 67rpx;
    line-height: 67rpx;
    background: #ffffff;
    border-radius: 34rpx;
    box-sizing: border-box;
    font-size: 24rpx;
    font-family: PingFang SC, PingFang SC-Regular;
    font-weight: 400;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
</style>
