﻿<template>
	<div class="mesPackLog-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="packCode">
							<el-input v-model="state.ruleForm.packCode" placeholder="请输入载具编码" readonly="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="packName">
							<el-input v-model="state.ruleForm.packName" placeholder="请输入载具名称" readonly="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="packTypeCode">
							<el-select clearable filterable v-model="state.ruleForm.packTypeCode" placeholder="请选择载具类型" disabled="true">
								<el-option v-for="(item,index) in mesPackTypePackTypeCodeDropdownList" :key="index" :value="item.value" :label="item.label" />
								
							</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="factoryCode">
							<el-select clearable filterable v-model="state.ruleForm.factoryCode" placeholder="请选择所属工厂">
								<el-option v-for="(item,index) in mesFactoryFactoryCodeDropdownList" :key="index" :value="item.value" :label="item.label" />
								
							</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="maxNum" v-show="false">
							<el-input-number v-model="state.ruleForm.maxNum" placeholder="请输入最大载容量" readonly="true" 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-number v-model="state.ruleForm.num" placeholder="请输入当前装载量" readonly="true" 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="请输入当前生产工单号" readonly="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="batchNo">
							<el-input v-model="state.ruleForm.batchNo" placeholder="请输入当前批次号" readonly="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="processCode">
							<el-input v-model="state.ruleForm.processCode" placeholder="请输入当前工序" readonly="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="packStatus">
							<el-select clearable v-model="state.ruleForm.packStatus" placeholder="请选择载具状态">
								<el-option v-for="(item,index) in dl('MesPackStatusEnum')" :key="index" :value="Number(item.value)" :label="`${item.name} (${item.code}) [${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="MES编码" prop="materialCode">
							<el-input v-model="state.ruleForm.materialCode" placeholder="请输入当前MES编码" readonly="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="MES名称" prop="materialName">
							<el-input v-model="state.ruleForm.materialName" placeholder="请输入当前MES名称" readonly="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="quantity">
							<el-input-number v-model="state.ruleForm.quantity" min="0" :precision="0" readonly="true" @update:modelValue="handleChangequ" 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="flowquantity">
                            <el-input v-model="state.ruleForm.flowquantity" @input="handleInput" :value="state.ruleForm.flowquantity" placeholder="请扫描载具二维码" clearable @keyup.enter="scanquantity" ><!-- -->
                                <template #append>
                                    <el-icon @click="scanquantity" style="cursor: pointer" ><ele-FullScreen /></el-icon> <!-- -->
                                </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="repair"><!-- -->
							<el-input-number v-model="state.ruleForm.repair" min="0" :precision="0" @update:modelValue="handleChange"  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="flowrepair">
                            <el-input v-model="state.ruleForm.flowrepair" placeholder="请扫描载具二维码" clearable @keyup.enter="scanrepair" ><!-- -->
                                <template #append>
                                    <el-icon @click="scanrepair" ><ele-FullScreen /></el-icon> <!-- -->
                                </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="scrap">
							<el-input-number v-model="state.ruleForm.scrap" min="0" :precision="0" @update:modelValue="handleChangesc" 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="flowscrap" v-show="false"> 
                            <el-input v-model="state.ruleForm.flowscrap" placeholder="请扫描载具二维码"  clearable  ><!-- @keyup.enter="scanCode"-->
                                <template #append>
                                    <el-icon  ><ele-FullScreen /></el-icon> <!-- @click="scanCode"-->
                                </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="rank">
							<el-input-number v-model="state.ruleForm.rank" min="0" :precision="0"  @update:modelValue="handleChangera" 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="flowrank">
                            <el-input v-model="state.ruleForm.flowrank" placeholder="请扫描载具二维码" clearable   @keyup.enter="scanrank"><!---->
                                <template #append>
                                    <el-icon @click="scanrank" ><ele-FullScreen /></el-icon> <!-- -->
                                </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="investor">
							<el-input-number v-model="state.ruleForm.investor" min="0" :precision="0" @update:modelValue="handleChangein" 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="flowinvestor">
                            <el-input v-model="state.ruleForm.flowinvestor" placeholder="请扫描载具二维码" clearable  @keyup.enter="scaninvestor"><!-- -->
                                <template #append>
                                    <el-icon  @click="scaninvestor"><ele-FullScreen /></el-icon> <!-- -->
                                </template>
                            </el-input>
                        </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 {  detailMesPack } from "/@/api/mes/mesPack";
	import {  checkMesPackCheckRecord } from "/@/api/simple/mesPackCheckRecord";
	import { pageMesPack, deleteMesPack } from '/@/api/mes/mesPack';
	import { getMesPackTypePackTypeCodeDropdown } from '/@/api/mes/mesPack';
	import { getMesFactoryFactoryCodeDropdown } from '/@/api/mes/mesPack';
	import {Scan } from "/@/api/simple/mesPackTransferLog";
	import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
	import { getDictLabelByVal as dv } from '/@/utils/dict-utils';
  	import { formatDate } from '/@/utils/formatTime';
	import { SysEnumApi } from '/@/api-services/api';
	import { nextTick } from "vue";
import { multiInstanceIcon } from "@logicflow/extension";
	//父级传递来的参数
	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>({
		
	});

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

	});

	// 打开弹窗
	const openDialog = async (row: any) => {
		// state.ruleForm = JSON.parse(JSON.stringify(row));
		// 改用detail获取最新数据来编辑
		await getMesFactoryFactoryCodeDropdownList();
		getMesPackTypePackTypeCodeDropdownList();

		let rowData = JSON.parse(JSON.stringify(row));
		if (rowData.id)
		{
			state.ruleForm = (await detailMesPack(rowData.id)).data.result;
			if(rowData.productStatus=="主机厂" || rowData.productStatus=="待确认")
			{
				state.ruleForm.flowquantity=rowData.packCode;
			    state.ruleForm.quantity=rowData.num;
			    state.ruleForm.repair=0;
			    state.ruleForm.scrap=0;
			    state.ruleForm.rank=0;
			    state.ruleForm.investor=0;
			}
			else if(rowData.productStatus=="返修")
			{
				state.ruleForm.flowrepair=rowData.packCode;
			    state.ruleForm.quantity=0;
			    state.ruleForm.repair=rowData.num;
			    state.ruleForm.scrap=0;
			    state.ruleForm.rank=0;
			    state.ruleForm.investor=0;
			}
			else if(rowData.productStatus=="专卖")
			{
				state.ruleForm.flowrank=rowData.packCode;
			    state.ruleForm.quantity=0;
			    state.ruleForm.repair=0;
			    state.ruleForm.scrap=0;
			    state.ruleForm.rank=rowData.num;
			    state.ruleForm.investor=0;
			}
			else if(rowData.productStatus=="社投")
			{
				state.ruleForm.flowinvestor=rowData.packCode;
			    state.ruleForm.quantity=0;
			    state.ruleForm.repair=0;
			    state.ruleForm.scrap=0;
			    state.ruleForm.rank=0;
			    state.ruleForm.investor=rowData.num;
			}
		}
		else{
			state.ruleForm = rowData;
			if(mesFactoryFactoryCodeDropdownList.value){
				state.ruleForm.factoryCode = mesFactoryFactoryCodeDropdownList.value[0].value;
			}
		}
		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) => {
			console.log((parseFloat(state.ruleForm.quantity)+parseFloat(state.ruleForm.repair)+parseFloat(state.ruleForm.rank)+parseFloat(state.ruleForm.investor)+parseFloat(state.ruleForm.scrap)));
			
			if(state.ruleForm.flowquantity==""|| state.ruleForm.flowquantity==null)
		    {
		    	state.ruleForm.flowquantity=undefined;
		    }
			if(state.ruleForm.flowrepair==""|| state.ruleForm.flowrepair==null)
		    {
		    	state.ruleForm.flowrepair=undefined;
		    }
			if(state.ruleForm.flowinvestor==""|| state.ruleForm.flowinvestor==null)
		    {
		    	state.ruleForm.flowinvestor=undefined;
		    }
			if(state.ruleForm.flowrank==""|| state.ruleForm.flowrank==null)
		    {
		    	state.ruleForm.flowrank=undefined;
		    }
			if( state.ruleForm.num<(parseFloat(state.ruleForm.quantity)+parseFloat(state.ruleForm.repair)+parseFloat(state.ruleForm.rank)+parseFloat(state.ruleForm.investor)+parseFloat(state.ruleForm.scrap)))
			{
				return ElMessage({
				         message: `合格数+返修数+报废数+社投数+专卖数总数不可以大于载具数`,
				         type: "error",});
			}
			if(parseFloat(state.ruleForm.quantity)>0 && state.ruleForm.flowquantity==undefined)
			{
				return ElMessage({
				         message: `合格数不为0时合格载具不可以为空`,
				         type: "error",});
			}
			else if(parseFloat(state.ruleForm.quantity)==0 && state.ruleForm.flowquantity!=undefined)
			{
				return ElMessage({
				         message: `合格数为0时合格载具需要为空`,
				         type: "error",});
			}
			if(parseFloat(state.ruleForm.repair)>0 && state.ruleForm.flowrepair==undefined)
			{
				return ElMessage({
				         message: `返修数不为0时返修载具不可以为空`,
				         type: "error",});
			}
			else if(parseFloat(state.ruleForm.repair)==0 && state.ruleForm.flowrepair!=undefined)
			{
				return ElMessage({
				         message: `返修数为0时返修载具需要为空`,
				         type: "error",});
			}
			if(parseFloat(state.ruleForm.investor)>0 && state.ruleForm.flowinvestor==undefined)
			{
				return ElMessage({
				         message: `社投数不为0时社投载具不可以为空`,
				         type: "error",});
			}
			else if(parseFloat(state.ruleForm.investor)==0 && state.ruleForm.flowinvestor!=undefined)
			{
				return ElMessage({
				         message: `社投数为0时社投载具需要为空`,
				         type: "error",});
			}
			if(parseFloat(state.ruleForm.rank)>0 && state.ruleForm.flowrank==undefined)
			{
				return ElMessage({
				         message: `专卖数不为0时专卖载具不可以为空`,
				         type: "error",});
			}
			else if(parseFloat(state.ruleForm.rank)==0 && state.ruleForm.flowrank!=undefined)
			{
				return ElMessage({
				         message: `专卖数为0时专卖载具需要为空`,
				         type: "error",});
			}
			if (isValid) {
				let values = state.ruleForm;
				 var result=(await checkMesPackCheckRecord(values)).data.result;
					if(result=="添加成功")
					 closeDialog();
					else
					{
						ElMessage({
					message: `${result}`,
					type: "error",
				});
					}
			} else {
				ElMessage({
					message: `表单有${Object.keys(fields).length}处验证失败，请修改后再提交`,
					type: "error",
				});
			}
		});
	};

	const mesPackTypePackTypeCodeDropdownList = ref<any>([]); 
	const getMesPackTypePackTypeCodeDropdownList = async () => {
		let list = await getMesPackTypePackTypeCodeDropdown();
		mesPackTypePackTypeCodeDropdownList.value = list.data.result ?? [];
	};
	
	const mesFactoryFactoryCodeDropdownList = ref<any>([]); 
	const getMesFactoryFactoryCodeDropdownList = async () => {
		let list = await getMesFactoryFactoryCodeDropdown();
		mesFactoryFactoryCodeDropdownList.value = list.data.result ?? [];
	};

// 扫码合格载具
const scanquantity = async ()=>{
      
	  if(state.ruleForm.flowquantity==undefined)
	  {
		state.ruleForm.flowquantity=undefined;
		return ElMessage({
        message: `请先扫描载具二维码`,
        type: "error",
      });
	  }
      let  res = await Scan({
        packCode:state.ruleForm.flowquantity,
      })
      let data = res.data.result || {};
	   //判断是否是返修类型载具
	 if(data.productStatus!="主机厂" && data.productStatus!="空" && data.productStatus!=null)
     {
		if(data.productStatus!="待确认")
	    {
			state.ruleForm.flowquantity=undefined;
  	 return ElMessage({
       message: `当前载具不是主机厂状态载具，请重新扫描载具！`,
       type: "error",
     });
	    }
		
     }
	  //社投
	  if(data.packCode==state.ruleForm.flowinvestor && state.ruleForm.flowinvestor !=undefined)
     {
		state.ruleForm.flowquantity=undefined;
  	 return ElMessage({
       message: `合格载具不允许和社投载具相同！`,
       type: "error",
     });
     }
	 //专卖
	 if(data.packCode==state.ruleForm.flowrank  && state.ruleForm.flowrank !=undefined)
     {
		state.ruleForm.flowquantity=undefined;
  	 return ElMessage({
       message: `合格载具不允许和专卖载具相同！`,
       type: "error",
     });
     }
	 //返修
	 if(data.packCode==state.ruleForm.flowrepair  && state.ruleForm.flowrepair !=undefined)
     {
		state.ruleForm.flowquantity=undefined;
  	 return ElMessage({
       message: `合格载具不允许和返修载具相同！`,
       type: "error",
     });
     }
	 //载具不可以是使用中的状态
	 if(data.packStatus==1)
     {
		state.ruleForm.flowquantity=undefined;
  	   return ElMessage({
       message: `合格载具状态不可以是使用中的载具！`,
       type: "error",
     });
     }
	  //载具不可以是在库存中的载具
	  if(data.storeCode!=undefined && data.storeCode!=null && data.storeCode!="")
     {
		if(data.storeCode!="GW"){
		state.ruleForm.flowquantity=undefined;
  	   return ElMessage({
       message: `合格载具状态不可以是在库存中的载具！`,
       type: "error",
     });}
     }
	  if(data.materialCode!=undefined && data.materialCode!=null && data.materialCode!="")
	  {
		if(data.materialCode!=state.ruleForm.materialCode && data.batchNo!=state.ruleForm.batchNo && data.processCode!=state.ruleForm.processCode && data.produceWorkOrderNo!=state.ruleForm.produceWorkOrderNo)
	    {
			state.ruleForm.flowquantity=undefined;
		  return ElMessage({
          message: `不是同一批次，同一产品，同一工序，同一计划的不允许相互转移`,
          type: "error",
        });
	    }
	  }
	  //state.ruleForm.flowquantity=undefined;
	  return ElMessage({
      message: `扫描成功`,
      type: "success",
    });
    }

// 扫码返修载具
const scanrepair = async ()=>{
      
	  if(state.ruleForm.flowrepair==undefined)
	  {
		state.ruleForm.flowrepair==undefined
		return ElMessage({
        message: `请先扫描载具二维码`,
        type: "error",
      });
	  }
      let  res = await Scan({
        packCode:state.ruleForm.flowrepair,
      })
      let data = res.data.result || {};
	  //合格
     if(data.packCode==state.ruleForm.packCode && data.packCode==state.ruleForm.flowquantity)
     {
		state.ruleForm.flowrepair==undefined
  	 return ElMessage({
       message: `返修载具不允许和合格载具相同！`,
       type: "error",
     });
     }
	 debugger
	 //判断是否是返修类型载具
	 if(data.productStatus!="返修" && data.productStatus!="空" && data.productStatus!=null)
     {
	// 	state.ruleForm.flowrepair==undefined
  	//  return ElMessage({
    //    message: `当前载具不是返修状态载具，请扫描返修载具！`,
    //    type: "error",
    //  });
	 if(data.productStatus!="待确认")
         {
			if(data.packCode==state.ruleForm.packCode && state.ruleForm.flowquantity==undefined){}
			else{
				state.ruleForm.flowrepair==undefined
  	       return ElMessage({
           message: `当前载具不是返修状态载具，请重新扫描载具二维码！`,
           type: "error",
         });
			}
		}
     }
	  //社投
	  if(data.packCode==state.ruleForm.flowinvestor  && state.ruleForm.flowinvestor !=undefined)
     {

		
		state.ruleForm.flowrepair==undefined
  	 return ElMessage({
       message: `返修载具不允许和社投载具相同！`,
       type: "error",
     });
     }
	  //专卖
	  if(data.packCode==state.ruleForm.flowrank  && state.ruleForm.flowrank !=undefined)
     {
		state.ruleForm.flowrepair==undefined
  	 return ElMessage({
       message: `返修载具不允许和专卖载具相同！`,
       type: "error",
     });
     }
	  //载具不可以是使用中的状态
	  if(data.packStatus==1)
     {
		state.ruleForm.flowrepair=undefined;
  	   return ElMessage({
       message: `返修载具状态不可以是使用中的载具！`,
       type: "error",
     });
     }
	  //载具不可以是在库存中的载具
	  if(data.storeCode!=undefined && data.storeCode!=null && data.storeCode!="")
     {
		if(data.storeCode!="GW"){
		state.ruleForm.flowrepair=undefined;
  	   return ElMessage({
       message: `返修载具状态不可以是在库存中的载具！`,
       type: "error",
     });
	}
     }
	  if(data.materialCode!=undefined && data.materialCode!=null && data.materialCode!="")
	  {
		if(data.materialCode!=state.ruleForm.materialCode && data.batchNo!=state.ruleForm.batchNo && data.processCode!=state.ruleForm.processCode && data.produceWorkOrderNo!=state.ruleForm.produceWorkOrderNo)
	    {
			state.ruleForm.flowrepair==undefined
		  return ElMessage({
          message: `不是同一批次，同一产品，同一工序，同一计划的不允许相互转移`,
          type: "error",
        });
	    }
	  }
	  return ElMessage({
      message: `扫描成功`,
      type: "success",
    });
    }

// 扫码社投载具
const scaninvestor = async ()=>{
      
	  if(state.ruleForm.flowinvestor==undefined)
	  {
		state.ruleForm.flowinvestor==undefined
		return ElMessage({
        message: `请先扫描载具二维码！`,
        type: "error",
      });
	  }
      let  res = await Scan({
        packCode:state.ruleForm.flowinvestor,
      })
      let data = res.data.result || {};
	   //判断是否是返修类型载具
	 if(data.productStatus!="社投" && data.productStatus!="空" && data.productStatus!=null)
     {
	// 	state.ruleForm.flowinvestor==undefined
  	//  return ElMessage({
    //    message: `当前载具不是社投类型，请扫描社投载具！`,
    //    type: "error",
    //  });
	if(data.productStatus!="待确认")
         {
			if(data.packCode==state.ruleForm.packCode && state.ruleForm.flowquantity==undefined){}
			else{
				state.ruleForm.flowinvestor==undefined
  	       return ElMessage({
           message: `当前载具不是社投类型，请重新扫描载具二维码！`,
           type: "error",
         });
			}
		}
     }
     if(data.packCode==state.ruleForm.packCode && data.packCode==state.ruleForm.flowquantity)
     {
		state.ruleForm.flowinvestor==undefined
  	 return ElMessage({
       message: `社投载具不允许和合格载具相同！`,
       type: "error",
     });
     }
	 //专卖
	 if(data.packCode==state.ruleForm.flowrank  && state.ruleForm.flowrank !=undefined)
     {
		state.ruleForm.flowinvestor==undefined
  	 return ElMessage({
       message: `社投载具不允许和专卖载具相同！`,
       type: "error",
     });
     }
	 //返修
	 if(data.packCode==state.ruleForm.flowrepair  && state.ruleForm.flowrepair !=undefined)
     {
		state.ruleForm.flowinvestor==undefined
  	 return ElMessage({
       message: `社投载具不允许和返修载具相同！`,
       type: "error",
     });
     }
	  //载具不可以是使用中的状态
	  if(data.packStatus==1)
     {
		state.ruleForm.flowinvestor=undefined;
  	   return ElMessage({
       message: `社投载具状态不可以是使用中的载具！`,
       type: "error",
     });
     }
	  //载具不可以是在库存中的载具
	  if(data.storeCode!=undefined && data.storeCode!=null && data.storeCode!="")
     {
		if(data.storeCode!="GW"){
		state.ruleForm.flowinvestor=undefined;
  	   return ElMessage({
       message: `社投载具状态不可以是在库存中的载具！`,
       type: "error",
     });
	 }
     }
	  if(data.materialCode!=undefined  && data.materialCode!=null && data.materialCode!="")
	  {
		if(data.materialCode!=state.ruleForm.materialCode && data.batchNo!=state.ruleForm.batchNo && data.processCode!=state.ruleForm.processCode && data.produceWorkOrderNo!=state.ruleForm.produceWorkOrderNo)
	    {
			state.ruleForm.flowinvestor==undefined
		  return ElMessage({
          message: `不是同一批次，同一产品，同一工序，同一计划的不允许相互转移`,
          type: "error",
        });
	    }
	  }
	  return ElMessage({
      message: `扫描成功`,
      type: "success",
    });
    }

	// 专卖设投载具
const scanrank = async ()=>{
      
	  if(state.ruleForm.flowrank==undefined)
	  {
		state.ruleForm.flowrank==undefined
		return ElMessage({
        message: `请先扫描载具二维码！`,
        type: "error",
      });
	  }
      let  res = await Scan({
        packCode:state.ruleForm.flowrank,
      })
      let data = res.data.result || {};
	   //判断是否是返修类型载具
	 if(data.productStatus!="专卖" && data.productStatus!="空" && data.productStatus!=null)
     {
	// 	state.ruleForm.flowrank==undefined
  	//  return ElMessage({
    //    message: `当前载具不是专卖状态，请扫描状态载具！`,
    //    type: "error",
    //  });
	if(data.productStatus!="待确认")
         {
			if(data.packCode==state.ruleForm.packCode && state.ruleForm.flowquantity==undefined){}
			else{
				state.ruleForm.flowrank==undefined
  	       return ElMessage({
           message: `当前载具不是专卖状态，请重新扫描载具二维码！`,
           type: "error",
         });
			}
		}
     }
     if(data.packCode==state.ruleForm.packCode && data.packCode==state.ruleForm.flowquantity)
     {
		state.ruleForm.flowrank==undefined
  	 return ElMessage({
       message: `专卖载具不允许和合格载具相同！`,
       type: "error",
     });
     }
	   //社投
	   if(data.packCode==state.ruleForm.flowinvestor  && state.ruleForm.flowinvestor !=undefined)
     {
		state.ruleForm.flowrank==undefined
  	 return ElMessage({
       message: `专卖载具不允许和社投载具相同！`,
       type: "error",
     });
     }
	 //返修
	 if(data.packCode==state.ruleForm.flowrepair  && state.ruleForm.flowrepair !=undefined)
     {
		state.ruleForm.flowrank==undefined
  	 return ElMessage({
       message: `专卖载具不允许和返修载具相同！`,
       type: "error",
     });
     }
	 	  //载具不可以是使用中的状态
		   if(data.packStatus==1)
     {
		state.ruleForm.flowrank=undefined;
  	   return ElMessage({
       message: `社投载具状态不可以是使用中的载具！`,
       type: "error",
     });
     }
	  //载具不可以是在库存中的载具
	  if(data.storeCode!=undefined && data.storeCode!=null && data.storeCode!="")
     {
		if(data.storeCode!="GW"){
		state.ruleForm.flowrank=undefined;
  	   return ElMessage({
       message: `社投载具状态不可以是在库存中的载具！`,
       type: "error",
     });}
     }
	  if(data.materialCode!=undefined && data.materialCode!=null && data.materialCode!="")
	  {
		if(data.materialCode!=state.ruleForm.packCode && data.batchNo!=state.ruleForm.batchNo && data.processCode!=state.ruleForm.processCode && data.produceWorkOrderNo!=state.ruleForm.produceWorkOrderNo)
	    {
			state.ruleForm.materialCode==undefined
		  return ElMessage({
          message: `不是同一批次，同一产品，同一工序，同一计划的不允许相互转移`,
          type: "error",
        });
	    }
	  }
	  return ElMessage({
      message: `扫描成功`,
      type: "success",
    });
    }

	//合格数字为载具数时清空其他的值
	const handleChangequ= async (value:any)=> {
	  nextTick(() => {
		    if(state.ruleForm.quantity==state.ruleForm.num)
			{
				state.ruleForm.repair=0;
				state.ruleForm.scrap=0;
				state.ruleForm.rank=0;
				state.ruleForm.investor=0;
			}
        });
	}
 
	//返修数值发生变化
	const handleChange = async (value:any)=> {
	  nextTick(() => {
		if(value+state.ruleForm.investor+state.ruleForm.rank+state.ruleForm.scrap>state.ruleForm.num)
	    {
			value=0;state.ruleForm.repair=value;
				return ElMessage({
                  message: `返修+报废+专卖+社投总数不可以大于载具数`,
                  type: "error",
                });
	    }
		else{
			if(state.ruleForm.productStatus!="返修")
			{
				if(value+state.ruleForm.investor+state.ruleForm.rank+state.ruleForm.scrap>state.ruleForm.num)
			    {
				value=0;state.ruleForm.repair=value;
				state.ruleForm.quantity=state.ruleForm.num;
				handleChangequ(state.ruleForm.num);
				return ElMessage({
                  message: `返修+报废+专卖+社投总数不可以大于载具合格数`,
                  type: "error",
                });
			    }
			}
			else{
				if(value+state.ruleForm.investor+state.ruleForm.rank+state.ruleForm.scrap>state.ruleForm.num)
			    {
				value=0;state.ruleForm.repair=value;
				state.ruleForm.quantity=state.ruleForm.num;
				handleChangequ(state.ruleForm.num);
				return ElMessage({
                  message: `返修+报废+专卖+社投总数不可以大于载具合格数`,
                  type: "error",
                });
			    }
			}
		}
		    
		    state.ruleForm.quantity=(state.ruleForm.num-value-state.ruleForm.investor-state.ruleForm.rank-state.ruleForm.scrap);
			if(state.ruleForm.quantity==0)
			{
				state.ruleForm.flowquantity=undefined;
			}
        });
    }

	//报废数值发生变化
	const handleChangesc = async (value:any)=> {
	  nextTick(() => {
		if(value+state.ruleForm.investor+state.ruleForm.rank+state.ruleForm.repair>state.ruleForm.num)
	    {
			value=0;state.ruleForm.scrap=value;
				return ElMessage({
                  message: `返修+报废+专卖+社投总数不可以大于载具数`,
                  type: "error",
                });
	    }
		else{
			if(value+state.ruleForm.investor+state.ruleForm.rank+state.ruleForm.repair>state.ruleForm.num)
			{
				value=0;state.ruleForm.scrap=value;
				state.ruleForm.quantity=state.ruleForm.num;
				handleChangequ(state.ruleForm.num);
				return ElMessage({
                  message: `返修+报废+专卖+社投总数不可以大于载具合格数`,
                  type: "error",
                });
			}
		}
		    
			state.ruleForm.quantity=(state.ruleForm.num-value-state.ruleForm.investor-state.ruleForm.rank-state.ruleForm.repair);
			
        });
    }

	//专卖数值发生变化
	const handleChangera = async (value:any)=> {
	  nextTick(() => {
		if(value+state.ruleForm.investor+state.ruleForm.scrap+state.ruleForm.repair>state.ruleForm.num)
	    {
			value=0;state.ruleForm.rank=value;
				return ElMessage({
                  message: `返修+报废+专卖+社投总数不可以大于载具数`,
                  type: "error",
                });
	    }
		else{
			if(state.ruleForm.productStatus!="专卖")
			{
			  if(value+state.ruleForm.investor+state.ruleForm.scrap+state.ruleForm.repair>state.ruleForm.num)
			  {
				value=0;state.ruleForm.rank=value;
				state.ruleForm.quantity=state.ruleForm.num;
				handleChangequ(state.ruleForm.num);
				return ElMessage({
                  message: `返修+报废+专卖+社投总数不可以大于载具数`,
                  type: "error",
                });
			  }
			}
			else{
				if(value+state.ruleForm.investor+state.ruleForm.scrap+state.ruleForm.repair>state.ruleForm.num)
			   {
				value=0;state.ruleForm.rank=value;
				state.ruleForm.quantity=state.ruleForm.num;
				handleChangequ(state.ruleForm.num);
				return ElMessage({
                  message: `返修+报废+专卖+社投总数不可以大于载具数`,
                  type: "error",
                });
			   }
			}
		}
		state.ruleForm.quantity=(state.ruleForm.num-value-state.ruleForm.investor-state.ruleForm.scrap-state.ruleForm.repair);
			if(state.ruleForm.quantity==0)
			{
				state.ruleForm.flowquantity=undefined;
			}
        });
		
    }

	//社投数值发生变化
	const handleChangein = async (value:any)=> {
	  nextTick(() => {
		if(value+state.ruleForm.rank+state.ruleForm.scrap+state.ruleForm.repair>state.ruleForm.num)
	    {
			value=0;state.ruleForm.investor=value;
				return ElMessage({
                  message: `返修+报废+专卖+社投总数不可以大于载具数`,
                  type: "error",
                });
	    }
		else{
			if(state.ruleForm.productStatus!="社投")
	     {
			if(value+state.ruleForm.rank+state.ruleForm.scrap+state.ruleForm.repair>state.ruleForm.num)
			{
				value=0;state.ruleForm.investor=value;
				state.ruleForm.quantity=state.ruleForm.num;
				handleChangequ(state.ruleForm.num);
				return ElMessage({
                  message: `返修+报废+专卖+社投总数不可以大于载具数`,
                  type: "error",
                });
			}
	     }
		else{
			if(value+state.ruleForm.rank+state.ruleForm.scrap+state.ruleForm.repair>state.ruleForm.num)
			{
				value=0;state.ruleForm.investor=value;
				state.ruleForm.quantity=state.ruleForm.num;
				handleChangequ(state.ruleForm.num);
				console.log();
				return ElMessage({
                  message: `返修+报废+专卖+社投总数不可以大于载具数`,
                  type: "error",
                });
			}
		}
		}
		
		state.ruleForm.quantity=(state.ruleForm.num-value-state.ruleForm.rank-state.ruleForm.scrap-state.ruleForm.repair);
		if(state.ruleForm.quantity==0)
			{
				state.ruleForm.flowquantity=undefined;
			}
        });
    }

	const handleInput = async (value:any)=> {
		state.ruleForm.flowquantity = value;
	}
	//将属性或者函数暴露给父组件
	defineExpose({ openDialog });
</script>




