<!--
 * @Description: 
 * @Author: zenghua.wang
 * @Date: 2023-06-20 14:29:45
 * @LastEditors: zenghua.wang
 * @LastEditTime: 2025-01-25 09:24:27
-->
<template>
  <div class="layout">
    <div class="layout-header">
      <div class="layout-header-top">
        <div class="layout-header-top-left">
          <span>您好，欢迎来到农业产业服务平台</span>
          <el-tag>运营大屏</el-tag>
          <el-tag>产业服务APP</el-tag>
          <el-tag>产业运营管理</el-tag>
        </div>
        <div class="layout-header-top-right">
          <span>商家中心</span>
          <span>个人中心</span>
          <span>返回首页</span>
        </div>
      </div>
      <div class="layout-header-bottom">
        <div class="layout-header-bottom-left">
          <div class="layout-header-bottom-search">
            <div class="title">农业产业服务平台</div>
            <el-input v-model="keyword" placeholder="请输入关键词进行搜索"></el-input>
            <el-button type="primary" @click="Search">搜索</el-button>
          </div>
          <el-menu ellipsis class="layout-header-bottom-menu" mode="horizontal">
            <app-link v-for="(item, index) in meuns" :key="index" :to="item.path">
              <el-menu-item>{{ item.label }}</el-menu-item>
            </app-link>
          </el-menu>
        </div>
        <div class="layout-header-bottom-right">
          <div class="layout-header-bottom-right-qr">
            <div class="layout-header-bottom-right-qr-img">
              <img :src="qrImg" alt="" />
              <p>下载数农App</p>
            </div>
            <div class="layout-header-bottom-right-qr-img">
              <img :src="qrImg" alt="" />
              <p>打开数农小程序</p>
            </div>
          </div>
          <p>使用数农手机服务，更方便</p>
        </div>
      </div>
    </div>
    <!-- 子应用不能使用router-view的插槽功能 -->
    <router-view v-if="isSubApp" />
    <router-view v-else v-slot="{ Component, route }">
      <transition name="fade-slide" mode="out-in" appear>
        <keep-alive v-if="isReload" :include="cacheRoutes">
          <component :is="useWrapComponents(Component, route)" :key="route.path" />
        </keep-alive>
      </transition>
    </router-view>
  </div>
</template>

<script setup name="layout">
import { computed, ref } from 'vue';
import { useSettingStore } from '@/store/modules/setting';
import { usePermissionStore } from '@/store/modules/permission';
import { useWrapComponents } from '@/hooks/useWrapComponents';
import { qrImg } from './base64img';
import AppLink from './Link.vue';
import { useRoute } from 'vue-router';

const route = useRoute();
const SettingStore = useSettingStore();
const PermissionStore = usePermissionStore();
const cacheRoutes = computed(() => PermissionStore.keepAliveRoutes);
const isReload = computed(() => SettingStore.isReload);

const isSubApp = computed(() => route.path.includes('sub'));

const keyword = ref('');

const meuns = ref([
  {
    label: '智慧种植',
    path: '/login',
  },
  {
    label: '农事服务',
    path: '/sub-admin/home',
  },
  {
    label: '涉农金融',
  },
  {
    label: '电商交易',
  },
  {
    label: '分拣包装',
  },
  {
    label: '仓储物流',
  },
  {
    label: '公共品牌运营',
  },
]);

function Search() {
  console.log(keyword.value, 'search');
}
</script>

<style lang="scss" scoped>
.layout {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  &-header {
    height: 206px;
    overflow: hidden;
    &-top {
      display: flex;
      height: 44px;
      justify-content: space-between;
      align-items: center;
      background-color: #f8f8f8;
      padding: 0 32px;
      &-left {
        line-height: 36px;
        font-size: 16px;
        .el-tag {
          color: #fff;
          background-color: #a4adb3;
          margin-left: 12px;
          border-color: #a4adb3;
          cursor: pointer;
          font-size: 18px;
        }
      }
      &-right {
        span {
          color: #000;
          margin-left: 25px;
          line-height: 36px;
          font-size: 16px;
          text-align: center;
          cursor: pointer;
          &:nth-child(1) {
            margin-left: 0;
            font-weight: bold;
          }
        }
      }
    }
    &-bottom {
      display: flex;
      padding: 20px 32px 0;
      &-left {
        flex-grow: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        width: calc(100% - 300px);
        .layout-header-bottom-search {
          display: flex;
          align-items: center;
          .title {
            font-size: 45px;
            white-space: nowrap;
          }
          .el-input {
            flex-grow: 1;
            max-width: 460px;
            margin-left: 40px;
            height: 50px;
            font-size: 18px;
          }
          .el-button {
            margin-left: 40px;
            font-size: 18px;
            height: 45px;
            padding: 8px 24px;
          }
        }
        .layout-header-bottom-menu {
          justify-content: space-around;
          border: none;
          .el-menu-item {
            font-size: 24px;
          }
        }
      }
      &-right {
        margin-top: -10px;
        width: 240px;
        padding-left: 20px;
        p {
          text-align: center;
        }
        &-qr {
          display: flex;
          justify-content: space-between;
          &-img {
            img {
              width: 110px;
              height: 110px;
            }
            p {
              text-align: center;
            }
          }
        }
      }
    }
  }
  &-main {
    width: 100%;
    height: calc(100% - 206px);
    background-color: #f8f8f8;
  }
}
</style>
