﻿<template>
	<div class="mesWorkRecord-container">
		<el-dialog v-model="state.isShowDialog" v-if="state.isShowDialog" :width="800" draggable="" :close-on-click-modal="false">
			<template #header>
				<div style="color: #fff">
					<!--<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>-->
					<span>{{ props.title }}</span>
				</div>
			</template>
			<el-form :model="state.ruleForm" ref="ruleFormRef" label-width="auto" :rules="rules">
				<el-row :gutter="35">
					<el-form-item v-show="false">
						<el-input v-model="state.ruleForm.id" />
					</el-form-item>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="开工日期" prop="startWorkDate">
							<el-date-picker v-model="state.ruleForm.startWorkDate" type="date" placeholder="开工日期" />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="完工日期" prop="endWorkDate">
							<el-date-picker v-model="state.ruleForm.endWorkDate" type="date" placeholder="完工日期" />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="生产工单Id" prop="produceWorkOrderId">
							<el-input v-model="state.ruleForm.produceWorkOrderId" placeholder="请输入生产工单Id" maxlength="0" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="电晕批次号" prop="dyBatchNo">
							<el-input v-model="state.ruleForm.dyBatchNo" placeholder="请输入电晕批次号" maxlength="32" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="覆膜批次号" prop="fmBatchNo">
							<el-input v-model="state.ruleForm.fmBatchNo" placeholder="请输入覆膜批次号" maxlength="32" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="报工数量(批次数)" prop="num">
							<el-input v-model="state.ruleForm.num" placeholder="请输入报工数量(批次数)" maxlength="18" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="报工单位编码" prop="unitCode">
							<el-input v-model="state.ruleForm.unitCode" placeholder="请输入报工单位编码" maxlength="100" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="报工单位名称" prop="unitName">
							<el-input v-model="state.ruleForm.unitName" placeholder="请输入报工单位名称" maxlength="100" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="设备编码" prop="equipmentCode">
							<el-input v-model="state.ruleForm.equipmentCode" placeholder="请输入设备编码" maxlength="100" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="设备名称" prop="equipmentName">
							<el-input v-model="state.ruleForm.equipmentName" placeholder="请输入设备名称" maxlength="100" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="产线编码" prop="productionLineCode">
							<el-input v-model="state.ruleForm.productionLineCode" placeholder="请输入产线编码" maxlength="100" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="产线名称" prop="productionLineName">
							<el-input v-model="state.ruleForm.productionLineName" placeholder="请输入产线名称" maxlength="100" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="作业人员账号" prop="workPersonAccount">
							<el-input v-model="state.ruleForm.workPersonAccount" placeholder="请输入作业人员账号" maxlength="100" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="作业人员姓名" prop="workPersonName">
							<el-input v-model="state.ruleForm.workPersonName" placeholder="请输入作业人员姓名" maxlength="100" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="贴膜静置" prop="deviceTm">
							<el-input v-model="state.ruleForm.deviceTm" placeholder="请输入贴膜静置" maxlength="32" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="速度" prop="deviceSpeed">
							<el-input v-model="state.ruleForm.deviceSpeed" placeholder="请输入速度" maxlength="32" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="达因值" prop="deviceDyz">
							<el-input v-model="state.ruleForm.deviceDyz" placeholder="请输入达因值" maxlength="32" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="温度" prop="deviceWd">
							<el-input v-model="state.ruleForm.deviceWd" placeholder="请输入温度" maxlength="32" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="功率" prop="deviceGl">
							<el-input v-model="state.ruleForm.deviceGl" placeholder="请输入功率" maxlength="32" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="压力" prop="deviceYl">
							<el-input v-model="state.ruleForm.deviceYl" placeholder="请输入压力" maxlength="32" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="是否打印看板" prop="isPrintPanel">
							<el-input-number v-model="state.ruleForm.isPrintPanel" placeholder="请输入是否打印看板" clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="打印看板日期" prop="printPanelDate">
							<el-date-picker v-model="state.ruleForm.printPanelDate" type="date" placeholder="打印看板日期" />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="生产计划id" prop="producePlanId">
							<el-input v-model="state.ruleForm.producePlanId" placeholder="请输入生产计划id" maxlength="0" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="生产计划号" prop="producePlanNo">
							<el-input v-model="state.ruleForm.producePlanNo" placeholder="请输入生产计划号" maxlength="100" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="生产工单号" prop="produceWorkOrderNo">
							<el-input v-model="state.ruleForm.produceWorkOrderNo" placeholder="请输入生产工单号" maxlength="32" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="裁板批次" prop="cbBatchNo">
							<el-input v-model="state.ruleForm.cbBatchNo" placeholder="请输入裁板批次" maxlength="32" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="显影批次" prop="xyBatchNo">
							<el-input v-model="state.ruleForm.xyBatchNo" placeholder="请输入显影批次" maxlength="32" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="蚀刻批次" prop="skBatchNo">
							<el-input v-model="state.ruleForm.skBatchNo" placeholder="请输入蚀刻批次" maxlength="32" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="cancel">取 消</el-button>
					<el-button type="primary" @click="submit">确 定</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>
<style lang="scss" scoped>
:deep(.el-select),
:deep(.el-input-number) {
	width: 100%;
}
</style>
<script lang="ts" setup>
    import { ref,onMounted, reactive } from "vue";
	import { ElMessage } from "element-plus";
	import type { FormRules } from "element-plus";
	import { addMesWorkRecord, updateMesWorkRecord, detailMesWorkRecord } from "/@/api/mes/mesWorkRecord";
	import { pageMesWorkRecord, deleteMesWorkRecord } from '/@/api/mes/mesWorkRecord';

  	import { formatDate } from '/@/utils/formatTime';

	//父级传递来的参数
	var props = defineProps({
		title: {
		type: String,
		default: "",
	},
	});
	//父级传递来的函数，用于回调
	const emit = defineEmits(["reloadTable"]);
	const ruleFormRef = ref();
    const state = reactive({
    isShowDialog: false,
    ruleForm: {} as any,
});

	//自行添加其他规则
	const rules = ref<FormRules>({
		startWorkDate: [{required: true, message: '请选择开工日期！', trigger: 'change',},],
		produceWorkOrderId: [{required: true, message: '请输入生产工单Id！', trigger: 'blur',},],
		num: [{required: true, message: '请输入报工数量(批次数)！', trigger: 'blur',},],
		equipmentCode: [{required: true, message: '请输入设备编码！', trigger: 'blur',},],
		workPersonAccount: [{required: true, message: '请输入作业人员账号！', trigger: 'blur',},],
		isPrintPanel: [{required: true, message: '请输入是否打印看板！', trigger: 'blur',},],
		producePlanId: [{required: true, message: '请输入生产计划id！', trigger: 'blur',},],
		producePlanNo: [{required: true, message: '请输入生产计划号！', trigger: 'blur',},],
		produceWorkOrderNo: [{required: true, message: '请输入生产工单号！', trigger: 'blur',},],
	});

	// 页面加载时
	onMounted(() => {

	});

	// 打开弹窗
	const openDialog = async (row: any) => {
		// state.ruleForm = JSON.parse(JSON.stringify(row));
		// 改用detail获取最新数据来编辑
		let rowData = JSON.parse(JSON.stringify(row));
		if (rowData.id)
			state.ruleForm = (await detailMesWorkRecord(rowData.id)).data.result;
		else
			state.ruleForm = rowData;
		state.isShowDialog = true;
	};

	// 关闭弹窗
	const closeDialog = () => {
		emit("reloadTable");
		state.isShowDialog = false;
	};

	// 取消
	const cancel = () => {
		state.isShowDialog = false;
	};

	// 提交
	const submit = async () => {
		ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
			if (isValid) {
				let values = state.ruleForm;
				if (state.ruleForm.id == undefined || state.ruleForm.id == null || state.ruleForm.id == "" || state.ruleForm.id == 0) {
					await addMesWorkRecord(values);
				} else {
					await updateMesWorkRecord(values);
				}
				closeDialog();
			} else {
				ElMessage({
					message: `表单有${Object.keys(fields).length}处验证失败，请修改后再提交`,
					type: "error",
				});
			}
		});
	};






	//将属性或者函数暴露给父组件
	defineExpose({ openDialog });
</script>




