﻿<template>
	<div class="mesQiInspJob-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="inspJobNo">
							<el-input v-model="state.ruleForm.inspJobNo" 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="inspType">
							<el-select clearable v-model="state.ruleForm.inspType" placeholder="请选择检验类型">
								<el-option v-for="(item,index) in dl('checkTypes')"  :key="index" :value="Number(item.value)" :label="`${item.name} [${item.value}]`"></el-option>
								
							</el-select>
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="检验状态" prop="inspJobStatus">
							<el-switch v-model="state.ruleForm.inspJobStatus" active-text="是" inactive-text="否" />
							
						</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="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="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="produceOrderNo">
							<el-input v-model="state.ruleForm.produceOrderNo" 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="productCode">
							<el-input v-model="state.ruleForm.productCode" 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="productName">
							<el-input v-model="state.ruleForm.productName" 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="processCode">
							<el-input v-model="state.ruleForm.processCode" 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="processName">
							<el-input v-model="state.ruleForm.processName" 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="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="sendNum">
							<el-input-number v-model="state.ruleForm.sendNum" 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="inspNum">
							<el-input-number v-model="state.ruleForm.inspNum" 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="passNum">
							<el-input-number v-model="state.ruleForm.passNum" 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="inPassNum">
							<el-input-number v-model="state.ruleForm.inPassNum" 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="inspResult">
							<el-input v-model="state.ruleForm.inspResult" 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="inPassHandle">
							<el-input v-model="state.ruleForm.inPassHandle" 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="sendPersonAccount">
							<el-input v-model="state.ruleForm.sendPersonAccount" 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="sendPersonName">
							<el-input v-model="state.ruleForm.sendPersonName" 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="sendDate">
							<el-date-picker v-model="state.ruleForm.sendDate" 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="inspPersonAccount">
							<el-input v-model="state.ruleForm.inspPersonAccount" 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="inspPersonName">
							<el-input v-model="state.ruleForm.inspPersonName" 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="inspDate">
							<el-date-picker v-model="state.ruleForm.inspDate" type="date" placeholder="检验时间" />
							
						</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 { addMesQiInspJob, updateMesQiInspJob, detailMesQiInspJob } from "/@/api/mes/mesQiInspJob";
	import { pageMesQiInspJob, deleteMesQiInspJob } from '/@/api/mes/mesQiInspJob';

	import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
  	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>({
		inspJobNo: [{required: true, message: '请输入报检单号！', trigger: 'blur',},],
		inspType: [{required: true, message: '请选择检验类型！', trigger: 'change',},],
		produceWorkOrderNo: [{required: true, message: '请输入工单号！', trigger: 'blur',},],
		producePlanNo: [{required: true, message: '请输入生产计划号！', trigger: 'blur',},],
		produceOrderNo: [{required: true, message: '请输入生产订单号！', trigger: 'blur',},],
		productCode: [{required: true, message: '请输入产品编码！', trigger: 'blur',},],
		processCode: [{required: true, message: '请输入工序编码！', trigger: 'blur',},],
		equipmentCode: [{required: true, message: '请输入设备编码！', trigger: 'blur',},],
		sendNum: [{required: true, message: '请输入送检数量！', trigger: 'blur',},],
		inspNum: [{required: true, message: '请输入检验数量！', trigger: 'blur',},],
		passNum: [{required: true, message: '请输入合格数量！', trigger: 'blur',},],
		inPassNum: [{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 detailMesQiInspJob(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 addMesQiInspJob(values);
				} else {
					await updateMesQiInspJob(values);
				}
				closeDialog();
			} else {
				ElMessage({
					message: `表单有${Object.keys(fields).length}处验证失败，请修改后再提交`,
					type: "error",
				});
			}
		});
	};






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




