<template>
  <section class="app-main">
    <transition name="fade-transform" mode="out-in">
      <keep-alive :include="cachedViews">
        <router-view :key="key" />
      </keep-alive>
    </transition>
    <div class="tkbox" v-if="open">
      <div class="tkbox-title">
        <div class="tkbox-title-left">
          <img src="../../assets/images/八一.png" alt />
          <span>重要消息</span>
        </div>
        <div class="tkbox-title-right">
          <img src="../../assets/images/关闭.png" alt @click="showfun" />
        </div>
      </div>
      <div class="tkbox-main">
        <p>
          <img src="../../assets/images/警示.png" alt />
          <span>{{title}}</span>
        </p>
      </div>
      <div class="tkbox-footer">
        <el-button type="primary" @click="quchulifun">去处理</el-button>
      </div>
    </div>
  </section>
</template>

<script>
import { printTrigger, printTriggerClear } from "@/api/PrintsManage/manage";
import Cookies from "js-cookie";
export default {
  name: "AppMain",
  data() {
    return {
      open: false,
      timer: null,
      title: ""
    };
  },
  created() {
    this.timer = null;
    this.startTime();
  },
  computed: {
    cachedViews() {
      return this.$store.state.tagsView.cachedViews;
    },
    key() {
      return this.$route.path;
    }
  },
  methods: {
    showfun() {
      printTriggerClear().then(res => {
        // console.log(res)
      });
      this.open = false;
    },
    quchulifun() {
      printTriggerClear().then(res => {
        if (res.code == 200) {
          window.open(`/print/manage`, "_self");
        }
      });
    },
    startTime() {
      this.timer = setInterval(() => {
        printTrigger().then(res => {
          if (res.code == 200) {
            if (res.printInfo_u != 0) {
              
              var sendId = Cookies.get("userId");
              if (res.printUserInfo == sendId) {
                this.title = res.msg;
                this.open = true;
              }
              if (res.printInfo == sendId) {
                // this.title = res.msg;
                this.title = "您有打印文件需要处理，请尽快处理";
                this.open = true;
              }
            }
          }
        });
      }, 10000); /* 每500毫秒执行一次，实现动态显示时间效果 */
    }
  },
  destroyed() {
    clearInterval(this.timer); // 清除定时器
    this.timer = null;
  }
};
</script>

<style lang="scss" scoped>
.app-main {
  /* 50= navbar  50  */
  min-height: calc(100vh - 50px);
  width: 100%;
  position: relative;
  overflow: hidden;
  position: relative;
}

.tkbox {
  width: 500px;
  height: 220px;
  background-image: url("../../assets/images/框.png");
  background-size: 100% 100%;
  background-repeat: no-repeat;
  position: absolute;
  left: 30%;
  top: 30%;
}

.tkbox-title {
  width: 100%;
  height: 90px;
  display: flex;
  flex-direction: row;
}

.tkbox-title-left {
  flex: 3;
  display: flex;
  align-items: center;
}

.tkbox-title-left img {
  margin-right: 10px;
  width: 30px;
  height: 30px;
  margin-left: 35px;
  display: inline-block;
}

.tkbox-title-left span {
  color: #fff;
}

.tkbox-title-right {
  flex: 1;
  display: flex;
  justify-content: right;
  align-items: center;
  margin-right: 35px;
}

.tkbox-main {
  width: 100%;
  height: 60px;
}

.tkbox-main p {
  width: 90%;
  height: auto;
  margin: 0 auto;
  color: #fff;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tkbox-main p span {
  margin-left: 10px;
}

.tkbox-footer {
  width: 100%;
  height: 30px;
  margin-bottom: 30px;
  text-align: center;
}

.fixed-header + .app-main {
  padding-top: 50px;
}

.hasTagsView {
  .app-main {
    /* 84 = navbar + tags-view = 50 + 34 */
    min-height: calc(100vh - 84px);
  }

  .fixed-header + .app-main {
    padding-top: 84px;
  }
}
</style>

<style lang="scss">
// fix css style bug in open el-dialog
.el-popup-parent--hidden {
  .fixed-header {
    padding-right: 17px;
  }
}
// 设置背景颜色
.app-main {
  background: #022845;
}
// 头部背景颜色、字体颜色
.navbar {
  background: #114a80 !important;
  color: #fff !important;
  // box-shadow:5px 5px 10px black;
  border-bottom: 1px solid #15324e;
}
.el-scrollbar__view {
  background-color: #114a80;
}
.app-breadcrumb.el-breadcrumb .no-redirect {
  color: #fff !important;
}
.el-breadcrumb__inner a {
  color: #fff !important;
}
.tags-view-container {
  background: #022845 !important;
  border: 0px !important;
}

.navbar .right-menu .avatar-container .avatar-wrapper .el-icon-caret-bottom {
  color: #fff !important;
}
.navbar .right-menu .right-menu-item {
  color: #fff !important;
}

// 设置主题内外边距
.app-container {
  margin: 10px 10px 10px 10px;
  padding: 15px 15px 15px 15px;
}
</style>
