<template>
  <div class="content relative co-main-page" style="height: 100vh">
    <img
      src="/invest/resources/img/background2.png"
      alt="조감도"
      class="background-img"
    />
  </div>
</template>

<script>
// API
import { sysListByPageProc } from "../../../../../resources/api/popup";

export default {
  data() {
    return {
      popupList: [],
    };
  },
  created() {
    // 쿠키 초기화
    const today = new Date();
    let tomorrow = new Date(today.setDate(today.getDate() + 1));
    tomorrow.setHours(0, 0, 0, 0);
    tomorrow = new Date(tomorrow);
    if (this.$cookies.get("popup") == null) {
      this.$cookies.set("popup", [], tomorrow);
    }

    this.fnPopupList();
  },
  methods: {
    // 팝업조회(상세)
    async fnPopupList() {
      let data = {
        pageType: this.$store.state.userType,
      };
      try {
        const response = await sysListByPageProc(data);
        let popupList = response.data.data;
        if (popupList != null && popupList.length > 0) {
          this.fnShowPopup(popupList);
        }
      } catch (error) {
        alert("에러가 발생했습니다.\n시스템관리자에게 문의하세요.");
      }
    },
    // 팝업 표시
    fnShowPopup(popupList) {
      for (let popup of popupList) {
        let count = false;
        const popupCookies = this.$cookies.get("popup");
        if (popupCookies.length > 0) {
          for (let cookie of popupCookies) {
            if (popup.popupId == cookie) {
              count = true;
            }
          }
        }
        if (!count) {
          let size = "width=" + popup.wdthLen + ", height=" + popup.vrtcLen;
          window.open(
            "/invest/cmmn/popup.page?popupId=" + popup.popupId,
            "_blank",
            size + ", scrollbars=no, resizable=no, toolbars=no, menubar=no"
          );
        }
      }
    },
  },
};
</script>
