<template>
  <footer class="footer">
    <!-- 主要内容区域 -->
    <div class="footer-main">
      <div class="container">
        <div class="footer-content">
          <!-- 左侧联系方式 -->
          <div class="contact-section">
            <h3 class="section-title">联系我们</h3>
            <div class="contact-item phone">
              <img src="@assets/footer-phone.png" alt="电话" class="contact-icon">
              <span class="contact-text">{{ companyInfo.mobile || '400-624-0069' }}</span>
            </div>
            <div class="contact-item addr">
              <img src="@assets/footer-addr.png" alt="地址" class="contact-icon">
              <span class="contact-text">{{ companyInfo.address || '贵州省贵阳市观山湖区金融城MAX-A座' }}</span>
            </div>
            <div class="qrcode-section">
              <img :src="imgHost + companyInfo.wechatQrcode || '@assets/footer-qrcode.png'" alt="微信公众号" class="qrcode"
                @error="handleImageError">
              <p class="qrcode-text">微信公众号入口</p>
            </div>
          </div>

          <!-- 右侧导航链接 -->
          <div class="nav-sections">
            <!-- 达泽科技 -->
            <div class="nav-column">
              <h3 class="section-title">达泽科技</h3>
              <ul class="nav-list">
                <li><a href="/" class="nav-link">首页</a></li>
                <li><a href="/about" class="nav-link">关于我们</a></li>
                <li><a href="/cases" class="nav-link">解决方案</a></li>
                <li><a href="/products" class="nav-link">技术框架</a></li>
              </ul>
            </div>

            <!-- 关于我们 -->
            <div class="nav-column">
              <h3 class="section-title">关于我们</h3>
              <ul class="nav-list">
                <li><a href="/about" class="nav-link">企业简介</a></li>
                <li><a href="/about" class="nav-link">发展历程</a></li>
                <li><a href="/about" class="nav-link">企业荣誉</a></li>
              </ul>
            </div>

            <!-- 联系我们 -->
            <div class="nav-column">
              <h3 class="section-title">联系我们</h3>
              <ul class="nav-list">
                <li><a href="/contact" class="nav-link">联系方式</a></li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 底部版权信息 -->
    <div class="footer-bottom">
      <div class="container">
        <div class="copyright-content">
          <p class="copyright-text"><a href="https://beian.miit.gov.cn/" target="_blank">{{ companyInfo.filingInfo||'' }}</a></p>
        </div>
      </div>
    </div>
  </footer>
</template>

<script>
import { ref, onMounted } from 'vue'
import { getCompanyInfo } from '@/api/modules/home'
import defaultQrcode from '@assets/footer-qrcode.png'

export default {
  name: 'Footer',
  setup() {
    // 环境变量
    const imgHost = import.meta.env.VITE_APP_IMG_HOST
    const companyInfo = ref({})
    const loading = ref(false)

    const fetchCompanyInfo = async () => {
      try {
        loading.value = true
        const response = await getCompanyInfo()
        if (response.data) {
          companyInfo.value = response.data
        }
      } catch (error) {
        console.error('获取公司信息失败:', error)
      } finally {
        loading.value = false
      }
    }

    const handleImageError = (event) => {
      // 如果微信二维码图片加载失败，使用默认图片
      event.target.src = defaultQrcode
    }

    onMounted(() => {
      fetchCompanyInfo()
    })

    return {
      imgHost,
      companyInfo,
      loading,
      handleImageError
    }
  }
}
</script>

<style lang="scss" scoped>
.footer {
  // background: linear-gradient(135deg, #4a6cf7 0%, #1e3a8a 50%, #0f172a 100%);
  background: url('@assets/footer-bg.png') no-repeat center top;
  background-size: cover;
  // background-color: #07122A;
  color: white;
  position: relative;
}

.footer-main {
  padding: 205px 0 $spacing-xl 0;
}

.container {
  max-width: $container-width;
  margin: 0 auto;
  padding: 0 $container-padding;
}

.footer-content {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 300px;
  align-items: flex-start;
}

.contact-section {
  .section-title {
    font-size: 32px;
    font-weight: 400;
    margin-bottom: 50px;
    color: white;
    padding-bottom: 15px;
    display: inline-block;
    position: relative;
    ;

    &::after {
      content: '';
      width: 64px;
      height: 4px;
      position: absolute;
      left: 0;
      bottom: 0;
      background-color: #2E64AF;
    }
  }

  .contact-item {
    font-size: 18px;
    display: flex;
    align-items: baseline;
    margin-bottom: $spacing-base;

    .contact-icon {
      width: 20px;
      height: 20px;
      margin-right: 10px;
      margin-top: 2px;
      flex-shrink: 0;
    }

    .contact-text {
      color: rgba(255, 255, 255, 0.9);
      line-height: 1.5;
    }

    &.phone {
      font-size: 32px;
      margin-bottom: 24px;
    }

    &.addr {
      margin-bottom: 32px;
    }
  }

  .qrcode-section {
    margin-top: 12px;
    text-align: left;

    .qrcode {
      width: 120px;
      height: 120px;
      border-radius: $border-radius-base;
      background: white;
      padding: 4px;
    }

    .qrcode-text {
      margin-top: $spacing-small;
      color: rgba(255, 255, 255, 0.8);
    }
  }
}

.nav-sections {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: $spacing-xl;
}

.nav-column {
  .section-title {
    font-size: 28px;
    font-weight: 400;
    margin-bottom: 50px;
    color: white;
    display: inline-block;
  }

  .nav-list {
    list-style: none;
    padding: 0;
    margin: 0;

    li {
      margin-bottom: 30px;
    }

    .nav-link {
      color: rgba(255, 255, 255, 0.8);
      text-decoration: none;
      font-size: 18px;
      transition: color 0.3s ease;

      &:hover {
        color: white;
        // text-decoration: underline;
      }
    }
  }
}

.footer-bottom {
  // background: rgba(0, 0, 0, 0.3);
  padding: $spacing-base 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);

  .copyright-content {
    text-align: center;

    .copyright-text {
      font-size: $font-size-small;
      color: rgba(255, 255, 255, 0.4);
      margin: 0;
      line-height: 1.5;
    }
  }
}

// 移动端适配
@media (max-width: 768px) {
  .footer-main {
    padding: $spacing-xl 0 $spacing-large 0;
  }

  .footer-content {
    grid-template-columns: 1fr;
    gap: $spacing-large;
  }

  .contact-section {
    .contact-item {
      .contact-text {
        font-size: $font-size-small;
      }
    }

    .qrcode-section {
      text-align: center;
      margin-top: $spacing-medium;

      .qrcode {
        width: 100px;
        height: 100px;
      }
    }
  }

  .nav-sections {
    // grid-template-columns: 1fr;
    gap: $spacing-medium;
  }

  .nav-column {
    .section-title {
      font-size: $font-size-medium;
    }

    .nav-list {
      .nav-link {
        font-size: $font-size-small;
      }
    }
  }

  .footer-bottom {
    .copyright-text {
      font-size: 11px;
      padding: 0 $spacing-small;
    }
  }
}

// 超小屏幕适配
@media (max-width: 480px) {
  .footer {
    background-position: 0px -35px;
    background-color: #07122A;
  }

  .container {
    padding: 0 $spacing-base;
  }

  .footer-main {
    padding: $spacing-large 0;
  }

  .contact-section {
    .contact-item {
      flex-direction: row;
      align-items: center;

      .contact-icon {
        margin-bottom: $spacing-xs;
        // margin-right: 0;
      }
    }
  }

  .nav-sections {
    gap: $spacing-base;
  }
}
</style>