﻿<template>
	<div class="mesMaterialTestTaskHead-container">
		<el-dialog v-model="state.isShowDialog" v-if="state.isShowDialog" :width="900" 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="50" 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="请选择产品" :disabled="isEditable"  clearable @keyup.enter="scanCode"  >
                               <template #append v-if="props.title=='编辑原材料检验任务主表'==false">
								  <el-icon  @click="scanCode"></el-icon><!--<ele-FullScreen />-->
								  <el-button @click="openChoose">选择</el-button>
                               </template>
                            </el-input>
						</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" disabled="true" 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="productModel">
							<el-input v-model="state.ruleForm.productModel" disabled="true" placeholder="请输入原材料规格" maxlength="150" 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="请选择检验类型" :disabled="isEditable"  >
								<el-option v-for="(item,index) in checktype"  :key="index" :value="item.code"  :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="materialType">
							<el-select clearable filterable v-model="state.ruleForm.materialType" placeholder="请选择材料名称"   @change="onChooseMaterialFinishApplyType">
								<el-option v-for="(item,index) in mesQiItemQiItemCodeDropdownList" :key="index" :value="item.code" :label="item.name" />

							</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="inspStatus">
							<el-switch v-model="state.ruleForm.inspStatus" 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="inspResult">
							<el-input v-model="state.ruleForm.inspResult" 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" v-if="state.ruleForm.id">
						<el-form-item label="不合格处置" prop="inPassHandle">
							<el-input v-model="state.ruleForm.inPassHandle" placeholder="请输入不合格处置" maxlength="255" 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="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="sendPersonName">
							<el-input v-model="state.ruleForm.sendPersonName" 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="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="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="inspPersonName">
							<el-input v-model="state.ruleForm.inspPersonName" 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="inspDate">
							<el-date-picker v-model="state.ruleForm.inspDate" 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="examinePersonAccount">
							<el-input v-model="state.ruleForm.examinePersonAccount" 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="examinePersonName">
							<el-input v-model="state.ruleForm.examinePersonName" 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="examineDate">
							<el-date-picker v-model="state.ruleForm.examineDate" 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="supplierCode">
                           <el-input v-model="state.ruleForm.supplierCode"  placeholder="请选择供应商" disabled="true" maxlength="100" show-word-limit clearable >
                               <template #append v-if="props.title=='编辑原材料检验任务主表'==false">
                                  <el-button @click="openSupper">选择</el-button>
                               </template>
                            </el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="供应商名称" prop="supplierName">
							<el-input v-model="state.ruleForm.supplierName" placeholder="请输入供应商名称" disabled="true" 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="partSpec">
							<el-input v-model="state.ruleForm.partSpec" placeholder="请输入产品名称规格" :disabled="isEditable"  maxlength="150" 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="materialSpec">
							<el-input v-model="state.ruleForm.materialSpec" placeholder="请输入材料进厂批次" maxlength="64" 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="materialSpec">
							<el-date-picker v-model="state.ruleForm.materialSpec" placeholder="请输入材料进厂批次"  :disabled="isEditable"   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="testSpec">
							<el-input v-model="state.ruleForm.testSpec" placeholder="请输入检验批次" disabled="true" 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="heatNumber">
							<el-input v-model="state.ruleForm.heatNumber" placeholder="请输入钢厂炉号" :disabled="isEditable"  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="cartNumber">
							<el-input v-model="state.ruleForm.cartNumber" placeholder="请输入冷轧厂卡号" :disabled="isEditable"  maxlength="255" 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="purchaseNumber">
							<el-input-number v-model="state.ruleForm.purchaseNumber" placeholder="请输入进货数量" :disabled="isEditable"   min="1" 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="purchaseQuantity">
							<el-input-number v-model="state.ruleForm.purchaseQuantity" placeholder="请输入进货件数" :disabled="isEditable"   :precision="0" min="1" 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="sortCode">
							<el-input-number v-model="state.ruleForm.sortCode" 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="remark">
							<el-input v-model="state.ruleForm.remark"  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>
			<template v-if="state.ruleForm.id">
                <el-tabs v-model="tabActive">
                <el-tab-pane label="检验项目及标准" name="item"></el-tab-pane>
                </el-tabs>
                <MesQiInspTempItem :qiInspJobIds="state.ruleForm.id+'-'+state.ruleForm.samplingNumMax+'-修改'" v-if="tabActive == 'item'"></MesQiInspTempItem>
            </template>
			<template v-if="props.title=='添加原材料检验任务主表'">
                <el-tabs v-model="tabActive">
                <el-tab-pane label="检验项目及标准" name="item"></el-tab-pane>
                </el-tabs>
                <el-table :data="detailList">
				<el-table-column type="index" label="序号" width="55" align="center" />
                <el-table-column prop="qiItemName" label="检验项名称" width="120"  show-overflow-tooltip="" />
                <el-table-column prop="testRequire" label="检验要求" width="100"  show-overflow-tooltip="" />
				<el-table-column prop="samplingNum" label="取样数" width="100"  show-overflow-tooltip="" />
				<el-table-column prop="standVal" label="标准值" width="100"  show-overflow-tooltip="" />
				<el-table-column prop="maxVal" label="上限值" width="100"  show-overflow-tooltip="" />
				<el-table-column prop="minVal" label="下限值" width="100"  show-overflow-tooltip="" />
            </el-table>
            </template>
		</el-dialog>
		<!--  选择原材料  -->
		<choose-material title="选择原材料" ref="chooseMaterialRef"  :is-any="false" @finish="onChooseMaterialFinish"></choose-material>
		<!--  选择供应商  -->
		<choose-supper title="选择原材料" ref="chooseSupperRef"  :is-any="false" @finish="onChooseSupperFinish"></choose-supper>
	</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 { addMesMaterialTestTaskHead, updateMesMaterialTestTaskHead, detailMesMaterialTestTaskHead,getMesQiItemQiItemCodeDropdown ,ScanMaintel,ScanSupper,sendProducePlanTemplate,getMesQiItemQiItemCodeDropdowns,getMesQiItemQiItemCode} from "/@/api/simple/mesMaterialTestTaskHead";
	import { pageMesMaterialTestTaskHead, deleteMesMaterialTestTaskHead } from '/@/api/simple/mesMaterialTestTaskHead';
	import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
  	import { formatDate } from '/@/utils/formatTime';
	//import ChooseMaterial from "/@/businessComponents/chooseMaterial.vue";
	import ChooseMaterial from "/@/views/simple/mesmaterialtesttemplatehead/component/chooseMaterial.vue";
	import ChooseSupper from "/@/views/simple/mesMaterialTestTaskHead/component/chooseSupper.vue";
	import MesQiInspTempItem from "/@/views/simple/mesMaterialTestTaskDetial/index.vue";
    import { disable } from "ol/rotationconstraint";
	//父级传递来的参数
	var props = defineProps({
		title: {
		type: String,
		default: "",
	},
	});
	//父级传递来的函数，用于回调
	const emit = defineEmits(["reloadTable"]);
	const ruleFormRef = ref();
    const state = reactive({
    isShowDialog: false,
    ruleForm: {} as any,
});

 // 子表
 const detailList = ref([]);

const checktype=ref([]);//检验的表
	//自行添加其他规则
	const rules = ref<FormRules>({
	});

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

	});
const isEditable=ref(false);
	// 打开弹窗
	const openDialog = async (row: any) => {
		// state.ruleForm = JSON.parse(JSON.stringify(row));
		// 改用detail获取最新数据来编辑
		detailList.value = [];
		checktype.value=[];
		let list: any[] = (dl('materialchecktype') || []).map((item: any) => ({
        ...item,
		code:item.code,
        name: item.name,
        value: item.value,
      }));
	
	  for(let index=0;index<list.length;index++)
	  {
		if(list[index]["name"]=="原材料检验")
		{
			checktype.value.push(list[index]);
		}
	  }
	  
		let rowData = JSON.parse(JSON.stringify(row));
		if (rowData.id)
	    {
			state.ruleForm = (await detailMesMaterialTestTaskHead(rowData.id)).data.result;
			console.log(`${rowData.materialCode}`);
			getMesQiItemQiItemCodeDropdownList(`${rowData.materialCode}`);
			state.ruleForm.inspType=`${rowData.inspType}`;
			state.ruleForm.materialSpec=new Date(state.ruleForm.materialSpec);
			state.ruleForm.materialType=`${rowData.materialType}`;
			if(props.title=="编辑原材料检验任务主表")
		    {
				isEditable.value=true;
				getMesQiItemQiItemCodeDropdownList(rowData.productCode);
		    }
	    }
		else
		{
			state.ruleForm = rowData;
			state.ruleForm.inspType="1";
			isEditable.value=false;
			//state.ruleForm.materialType="Standard";
		}
		if(props.title=="添加原材料检验任务主表")
		{
			isEditable.value=false;
		}
		state.isShowDialog = true;
	};

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

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

	// 提交
	const submit = async () => {
		ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
			if (isValid) {
				let values = state.ruleForm;
				if(state.ruleForm.productCode==undefined)
			    {
			    	return ElMessage({
                     message: `原材料不可以为空！`,
                     type: "error",
                    });
			    }
				if(state.ruleForm.materialSpec==undefined)
			    {
			    	return ElMessage({
                     message: `材料进厂批次不可以为空！`,
                     type: "error",
                    });
			    }
				if(state.ruleForm.partSpec==undefined)
			    {
			    	return ElMessage({
                     message: `产品名称规格不可以为空！`,
                     type: "error",
                    });
			    }
				if(state.ruleForm.heatNumber==undefined)
			    {
			    	return ElMessage({
                     message: `钢厂炉号不可以为空！`,
                     type: "error",
                    });
			    }
				if(state.ruleForm.cartNumber==undefined)
			    {
			    	return ElMessage({
                     message: `冷轧厂卡号不可以为空！`,
                     type: "error",
                    });
			    }
				if(state.ruleForm.purchaseNumber==undefined)
			    {
			    	return ElMessage({
                     message: `进货数量不可以为空！`,
                     type: "error",
                    });
			    }
				if(state.ruleForm.purchaseQuantity==undefined)
			    {
			    	return ElMessage({
                     message: `进货件量不可以为空！`,
                     type: "error",
                    });
			    }
				var numReg = /^[0-9]+$/
				if (!numReg.test(state.ruleForm.materialSpec))
				{
					state.ruleForm.materialSpec=new Date(state.ruleForm.materialSpec);
					state.ruleForm.materialSpec=state.ruleForm.materialSpec.getFullYear()+('0' + (state.ruleForm.materialSpec.getMonth() + 1)).slice(-2)+state.ruleForm.materialSpec.getDate().toString().padStart(2, '0');
				}
				if (state.ruleForm.id == undefined || state.ruleForm.id == null || state.ruleForm.id == "" || state.ruleForm.id == 0) {
					//await addMesMaterialTestTaskHead(values);
					var result=(await addMesMaterialTestTaskHead(values)).data.result;
					if(result=="添加成功")
					 closeDialog();
					else
					{
					  ElMessage({
					    message: `${result}`,
					    type: "error",
				       });
					}
				} else {
					await updateMesMaterialTestTaskHead(values);
					closeDialog();
				}
				
			} else {
				ElMessage({
					message: `表单有${Object.keys(fields).length}处验证失败，请修改后再提交`,
					type: "error",
				});
			}
		});
	};

	const tabActive = ref('item');
	const chooseMaterialRef = ref();
    const openChoose = ()=>{
      chooseMaterialRef.value.openDialog({})
    }
    const onChooseMaterialFinish = async(row)=>{
      state.ruleForm.productName = row?.materialName;
      state.ruleForm.productCode = row?.materialCode;
      state.ruleForm.productModel = row?.specs;

	  //判断当前先择的原材料是否存在检验模板
	  let listtemplate = await sendProducePlanTemplate({packCode:state.ruleForm.productCode,});
	  let datatemplate = listtemplate.data.result ?? [];
	  if(datatemplate.length==0)
	  {
		state.ruleForm.productName = "";
        state.ruleForm.productCode = "";
        state.ruleForm.productModel = "";
		return ElMessage({
        message: `当前${ row?.materialCode}产品没有原材料检验模板，请先维护原材料检验模板`,
        type: "error",
      });
	  }

	  //生成进厂检验规则
      let list = await getMesQiItemQiItemCodeDropdown({packCode:state.ruleForm.productCode,});
      let data = list.data.result ?? [];
	  if(data.length==0)
	  {
		  const datenow=new Date();
		  const datanow=datenow.getFullYear()+('0' + (datenow.getMonth() + 1)).slice(-2)+datenow.getDate().toString().padStart(2, '0');
		  state.ruleForm.testSpec=datanow+row?.materialCode+"0001";
	  }
	  else{
		const datenow=data[0].testSpec;
		let num=datenow.substring(datenow.length-4);
		let number=parseFloat(num)+1;
		state.ruleForm.testSpec=datenow.substring(0,datenow.length-4)+number.toString().padStart(4,'0');
	  }
	  getMesQiItemQiItemCodeDropdownList(row?.materialCode);
	  state.ruleForm.materialType=mesQiItemQiItemCodeDropdownList.value[0].code;
	  onChooseMaterialFinishApplyType("");
	  
    }

	const chooseSupperRef = ref();
    const openSupper = ()=>{
      chooseSupperRef.value.openDialog({})
    }
    const onChooseSupperFinish = (row)=>{
      state.ruleForm.supplierName = row?.supplierName;
      state.ruleForm.supplierCode = row?.supplierCode;
    }

	// 扫码载具转移前条码
	const scanCode = async ()=>{
		
	  console.log(state.ruleForm.productCode);
	  const matial=state.ruleForm.productCode.split('*');
	  if(matial.length!=5)
	  {
		return ElMessage({
        message: `二维码信息不正确`,
        type: "error",
      });
	  }

	  //判断当前先择的原材料是否存在检验模板
	  let listtemplate = await sendProducePlanTemplate({packCode:matial[0],});
	  let datatemplate = listtemplate.data.result ?? [];
	  if(datatemplate.length==0)
	  {
		state.ruleForm.productCode="";
		return ElMessage({
        message: `当前${ matial[0]}产品没有原材料检验模板，请先维护原材料检验模板`,
        type: "error",
      });
	  }

      //查询原材料编码
      let  res = await ScanMaintel({
        packCode:matial[0],
      })
      let datas = res.data.result || {};
	  if(datas.materialCode==undefined)
	  {
		state.ruleForm.productCode="";
        state.ruleForm.productName="";
	    state.ruleForm.productModel="";
        state.ruleForm.heatNumber="";

	    state.ruleForm.purchaseNumber="";
	    state.ruleForm.purchaseQuantity="";
		return ElMessage({
        message: `系统中不存在当前原材料信息`,
        type: "error",
      });
	  }
	  else
	  {
		state.ruleForm.productName = datas.materialName;
        state.ruleForm.productCode = datas.materialCode;
        state.ruleForm.productModel = datas.specs;
		state.ruleForm.heatNumber=matial[2];
		state.ruleForm.purchaseNumber=matial[3];
	    state.ruleForm.purchaseQuantity=matial[4];
	    //生成进厂检验规则
        let list = await getMesQiItemQiItemCodeDropdown({packCode:state.ruleForm.productCode,});
        let data = list.data.result ?? [];
	    if(data.length==0)
	    {
		  const datenow=new Date();
		  const datanow=datenow.getFullYear()+('0' + (datenow.getMonth() + 1)).slice(-2)+datenow.getDate().toString().padStart(2, '0');
		  state.ruleForm.testSpec=datanow+datas.materialCode+"0001";
	    }
	    else{
		const datenow=data[0].testSpec;
		let num=datenow.substring(datenow.length-4);
		let number=parseFloat(num)+1;
		state.ruleForm.testSpec=datenow.substring(0,datenow.length-4)+number.toString().padStart(4,'0');
	    }
	  }
	  getMesQiItemQiItemCodeDropdownList(datas?.materialCode);
	  state.ruleForm.materialType=mesQiItemQiItemCodeDropdownList.value[0].code;
	  onChooseMaterialFinishApplyType("");
	  //查询供应商信息
	  let  res1 = await ScanSupper({
        packCode:matial[1],
      })
      let data1 = res1.data.result || {};
	  if(data1.supplierCode==undefined)
	  {
		state.ruleForm.supplierCode="";
        state.ruleForm.supplierName="";
		return ElMessage({
        message: `系统中不存在当前供应商信息`,
        type: "error",
      });
	  }
	  else{
		state.ruleForm.supplierCode = data1.supplierCode;
        state.ruleForm.supplierName = data1.supplierName;
	  }
    }

	//查询原材料检验类型
	const mesQiItemQiItemCodeDropdownList = ref<any>([]);
	const getMesQiItemQiItemCodeDropdownList = async (maintial:any) => {
		let list = await getMesQiItemQiItemCodeDropdowns({
        packCode:maintial,
         });
		mesQiItemQiItemCodeDropdownList.value = list.data.result ?? [];
	};


		//原材料有值后进行选择值
	  const onChooseMaterialFinishApplyType = async(data: any) => {
		detailList.value = [];
		let list = await getMesQiItemQiItemCode({
          packCode:state.ruleForm.productCode,packType:state.ruleForm.materialType,
         });
		 let datas = list.data.result ?? [];
		 detailList.value.push(...datas);
    };

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




