<template>
	<div>
		<layout>
			<layout-content>
				<div class="gva-table-box">
					<h1 style="margin: 0%;margin-bottom: 10px;">车缝完工报工</h1>
					<el-row :gutter="10" style="align-items: center; margin-bottom: 20px;">
						<!-- 子订单编号输入框 -->
						<el-col :span="4"  style="padding: 0px;margin: 0px;">
						  <el-input v-model="add_searchInfo" placeholder="请扫描子订单编号"@keyup.enter="add_onSubmit" id="searchInput" style="width: 100%; height: 50px;"/>
						</el-col>
					
						<!-- 查询按钮 -->
						<el-col :span="1.5"  style="padding: 0px;margin: 0px;">
						  <el-button type="primary" icon="search" @click="add_onSubmit"style="height: 50px;width: 80px;">查询</el-button>
						</el-col>
					
						<el-col :span="1.5" style="padding: 0px;margin: 0px;">
						  <el-text style="font-size: 30px;">机台号</el-text>
						</el-col>
						<!-- 机台号输入框 -->
						<el-col :span="2"><el-input v-model="add_formData['机台号']" readonly style="width: 100%; height: 40px;"/></el-col>
					   
						<el-col :span="1.5" style="padding: 0px;margin: 0px;">
							<el-text style="font-size: 30px;">工序</el-text>
						</el-col>
						<!-- 工序输入框 -->
						<el-col :span="2"><el-input v-model="add_formData['工序']"  readonly  style="width: 100%; height: 40px;" /></el-col>
					
						<el-col :span="1.5" style="padding: 0px;margin: 0px;">
							<el-text style="font-size: 30px;">组别</el-text>
						</el-col>
						<!-- 组别输入框 -->
						<el-col :span="2"><el-input v-model="add_formData['组别']" readonly  style="width: 100%; height: 40px;" /></el-col>
					
						<el-col :span="1.5" style="padding: 0px;margin: 0px;">
							<el-text style="font-size: 30px;">人员</el-text>
						</el-col>
						<!-- 人员输入框 -->
						<el-col :span="2"><el-input v-model="add_formData['人员']" readonly style="width: 100%; height: 40px;"/></el-col>
					
					</el-row>
				
					  <!-- 是否尾包 -->
					  <el-row :gutter="10" style="align-items: center; margin-bottom: 20px;">
						<!-- 是否尾包文本 -->
						<el-col :span="2.5">
						  <el-text style="font-size: 30px;">是否尾包</el-text>
						</el-col>
					
						<!-- 是否尾包按钮 -->
						<el-col :span="5">
						    <el-button
						      :type="activeButton === 'yes' ? 'info' : 'primary'" 
						      @click="setActiveButton('yes')" 
						      :style="activeButton === 'yes' ? activeButtonStyle : defaultButtonStyle"
						      style="height: 45px; width: 60px; margin-right: 10px; font-size: 24px;"
						    >
						      是
						    </el-button>
						    <el-button 
						      :type="activeButton === 'no' ? 'info' : 'primary'" 
						      @click="setActiveButton('no')" 
						      :style="activeButton === 'no' ? activeButtonStyle : defaultButtonStyle"
						      style="height: 45px; width: 60px; margin-right: 10px; font-size: 24px;"
						    >
						      否
						    </el-button>
						  </el-col>
					  </el-row>
					  
					  
					  
					  <el-row :gutter="0">
					    <el-col :span="2.5">
					      <el-text style="font-size: 24px; margin-left: 45px;">尺 码&nbsp;</el-text>
					    </el-col>
					  
					    <!-- 动态生成输入框 -->
					    <el-col 
					      v-for="(item, index) in 10" 
					      :key="index" 
					      :span="1" 
					      :style="{
					        padding: '0', 
					        margin: 
							index < 2 ? '0' : 
							index < 3 ? '0px 9px 0px 0px': 
							index < 4 ? '0px 19px 0px 0px':
							index < 5 ? '0px 29px 0px 0px':
							index < 6 ? '0px 30px 0px 0px':
							index < 7 ? '0px 40px 0px 0px':
							 '0px 20px 0px 0px' 
					      }"
					    >
					      <el-input 
					        v-model="cmformdata[`cm${index + 1}`]" 
					        :id="`cm${index + 1}`" 
					        readonly 
					        :style="{
					          width: 
							  index < 2 ? '70px' : 
							  index < 3 ? '73px' :
							  index < 4 ? '75px' : 
							  '100px', 
					          height: '40px'
					        }"
					      />
					    </el-col>
					  
					    <!-- 总输入框 -->
					    <el-col :span="1">
					      <el-input v-model="cmformdata.cmtotal" id="cmtotal" readonly style="width: 65px; height: 40px;" />
					    </el-col>
					  
					    <!-- 删除报工按钮 -->
					    <el-col :span="2">
					      <el-button  
					        type="danger" 
					        icon="delete" 
					        @click="del_delclick"
					        v-if="delall === true" 
					        :disabled="Selection === ''"
					        :style="{
					          backgroundColor: Selection === '' ? '' : 'red',
					          borderColor: Selection === '' ? '' : 'red',
					          color: Selection === '' ? '' : '#fff'
					        }"
					        style="width: 130px; height: 40px; font-size: 20px; margin-left: 20px;">
					        删除报工
					      </el-button>
					    </el-col>
					  </el-row>
					  
					  <el-row :gutter="0">
					  	<el-col :span="2.5">
					  		<el-text style="font-size: 24px; margin-left: 35px;">制单数</el-text>
					  	</el-col>
					  	<el-col v-for="(item, index) in 10" :key="index" :span="1" 
						:style="{
						  padding: '0', 
						  margin: 
													index < 2 ? '0' : 
													index < 3 ? '0px 9px 0px 0px': 
													index < 4 ? '0px 19px 0px 0px':
													index < 5 ? '0px 29px 0px 0px':
													index < 6 ? '0px 30px 0px 0px':
													index < 7 ? '0px 40px 0px 0px':
													 '0px 20px 0px 0px' 
						}"
						>
					  		<el-input v-model="zdslformdata[`cmsl${index + 1}`]" :id="`cm${index + 1}`" readonly 
							:style="{
							  width: 
							  index < 2 ? '70px' : 
							  index < 3 ? '73px' :
							  index < 4 ? '75px' : 
							  '100px', 
							  height: '40px'
							}"
							/>
					  	</el-col>
					  	<el-col :span="1"><el-input v-model="zdslformdata.zdtotal" id="zdtotal" readonly style="width: 65px;height: 40px;" /></el-col>
						<el-button type="primary" @click="cp_gdprintonClick" style="width: 130px; height: 40px; font-size: 20px; margin-left: 20px;" >  子订单详情页 </el-button>
					  </el-row>
					  
					  <el-row :gutter="0">
					  	<el-col :span="2.5">
					  		<el-text style="font-size: 24px; margin-left: 35px;">实裁数</el-text>
					  	</el-col>
					  	<el-col v-for="(item, index) in 10" :key="index" :span="1" 
						:style="{
						  padding: '0', 
						  margin: 
													index < 2 ? '0' : 
													index < 3 ? '0px 9px 0px 0px': 
													index < 4 ? '0px 19px 0px 0px':
													index < 5 ? '0px 29px 0px 0px':
													index < 6 ? '0px 30px 0px 0px':
													index < 7 ? '0px 40px 0px 0px':
													 '0px 20px 0px 0px' 
						}"
						>
					  		<el-input v-model="scslformdata[`scsl${index + 1}`]" :id="`scsl${index + 1}`" readonly 
							:style="{
							  width: 
							  index < 2 ? '70px' : 
							  index < 3 ? '73px' :
							  index < 4 ? '75px' : 
							  '100px', 
							  height: '40px'
							}"
							/>
					  	</el-col>
					  	<el-col :span="1"><el-input v-model="scslformdata.sctotal" id="sctotal" readonly style="width: 65px;height: 40px;" /></el-col>
					  </el-row>
					  
					  <el-row :gutter="0">
					   <el-col :span="2.5"><el-text style="font-size: 24px;margin-left: 10px;">上报数量</el-text></el-col>
					   <el-col :span="1" style="padding-right: 0px;margin: 0px 1px 0px 0px;">
						   <el-input v-model="slformdata.sl1" id="sl1"  :readonly="!scslformdata.scsl1" @input="updateTotal" style="width: 70px;height: 40px;" /></el-col>
					   <el-col :span="1" style="padding-right: 0px;margin: 0px 0px 0px 0px;">
						   <el-input v-model="slformdata.sl2" id="sl2"  :readonly="!scslformdata.scsl2" @input="updateTotal" style="width: 70px;height: 40px;" /></el-col>
					   <el-col :span="1" style="padding-right: 0px;margin: 0px 9px 0px 0px;">
						   <el-input v-model="slformdata.sl3" id="sl3"  :readonly="!scslformdata.scsl3" @input="updateTotal" style="width: 73px;height: 40px;" /></el-col>
					   <el-col :span="1" style="padding-right: 0px;margin: 0px 20px 0px 0px;">
						   <el-input v-model="slformdata.sl4" id="sl4"  :readonly="!scslformdata.scsl4" @input="updateTotal" style="width: 75px;height: 40px;" /></el-col>
					   <el-col :span="1" style="padding-right: 0px;margin: 0px 30px 0px 0px;">
						   <el-input v-model="slformdata.sl5" id="sl5"  :readonly="!scslformdata.scsl5" @input="updateTotal" style="width: 100px;height: 40px;" /></el-col>
					   <el-col :span="1" style="padding-right: 0px;margin: 0px 30px 0px 0px;">
						   <el-input v-model="slformdata.sl6" id="sl6"  :readonly="!scslformdata.scsl6" @input="updateTotal" style="width: 100px;height: 40px;" /></el-col>
					   <el-col :span="1" style="padding-right: 0px;margin: 0px 39px 0px 0px;">
						   <el-input v-model="slformdata.sl7" id="sl7"  :readonly="!scslformdata.scsl7" @input="updateTotal" style="width: 100px;height: 40px;" /></el-col>
					   <el-col :span="1" style="padding-right: 0px;margin: 0px 20px 0px 0px;">
						   <el-input v-model="slformdata.sl8" id="sl8"  :readonly="!scslformdata.scsl8" @input="updateTotal" style="width: 100px;height: 40px;" /></el-col>
					   <el-col :span="1" style="padding-right: 0px;margin: 0px 20px 0px 0px;">
						   <el-input v-model="slformdata.sl9" id="sl9"  :readonly="!scslformdata.scsl9" @input="updateTotal" style="width: 100px;height: 40px;" /></el-col>
					   <el-col :span="1" style="padding-right: 0px;margin: 0px 20px 0px 0px;">
						   <el-input v-model="slformdata.sl10" id="sl10"  :readonly="!scslformdata.scsl10" @input="updateTotal" style="width: 100px;height: 40px;" /></el-col>
					   <el-col :span="1"><el-input v-model="slformdata.sctotal" id="cm11" readonly style="width: 65px;height: 40px;" /></el-col>
					    <el-col :span="2">
					      <el-button type="primary" @click="add_Dialog" style="width: 130px; height: 40px; font-size: 20px; margin-left: 20px;" >报工</el-button>
					    </el-col>
					  </el-row>
					

					
							<!-- 表格数据 -->
							  <el-tabs v-model="activeName">
								<el-tab-pane label="报工历史记录"  name="first">
							<el-table
							    ref="multipleTable"
							    style="width: 100%; height: 52vh"
							    tooltip-effect="dark"
							    :row-style="{ height: '50px' }"
							    :header-cell-style="{ padding: '5px', fontSize: '20px' }"
							    :cell-style="{ padding: '10px', fontSize: '20px' }"
							    :header-row-style="{ height: '20px' }"
							    :data="add_tableData"
							    border
							    row-key="ID"
							    size="small"
							    highlight-current-row="true"
							    @row-dblclick="updateCompanyFunc"
							    @row-click="tableRowClick"
							    :show-overflow-tooltip="true"
							    @selection-change="selectionChange"
							>
							<el-table-column type="selection" width="60" />
							    <!-- 操作列 -->
							    <el-table-column align="left" label="操作" width="150">
							        <template v-slot="scope">
							            <!-- 当 sys_rq、组别和 serial 不为空时显示按钮 -->
							            <el-button
							                v-if="scope.row.sys_rq && scope.row.组别 && scope.row.serial"
							                type="primary"
							                @click="add_bdprintxp(scope.row)"
							                style="width: 110px; height: 40px; font-size: 20px;"
							            >
							                补打小票
							            </el-button>
							        </template>
							    </el-table-column>
							
							    <!-- 报工时间 -->
							    <el-table-column align="center" label="报工时间" prop="sys_rq" width="150" />
							
							    <!-- 子订单编号 -->
							    <el-table-column align="center" label="子订单编号" prop="子订单编号" width="110" />
							
							    <!-- 组别 -->
							    <el-table-column align="center" label="组别" prop="组别" width="80" />
							
							    <!-- 尺码列表 -->
							    <el-table-column
							        v-for="item in sizeDatas"
							        :key="item"
							        align="center"
							        :label="item"
							        width="100"
							        :cell-style="cellStyle"
							    >
							        <template v-slot="scope">
							            <div
							                :class="{ 'highlight-cell': isCellHighlighted(scope.$index, item) }"
							                style="margin-left: -5px; width: 80px;"
							                @click="handleSizeClick(scope.$index, item, scope.row)"
							            >
							                {{ scope.row[item] || '—' }} 
							            </div>
							        </template>
							    </el-table-column>
							
							    <!-- 数量 -->
							    <el-table-column align="left" sortable label="数量" prop="数量" width="100" />
							
							    <!-- 流水号 -->
							    <el-table-column align="center" label="流水号" width="150">
							        <template v-slot="scope">
							            <!-- 当 sys_rq、组别和 serial 不为空时显示流水号 -->
							            <div v-if="scope.row.sys_rq && scope.row.组别 && scope.row.serial">
							                第{{ scope.row.serial }}包
							            </div>
							        </template>
							     </el-table-column>
							</el-table>
								</el-tab-pane>
							
							
							<el-tab-pane label="订单资料附件" name="third">
							  <el-table ref="multipleTable"
										:row-style="{ height: '30px' }"
										:cell-style="{ padding: '0px' }" :header-row-style="{ height: '30px' }"
										:header-cell-style="{ padding: '0px' }"
										:show-overflow-tooltip="true"
										:cell-class-name="planUsageCellClass"
										highlight-current-row="true"
										@row-dblclick="gdbomupdateCompanyFunc"
										style="width: 100%;height: 36vh" border tooltip-effect="dark" :data="ddtableData" row-key="ID"
													   @selection-change="fjSelectionChange">
							   <el-table-column align="left" label="关联编号" prop="关联编号"  width="115"/>
							   <el-table-column align="left" label="备注" 	prop="附件备注"  width="110"/>
							   <el-table-column align="left" label="文件类型" prop="附件类型"  width="100"/>
							   <el-table-column align="left" label="建档时间" prop="sys_rq"  width="160"/>
							   <el-table-column align="left" label="建档用户" prop="sys_id"  width="200"/>
											 <el-table-column align="left" label="操作"width="100"fixed="right">
											   <template #default="scope">
												 <el-button type="success" size="small" :data="ddtableData" @click="showPdf(scope.row)" >PDF预览</el-button> 
											   </template>
											 </el-table-column>
							  </el-table>
							</el-tab-pane> 
							
							
							<el-tab-pane label="技术附件" @click="showTable('技术附件')" name="fourth">
								<el-table ref="multipleTable"
												  :row-style="{ height: '30px' }"
												  :cell-style="{ padding: '0px' }" :header-row-style="{ height: '30px' }"
												  :header-cell-style="{ padding: '0px' }"
												  :show-overflow-tooltip="true"
												  :cell-class-name="planUsageCellClass"
												  highlight-current-row="true"
												  @row-dblclick="ExcelShow"
												  style="width: 100%;height: 36vh" border tooltip-effect="dark" :data="jstableData" row-key="ID" @selection-change="fjSelectionChange">
											  <el-table-column align="left" label="关联编号" prop="关联编号"  width="115"/>
											  <el-table-column align="left" label="备注" 	prop="附件备注"  width="110"/>
											  <el-table-column align="left" label="文件类型" prop="附件类型"  width="100"/>
											  <el-table-column align="left" label="建档时间" prop="sys_rq"  width="160"/>
											  <el-table-column align="left" label="建档用户" prop="sys_id"  width="200"/>
											  <el-table-column align="left" label="操作"width="100"fixed="right">
												<template #default="scope">
												  <el-button type="success" size="small" :data="ddtableData" @click="showPdf(scope.row)" >PDF预览</el-button> 
												</template>
											  </el-table-column>
								</el-table>
							  </el-tab-pane>
							</el-tabs>

				</div>

			   <!-- 是否订单尾包确认弹窗 -->
			   <el-dialog v-model="DialogVisible" title="是否订单尾包" destroy-on-close width="30%" style="top: 20%;">
				 <h3>请再次确认是否该订单产品已全部报工，该批为订单尾包？</h3>
				 <div class="dialog-footer" style="text-align: right;">
				   <el-button @click="confirmDialogVisible">取消</el-button>
				   <el-button type="primary" @click="handleConfirm">确认</el-button>
				 </div>
			   </el-dialog>
			   
			   <SubOrderPage ref="SubOrderPageRef" />
			   <PrintPage ref="printPageRef" />
			   <!-- 子订单详情页 -->
			   <luckyexcelPage ref="luckyexcelPageRef" />
			</layout-content>
		</layout>
	</div>
</template>
<script>
	export default {
		data() {
		  return {
				currentTable: '', // 当前展示的表格
				activeName: 'first',
		  };
		}, 
		methods: {
			handleKeyDown(event, prevId, currentId, nextId) {
				const currentElement = document.getElementById(currentId);
				const isEmpty = currentElement.value === '';
				const atStart = currentElement.selectionStart === 0;
				const atEnd = currentElement.selectionStart === currentElement.value.length;
				switch (event.keyCode) {
					case 13: // Enter
					case 40: // 向下箭头
						if (nextId) {
							document.getElementById(nextId).focus();
						}
						break;
					case 38: // 向上箭头
						if (prevId) {
							document.getElementById(prevId).focus();
						}
						break;
					case 8: // 删除键
						if (prevId && (isEmpty || atStart)) {
							document.getElementById(prevId).focus();
						}
						break;
					case 37: // 向左箭头
						if (prevId && atStart) {
							document.getElementById(prevId).focus();
						}
						break;
					case 39: // 向右箭头
						if (nextId && atEnd) {
							document.getElementById(nextId).focus();

						}
						break;
					default:
						break;
				}
			},
		},
	};
</script>
<script setup>
// 全量引入格式化工具 请按需保留
import $script from 'scriptjs'
import $ from 'jquery';
import LuckyExcel from 'luckyexcel';
import {Layout,LayoutSider,LayoutContent} from '@arco-design/web-vue';
import {hiprint} from "vue-plugin-hiprint";
import {ref,reactive,nextTick,watch,setBlockTracking} from 'vue'
import {getSpotList,search,SubWorkOrderStatusList,getTab,OrderAttachments,getTabByGdbh,processAdd,spotcheckdel,Mabaolist} from '@/api/mes/job'
import {getMachineMac} from '@/api/jixiaoguanli/jitairibaobiao'
import {getMac} from '@/api/jixiaoguanli/baogong'
import {ElMessage} from "element-plus";
import {get} from 'scriptjs';
import PrintPage from '../yunyin/shengchanguanli/components/print.vue'
import luckyexcelPage from '../yunyin/shengchanguanli/components/luckyexcel.vue';
import SubOrderPage from '../yunyin/shengchanguanli/components/SubOrder.vue';
import { useUserStore } from '@/pinia/modules/user';
defineOptions({name: 'Company'})
const path = `${import.meta.env.VITE_BASE_PATH}:${import.meta.env.VITE_UPLOADS_PORT}`
console.log(path)
//定义跳转页面
const SubOrderPageRef = ref()//子订单详情页
const printPageRef = ref()//打印预览
const luckyexcelPageRef = ref()//pdf预览
//子订单详情页
const cp_gdprintonClick = async () => {
	if(add_searchInfo.value === '' || add_searchInfo.value === null){
		ElMessage({ type: 'warning', message: '请扫描子订单（条码）后再查看' });
		return false;
	}
	SubOrderPageRef.value.open(add_searchInfo.value,add_formData['工序']) 
}
//获取登录用户信息
const userStore = useUserStore()
const _username = ref('')
_username.value = userStore.userInfo.userName + '/' + userStore.userInfo.nickName
console.log('获取用户名称',_username.value)
//全局获取当前日期
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始，需要补零
const day = String(today.getDate()).padStart(2, '0');
const hours = String(today.getHours()).padStart(2, '0');
const minutes = String(today.getMinutes()).padStart(2, '0');
const seconds = String(today.getSeconds()).padStart(2, '0');
const currentDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
const currentDates = `${year}-${month}-${day}`;


//全局获取code，接口接收code
const _code = '车缝'
//全局接口接受的物理地址
const Machine = ref('')
//全局获取UniqId
const UniqId = ref('')

	//物理地址获取机台编号
	const getMachineMacdata = async () => {
		console.log("车缝机台获取物理地址", Machine.value)
		try {
			const data = await getMachineMac({sys_sbID: Machine.value});
			if (data.data === null) {
				// ElMessage({
				// 	type: 'error',
				// 	message: '未获取到机台编号请确认MAC地址或与管理员联系'
				// })
				add_formData['机台号'] = '测试机台'
				add_formData['工序'] = _code
				add_formData['组别'] = "测试"
				add_formData['人员'] = "测试"
				return;
			} else {
				add_formData['机台号'] = data.data['机台号']
				add_formData['工序'] = data.data['生产工序']
				add_formData['工序名称'] = data.data['生产工序']
				add_formData['组别'] = data.data['组别']
				add_formData['人员'] = data.data['组长']
				setTimeout(() => {
					const inputElement = document.getElementById('searchInput');
					if (inputElement) {
						inputElement.focus();
					}
				}, 100); // 延迟100毫秒
			}
		} catch (error) {
			console.error(error)
		}
	}
	//自动获取物理地址
	const GetAddr = () => {
		var xmlhttp = null;
		var res;
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		// 2. 设置回调函数
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				res = eval('(' + xmlhttp.response + ')');
				let result = ''
				for (let i = 0; i < res.macAddress.length; i++) {
					if (i % 2 === 0 && i !== 0) {
						result += '-' // 根据实际需求修改分隔符
					}
					result += res.macAddress[i]
				}
				Machine.value = result
				getMachineMacdata(Machine.value)
			}
		}
		// 3. 打开一个连接
		xmlhttp.open("get", "http://127.0.0.1:8090/init")
		// 5. 发送
		xmlhttp.send();
	}
	// getMachineMacdata();
	GetAddr()
	
// PDF预览
const showPdf = async (row) => {
	luckyexcelPageRef.value.open(row)
}

	// 尺码
	const cmformdata = reactive({
		cm1: '',
		cm2: '',
		cm3: '',
		cm4: '',
		cm5: '',
		cm6: '',
		cm7: '',
		cm8: '',
		cm9: '',
		cm10: '',
		cmtotal: '合计',
	});
	// 制单数
	const zdslformdata = reactive({
		cmsl1: '',
		cmsl2: '',
		cmsl3: '',
		cmsl4: '',
		cmsl5: '',
		cmsl6: '',
		cmsl7: '',
		cmsl8: '',
		cmsl9: '',
		cmsl10: '',
		zdtotal: '',
	});
	// 实裁量
	const scslformdata = reactive({
		scsl1: '',
		scsl2: '',
		scsl3: '',
		scsl4: '',
		scsl5: '',
		scsl6: '',
		scsl7: '',
		scsl8: '',
		scsl9: '',
		scsl10: '',
		sctotal: '',
	});
	// 数量
	const slformdata = reactive({
		sl1: '',
		sl2: '',
		sl3: '',
		sl4: '',
		sl5: '',
		sl6: '',
		sl7: '',
		sl8: '',
		sl9: '',
		sl10: '',
		sctotal: '',
	});

//实裁相加
function updateTotal() {
	// 直接指定要累加的属性名  
	const relevantKeys = ['sl1', 'sl2', 'sl3', 'sl4', 'sl5', 'sl6', 'sl7', 'sl8', 'sl9', 'sl10'];
	const values = relevantKeys.map(key => parseInt(slformdata[key], 10) ||
	0); // 使用 || 0 来处理可能的 NaN 或 undefined/null  
	slformdata.sctotal = values.reduce((sum, value) => sum + value, 0);
	
	const relevantKeyss = ['scsl1', 'scsl2', 'scsl3', 'scsl4', 'scsl5', 'scsl6', 'scsl7', 'scsl8', 'scsl9', 'scsl0'];
	const valuess = relevantKeyss.map(key => parseInt(scslformdata[key], 10) ||
	0); // 使用 || 0 来处理可能的 NaN 或 undefined/null  
	scslformdata.sctotal = valuess.reduce((sum, value) => sum + value, 0);

}


	//历史记录表格
	const add_tableData = reactive([]);
	//全局获取颜色款式款号
	const _yskskh = ref('')
	//全局获取新增流水号
	const _serial = ref('')
	//全局获取序号
	const _serial_num = ref('')
	const _list = ref('')
	//流水号补零
	function padNumber(num, length) {
		let str = '' + num;
		while (str.length < length) {
			str = '0' + str;
		}
		return str;
	}
	// 代表扫描两次自动保存
	// const searcs = ref('')
	//尺寸列表
	const sizeDatas = reactive([])
	//搜索
	const add_searchInfo = ref('')
	//技术附件
	const jstableData = reactive([])
	const ddtableData = reactive([])
	
	//查询
	const add_onSubmit = async () => {
		if(add_formData['机台号'] === ''){
			ElMessage({type: 'warning',message: '未获取到机台'})
			return false;
		}
		sizeDatas.length = 0;
		add_tableData.length = 0;
		if (!add_searchInfo.value.startsWith('DC')) {
			// 如果没有以"DC"开头，则添加前缀  
			add_searchInfo.value = 'DC' + add_searchInfo.value;
		}
		if (add_searchInfo.value === '' || add_searchInfo.value === undefined) {
			const WorkListdata = [];
			add_tableData.splice(0, add_tableData.length, ...WorkListdata);
			ElMessage({
				type: 'warning',
				message: '请扫描小票二维码'
			})
		} else {
			//获取报工历史记录
			const getSpotLists = await getSpotList({order: add_searchInfo.value,code: _code,sys_sbID: add_formData['机台号']});
			// console.log(getSpotLists)
			sizeDatas.splice(0, getSpotLists.data.headers.length, ...getSpotLists.data.headers); //型号数据
			add_tableData.splice(0, add_tableData.length, ...getSpotLists.data.records); //表格数据
			_list.value = getSpotLists.data.list
			
			if (!add_searchInfo.value.includes('-') && getSpotLists.data.records.length === 0) {
				ElMessage({
					type: 'warning',
					message: '未查询到报工历史数据'
				})
				return false;
			}
			
			//xlsx附件
			const searchValue = add_searchInfo.value.split('-')[0];
			const jsOrderAttachments = await OrderAttachments({order:searchValue,desc:'技术附件'})
			const ddOrderAttachments = await OrderAttachments({order:searchValue,desc:'订单资料附件'})
			jstableData.splice(0,jsOrderAttachments.data.length,...jsOrderAttachments.data);
			ddtableData.splice(0,ddOrderAttachments.data.length,...ddOrderAttachments.data);
			
			_yskskh.value = getSpotLists.data.list //颜色、款式、款号
			_serial.value = String(getSpotLists.data.serial) //流水号
			_serial_num.value  = String(getSpotLists.data.serial_num);//序号
				console.log(_serial_num.value)
			//获取尺码、制单数/实裁量上面信息
			const keys1 = ['cm1', 'cm2', 'cm3', 'cm4', 'cm5', 'cm6', 'cm7', 'cm8', 'cm9', 'cm10', ];
			const keys2 = ['cmsl1', 'cmsl2', 'cmsl3', 'cmsl4', 'cmsl5', 'cmsl6', 'cmsl7', 'cmsl8', 'cmsl9',
				'cmsl10', 'zdtotal',
			];
			const keys3 = ['scsl1', 'scsl2', 'scsl3', 'scsl4', 'scsl5', 'scsl6', 'scsl7', 'scsl8', 'scsl9',
				'scsl10', 'sctotal',
			];
			//如果搜索是子订单编号
			if (add_searchInfo.value.includes('-')) {
				for (let key of keys1) {
					if (getSpotLists.data.list.hasOwnProperty(key)) { // 确保键存在于对象中  
						cmformdata[key] = getSpotLists.data.list[key];
					}
				}
				for (let key of keys2) {
					if (getSpotLists.data.list.hasOwnProperty(key)) { // 确保键存在于对象中  
						zdslformdata[key] = getSpotLists.data.list[key];
					}
				}
				for (let key of keys3) {
					if (getSpotLists.data.list.hasOwnProperty(key)) { // 确保键存在于对象中  
						scslformdata[key] = getSpotLists.data.list[key];
					}
				}
				setTimeout(() => {
					const inputElement = document.getElementById('sl1');
					if (inputElement) {
						inputElement.focus();
					}
				}, 100); // 延迟100毫秒
			} else {
				for (let key of keys1) {
					cmformdata[key] = '';
				}
				for (let key of keys2) {
					zdslformdata[key] = '';
				}
			}
			updateTotal()
			// //历史记录
			// if (getSpotLists.data.headers) {
				
			// }
		}
	}
	

	const AttendanceVisible = ref(false)

	//清空对象的属性值
	const gd_clearFormData = () => {
		Object.keys(add_formData).forEach(key => {
			add_formData[key] = '';
		});
	};

	const add_formData = reactive({
		机台号: '',
		工序: '',
		组别: '',
		人员: '',
		尺码: '',
		数量: '',
		是否订单尾包: '0',
	});

	const currentSlValue = ref('')
	
	//车缝报工
	const add_Dialog = async () => {
		if(add_formData['机台号'] === '测试机台'){
			ElMessage({ type: 'warning', message: '测试机台禁止报工' });
			return;
		}
		sizeDatas.length = 0;
		add_tableData.length = 0;
		// console.log(_serial.value)
		if (_serial.value === NaN) {
			ElMessage({type: 'warning',message: '网络异常.请检查'})
			return fasle;
		}
		if (add_searchInfo.value === '') {
			ElMessage({type: 'warning',message: '请扫描子订单编号输入数量后，再进行上报'})
			return fasle;
		}
		//尺码
		let cmArray = [cmformdata.cm1, cmformdata.cm2, cmformdata.cm3, cmformdata.cm4, cmformdata.cm5, cmformdata
			.cm6, cmformdata.cm7, cmformdata.cm8, cmformdata.cm9, cmformdata.cm10
		];
		//制单数
		let zdsl1Array = [zdslformdata.zdsl1, zdslformdata.zdsl12, zdslformdata.zdsl13, zdslformdata.zdsl14,
			zdslformdata.zdsl15, zdslformdata.zdsl16, zdslformdata.zdsl17, zdslformdata.zdsl18, zdslformdata
			.zdsl19, zdslformdata.zdsl110
		];
		//上报数量
		let slArray = [slformdata.sl1, slformdata.sl2, slformdata.sl3, slformdata.sl4, slformdata.sl5, slformdata
			.sl6, slformdata.sl7, slformdata.sl8, slformdata.sl9, slformdata.sl10
		];
		let resultArrays = [];
		for (let i = 0; i < slArray.length; i++) {
			// 创建一个新数组来存储当前索引下的所有值  
			let currentValues = [add_formData['机台号'], cmArray[i], zdsl1Array[i], slArray[i]];
			// 添加到结果数组中  
			resultArrays.push(currentValues);
		}
		
		//获取报工历史记录
		const getSpotLists = await getSpotList({order: add_searchInfo.value,code: _code,sys_sbID: add_formData['机台号']});
		
		
		let paramsList = []; // 用于存储每个元素的 cm 和 sl  
		let serialNumber = parseInt(getSpotLists.data.serial, 10);
		
		for (let i = 0; i < resultArrays.length; i++) {
			if (slArray[i]) {
				let params = {};
				params.order_id = add_searchInfo.value;
				params.sczl_jtbh = add_formData['机台号'];
				params.gxmc = add_formData['工序'];
				params.sys_id = add_formData['人员'];
				params.wb = add_formData['是否订单尾包'];
				params.cm = resultArrays[i][1];
				params.sl = resultArrays[i][3];
				params.sys_rq = currentDates;
				params.code = '车缝';
				params.sczl_bh = add_formData['组别'];
				// 流水号（包数）
				serialNumber++;
				params.serial = padNumber(serialNumber, 3);
				//流水号序号
				// _serial_num.value++;
				// params.serial_num = _serial_num.value;
				
				// 流水号序号
				params.serial_num = serialNumber;
				paramsList.push(params);
			}
		}
		console.log("新增报工",paramsList)
		// return;
		if (paramsList.length === 0) {
			ElMessage({type: 'info',message: '请填写报工尺码数量'});
			return;
		}
		let allSuccess = true;
		for (let i = 0; i < paramsList.length; i++) {
			const cf_gettab = await search(paramsList[i]);
			console.log("新增报工返回状态",cf_gettab)
			if (cf_gettab.code !== 0) { 
				allSuccess = false;
				break; // 如果某个报工失败，则中断循环  
			}
		}
		//光标跳转input框
		setTimeout(() => {
			const inputElement = document.getElementById('searchInput');
			if (inputElement) {
				inputElement.focus();		
			}
		}, 100); // 延迟100毫秒
		
		
		
		if (allSuccess) {
			// const lsjltable = await getTab({
			// 	order_id: add_searchInfo.value,
			// 	sczl_jtbh: add_formData['机台号']
			// });
			const getSpotLists = await getSpotList({
				order: add_searchInfo.value,
				code: _code,
				sys_sbID: add_formData['机台号']
			});
			sizeDatas.splice(0, getSpotLists.data.headers.length, ...getSpotLists.data.headers);
			add_tableData.splice(0, add_tableData.length, ...getSpotLists.data.records);
			
			add_printxp();
			search.value = '';
			// add_searchInfo.value = ''; 
			ElMessage({
				type: 'success',
				message: '报工成功'
			});
			// 上报成功后 清空所有输入框上报数量
			  if (slformdata) {
			    for (let i = 1; i <= 10; i++) {
			      slformdata['sl' + i] = '';
			    }
			    // 清空总和
			    slformdata.sctotal = '';
			  } else {
			    console.error('未定义');
			  }
		}
	}
	
	
	// 新增取消
	const add_closeDialog = () => {
		AttendanceVisible.value = false
	};
	
	
//是否订单尾包选择是否按钮
const activeButton = ref('no')
const DialogVisible = ref(false)
// 定义按钮的默认样式和激活样式
const defaultButtonStyle = {
	backgroundColor: '#808080', //用于默认状态
	color: 'white',
};
const activeButtonStyle = {
	backgroundColor: 'red', //用于选中状态
	color: 'white',
};
//点击尾包是否按钮
const setActiveButton = (button) => {
	console.log("setActiveButton")
	activeButton.value = button;
	//1 = 是 0 = 否
	if (button === 'yes') {
		console.log("yes")
		add_formData['是否订单尾包'] = '1';
		DialogVisible.value = true;
	} else if (button === 'no') {
		console.log("no")
		add_formData['是否订单尾包'] = '0';
		DialogVisible.value = false;
	}
};
//是否尾包弹窗确定
const handleConfirm = () => {
	add_formData['是否订单尾包'] = '1'
	activeButton.value = 'yes'; 
	DialogVisible.value = false
};
//是否尾包弹窗取消
const confirmDialogVisible = () => {
	add_formData['是否订单尾包'] = '0'
	activeButton.value = 'no';
	DialogVisible.value = false
};

// =========== 打印小票 ===========
const jsondata = {"panels":[{"index":0,"name":1,"height":296.6,"width":210,"paperHeader":19.5,"paperFooter":832.5,"printElements":[{"options":{"left":435,"top":61.5,"height":159,"width":159,"title":"二维码","qrcodeType":"qrcode","testData":"qrcode","right":597.75,"bottom":218.25,"vCenter":518.25,"hCenter":138.75,"field":"emm","qrCodeLevel":2,"coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"zIndex":1},"printElementType":{"title":"二维码","type":"qrcode"}},{"options":{"left":3,"top":456,"height":45,"width":199.5,"title":"2024-10-22","right":419.25,"bottom":200.25,"vCenter":319.5,"hCenter":177.75,"field":"dyrq","coordinateSync":false,"widthHeightSync":false,"fontSize":30,"textContentVerticalAlign":"middle","qrCodeLevel":0,"qid":"kh_6","textAlign":"left","hideTitle":true},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":0,"top":21,"height":37,"width":291,"title":"DC2410023-0100","right":291,"bottom":64,"vCenter":145.5,"hCenter":45.5,"field":"zddbh","coordinateSync":false,"widthHeightSync":false,"fontSize":33,"textContentVerticalAlign":"middle","qrCodeLevel":0,"qid":"zddbh_1","lineHeight":33,"hideTitle":true},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":112.5,"top":64.5,"height":43,"width":193.5,"title":"","right":285,"bottom":508,"vCenter":188.25,"hCenter":486.5,"field":"zb","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":40,"textContentVerticalAlign":"middle","qrCodeLevel":0,"qid":"kh_5"},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":0,"top":64.5,"height":43,"width":126,"title":"组别：","coordinateSync":false,"widthHeightSync":false,"fontSize":40,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":92,"bottom":114.99999713897705,"vCenter":46,"hCenter":93.49999713897705},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":430.5,"top":225,"height":44,"width":40.5,"title":"第","right":459,"bottom":313.5,"vCenter":438.75,"hCenter":287.25,"coordinateSync":false,"widthHeightSync":false,"fontSize":40,"textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":553.5,"top":225,"height":44,"width":40.5,"title":"包","right":597.7500457763672,"bottom":268.25,"vCenter":577.5000457763672,"hCenter":246.25,"coordinateSync":false,"widthHeightSync":false,"fontSize":40,"textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":474,"top":225,"height":44,"width":78,"title":"005","right":538.5,"bottom":313.5,"vCenter":498.75,"hCenter":287.25,"field":"lsh","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":40,"textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":112.5,"top":112.5,"height":43,"width":190.5,"title":"这是更新后的元素","right":282.75,"bottom":362.5,"vCenter":187.5,"hCenter":341,"field":"cm","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":40,"textContentVerticalAlign":"middle","qrCodeLevel":0,"qid":"kh_3","textContentWrap":"ellipsis"},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":0,"top":114,"height":43,"width":124.5,"title":"尺码：","coordinateSync":false,"widthHeightSync":false,"fontSize":40,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":88.25,"bottom":290.5,"vCenter":42.25,"hCenter":269},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":0,"top":219,"height":44,"width":123,"title":"尾包:","coordinateSync":false,"widthHeightSync":false,"fontSize":40,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":120,"bottom":270.50000858306885,"vCenter":70.5,"hCenter":248.50000858306885},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":115.5,"top":219,"height":44,"width":55.5,"title":"否","right":573.7500228881836,"bottom":437.75001430511475,"vCenter":546.0000228881836,"hCenter":415.75001430511475,"field":"wb","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":40,"textContentVerticalAlign":"middle","qrCodeLevel":0,"qid":"kh_7"},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":114,"top":163.5,"height":43,"width":190.5,"title":"这是更新后的元素","right":280.5,"bottom":334.00000858306885,"vCenter":185.25,"hCenter":312.50000858306885,"field":"sl","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":40,"textContentVerticalAlign":"middle","qrCodeLevel":0,"qid":"kh_4"},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":0,"top":163.5,"height":43,"width":124.5,"title":"数量：","coordinateSync":false,"widthHeightSync":false,"fontSize":40,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":70.25,"bottom":275.50001430511475,"vCenter":24.25,"hCenter":254.00001430511475},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":1.5,"top":286.5,"height":46,"width":157.5,"title":"生产款号：","coordinateSync":false,"widthHeightSync":false,"fontSize":30,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":156,"bottom":459.25,"vCenter":75,"hCenter":437.75},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":142.5,"top":286.5,"height":46,"width":444,"title":"MMGPayton Coach Jacket506880","right":454.5000114440918,"bottom":340.75,"vCenter":291.0000114440918,"hCenter":317.75,"field":"kh","coordinateSync":false,"widthHeightSync":false,"fontSize":30,"textContentVerticalAlign":"middle","qrCodeLevel":0,"qid":"zddbh_1","hideTitle":true,"lineHeight":36,"textContentWrap":"nowrap"},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":0,"top":343.5,"height":46,"width":121.5,"title":"款式：","coordinateSync":false,"widthHeightSync":false,"fontSize":30,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":94.25,"bottom":464.50001430511475,"vCenter":48.25,"hCenter":443.00001430511475},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":85.5,"top":343.5,"height":47,"width":493.5,"title":"西装","right":572.25,"bottom":394.25000858306885,"vCenter":343.5,"hCenter":370.75000858306885,"field":"pm","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":30,"qrCodeLevel":0,"qid":"kh_1","lineHeight":36,"textContentWrap":"nowrap","textContentVerticalAlign":"middle"},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":84,"top":400.5,"height":46,"width":495,"title":"","right":570.75,"bottom":451.7500057220459,"vCenter":327,"hCenter":428.7500057220459,"field":"ys","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":30,"qrCodeLevel":0,"qid":"kh_2","lineHeight":36,"textContentWrap":"nowrap","textContentVerticalAlign":"middle"},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":0,"top":400.5,"height":46.5,"width":120,"title":"颜色：","coordinateSync":false,"widthHeightSync":false,"fontSize":30,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":72.75,"bottom":480.75,"vCenter":37.5,"hCenter":457.5},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":303,"top":19.5,"height":37,"width":291,"title":"DC2410023-0100","right":595.0000076293945,"bottom":55.24998474121094,"vCenter":449.50000762939453,"hCenter":36.74998474121094,"field":"zddbh","coordinateSync":false,"widthHeightSync":false,"fontSize":33,"textContentVerticalAlign":"middle","qrCodeLevel":0,"qid":"zddbh_1","lineHeight":33,"hideTitle":true},"printElementType":{"title":"这是更新后的元素","type":"text"}}],"paperNumberLeft":568.5,"paperNumberTop":339,"paperNumberDisabled":true,"paperNumberContinue":true,"watermarkOptions":{"content":"vue-plugin-hiprint","rotate":25,"timestamp":true,"format":"YYYY-MM-DD HH:mm"},"panelLayoutOptions":{}}]}


//点击显示表格高亮
function isCellHighlighted(rowIndex, item) {
	return highlightedCells.value.some(hc => hc.rowIndex === rowIndex && hc.item === item);
	console.log(highlightedCells.value)
}
	
const highlightedCells = ref([]);
const selectedSizes = ref([]);
let _table_row = ref('');
//点击表格行事件
function handleSizeClick(rowIndex, item, row) {
	_table_row = row
	// 查找当前单元格是否已高亮  
	const index = highlightedCells.value.findIndex(hc => hc.rowIndex === rowIndex && hc.item === item);
	if (index !== -1) {
		// 如果已高亮，则移除  
		highlightedCells.value.splice(index, 1);
	} else {
		// 如果已经有一个高亮条目，移除第一个高亮条目
		if (highlightedCells.value.length > 0) {
			highlightedCells.value.splice(0, 1);
		}
		// 添加新的高亮信息  
		highlightedCells.value.push({
			rowIndex,
			item
		});
	}
	let newSizeItem = {
		size: item
	};
	const quantityWithParentheses = row[item];
	const match = quantityWithParentheses.match(/^([^()]+)\(([^()]+)\)$/);
	if (match) {
		// console.log("点击尺码包数据",match)
		//获取流水号（包数）
		newSizeItem.serial = match[1];
		//获取数量
		newSizeItem.sl = parseInt(match[2], 10);
		const existingIndex = selectedSizes.value.findIndex(s => s.size === item);
		if (existingIndex !== -1) {
			selectedSizes.value.splice(existingIndex, 1);
		}
		// 清空 selectedSizes 数组
		selectedSizes.value = [];
		selectedSizes.value.push(newSizeItem);
	} else {
		console.error('Invalid match format:', quantityWithParentheses);
	}
}

let _table_print = ref([]);//打印小票数据
let allParams = [];
//补打小票按钮
const add_bdprintxp = () => {
	if (selectedSizes.value.length === 0) {
		ElMessage({
			type: 'warning',
			message: '请选择补打尺码'
		});
		return false;
	}
	console.log(_table_row['组别'])
	if(_table_row['组别'] != add_formData['组别']){
		ElMessage({
			type: 'warning',
			message: '请到对应小组进行补打小票'
		});
		return false;
	}

	let params = {};
	params.order_id = _table_row['子订单编号'];
	params.kh = _table_row['款号'];
	params.ks = _table_row['款式'];
	params.color = _table_row['颜色备注'];
	params.cm = selectedSizes.value[0].size;
	params.sl = selectedSizes.value[0].sl;
	params.sczl_jtbh = _table_row['组别'];
	params.sys_rq = currentDate;
	params.serial = selectedSizes.value[0].serial;
	params.wb = _table_row['尾包'];
	
	const weibao = _table_row['尾包'] === '是' ? '1' : '0';
	const ewm = `${params.order_id},${add_formData['机台号']},3,${params.cm},${params.sl},${weibao},${params.serial}`;

	_table_print.value = [{
		emm: ewm,
		zddbh: params.order_id,
		kh: params.kh,
		pm: params.ks,
		ys: params.color,
		cm: params.cm,
		sl: params.sl,
		zb: params.sczl_jtbh,
		dyrq: currentDates,
		wb: _table_row['尾包'],
		lsh: params.serial
	}];

	const hiprintTemplate = new hiprint.PrintTemplate({
		template: jsondata
	});
	hiprintTemplate.print(_table_print.value);
};



const _print = ref('')
// 打印预览
const add_printxp = async () => {
	console.log("打印小票")
	let cmArray = [cmformdata.cm1, cmformdata.cm2, cmformdata.cm3, cmformdata.cm4, cmformdata.cm5, cmformdata.cm6,
		cmformdata.cm7, cmformdata.cm8, cmformdata.cm9, cmformdata.cm10
	];
	let slArray = [slformdata.sl1, slformdata.sl2, slformdata.sl3, slformdata.sl4, slformdata.sl5, slformdata.sl6,
		slformdata.sl7, slformdata.sl8, slformdata.sl9, slformdata.sl10
	];
	let allParams = []; // 用于存储所有要打印的参数对象  
	let allParamss = ref([]); // 用于存储所有要打印的参数对象
	if (!slArray.some(item => item !== "" && item !== null && item !== undefined)) {
		ElMessage({
			type: 'warning',
			message: '请填写上报数量后再使用打印功能'
		});
		return;
	} else {
		for (let i = 0; i < slArray.length; i++) {
		    if (slArray[i]) {
		        let params = {};
		        params.order_id = add_searchInfo.value;	
		        params.sczl_jtbh = add_formData['组别'];
		        params.gx = add_formData['工序'];
		        params.sys_id = add_formData['人员'];
		        params.wb = add_formData['是否订单尾包'];
		        params.cm = cmArray[i];
		        params.sl = slArray[i];
		        params.sys_rq = currentDate;
				// 流水号（包数）
				_serial.value++;
				console.log('小票打印前的流水号', _serial.value)
				params.serial = padNumber( _serial.value, 3);
		        allParams.push(params);
		        allParamss.value = allParams.map((row) => {
					console.log("row",row)
		            let weibao = add_formData['是否订单尾包'] === '1' ? '是' : '否';
		            // 二维码数据：订单子编号，组别，工序(固定)，尺码，数量，是否尾包(1代表是0代表否)，流水号
		            const ewm =
		                `${row['order_id']},${add_formData['机台号']},3,${row['cm']},${row['sl']},${add_formData['是否订单尾包']},${row['serial']}`;
		            return {
		                emm: ewm,
		                zddbh: row['order_id'],
		                kh: _yskskh.value['款号'],
		                pm: _yskskh.value['款式'],
		                ys: _yskskh.value['颜色备注'],
		                cm: row['cm'],
		                sl: row['sl'],
		                zb: row['sczl_jtbh'],
		                dyrq: currentDates,
		                wb: weibao,
		                lsh: row['serial']
		            };
		        });
		
		        const hiprintTemplate = new hiprint.PrintTemplate({
		            template: jsondata
		        });
		        hiprintTemplate.print(allParamss.value);
		    }
		}
	
	}
};


//报工删除
const delall = ref(true)
const Selection = ref('')
const selectionChange = (selection, type) => {
	const ids = selection.map(item => {
		return item.UniqId
	})
	Selection.value = ids.join(',')
	console.log(Selection.value)
}
const del_delclick = async () => {
	console.log(Selection.value)
	console.log(add_formData['组别'])
	const res1 = await spotcheckdel({UniqId:Selection.value,sys_id:add_formData['组别']})
	if(res1.code === 0){
		ElMessage.success('删除成功')
		Selection.value = ''
		add_onSubmit()
	}
}


// =========== 分页 ===========
// 分页相关的响应式变量
const page = ref(1)
const total = ref(0)
const pageSize = ref(10)
// 分页
const handleCurrentChange = (val) => {
	page.value = val;
	_getStaffList();
};

// 修改页面容量 点击多少条/页
const handleSizeChange = (val) => {
	page.value = 10; //默认显示
	pageSize.value = val;
	_getStaffList();
};
</script>
<style scoped>
	:deep(.el-table__body .status-plan-usage-low) {
	  background: #ff80ff !important;
	}
	:deep(.el-table__body .status-plan-usage-lows) {
	  background: white !important;
	}
	.form-container {
		display: flex;
		flex-wrap: wrap;
	}

	.form-column {
		/*flex: 1;*/
		margin-right: 15px;
		/* 调整列之间的间距 */
	}

	/* 左侧输入框宽度调整 */
	.form-column .el-form-item .el-input {
		width: 150px;
		/* 调整左侧输入框的宽度 */
	}

	/* 媒体查询，根据需要调整断点 */
	@media screen and (max-width: 768px) {
		.form-column {
			flex: 1 0 100%;
			/* 在小屏幕下变成单列布局 */
			margin-right: 0;
		}
	}

	/* 表格复选框大小调整 */
	:deep(.el-checkbox.el-checkbox--small .el-checkbox__inner) {
		width: 30px;
		/* 复选框宽度 */
		height: 20px;
		/* 复选框高度 */
	}

	:deep(.el-checkbox.el-checkbox--small.is-checked .el-checkbox__inner::after) {
		transform: scale(1.2) rotate(45deg);
		/* 调整选中后的对勾大小 */
		top: 5%;
		/* 调整对勾位置 */
		left: 40%;
		/* 调整对勾位置 */
		width: 5px;
		/* 调整对勾宽度 */
		height: 9px;
		/* 调整对勾高度 */
	}

	/*:deep(.el-table td .cell) {*/
	/*  line-height: 30px !important;*/
	/*}*/
	.JKWTree-container {
		display: flex;
	}

	.JKWTree-tree {
		/*width: 300px;*/
		background-color: #fff;
		padding: 10px;
		margin-right: 20px;
	}

	.JKWTree-tree h3 {
		font-size: 15px;
		font-weight: 700;
		margin: 10px 0;
	}

	.JKWTree-content {
		flex: 1;
	}

	/* 图片上传 */
	.upload-box {
		width: 200px;
		height: 200px;
		border: 2px dashed #e2e2e2;
		display: flex;
		justify-content: center;
		align-items: center;
		position: relative;
		cursor: pointer;
	}

	.uploaded-image {
		width: 100%;
		height: 100%;
		object-fit: cover;
	}

	.upload-icon {
		font-size: 40px;
		color: #c0c4cc;
	}

	.file-input {
		display: none;
	}

	.el-table .warning-row {
		background: oldlace;
	}

	:deep(.el-input .is-disabled .cm_input) {
		color: red;
	}

	/* 选中某行时的背景色 */
	:deep(.el-table__body tr.current-row)>td {
		background: #ff80ff !important;
	}
</style>

<style scoped>
	:deep(.el-table td .cell) {
		line-height: 20px !important;
	}

	:deep(.el-tabs__header) {
		margin-bottom: 0;
	}

	.search {
		margin-left: 0px !important;
		margin-right: 10px !important;
	}

	.bt {
		margin-left: 2px !important;
		padding: 3px !important;
		font-size: 12px;
	}

	.el-tabs__header {
		margin: 0px !important;
	}

	.gva-table-box {
		max-width: 1400px;
		padding: 0px !important;
		margin-left: -10px !important;
	}

	.mab {
		margin-bottom: 5px;
	}

	/* 点击按钮改变颜色 */
	.active-button {
		background-color: #ff0000;
	}

	.default-button {
		background-color: #808080;
	}

	::v-deep .el-input_inner {
		font-size: 20px;
		/* 更改为你想要的字体大小 */
	}

	/* 搜索样式 */
	::v-deep .el-input__wrapper #searchInput {
		font-size: 16px;
	}

	::v-deep .el-input__wrapper #jitaihao {
		font-size: 18px;
	}

	::v-deep .el-input__wrapper #gongxu {
		font-size: 18px;
	}

	::v-deep .el-input__wrapper #zubie {
		font-size: 18px;
	}

	::v-deep .el-input__wrapper #renyuan {
		font-size: 18px;
	}

	::v-deep .el-input__wrapper #shuliang {
		font-size: 18px;
		color: red;
	}

	::v-deep .el-input__wrapper #chima {
		font-size: 18px;
	}

	/* 尺码 */
	::v-deep .el-input__wrapper #cm1 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #cm2 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #cm3 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #cm4 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #cm5 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #cm6 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #cm7 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #cm8 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #cm9 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #cm10 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #cm11 {
		font-size: 19px;
	}
	::v-deep .el-input__wrapper #cmtotal {
		font-size: 19px;
	}

	/* 制单数 */
	::v-deep .el-input__wrapper #zdsc1 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #zdsc2 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #zdsc3 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #zdsc4 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #zdsc5 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #zdsc6 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #zdsc7 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #zdsc8 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #zdsc9 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #zdsc10 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #zdtotal {
		font-size: 19px;
	}

	/* 实裁数 */
	::v-deep .el-input__wrapper #scsl1 {
		font-size: 19px;
		color: red !important;
	}

	::v-deep .el-input__wrapper #scsl2 {
		font-size: 19px;
		color: red !important;
	}

	::v-deep .el-input__wrapper #scsl3 {
		font-size: 19px;
		color: red !important;
	}

	::v-deep .el-input__wrapper #scsl4 {
		font-size: 19px;
		color: red !important;
	}

	::v-deep .el-input__wrapper #scsl5 {
		font-size: 19px;
		color: red !important;
	}

	::v-deep .el-input__wrapper #scsl6 {
		font-size: 19px;
		color: red !important;
	}

	::v-deep .el-input__wrapper #scsl7 {
		font-size: 19px;
		color: red !important;
	}

	::v-deep .el-input__wrapper #scsl8 {
		font-size: 19px;
		color: red !important;
	}

	::v-deep .el-input__wrapper #scsl9 {
		font-size: 19px;
		color: red !important;
	}

	::v-deep .el-input__wrapper #scsl10 {
		font-size: 19px;
		color: red !important;
	}

	::v-deep .el-input__wrapper #sctotal {
		font-size: 19px;
		color: red !important;
	}

	/* 数量 */
	::v-deep .el-input__wrapper #sl1 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #sl2 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #sl3 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #sl4 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #sl5 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #sl6 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #sl7 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #sl8 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #sl9 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #sl10 {
		font-size: 19px;
	}

	::v-deep .el-input__wrapper #sctotal {
		font-size: 19px;
	}

	/* 选择历史记录改变颜色 */
	.highlight-cell {
		height: 40px;
		/* 背景 */
		background-color: rgba(190, 79, 79, 0.7) !important;
		/* 使用 Flexbox 布局 */
		display: flex;
		/* 垂直居中 */
		align-items: center;
		/* 水平居中 */
		justify-content: center;
		/* 可选，确保 div 宽度填满单元格 */
		width: 100%;
		/* 可选，确保 padding 和 border 不会增加 div 的宽度 */
		box-sizing: border-box;
	}

	.custom-button-text {
		font-size: 25px;
		/* 或者你想要的任何大小 */
	}
	
	/* 自定义表格样式 */
	.custom-table >>> .el-table {
	  border: 2px solid #333; /* 表格整体边框加深 */
	}
	
	.custom-table >>> .el-table__header-wrapper th {
	  border-bottom: 2px solid #333; /* 表头底部边框加深 */
	}
	
	.custom-table >>> .el-table__body-wrapper td {
	  border: 1px solid #666; /* 表格单元格边框加深 */
	}
	
	.custom-table >>> .el-table__cell {
	  font-size: 20px; /* 单元格字体大小 */
	  font-weight: 600; /* 单元格字体加粗 */
	}
	.number-container {
	  display: flex;
	  flex-wrap: wrap;
	  gap: 4px;
	  margin-top: 3px;
	}
	
	.number-box {
	  display: flex;
	  justify-content: center;
	  align-items: center;
	  width: 40px;
	  height: 40px;
	  background-color: #f2f2f2;
	  border: 1px solid #ddd;
	  border-radius: 8px;
	  font-size: 18px;
	  color: #333;
	  font-weight: bold;
	  transition: background-color 0.3s;
	}
	
	.number-box.green {
		 /* 完成包数（绿色） */
	  background-color: palegreen;
	  color: #155724;
	  border-color: #c3e6cb;
	}
	
	.number-box.red {
	  background-color: red; /* 废弃包数（红色） */
	  color: #721c24;
	  border-color: #f5c6cb;
	}
</style>
