<template>
  <dic class="container">
    <div class="container-header">
      <van-search
          v-model="search_keyword"
          background="transparent"
          left-icon="none"
          :right-icon="searchImg"
          shape="round"
          placeholder="请输入内容"
      />
    </div>
    <div class="container-content">
      <van-notice-bar
          @click="handleNoticeBar"
          v-show="noticeBarState.show"
          :left-icon="noticeImg"
          scrollable
          background="linear-gradient(180deg, #F3F7FF 0%, #FDFEFF 100%)"
          mode="closeable"
          :text="noticeBarState.event_title"
      />
      <div class="padding-content">
        <van-grid :column-num="2">
          <van-grid-item v-for="(item, index) in menu" :key="index" @click="handleClickMenu(item.url)">
            <div class="card">
              <div :class="item.icon"></div>
              <van-badge :content="item.num" max="99" :show-zero="false">
                <div class="card-title">{{ item.name }}</div>
              </van-badge>
            </div>
          </van-grid-item>
        </van-grid>
        <div class="app_panel">
          <div class="app_panel_title">综合应用</div>
          <div v-for="(item, index) in menu2" :key="index" class="box">
            <div class="box-title">{{ item.name }}</div>
            <div class="box-content">
              <div v-for="(item2, index2) in item.children" :key="index2" class="box-item"  @click="handleClickMenu(item.url)">
                <img class="icon" :src="getImageUrl(item2.icon)" alt="" />
                <span>{{ item2.name }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </dic>
</template>

<script lang="ts" setup>
import { ref, reactive, onMounted } from 'vue';
import { getActiveEventList } from "@/api/event";
import noticeImg from '@/assets/images/notice.png'
import searchImg from '@/assets/images/search.png'
import {useRouter} from "vue-router";

const router = useRouter();
const search_keyword = ref('');
const noticeBarState = reactive({
  show: false,
  event_id: '',
  event_title: ''
})

const handleNoticeBar = () => {
  console.log(noticeBarState.event_title);
}
// 菜单数据
const menu = ref([
  { name: '工作审批', icon: 'icon1', num: 0, url: '' },
  { name: '信息接报', icon: 'icon2', num: 0, url: '' },
  { name: '在线点名', icon: 'icon3', num: 0, url: '' },
  { name: '事件管理', icon: 'icon4', num: 0, url: 'EventList' },
]);

// 综合应用菜单
const menu2 = ref([
  {
    name: '自然灾害风险监测',
    children: [
      { name: '灾害监测', icon: 'monitor', url: '' },
      { name: '大风灾害', icon: 'wind', url: '' },
      { name: '森林火灾', icon: 'forestFire', url: '' },
      { name: '台风实况', icon: 'typhoon', url: '' },
      { name: '水文监测', icon: 'hydrology', url: '' }
    ]
  },
  {
    name: '应急事件场景专题',
    children: [
      { name: '自然灾害', icon: 'nature', url: '' },
      { name: '事故灾害', icon: 'accident', url: '' },
      { name: '城市事件', icon: 'city', url: '' }
    ]
  }
])
const handleClickMenu = (url) => {
  if (!url) return;
  router.push({ name: url });
}
const getImageUrl = (name) => {
  return new URL(`../../assets/images/index/${name}.png`, import.meta.url).href;
};

const initData = () => {
  // 通知栏数据
  getActiveEventList().then((res) => {
    if(res.data.event_id != noticeBarState.event_id) {
      noticeBarState.show = true
      noticeBarState.event_id = res.data.event_id;
      noticeBarState.event_title = res.data.event_title;
    }
  })
  // 菜单数据
}
onMounted(() => {
  initData()
})
</script>

<style lang="scss" scoped>
.container {
  display: block;
  width: 100%;
  height: 100%;
  padding-bottom: 20px;
}
.container-header {
  width: 100%;
  height: 370px;
  background: url('@/assets/images/index/banner.png') no-repeat;
  background-size: 100% 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 70px;
  //padding: 0 30px;
  .van-search {
    width: 100%;
  }
}
.container-content {
  margin-top: -70px;
  .van-notice-bar {
    width: 100%;
    margin-bottom: 11px;
  }
  .padding-content {
    padding: 0 16px;
  }
  .van-hairline--top:after {
    border-top-width: 0 !important;
  }
  :deep(.van-grid) {

    .van-grid-item {
      &:nth-child(1) {
        padding-right: 12px;
        padding-bottom: 12px;
      }
      &:nth-child(2) {
        padding-bottom: 12px;
      }
      &:nth-child(3) {
        padding-right: 12px;
      }
      .card {
        width: 100%;
        height: 89px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 9px 15px 9px 0;
        font-size: 14px;
        background: url(@/assets/images/index/cardBg1.png) no-repeat;
        background-size: 100% 100%;
        &:nth-child(2) {
          background: url(@/assets/images/index/cardBg2.png) no-repeat;
          background-size: 100% 100%;
        }
        &:nth-child(3) {
          background: url(@/assets/images/index/cardBg3.png) no-repeat;
          background-size: 100% 100%;
        }
        &:nth-child(4) {
          background: url(@/assets/images/index/cardBg4.png) no-repeat;
          background-size: 100% 100%;
        }
        .card-title {
          font-size: 14px;
          color: #414F64;
        }
      }
      .icon1 {
        background: url(@/assets/images/index/icon1.png) no-repeat;
      }
      .icon2 {
        background: url(@/assets/images/index/icon2.png) no-repeat;
      }
      .icon3 {
        background: url(@/assets/images/index/icon3.png) no-repeat;
      }
      .icon4 {
        background: url(@/assets/images/index/icon4.png) no-repeat;
      }
      .icon1,
      .icon2,
      .icon3,
      .icon4
      {
        width: 67px;
        height: 67px;
        background-size: 100% 100%;
      }
    }
    .van-grid-item__content {
      padding: 0;
      background: transparent;
      &::after {
        border: none;
      }
    }
  }
}

.app_panel {
  padding-top: 12px;
  .app_panel_title {
    height: 26px;
    font-weight: bold;
    font-size: 18px;
    color: #414F64;
    letter-spacing: 0;
    margin-bottom: 4px;
  }
  .box {
    width: 100%;
    height: 72px;
    background: url("@/assets/images/index/boxBg.png") no-repeat;
    background-size: 100% 100%;
    margin-bottom: 12px;
    &:last-child {
      margin-bottom: 0;
    }
    .box-title {
      font-size: 12px;
      color: #3687fe;
      padding: 0 10px;
    }
    .box-content {
      display: flex;
      flex-wrap: wrap;
      padding-top: 3px;
      .box-item {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        width: 20%;
        font-size: 12px;
        .icon {
          width: 32px;
          height: 34px;
        }
      }
    }
  }
}
</style>
