<template>
  <div class="home-pages">
    <!--  头部 -->
    <comHead v-if="headData.show" :row="headData" :datas="realList"></comHead>
    <!-- 导航 -->
    <div class="nav-bos">
      <div v-for="(item, index) in navList" :key="index" class="nav-list" @click="onPath(item.url)">
        <img class="nav-image" :src="item.img" alt="" />
        <div class="flex-row-between">
          <div>
            <div class="name1">{{ item.name1 }}</div>
            <div class="name2">{{ item.name2 }}</div>
          </div>
          <div class="nav-more flex-row-center">
            <el-icon><ArrowRight /></el-icon>
          </div>
        </div>
      </div>
    </div>
    <!-- 猜你喜欢 -->
    <indexMorTitle :datas="{ title1: '猜你喜欢' }"></indexMorTitle>
    <comGoods :row="{ styleType: 1, goodsShow: [1, 2, 3], goodsTitleType: 3 }" :datas="recommendList"></comGoods>
  </div>
</template>

<script setup lang="ts">
import indexMorTitle from '@/views/home/pccomponents/pages/indexMorTitle.vue';
import comHead from '@/views/home/pccomponents/pages/headData.vue';
import comGoods from '@/views/home/pccomponents/pages/goods.vue';
import { onPath } from '@/utils/siteConfig';
import { getSearchTitle, getHomeNav } from '@/api/home/index';
import {
  getEnterpriseRightsMemberEquityList,
  getEnterpriseHomeAdList,
  getCustomerProductPage,
  customerMessageList
} from '@/api/home/index-enterprise';
import enterprise1 from '@/assets/images/home/enterprise1.png';
import enterprise2 from '@/assets/images/home/enterprise2.png';
import enterprise3 from '@/assets/images/home/enterprise3.png';
import enterprise4 from '@/assets/images/home/enterprise4.png';

const headData = ref<any>({});
const realList = ref<any>([]);
const recommendList = ref<any>([]);
//导航
const navList = ref<any>([
  { name1: '采购日历', name2: '提前制定和管理月度采购计划', url: '/enterprise/purchaseHistory', img: enterprise1 },
  { name1: '自助开票', name2: '灵活自助开票 换开管票服务', url: '/enterprise/invoiceManage', img: enterprise2 },
  { name1: '下载中心', name2: '批量订单打印', url: '/order/orderManage', img: enterprise3 },
  { name1: '批量下单', name2: '智能识别多商品多地址一键下单', url: '/cart', img: enterprise4 }
]);

onMounted(() => {
  document.documentElement.style.setProperty('--hover-color', '#E7000B');
  getHead();
});

//头部
const getHead = async () => {
  headData.value.topStyle = 1;
  headData.value.toplabel = [];
  headData.value.classifyShow = true;
  headData.value.headType = 4;
  headData.value.leftStyle = 1;
  headData.value.carouselList = [];
  headData.value.advertList = [];
  headData.value.realDataType = 1;
  headData.value.realNumber = 6;
  headData.value.navlList = [];
  try {
    const datas1 = await getSearchTitle(5);
    if (datas1.code == 200) {
      datas1.data.forEach((item: any) => {
        headData.value.toplabel.push({
          title: item.navigationName
        });
      });
    }

    const datas2 = await getHomeNav(5);
    headData.value.topNav = [];
    datas2.data.forEach((item: any) => {
      headData.value.topNav.push({
        title: item.navigationName,
        url: item.url ? item.url : ''
      });
    });

    const datas3 = await getEnterpriseHomeAdList({});
    if (datas3.code == 200) {
      datas3.data.forEach((item: any) => {
        headData.value.carouselList.push({
          imageUrl: item.imageUrl
        });
      });
    }

    const datas5 = await customerMessageList({ status: '0', pageSize: 20 });
    if (datas5.code == 200) realList.value = datas5.rows;

    const datas6 = await getEnterpriseRightsMemberEquityList({});
    if (datas6.code == 200) {
      datas6.data.forEach((item: any) => {
        headData.value.navlList.push({
          imageUrl: item.imageUrl,
          title: item.title,
          url: item.link ? item.link : ''
        });
      });
    }

    headData.value.show = true;
  } catch (error) {}
};

//猜你喜欢
getCustomerProductPage({}).then((res) => {
  if (res.code == 200) {
    recommendList.value = res.rows;
  }
});
</script>

<style lang="scss" scoped>
.home-pages {
  width: 100%;
  padding-bottom: 30px;

  :deep(.hover-color) {
    cursor: pointer;

    &:hover {
      color: var(--hover-color) !important;

      .zi-hover {
        color: var(--hover-color) !important;
      }
    }
  }
  // 导航
  .nav-bos {
    margin: 0 auto;
    width: 100%;
    max-width: 1500px;
    min-width: 1200px;
    display: flex;
    gap: 0 10px;
    .nav-list {
      margin-top: 15px;
      flex: 0 0 calc((100% - 30px) / 4);
      height: 150px;
      background: #ffffff;
      border-radius: 5px;
      padding: 20px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      cursor: pointer;
      .nav-image {
        width: 50px;
        height: 50px;
        background: #ffeeea;
        border-radius: 6px 6px 6px 6px;
      }
      .name1 {
        font-size: 15px;
        margin-bottom: 5px;
        color: #101828;
      }
      .name2 {
        font-size: 13px;
        color: #6a7282;
      }
      .nav-more {
        width: 20px;
        height: 20px;
        border-radius: 20px;
        border: 1px solid #3d3e3f;
      }
    }
  }
}
</style>
