<template name="simple-name">
  <div
    class="simplebigBox"
    :style="nowStart ? styleData.simplebigBox : styleData.noSimplebigBox"
    ref="simple"
    @click.stop="styleClick('click', 'simple')"
    @mousemove.stop="styleClick('mousemove', 'simple')"
    @mouseout.stop="styleClick('mouseout')"
  >
    <div
      v-if="isShow"
      id="simple"
      :style="styleData.simplebox"
    >
      <div>已盖{{ text }}层楼</div>
      <div>{{ time }}竣工</div>
    </div>
    <div
      v-else
      id="simple"
      :style="styleData.simplebox"
    >
      <div>{{ time }}已竣工</div>
      <div>{{ userText }}人参与施工</div>
    </div>
  </div>
</template>
<script>
import bus from "../../../util/bus.js";
import apis1 from "../../../util/apis1.js";
let { building } = apis1;
export default {
  props: [
    "isTemplate",
    "datas",
    "styleData",
    "keyData",
    "templateData",
    "isWebClick",
    "modifyContent",
  ],
  data() {
    return {
      text: null, //楼层
      userText: null,
      endtime: 1626775200, //活动结束时间
      time: "",
      isShow: true, //是否竣工
      nowStart: true,
      styleDataOld: {},
    };
  },
  created() {
    //深拷贝重置需要
    this.styleDataOld = JSON.parse(JSON.stringify(this.styleData));
    this.initDadas();
  },
  mounted() {
    // 给bug绑定一个log事件,等待兄弟组件出发
    bus.$on("gertger", (content) => {
      // 输出兄弟组件传递的内容
      this.text = content;
      console.log(this.text, content);
    });
  },
  updated() {
    bus.$on("gertger", (content) => {
      // 输出兄弟组件传递的内容
      this.text = content;
      console.log(this.text, content);
    });
  },
  methods: {
    //点击可修改位置的方法
    styleClick(type, refName) {
      if (this.isWebClick) {
        //传值给B端
        let byValue = {
          modifyContent: this.modifyContent,
          refName: refName,
          styleData: this.styleData,
          styleDataOld: this.styleDataOld,
          c_this: this,
          isCustomSwitching: this.isCustomSwitching,
        };
        this.$emit("opertaionCom", type, byValue);
      }
    },
    initDadas(data) {
      if (this.isTemplate) {
        this.$toast("活动预览，仅供查看");
        this.text = 1000;
        this.time = "2021年8月9日23:59";
        var datasAll = this.templateData;
        console.log(datasAll, "2222SukaBulie");
        if (datasAll) {
          this.text = 0;
          var time1 = new Date(datasAll.activity.dateValue[1]); //券开始时间
          console.log(time1, datasAll.activity.endTime, "newDate");
          var year = time1.getFullYear();
          var month = time1.getMonth() + 1;
          var day = time1.getDate();
          var H = time1.getHours();
          var Min = time1.getMinutes();
          var time3 = H + ":" + Min;
          if (H < 10 && Min < 10) {
            time3 = "0" + H + ":" + "0" + Min;
          } else if (H < 10) {
            time3 = "0" + H + ":" + Min;
          } else if (Min < 10) {
            time3 = H + ":" + "0" + Min;
          } else {
            time3 = H + ":" + Min;
          }
          console.log(year, month, day);
          this.time = year + "年" + month + "月" + day + "日 " + time3;
        }
        return;
      }
      const self = this;
      let actStatus = sessionStorage.getItem("actStatus");
      if (actStatus == 2) {
        this.$toast("活动已结束");
        this.nowStart = true;
      }
      if (actStatus == 1) {
        this.$toast("活动未开始");
        this.nowStart = true;
      }
      building((data) => {
        console.log(data, "22222222222222222333");
        if (new Date().getTime() > data.data.endTime) {
          this.isShow = false;
          bus.$emit("timeout", true);
        } else {
          this.isShow = true;
          bus.$emit("timeout", false);
        }
        this.text = data.data.bulidCount;
        this.endtime = data.data.endTime;
        this.userText = data.data.userCount;
        bus.$emit("data", data.data);
        var time1 = new Date(this.endtime); //券开始时间
        var year = time1.getFullYear();
        var month = time1.getMonth() + 1;
        var day = time1.getDate();
        var H = time1.getHours();
        var Min = time1.getMinutes();
        var time3 = H + ":" + Min;
        if (H < 10 && Min < 10) {
          time3 = "0" + H + ":" + "0" + Min;
        } else if (H < 10) {
          time3 = "0" + H + ":" + Min;
        } else if (Min < 10) {
          time3 = H + ":" + "0" + Min;
        } else {
          time3 = H + ":" + Min;
        }
        this.time = year + "年" + month + "月" + day + "日 " + time3;
      });
    },
  },
};
</script>
<style scoped>
.simplebigBox {
  position: relative;
}
</style>