<template>
  <div class="repeatBuyTop" :style="styleData.repeatBuyTopStyle" ref="repeatBuyTop"
    @click="styleClick('click', 'repeatBuyTop')" @mousemove="styleClick('mousemove', 'repeatBuyTop')"
    @mouseout="styleClick('mouseout')">
    <template v-if="!(actStatus == '1' || actStatus == '2')">
      <!-- <div :style="styleData.statusText" v-if="haveStatus=='0'|| haveStatus=='3'|| haveStatus=='2'">
        尊敬的用户，您已完成复购下单，赶快选择您心仪的好礼吧～</div>
      <div :style="styleData.statusText" v-if="haveStatus=='1'">尊敬的用户，您在{{secondBuyStartTime}}至{{secondBuyEndTime}}期间已完成店铺首购，快在活动期间内复购下单，订单确认收货后，报名领取惊喜好礼吧～</div>
      <div :style="styleData.statusText" v-if="haveStatus=='4'">
        尊敬的用户，您在{{secondBuyStartTime}}至{{secondBuyEndTime}}无购买记录，未获得复购特权资格～</div> -->
        <div v-if="haveStatus == 0" :style="styleData.statusText">
          恭喜您！已达成复购任务！ 请尽快点击下方奖品领奖，奖品数量有限（以实际奖品数量为准）
        </div>
        <div v-if="haveStatus == 1" :style="styleData.statusText">
          尊敬的用户，您在*{{secondBuyStartTime}}至{{secondBuyEndTime}}（时间）已下过单，活动期间内在店铺下单商品后，即有机会领取奖品~
        </div>
        <div v-if="haveStatus == 4" :style="styleData.statusText">
          尊敬的用户，您在*{{secondBuyStartTime}}至{{secondBuyEndTime}}未下过单，无法参与本次复购活动，请下次再来哦~
        </div>
    </template>
    <div :style="styleData.repeatBuyTopBtn2" v-if="haveStatus=='4' || haveStatus=='2'" @click="goToShop"></div>
    <div :style="styleData.repeatBuyTopBtn1" v-if="haveStatus=='1'" @click="goToBuy"></div>
    <div :style="styleData.repeatBuyTopTip">
      <template v-if="!(actStatus == '1' || actStatus == '2')">
        <div v-if="isTemplate">*{{secondBuyStartTime}}至{{secondBuyEndTime}}店铺存在已完成订单</div>
        <div v-else>*{{secondBuyStartTime}}至{{secondBuyEndTime}}店铺存在已完成订单</div>
      </template>
      <div>*活动期间内复购下单确认收货后，方可报名领取奖励。</div>
    </div>
  </div>
</template>

<script>
import apis1 from "../../../util/apis1.js";
let { storeGoodsPoint, getbuyAct } = apis1;
import { goToShopPage } from '../../../util/tools.js';
import store from '../../../store/store.js';
import dateUtil from '../../../util/dateUtil.js';

export default {
  props: [
    "datas",
    "keyData",
    "styleData",
    "isTemplate",
    "templateData",
    "modifyContent",
    "isWebClick",
  ],
  data() {
    return {
      styleDataOld: {},
      haveStatus: '1', // 0 未获得  1 获得  2 完成下单 4 没有复购资格   开始时间 结束时间  店铺字段  你自己找吧！！！
      secondBuyEndTime: 0,//活动结束时间
      orderShop: 0,
      secondBuyStartTime: 0,
      actStatus: ''
    };
  },
  created() {
    //深拷贝重置需要
    this.styleDataOld = JSON.parse(JSON.stringify(this.styleData));
    this.initData();
    this.publicData.$on('activityLoaded', (data) => {
      this.actStatus = data.actStatus
    });
  },

  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);
      }
    },
    initData() {
      if (this.isTemplate) {

        var datasAll = this.templateData;
        if (datasAll) {
          this.haveStatus = '0'
          this.secondBuyStartTime = dateUtil.dateChangeYYYY(new Date(parseInt(datasAll.activityCommonRule.orderStartTime) - parseInt(datasAll.activityCommonRule.day) * 24 * 3600 * 1000), 1)
          this.secondBuyEndTime = dateUtil.dateChangeYYYY(new Date(parseInt(datasAll.activityCommonRule.orderStartTime) - 1000), 1)
        } else {
            this.haveStatus = '1'
        }
      } else {
        getbuyAct((initdatas) => {
          if (initdatas.data) {
            this.haveStatus = initdatas.data.status;
            this.orderShop = initdatas.data.orderShop;
            this.secondBuyEndTime = dateUtil.dateChangeYYYY(new Date(initdatas.data.secondBuyEndTime - 1000), 1);
            this.secondBuyStartTime = dateUtil.dateChangeYYYY(new Date(initdatas.data.secondBuyStartTime), 1);
          }
        })
      }
    },
    goToShop() {
      if (this.isTemplate && !this.isWebClick) {
        return;
      }
      if (this.isWebClick) { return }
      storeGoodsPoint(4)
      goToShopPage(store.state.shopId);
    },
    goToBuy() {
      if (this.isTemplate && !this.isWebClick) {
        return;
      }
      if (this.isWebClick) { return }
      if (this.orderShop == 0) {
        goToShopPage(store.state.shopId);
      } else {
        // 跳转锚点
        this.publicData.$emit('buyShop', true);
      }

    },
  },
};
</script>

<style lang="scss" scoped="scoped">
.repeatBuyTop {
}
</style>
