<template>
  <div class="navbar">
    <div>
      <!-- <hamburger :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" /> -->
      <!-- <breadcrumb class="breadcrumb-container" /> -->
      <el-dropdown v-show="status" placement="bottom" trigger="click" @command="sumTypeCkeck">
        <el-button type="primary">
          {{ sumType }}<i class="el-icon-arrow-down el-icon--right" />
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <div style="margin: 0 10% 10px;">
            <el-select v-model="value" filterable remote reserve-keyword :remote-method="remoteMethod" size="small" style="width: 100%" placeholder="请搜索业务线">
              <el-option v-for="item in arr_data" :key="item.code" :label="item.name" :value="item.code" @click.native="sumTypeCkeck(item)">
                {{ item.name }}
              </el-option>
            </el-select>
          </div>
          <div style="height: 200px; overflow:scroll; overflow-x: hidden">
            <el-dropdown-item
              v-for="(item,index) in sumTypeArray"
              :key="index"
              :label="item.name"
              :value="item.code"
              :command="item"
              v-text="item.name"
            />
          </div>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <div>
      <div class="right-menu" style="display: fiex; align-items: center; justify-content: space-between;">
        <el-avatar style="vertical-align: middle; background: #FFF;" size="small"><img :src="options.phoneUrl"></el-avatar>
        <el-dropdown placement="bottom" trigger="click">
          <span class="el-dropdown-link avatar-container" style="color: #FFFFFF; cursor: pointer;" @click="show2 = !show2">
            {{ username }}
            <i class="el-icon-arrow-right" :class="{rotateNone:show2,rotate:!show2}" />
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="Logout">退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
// import Breadcrumb from '@/components/Breadcrumb' // 面包屑
// import Hamburger from '@/components/Hamburger'  // 导航开关
import { settingQueryBizTypeList } from '@/api/settingQueryBizTypeList.js'
import Utils from '../../util.js'
import { logoutUrl } from '@/apiConfig/requestIP.js'
import { memberQueryMemberInfoByIDAPorName, settingGetBizList, settingUserSetBiz, settingUserGetBiz } from '@/api/projectIndex'

export default {
  // components: {
  //   Breadcrumb
  //   Hamburger
  // },
  data() {
    return {
      bizOptions: [],
      show2: false,
      options: [],
      value: '',
      arr_data: [],
      sumTypeArray: [],
      sumType: '',
      formulaArea: '', // 公式的文本框
      bizID: localStorage.getItem('bizId'),
      bizShow: {
        id: ''
      }
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'status'
    ]),
    username() {
      return localStorage.getItem('realname')
    }
  },
  created() {
    this.get_bizArr()
  },
  methods: {
    remoteMethod(query) {
      if (query !== '') {
        setTimeout(() => {
          settingGetBizList({ bizName: query }).then(res => {
            this.arr_data = res.data
          })
        }, 200)
      } else {
        this.arr_data = []
      }
    },
    // toggleSideBar() {
    //   this.$store.dispatch('app/toggleSideBar')
    // },
    // logout() {
    //   // await this.$store.dispatch('user/logout')
    //   // this.$router.push(`/login?redirect=${this.$route.fullPath}`)
    //   location.href = logoutUrl
    // },
    sumTypeCkeck(type) { // 下拉列表的点击事件
      this.sumType = type.name
      settingUserSetBiz({ bizId: type.code }).then(res => {
        localStorage.setItem('bizId', type.code)
        window.location.reload()
      })
    },
    get_bizArr() {
      settingQueryBizTypeList({}).then(res => {
        this.bizOptions = res.data.list
        var int = Number(localStorage.getItem('key'))
        int === 0 ? int = '' : ''
        this.bizShow.id = int
        memberQueryMemberInfoByIDAPorName({ memberIDAP: localStorage.getItem('realname') }).then(res => {
          this.options = res.data[0]
        })
      })
      settingGetBizList({}).then(res => {
        this.sumTypeArray = res.data
        settingUserGetBiz().then(res => {
          if (res.data) {
            this.sumTypeArray.map(item => {
              if (res.data.bizId === item.code) {
                this.sumType = item.name
                localStorage.setItem('bizId', item.code)
              }
            })
          } else {
            this.sumType = this.sumTypeArray[0].name
            localStorage.setItem('bizId', this.sumTypeArray[0].code)
          }
          if (this.sumType === '') {
            this.sumType = this.sumTypeArray[0].name
            localStorage.setItem('bizId', this.sumTypeArray[0].code)
          }
        })
      })
    },
    bizchnage(ele) {
      Utils.$emit('demo', ele)
      localStorage.setItem('key', ele)
      window.location.reload()
    },
    Logout() {
      location.href = logoutUrl
    }
  }
}
</script>

<style lang="scss" scoped>
.navbar .rotateNone {
  transform: rotate(270deg);
}
.navbar img {
    margin: 0 auto;
}
.navbar .rotate {
  transform: rotate(90deg);
}
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  overflow: hidden;
  position: relative;
  background: #409EFF;
  box-shadow: 0 1px 4px rgba(0,21,41,.08);

  .hamburger-container {
    line-height: 46px;
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background .3s;
    -webkit-tap-highlight-color:transparent;

    &:hover {
      background: rgba(0, 0, 0, .025)
    }
  }

  .breadcrumb-container {
    float: left;
    /deep/ .el-breadcrumb__separator {
      color:white !important
    }
  }

  .right-menu {
    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #c0c8d8;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background .3s;

        &:hover {
          background: rgba(0, 0, 0, .025)
        }
      }
    }

    .avatar-container {
      margin-right: 30px;

      .avatar-wrapper {
        position: relative;

        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 12px;
        }
      }
    }
  }
}
</style>
