<template>
  <div>
    <!-- 左侧树形结构 -->
    <el-container>
      <el-aside width="250px">
        <div class="JKWTree-tree">
          <h3>手工检验计件单据维护</h3>
          <el-tree :data="treeData" :props="defaultProps" highlight-current="true"
            @node-click="handleNodeClick"></el-tree>
        </div>
      </el-aside>

      <el-container>
        <el-main>
          <!-- 按钮区域 -->
          <div class="gva-table-box">
            <div class="gva-btn-list">
              <el-row :span="6">
                <el-input v-model="positionvalue" placeholder="输入工单编号或产品名称" />
              </el-row>
              <el-button type="primary" :icon="Search" @click="onSearch">搜索</el-button>
              <el-button type="primary"  @click="onAdd">新增</el-button>
			  <el-button type="primary"  @click="onRefresh">刷新质检系数</el-button>
			  <el-button type="primary"  @click="onCountByGdbh">按工单显示</el-button>
			  <el-button type="primary"  @click="onDel">删除</el-button>
              <div style="margin-left: auto;">
                <el-button type="primary" :icon="Download" @click="exportExcel">导出到Excel</el-button>
              </div>
            </div>
            <!-- 数据展示 -->
            <el-table ref="multipleTable" style="width: 100%" tooltip-effect="dark" :data="tableData" row-key="ID"
              highlight-current-row="true" border @selection-change="handleSelectionChange" 
			  :show-overflow-tooltip="true" @row-dblclick="doubleClick">
              <el-table-column type="selection" width="55" />
              <el-table-column align="left" label="工单印件" prop="combinedProp" width="340"/>
              <el-table-column align="left" label="印件工序" prop="combinedProp2" width="340"/>
              <el-table-column align="left" label="日期" prop="sczl_rq" width="120" />
              <el-table-column align="left" label="产量" prop="sczl_cl" width="120" />
              <el-table-column align="left" label="千件工价" prop="千件工价" width="120" />
              <el-table-column align="left" label="检验类别" prop="sczl_检验类别" width="120" />
              <el-table-column align="left" label="废品率系数" prop="sczl_废品率系数" width="120" />
              <el-table-column align="left" label="日定额" prop="日定额" width="120" />
              <el-table-column align="left" label="组长编号" prop="sczl_bh0" width="120" />
			  <el-table-column align="left" label="组长姓名" prop="员工姓名" width="120" />
			  <el-table-column align="left" label="流程单备注" prop="qczl_NumDesc" width="120" />
			  <el-table-column align="left" label="创建用户" prop="sys_id" width="120" />
              <el-table-column align="left" label="创建时间" prop="sys_rq" width="160" />
              <el-table-column align="left" label="修改时间" prop="mod_rq" width="160" />
              <el-table-column align="left" label="UNIQID" prop="UniqId" width="120" />
            </el-table>
            <!-- 分页 -->
            <div class="gva-pagination">
              <el-pagination layout="total, sizes, prev, pager, next, jumper" v-model:current-page="page"
                v-model:page-size="limit"
                :page-sizes="[10, 30, 50, 100]" :total="total" @current-change="handleCurrentChange"
                @size-change="handleSizeChange" />
            </div>
          </div>
          <!-- 弹出框 -->
          <el-dialog v-model="dialogFormVisible" :before-close="closeDialog" :title="type === 'create' ? '添加' : '修改'"
            destroy-on-close width="1200px">
            <!-- <el-scrollbar height="500px"> -->
            <el-form :model="formData" label-position="left" ref="elFormRef" :rules="rule">

              <el-row :gutter="20">
                <el-col :span="4">
                  <el-form-item label="日期" prop="id">
                    <el-input v-model="formData.sczl_rq" :clearable="true" placeholder="" />
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="组别" prop="name">
                    <el-row :gutter="20">
                      <el-col :span="12">
                        <el-input v-model="formData.sczl_bzdh" :clearable="true" placeholder="" />
                      </el-col>                      
                    </el-row>
                  </el-form-item>
                </el-col>
				<el-col :span="4">
				  <el-form-item label="组长" prop="name">
				    <el-row :gutter="20">
				      <el-col :span="12">
				        <el-input v-model="formData.sczl_bh0" @keyup.enter.native="getygsubmit($event, '0')":clearable="true" placeholder="" />
				      </el-col>
						<el-col :span="12">
						  <el-input v-model="formData.sczl_bh0_name" :clearable="true" placeholder="" />
						</el-col>  
				    </el-row>
				  </el-form-item>
				</el-col>
				<el-col :span="4">
				  <el-form-item label="箱数" prop="name">
				    <el-row :gutter="20">
				      <el-col :span="2">
				        <el-input v-model="formData.sczl_cl0" :clearable="true" placeholder="" />
				      </el-col>                      
				    </el-row>
				  </el-form-item>
				</el-col>
				<el-col :span="3">
				  <el-form-item label="每箱数" prop="name">
				    <el-row :gutter="20">
				      <el-col :span="2">
				        <el-input v-model="formData.sczl_fp0" :clearable="true" placeholder="" />
				      </el-col>                      
				    </el-row>
				  </el-form-item>
				</el-col>
              </el-row>

              <el-row :gutter="20">
                <el-col :span="20">
                  <el-row :gutter="20">
                    <el-col :span="5">
                      <el-form-item label="工单编号" prop="id">
                        <el-input v-model="formData.sczl_gdbh" @keyup.enter="getGxMcsubmit" :clearable="true" placeholder="" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="5">                      
                        <el-input v-model="formData.sczl_yjgx" :clearable="true" placeholder="" />
                    </el-col>
					<el-col :span="5">
					    <el-input v-model="formData.sczl_gxmc" :clearable="true" placeholder="" />
					</el-col>
					<el-col :span="5">
					    <el-input v-model="formData.yj_yjmc" :clearable="true" placeholder="" />
					</el-col>
                  </el-row>
                </el-col>
              </el-row>
			  			  
			  <el-row :gutter="20">
			     <el-col :span="4">
			       <el-form-item label="产量合计" prop="id">
			         <el-input v-model="formData.sczl_cl" :clearable="true" placeholder="" />
			       </el-form-item>
			     </el-col>
			     <el-col :span="6">          
			         <el-row :gutter="20">
			           <el-col :span="12">
						<el-form-item label="定额代号" prop="id">
			             <el-input v-model="formData.sczl_dedh" @keyup.enter.native="getDedhsubmit" :clearable="true" placeholder="" />
						</el-form-item>
			           </el-col>
			         </el-row>
			     </el-col>
			     <el-col :span="3">
			       <el-form-item label="检验类别" prop="name">
			         <el-input v-model="formData.sczl_检验类别" :clearable="true" placeholder="" />
			       </el-form-item>
			     </el-col>
				 <el-col :span="3">
				   <el-form-item label="废品率系数" prop="name">
				     <el-input v-model="formData.sczl_废品率系数" :clearable="true" placeholder="" />
				   </el-form-item>
				 </el-col>
			   </el-row>
			  
			  <el-row :gutter="20">
			     <el-col :span="4">
			       <el-form-item label="计时时数" prop="id">
			         <el-input v-model="formData.sczl_jsss" :clearable="true" placeholder="" />
			       </el-form-item>
			     </el-col>
			     <el-col :span="6">          
			         <el-row :gutter="20">
			           <el-col :span="12">
						 <el-form-item label="冲月定额" prop="id">
			             <el-input v-model="formData.sczl_冲定额" :clearable="true" placeholder="" />
						 </el-form-item>
			           </el-col>
			         </el-row>
			     </el-col>
			   </el-row>
			   
			   
			   <el-row :gutter="1">
			      <el-col :span="4">
			        <el-form-item label="流程单号" prop="id">
			          <el-input v-model="formData.流程单号1" :clearable="true" placeholder="" />
			        </el-form-item>
			      </el-col>
				  <el-col :span="1">			  			
				    <el-input v-model="formData.流程单号2" :clearable="true" placeholder="" />
				  </el-col>
				  <el-col :span="1">
				    <el-input v-model="formData.流程单号3" :clearable="true" placeholder="" />
				  </el-col>
				  <el-col :span="1">
				    <el-input v-model="formData.流程单号4" :clearable="true" placeholder="" />
				  </el-col>
				  <el-col :span="1">
				    <el-input v-model="formData.流程单号5" :clearable="true" placeholder="" />
				  </el-col>
				  <el-col :span="1">
				    <el-input v-model="formData.流程单号6" :clearable="true" placeholder="" />
				  </el-col>
				  <el-col :span="1">
				    <el-input v-model="formData.流程单号7" :clearable="true" placeholder="" />
				  </el-col>
				  <el-col :span="1">
				    <el-input v-model="formData.流程单号8" :clearable="true" placeholder="" />
				  </el-col>
				  <el-col :span="1">
				    <el-input v-model="formData.流程单号9" :clearable="true" placeholder="" />
				  </el-col>
			      <el-col :span="6">          
			          <el-row :gutter="20">
			            <el-col :span="12">
			   						 <el-form-item label="备注" prop="id">
			              <el-input v-model="formData.qczl_NumDesc" :clearable="true" placeholder="" />
			   						 </el-form-item>
			            </el-col>
			          </el-row>
			      </el-col>
			    </el-row>
			  
			  <el-row :gutter="10">
				  <el-col :span="2">
					
				  </el-col>
			    <el-col :span="2">
			      <span>员工编号</span>
			    </el-col>
			    <el-col :span="2">
			      <span>员工姓名</span>
			    </el-col>
			    <el-col :span="2">
			      <span>箱数</span>
			    </el-col>
			    <el-col :span="2">
			      <span>每箱数量</span>
			    </el-col>
			    <el-col :span="2">
			      <span></span>
			    </el-col>
				<el-col :span="2">
				  <span>员工编号</span>
				</el-col>
				<el-col :span="2">
				  <span>员工姓名</span>
				</el-col>
				<el-col :span="2">
				  <span>箱数</span>
				</el-col>
				<el-col :span="2">
				  <span>每箱数量</span>
				</el-col>
			  </el-row>
			  
			  <el-row :gutter="10" style="margin-top: 10px;">
				 <el-col :span="2">
				   <span></span>
				 </el-col>
			     <el-col :span="2">
			       <el-input v-model="formData.sczl_bh1" :clearable="true" @keyup.enter.native="getygsubmit($event, '1')"  placeholder="" />
			     </el-col>
			     <el-col :span="2">
			       <el-input v-model="formData.sczl_bh1_name" :clearable="true" placeholder="" />
			     </el-col>
			     <el-col :span="2">
			       <el-input v-model="formData.sczl_cl1" :clearable="true" placeholder="" />
			     </el-col>
			     <el-col :span="2">
			       <el-input v-model="formData.sczl_fp1" :clearable="true" placeholder="" />
			     </el-col>
			     <el-col :span="2">			       
			     </el-col>
				<el-col :span="2">
				  <el-input v-model="formData.sczl_bh7" @keyup.enter.native="getygsubmit($event, '7')" :clearable="true" placeholder="" />
				</el-col>
				<el-col :span="2">
				  <el-input v-model="formData.sczl_bh7_name" :clearable="true" placeholder="" />
				</el-col>
				<el-col :span="2">
				  <el-input v-model="formData.sczl_cl7" :clearable="true" placeholder="" />
				</el-col>
				<el-col :span="2">
				  <el-input v-model="formData.sczl_fp7" :clearable="true" placeholder="" />
				</el-col>
			   </el-row>	
						 
			  <el-row :gutter="10" style="margin-top: 10px;">
			  				 <el-col :span="2">
			  				   <span></span>
			  				 </el-col>
			     <el-col :span="2">
			       <el-input v-model="formData.sczl_bh2" @keyup.enter.native="getygsubmit($event, '2')" :clearable="true" placeholder="" />
			     </el-col>
			     <el-col :span="2">
			       <el-input v-model="formData.sczl_bh2_name" :clearable="true" placeholder="" />
			     </el-col>
			     <el-col :span="2">
			       <el-input v-model="formData.sczl_cl2" :clearable="true" placeholder="" />
			     </el-col>
			     <el-col :span="2">
			       <el-input v-model="formData.sczl_fp2" :clearable="true" placeholder="" />
			     </el-col>
			     <el-col :span="2">			       
			     </el-col>
			  				<el-col :span="2">
			  				  <el-input v-model="formData.sczl_bh8" @keyup.enter.native="getygsubmit($event, '8')" :clearable="true" placeholder="" />
			  				</el-col>
			  				<el-col :span="2">
			  				  <el-input v-model="formData.sczl_bh8_name" :clearable="true" placeholder="" />
			  				</el-col>
			  				<el-col :span="2">
			  				  <el-input v-model="formData.sczl_cl8" :clearable="true" placeholder="" />
			  				</el-col>
			  				<el-col :span="2">
			  				  <el-input v-model="formData.sczl_fp8" :clearable="true" placeholder="" />
			  				</el-col>
			   </el-row>
				
				<el-row :gutter="10" style="margin-top: 10px;">
								 <el-col :span="2">
								   <span></span>
								 </el-col>
				   <el-col :span="2">
				     <el-input v-model="formData.sczl_bh3" @keyup.enter.native="getygsubmit($event, '3')" :clearable="true" placeholder="" />
				   </el-col>
				   <el-col :span="2">
				     <el-input v-model="formData.sczl_bh3_name" :clearable="true" placeholder="" />
				   </el-col>
				   <el-col :span="2">
				     <el-input v-model="formData.sczl_cl3" :clearable="true" placeholder="" />
				   </el-col>
				   <el-col :span="2">
				     <el-input v-model="formData.sczl_fp3" :clearable="true" placeholder="" />
				   </el-col>
				   <el-col :span="2">			       
				   </el-col>
								<el-col :span="2">
								  <el-input v-model="formData.sczl_bh9" @keyup.enter.native="getygsubmit($event, '9')" :clearable="true" placeholder="" />
								</el-col>
								<el-col :span="2">
								  <el-input v-model="formData.sczl_bh9_name" :clearable="true" placeholder="" />
								</el-col>
								<el-col :span="2">
								  <el-input v-model="formData.sczl_cl9" :clearable="true" placeholder="" />
								</el-col>
								<el-col :span="2">
								  <el-input v-model="formData.sczl_fp9" :clearable="true" placeholder="" />
								</el-col>
				 </el-row>
				 
				 
				<el-row :gutter="10" style="margin-top: 10px;">
								 <el-col :span="2">
								   <span></span>
								 </el-col>
				   <el-col :span="2">
				     <el-input v-model="formData.sczl_bh4" @keyup.enter.native="getygsubmit($event, '4')" :clearable="true" placeholder="" />
				   </el-col>
				   <el-col :span="2">
				     <el-input v-model="formData.sczl_bh4_name" :clearable="true" placeholder="" />
				   </el-col>
				   <el-col :span="2">
				     <el-input v-model="formData.sczl_cl4" :clearable="true" placeholder="" />
				   </el-col>
				   <el-col :span="2">
				     <el-input v-model="formData.sczl_fp4" :clearable="true" placeholder="" />
				   </el-col>
				   <el-col :span="2">			       
				   </el-col>
								<el-col :span="2">
								  <el-input v-model="formData.sczl_bh10" @keyup.enter.native="getygsubmit($event, '10')" :clearable="true" placeholder="" />
								</el-col>
								<el-col :span="2">
								  <el-input v-model="formData.sczl_bh10_name" :clearable="true" placeholder="" />
								</el-col>
								<el-col :span="2">
								  <el-input v-model="formData.sczl_cl10" :clearable="true" placeholder="" />
								</el-col>
								<el-col :span="2">
								  <el-input v-model="formData.sczl_fp10" :clearable="true" placeholder="" />
								</el-col>
				 </el-row>
				  
				  
				  <el-row :gutter="10" style="margin-top: 10px;">
				  				 <el-col :span="2">
				  				   <span></span>
				  				 </el-col>
				     <el-col :span="2">
				       <el-input v-model="formData.sczl_bh5" @keyup.enter.native="getygsubmit($event, '5')" :clearable="true" placeholder="" />
				     </el-col>
				     <el-col :span="2">
				       <el-input v-model="formData.sczl_bh5_name" :clearable="true" placeholder="" />
				     </el-col>
				     <el-col :span="2">
				       <el-input v-model="formData.sczl_cl5" :clearable="true" placeholder="" />
				     </el-col>
				     <el-col :span="2">
				       <el-input v-model="formData.sczl_fp5" :clearable="true" placeholder="" />
				     </el-col>
				     <el-col :span="2">			       
				     </el-col>
				  				<el-col :span="2">
				  				  <el-input v-model="formData.sczl_bh11" @keyup.enter.native="getygsubmit($event, '11')" :clearable="true" placeholder="" />
				  				</el-col>
				  				<el-col :span="2">
				  				  <el-input v-model="formData.sczl_bh11_name" :clearable="true" placeholder="" />
				  				</el-col>
				  				<el-col :span="2">
				  				  <el-input v-model="formData.sczl_cl11" :clearable="true" placeholder="" />
				  				</el-col>
				  				<el-col :span="2">
				  				  <el-input v-model="formData.sczl_fp11" :clearable="true" placeholder="" />
				  				</el-col>
				   </el-row>
				   
				   
				   <el-row :gutter="10" style="margin-top: 10px;">
				   				 <el-col :span="2">
				   				   <span></span>
				   				 </el-col>
				      <el-col :span="2">
				        <el-input v-model="formData.sczl_bh6" @keyup.enter.native="getygsubmit($event, '6')" :clearable="true" placeholder="" />
				      </el-col>
				      <el-col :span="2">
				        <el-input v-model="formData.sczl_bh6_name" :clearable="true" placeholder="" />
				      </el-col>
				      <el-col :span="2">
				        <el-input v-model="formData.sczl_cl6" :clearable="true" placeholder="" />
				      </el-col>
				      <el-col :span="2">
				        <el-input v-model="formData.sczl_fp6" :clearable="true" placeholder="" />
				      </el-col>
				      <el-col :span="2">			       
				      </el-col>
				   				<el-col :span="2">
				   				  <el-input v-model="formData.sczl_bh12" @keyup.enter.native="getygsubmit($event, '12')" :clearable="true" placeholder="" />
				   				</el-col>
				   				<el-col :span="2">
				   				  <el-input v-model="formData.sczl_bh12_name" :clearable="true" placeholder="" />
				   				</el-col>
				   				<el-col :span="2">
				   				  <el-input v-model="formData.sczl_cl12" :clearable="true" placeholder="" />
				   				</el-col>
				   				<el-col :span="2">
				   				  <el-input v-model="formData.sczl_fp12" :clearable="true" placeholder="" />
				   				</el-col>
				    </el-row>
					
													 
						 
					<el-row :gutter="20">
					   <el-col :span="20">
						 <el-form-item label="其他备注" prop="id">
						   <el-input v-model="formData.sczl_desc" :clearable="true" placeholder="" />
						 </el-form-item>
					   </el-col>			  				
					 </el-row>
			
            </el-form>
			
			<el-dialog
			  v-model="dialogSelectVisible"
			  title="选择"
			  destroy-on-close
			  width="600px"
						>
			  <el-table
			    tooltip-effect="dark"
			    :data="selectData"
			    row-key="ID"
			    highlight-current-row="true"
			    border
			    style="width:100%"
			    @row-dblclick="handleSelectClick"
			  >
			    <el-table-column
			      prop="Gd_cpmc"
			      label="印件名称"
			      width="340"
			    />
						  <el-table-column
						    prop="jyGx"
						    label="检验工序"
						    width="150"
						  />
			    <el-table-column
			      prop="Gy0_gxmc"
			      label="工序名称"
			      width="150"
			    />			 
			  </el-table>
			</el-dialog>

            <template #footer>
              <div class="dialog-footer">
                <el-button @click="closeDialog">取 消</el-button>
                <el-button type="primary" @click="enterDialog">确 定</el-button>
              </div>
            </template>
          </el-dialog>

			<el-dialog
		    v-model="GetDedhVisible"
		    title="选择"
		    destroy-on-close
		    width="600px"
		  			>		     
		       <el-aside width="250px">
		         <div class="JKWTree-tree">		          
		           <el-tree :data="GetDedhtreeData" :props="defaultProps" highlight-current="true"
		             @node-click="GetDedhhandleNodeClick" @node-dblclick="handleNodeDoubleClick"></el-tree>
		         </div>
		       </el-aside>		       
		  </el-dialog>

        </el-main>
      </el-container>
    </el-container>

  </div>
</template>

<script setup>
import {
  getDateList,
  getInspectCount,
  shougonglocate,
  shougonggetInfo,
  shougonggetGxMc,
  shougonggetDedh,
  shougonggetScrapFactor,
  shougongedit,
  shougongdel,
  getYg,
  getInspectCountByGdbh,
  inspectadd
} from '@/api/jixiaoguanli/jitairibaobiao'

// 全量引入格式化工具 请按需保留
import { getDictFunc, formatDate, formatBoolean, filterDict, ReturnArrImg, onDownloadFile } from '@/utils/format'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Search, Refresh, Download } from '@element-plus/icons-vue'
import { ref, reactive, onMounted, onBeforeMount } from 'vue'
import { getPackingSideTable, getPackingTable } from '@/api/mes_api_gty/myapi'

defineOptions({
  name: '06-packingDocuments'
})

// 侧边栏数据请求
const treeData = reactive([]);
const getTabdata = async () => {
    //接口调用函数
    const response  = await getInspectCount();
	console.log(response)
	
const transformedData = response.data.map(item => ({
	      label: `${item.date.replace(/-/g, '.')}【单据数: ${item.counts}张】`,
	      children: item.sys.map(sysItem => ({
	        label: `${sysItem.sys_id} 【记录数: ${sysItem.count}张】`,
	        params: {
	          date: item.date.replace(/-/g, '.'),
	          sys_id: sysItem.sys_id,
	          total: sysItem.count,
	        },
	      })),
	    }));
	    treeData.splice(0, treeData.length, ...transformedData);

	}

getTabdata();

// 自动化生成的字典（可能为空）以及字段
const formData = ref({
		  sczl_rq: '',
          sczl_bzdh: '',
          sczl_bh0: '',
          sczl_bh0_name: '',
          sczl_cl0: '',
          sczl_fp0: '',
          sczl_gdbh: '',
          sczl_yjgx: '',
          sczl_gxmc: '',
          yj_yjmc: '',
          sczl_cl: '',
          sczl_dedh: '',
          sczl_检验类别: '',
          sczl_废品率系数: '',
          sczl_jsss: '',
          sczl_冲定额: '',
          流程单号1: '',
          流程单号2: '',
          流程单号3: '',
          流程单号4: '',
          流程单号5: '',
          流程单号6: '',
          流程单号7: '',
          流程单号8: '',
          流程单号9: '',
          qczl_NumDesc: '',
          sczl_desc: '',
          sczl_bh1: '',
          sczl_bh2: '',
          sczl_bh3:'',
          sczl_bh4: '',
          sczl_bh5: '',
          sczl_bh6: '',
          sczl_bh7: '',
          sczl_bh8: '',
          sczl_bh9: '',
          sczl_bh10: '',
          sczl_bh11: '',
          sczl_bh12: '',
          sczl_bh1_name: '',
          sczl_bh2_name: '',
          sczl_bh3_name: '',
          sczl_bh4_name: '',
          sczl_bh5_name: '',
          sczl_bh6_name: '',
          sczl_bh7_name: '',
          sczl_bh8_name: '',
          sczl_bh9_name: '',
          sczl_bh10_name: '',
          sczl_bh11_name: '',
          sczl_bh12_name: '',
          sczl_cl1: '',
          sczl_cl2: '',
          sczl_cl3: '',
          sczl_cl4: '',
          sczl_cl5: '',
          sczl_cl6: '',
          sczl_cl7: '',
          sczl_cl8: '',
          sczl_cl9: '',
          sczl_cl10: '',
          sczl_cl11:'',
          sczl_cl12: '',
          sczl_fp1: '',
          sczl_fp2: '',
          sczl_fp3: '',
          sczl_fp4: '',
          sczl_fp5: '',
          sczl_fp6: '',
          sczl_fp7: '',
          sczl_fp8: '',
          sczl_fp9: '',
          sczl_fp10: '',
          sczl_fp11: '',
          sczl_fp12: '',
})

// 验证规则
const rule = reactive({
})

const elFormRef = ref()
const elSearchFormRef = ref()

// =========== 表格控制部分 ===========
const tableData = reactive([])
const detailData = reactive([])
const total = ref(0)
const page = ref(1)
const limit = ref(10)
const searchInfo = ref('')
const params = {
  type: '',
  date: '',
  sys_id: '',
  gdbh: '',
}

// 分页设置
const handleSizeChange = (val) => {
  switch (params.type) {
    case 'getTableData':
      getTableData()
      break
    case 'getLocateTable':
      GetLocate()
      break
    default:
      break
  }
}

// 页面跳转
const handleCurrentChange = (val) => {
 switch (params.type) {
   case 'getTableData':
     getTableData()
     break
   case 'getLocateTable':
     GetLocate()
     break
   default:
     break
 }
}

const getTableData = async() => {
  // const response = await getDateList(params);
  // console.log(response)
  // if (response.code === 0) {
  //   const processedData = response.data.data.map(item => {
  //     return {
  //       ...item,
  //       combinedProp: item.sczl_gdbh + '--'+item.yj_yjmc,
		// combinedProp2: item.sczl_yjgx + '-'+item.sczl_gxmc
  //     };
  //   });
  //   tableData.splice(0, tableData.length, ...processedData);
  // }
  
  const response = await getDateList({
    date: params.date, sys_id: params.sys_id,
    page: page.value.toString(), limit: limit.value.toString(),
	
  })
  if (response.code === 0) {
	  console.log(response)
    const processedData = response.data.data.map(item => {
      return {
        ...item,
        combinedProp: item.sczl_gdbh + '--'+item.yj_yjmc,
        combinedProp2: item.sczl_yjgx + '-'+item.sczl_gxmc
      };
    });
    tableData.splice(0, tableData.length, ...processedData);
  }
}

const handleNodeClick = (node,check) => {
 //存放当前节点的nodeId
   if (node.params) {
    params.date = node.params.date.replace(/\./g, '-');
    params.sys_id = node.params.sys_id;
    total.value = node.params.total;
	   params.type = 'getTableData'
	    page.value = 1
    getTableData();
  }
}
//定位
const GetLocate = async () => {
  const response = await shougonglocate({
    gdbh: params.gdbh,
    page: page.value.toString(), limit: limit.value.toString(),
  })
  console.log(response)
  if (response.code === 0) {
    const processedData = response.data.rows.map(item => {
      return {
        ...item,
        combinedProp: item.sczl_gdbh + '--'+item.yj_yjmc,
        combinedProp2: item.sczl_yjgx + '-'+item.sczl_gxmc
      };
    });
	  total.value = response.data.total
    tableData.splice(0, tableData.length, ...processedData);
  }
}
let positionvalue=ref()
// 搜索
function onSearch() {
	params.gdbh = positionvalue.value
	params.type = 'getLocateTable'
	page.value = 1
	GetLocate()
}
//获取详细信息
const GetInfo = async (value) => {
  const response = await shougonggetInfo({UniqId:value});
  console.log(response) 
  if (response.code === 0) {
	formData.value=response.data;
  }
}
//获取员工信息
const GetYg = async (value,inputName) => {
  const response = await getYg({sczl_bh:value});
  console.log(response) 
  if (response.code === 0) {
	console.log(response.data.ygxm) 
	let Bname = 'sczl_bh' + inputName+'_name';
	formData.value[Bname]=response.data.ygxm
	// console.log(formData.value[Bname])
  }
}
//员工编号回车事件
const getygsubmit = (event, inputName) => {

	  console.log(inputName)
	 
		  let combinedString = 'sczl_bh' + inputName;
		   console.log(combinedString)
		  //  let variableName = 'sczl_gdbh'+inputName;
		   let variableValue = eval('formData.value.' + combinedString);
		   console.log(variableValue)
		   GetYg(variableValue,inputName)  
}
//工单编号回车事件
const getGxMcsubmit = async() => {

  console.log(formData.value.sczl_gdbh) 
  GetGxMc()
}
const dialogSelectVisible = ref(false)
const selectData = reactive([])
//查询印件工序及产品名称
const GetGxMc = async () => {
  console.log(formData.value.sczl_gdbh)
  const response = await shougonggetGxMc({gdbh:formData.value.sczl_gdbh});
  console.log(response) 
 
  if (response.code === 0) {
	  if(response.data.length==1){
	  const { Gd_cpmc, Gy0_yjno, Gy0_gxh, Gy0_gxmc,jyGx} = response.data[0]
	  formData.value.yj_yjmc=Gd_cpmc
	  formData.value.sczl_gxmc=Gy0_gxmc
	  formData.value.sczl_yjgx=jyGx
	  console.log(Gy0_gxmc)
	  console.log(formData.value.sczl_gxmc)	  
	  }else{
		  
		  selectData.splice(0, selectData.length, ...response.data)
		  dialogSelectVisible.value=true
	  }
	// console.log(response.data.ygxm) 
	// let Bname = 'sczl_bh' + inputName+'_name';
	// formData.value[Bname]=response.data.ygxm
	// // console.log(formData.value[Bname])
	// console.log(response.data.length)
  }
}
// 处理选择框
const handleSelectClick = (row, column, event) => {
  const { Gd_cpmc, Gy0_yjno, Gy0_gxh, Gy0_gxmc,jyGx } = row
  formData.value.yj_yjmc=Gd_cpmc
  formData.value.sczl_gxmc=Gy0_gxmc
  formData.value.sczl_yjgx=jyGx
  dialogSelectVisible.value = false
}
//获取定额代号
const GetDedh = async (value) => {
  const response = await shougonggetDedh();
  console.log(response)
  const treeData = {};
  if(response.code==0){
	  
	  // 遍历接口返回的数据，构建父子关系
response.data.bh_mc.forEach(item => {
  if (item.sys_bh === response.data.sys_bh) {
    if (!treeData[item.sys_bh]) {
      treeData[item.sys_bh] = { label: item.sys_bh, children: [] };
	  console.log('2222')
    }
    treeData[item.sys_bh+sys_mc].children.push({ label: item.sys_bh + item.sys_mc, params: { sys_bh: item.sys_bh } });
	console.log('1333')
  } else if (item.sys_bh.startsWith(response.data.sys_bh)) {
    if (!treeData[response.data.sys_bh]) {
      treeData[response.data.sys_bh] = { label: response.data.sys_bh+response.data.sys_mc, children: [] };
	  console.log()
    }
    treeData[response.data.sys_bh].children.push({ label: item.sys_bh + item.sys_mc, params: { sys_bh: item.sys_bh } });
	console.log('1111')
  }
});
      // 将父子关系转换为数组
      const transformedData = Object.values(treeData);
	  console.log(transformedData)
	  GetDedhtreeData = transformedData;
	  
	   // const treeData = fillDataToTree(response);
	   // console.log(treeData)
	   // // GetMachineDedhtreeData=treeData
	   // GetMachineDedhtreeData.splice(0, GetMachineDedhtreeData.length, ...treeData);
	   // const GetMachineDedhtreeData=
	    GetDedhVisible.value=true
		console.log(formData)
  }

}
//定额代号树形结构单机
const GetDedhhandleNodeClick = (node,check,nodeData) => {
  //存放当前节点的nodeId
  //存放当前节点的nodeId
  if (node.params) {
       // 点击的是父节点
       // 执行相应的父节点单击事件处理逻辑
	 //   console.log(node.params)
	    formData.value.sczl_dedh=node.params.sys_bh
		// console.log(formData.value.sczl_dedh)
		GetDedhVisible.value=false
		console.log(node.params)
     } else {
       // 点击的是子节点
       // 执行相应的子节点单击事件处理逻辑
    //    console.log('11111');
	   // console.log(node.params)
       // 例如，您可以在这里执行子节点单击事件触发的操作
     }
}
let GetDedhtreeData = reactive([]);
const GetDedhVisible = ref(false)
//定额代号回车事件
const getDedhsubmit = () => {

	 GetDedh()
}
//刷新废品率系数
const GetScrapFactor = async (value) => {
  const response = await shougonggetScrapFactor(value);
  if(response.code==0){
	console.log(response.data.num)
	const rowIndex = tableData.findIndex(row => row.UniqId === lastCellValue);
	console.log(rowIndex)
	tableData[rowIndex].sczl_废品率系数 = response.data.num;
  }
  // console.log(response)
  // const rowIndex = tableData.findIndex(row => row.UniqId === 123);
}
const ADD=ref('0')
//新增
function onAdd() {
	ADD.value='新增'
	console.log(ADD.value)
	dialogFormVisible.value = true
	// Productionadd()
}
const ScrapFactor={
	gdbh:'',
	yjno:'',
	gxh:'',
	type:'',
}
// 刷新废品率系数
function onRefresh() {
	GetScrapFactor(ScrapFactor)
}

// 更新数据
const updateDetailData = async() => {
  const restoredData = {
   UniqId: lastCellValue,
   sczl_rq: formData.value.sczl_rq,
   sczl_bzdh: formData.value.sczl_bzdh,
   sczl_bh0: formData.value.sczl_bh0,
   sczl_cl0: formData.value.sczl_cl0,
   sczl_fp0: formData.value.sczl_fp0,
   sczl_gdbh: formData.value.sczl_gdbh,
   sczl_yjgx: formData.value.sczl_yjgx,
   sczl_gxmc: formData.value.sczl_gxmc,
   sczl_cl:formData.value.sczl_cl,
   sczl_dedh: formData.value.sczl_dedh,
   sczl_检验类别: formData.value.sczl_检验类别,
   sczl_废品率系数: formData.value.sczl_废品率系数,
   sczl_jsss: formData.value.sczl_jsss,
   sczl_冲定额: formData.value.sczl_冲定额,
   qczl_NumDesc:formData.value.流程单号1,
   qczl_NumDesc1: formData.value.流程单号2,
   qczl_NumDesc12: formData.value.流程单号3,
   qczl_NumDesc13: formData.value.流程单号4,
   qczl_NumDesc14: formData.value.流程单号5,
   qczl_NumDesc15: formData.value.流程单号6,
   qczl_NumDesc16: formData.value.流程单号7,
   qczl_NumDesc17: formData.value.流程单号8,
   qczl_NumDesc18: formData.value.流程单号9,
   sczl_desc: formData.value.sczl_desc,
   sczl_bh1: formData.value.sczl_bh1,
   sczl_bh2: formData.value.sczl_bh2,
   sczl_bh3:formData.value.sczl_bh3,
   sczl_bh4: formData.value.sczl_bh4,
   sczl_bh5: formData.value.sczl_bh5,
   sczl_bh6: formData.value.sczl_bh6,
   sczl_bh7: formData.value.sczl_bh7,
   sczl_bh8: formData.value.sczl_bh8,
   sczl_bh9: formData.value.sczl_bh9,
   sczl_bh10: formData.value.sczl_bh10,
   sczl_bh11: formData.value.sczl_bh11,
   sczl_bh12: formData.value.sczl_bh12,
   sczl_cl1: formData.value.sczl_cl1,
   sczl_cl2: formData.value.sczl_cl2,
   sczl_cl3: formData.value.sczl_cl3,
   sczl_cl4: formData.value.sczl_cl4,
   sczl_cl5: formData.value.sczl_cl5,
   sczl_cl6: formData.value.sczl_cl6,
   sczl_cl7: formData.value.sczl_cl7,
   sczl_cl8: formData.value.sczl_cl8,
   sczl_cl9: formData.value.sczl_cl9,
   sczl_cl10: formData.value.sczl_cl10,
   sczl_cl11:formData.value.sczl_cl11,
   sczl_cl12: formData.value.sczl_cl12,
   sczl_fp1: formData.value.sczl_fp1,
   sczl_fp2: formData.value.sczl_fp2,
   sczl_fp3: formData.value.sczl_fp3,
   sczl_fp4: formData.value.sczl_fp4,
   sczl_fp5: formData.value.sczl_fp5,
   sczl_fp6: formData.value.sczl_fp6,
   sczl_fp7: formData.value.sczl_fp7,
   sczl_fp8: formData.value.sczl_fp8,
   sczl_fp9: formData.value.sczl_fp9,
   sczl_fp10: formData.value.sczl_fp10,
   sczl_fp11: formData.value.sczl_fp11,
   sczl_fp12: formData.value.sczl_fp12,
   sys_id:'[1013/洪丽]',
  }
  // detailData.table.forEach((item, index, array) => {
  //   const num = index + 1
  //   restoredData[`sczl_gdbh${num}`] = item.sczl_gdbh
  //   restoredData[`sczl_yjGx${num}`] = item.sczl_yjGx
  //   restoredData[`sczl_gxmc${num}`] = item.sczl_gxmc
  //   // restoredData[`Gd_cpmc${num}`] = item.Gd_cpmc
  //   restoredData[`sczl_cl${num}`] = item.sczl_cl
  //   restoredData[`sczl_PgCl${num}`] = item.sczl_PgCl
  //   restoredData[`sczl_clAdd${num}`] = item.sczl_clAdd
  // })
  if(ADD.value=='新增'){
  	 // console.log('新增')
  	 console.log('新增')
  	 console.log(ADD.value)
  	 console.log(restoredData)
  	 const response = await inspectadd(restoredData);
  	 // ADD.value='1'
  	 // console.log(ADD.value)
  	 ADD.value='0'
  	 console.log(response)
  	 
  }else{
  	const response = await shougongedit(restoredData);
  	 console.log('修改')
  	  console.log(ADD.value)
  	  console.log(response)
  	 // ADD.value='0'
  	 // console.log(ADD.value)
  }
 //  console.log(restoredData)
 //    console.log(lastCellValue)
 //    formData.value.UniqId=lastCellValue
 //    console.log(formData)
	// restoredData.UniqId='5'
   
  // console.log(FormData)
  // console.log(response)
}
// 删除
function onDel() {
	Del()
}

//删除
const Del = async () => {
  const response = await shougongdel({UniqId:lastCellValue});
  if (response.code === 0) {
	console.log(333)
  }
  getTableData()
}
// 按工单显示
function onCountByGdbh() {
	CountByGdbh()
}
//按工单显示
const CountByGdbh = async () => {
  const response = await getInspectCountByGdbh();
  // console.log(response)
  if (response.code === 0) {
	  console.log(response)
	  
	const transformedData = response.data.map(item => ({
		      label: `${item.sczl_gdbh+item.cpmc}`,
		      children: item.sys.map(sysItem => ({
		        label: `${sysItem.sys_id} 【记录数: ${sysItem.count}张】`,
		        params: {
		          date: item.sczl_gdbh,
		          sys_id: sysItem.sys_id,
		          total: sysItem.count,
		        },
		      })),
		    }));
		    treeData.splice(0, treeData.length, ...transformedData);
			
  }
  getTableData()
}
// ============== 表格控制部分结束 ===============

// 获取需要的字典 可能为空 按需保留
const setOptions = async () => {
}

// 获取需要的字典 可能为空 按需保留
setOptions()

// 多选数据
const multipleSelection = ref([])
// 多选
const handleSelectionChange = (val) => {
  if(val.length>0){
  	multipleSelection.value = val
  	const lenth=val.length
  	ScrapFactor.gdbh=val[lenth-1].combinedProp.split('-')[0];
  	const parts = val[lenth-1].combinedProp2.split('-')
  	ScrapFactor.yjno=parts[0];
  	ScrapFactor.gxh=parts[1];
  	// ScrapFactor.type=val[lenth-1].sczl_检验类别
	ScrapFactor.type='正品板'
  	console.log(ScrapFactor)
  	lastCellValue=val[lenth-1].UniqId
  	console.log(ScrapFactor)
  	val.splice(0, val.length);  // 清空 val 数组	
  	console.log(lastCellValue)
  }
}

// 批量删除控制标记
const deleteVisible = ref(false)

// 多选删除
const onDelete = async () => {
  const ids = []
  if (multipleSelection.value.length === 0) {
    ElMessage({
      type: 'warning',
      message: '请选择要删除的数据'
    })
    return
  }
  multipleSelection.value &&
    multipleSelection.value.map(item => {
      ids.push(item.ID)
    })
  const res = await deleteCompanyByIds({ ids })
  if (res.code === 0) {
    ElMessage({
      type: 'success',
      message: '删除成功'
    })
    if (tableData.value.length === ids.length && page.value > 1) {
      page.value--
    }
    deleteVisible.value = false
    getTableData()
  }
}

// 行为控制标记（弹窗内部需要增还是改）
const type = ref('')

// 更新行
const updateCompanyFunc = async (row) => {
  const res = await findCompany({ ID: row.ID })
  type.value = 'update'
  if (res.code === 0) {
    formData.value = res.data.recompany
    dialogFormVisible.value = true
  }
}

// 弹窗控制标记
const dialogFormVisible = ref(false)

// 打开弹窗
const openDialog = () => {
  type.value = 'create'
  dialogFormVisible.value = true
}

// 关闭弹窗
const closeDialog = () => {
  dialogFormVisible.value = false
  formData.value = {
    address: '',
    image: '',
    name: '',
  }
}
// 弹窗确定
const enterDialog = async () => {
  // elFormRef.value?.validate(async (valid) => {
  //   if (!valid) return
  //   let res
  //   switch (type.value) {
  //     case 'create':
  //       res = await createCompany(formData.value)
  //       break
  //     case 'update':
  //       res = await updateCompany(formData.value)
  //       break
  //     default:
  //       res = await createCompany(formData.value)
  //       break
  //   }
  //   if (res.code === 0) {
  //     ElMessage({
  //       type: 'success',
  //       message: '创建/更改成功'
  //     })
  //     closeDialog()
  //     getTableData()
  //   }
  // })
  updateDetailData()
}
let table=ref(5);
let lastCellValue=ref()
// 双击表格操作
function doubleClick(row, column, event) {
  type.value = 'update';
  		  lastCellValue= row['UniqId'];
  		 console.log(lastCellValue)
  	 table.value=lastCellValue
  	 	 dialogFormVisible.value = true
  		// dialogSelectVisible.value = true
    GetInfo(table.value)
  // dialogFormVisible.value = true
}

// 导出excel
function exportExcel() {
  console.log('导出到excel');
}

// 生命周期钩子
onMounted(async () => {
});
</script>

<style>
.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;
}

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