<template>
	<ServicePageScaffold title="派单调度中心" fallback-url="/pages/mall/admin/home-service/application-management/index">
		<ServicePanel title="派单调度中心" subtitle="首批只做调度总览和待派单清单，后续再补排班与改派。">
			<view v-for="item in applications" :key="item.id" class="dispatch-card">
				<view class="dispatch-row">
					<view>
						<text class="dispatch-title">{{ item.serviceName }}</text>
						<text class="dispatch-meta">{{ item.caseNo }} · {{ item.elderName }}</text>
					</view>
					<ServiceStatusTag :text="item.statusText" :tone="item.statusTone"></ServiceStatusTag>
				</view>
				<text class="dispatch-info">建议上门时间：{{ item.preferredTime }}</text>
				<text class="dispatch-info">评估结论：{{ item.assessmentResult }}</text>
				<text class="dispatch-info">当前执行人员：{{ item.staffName }}</text>
				<view class="row-actions">
					<view class="action ghost" @click="goPlan(item.caseId)">查看方案</view>
					<view class="action primary" @click="toastAssign">模拟派单</view>
				</view>
			</view>
		</ServicePanel>
	</ServicePageScaffold>
</template>

<script setup lang="uts">
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import ServicePageScaffold from '@/components/homeService/ServicePageScaffold.uvue'
import ServicePanel from '@/components/homeService/ServicePanel.uvue'
import ServiceStatusTag from '@/components/homeService/ServiceStatusTag.uvue'
import { fetchAdminHomeServiceApplications } from '@/services/homeServiceService.uts'
import { HomeServiceAdminApplicationType } from '@/types/home-service.uts'

const applications = ref<Array<HomeServiceAdminApplicationType>>([])

async function loadData() {
	applications.value = await fetchAdminHomeServiceApplications()
}

function goPlan(caseId: string) {
	uni.navigateTo({ url: '/pages/mall/admin/home-service/service-plan/index?id=' + caseId })
}

function toastAssign() {
	uni.showToast({ title: '已完成 mock 派单演示', icon: 'none' })
}

onLoad(() => {
	loadData()
})
</script>

<style scoped>
.page {
	min-height: 100vh;
	background: #f5f7fb;
	padding: 24rpx;
	box-sizing: border-box;
}

.dispatch-card {
	padding: 24rpx;
	border-radius: 20rpx;
	background: #f8fbfc;
	margin-bottom: 20rpx;
}

.dispatch-row,
.row-actions {
	flex-direction: row;
	justify-content: space-between;
	align-items: flex-start;
}

.dispatch-title {
	font-size: 30rpx;
	font-weight: 700;
	color: #16324f;
}

.dispatch-meta,
.dispatch-info {
	margin-top: 8rpx;
	font-size: 24rpx;
	line-height: 36rpx;
	color: #66788a;
}

.row-actions {
	margin-top: 20rpx;
	gap: 16rpx;
}

.action {
	flex: 1;
	padding: 22rpx 0;
	border-radius: 16rpx;
	text-align: center;
	font-size: 26rpx;
	font-weight: 700;
}

.ghost {
	background: #ffffff;
	color: #16324f;
	border-width: 2rpx;
	border-style: solid;
	border-color: #d7e0ea;
}

.primary {
	background: #1d4ed8;
	color: #ffffff;
}
</style>