<template>
  <div v-if="show">
    <basicbackground :colorTitle="colorTitle" @closeClick="closeClick">
      <div :style="floor" v-if="successLightShow">
        <span :style="text11"
          >您已成功点亮许愿灯{{ index + 1 }}，请静等开奖；</span
        >
        <span :style="text21">开奖时间：{{ drawPrizeTime }}</span>
        <div :style="prizeImg">
          <img :src="datas.prizeUrl" :style="img"/>
        </div>
        <button v-lz-click="'27'" @click="back" :style="backBtn">返回</button>
      </div>
      <div :style="floor" v-if="whetherLightShow">
        <div>
          <span :style="text12"
            >许愿灯{{ index + 1 }}的解锁条件为下单满{{ needMoney }}元</span
          >
          <span :style="text22"
            >许愿灯{{ index + 1 }}的奖品为{{ datas.prizeName }}</span
          >
          <span :style="text3">是否确认点亮？</span>
        </div>
        <div :style="prizeImg">
          <img :src="datas.prizeUrl" :style="img"/>
        </div>
        <button v-lz-click="'20'" @click="lightWishLamp" :style="lightLamp">确认点亮</button>
      </div>
      <div :style="floor" v-if="notUnlocking">
        <div>
          <span :style="text13"
            >你还未解锁许愿灯{{ index + 1 }}，无法点亮；</span
          >
          <span :style="text23">许愿灯{{index + 1}}的解锁条件为下单满{{ needMoney }}元;</span>
          <span :style="text33">许愿灯{{index + 1}}的奖品为{{ datas.prizeName }};</span>
          <span :style="text4">快去下单解锁吧</span>
        </div>
        <div :style="prizeImg">
          <img :src="datas.prizeUrl" :style="img"/>
        </div>
        <button @click="goShop" :style="goToShop" v-lz-click="'4'">
          进店逛逛
        </button>
      </div>
    </basicbackground>
  </div>
</template>
<script>
import basicbackground from "../../basisComponent/drawPrizeResult/basicbackground.vue";
// import {successLightService} from '../../../util/comCreate.js';
import dateUtil from "../../../util/dateUtil.js";
import store from "../../../store/store.js";
import apis from "../../../util/apis1.js";
let { lightUp } = apis;
import { goToShopPage } from "../../../util/tools.js";
export default {
  components: { basicbackground },
  name: "wishLamp",
  data() {
    return {
      colorTitle:
        "//img10.360buyimg.com/imgzone/jfs/t1/166920/15/15858/13167/6066b444E610d0d51/898436bd947018ac.png",
      successLightShow: false, //点亮成功
      whetherLightShow: false, //是否点亮
      notUnlocking: false, //未解锁
      floor:'',//底板样式
      text11:'',//成功点亮模块文案1
      text12:'',//成功点亮模块文案2
      text13:'',//成功点亮模块文案3
      text21:'',//解锁许愿灯模块文案1
      text22:'',//解锁许愿灯模块文案2
      text23:'',//解锁许愿灯模块文案3
      text3:'',//未解锁模块文案1
      text33:'',//未解锁模块文案2
      text4:'',//未解锁模块文案3
      prizeImg:'',//奖品图片框
      img:'',//奖品图片
      backBtn:'',//返回按钮
      lightLamp:'',//确认点亮按钮
      goToShop:'',//进店逛逛按钮
      needMoney:0,//满足金额

    };
  },
  created() {
    this.needMoney = parseFloat((this.datas.needMoney) * 100 /10000).toFixed(2);
    //判断显示弹窗内容
    if (this.datas.lightType == 2) {
      this.successLightShow = true;
      this.whetherLightShow = false;
      this.notUnlocking = false;
    } else if (this.datas.lightType == 1) {
      this.successLightShow = false;
      this.whetherLightShow = true;
      this.notUnlocking = false;
    } else if (this.datas.lightType == 0) {
      this.successLightShow = false;
      this.whetherLightShow = false;
      this.notUnlocking = true;
    }
    //时间转换
    console.log(this.drawPrizeTime);
    var data = dateUtil.dateChangeYYYY(this.drawPrizeTime, 3);
    this.drawPrizeTime = data.year + "年" + data.month + "月" + data.day + "日";
    console.log(this.drawPrizeTime);
    console.log(this.index);
    //获取css样式
    this.floor = this.styleData.floor
    this.text11 = this.styleData.floor.text11
    this.text12 = this.styleData.floor.text12
    this.text13 = this.styleData.floor.text13
    this.text21 = this.styleData.floor.text21
    this.text22 = this.styleData.floor.text22
    this.text23 = this.styleData.floor.text23
    this.text3 = this.styleData.floor.text3
    this.text33 = this.styleData.floor.text33
    this.text4 = this.styleData.floor.text4
    this.prizeImg = this.styleData.floor.prizeImg
    this.img = this.styleData.floor.prizeImg.img
    this.backBtn = this.styleData.floor.backBtn
    this.lightLamp = this.styleData.floor.lightLamp
    this.goToShop = this.styleData.floor.goToShop
  },
  methods: {
    closeClick() {
      document.querySelector("body").removeAttribute("style");
    //   console.log(this.isFirstLight,'isFirstLight')
      this.submit(this.isFirstLight);
    },
    back() {
      console.log("关闭");
      this.closeClick();
    },
    lightWishLamp() {
      var nowTime = parseInt(new Date().getTime());
      if (nowTime < this.wishStartTime) {
        this.$toast("许愿期尚未开始");
      } else {
        lightUp(this.datas.prizeId, null, (lightUpData) => {
            console.log(lightUpData);
            this.successLightShow = true;
            this.whetherLightShow = false;
            this.notUnlocking = false;
            //TODO 重新调用灯的信息
            this.isFirstLight = true
        });

      }
    },
    goShop() {
      console.log(store.state.shopId, "进店逛逛");
      let shopId = store.state.shopId;
      goToShopPage(shopId);
    },
  },
};
</script>
<style lang="scss" scoped>
</style>
