<template>
  <div
    class="signDayStyle"
    :style="styleData.signDayStyle"
    ref="cheakSignIn"
    @click="styleClick('click', 'cheakSignIn')"
    @mousemove="styleClick('mousemove', 'cheakSignIn')"
    @mouseout="styleClick('mouseout')"
  >
    <div :style="styleData.signInDaysStyle">
      <span :style="styleData.Textstyle">
        您已连续签到
        <span :style="styleData.NumStyle">{{ signInDays }}</span
        >天，签到就能领福利啦！
      </span>
    </div>
    <div :style="styleData.ButtonStyle" class="buttondiv">
      <img
        v-if="lastSign"
        :style="styleData.btnStyle"
        @click="SignDayUp"
        v-lz-click="'13'"
        :src="styleData.btnStyle.imageUrl"
      />
      <img
        v-else
        :style="styleData.focusStyle"
        :src="styleData.focusStyle.imageUrl"
      />
    </div>
  </div>
</template>
<script>
import apis1 from "../../../util/apis1.js";
import bus from "../../../util/bus.js";
import dataUtil from "../../../util/dateUtil.js";
import { PrizeResultPopComService } from "../../../util/comCreate";
import { Toast } from "vant";
let { getDaySignClick, daySignMainRequest, followShop } = apis1;
export default {
  props: [
    "isTemplate",
    "datas",
    "styleData",
    "keyData",
    "templateData",
    "modifyContent",
    "isWebClick",
  ],
  data() {
    return {
      signInDays: 0, //签到天数
      popText: "",
      prerentList: [], //礼品列表
      lastSign: 0,
      isFocusShop: 0,
      dailySign: 0,
      status: [],
      noStart: false,
      prizeResultData: {
        styleData: {},
        datas: {},
        keyData: {
          prizeUrl: "showImg",
          prizeName: "prizeName",
          prizeType: "prizeType",
          priceInfo: "priceInfo",
          discountType: "discountType",
          couponType: "couponType",
        },
      },
      styleDataOld: {},
    };
  },
  created() {
    //深拷贝重置需要
    this.styleDataOld = JSON.parse(JSON.stringify(this.styleData));
    this.initdatas(false);
  },
  methods: {
    //点击可修改位置的方法
    styleClick(type, refName) {
      if (this.isWebClick) {
        //传值给B端
        let byValue = {
          modifyContent: this.modifyContent,
          refName: refName,
          styleData: this.styleData,
          styleDataOld: this.styleDataOld,
          c_this: this,
        };
        this.$emit("opertaionCom", type, byValue);
      }
    },
    initdatas(isFalse) {
      if (this.isTemplate == true) {
        this.nowDate = 1613721651000;
        var mainDatasAll = {
          signStartTime: 1611208276000,
          signEndTime: 1613887436000,
          activityEndTime: 1616379869000,
        };
        var datasAll = this.templateData;
        if (datasAll) {
          this.isFocusShop = datasAll.signDraw.isFollow;
        }

        //抽奖活动一直显示我的奖品
        // this.isShow = true;
        this.publicData.$emit("showMyPrize", true);
      } else {
        let actStatus = sessionStorage.getItem("actStatus");
        if (actStatus == 2) {
          Toast("活动已结束");
        }
        if (actStatus == 1) {
          Toast("活动尚未开始");
        }
        daySignMainRequest((data) => {
          console.log(data);
          //请求签到总接口
          this.dailySign = data.data.dailySign;
          this.status = data.data.result;
          this.signInDays = data.data.continuityNum; //获取已签到的天数
          this.allSignDay = data.data.signContinuityNum;
          this.lastSign = data.data.sign;
          this.isFocusShop = data.data.isFocusShop;
          bus.$emit("status", this.status);
          bus.$emit("allSignDay", this.allSignDay);
          bus.$emit("signInday", this.signInDays);
          bus.$emit("data", data.data);
          if (isFalse) {
            if (this.dailySign == 1 && this.signInDays >= 7) {
              Toast("您已连续签到满7天，继续签到不能再领奖哦~");
            } else {
              Toast("签到成功");
            }
          }
        });
      }
    },
    SignDayUp() {
      if (this.isTemplate) {
        this.$toast("活动预览，仅供查看");
        return;
      }
      let actStatus = sessionStorage.getItem("actStatus");
      if (actStatus == 2) {
        Toast("活动已结束");
        return;
      }
      if (actStatus == 1) {
        Toast("活动尚未开始");
        return;
      }
      //点击签到按钮调用签到接口
      if (this.lastSign != false) {
        this.lastSign = false;
        if (this.isFocusShop == 1) {
          followShop();
        }
        //如果第一次进入活动或今日第一次点击
        getDaySignClick((data) => {
          console.log(data.data);
          var prize = data.data;
          //请求签到接口
          this.signInDays++; //签到天数加1
          if (this.allSignDay < this.signInDays) {
            this.allSignDay++;
          }
          bus.$emit("allSignDay", this.allSignDay);
          bus.$emit("signInday", this.signInDays);
          if (prize != undefined) {
            //如果今日天数等于奖品的位置
            this.prizeResultData.datas = prize;
            PrizeResultPopComService.create(
              //中奖弹窗
              this.prizeResultData,
              prize,
              (submit) => {
                PrizeResultPopComService.close();
                this.initdatas(true);
                this.publicData.$emit("isNotyFiceWinnerReorrd", true);
              }
            );
          } else {
            this.initdatas(true);
          }
        });
      } else {
        Toast("当天只允许签到一次");
      }
    },
  },
};
</script>
<style scoped>
.buttondiv {
  z-index: 10;
}
.btnStyle {
  width: 2.3rem;
  height: 0.7rem;
  top: 0.99rem;
  left: 1.55rem;
}
.focusStyle {
  width: 3.3rem;
  height: 0.9rem;
  top: 0.99rem;
  left: 1rem;
}
.signDayStyle {
  position: relative;
}
</style>