<template>
  <div
    class="item-list-con"
    @click="goGoods(data.goodsId, data.type, data.salesType)"
  >
    <div class="img-box">
      <img class="thumb" :src="data.thumb" />
      <div class="goods-stock" :style="{'background':goodStatus.bgColor}">
        <m-icon :icon="goodStatus.icon" :size="10" />
        <span>{{goodStatus.name}}</span>
      </div>
    </div>
    <div class="goods-desc">
      <div class="name">{{ data.name }}</div>
      <div class="desc flex-between">
        <div class="circulationCount flex-default">
          <div class="label">限量</div>
          <div class="num">{{ data.circulationCount }}份</div>
        </div>
        <div class="value">
          <m-price class="price" :amt="data.defaultPrice" :rmbSize="14" :intSize="22" :floatSize="22"/>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { formatTimeDuring } from "@/utils";
export default {
  props: {
    data: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  computed:{
    goodStatus(){
      let obj={
        name:"",
        icon:"",
        bgColor:""
      }
      if(this.data.preheatEndTime&&this.data.preheatEndTime>this.currentTime){
        let time=formatTimeDuring(this.data.preheatEndTime - this.currentTime)
        let dayhours=parseInt(time.day) * 24 + parseInt(time.hour)
        if(dayhours<9){
          dayhours='0'+dayhours
        }
        if(dayhours<1){
          dayhours="00"
        }
        obj={
          name:`即将开售 ${dayhours} : ${time.min} : ${time.sec}`,
          icon:"icon-clocks-and-watches",
          bgColor:"#4CC16D"
        }
      }else{
        if(this.data.stockCount){
          obj={
            name:"热销中",
            icon:"icon-hot-goods",
            bgColor:"rgba(0, 0, 0, 0.2)"
          }
        }else{
          obj={
            name:"已售罄",
            icon:"icon-sell-out",
            bgColor:"rgba(0, 0, 0, 0.2)"
          }
        }
      }
      return obj
    },
  },
};
</script>
<style lang="less" scoped>
.item-list-con{
    margin: 0 5px;
    background: #ffffff;
    border-radius: 8px;
    margin-bottom: 18px;
    .img-box{
        position: relative;
        width: 343px;
        height: 270px;
        .thumb{
            width: 100%;
            height: 100%;
            border-radius: 10px;
            object-fit: cover;
        }
        .goods-stock{
          position: absolute;
          top: 14px;
          left: 12px;
          background: rgba(0, 0, 0, 0.2);
          border-radius:2px 2px;
          // width: 120px;
          height: 18px;
          line-height: 18px;
          text-align: center;
          padding: 0 4px;
          span {
            font-size: 11px;
            color: #ffffff;
            margin-left: 2px;
            margin-right: 1px;
          }
        }
    }
    .goods-desc{
        padding: 10px 15px 16px;
        border-radius: 0 0 8px 8px;
        .name{
            font-size: 18px;
            font-weight: 500;
            font-family: PingFangSC-Medium, PingFang SC;
            color: #030711;
            line-height: 25px;
            margin-bottom: 8px;
        }
        .desc{
          .circulationCount {
            // width: 86px;
            height: 16px;
            line-height: 16px;
            font-size: 10px;
            overflow: hidden;
            border-radius: 2px;
            .label {
              width: 35px;
              height: 16px;
              text-align: center;
              background: #f3e0bc;
              color: #030711;
            }
            .num {
              // width: 51px;
              padding:0 8px;
              min-width: 51px;
              height: 16px;
              background: #4b4b4c;
              color: #f3e0bc;
              text-align: center;
            }
          }
        }
    }
}

</style>