<template>
  <view class="customs-service-grid" v-if="configData">
    <!-- 顶部统计栏 -->
    <view class="stats-bar customs-service-grid-nav">
      <view class="stat-item" v-for="(item,index) in configData.board" :key="index">
        <text class="stat-number">{{item.value}}</text>
        <text class="stat-label">{{item.title}}</text>
      </view>
    </view>

    <view class="service-section-container">
      <!-- 我要办 -->
      <view class="service-section">
        <view class="section-header">
          <section-title title="我要办" />
        </view>
        <view class="service-grid">
          <view v-for="(service, index) in configData.menusDo" :key="index" class="service-item"
            @click="handleServiceClick(service.url)">
            <view class="service-icon">
              <image :src="service.img" class="img"></image>
            </view>
            <text class="service-title">{{ service.name }}</text>
          </view>
        </view>
      </view>

      <!-- 我要查 -->
      <view class="service-section">
        <view class="section-header">
          <section-title title="我要查" />
        </view>
        <view class="service-grid">
          <view v-for="(service, index) in configData.menusSearch" :key="index" class="service-item"
            @click="handleServiceClick(service.url)">
            <view class="service-icon">
              <image :src="service.img" class="img"></image>
            </view>
            <text class="service-title">{{ service.name }}</text>
          </view>
        </view>
      </view>

      <!-- 公共服务 -->
      <view class="service-section">
        <view class="section-header">
          <section-title title="电子账册" @title-click="handleTitleClick" />
        </view>
        <view class="service-grid">
          <view
            v-for="(service, index) in configData.menusCustomsBook"
            :key="index"
            class="service-item"
            @click="handleServiceClick(service)"
          >
            <view class="service-icon" >
              <image :src="service.img" class="img"></image>
            </view>
            <text class="service-title">{{ service.name }}</text>
          </view>
        </view>
      </view>

      <!-- 展转贸 -->
      <view class="service-section">
        <view class="section-header">
          <section-title title="展转贸" />
        </view>
        <view class="service-grid">
          <view v-for="(service, index) in configData.menusExpoToTrade" :key="index" class="service-item"
            @click="handleServiceClick(service.url)">
            <view class="service-icon">
              <image :src="service.img" class="img"></image>
            </view>
            <text class="service-title">{{ service.name }}</text>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
  import { ref } from 'vue'
  import { postConfigApi } from '@/api/customs'
  interface ServiceItem {
    id : string
    title : string
    icon : string
    color : string
    route ?: string
  }



  const handleServiceClick = (url : string) => {
    console.log('点击服务:', url)
    if (url && url != '#') {
      uni.navigateTo({
        url,
        fail: () => {
          uni.reLaunch({
            url
          })
        }
      })
    }
    // 这里可以添加具体的跳转逻辑
    // uni.showToast({
    //   title: `进入${service.title}`,
    //   icon: 'none',
    // })
  }
  const configData = ref(null)
  const getList = () => {
    postConfigApi({
      page: 1,
      page_size: 10
    }).then(res => {
      if (res.code == 1) {
        configData.value = res.data
      }
    })
  }

  getList()
</script>

<style lang="scss" scoped>
  .customs-service-grid {
    position: relative;
    z-index: 2;
    padding: 0 32rpx;
  }

  .customs-service-grid-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
  }

  // 顶部统计栏
  .stats-bar {
    position: relative;
    z-index: 2;
    background: #ffffff;
    border-radius: 20rpx;
    padding: 40rpx 32rpx;
    // margin-bottom: 40rpx;
    box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);

    .stat-item {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;

      .stat-number {
        font-size: 48rpx;
        font-weight: bold;
        color: #333;
        margin-bottom: 8rpx;
      }

      .stat-label {
        font-size: 24rpx;
        color: #666;
        text-align: center;
      }
    }
  }

  .service-section-container {
    background: #ffffff;
    position: absolute;
    left: 0;
    width: 100%;
    // border-radius: 80rpx 80rpx 0 0;

    &::before {
      content: '';
      position: absolute;
      z-index: 1;
      top: -100rpx;
      left: 0;
      right: 0;
      height: 100rpx;
      background: #ffffff;
      border-radius: 80rpx 80rpx 0 0;
    }
  }

  // 服务模块
  .service-section {
    padding: 32rpx;
    // margin-bottom: 32rpx;

    .section-header {
      display: flex;
      align-items: center;
      margin-bottom: 32rpx;

      .section-bar {
        width: 8rpx;
        height: 32rpx;
        background: #4a90e2;
        border-radius: 4rpx;
        margin-right: 16rpx;
      }

      .section-title {
        font-size: 32rpx;
        font-weight: 600;
        color: #333;
      }
    }

    .service-grid {
      display: grid;
      grid-template-columns: repeat(5, 1fr);
      gap: 24rpx;

      .service-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 16rpx;

        .service-icon {
          width: 80rpx;
          height: 80rpx;
          // border: 3rpx dashed;
          border-radius: 16rpx;
          display: flex;
          align-items: center;
          justify-content: center;
          background: rgba(255, 255, 255, 0.8);
          transition: all 0.3s ease;

          .img {
            width: 50rpx;
            height: 50rpx;
          }

          .icon-text {
            font-size: 32rpx;
          }
        }

        .service-title {
          font-size: 24rpx;
          color: #333;
          text-align: center;
          line-height: 1.2;
          max-width: 100%;
          word-break: break-all;
        }

        &:active .service-icon {
          transform: scale(0.95);
          opacity: 0.8;
        }
      }
    }
  }
</style>
