<template>
  <div class="layout_wrap">
    <div class="layout_header">
      <div class="header_left">
        <img src="@/assets/img/logo.png" />
        <div>星火云鸽管控平台</div>
      </div>
      <div class="header_right">
        <Dropdown
          :transfer="true"
          @on-visible-change="userDropdownVisibleChange"
          @on-click="userDropdownSelectChange"
        >
          <div class="right_user_info">
            <div class="user_img">
              <img src="@/assets/img/user.png" />
            </div>
            <div class="user_name">{{ userInfo.aname }}</div>
            <Icon
              :class="['user_drop', userDropdown ? 'arrow_dropdown' : '']"
              type="md-arrow-dropdown"
              :size="20"
            />
          </div>
          <DropdownMenu slot="list">
            <DropdownItem name="1">个人信息</DropdownItem>
            <DropdownItem name="2">修改密码</DropdownItem>
            <DropdownItem name="5">更换手机号</DropdownItem>
            <DropdownItem name="4">退出</DropdownItem>
          </DropdownMenu>
        </Dropdown>
      </div>
    </div>
    <div class="layout_main">
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userDropdown: false,
      userInfo: {}
    };
  },
  created() {
    this.userInfo = JSON.parse(
      localStorage.getItem("xh_control_userInfo")
    ).content;
  },
  methods: {
    // 下拉菜单显示隐藏
    userDropdownVisibleChange(visible) {
      this.userDropdown = visible;
    },
    // 用户点击下拉菜单项
    userDropdownSelectChange(name) {
      if (name === "1") {
        // 个人中心
      } else if (name === "2") {
        // 修改密码
      } else if (name === "3") {
        // 更换手机号
      } else if (name === "4") {
        // 退出
        this.$Modal.confirm({
          title: "提示",
          content: "确定退出吗？",
          onOk: () => {
            this.toLoginOut();
          },
          onCancel: () => {}
        });
      }
    },
    // 退出
    toLoginOut() {
      this.$router.push("/login");
    }
  }
};
</script>

<style lang="less" scoped>
.layout_wrap {
  width: 100vw;
  height: 100vh;
  background-color: #f1f6fc;
  overflow: auto;
  .layout_header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    height: 50px;
    background-color: #fff;
    .header_left {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      font-size: 24px;
      font-weight: bold;
      img {
        margin-right: 10px;
        width: 36px;
        height: 36px;
      }
    }
    .header_right {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      .right_user_info {
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        .user_img {
          width: 30px;
          height: 30px;
          overflow: hidden;
          img {
            width: 100%;
            height: 100%;
            border-radius: 50%;
            object-fit: cover;
          }
        }
        .user_name {
          margin: 0 6px 0 10px;
        }
        .user_drop {
          transition: all 0.2s ease-in-out;
          &.arrow_dropdown {
            transform: rotate(180deg);
          }
        }
      }
    }
  }
  .layout_main {
    position: relative;
    width: 100%;
    height: calc(100% - 50px);
    overflow: auto;
  }
}
</style>
