<template>
  <div class="orderCourtesyDivAll" ref="orderCourtesy"
      @click="styleClick('click', 'orderCourtesy')"
      @mousemove="styleClick('mousemove', 'orderCourtesy')"
      @mouseout="styleClick('mouseout')">

    <div
      :style="styleData.messageTip"></div>

    <div
      class="bgClass"
      :style="styleData.bgClass"
      v-if="timeStatus=='0'"
    >
      <div class="orderEndTimeDiv" :style="styleData.orderEndTimeDiv" :key="timer" v-if="ifShowTime">
        <van-count-down class="countDownStyle1" :style="styleData.countDownStyle1"
                        :time="orderEndTime - new Date().getTime()" format="DD 天 HH 时 mm 分 ss 秒">
          <template #default="timeData">
            <div class="block1">
              <div style="display: flex;">
                <div class="block" v-if="timeData.days >= 100" :style="styleData.block">
                  {{ parseInt(timeData.days / 100) % 10 }}
                </div>

                <div class="block" v-if="timeData.days >= 10" :style="styleData.block">
                  {{ parseInt(timeData.days / 10) % 10 }}
                </div>
                <div class="block" v-if="timeData.days < 10" :style="styleData.block">0</div>
                <div class="block" :style="styleData.block">{{ timeData.days % 10 }}</div>
              </div>
            </div>
            <div class="colon">天</div>
            <div class="block1">
              <div style="display: flex;">
                <div class="block" v-if="timeData.hours >= 100" :style="styleData.block">
                  {{ parseInt(timeData.hours / 100) % 10 }}
                </div>
                <div class="block" v-if="timeData.hours >= 10" :style="styleData.block">
                  {{ parseInt(timeData.hours / 10) % 10 }}
                </div>
                <div class="block" v-if="timeData.hours < 10" :style="styleData.block">0</div>
                <div class="block" :style="styleData.block">{{ timeData.hours % 10 }}</div>
              </div>
            </div>
            <div class="colon">时</div>

            <div class="block1">
              <div style="display: flex;">
                <div class="block" v-if="timeData.minutes >= 100" :style="styleData.block">
                  {{ parseInt(timeData.minutes / 100) % 10 }}
                </div>
                <div class="block" v-if="timeData.minutes >= 10" :style="styleData.block">
                  {{ parseInt(timeData.minutes / 10) % 10 }}
                </div>
                <div class="block" v-if="timeData.minutes < 10" :style="styleData.block">0</div>
                <div class="block" :style="styleData.block">{{ timeData.minutes % 10 }}</div>
              </div>
            </div>

            <div class="colon">分</div>

            <div class="block1">
              <div style="display: flex;">
                <div class="block" v-if="timeData.seconds >= 100" :style="styleData.block">
                  {{ parseInt(timeData.seconds / 100) % 10 }}
                </div>

                <div class="block" v-if="timeData.seconds >= 10" :style="styleData.block">
                  {{ parseInt(timeData.seconds / 10) % 10 }}
                </div>
                <div class="block" v-if="timeData.seconds < 10" :style="styleData.block">0</div>
                <div class="block" :style="styleData.block">{{ timeData.seconds % 10 }}</div>
              </div>
            </div>

            <div class="colon">秒</div>
          </template>
        </van-count-down>
      </div>
    </div>
    <div
      class="bgClass"
      :style="styleData.bgClass1"
      v-if="timeStatus=='1'"
    >
      <div class="orderEndTimeDiv" :style="styleData.orderEndTimeDiv" :key="timer" v-if="ifShowTime">
        <van-count-down class="countDownStyle1" :style="styleData.countDownStyle1"
                        :time="orderEndTime - new Date().getTime()" format="DD 天 HH 时 mm 分 ss 秒">
          <template #default="timeData">
            <div class="block1">
              <div style="display: flex;">
                <div class="block" v-if="timeData.days >= 100" :style="styleData.block">
                  {{ parseInt(timeData.days / 100) % 10 }}
                </div>

                <div class="block" v-if="timeData.days >= 10" :style="styleData.block">
                  {{ parseInt(timeData.days / 10) % 10 }}
                </div>
                <div class="block" v-if="timeData.days < 10" :style="styleData.block">0</div>
                <div class="block" :style="styleData.block">{{ timeData.days % 10 }}</div>
              </div>
            </div>
            <div class="colon">天</div>
            <div class="block1">
              <div style="display: flex;">
                <div class="block" v-if="timeData.hours >= 100" :style="styleData.block">
                  {{ parseInt(timeData.hours / 100) % 10 }}
                </div>
                <div class="block" v-if="timeData.hours >= 10" :style="styleData.block">
                  {{ parseInt(timeData.hours / 10) % 10 }}
                </div>
                <div class="block" v-if="timeData.hours < 10" :style="styleData.block">0</div>
                <div class="block" :style="styleData.block">{{ timeData.hours % 10 }}</div>
              </div>
            </div>
            <div class="colon">时</div>

            <div class="block1">
              <div style="display: flex;">
                <div class="block" v-if="timeData.minutes >= 100" :style="styleData.block">
                  {{ parseInt(timeData.minutes / 100) % 10 }}
                </div>
                <div class="block" v-if="timeData.minutes >= 10" :style="styleData.block">
                  {{ parseInt(timeData.minutes / 10) % 10 }}
                </div>
                <div class="block" v-if="timeData.minutes < 10" :style="styleData.block">0</div>
                <div class="block" :style="styleData.block">{{ timeData.minutes % 10 }}</div>
              </div>
            </div>

            <div class="colon">分</div>

            <div class="block1">
              <div style="display: flex;">
                <div class="block" v-if="timeData.seconds >= 100" :style="styleData.block">
                  {{ parseInt(timeData.seconds / 100) % 10 }}
                </div>

                <div class="block" v-if="timeData.seconds >= 10" :style="styleData.block">
                  {{ parseInt(timeData.seconds / 10) % 10 }}
                </div>
                <div class="block" v-if="timeData.seconds < 10" :style="styleData.block">0</div>
                <div class="block" :style="styleData.block">{{ timeData.seconds % 10 }}</div>
              </div>
            </div>

            <div class="colon">秒</div>
          </template>
        </van-count-down>
      </div>
    </div>
    <div
      class="bgClass"
      :style="styleData.bgClass2"
      v-if="timeStatus=='2'"
    >
      <div class="orderEndTimeDiv" :style="styleData.orderEndTimeDiv" :key="timer" v-if="ifShowTime">
        <van-count-down class="countDownStyle1" :style="styleData.countDownStyle1"
                        :time="orderEndTime - new Date().getTime()" format="DD 天 HH 时 mm 分 ss 秒">
          <template #default="timeData">
            <div class="block1">
              <div style="display: flex;">
                <div class="block" v-if="timeData.days >= 100" :style="styleData.block">
                  {{ parseInt(timeData.days / 100) % 10 }}
                </div>

                <div class="block" v-if="timeData.days >= 10" :style="styleData.block">
                  {{ parseInt(timeData.days / 10) % 10 }}
                </div>
                <div class="block" v-if="timeData.days < 10" :style="styleData.block">0</div>
                <div class="block" :style="styleData.block">{{ timeData.days % 10 }}</div>
              </div>
            </div>
            <div class="colon">天</div>
            <div class="block1">
              <div style="display: flex;">
                <div class="block" v-if="timeData.hours >= 100" :style="styleData.block">
                  {{ parseInt(timeData.hours / 100) % 10 }}
                </div>
                <div class="block" v-if="timeData.hours >= 10" :style="styleData.block">
                  {{ parseInt(timeData.hours / 10) % 10 }}
                </div>
                <div class="block" v-if="timeData.hours < 10" :style="styleData.block">0</div>
                <div class="block" :style="styleData.block">{{ timeData.hours % 10 }}</div>
              </div>
            </div>
            <div class="colon">时</div>

            <div class="block1">
              <div style="display: flex;">
                <div class="block" v-if="timeData.minutes >= 100" :style="styleData.block">
                  {{ parseInt(timeData.minutes / 100) % 10 }}
                </div>
                <div class="block" v-if="timeData.minutes >= 10" :style="styleData.block">
                  {{ parseInt(timeData.minutes / 10) % 10 }}
                </div>
                <div class="block" v-if="timeData.minutes < 10" :style="styleData.block">0</div>
                <div class="block" :style="styleData.block">{{ timeData.minutes % 10 }}</div>
              </div>
            </div>

            <div class="colon">分</div>

            <div class="block1">
              <div style="display: flex;">
                <div class="block" v-if="timeData.seconds >= 100" :style="styleData.block">
                  {{ parseInt(timeData.seconds / 100) % 10 }}
                </div>

                <div class="block" v-if="timeData.seconds >= 10" :style="styleData.block">
                  {{ parseInt(timeData.seconds / 10) % 10 }}
                </div>
                <div class="block" v-if="timeData.seconds < 10" :style="styleData.block">0</div>
                <div class="block" :style="styleData.block">{{ timeData.seconds % 10 }}</div>
              </div>
            </div>

            <div class="colon">秒</div>
          </template>
        </van-count-down>
      </div>
    </div>

    <div :style="styleData.topPic"
         v-if="consumptionGiftPrizeVoList && consumptionGiftPrizeVoList.length > 0"></div>

    <div class="swipe_box" v-if="consumptionGiftPrizeVoList && consumptionGiftPrizeVoList.length > 1">
      <swiper ref="mySwiper" :options="swiperOption" slidesPerView='1.1' :style="styleData.swiperAll">
        <swiper-slide v-for="(item,index) in consumptionGiftPrizeVoList" :key="index" :style="styleData.swiperItem">
          <div :style="styleData.fullMsg">
            满<span :style="styleData.fullSpan">{{ item.num }}</span>元即送
          </div>

          <div :style="styleData.jiedian" v-if="totalOrderPrice<item.num">
            距离完成当前节点还差{{ parseFloat((parseFloat(item.num) - totalOrderPrice).toFixed(2)) }}元
          </div>
          <div :style="styleData.jiedian" v-else>
            当前节点已完成
          </div>


          <!-- 商品图片 -->
          <div :style="styleData.skuPicture">
            <img :src="item.prizeImg" alt="" style="width:1.5rem;height:1.5rem">
          </div>

          <!-- 商品名称 -->
          <div :style="styleData.prizeName">
            {{ item.prizeName }}
          </div>

          <!-- 剩余份数 -->
          <div :style="styleData.stock">
            奖品剩余：{{ item.prizeSurplusCnt }}份
          </div>
          <div>
            <div :style="styleData.progress">
              <van-progress
                :percentage="progressNum"
                stroke-width="13"
                :color="keyData.color"
                track-color="#fef8de"
                :show-pivot=false
              />

            </div>

            <div v-if="consumptionGiftPrizeVoList.length== 4">

              <div :style="styleData.giftBox"></div>
              <div :style="styleData.giftBox" style="left: 1.118rem"></div>
              <div :style="styleData.giftBox" style="left: 2.386rem"></div>
              <div :style="styleData.giftBox" style="left: 3.654rem"></div>

              <div :style="styleData.manyuan">满{{ consumptionGiftPrizeVoList[3].num }}元</div>
              <div :style="styleData.manyuan" style="left: 0.634rem">满{{
                  consumptionGiftPrizeVoList[0].num
                }}元
              </div>
              <div :style="styleData.manyuan" style="left: 1.902rem">满{{
                  consumptionGiftPrizeVoList[1].num
                }}元
              </div>
              <div :style="styleData.manyuan" style="left: 3.17rem">满{{
                  consumptionGiftPrizeVoList[2].num
                }}元
              </div>
            </div>

            <div v-if="consumptionGiftPrizeVoList.length== 3">

              <div :style="styleData.giftBox" style="left: 1.435rem"></div>
              <div :style="styleData.giftBox" style="left: 3.02rem"></div>
              <div :style="styleData.giftBox" style="left: 4.605rem"></div>

              <!--              <div :style="styleData.manyuan">满{{ consumptionGiftPrizeVoList[3].num }}元</div>-->
              <div :style="styleData.manyuan2" style="left: 0.7925rem">满{{
                  consumptionGiftPrizeVoList[0].num
                }}元
              </div>
              <div :style="styleData.manyuan2" style="left: 2.3775rem">满{{
                  consumptionGiftPrizeVoList[1].num
                }}元
              </div>
              <div :style="styleData.manyuan2" style="left: 3.9625rem">满{{
                  consumptionGiftPrizeVoList[2].num
                }}元
              </div>
            </div>
            <div v-if="consumptionGiftPrizeVoList.length== 2">

              <div :style="styleData.giftBox" style="left: 1.96rem"></div>
              <div :style="styleData.giftBox" style="left: 4.08rem"></div>

              <!--              <div :style="styleData.manyuan">满{{ consumptionGiftPrizeVoList[3].num }}元</div>-->
              <div :style="styleData.manyuan3" style="left: 1.055rem">满{{
                  consumptionGiftPrizeVoList[0].num
                }}元
              </div>
              <div :style="styleData.manyuan3" style="left: 3.165rem">满{{
                  consumptionGiftPrizeVoList[1].num
                }}元
              </div>
            </div>


          </div>

          <!-- 确认收货msg -->
          <div :style="styleData.sureMsg">
            <div>
              您已下单<span
              :style="styleData.sureSpan">{{ totalOrderAmount }}元</span>（已确认收货<span>{{ totalOrderPrice }}元</span>）
            </div>
          </div>

          <!-- 按钮 -->
          <div v-if="item.status == 0" :style="styleData.btn1" @click="conditionClick"></div>
          <div v-if="item.status == 1" :style="styleData.btn2" @click="prizeStstusClick(item)"></div>
          <div v-if="item.status == 2" :style="styleData.btn3"></div>
          <div v-if="item.status == 3" :style="styleData.btn4"></div>

        </swiper-slide>

      </swiper>
    </div>
    <div v-if="consumptionGiftPrizeVoList && consumptionGiftPrizeVoList.length == 1"
         :style="styleData.swiperAll1">
      <div v-for="(item,index) in consumptionGiftPrizeVoList" :key="index" :style="styleData.swiperItem">
        <div :style="styleData.fullMsg">
          满<span :style="styleData.fullSpan">{{ item.num }}</span>元即送
        </div>

        <div :style="styleData.jiedian" v-if="totalOrderPrice<item.num">
          距离完成当前节点还差{{ parseFloat((parseFloat(item.num) - totalOrderPrice).toFixed(2)) }}元
        </div>
        <div :style="styleData.jiedian" v-if="totalOrderPrice>=item.num">
          当前节点已完成
        </div>

        <!-- 商品图片 -->
        <div :style="styleData.skuPicture">
          <img :src="item.prizeImg" alt="" style="width:1.5rem;height:1.5rem">
        </div>

        <!-- 商品名称 -->
        <div :style="styleData.prizeName">
          {{ item.prizeName }}
        </div>

        <!-- 剩余份数 -->
        <div :style="styleData.stock">
          奖品剩余：{{ item.prizeSurplusCnt }}份
        </div>

        <!-- 进度条 -->
        <div :style="styleData.progress">
          <van-progress
            :style="styleData.progressInner"
            :percentage='(totalOrderPrice/totalPrice)*100 <= 100 ? ((totalOrderPrice/totalPrice)*100 < 10)&&((totalOrderPrice/totalPrice)*100 >0)?5:(totalOrderPrice/totalPrice)*100/2  :80'
            pivot-color="#7232dd"
            stroke-width="13"
            :color="keyData.color"
            track-color="#fef8de"
            :show-pivot=false
          />
        </div>


        <div :style="styleData.giftBox" style="left: 3.02rem"></div>

        <div :style="styleData.manyuan4" style="left: 1.585rem">满{{
            consumptionGiftPrizeVoList[0].num
          }}元
        </div>


        <!-- 确认收货msg -->
        <div :style="styleData.sureMsg">
          <div>
            您已下单<span
            :style="styleData.sureSpan">{{ totalOrderAmount }}元</span>（已确认收货<span>{{ totalOrderPrice }}元</span>）
          </div>
        </div>


        <!-- 按钮 -->
        <div v-if="item.status == 0" :style="styleData.btn1" @click="conditionClick"></div>
        <div v-if="item.status == 1" :style="styleData.btn2" @click="prizeStstusClick(item)"></div>
        <div v-if="item.status == 2" :style="styleData.btn3"></div>
        <div v-if="item.status == 3" :style="styleData.btn4"></div>
      </div>

    </div>

  </div>
</template>

<script>
// import Swiper from "swiper";
// import Swiper, {Pagination,Navigation} from "swiper"
// Swiper.use([Pagination,Navigation])
// import "swiper/swiper-bundle.css"

import {Swiper, SwiperSlide} from 'vue-awesome-swiper'
import 'swiper/swiper.scss'
import Vue from 'vue';
import {CountDown, Progress} from 'vant';

Vue.use(CountDown);
Vue.use(Progress);
import apis1 from '../../../util/apis1.js';

let {orderCourtesy, immediatelyDraw} = apis1;
// immediatelyDraw 领奖
import {goToShopPage} from '../../../util/tools.js';
import store from '../../../store/store.js';
import {conditionPopService1, orderEndPopService, orderGoodsPopService} from '../../../util/hdzxtcomCreate.js';
import {PrizeResultPopComService, NoPrizeResultPopComService} from '../../../util/hdzxtcomCreate.js';
import dateUtil from "../../../util/dateUtil";
import bus from '../../../util/bus.js';
export default {
  props: ['datas', 'styleData', 'keyData', 'isTemplate', 'templateData', 'modifyContent', 'isWebClick'],
  components: {
    Swiper,
    SwiperSlide
  },
  data() {
    return {
      timer: new Date().getTime(),
      orderEndTime: null,
      consumptionGiftPrizeVoList: [],
      basicData: {},
      swiperOption: {
        slidesPerView: 1.1,
        spaceBetween: 5,
        loop: false,
      },

      totalOrderAmount: 0,//已下单
      totalOrderPrice: 0,//已收货
      totalPrice: 1,//满额最大金额

      progressNum: 0,

      ifShow: false,
      ifShowTime: true,//是否展示倒计时

      assignGoodsFlag: 0,//0-全店商品 1-指定商品

      timeBackgrounImage: '//img10.360buyimg.com/imgzone/jfs/t1/218000/8/22239/7359/63aa9115Fd4791267/541531b76326fdae.png',
      styleDataOld:{},
      timeStatus:'0'

    };

  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.swiper
    }
  },
  created() {
    this.styleDataOld = JSON.parse(JSON.stringify(this.styleData));
    this.initData();
  },
  methods: {

    getProgress() {
      let progress = 0

      progress = (this.totalOrderPrice / this.totalPrice) * 100


      if (this.consumptionGiftPrizeVoList.length == 2) {
        if (progress == 100) {
          progress = 72
        } else if (progress < 100) {
          if (this.totalOrderPrice < this.consumptionGiftPrizeVoList[0].num) {
            progress = (this.totalOrderPrice / this.consumptionGiftPrizeVoList[0].num) * 100 * 0.3
          } else if (this.totalOrderPrice == this.consumptionGiftPrizeVoList[0].num) {
            progress = 30
          } else if (this.totalOrderPrice > this.consumptionGiftPrizeVoList[0].num && this.totalOrderPrice < this.consumptionGiftPrizeVoList[1].num) {
            let tempPro = (this.totalOrderPrice - this.consumptionGiftPrizeVoList[0].num) / (this.consumptionGiftPrizeVoList[1].num - this.consumptionGiftPrizeVoList[0].num) * 100 * 0.42
            progress = 30 + tempPro
          }
          if (progress > 0 && progress < 10) {
            progress = 5
          }
        } else {
          progress = 90
        }
      }

      if (this.consumptionGiftPrizeVoList.length == 3) {
        if (progress == 100) {
          progress = 82
        } else if (progress < 100) {

          if (this.totalOrderPrice < this.consumptionGiftPrizeVoList[0].num) {
            progress = (this.totalOrderPrice / this.consumptionGiftPrizeVoList[0].num) * 100 * 0.22
          } else if (this.totalOrderPrice == this.consumptionGiftPrizeVoList[0].num) {
            progress = 22
          } else if (this.totalOrderPrice > this.consumptionGiftPrizeVoList[0].num && this.totalOrderPrice < this.consumptionGiftPrizeVoList[1].num) {
            let tempPro = (this.totalOrderPrice - this.consumptionGiftPrizeVoList[0].num) / (this.consumptionGiftPrizeVoList[1].num - this.consumptionGiftPrizeVoList[0].num) * 100 * 0.3
            progress = 22 + tempPro

          } else if (this.totalOrderPrice == this.consumptionGiftPrizeVoList[1].num) {
            progress = 52
          } else if (this.totalOrderPrice > this.consumptionGiftPrizeVoList[1].num && this.totalOrderPrice < this.consumptionGiftPrizeVoList[2].num) {

            let tempPro = (this.totalOrderPrice - this.consumptionGiftPrizeVoList[1].num) / (this.consumptionGiftPrizeVoList[2].num - this.consumptionGiftPrizeVoList[1].num) * 100 * 0.3
            console.log(tempPro, 'progressprogress---ss')
            progress = 52 + tempPro

          }
          if (progress > 0 && progress < 10) {
            progress = 5
          }
        } else {
          progress = 90
        }
      }
      if (this.consumptionGiftPrizeVoList.length == 4) {
        if (progress == 100) {
          progress = 88
        } else if (progress < 100) {
          progress = progress

          if (this.totalOrderPrice < this.consumptionGiftPrizeVoList[0].num) {
            progress = (this.totalOrderPrice / this.consumptionGiftPrizeVoList[0].num) * 100 * 0.15
          } else if (this.totalOrderPrice == this.consumptionGiftPrizeVoList[0].num) {
            progress = 15
          } else if (this.totalOrderPrice > this.consumptionGiftPrizeVoList[0].num && this.totalOrderPrice < this.consumptionGiftPrizeVoList[1].num) {

            let tempPro = (this.totalOrderPrice - this.consumptionGiftPrizeVoList[0].num) / (this.consumptionGiftPrizeVoList[1].num - this.consumptionGiftPrizeVoList[0].num) * 100 * 0.25
            progress = 12 + tempPro

          } else if (this.totalOrderPrice == this.consumptionGiftPrizeVoList[1].num) {
            progress = 40
          } else if (this.totalOrderPrice > this.consumptionGiftPrizeVoList[1].num && this.totalOrderPrice < this.consumptionGiftPrizeVoList[2].num) {

            let tempPro = (this.totalOrderPrice - this.consumptionGiftPrizeVoList[1].num) / (this.consumptionGiftPrizeVoList[2].num - this.consumptionGiftPrizeVoList[1].num) * 100 * 0.25
            progress = 40 + tempPro

          } else if (this.totalOrderPrice == this.consumptionGiftPrizeVoList[2].num) {
            progress = 65
          } else if (this.totalOrderPrice > this.consumptionGiftPrizeVoList[2].num && this.totalOrderPrice < this.consumptionGiftPrizeVoList[3].num) {


            let tempPro = (this.totalOrderPrice - this.consumptionGiftPrizeVoList[2].num) / (this.consumptionGiftPrizeVoList[3].num - this.consumptionGiftPrizeVoList[2].num) * 100 * 0.23
            progress = 65 + tempPro

          }

          if (progress > 0 && progress < 10) {
            progress = 5
          }

        } else {
          progress = 95
        }
      }

      this.progressNum = progress
    },

    async initData() {
      if (this.isTemplate) {
        if (this.templateData) {
          let activityCommonRule = this.templateData.consumptionGift.draw.prizeList

          activityCommonRule.forEach(item => {
            item.prizeImg = item.showImg;
            item.prizeSurplusCnt = item.totalPrizeNum;
            item.status = '0';

          });

          this.orderEndTime = this.templateData.consumptionGift.rules.orderEndTime
          this.consumptionGiftPrizeVoList = activityCommonRule

          this.ifShow = this.templateData.consumptionGift.fulfilQuota == '0' ? false : true

        } else {
          let activityCommonRule = [{
            prizeName: '积分',
            prizeImg: '//img10.360buyimg.com/imgzone/jfs/t1/172629/8/10529/9649/60a4cb50Edc2ee40a/b53b1246de5f2089.png',
            num: 20,
            prizeSurplusCnt: 5,
            orderPrice: 0,
            receivingPrice: 0,
            orderNum: 0,
            receivingNum: 0,
            orderSkuNum: 0,
            receivingSkuNum: 0,
            status: '0' // 0 可以领取 1可以领取的置灰 2 以领取 3已领光 4 不满足条件（进店框框）
          }]
          this.orderEndTime = 0

          this.consumptionGiftPrizeVoList = activityCommonRule
          this.ifShow = true

        }
      } else {
        orderCourtesy(res => {
          this.consumptionGiftPrizeVoList = res.data.orderCourtesyVoList
          sessionStorage.setItem("priceTypeFlag", res.data.priceType);
          this.assignGoodsFlag = res.data.assignGoodsFlag;
          bus.$emit('assignGoodsFlag', res.data.assignGoodsFlag);
          sessionStorage.setItem('assignGoodsFlag', this.assignGoodsFlag);
          this.ifShow = res.data.isOpen == '0' ? false : true

          this.basicData = res.data

          if (this.consumptionGiftPrizeVoList.length > 0) {
            this.totalOrderAmount = parseFloat(this.consumptionGiftPrizeVoList[0].totalOrderPrice)
            this.totalOrderPrice = parseFloat(this.consumptionGiftPrizeVoList[0].totalOrderAmount)

            this.totalPrice = parseFloat(this.consumptionGiftPrizeVoList[this.consumptionGiftPrizeVoList.length - 1].num)
          }

          this.getProgress();

          let ddata = dateUtil.dateChangeYYYY(new Date().getTime(), 1);
          // let endTime = dateUtil.dateChangeYYYY(1674897311790, 1);//活动结束时时间
          let endTime = res.data.orderEndTime;//下单结束时时间
          let settlementStartTime = res.data.settlementStartTime;//领奖开始时间
          let settlementEndTime = res.data.settlementEndTime;//领奖结束时间

          if (new Date().getTime() < res.data.orderStartTime) {
            this.orderEndTime = ''
            this.timeStatus = '0'
          } else {
            if (new Date().getTime() <= endTime - 3600000) {
              //参与活动倒计时
              if(new Date().getTime() > res.data.orderEndTime){
                sessionStorage.setItem('canBuy', 1);
              }else{
                sessionStorage.setItem('canBuy', 0);
              }
              this.orderEndTime = endTime - 3600000;
              this.timeStatus = '0'
            } else if (new Date().getTime() > endTime && new Date().getTime() < settlementStartTime) {
              //开始结算
              sessionStorage.setItem('canBuy', 1);
              this.timeBackgrounImage = 'https://img10.360buyimg.com/imgzone/jfs/t1/20344/10/20237/52186/63ad6e24Fd23c2e1b/ec743fbd80dccc74.png';
              this.ifShowTime = false
              this.timeStatus = '1'
            } else {
              //开始领奖
              this.ifShowTime = true
              sessionStorage.setItem('canBuy', 1);
              this.timeBackgrounImage = 'https://img10.360buyimg.com/imgzone/jfs/t1/99162/28/35765/7364/63ad6e24F602a1357/ef22c8b137a446c6.png';
              this.orderEndTime = settlementEndTime 
              this.timeStatus = '2'
            }
          }
          this.timer = new Date().getTime();
        });
      }
    },
    //奖品状态点击
    prizeStstusClick(item) {
      console.log(item);
      if (this.isTemplate || this.isWebClick) {
        // this.$toast('活动预览，仅供参考');
        return;
      }
      let actStatus4 = sessionStorage.getItem('actStatus');
      if (actStatus4 == 1) {
        this.$toast('活动尚未开始');
        return;
      }
      if (actStatus4 == 2) {
        this.$toast("活动已结束");
        return;
      }
      if (item.status == 1) {
        //正常领奖
        immediatelyDraw(item.prizeInfoId, receiveData => {
          if (receiveData.resp_code == 0) {
            if (receiveData.data.result == true) {
              this.initData();
              this.publicData.$emit('isNotyFiceWinnerReorrd', true, this.isTemplate);
              var obj = {
                datas: {},
                keyData: {
                  prizeUrl: 'showImg',
                  prizeName: 'prizeName',
                  prizeType: 'prizeType',
                  priceInfo: 'priceInfo',
                  discountType: 'discountType',
                  couponType: 'couponType'
                }
              };
              obj.datas = receiveData.data;
              PrizeResultPopComService.create(obj, receiveData.data, this.styleData, submit => {
                PrizeResultPopComService.close();
              });
            } else {
              NoPrizeResultPopComService.create(this.styleData, submit => {
                NoPrizeResultPopComService.close();
              });
              this.initData();
            }
          } else if (receiveData.resp_code == 60010) {
            this.$toast('抱歉，奖品已发完~');
            setTimeout(() => {
              this.initData();
            }, 1000);

          }
        });
      }
    },
    //点击可修改位置的方法
    styleClick(type, refName) {
      if (this.isWebClick) {
        //传值给B端
        let byValue = {
          modifyContent: this.modifyContent,
          refName: refName,
          styleData: this.styleData,
          isCustomSwitching: this.receive,
          c_this: this,
          styleDataOld: this.styleDataOld
        };
        this.$emit('opertaionCom', type, byValue);
      }
    },
    //去下单
    conditionClick() {
      if (this.isTemplate|| this.isWebClick) {
        // this.$toast('活动预览，仅供参考');
        return;
      }

      if (sessionStorage.getItem('actStatus') == 1) {
        this.$toast('活动尚未开始');
        return;
      }

      if (sessionStorage.getItem('canBuy') == '0') {
        if (this.assignGoodsFlag == '0') {
          goToShopPage(store.state.shopId);
        } else {
          this.stopScroll();
          orderGoodsPopService.create(this.isTemplate, this.styleData, submit => {
            this.canScroll();
            orderGoodsPopService.close();
          });
        }
      } else {
        this.stopScroll();
        orderEndPopService.create(this.isTemplate, '', submit => {
          this.canScroll();
          orderEndPopService.close();
        });
      }
    },

  }
};
</script>

<style lang="scss">
.orderCourtesyDivAll {
  .bgClass {
    background-size: 100% 100%;
    background-repeat: no-repeat;
    width: 6.9rem;
    height: .78rem;
    margin-left: calc(50% - 6.9rem / 2);
    display: flex;
    align-items: center;
    margin-top: 0.37rem;
    margin-bottom: .3rem;
  }

  .orderEndTimeDiv {
    font-size: 0.3rem;
    font-weight: bold;
    display: -webkit-box;
    display: -ms-flexbox;
    -webkit-box-align: center;
    -ms-flex-align: center;
    background: #8f3f37;
    height: 0.4rem;
    border-radius: 0.2rem;
    margin-left: 3.5rem;
    padding-left: 0.2rem;
    padding-right: 0.2rem;
  }

  .prizeDivAll {
    padding: 0.45rem 0.44rem 0 0.44rem;
  }

  .prizeImageDiv {
    width: 1.8rem;
    height: 1.8rem;
    border-radius: 50%;
  }

  .prizeStatusImgStyle {
    width: 1.91rem;
    height: 0.55rem;
  }

  .van-swipe__indicators {
    display: none;
  }

  .swipe_box {
    width: 100%;
    height: 5.94rem;
    // background: skyblue;
  }

  .van-progress {
    border-radius: 10px;
    // background: red !important;
  }

  //.swiperItem {
  //  width: 6.34rem !important;
  //}
}
</style>
