<template>
  <div class="header">
    <div class="header-one">
      <div style="display: flex">
        <div @click="gotoGov" style="cursor: pointer;">数字政府</div>
      <span v-if="!isHome">
        <a-dropdown>
            <a class="ant-dropdown-link">
              定海<a-icon type="down" style="margin-left: 5px"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item v-for="(item,index) in list" :key="index">
                <div @click="goto(item.url)">{{ item.name }}</div>
              </a-menu-item>
            </a-menu>
        </a-dropdown>
      </span>
      </div>
      
      <div>
        <div class="top-name">
          <div class="top-button" @click="gotoHome">数字舟山</div>
          <div class="admin-name">{{userInfo.aliasName}}</div>
        </div>
      </div>
    </div>
    <div class="header-search" @click="gotoSearch">
      请输入关键词
      <div class="header-search-button">搜索</div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';
import { clearStore } from '@/util/store'
export default {
  props: {
    noSearch: {
      type: Boolean,
      default: false
    },
    headerClick: {
      type: Boolean,
      default: false
    },
    isHome: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      list: [{
        name: '舟山',
        url: 'https://szzs.zhoushan.gov.cn/portal/#/dashboard'
      },{
        name: '定海',
        url: '/gov'
      },{
        name: '普陀',
        url: 'https://szh.putuo.gov.cn:4443/digitgov_index'
      },{
        name: '岱山',
        url: 'https://szgg.daishan.gov.cn:8088/#/dashboard'
      },{
        name: '嵊泗',
        url: 'https://szss.shengsi.gov.cn/portal/?isNum=1'
      },{
        name: '高新区',
        url: 'http://60.163.193.114:8081/#/gov'
      },{
        name: '普朱',
        url: 'http://61.153.218.179:8082/#/govDigital'
      },{
        name: '新城',
        url: 'http://60.163.193.140:8081/#/gov'
      },{
        name: '金塘',
        url: 'http://60.163.193.146:8081/#/govDigital'
      },{
        name: '六横',
        url: 'http://60.163.193.145:8081/#/govDigital'
      }]
    }
  },
  computed: {
    ...mapGetters(['userInfo'])
  },
  methods: {
    gotoSearch () {
      this.$router.push({
        path: '/search'
      })
    },
    gotoGov () {
      // if (this.headerClick) {
        this.$router.push({
          path: '/gov'
        })
      // }else{
        // this.$router.push({
        //   path: '/home'
        // })
      // }
    },
    gotoHome () {
      let herf = 'https://szzs.zhoushan.gov.cn/portal/#/dashboard'
      // if (this.isHome) {
      //   // window.location.href = 'https://szzs.zhoushan.gov.cn/portal/#/'
      //   herf = 'https://szzs.zhoushan.gov.cn/portal/#/'
      // } else {
      //   herf = 'https://szzs.zhoushan.gov.cn/portal/#/dashboard'
      // }
      let ua = navigator.userAgent.toLowerCase()
      if((ua.indexOf('dingtalk') >= 0 || !!ua.match(/AppleWebKit.*Mobile.*/) || ua.indexOf('iPad') > -1 || ua.indexOf('ipad') > -1 || ua.indexOf('android') > -1 || ua.indexOf('Adr') > -1)){
            dd.openLink({
                url: `${herf}?ddtab=true`
            }).then(res => {
                console.log(res)
          }).catch(err => {})
        }else{
          window.open(herf,'_blank')
        }
    },
    goto (val) {
      if( val === '/gov' ){
        this.$router.push({
          path: '/gov'
        })
        return false
      }
      if( val ){
        let herf = val
        let ua = navigator.userAgent.toLowerCase()
        if((ua.indexOf('dingtalk') >= 0 || !!ua.match(/AppleWebKit.*Mobile.*/) || ua.indexOf('iPad') > -1 || ua.indexOf('ipad') > -1 || ua.indexOf('android') > -1 || ua.indexOf('Adr') > -1)){
              dd.openLink({
                  url: `${herf}?ddtab=true`
              }).then(res => {
                  console.log(res)
            }).catch(err => {})
          }else{
            window.open(herf,'_blank')
          }
      }
    },
    logout () {
      clearStore({
        type: 'all'
      })
      this.$router.push({
        path: '/login'
      })
    }
  }
}

</script>

<style lang="less" scoped>
  .header {
      background: url(/image/header.png);
      height: 3rem;
      background-size: 100% 100%;
  }
  .top-name{
    display: flex;
    font-size: 18px;
    align-items: center;
    .admin-name{
      display: flex;
      align-items: center;
      font-size: 0.15rem;
      letter-spacing: 0.1rem;
      &::before{
        width: .25974rem;
        height: .25974rem;
        margin-right: .15rem;
        display: inline-block;
        background: url(/image/user1.png) no-repeat;
        background-size: 100% 100%;
        vertical-align: top;
        content: "";
      }
    }
  }
  .header-one {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3rem 0.47rem;
    div {
      font-size: 0.18rem;
      color: #FCFCFC;
    }
    .top-button {
      font-size: 0.09rem;
      padding: 0.045rem 0.12rem;
      background: #25A0F9;
      border-radius: 3px;
      margin-right: 0.4rem;
      cursor: pointer;
    }
    ::v-deep a {
      color: white;
      font-size: 0.13rem;
      margin-left: 10px;
    }
  }
  .header-search {
    width: 50%;
    margin: 0 auto;
    color: rgba(112, 112, 112, 0.5);
    padding: 0.08rem 0.18rem;
    position: relative;
    background: white;
    border-radius: 10px;
    font-size: 0.1rem;
    margin-top: 0.12rem;
    cursor: pointer;
    .header-search-button {
      cursor: pointer;
      color: #FFFFFF;
      border-radius: 0 10px 10px 0;
      background: #FC8F4A;
      position: absolute;
      top: 0;
      right: 0;
      height: 100%;
      display: flex;
      align-items: center;
      padding: 0 0.25rem;
      font-size: 0.1rem;
    }
  }
</style>