<template>
	<ServicePageScaffold title="到岗签到" fallback-url="/pages/mall/merchant/home-service/tasks">
			<ServicePanel title="到岗签到" subtitle="记录真实签到结果、到岗说明和执行留痕提示。">
			<text class="info">任务编号：{{ taskNo }}</text>
			<text class="info">当前状态：{{ taskStatus }}</text>
			<view class="block">
				<text class="label">签到确认</text>
				<view class="tag-row">
					<view class="tag active">GPS 已到位</view>
					<view class="tag active">服务对象确认</view>
					<view class="tag">拍照凭证待接入</view>
				</view>
			</view>
			<view class="block">
				<text class="label">签到说明</text>
				<textarea v-model="note" class="textarea" placeholder="可填写到岗时间、现场情况、陪护确认信息"></textarea>
			</view>
			<view class="submit-btn" @click="submitCheckIn">确认签到</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 { fetchWorkerTaskDetail, submitWorkerCheckIn } from '@/services/homeServiceService.uts'

const taskId = ref('')
const taskNo = ref('')
const taskStatus = ref('待上门')
const note = ref('已完成到岗签到，服务对象和家属已确认。')

onLoad((options) => {
	const id = options['id']
	if (id != null) {
		taskId.value = id as string
		fetchWorkerTaskDetail(taskId.value).then((res) => {
			if (res != null) {
				taskNo.value = res.caseNo
				taskStatus.value = res.statusText
			}
		})
	}
})

async function submitCheckIn() {
	if (taskId.value == '') {
		return
	}
	const result = await submitWorkerCheckIn(taskId.value, note.value)
	if (result != null) {
		uni.showToast({ title: '签到完成', icon: 'success' })
		setTimeout(() => {
			uni.navigateBack()
		}, 400)
	}
}
</script>

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

.info,
.label {
	font-size: 28rpx;
	line-height: 40rpx;
	color: #16324f;
}

.block {
	margin-top: 24rpx;
}

.tag-row {
	margin-top: 16rpx;
	flex-direction: row;
	flex-wrap: wrap;
	gap: 16rpx;
}

.tag {
	padding: 12rpx 20rpx;
	border-radius: 999rpx;
	background: #eef2f6;
	font-size: 24rpx;
	color: #66788a;
}

.active {
	background: #e8f7ef;
	color: #15803d;
}

.textarea {
	margin-top: 16rpx;
	width: 100%;
	height: 220rpx;
	padding: 24rpx;
	box-sizing: border-box;
	background: #f8fbfc;
	border-radius: 20rpx;
	font-size: 28rpx;
	color: #23384d;
}

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