<template>
	<ServicePageScaffold title="执行任务">
		<ServicePanel title="执行任务" subtitle="按移动执行页风格，先做任务卡片与状态动作。">
			<view v-for="item in tasks" :key="item.id" class="task-card" @click="goDetail(item.id)">
				<view class="task-top">
					<view>
						<text class="task-title">{{ item.elderName }} · {{ item.serviceName }}</text>
						<text class="task-meta">{{ item.caseNo }}</text>
					</view>
					<ServiceStatusTag :text="item.statusText" :tone="item.statusTone"></ServiceStatusTag>
				</view>
				<text class="task-info">预约时间：{{ item.appointmentTime }}</text>
				<text class="task-info">签到状态：{{ item.checkInStatus }}</text>
				<text class="task-info">服务地址：{{ item.address }}</text>
				<view class="action-btn">{{ item.actionText }}</view>
			</view>
		</ServicePanel>
	</ServicePageScaffold>
</template>

<script setup lang="uts">
import { ref } from 'vue'
import { onLoad, onShow } 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 { fetchWorkerTasks } from '@/services/homeServiceService.uts'
import { HomeServiceTaskType } from '@/types/home-service.uts'

const tasks = ref<Array<HomeServiceTaskType>>([])

async function loadData() {
	tasks.value = await fetchWorkerTasks()
}

function goDetail(taskId: string) {
	uni.navigateTo({ url: '/pages/mall/merchant/home-service/task-detail?id=' + taskId })
}

onLoad(() => {
	loadData()
})

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

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

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

.task-top {
	flex-direction: row;
	justify-content: space-between;
	align-items: flex-start;
}

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

.task-meta,
.task-info {
	margin-top: 10rpx;
	font-size: 26rpx;
	line-height: 38rpx;
	color: #66788a;
}

.action-btn {
	margin-top: 20rpx;
	padding: 20rpx 0;
	text-align: center;
	font-size: 28rpx;
	font-weight: 700;
	color: #ffffff;
	background: #0f766e;
	border-radius: 16rpx;
}
</style>