<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: [],
      idcard: ''
    }
  },
  onLoad(options) {
    this.idcard = options.idcard || ''
  },
  mounted() {
    this.fetchHotList()
  },
  methods: {
    // 查询热门事项
    async fetchHotList() {
      try {
        const res = await getBusinessList({
          hot: 1,
          status: 1,
          current: 1,
          size: 6,
          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?idcard=${this.idcard}`
      })
    },
    // 部门取号
    goDept() {
      uni.navigateTo({
        url: `/pages/home/dept?idcard=${this.idcard}`
      })
    },
    // 历史取号
    goHistory() {
      uni.navigateTo({
        url: `/pages/home/businessList?source=history&idcard=${this.idcard}&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-around;
  padding: 0 5%;
  box-sizing: border-box;
}

/* 左侧按钮组 */
.btn-group {
  /* width: 60%; */
  /* height: 85%; */
  display: flex;
  flex-wrap: wrap;
  /* justify-content: space-between; */
  align-content: space-around;
}

.btn-item {
  width: 500px;
  height: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.btn-item.blue {
  margin-right: 60px;
  margin-bottom: 60px;
  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 {
  margin-right: 60px;
  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 {
  width: 55%;
  height: 740px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  padding: 40px 40px 16px;
  box-sizing: border-box;
}

.recommend-title {
  font-size: 40px;
  font-weight: bold;
  color: rgba(51, 51, 51, 1);
  text-align: center;
  margin-bottom: 30px;
}

.recommend-list {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  height: 85%;
}

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

.dot {
  color: #4080ff;
  font-size: 30px;
  margin-right: 10px;
}

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