<template>
  <div class="nav-bar-container">
    <div class="left-panel">
      <vab-remix-icon class="logo" icon-class="logo" />
      <span class="hidden-xs-only">无症状人群胃癌筛查随访数据中心</span>
    </div>
    <div class="userInfo">
      <error-log></error-log>
      <!-- <avatar></avatar> -->
      <div class="fontSelect">
        <div v-for="(item, index) in fontList" :key="index" class="font" @click="changeFont(index)">
          <div class="label">{{ item.label }}</div>
        </div>
      </div>
      <div v-show="curSelectedIndex != -1" class="community" @click="openModalFlag">
        <img src="~@/assets/img/DataCenter/shift.png" alt />
        {{
        curSelectedIndex != -1
        ? screeningList[curSelectedIndex - 1] ? screeningList[curSelectedIndex - 1].title
        : "" :''
        }}
      </div>

      <div class="user">
        <img src="~@/assets/img/DataCenter/user.png" alt />
        <avatar></avatar>
      </div>
      <el-popover placement="top-start" width="200" trigger="click" popper-class="message-pop">
        <div v-for="(item, index) in messageList" :key="index" class="message-box mb-24">
          <div class="top-box mb-12">
            <span class="blue-dot mt-5 mr-8"></span>
            <span class="top-text">{{ item.date }}</span>
          </div>
          <div class="main-text ml-8">{{ item.message }}</div>
        </div>
        <template slot="reference">
          <el-badge :value="messageCount" :class-name="'badge'">
            <div class="user">
              <img src="~@/assets/img/DataCenter/message.png" alt />
              消息
            </div>
          </el-badge>
        </template>
      </el-popover>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex"

import {
  Avatar,
  Breadcrumb,
  ErrorLog,
  FullScreenBar,
  ThemeBar,
} from "@/layouts/components"

export default {
  name: "NavBar",
  components: {
    Avatar,
    Breadcrumb,
    ErrorLog,
    FullScreenBar,
    ThemeBar,
  },
  props: {
    curSelectedIndex: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      pulse: false,
      isDot: true,
      messageCount: 10,
      screeningList: [
        {
          title: "社区筛查",
          src: require("@/assets/img/DataCenter/shequ.png"),
        },
        {
          title: "医院筛查",
          src: require("@/assets/img/DataCenter/yiyuan.png"),
        },
        {
          title: "体检筛查",
          src: require("@/assets/img/DataCenter/tijian.png"),
        },
      ],
      fontList: [
        { fontSize: "-", label: "A-" },
        { fontSize: 14, label: "A" },
        { fontSize: "+", label: "A+" },
      ],
      fontSize: localStorage.getItem("fontSize") - 0 || 14,
      messageList: [
        {
          date: "2022-12-12",
          message: "驳回修改病例【6条】",
        },
        {
          date: "2022-12-12",
          message: "驳回修改病例【6条】",
        },
      ],
    }
  },
  computed: {
    ...mapGetters({
      collapse: "settings/collapse",
      visitedRoutes: "tagsBar/visitedRoutes",
      device: "settings/device",
      routes: "routes/routes",
      feedBackNumber: "user/feedBackNumber",
    }),
  },
  created() {},
  mounted() {},
  methods: {
    handleCollapse() {
      this.$store.dispatch("settings/changeCollapse")
    },
    viewMsg() {
      this.$router.push({ name: "Message" })
    },
    async refreshRoute() {
      this.$baseEventBus.$emit("reloadRouterView")
      this.pulse = true
      setTimeout(() => {
        this.pulse = false
      }, 1000)
    },
    openModalFlag() {
      this.$emit("openModalFlag")
    },
    changeFont(i) {
      let fontSize = this.fontList[i].fontSize
      if (fontSize == "-") {
        if (this.fontSize > 12) {
          this.fontSize = this.fontSize - 2
        }
      } else if (fontSize == "+") {
        if (this.fontSize < 18) {
          this.fontSize = this.fontSize + 2
        }
      } else {
        this.fontSize = 14
      }
      // this.fontIndex = i
      this.$store.commit("table/setFontSize", this.fontSize)
      localStorage.setItem("fontSize", this.fontSize)
      console.log(this.fontSize)
    },
  },
}
</script>

<style lang="scss" scoped>
.nav-bar-container {
  position: relative;
  height: 74px;
  overflow: hidden;
  user-select: none;
  background: #4e68ff;
  box-shadow: $base-box-shadow;
  display: flex;
  justify-content: space-between;
  color: #fff;
  border-radius: 0px 0px 4px 4px;
  .left-panel {
    display: flex;
    align-items: center;
    justify-items: center;
    font-size: 24px;
    font-weight: 600;
    height: 74px;
    max-height: 74px;
    letter-spacing: 2px;

    .logo {
      margin-right: 20px;
      margin-left: 40px;
      font-size: 40px;
      vertical-align: middle;
    }
    .fold-unfold {
      margin-left: 10px;
      font-size: 20px;
      color: $base-color-gray;
      cursor: pointer;
    }

    ::v-deep {
      .breadcrumb-container {
        margin-left: 10px;
      }
    }
  }
  .userInfo {
    display: flex;
    align-items: center;
    padding-right: 40px;
    .fontSelect {
      display: flex;
      margin-right: 20px;
      .font {
        width: 40px;
        height: 40px;
        background: #4e68ff;
        border-radius: 4px;
        border: 1px solid #ffffff;
        text-align: center;
        line-height: 40px;
        cursor: pointer;
        margin-left: 20px;
        &:active {
          box-sizing: border-box;
          background: #ffffff;
          height: 40px;
          color: #4e68ff;
          padding: 1px;
          .label {
            height: 36px;
            border: 1px solid #4e68ff;
          }
        }
      }
    }
    .community {
      width: 106px;
      height: 30px;
      white-space: nowrap;
      background: rgba(255, 255, 255, 0.1);
      color: #fff;
      display: flex;
      justify-content: center;
      align-items: center;
      cursor: pointer;
      img {
        margin-right: 4px;
        width: 18px;
        height: 18px;
      }
    }
    .user {
      white-space: nowrap;
      margin-left: 40px;
      height: 30px;
      display: flex;
      justify-content: center;
      align-items: center;
      cursor: pointer;
      color: #fff;
      img {
        margin-right: 4px;
        width: 18px;
        height: 18px;
      }
    }
  }
}
.message-box {
  .top-box {
    display: flex;
    flex-direction: row;
    .blue-dot {
      width: 4px;
      height: 4px;
      background: #4b65ff;
      display: block;
      border-radius: 100%;
    }
    .top-text {
      font-size: 14px;
      font-family: AlibabaPuHuiTiR;
      color: #999999;
    }
  }
}
// .el-popper {
//   ::v-deep .popper__arrow {
//     display: none;
//   }
// }
</style>
<style lang="scss">
.message-pop {
  padding: 40px 28px 12px;
  z-index: 10;

  .popper__arrow::after {
    display: none;
  }
  .popper__arrow {
    display: none;
  }
}
</style>
