<template>
	<Container backBtn logoutBtn @handleBack="handleBack">
		<template #main>
			<view class="theme-page">
				<view class="card">
					<view class="title">部门取号</view>
					<view class="btn-group">
						<view class="btn-item" v-for="(item, index) in deptList" :key="index"
							@click="handleSelect(item)">
							{{ item.deptName }}
						</view>
					</view>
				</view>
			</view>
		</template>
	</Container>
</template>

<script>
	import Container from '@/components/container/container.vue'
	import {
		getList,
	} from '@/api/system/dept.js'

	export default {
		components: {
			Container
		},
		data() {
			return {
				deptList: [],
				idcard: ''
			}
		},
		onLoad(options) {
			this.idcard = options.idcard || ''
		},
		mounted() {
			this.fetchDeptList()
		},
		methods: {
			handleBack() {
				uni.navigateBack()
			},

			handleSelect(item) {
				uni.navigateTo({
					url: `/pages/home/businessList?source=dept&deptId=${item.id}&deptName=${item.deptName}&idcard=${this.idcard}`
				})
			},

			async fetchDeptList() {
				try {
					const res = await getList({ parentId: '1123598813738675202' })
					if (res.success && res.data) {
						this.deptList = res.data.records || res.data || []
					}
				} catch (e) {
					console.error('获取部门列表失败', e)
				}
			}
		}
	}
</script>

<style scoped>
	.theme-page {
		width: 100%;
		height: 100%;
		padding: 200px 60px 150px;
		display: flex;
		align-items: center;
		justify-content: center;
		box-sizing: border-box;
	}

	.card {
		width: 100%;
		height: 740px;
		background: #fff;
		border-radius: 60px;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 40px;
	}

	.title {
		font-size: 40px;
		font-weight: bold;
		color: rgba(51, 51, 51, 1);
		margin-bottom: 60px;
	}

	.btn-group {
		width: 100%;
		flex: 1;
		display: flex;
		flex-wrap: wrap;
		align-content: flex-start;
		gap: 40px;
	}

	.btn-item {
		padding: 17px 25px;
		width: 400px;
		height: 140px;
		text-align: center;
		background: rgba(236, 243, 255, 1);
		border-radius: 20px;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 40px;
		color: rgba(51, 51, 51, 1);
		cursor: pointer;
	}
</style>
