<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', index == fontIndex ? 'active' : '']"
          @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 />
        {{ screeningList[curSelectedIndex].title }}
      </div>

      <div class="user">
        <img src="~@/assets/img/DataCenter/user.png" alt />
        <avatar></avatar>
      </div>
      <el-badge :value="messageCount" :class-name="'badge'">
        <div class="user">
          <img src="~@/assets/img/DataCenter/message.png" alt />
          消息
        </div>
      </el-badge>
    </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: Number,
      default: -1,
    },
  },
  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: "12px", label: "A-" },
        { fontSize: "14px", label: "A" },
        { fontSize: "16px", label: "A+" },
      ],
      fontIndex: localStorage.getItem("fontIndex") || 1,
    }
  },
  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) {
      this.fontIndex = i
      this.$store.commit("table/setFontIndex", i)
      localStorage.setItem("fontIndex", i)
    },
  },
}
</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;
      }
    }
  }
}
</style>
