<template>
	<request-form
		title="请假申请"
		subtitle="请完善请假信息，支持手机端快速提交"
		biz-type="leave"
		:request-api="submitLeave"
		:initial-form="initialForm"
		:sections="sections"
		:flow-fields="flowFields"
	/>
</template>

<script>
import RequestForm from '@/components/hrm/RequestForm.vue'
import { addLeaveReq } from '@/api/hrm/leave'

export default {
	components: { RequestForm },
	data() {
		return {
			initialForm: { leaveType: '', startTime: '', endTime: '', hours: '', reason: '', handover: '', remark: '' },
			sections: [
				{ key: 'basic', title: '基础信息', fields: [
					{ key: 'leaveType', label: '请假类型', type: 'select', required: true, placeholder: '请选择请假类型', options: ['年假', '事假', '病假', '调休', '婚假', '丧假', '其他'] },
					{ key: 'startTime', label: '开始时间', type: 'datetime', required: true, placeholder: '请选择开始时间' },
					{ key: 'endTime', label: '结束时间', type: 'datetime', required: true, placeholder: '请选择结束时间' },
					{ key: 'hours', label: '时长(小时)', type: 'computed', required: true, placeholder: '自动计算' }
				]},
				{ key: 'desc', title: '说明', fields: [
					{ key: 'reason', label: '事由', type: 'textarea', required: true, placeholder: '请填写请假原因' },
					{ key: 'handover', label: '工作交接', type: 'textarea', required: false, placeholder: '请填写交接安排（可选）' },
					{ key: 'remark', label: '备注', type: 'textarea', required: false, placeholder: '可选' }
				]}
			],
			flowFields: [
				{ key: 'leaveType', label: '请假类型', required: true },
				{ key: 'startTime', label: '开始时间', required: true },
				{ key: 'endTime', label: '结束时间', required: true },
				{ key: 'hours', label: '时长', required: true },
				{ key: 'reason', label: '事由', required: true }
			]
		}
	},
	methods: {
		submitLeave(payload) { return addLeaveReq({ ...payload, status: 'pending', bizType: 'leave' }) }
	}
}
</script>

<style scoped></style>