<template>
  <div class="map-layout">
    <div class="map-header">
      <div class="map-header-search">
        <el-input placeholder="请输入关键字" v-model="searchValue" @focus="onFoucs" />
        <transition name="fade">
          <ul class="header-search-group" ref="headerSearchGroup" v-show="showHeaderList">
            <li class="header-search-list" @click="toDetail(item)" v-for="item in searchList" :key="item.id">
              <div>
                <p class="list-name">{{ item.name }}</p>
                <p>{{ item.address }}</p>
              </div>
              <div class="list-area">{{ item.deptName }}</div>
            </li>
          </ul>
        </transition>
      </div>
      <div class="map-header-center">
        <div class="map-header-center-title">融通地产危险源辨识系统</div>
        <!-- <div class="map-header-center-tip">
          Rongtong Real Estate Hazard Identification System
        </div> -->
      </div>
      <div class="map-header-right">
        <div @click="toBack"><i class="el-icon-back"></i><span>返回</span> </div>
        <div><i class="el-icon-s-home"></i><span>管理端</span> </div>
        <!-- <span><i class="el-icon-switch-button"></i> 退出</span> -->
      </div>
    </div>
    <div class="map-content">
      <div class="map-content-left"></div>
      <mapDetail v-if="$route.name == 'mapDetail'" />
      <mapIndex ref="mapIndex" v-if="$route.name == 'mapIndex'" />
      <div class="map-content-right"></div>
    </div>

    <div class="map-footer"></div>
  </div>
</template>

<script>
import mapIndex from "./map-index.vue";
import mapDetail from "./map-detail.vue";
import { projectList } from '@/api/map'
export default {
  name: "echarts",
  components: { mapIndex, mapDetail },
  data() {
    return {
      showHeaderList: false,
      searchValue: "",
      searchList: []
    };
  },
  mounted() {
    this.getProjectList()
    document.addEventListener('click', e => {
      if (this.showHeaderList) {
        const headerSearchGroup = document.querySelector('.map-header-search')
        if (!headerSearchGroup.contains(e.target)) {
          this.showHeaderList = false
        }
      }
    })
  },
  watch: {
    searchValue() {
      this.getProjectList()
    }
  },
  methods: {
    toBack() {
      // if (this.$route.name == 'mapDetail') {
      this.$router.go(-1)
      // } else {
      // }
    },
    onFoucs() {
      this.showHeaderList = true
    },
    getProjectList() {
      projectList({ name: this.searchValue.trim() }).then(res => {
        this.searchList = res.data.rows;
      })
    },
    toDetail(item) {
      if (this.$route.name == 'mapDetail') {
        this.$router.replace({
          name: 'mapDetail',
          query: {
            projectId: item.id
          }
        })

      } else {
        this.$router.push({
          name: 'mapDetail',
          query: {
            projectId: item.id
          }
        })
      }
      this.showHeaderList = false
    }
  },
};
</script>

<style lang="scss" scoped>
.header-search-group {
  width: 110%;
  height: 350px;
  position: absolute;
  background: #001525;
  padding: 20px 10px;
  z-index: 10;
  overflow: auto;
  top: 30px;
  left: 10px;

  .header-search-list {
    background: #003863;
    width: 100%;
    display: flex;
    padding: 10px 16px;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    margin-bottom: 5px;
    border-radius: 5px;

    &>div:first-child {
      flex: 1;
      overflow: hidden;

      p {
        white-space: nowrap;
        text-overflow: ellipsis;
        margin: 0;
        width: 90%;
        overflow: hidden;
      }

      .list-name {
        font-size: 16px;
        font-weight: 500;
        margin-bottom: 5px;
      }

    }

    .list-area {
      color: orange;
    }
  }
}

.map-layout {
  width: 100%;
  height: 100%;
  background: #000;
  background: url("../../assets/map/bg.png") no-repeat;
  background-size: 100% 100%;
  overflow: hidden;

  .map-header {
    height: 83px;
    z-index: 10;
    color: #fff;
    padding: 5px 16px;
    background: url("../../assets/map/top.png") no-repeat;
    background-size: 100% 100%;
    box-shadow: border-box;
    display: flex;

    .map-header-search {
      width: 20%;
      position: relative;
      height: 35px;
      display: flex;
      align-items: center;

      .el-input {
        ::v-deep input {
          height: 26px;
          background: transparent;
          border-color: #005495;
          border-radius: 26px;
          color: #fff;

          &::placeholder {
            color: rgb(125, 125, 125);
            font-size: 12px;
          }
        }
      }
    }

    &-center {
      text-align: center;
      flex: 1;

      &-title {
        text-shadow: 0px 0px 10px rgba(21, 203, 249, 1);
        font-weight: 700;
        font-size: 30px;
        line-height: 53px;
        height: 100%;
      }

      &-tip {
        font-family: "微软雅黑", sans-serif;
        font-size: 16px;
        color: rgba(215, 215, 215, 0.4);
      }
    }

    .map-header-right {
      width: 20%;
      font-size: 12px;
      color: #2391FF;
      display: flex;
      justify-content: flex-end;
      align-items: center;
      height: 36px;
      cursor: pointer;

      >div {
        margin-left: 20px;

        span {
          margin-top: -5px;
        }
      }

      i {
        width: 23px;
        height: 23px;
        border-radius: 100%;
        border: 1px solid #2391FF;
        display: inline-block;
        text-align: center;
        line-height: 22px;
        margin-right: 6px;
      }
    }
  }

  .map-footer {
    background: url("../../assets/map/bottom.png") no-repeat;
    background-size: 100% 100%;
    height: 44px;
  }

  .map-content {
    width: 100%;
    height: calc(100% - 128px);
    position: relative;

    &-left::after,
    &-right::after {
      content: "";
      width: 44px;
      height: 84%;
      background: url("../../assets/map/hud-left.png") no-repeat;
      background-size: 100% 100%;
      position: absolute;
      left: 0;
      top: 50%;
      z-index: 10;
      transform: translateY(-52%);
    }

    &-right::after {
      background-image: url("../../assets/map/hud-right.png");
      position: absolute;
      right: 0;
      left: auto;
    }
  }
}

::-webkit-scrollbar {
  display: none;
}
</style>
