<template>
  <Container logoutBtn>
    <template #main>
      <view class="home-page">
        <!-- 左侧四大功能按钮 -->
        <view class="btn-group">
          <view class="btn-item blue" @click="goTheme"> </view>
          <view class="btn-item green" @click="goDept"> </view>
          <view class="btn-item orange" @click="goHistory"> </view>
          <view class="btn-item red" @click="goBusiness"> </view>
        </view>

        <!-- 右侧热门推荐 -->
        <view class="hot-recommend">
          <view class="recommend-title">热门推荐</view>
          <view class="recommend-list">
            <view class="recommend-item" v-for="(item, index) in recommendList" :key="index" @click="handleSelect(item)">
              <text class="dot">◆</text>
              <text class="text">{{ item.itemName }}</text>
            </view>
          </view>
        </view>
      </view>
    </template>
  </Container>
</template>

<script>
import Container from '@/components/container/container.vue'
import { getBusinessList } from '@/api/ticket.js'

export default {
  components: {
    Container
  },
  data() {
    return {
      recommendList: []
    }
  },
  computed: {
    idcard() {
      return uni.getStorageSync('idcard') || ''
    }
  },
  mounted() {
    this.fetchHotList()
  },
  methods: {
    // 查询热门事项
    async fetchHotList() {
      try {
        const res = await getBusinessList({
          hot: 1,
          status: 1,
          current: 1,
          size: 12,
          descs: 'create_time,id'
        })
        if (res.success && res.data) {
          this.recommendList = res.data.records || []
        }
      } catch (e) {
        console.error('获取热门事项失败', e)
      }
    },

    // 点击事项 → 跳转办事指南
    handleSelect(item) {
      uni.navigateTo({
        url: `/pages/home/guide?id=${item.id}&itemName=${item.itemName}`
      })
    },

    // 主题取号
    goTheme() {
      uni.navigateTo({
        url: '/pages/home/theme'
      })
    },
    // 部门取号
    goDept() {
      uni.navigateTo({
        url: '/pages/home/dept'
      })
    },
    // 历史取号
    goHistory() {
      uni.navigateTo({
        url: '/pages/home/businessList?source=history&titleName=历史取号'
      })
    },
    // 业务取号
    goBusiness() {
      uni.navigateTo({
        url: '/pages/home/businessList?source=business&titleName=业务取号'
      })
    }
  }
}
</script>

<style scoped>
* {
  box-sizing: border-box;
}

.home-page {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4vw;
  box-sizing: border-box;
}

/* 左侧四大功能按钮 - 2×2 网格 */
.btn-group {
  padding-top: 2vw;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  /* justify-content: center; */
  /* gap: 3vh 3vw; */
}

.btn-item {
  margin: 0 2vw 2vw 0;
  width: 28vw;
  height: 32vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
}
.btn-item:nth-child(n + 3),
.btn-item:nth-child(n + 4) {
  margin-bottom: 0;
}
.btn-item:nth-child(2n) {
  margin-right: 0;
}

.btn-item.blue {
  background: url('../../static/images/ticket/theme_bg.png');
  background-size: 100% 100%;
}

.btn-item.green {
  background: url('../../static/images/ticket/dept_bg.png');
  background-size: 100% 100%;
}

.btn-item.orange {
  background: url('../../static/images/ticket/history_bg.png');
  background-size: 100% 100%;
}

.btn-item.red {
  background: url('../../static/images/ticket/business_bg.png');
  background-size: 100% 100%;
}

/* 右侧热门推荐 */
.hot-recommend {
  margin-top: 2vw;
  width: 54vw;
  height: 68vh;
  background: #fff;
  border-radius: 1.5vw;
  box-shadow: 0 0.5vh 1.5vh rgba(0, 0, 0, 0.08);
  padding: 3vh 2vw 2vh;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

.recommend-title {
  font-size: 2.4vw;
  font-weight: bold;
  color: rgba(51, 51, 51, 1);
  text-align: center;
  margin-bottom: 2.5vh;
  flex-shrink: 0;
}

.recommend-list {
  display: flex;
  flex-direction: column;
  gap: 2.5vh;
  flex: 1;
  overflow-y: auto;
}

.recommend-item {
  display: flex;
  align-items: flex-start;
  line-height: 1.5;
}

.dot {
  color: #4080ff;
  font-size: 1.8vw;
  margin-right: 0.8vw;
  flex-shrink: 0;
}

.text {
  font-size: 1.8vw;
  color: rgba(51, 51, 51, 1);
}
</style>
