<template>
<div class="blind-sku-page">
  <div class="blind-sku-scroll">
   <div class="blind-sku-scroll-box flex-default">
      <div class="blind-card" v-for="(prop, index) in skus" :key="index" @click="showDetail(prop)">
        <img class="thumb" :src="prop.thumb" alt=""/>
        <div class="name">{{prop.skuProps?prop.skuProps[0].propVal:" "}}</div>
        <div class="num">丨限量{{prop.circulation}}份丨</div>
        <img src="@/assets/img/hide-box.png" class="hide-box" alt="" v-show="prop.isHide" >
      </div>
   </div>
  </div>
  <div class="blind-buy">
      <div class="buy-btn" @click="handleConfirm">
         <img :src="goodStatus.img" class="buy-btn" alt=""  >
         <p class="p">{{goodStatus.label}}</p>
      </div>
  </div>
  <van-popup v-model="showPopup" round >
    <div class="blind-large-con">
      <div class="blind-large-card">
        <img class="thumb" :src="selectBlind.thumb" alt="" />
        <div class="name">{{selectBlind.skuProps?selectBlind.skuProps[0].propVal:" "}}</div>
        <div class="num">丨限量{{selectBlind.circulation}}份丨</div>
      </div>
      <div class="close-img flex-center" @click="showPopup=false">
        <van-icon name="cross"  color="#ffffff" size="12px"/>
      </div>
    </div>
    
  </van-popup>
  </div>
</template>
<script>
import { Icon } from 'vant';
import { formatTimeDuring } from "@/utils";
export default {
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    // 规格列表
    skuList: {
      type: Array,
      defualt: () => [],
    },
    // 规格详情
    skuMap: {
      type: Object,
      default: () => {
        return {};
      },
    },
    skus: {
       type: Array,
      defualt: () => [],
    },
    data: {
      type: Object,
      default: () => {
        return {};
      },
    },
    // isHasStock: Boolean
  },
  components:{
    [Icon.name]: Icon,
  },
  data() {
    return {
      showPopup: false,
      selectBlind:{}
    }
  },
  computed: {
    isHasStock() {
      return this.skus && this.skus.some((item) => {
        return item.stock
      })
    },
    goodStatus(){
      let obj={
        disable:false,
        label:"",
        img:""
      }
      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={
          disable:true,
          label:`${dayhours} : ${time.min} : ${time.sec}`,
          img:require('@/assets/img/clocks-and-watches.png')
        }
      }else{
        if(this.isHasStock){
          obj={
            disable:false,
            label:"",
            img:require('@/assets/img/buy.png')
          }
        }else{
          obj={
            disable:true,
            label:"",
            img:require('@/assets/img/sell-out.png')
          }
        }
      }
      return obj
    },
  },
  methods: {
    showDetail(prop) {
      this.showPopup = true
      this.selectBlind = prop
    },
    handleConfirm() {
      if(!this.goodStatus.disable){
        this.$emit("buy");
      }
      
    }
  },
  mounted() {
    
  }
};
</script>
<style lang="less" scoped>
.blind-sku-page {
  .van-popup--center.van-popup--round{
    border-radius: 0px;
  }
  .van-popup{
    background: transparent;
  }
}
.blind-sku-scroll {
  margin: auto;
  width: 343px;
  height: 178px;
  padding: 42px 12px 20px;
  background: url("~@/assets/img/blind-box-sku.png") no-repeat;
  background-size: 100%;
  &-box {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
  }
}
.blind-card {
  width: 92px;
  min-width: 92px;
  height: 116px;
  background: #ffffff;
  border-radius: 6px;
  text-align: center;
  padding: 10px 3px;
  margin-left: 12px;
  position: relative;
  .thumb {
    width: 56px;
    height: 56px;
  }
  .name {
      color: #2C66F5;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
  }
  .num {
    height: 40px;
  }
  .text {
    transform: translateY(2px);
  }
  .hide-box {
    position: absolute;
    width: 40px;
    height: 18px;
    left:0;
    top:0;
  }
}
.blind-buy {
    text-align: center;
    margin-top: 36px;
    .buy-btn {
        width:191px ;
        height: 75px;
        margin: 0 auto;
        position: relative;
        img{
          width: 100%;
          height: 100%;
        }
        .p{
          position: absolute;
          width: 100%;
          top: 25px;
          left: 0;
          text-align: center;
          height: 22px;
          font-size: 17px;
          // font-family: YouSheBiaoTiHei;
          font-weight: bold;
          color: #FFFFFF;
          line-height: 22px;
        }
    }
}
.blind-large-con{
  .blind-large-card {
    width:227px ;
    height: 296px;
    text-align: center;
    padding:20px 18px;
    background: #ffffff;
    border-radius: 4px;
    > .thumb {
      width: 120px;
      height: 167px;
      margin-bottom: 32px;
      object-fit: cover;
    }
    .name {
        color: #030711;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        height: 24px;
        margin-bottom: 10px;
        font-size: 14px;
        font-weight: 500;
    }
    .num {
      color: #999999;
    }
    
  }
  .close-img{
    margin: 0 auto;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #333333;
    margin-top: 65px;
  }
}

</style>