﻿<template>
	<div class="mescontrol-container">
		<div class="mescontrol-total">
			<!-- <div style="height: 30px; padding: 10px 10px 0px 10px; color: #ffffff; display: flex; flex-direction: column; justify-content: space-between">
				<div style="height: 70%;margin-left: 45%; display: flex; justify-content: space-between; align-items: center">
					<div>生产日期：{{ titleform.scheduleTime }}</div> 
					<div style="font-size: 25px">无工单报工</div>
					<div>作业人员：{{ workUser.account }}</div> 
				</div>
			</div> -->
			<div style="height: calc(100% - 50px); margin: 10px; background: #ffffff">
				<div class="elbutton" style="display: flex; justify-content: space-between; padding: 5; height: 1%">
					<div style="width: 42%; display: flex; justify-content: space-between">
						
					</div>
					<div style="width: 45%; display: flex; justify-content: space-between">
						
					</div>
				</div>
				<div style="padding: 10px; height: 60%; color: var(--el-color-primary)">
					<el-row style="height: 100%">
						<el-col :span="12" class="elcol">
							<div style="display: flex; height: 10%">
								<span style="font-size: 82%; font-weight: bold">工位编码：</span>
								<span style="width: 85%">
								    <el-input v-model=" state.ruleForm.storeSiteCode" placeholder=" " clearable @keyup.enter.stop="onScanAccount" style="width: 40%">
									  <template #append>
									     <el-icon class="el-input__icon" style="cursor: pointer" @click="onScanAccount">
										     <ele-FullScreen />
									     </el-icon>
									  </template>
									</el-input>{{ state.ruleForm.store }}
								</span>
							</div>
							<div style="display: flex; height: 10%">
								<span style="font-size: 80%; font-weight: bold;">报工人：</span>
								<span style="width: 70%">
								    <el-input v-model=" state.ruleForm.peopleCode" placeholder=" " clearable @keyup.enter.stop="onScanAccounts" style="width: 60%">
									  <template #append>
									     <el-icon class="el-input__icon" style="cursor: pointer" @click="onScanAccounts">
										     <ele-FullScreen />
									     </el-icon>
									  </template>
									</el-input>{{ state.ruleForm.people }}
								</span>
								<span style="font-size: 80%; font-weight: bold;margin-left: 27px;">
									<span >是否末序报工：</span>
						            <el-switch  v-model="state.ruleForm.isOrderPlan" active-text="是" inactive-text="否" />
								</span>
							</div>
							<div  class="processforms"  >
					            <mesPackWork v-if="shouldRender" :key="componentKey" :id="state.ruleForm.store" @value-changed="handleValueChanged" ></mesPackWork>			
							</div>
							
						</el-col>
						<el-col :span="6" class="elcol">
							<div style="display: flex; height: 10%">
								<span style="font-size: 80%; font-weight: bold">消耗载具：</span>
								<div style="width: 100%">
									<el-input  v-model="state.ruleForm.isPackCodeflow" placeholder="请扫描消耗载具" clearable @keyup.enter.stop="onScanAccountIs" style="width: 90%">
									  <template #append>
									     <el-icon class="el-input__icon" style="cursor: pointer" @click="onScanAccountIs">
										     <ele-FullScreen />
									     </el-icon>
									  </template>
									</el-input>
								</div>
								<div style="width: 10%; height: 10%" >
									<el-button type="primary" style="margin-left: 1px;font-size: 100%;"  @click="scanShow" >⇋</el-button>
								</div>
							</div>
							
							<div class="processform" style="display: flex; position: relative;">
								<div style="width: 80%; height: 100%;">
									<el-form :model="processform" label-width="50%" style="flex-wrap: wrap;">
										<el-form-item label="载具编码：">{{ state.ruleForm.isPackCode }}</el-form-item>
										<el-form-item label="载具名称：">{{ state.ruleForm.isPackName }}</el-form-item>
										<el-form-item label="MES编码：">{{ state.ruleForm.isMaterialCode }}</el-form-item>
										<el-form-item label="MES名称：">{{ state.ruleForm.isMaterialName }}</el-form-item>
										<el-form-item label="生产批：">{{ state.ruleForm.isBatchNo  }}</el-form-item>
										<el-form-item label="工位编码：">{{ (state.ruleForm.isStoreSiteCode)  }}</el-form-item>
										<!-- <el-form-item label="工位名称：">{{ (state.ruleForm.isStoreSiteName)  }}</el-form-item> -->
										<el-form-item label="装载数量：">{{state.ruleForm.isNum || 0}}</el-form-item>
										<el-form-item label="报工数：" style="width: 100%;">
											<el-input v-model="state.ruleForm.actualNumber" @input="handleInput1(state.ruleForm.actualNumber)"  placeholder="请输入报工数"  />
										</el-form-item>
										<el-form-item>
											<el-button type="primary"  @click="scanShowCleans" style="margin-left: 60%;"> 出站</el-button><!--style="margin-left: 100px;"-->
										</el-form-item>
									</el-form>
								</div>
								<div style="width: 50%; height: 50%; position: absolute; right: 0; bottom: 0">
									<instrument :dataArr="(processform.finishNum || 0) / (processform.planNum || 0) || 0"></instrument>
								</div>
							</div>
						</el-col>
						<el-col :span="6" class="elcol">
							<div style="display: flex; height: 10%">
								<span style="font-size: 80%; font-weight: bold">装载载具：</span>
								<div style="width: 100%">
									<el-input  v-model="state.ruleForm.packCodeFlow" placeholder="请扫描装载载具" clearable @keyup.enter.stop="onScanAccountI" style="width: 100%">
									  <template #append>
									     <el-icon class="el-input__icon" style="cursor: pointer" @click="onScanAccountI">
										     <ele-FullScreen />
									     </el-icon>
									  </template>
									</el-input>
								</div>
								<div style="width: 20%; height: 10%" >
									<el-button type="primary" style="margin-left: 15px;" @click="reportwork" >报工</el-button><!--@click="scanShow" size="large" -->
								</div>
							</div>
							
							<div class="processform" style="display: flex; position: relative">
								<div style="width: 80%; height: 100%">
									<el-form :model="processform" label-width="45%">
										<el-form-item label="载具编码：">{{ state.ruleForm.packCode }}</el-form-item>
										<el-form-item label="载具名称：">{{ state.ruleForm.packName }}</el-form-item>
										<el-form-item label="MES编码：">{{ state.ruleForm.materialCode }}</el-form-item>
										<el-form-item label="MES名称：">{{ state.ruleForm.materialName }}</el-form-item>
										<el-form-item label="生产批：">{{ state.ruleForm.batchNo  }}</el-form-item>
										<el-form-item label="工位编码：">{{ (state.ruleForm.storeSiteCodes)  }}</el-form-item>
										<!-- <el-form-item label="工位名称：">{{ (state.ruleForm.storeSiteNames)  }}</el-form-item> -->
										<el-form-item label="装载数量：">{{state.ruleForm.num}}</el-form-item>
										<el-form-item>
											<el-button type="primary" style="margin-left: 60%;" @click="scanShowClean" >出站</el-button>
										</el-form-item>
									</el-form>
								</div>
								<!-- <div style="width: 50%; height: 50%; position: absolute; right: 0; bottom: 0">
									<instrument :dataArr="(processform.finishNum || 0) / (processform.planNum || 0) || 0"></instrument>
								</div> -->
							</div>
						</el-col>
					
					</el-row>
				</div>
				<div style="height: 38%; padding: 12px; color: var(--el-color-primary)" v-if="shoulipad">
					<div style="height: 22px; font-size: 100%; font-weight: bold; padding-left: 10px">工站出入记录</div>
					<el-row style="border: 1px solid #cccccc; padding: 10px; height: calc(100% - 22px)" :gutter="10">
						<el-col :span="12" style="height: 100%" class="packlist">
							<div style="margin-bottom: 10px; height: 25px">入站记录</div>
							<el-table ref="packTableRef" :data="packTableData || []" style="width: 100%;height: 80%;"  border="">
								<!-- <el-table-column type="selection" width="30" /> -->
								<el-table-column type="index" label="序号" width="50" align="center" />
								<el-table-column prop="packCode" label="载具编码" show-overflow-tooltip="" />
								<el-table-column prop="packName" label="载具名称" show-overflow-tooltip="" />
								<el-table-column prop="quantity" label="入站数量" show-overflow-tooltip="" />
								<el-table-column prop="materialCode" label="入站存货编码" width="140"></el-table-column>
								<el-table-column prop="materialName" label="入站存货名称" width="140"></el-table-column>
								<el-table-column prop="batchNo" label="入站批次号" width="140"></el-table-column>
							</el-table>
						</el-col>
						<el-col :span="12" style="height: 100%">
							<div style="margin-bottom: 10px; height: 25px">出站记录</div>
							<el-table ref="packTableRef" :data="packRecordData || []" style="width: 100%;height: 80%;" border="">
								<!-- <el-table-column type="selection" width="30" /> -->
								<el-table-column type="index" label="序号" width="50" align="center" />
								<el-table-column prop="packCode" label="载具编码" show-overflow-tooltip="" />
								<el-table-column prop="packName" label="载具名称" show-overflow-tooltip="" />
								<el-table-column prop="quantity" label="出站数量" show-overflow-tooltip="" />
								<el-table-column prop="materialCode" label="出站存货编码" width="140"></el-table-column>
								<el-table-column prop="materialName" label="出站存货名称" width="140"></el-table-column>
								<el-table-column prop="batchNo" label="出站批次号" width="140"></el-table-column>
							</el-table>
						</el-col>
					</el-row>
				</div>
			</div>
		</div>
	</div>
</template>
<script lang="ts" setup="" name="mescontrol">
import { onMounted, reactive, ref,nextTick } from 'vue';
import 'echarts-wordcloud';
import { ElMessageBox, ElMessage } from 'element-plus';
import mesPackWork from '/@/views/simple/mesPackWork/index.vue';
import { getPersonByAccount } from '/@/api/mes/mesControlBoard';
import { Scan } from "/@/api/simple/mesPackTransferLog";
import { workshopstation,getinsout,transferPack ,addBatchSaveHead} from "/@/api/simple/mesWorkOrderMissing";
import { isFloat } from 'xe-utils';
import { stat } from 'fs';
const shouldRender= ref(true);//默认为显示子窗体
const componentKey=ref(0);//key值多次渲染子页面
const processform = ref<any>({});//字体中绑定值，暂时不用，留存
const packTableData = ref([]);//入站记录
const packRecordData= ref([]);//出站记录
const detiallistin=ref([]);//消耗载具记录
const detiallistout=ref([]);//装载载具记录
const shoulipad= ref(true);//判断是否显示，如果分辨率是1150*660则不显示
const shoulipads= ref(true);//判断是否显示，如果分辨率是1150*660则不显示
// 页面初始化
onMounted(() => {
var screenWidth = window.innerWidth;
var screenHeight = window.innerHeight;
const values=screenWidth+"*"+screenHeight
console.log("Screen Width: " + screenWidth + ", Screen Height: " + screenHeight);
if(values=="1150*660")
{
	shoulipad.value=false;
	shoulipads.value=false;
}
else{
	shoulipads.value=true;
}
});

// 变量
const state = reactive({
  ruleForm: {} as any,
	visible: false,
	title: '',
});

//子级向父级传递来的参数
var props = defineProps({
	packId: {
    type: String,
    default: "",
    },
    packtTpeId: {
    type: String,
    default: "",
    },
});

//获取工站信息
const onScanAccount = async () => {
	// const val=ref();
    //     if(state.ruleForm.store!=undefined)
    //     {
    //         let index = state.ruleForm.store.indexOf('/'); // 找到 '-' 的位置
			
    //         if (index !== -1) { // 如果找到了 '-'
    //           let result = state.ruleForm.store.substring(0, index); // 截取 '-' 前面的所有字符
    //           // 或者使用 slice 方法
    //           // let result = str.slice(0, index);
    //           val.value=result;
			  
    //         } else {
    //     		val.value=state.ruleForm.store;
				
    //         }
    //     }
    //     else{
    //     	val.value=state.ruleForm.storeSiteCode;
    //  }
	if(state.ruleForm.storeSiteCode==undefined)
    {
    	if(state.ruleForm.store!=undefined)
	    {
	    	let index = state.ruleForm.store.indexOf('/'); // 找到 '-' 的位置
			if (index !== -1) { // 如果找到了 '-'
			state.ruleForm.storeSiteCode= state.ruleForm.store.substring(0, index); // 截取 '-' 前面的所有字符
		    }
	    }
    }
	var res = await workshopstation({ packCode: state.ruleForm.storeSiteCode });
	let data = res.data.result || {};
	if(data.code=="" || data.code==null)
	{
		data.code=undefined;
	}
	if(data.code!=undefined)
	{
		state.ruleForm.store = data.code+"/"+data.name;
	    componentKey.value=componentKey.value+1;
	    //入站记录
	    var res = await getinsout({ store: state.ruleForm.storeSiteCode,types:'入库' });
	    let datain = res.data.result || {};
	    packTableData.value=[];
	    packTableData.value.push(...datain);
	    //出站记录
	    var ress = await getinsout({ store: state.ruleForm.storeSiteCode,types:'出库' });
	    let datas = ress.data.result || {};
	    packRecordData.value=[];
	    packRecordData.value.push(...datas);
	    ElMessage.success('扫描成功');
	}
	else{
		ElMessage.error('当前工位不存在');
	}
	state.ruleForm.storeSiteCode=undefined;
};

//获取人员信息
const onScanAccounts = async () => {
	var res = await getPersonByAccount({ account: state.ruleForm.peopleCode });
	let data = res.data.result || {};
	state.ruleForm.people = data.account+"-"+data.realName;
	state.ruleForm.peopleCode=undefined;
	ElMessage.success('扫描成功');
};

//获取消耗载具信息
const onScanAccountIs=async () => {
	if(state.ruleForm.store==undefined)
     {
  	   return ElMessage({
       message: `请先扫描工位！`,
       type: "error",
     });
     }if(state.ruleForm.people==undefined)
     {
  	   return ElMessage({
       message: `请先扫描报工人！`,
       type: "error",
     });
     }
	 
	let  res = await Scan({
        packCode:state.ruleForm.isPackCodeflow,
      })
    let data = res.data.result || {};
	if(data.packCode==state.ruleForm.packCode)
	    {
  	         return ElMessage({
             message: `当前载具已经是装载载具！`,
             type: "error",
          });
	    }
	const results=ref(false);
	const val=ref();
	if(data.storeCode=="" || data.storeCode==null)
	{
		data.storeCode=undefined;
	}
	if(data.storeCode!="GW" && data.storeCode!=undefined)
     {
		state.ruleForm.isPackCodeflow=undefined;
  	   return ElMessage({
       message: `当前载具在半成品仓库，请先出库！`,
       type: "error",
     });
     }
	if(data.materialCode=="" || data.materialCode==null)
	{
		data.materialCode=undefined;
	}
	if(data.materialCode==undefined)
     {
		state.ruleForm.isPackCodeflow=undefined;
  	   return ElMessage({
       message: `消耗载具不可以是空载具！`,
       type: "error",
     });
     }
	 else{
		if(data.packStatus==1)
     {
		state.ruleForm.isPackCodeflow=undefined;
  	   return ElMessage({
       message: `载具状态不可以是使用中的载具！`,
       type: "error",
     });
     }
		if(state.ruleForm.packCode!=undefined && state.ruleForm.packCode!=null && state.ruleForm.packCode!="")
	    {
			if(state.ruleForm.materialCode!=undefined && state.ruleForm.materialCode!=null && state.ruleForm.materialCode!="")
		   {
			if(data.materialCode!=state.ruleForm.materialCode && data.batchNo!=state.ruleForm.batchNo)
	          {
				state.ruleForm.isPackCodeflow=undefined;
				detiallistin.value=[];
                state.ruleForm.isPackCode=undefined;
                state.ruleForm.isPackName=undefined;
                state.ruleForm.isMaterialCode=undefined;
                state.ruleForm.isMaterialName=undefined;
                state.ruleForm.isBatchNo=undefined;
                state.ruleForm.isStoreSiteCode=undefined;
	             state.ruleForm.isStoreSiteName=undefined;
                state.ruleForm.isNum=undefined;
                state.ruleForm.actualNumber=undefined;
	             state.ruleForm.isPackCodeflow=undefined;
		         return ElMessage({
                message: `当前扫描的消耗载具与装载载具不是同一批次，同一产品！`,
                type: "error",
              });
	          }
		   }
	    }

		if(data.storeSiteCode=="" || data.storeSiteCode==null)
	    {
			data.storeSiteCode=undefined;
		}
		
        if(state.ruleForm.store!=undefined)
        {
            let index = state.ruleForm.store.indexOf('/'); // 找到 '-' 的位置
			
            if (index !== -1) { // 如果找到了 '-'
              let result = state.ruleForm.store.substring(0, index); // 截取 '-' 前面的所有字符
              // 或者使用 slice 方法
              // let result = str.slice(0, index);
              val.value=result;
			  
            } else {
        		val.value=state.ruleForm.store;
				
            }
        }
        else{
        	val.value=undefined;
        }
		
		if(data.storeSiteCode!=undefined)
	    {
			
	     	if(data.storeSiteCode!=val.value)
	         {  
			
				 ElMessageBox.confirm('当前扫描的消耗载具属于'+data.storeSiteCode+'工位载具，是否转到当前工位?', '警告', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                   }).then(async () => {
					  var result=(await transferPack({id:data.id,store:state.ruleForm.store,types:2,people:state.ruleForm.people})).data.result;
					  debugger
			     	if(result=="操作成功")
			     	 {
						results.value=true;
						if(results.value==true)
	                    {
	                    	detiallistin.value=[];
	                        detiallistin.value.push(data);
                            state.ruleForm.isPackCode=data.packCode;
                            state.ruleForm.isPackName=data.packName;
                            state.ruleForm.isMaterialCode=data.materialCode;
                            state.ruleForm.isMaterialName=data.materialName;
                            state.ruleForm.isBatchNo=data.batchNo;
                            state.ruleForm.isStoreSiteCode=val.value;
	                    	let lastIndex  = state.ruleForm.store.lastIndexOf('/'); // 找到 '-' 的位置
                                if (lastIndex  !== -1) { // 如果找到了 '-'
                                  let result = state.ruleForm.store.substring(lastIndex + 1); // 截取 '-' 前面的所有字符
	                    		  state.ruleForm.isStoreSiteName=result;
                                }
                            
                            state.ruleForm.isNum=data.num;
                            state.ruleForm.actualNumber=data.num;
	                        state.ruleForm.isPackCodeflow=undefined;
	                        onScanAccount();
	                    }
					 }
			     	else
			     	{
						results.value=false;
			     		return ElMessage({
			     	message: `${result}`,
			     	type: "error",
			     });
				}
                  }).catch((error) => {
					results.value=false;
					return ElMessage({
			     	message: `取消操作`,
			     	type: "error",
			         });
                   });
	         }  else{results.value=true}
	     }else
		 {
		if(data.storeSiteCode==undefined)
		 {
			var result=(await transferPack({id:data.id,store:state.ruleForm.store,types:0,people:state.ruleForm.people})).data.result;
			     	if(result=="操作成功")
			     	 {
						results.value=true;
					 }
			     	else
			     	{
			     		ElMessage({
			     	message: `${result}`,
			     	type: "error",
			     });
				}
		 }
		 }
	 }
	if(results.value==true)
	{
		detiallistin.value=[];
	    detiallistin.value.push(data);
        state.ruleForm.isPackCode=data.packCode;
        state.ruleForm.isPackName=data.packName;
        state.ruleForm.isMaterialCode=data.materialCode;
        state.ruleForm.isMaterialName=data.materialName;
        state.ruleForm.isBatchNo=data.batchNo;
        state.ruleForm.isStoreSiteCode=val.value;
		let lastIndex  = state.ruleForm.store.lastIndexOf('/'); // 找到 '-' 的位置
            if (lastIndex  !== -1) { // 如果找到了 '-'
              let result = state.ruleForm.store.substring(lastIndex + 1); // 截取 '-' 前面的所有字符
			  state.ruleForm.isStoreSiteName=result;
            }
        
        state.ruleForm.isNum=data.num;
        state.ruleForm.actualNumber=data.num;
	    state.ruleForm.isPackCodeflow=undefined;
	    onScanAccount();
	}
	 
};

//获取装载载具信息
const onScanAccountI=async () => {
	if(state.ruleForm.store==undefined)
     {
  	   return ElMessage({
       message: `请先扫描工位！`,
       type: "error",
     });
     }if(state.ruleForm.people==undefined)
     {
  	   return ElMessage({
       message: `请先扫描报工人！`,
       type: "error",
     });
     }
	let  res = await Scan({
        packCode:state.ruleForm.packCodeFlow,
      })
    let data = res.data.result || {};
	if(data.packCode==state.ruleForm.isPackCode )
	    {
  	         return ElMessage({
             message: `当前载具已经是消耗载具！`,
             type: "error",
          });
	    }
	const val=ref();
	if(state.ruleForm.store!=undefined)
                  {
                      let index = state.ruleForm.store.indexOf('/'); // 找到 '-' 的位置
                  
                      if (index !== -1) { // 如果找到了 '-'
                        let result = state.ruleForm.store.substring(0, index); // 截取 '-' 前面的所有字符
                        // 或者使用 slice 方法
                        // let result = str.slice(0, index);
                        val.value=result;
                      } else {
                  		val.value=state.ruleForm.store;
                      }
                  }
                  else{
                  	val.value=undefined;
                  }
	const results=ref(false);
	
	if(data.storeCode=="" || data.storeCode==null)
	{
		data.storeCode=undefined;
	}
	if(data.storeCode!="GW" && data.storeCode!=undefined)
     {
		state.ruleForm.packCodeFlow=undefined;
  	   return ElMessage({
       message: `当前载具在半成品仓库，请先出库！`,
       type: "error",
     });
     }
	if(data.materialCode=="" || data.materialCode==null)
	{
		data.materialCode=undefined;
	}
	// if(data.packCode== state.ruleForm.packCode)
	// {
	// 	return ElMessage({
    //             message: `当前扫描的装载载具是同一载具，不需要进行二次扫描！`,
    //             type: "error",
    //           });
	// }
	if(data.materialCode==undefined && data.storeSiteCode==undefined)
	{
		var result=(await transferPack({id:data.id,store:state.ruleForm.store,types:0,people:state.ruleForm.people})).data.result;
			     	if(result=="操作成功")
			     	 {
						results.value=true;
					 }
			     	else
			     	{
			     		ElMessage({
			     	message: `${result}`,
			     	type: "error",
			     });
				}
		results.value=true;
	}
	else{
		if(data.packStatus==1)
     {
		state.ruleForm.packCodeFlow=undefined;
  	   return ElMessage({
       message: `载具状态不可以是使用中的载具！`,
       type: "error",
     });
     }
		if(state.ruleForm.packCode!=undefined && state.ruleForm.packCode!=null && state.ruleForm.packCode!="")
	    {
			if(state.ruleForm.materialCode!=undefined && state.ruleForm.materialCode!=null && state.ruleForm.materialCode!="")
		   {
			if(data.materialCode!=state.ruleForm.materialCode && data.batchNo!=state.ruleForm.batchNo)
	          {
				state.ruleForm.packCodeflow=undefined;
				detiallistout.value=[];
	            state.ruleForm.packCode= undefined;
                state.ruleForm.packName=undefined;
                state.ruleForm.materialCode=undefined;
                state.ruleForm.materialName=undefined;
                state.ruleForm.batchNo=undefined;
                state.ruleForm.num=undefined;
	            state.ruleForm.storeSiteCodes=undefined;
	            state.ruleForm.storeSiteNames=undefined;
		         return ElMessage({
                message: `当前扫描的消耗载具与装载载具不是同一批次，同一产品！`,
                type: "error",
              });
	          }
		   }
	    }

		if(data.storeSiteCode=="" || data.storeSiteCode==null)
	    {
			data.storeSiteCode=undefined;
		}
		
                  
			if(data.storeSiteCode!=undefined)
	         {
			
	     	if(data.storeSiteCode!=val.value)
	         {  
			
				 ElMessageBox.confirm('当前扫描的消耗载具属于'+data.storeSiteCode+'工位载具，是否转到当前工位?', '警告', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                   }).then(async () => {
					  var result=(await transferPack({id:data.id,store:state.ruleForm.store,types:2,people:state.ruleForm.people})).data.result;
			     	if(result=="操作成功")
			     	 {
						results.value=true;
						if(results.value==true)
	                    {
	                   	detiallistout.value=[];
                          detiallistout.value.push(data);
	                      state.ruleForm.packCode=data.packCode;
                          state.ruleForm.packName=data.packName;
                          state.ruleForm.materialCode=data.materialCode;
                          state.ruleForm.materialName=data.materialName;
                          state.ruleForm.batchNo=data.batchNo;
                          state.ruleForm.storeSiteCodes=val.value;
                          let lastIndex  = state.ruleForm.store.lastIndexOf('/'); // 找到 '-' 的位置
                               if (lastIndex  !== -1) { // 如果找到了 '-'
	                   		state.ruleForm.storeSiteNames = state.ruleForm.store.substring(lastIndex + 1); // 截取 '-' 前面的所有字符
	                   		 
                               }
                          state.ruleForm.num=data.num;
	                      state.ruleForm.packCodeFlow=undefined;
	                      onScanAccount();
	                    }
					 }
			     	else
			     	{
						results.value=false;
			     		ElMessage({
			     	message: `${result}`,
			     	type: "error",
			     });
				}
                  }).catch((error) => {
					results.value=false;
					return ElMessage({
			     	message: `取消操作`,
			     	type: "error",
			         });
                   });
	         }  else{results.value=true;}
	     }else
		 {
			if(data.storeSiteCode==undefined)
		 {
			var result=(await transferPack({id:data.id,store:state.ruleForm.store,types:0,people:state.ruleForm.people})).data.result;
			     	if(result=="操作成功")
			     	 {
						results.value=true;
					 }
			     	else
			     	{
			     		ElMessage({
			     	message: `${result}`,
			     	type: "error",
			     });
				}
		 }
		 }
	}
	 if(results.value==true)
	 {
		detiallistout.value=[];
       detiallistout.value.push(data);
	   state.ruleForm.packCode=data.packCode;
       state.ruleForm.packName=data.packName;
       state.ruleForm.materialCode=data.materialCode;
       state.ruleForm.materialName=data.materialName;
       state.ruleForm.batchNo=data.batchNo;
       state.ruleForm.storeSiteCodes=val.value;
       let lastIndex  = state.ruleForm.store.lastIndexOf('/'); // 找到 '-' 的位置
            if (lastIndex  !== -1) { // 如果找到了 '-'
			state.ruleForm.storeSiteNames = state.ruleForm.store.substring(lastIndex + 1); // 截取 '-' 前面的所有字符
			 
            }
       state.ruleForm.num=data.num;
	   state.ruleForm.packCodeFlow=undefined;
	   onScanAccount();
	 }
	
	
};

//消耗载具和装载载具互换位置
const scanShow=async()=>{
	if(state.ruleForm.num==0||state.ruleForm.num==undefined)
    {
  	   return ElMessage({
       message: `装载载具为0时或者为空时不可以进行互换位置！`,
       type: "error",
     });
    }
	if(state.ruleForm.isPackCode==undefined)
    {
  	   return ElMessage({
       message: `消耗载具为空不可以进行互换！`,
       type: "error",
     });
    }
    //先用一个值接过消耗载具中的信息
	const listin=ref([]);//消耗载具记录
	 listin.value=detiallistin.value;
	 state.ruleForm.packCode= listin.value[0].packCode;
     state.ruleForm.packName=listin.value[0].packName;
     state.ruleForm.materialCode=listin.value[0].materialCode;
     state.ruleForm.materialName=listin.value[0].materialName;
     state.ruleForm.batchNo=listin.value[0].batchNo;
     state.ruleForm.num=listin.value[0].num;
	//用另外一个值接过装载载具中的信息
	const listout=ref([]);//装载载具记录
	listout.value= detiallistout.value;
	 state.ruleForm.isPackCode=listout.value[0].packCode;
     state.ruleForm.isPackName=listout.value[0].packName;
     state.ruleForm.isMaterialCode=listout.value[0].materialCode;
     state.ruleForm.isMaterialName=listout.value[0].materialName;
     state.ruleForm.isBatchNo=listout.value[0].batchNo;
     state.ruleForm.isNum=listout.value[0].num;
     state.ruleForm.actualNumber=listout.value[0].num;

	 detiallistin.value=listout.value;
	 detiallistout.value=listin.value;
	 ElMessage.success('互换成功');
}

//清空消耗载具/也是出站
const scanShowCleans=async()=>
{
	if(state.ruleForm.isPackCode==undefined)
	 {
  	       return ElMessage({
           message: `当前消耗载具为空！`,
           type: "error",
        });
	 }
	 if(state.ruleForm.people==undefined)
     {
  	   return ElMessage({
       message: `请先扫描报工人！`,
       type: "error",
     });
     }
	const val=ref();
    if(state.ruleForm.store!=undefined)
    {
        let index = state.ruleForm.store.indexOf('/'); // 找到 '-' 的位置
    
        if (index !== -1) { // 如果找到了 '-'
          let result = state.ruleForm.store.substring(0, index); // 截取 '-' 前面的所有字符
          // 或者使用 slice 方法
          // let result = str.slice(0, index);
          val.value=result;
        } else {
    		val.value=state.ruleForm.store;
        }
    }
    else{
    	val.value=undefined;
    }
     var result=(await transferPack({id:detiallistin.value[0].id,store:state.ruleForm.store,types:1,people:state.ruleForm.people})).data.result;
     	if(result=="操作成功")
     	 {
			detiallistin.value=[];
            state.ruleForm.isPackCode=undefined;
            state.ruleForm.isPackName=undefined;
            state.ruleForm.isMaterialCode=undefined;
            state.ruleForm.isMaterialName=undefined;
            state.ruleForm.isBatchNo=undefined;
            state.ruleForm.isStoreSiteCode=undefined;
	         state.ruleForm.isStoreSiteName=undefined;
            state.ruleForm.isNum=undefined;
            state.ruleForm.actualNumber=undefined;
	         state.ruleForm.isPackCodeflow=undefined;
	          packRecordData.value=[];
	          onScanAccount();
		 }
     	else
     	{
     		ElMessage({
     	message: `${result}`,
     	type: "error",
     });
    } 
	
}

//清空装载载具/也是出站
const scanShowClean=async()=>
{
	if(state.ruleForm.packCode==undefined)
	 {
  	       return ElMessage({
           message: `当前装载载具为空！`,
           type: "error",
        });
	    
	 }if(state.ruleForm.people==undefined)
     {
  	   return ElMessage({
       message: `请先扫描报工人！`,
       type: "error",
     });
     }
	const val=ref();
    if(state.ruleForm.store!=undefined)
    {
        let index = state.ruleForm.store.indexOf('/'); // 找到 '-' 的位置
    
        if (index !== -1) { // 如果找到了 '-'
          let result = state.ruleForm.store.substring(0, index); // 截取 '-' 前面的所有字符
          // 或者使用 slice 方法
          // let result = str.slice(0, index);
          val.value=result;
        } else {
    		val.value=state.ruleForm.store;
        }
    }
    else{
    	val.value=undefined;
    }
     var result=(await transferPack({id:detiallistout.value[0].id,store:state.ruleForm.store,types:1,people:state.ruleForm.people})).data.result;
     	if(result=="操作成功")
     	 {}
     	else
     	{
     		ElMessage({
     	message: `${result}`,
     	type: "error",
     });
    } 
	detiallistout.value=[];
	 state.ruleForm.packCode= undefined;
     state.ruleForm.packName=undefined;
     state.ruleForm.materialCode=undefined;
     state.ruleForm.materialName=undefined;
     state.ruleForm.batchNo=undefined;
     state.ruleForm.num=undefined;
	 state.ruleForm.storeSiteCodes=undefined;
	 state.ruleForm.storeSiteNames=undefined;
	 packRecordData.value=[];
	 onScanAccount();
}

//接收子级的值
const handleValueChanged=async(value:any)=>
{
	//console.log('Received value from child:', value);
	
	const val=ref();
	let index = value.indexOf('-'); // 找到 '-' 的位置
    
        if (index !== -1) { // 如果找到了 '-'
          let result = value.substring(0, index); // 截取 '-' 前面的所有字符
          val.value=result;
        } 
	let lastIndex  = value.lastIndexOf('-'); // 找到 '-' 的位置
    if (lastIndex  !== -1) { // 如果找到了 '-'
	   let resluts = value.substring(lastIndex + 1); // 截取 '-' 后面的所有字符
	   if(resluts=='消耗')
	   {
		   state.ruleForm.isPackCodeflow=val.value;
		   onScanAccountIs();
	   }
	   else
	   {
		   state.ruleForm.packCodeFlow=val.value;
		   onScanAccountI();
	   }
    }
} 

const handleInput1=(value:any) =>{
	
	const allowedValues = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '０', '１', '２', '３', '４', '５', '６', '７', '８', '９'];
	const currentChar = state.ruleForm.actualNumber.slice(-1);
	if (allowedValues.includes(currentChar))
	{
		if( /[-+]?\d*\.?\d*$/.test(state.ruleForm.actualNumber))
	    {
			state.ruleForm.actualNumber = ToCDB(state.ruleForm.actualNumber.toUpperCase());
	    } 
		if(state.ruleForm.actualNumber==0)
		{
			state.ruleForm.actualNumber = undefined;
		}
	}
	else{
		nextTick(() => {
			state.ruleForm.actualNumber = undefined;
        });
	}
    }

//全角转半角
const ToCDB=(str:any) =>{
        // 全角转半角
        var tmp = void 0;
        if (str) {
            tmp = '';
            for (var i = 0; i < str.length; i++) {
                if (str.charCodeAt(i) == 12288) {
                    tmp += String.fromCharCode(32);
                } else if (str.charCodeAt(i) == 160) {
                    tmp += String.fromCharCode(32); // 处理下Unicode为160的特殊空格
                } else if (str.charCodeAt(i) > 65248 && str.charCodeAt(i) < 65375) {
                    tmp += String.fromCharCode(str.charCodeAt(i) - 65248);
                } else {
                    tmp += str[i];
                }
            }
        } else {
            tmp = str;
        }
        return tmp;
      }



//报工
const reportwork=async()=>
{
	//console.log(state.ruleForm.isOrderPlan);
	if(state.ruleForm.store==undefined)
    {
  	   return ElMessage({
       message: `工位不可以为空！`,
       type: "error",
     });
    }
	if(state.ruleForm.people==undefined)
    {
  	   return ElMessage({
       message: `报工人不可以为空！`,
       type: "error",
     });
    }
	if(state.ruleForm.isPackCode==undefined)
    {
  	   return ElMessage({
       message: `消耗载具不可以为空！`,
       type: "error",
     });
    }
	
	if(state.ruleForm.actualNumber!=undefined && state.ruleForm.actualNumber!=0 && state.ruleForm.actualNumber!="" && state.ruleForm.actualNumber!=null)
    {
  	   
    }
	else{
		return ElMessage({
       message: `报工数量不可以为0或者空！`,
       type: "error",
     });
	}
	if(parseFloat(state.ruleForm.actualNumber)>parseFloat(state.ruleForm.isNum))
    {
  	   return ElMessage({
       message: `报工数量不可以大于消耗载具中装载数！`,
       type: "error",
     });
    }
	if(state.ruleForm.isOrderPlan==undefined)
	{
		state.ruleForm.isOrderPlan=false;
	}
	if(state.ruleForm.isOrderPlan==true)
	{
		if(state.ruleForm.packCode!=undefined)
	   {
		detiallistout.value=[];
	 state.ruleForm.packCode= undefined;
     state.ruleForm.packName=undefined;
     state.ruleForm.materialCode=undefined;
     state.ruleForm.materialName=undefined;
     state.ruleForm.batchNo=undefined;
     state.ruleForm.num=undefined;
	 state.ruleForm.storeSiteCodes=undefined;
	 state.ruleForm.storeSiteNames=undefined;
		return ElMessage({
       message: `最后一次报工不需要装载载具！`,
       type: "error",
     });
	   }
	}
	else{
		if(state.ruleForm.packCode==undefined)
       {
  	   return ElMessage({
       message: `装载载具不可以为空！`,
       type: "error",
     });
      }
	}
	let values = state.ruleForm;
	var result=(await addBatchSaveHead(values)).data.result;
	if(result=="添加成功")
	{
		ElMessage.success('报工成功');
		debugger
		 const val=ref();
         if(state.ruleForm.store!=undefined)
         {
             let index = state.ruleForm.store.indexOf('/'); // 找到 '-' 的位置
		
             if (index !== -1) { // 如果找到了 '-'
               let result = state.ruleForm.store.substring(0, index); // 截取 '-' 前面的所有字符
               // 或者使用 slice 方法
               // let result = str.slice(0, index);
               val.value=result;
		  
             } else {
         		val.value=state.ruleForm.store;
			
             }
         }
         else{
         	val.value=state.ruleForm.storeSiteCode;
      }
		if(state.ruleForm.isOrderPlan==false)
	    {
			state.ruleForm.num=parseFloat(state.ruleForm.num)+parseFloat(state.ruleForm.actualNumber);
	        detiallistout.value[0].num=state.ruleForm.num;
	        detiallistout.value[0].materialCode=state.ruleForm.isMaterialCode;
	        detiallistout.value[0].materialName=state.ruleForm.isMaterialName;
	        detiallistout.value[0].batchNo=state.ruleForm.isBatchNo;
	        state.ruleForm.materialCode=state.ruleForm.isMaterialCode;
	        state.ruleForm.materialName=state.ruleForm.isMaterialName;
	        state.ruleForm.batchNo=state.ruleForm.isBatchNo;
	        //state.ruleForm.packCodeflow=state.ruleForm.packCode;
            //onScanAccountIs();
	        if(parseFloat(state.ruleForm.isNum)-parseFloat(state.ruleForm.actualNumber)==0)
	        {
	      	  detiallistin.value=[];
              state.ruleForm.isPackCode=undefined;
              state.ruleForm.isPackName=undefined;
              state.ruleForm.isMaterialCode=undefined;
              state.ruleForm.isMaterialName=undefined;
              state.ruleForm.isBatchNo=undefined;
              state.ruleForm.isStoreSiteCode=undefined;
	      	  state.ruleForm.isStoreSiteName=undefined;
              state.ruleForm.isNum=undefined;
              state.ruleForm.actualNumber=undefined;
	          state.ruleForm.isPackCodeflow=undefined;
			  state.ruleForm.storeSiteCode=val.value;
			  onScanAccount();
	        }
	        else{
	      	state.ruleForm.isPackCodeflow=state.ruleForm.isPackCode;
	      	onScanAccountIs();
	        }
	    }
		else{
			state.ruleForm.isNum=parseFloat(state.ruleForm.isNum)-parseFloat(state.ruleForm.actualNumber);
			state.ruleForm.actualNumber=state.ruleForm.isNum;
			detiallistin.value[0].isNum=state.ruleForm.isNum;
			if(parseFloat(state.ruleForm.isNum)==0)
	        {
	      	  detiallistin.value=[];
              state.ruleForm.isPackCode=undefined;
              state.ruleForm.isPackName=undefined;
              state.ruleForm.isMaterialCode=undefined;
              state.ruleForm.isMaterialName=undefined;
              state.ruleForm.isBatchNo=undefined;
              state.ruleForm.isStoreSiteCode=undefined;
	      	  state.ruleForm.isStoreSiteName=undefined;
              state.ruleForm.isNum=undefined;
              state.ruleForm.actualNumber=undefined;
	          state.ruleForm.isPackCodeflow=undefined;
			  state.ruleForm.storeSiteCode=val.value;
			  onScanAccount();
	        }
			else{
	      	state.ruleForm.isPackCodeflow=state.ruleForm.isPackCode;
	      	onScanAccountIs();
	        }
		}
	 
	}
	  
	else
	{
	  ElMessage({
	    message: `${result}`,
	    type: "error",
	   });
	}
}

</script>
<style scoped>
:deep(.el-ipnut),
:deep(.el-select),
:deep(.el-input-number) {
	width: 100%;
}
:deep(.title-total .el-input__wrapper) {
	background: none;
}
:deep(.title-total .el-form-item--small .el-form-item__label) {
	/* font-size: 15px; */
	font-size: 100%;
	font-weight: bold;
	color: #ffffff;
}
:deep(.title-total .el-input--small .el-input__inner) {
	/* font-size: 15px; */
	font-size: 100%;
	color: #ffffff;
}
:deep(.el-input__prefix-inner) {
	/* font-size: 15px; */
	font-size: 100%;
	color: #ffffff;
}
:deep(.title-total .el-button--small) {
	/* font-size: 15px; */
	font-size: 100%;
	font-weight: bold;
	background: var(--el-color-primary);
}
:deep(.title-total .el-input.is-disabled .el-input__wrapper) {
	background: none;
}
:deep(.title-total .el-input.is-disabled .el-input__inner) {
	/* font-size: 15px; */
	font-size: 100%;
	-webkit-text-fill-color: #ffffff;
	color: #ffffff;
}
:deep(.elbutton .el-button > span) {
	/* font-size: 16px; */
	font-size: 100%;
	/* font-weight: bold; */
}
:deep(.title-total .el-input__wrapper.is-focus) {
	box-shadow: 0 0 0 1px #cccdcd;
}
:deep(.processform .el-form-item--small .el-form-item__label) {
	/* font-size: 15px; */
	/* font-weight: bold; */
	color: var(--el-color-primary);
}
:deep(.processform .el-form-item--small .el-form-item__content) {
	color: var(--el-color-primary);
	/* font-size: 15px; */
}
:deep(.el-table__header-wrapper .el-table th.el-table__cell) {
	background-color: var(--el-color-primary);
}
.mescontrol-total {
	width: 100%;
	height: 100%;
	background: #ffffff;/* var(--el-color-primary) */
}
.elcol {
	padding: 0px 10px;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
}
.processform {
	border: 1px solid #cfd1d1;
	padding: 10px 0px;
	height: 89%;
}

:deep(.packlist .el-table__header-wrapper .el-checkbox) {
	display: none;
}

</style>
