<template>
	<ServicePageScaffold title="服务记录" fallback-url="/pages/mall/merchant/home-service/tasks">
		<ServicePanel title="服务记录" subtitle="本页先记录执行摘要、服务步骤和后续待上传凭证占位。">
			<text class="info">任务编号：{{ taskNo }}</text>
			<view class="block">
				<text class="label">执行步骤</text>
				<view class="step-card" v-for="item in steps" :key="item">{{ item }}</view>
			</view>
			<view class="block">
				<text class="label">服务摘要</text>
				<textarea v-model="summary" class="textarea" placeholder="记录生命体征、护理动作、家属沟通和后续建议"></textarea>
			</view>
			<view class="block">
				<text class="label">凭证上传</text>
				<view class="upload-box">后续接入拍照、音视频和签名凭证</view>
			</view>
			<view class="submit-btn" @click="submitRecord">保存记录</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, submitWorkerServiceRecord } from '@/services/homeServiceService.uts'

const taskId = ref('')
const taskNo = ref('')
const summary = ref('已完成血压监测、基础照护和风险提醒，家属已确认后续随访时间。')
const steps = ['生命体征记录', '基础照护执行', '家属沟通说明']

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
				summary.value = res.recordSummary
			}
		})
	}
})

async function submitRecord() {
	if (taskId.value == '') {
		return
	}
	const result = await submitWorkerServiceRecord(taskId.value, summary.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,
.step-card,
.upload-box {
	font-size: 28rpx;
	line-height: 40rpx;
	color: #16324f;
}

.block {
	margin-top: 24rpx;
}

.step-card,
.upload-box {
	margin-top: 16rpx;
	padding: 22rpx 24rpx;
	background: #f8fbfc;
	border-radius: 18rpx;
}

.textarea {
	margin-top: 16rpx;
	width: 100%;
	height: 260rpx;
	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>