<!--
 * @Author: zwq
 * @Date: 2021-11-18 14:16:25
 * @LastEditors: zwq
 * @LastEditTime: 2025-10-15 16:31:11
 * @Description:
-->
<template>
	<el-form
		:model="dataForm"
		:rules="dataRule"
		ref="dataForm"
		@keyup.enter.native="dataFormSubmit()"
		label-position="top"
		label-width="80px">
		<el-row :gutter="20">
			<el-col :span="12">
				<el-form-item label="序号" prop="index">
					<el-input-number
						v-model="dataForm.index"
						:step="1"
						:min="1"
						step-strictly />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="班次名称" prop="name">
					<el-input
						v-model="dataForm.name"
						clearable
						placeholder="请输入班次名称" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="开始时间" prop="startDay">
					<el-time-picker
						style="width: 100%"
						format="H:mm"
						value-format="H:mm"
						v-model="dataForm.startDay"
						placeholder="选择日期时间"></el-time-picker>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="结束时间" prop="endDay">
					<el-time-picker
						style="width: 100%"
						format="H:mm"
						value-format="H:mm"
						v-model="dataForm.endDay"
						placeholder="选择日期时间"></el-time-picker>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="备注" prop="remark">
					<el-input
						v-model="dataForm.remark"
						clearable
						placeholder="请输入备注" />
				</el-form-item>
			</el-col>
		</el-row>
	</el-form>
</template>

<script>
export default {
	components: {},
	data() {
		return {
			dataForm: {
				id: undefined,
				index: undefined,
				name: undefined,
				startDay: undefined,
				endDay: undefined,
				remark: undefined,
			},
			_pageIndex: 1,
			dataRule: {
				index: [{ required: true, message: '序号不能为空', trigger: 'blur' }],
				name: [
					{ required: true, message: '班次名称不能为空', trigger: 'blur' },
				],
				startDay: [
					{ required: true, message: '开始时间不能为空', trigger: 'change' },
				],
				endDay: [
					{ required: true, message: '结束时间不能为空', trigger: 'change' },
				],
			},
		};
	},
	methods: {
		init(val) {
			this._pageIndex = val._pageIndex-1;
			this.dataForm.index = val._pageIndex || 1;
			this.dataForm.name = val.name || undefined;
			this.dataForm.startDay = val.startDay || undefined;
			this.dataForm.endDay = val.endDay || undefined;
			this.dataForm.remark = val.remark || undefined;
		},
		// 表单提交
		dataFormSubmit() {
			this.$refs['dataForm'].validate((valid) => {
				if (!valid) {
					return false;
				}
				this.$emit('refreshTableData', this._pageIndex, this.dataForm);
			});
		},
	},
};
</script>
