﻿<template>
	<div class="mesProducePlan-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="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="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="customerCode">
							<el-input v-model="state.ruleForm.customerCode" 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="customerName">
							<el-input v-model="state.ruleForm.customerName" 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="cmdNo">
							<el-input v-model="state.ruleForm.cmdNo" 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="产品出数PCS" prop="productPcs">
							<el-input-number v-model="state.ruleForm.productPcs" placeholder="请输入产品出数PCS" 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="workShopCode">
							<el-input v-model="state.ruleForm.workShopCode" 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="workShopName">
							<el-input v-model="state.ruleForm.workShopName" 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="workSectionCode">
							<el-input v-model="state.ruleForm.workSectionCode" 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="workSectionName">
							<el-input v-model="state.ruleForm.workSectionName" 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="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="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="planStartDate">
							<el-date-picker v-model="state.ruleForm.planStartDate" 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="planEndDate">
							<el-date-picker v-model="state.ruleForm.planEndDate" 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="planNum">
							<el-input-number v-model="state.ruleForm.planNum" 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="计划数量(m)" prop="planNumM">
							<el-input v-model="state.ruleForm.planNumM" placeholder="请输入计划数量(m)" 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="finishNum">
							<el-input-number v-model="state.ruleForm.finishNum" 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="实际完工(m)" prop="finishNumM">
							<el-input v-model="state.ruleForm.finishNumM" placeholder="请输入实际完工(m)" 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="生产计划状态 0.未下发 1.已下发" prop="producePlanStatus">
							<el-input-number v-model="state.ruleForm.producePlanStatus" placeholder="请输入生产计划状态 0.未下发 1.已下发" clearable />
							
						</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="produceOrderProductId">
							<el-input v-model="state.ruleForm.produceOrderProductId" 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="factoryCode">
							<el-input v-model="state.ruleForm.factoryCode" 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="factoryName">
							<el-input v-model="state.ruleForm.factoryName" 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="出数长度(m)" prop="productPcsLength">
							<el-input v-model="state.ruleForm.productPcsLength" placeholder="请输入出数长度(m)" maxlength="18" 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 { addMesProducePlan, updateMesProducePlan, detailMesProducePlan } from "/@/api/mes/mesProducePlan";
	import { pageMesProducePlan, deleteMesProducePlan } from '/@/api/mes/mesProducePlan';

  	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>({
		producePlanNo: [{required: true, message: '请输入计划单号！', trigger: 'blur',},],
		productCode: [{required: true, message: '请输入产品编码！', trigger: 'blur',},],
		customerCode: [{required: true, message: '请输入客户编码！', trigger: 'blur',},],
		customerName: [{required: true, message: '请输入客户名称！', trigger: 'blur',},],
		produceOrderNo: [{required: true, message: '请输入生产订单号！', trigger: 'blur',},],
		productPcs: [{required: true, message: '请输入产品出数PCS！', trigger: 'blur',},],
		workShopCode: [{required: true, message: '请输入车间编码！', trigger: 'blur',},],
		workSectionCode: [{required: true, message: '请输入工段编码！', trigger: 'blur',},],
		processCode: [{required: true, message: '请输入工序编码！', trigger: 'blur',},],
		planStartDate: [{required: true, message: '请选择计划开工日期！', trigger: 'change',},],
		planEndDate: [{required: true, message: '请选择计划完工日期！', trigger: 'change',},],
		planNum: [{required: true, message: '请输入计划数量！', trigger: 'blur',},],
		planNumM: [{required: true, message: '请输入计划数量(m)！', trigger: 'blur',},],
		finishNum: [{required: true, message: '请输入实际完工数量！', trigger: 'blur',},],
		producePlanStatus: [{required: true, message: '请输入生产计划状态 0.未下发 1.已下发！', trigger: 'blur',},],
		produceOrderProductId: [{required: true, message: '请输入生产订单产品Id！', trigger: 'blur',},],
		factoryCode: [{required: true, message: '请输入工厂编码！', trigger: 'blur',},],
		productPcsLength: [{required: true, message: '请输入出数长度(m)！', 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 detailMesProducePlan(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 addMesProducePlan(values);
				} else {
					await updateMesProducePlan(values);
				}
				closeDialog();
			} else {
				ElMessage({
					message: `表单有${Object.keys(fields).length}处验证失败，请修改后再提交`,
					type: "error",
				});
			}
		});
	};






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




