<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="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 
			  :show-overflow-tooltip="true"
			  @selection-change="handleSelectionChange" @row-dblclick="doubleClick">
              <el-table-column type="selection" width="55" />
              <el-table-column align="left" label="工单编号" prop="sczl_gdbh" width="120"/>
              <el-table-column align="left" label="产品名称" prop="Gd_cpmc"  width="340"/>
              <el-table-column align="left" label="印件及工序" prop="jyno_gxmc"  width="120"/>
              <el-table-column align="left" label="生产日期" prop="sczl_rq"  width="120"/>
              <el-table-column align="left" label="机台" prop="sczl_jtbh"  width="120"/>
              <el-table-column align="left" label="班组" prop="sczl_bzdh"  width="120"/>
              <el-table-column align="left" label="流程单" prop="sczl_num"  width="120"/>
              <el-table-column align="left" label="车头产量" prop="sczl_cl"  width="120"/>
              <el-table-column align="left" label="色度数" prop="sczl_ms" width="120" />
			  <el-table-column align="left" label="制程废" prop="sczl_zcfp" width="120" />
			  <el-table-column align="left" label="次品" prop="sczl_zccp"  width="120"/>
			  <el-table-column align="left" label="来料异常" prop="incomingerror"  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="sczl_打样工时"  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="组员编号1" prop="sczl_bh1" width="120"/>
			  <el-table-column align="left" label="组员姓名1" prop="name1"  width="120"/>
			  <el-table-column align="left" label="组员编号2" prop="sczl_bh2"  width="120"/>
			  <el-table-column align="left" label="组员姓名2" prop="name1" width="120" />
			  <el-table-column align="left" label="组员编号3" prop="sczl_bh3"  width="120"/>
			  <el-table-column align="left" label="组员姓名3" prop="name3" width="120"/>
			  <el-table-column align="left" label="组员编号4" prop="sczl_bh4" width="120"/>
			  <el-table-column align="left" label="组员姓名4" prop="name4"width="120" />
			  <el-table-column align="left" label="组员编号5" prop="sczl_bh5" width="120"/>
			  <el-table-column align="left" label="组员姓名5" prop="name5" width="120"/>
			  <el-table-column align="left" label="组员编号6" prop="sczl_bh6"width="120" />
			  <el-table-column align="left" label="组员姓名6" prop="name6" width="120"/> 
			  <el-table-column align="left" label="拆片联拼系数" prop="拆片联拼系数" width="120"/>
			  <el-table-column align="left" label="拆片条小盒系数" prop="拆片条小盒系数" width="120"/>
			  <el-table-column align="left" label="工价系数" prop="sczl_工价系数" width="160"/>
			  <el-table-column align="left" label="日定额" prop="日定额" width="120"/>
			  <el-table-column align="left" label="千件工价" prop="piecesprice " width="120"/>
			  <el-table-column align="left" label="补产标准" prop="addstandards " 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="160"/>
			<tbody>
			  <tr v-for="row in filteredRows" :key="row.sczl_gdbh">
				<td>{{ row.sczl_gdbh }}</td>
				<td>{{ row.sczl_rq }}</td>
				<td>{{ row.sczl_bzdh }}</td>
				<td>{{ row.sczl_cl }}</td>
				<!-- 其他列 -->
			  </tr>
			</tbody>
            </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_gdbh" @keyup.enter.native="getCPMCsubmit"  :clearable="true" placeholder="2023.12.14" />
                  </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.Gd_cpmc" :clearable="true" placeholder="ZT01733" />
                      </el-col>                      
                    </el-row>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row :gutter="20">
                <el-col :span="8">
                  <el-row :gutter="20">
                    <el-col :span="14">
                      <el-form-item label="印件号" prop="id">
                        <el-input v-model="formData.sczl_yjno" @keyup.enter.native="getYJMCsubmit" :clearable="true" placeholder="0.00" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="10">
                      <el-form-item label="印件名称" prop="id">
                        <el-input v-model="formData.yj_yjmc" :clearable="true" placeholder="是" />
                      </el-form-item>
                    </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_gxmc"  @keyup.enter.native="getGXsubmit" :clearable="true" placeholder="2023.12.14" />
                  </el-form-item>
                </el-col>
                <el-col :span="6">          
                    <el-row :gutter="20">
                      <el-col :span="12">
                        <el-input v-model="formData.sczl_gxh" :clearable="true" placeholder="ZT01733" />
                      </el-col>
                    </el-row>
                </el-col>
                <el-col :span="3">
                  <el-form-item label="工艺名称" prop="name">
                    <el-input v-model="formData.sczl_type" :clearable="true" placeholder="A班" />
                  </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_rq" :clearable="true" placeholder="2023.12.14" />
			       </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_jtbh" :clearable="true" placeholder="ZT01733" />
						</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_bzdh" :clearable="true" placeholder="A班" />
			       </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_ms" :clearable="true" placeholder="2023.12.14" />
			       </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_ls" :clearable="true" placeholder="ZT01733" />
						 </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_cl" :clearable="true" placeholder="A班" />
			       </el-form-item>
			     </el-col>
				 <el-col :span="3">
				   <el-form-item label="制程废品" prop="name">
				     <el-input v-model="formData.sczl_zcfp" :clearable="true" placeholder="A班" />
				   </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_装版总工时" :clearable="true" placeholder="2023.12.14" />
			        </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="ZT01733" />
			   						 </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="A班" />
			        </el-form-item>
			      </el-col>
			   				 <el-col :span="3">
			   				   <el-form-item label="异常停机" prop="name">
			   				     <el-input v-model="formData.sczl_异常停机工时" :clearable="true" placeholder="A班" />
			   				   </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_打样总工时" :clearable="true" placeholder="2023.12.14" />
			       </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="ZT01733" />
			  						 </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="A班" />
			       </el-form-item>
			     </el-col>			  				
			   </el-row>
			  
			  
			  <el-row :gutter="20">
			     <el-col :span="4">			       
			     </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.拆片联拼系数" :clearable="true" placeholder="ZT01733" />
			  						 </el-form-item>
			           </el-col>
			         </el-row>
			     </el-col>
			     <el-col :span="3">
			       <el-form-item label="拆片条小盒系数" prop="name">
			         <el-input v-model="formData.拆片条小盒系数" :clearable="true" placeholder="A班" />
			       </el-form-item>
			     </el-col>			  				 
			   </el-row>
			  
			  <el-row :gutter="20">
			     <el-col :span="4">			       
			     </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="ZT01733" />
			  						 </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="A班" />
			       </el-form-item>
			     </el-col>
				  <el-col :span="3">
					<el-form-item label="计产系数" prop="name">
					  <el-input v-model="formData.sczl_计产系数" :clearable="true" placeholder="A班" />
					</el-form-item>
				  </el-col>
			   </el-row>
            
              <el-row :gutter="10">
				  <el-col :span="2">
				    
				  </el-col>
                <el-col :span="2">
                  <span>员工姓名1</span>
                </el-col>
                <el-col :span="2">
                  <span>员工姓名2</span>
                </el-col>
                <el-col :span="2">
                  <span>员工姓名3</span>
                </el-col>
                <el-col :span="2">
                  <span>员工姓名4</span>
                </el-col>
                <el-col :span="2">
                  <span>员工姓名5</span>
                </el-col>
				<el-col :span="2">
				  <span>员工姓名6</span>
				</el-col>
				<el-col :span="2">
				  <span>员工姓名7</span>
				</el-col>
				<el-col :span="2">
				  <span>员工姓名8</span>
				</el-col>
				<el-col :span="2">
				  <span>员工姓名9</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" @keyup.enter.native="getGxMcsubmit($event, '1')":clearable="true" placeholder="ZI00401" />
                </el-col>
                <el-col :span="2">
                  <el-input v-model="formData.sczl_bh2" @keyup.enter.native="getGxMcsubmit($event, '2')" :clearable="true" placeholder="瞿春生" />
                </el-col>
                <el-col :span="2">
                  <el-input v-model="formData.sczl_bh3" @keyup.enter.native="getGxMcsubmit($event, '3')" :clearable="true" placeholder="11.0" />
                </el-col>
                <el-col :span="2">
                  <el-input v-model="formData.sczl_bh4" @keyup.enter.native="getGxMcsubmit($event, '4')" :clearable="true" placeholder="打包废纸" />
                </el-col>
                <el-col :span="2">
                  <el-input v-model="formData.sczl_bh5" @keyup.enter.native="getGxMcsubmit($event, '5')" :clearable="true" placeholder="是" />
                </el-col>
				<el-col :span="2">
				  <el-input v-model="formData.sczl_bh6" @keyup.enter.native="getGxMcsubmit($event, '6')" :clearable="true" placeholder="ZI00401" />
				</el-col>
				<el-col :span="2">
				  <el-input v-model="formData.sczl_bh7" @keyup.enter.native="getGxMcsubmit($event, '7')" :clearable="true" placeholder="瞿春生" />
				</el-col>
				<el-col :span="2">
				  <el-input v-model="formData.sczl_bh8" @keyup.enter.native="getGxMcsubmit($event, '8')" :clearable="true" placeholder="11.0" />
				</el-col>
				<el-col :span="2">
				  <el-input v-model="formData.sczl_bh9" @keyup.enter.native="getGxMcsubmit($event, '9')" :clearable="true" placeholder="打包废纸" />
				</el-col>
				<el-col :span="2">
				  <el-input v-model="formData.sczl_bh10" @keyup.enter.native="getGxMcsubmit($event, '10')" :clearable="true" placeholder="是" />
				</el-col>
              </el-row>
            </el-form>
			
			
			<el-row :gutter="10" style="margin-top: 10px;">
							 <el-col :span="2">
							   
							 </el-col>
			   <el-col :span="2">
			     <el-input v-model="formData.sczl_bh1_name"  :clearable="true" placeholder="ZI00401" />
			   </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_bh3_name" :clearable="true" placeholder="11.0" />
			   </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_bh5_name" :clearable="true" placeholder="是" />
			   </el-col>
				<el-col :span="2">
				  <el-input v-model="formData.sczl_bh6_name" :clearable="true" placeholder="ZI00401" />
				</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_bh8_name" :clearable="true" placeholder="11.0" />
				</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_bh10_name" :clearable="true" placeholder="是" />
				</el-col>
			 </el-row>
			
			<el-row :gutter="10" style="margin-top: 10px;">
				 <el-col :span="2">
				  
				 </el-col>
			   <el-col :span="2">
			     <el-input v-model="formData.sczl_rate1" :clearable="true" placeholder="ZI00401" />
			   </el-col>
			   <el-col :span="2">
			     <el-input v-model="formData.sczl_rate2" :clearable="true" placeholder="瞿春生" />
			   </el-col>
			   <el-col :span="2">
			     <el-input v-model="formData.sczl_rate3" :clearable="true" placeholder="11.0" />
			   </el-col>
			   <el-col :span="2">
			     <el-input v-model="formData.sczl_rate4" :clearable="true" placeholder="打包废纸" />
			   </el-col>
			   <el-col :span="2">
			     <el-input v-model="formData.sczl_rate5" :clearable="true" placeholder="是" />
			   </el-col>
				<el-col :span="2">
				  <el-input v-model="formData.sczl_rate6" :clearable="true" placeholder="ZI00401" />
				</el-col>
				<el-col :span="2">
				  <el-input v-model="formData.sczl_rate7" :clearable="true" placeholder="瞿春生" />
				</el-col>
				<el-col :span="2">
				  <el-input v-model="formData.sczl_rate8" :clearable="true" placeholder="11.0" />
				</el-col>
				<el-col :span="2">
				  <el-input v-model="formData.sczl_rate9" :clearable="true" placeholder="打包废纸" />
				</el-col>
				<el-col :span="2">
				  <el-input v-model="formData.sczl_rate10" :clearable="true" placeholder="是" />
				</el-col>
			 </el-row>
			 
			 
            
            <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-dialog
            v-model="GXVisible"
            title="选择"
            destroy-on-close
            width="800px"
          			>
            <el-table
              tooltip-effect="dark"
              :data="selectData"
              row-key="ID"
              highlight-current-row="true"
              border
              style="width:100%"
              @row-dblclick="SelectClick"
            >
              <el-table-column
                prop="sczl_gxmc"
                label="工序名称"
                width="800"
              />			        	 
            </el-table>
          </el-dialog>

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

  </div>
</template>

<script setup>
import {
  getproductionCount,
  getproductionList,
  productionlocate,
  productionByGdbh,
  productionInfo,
  productionGdmc,
  productionYjmc,
  productionGx,
  productionDedh,
  productionedit,
  productiondel,
  getYg
} 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 GetDedhVisible = ref(false)
// 侧边栏数据请求
const treeData = reactive([]);
const getTabdata = async () => {
    //接口调用函数
    const response  = await getproductionCount();
	console.log(response.data)
	
	
 const transformedData = response.data.map(item => ({
     label: `${item.date.replace(/-/g, '.')}【单据数: ${item.counts}张】`,
     children: Object.keys(item.sys).map(sysItem => {
        const matchResult = sysItem.match(/\[(.*?)\]/);
        const sysLabel = matchResult ? matchResult[1] : "";
        return {
          label: `${sysLabel}【记录数: ${item.sys[sysItem]}张】`,
          params: {
        date: item.date.replace(/\./g, '-'),
        sys_id: sysItem,
        total: item.sys[sysItem],
         },
       };
     }),
   }));
   treeData.splice(0, treeData.length, ...transformedData);
   console.log(treeData);
}

getTabdata();

// 自动化生成的字典（可能为空）以及字段
const formData = ref({
		  sczl_gdbh: '',
          Gd_cpmc: '',
          sczl_yjno: '',
          yj_yjmc: '',
          sczl_gxmc: '',
          sczl_gxh: '',
          sczl_type: '',
          sczl_rq: '',
          sczl_jtbh: '',
          sczl_bzdh: '',
          sczl_ms: '',
          sczl_ls: '',
          sczl_cl: '',
          sczl_zcfp: '',
          sczl_装版总工时: '',
          sczl_装版工时: '',
          sczl_保养工时: '',
          sczl_异常停机工时: '',
          sczl_打样总工时: '',
          sczl_打样工时: '',
          sczl_设备运行工时: '',
          拆片联拼系数: '',
          拆片条小盒系数: '',
          sczl_dedh: '',
          sczl_工价系数: '',
          sczl_计产系数: '',
          sczl_bh1: '',
          sczl_bh2: '',
          sczl_bh3: '',
          sczl_bh4: '',
          sczl_bh5: '',
          sczl_bh6: '',
          sczl_bh7: '',
          sczl_bh8: '',
          sczl_bh9: '',
          sczl_bh10: '',
          sczl_rate1: '',
          sczl_rate2: '',
          sczl_rate3: '',
          sczl_rate4: '',
          sczl_rate5: '',
          sczl_rate6: '',
          sczl_rate7: '',
          sczl_rate8: '',
          sczl_rate9: '',
          sczl_rate10: '',
          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: '',
})

// 验证规则
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 GetLocate = async () => {
  const response = await productionlocate({
    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()
//获取列表
const getTableData = async() => {
 const response = await getproductionList({date: params.date, sys_id: params.sys_id,
	  page: page.value.toString(), limit: limit.value.toString()});
   console.log(response)
   if (response.code === 0) {
     tableData.splice(0, tableData.length, ...response.data.rows);
   }
 }

const handleNodeClick = (node,check) => {
  //存放当前节点的nodeId
 if (node.params) {
   params.date = node.params.date;
   params.sys_id = node.params.sys_id;
   total.value = node.params.total;
   console.log(params)
   getTableData();
 }

}
//员工编号回车事件
const getGxMcsubmit = (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 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 getDedhsubmit = () => {

	 GetDedh()
}
let GetDedhtreeData = reactive([]);
//获取定额代号
const GetDedh = async () => {
  const response = await productionDedh();
  console.log(response);

  // Initialize the tree structure
  let treeData = [];

  if (response.code === 0) {
    const data = response.data;
   
       // 递归函数来构建树形结构
       const buildTree = (node) => {
         const treeNode = {
           label: node.sys_bh + '【' + node.sys_mc+'】',
           children: []
         };
   
         // 如果存在子节点，递归地添加它们
         if (node.bh_mc && Array.isArray(node.bh_mc)) {
           node.bh_mc.forEach(childNode => {
             treeNode.children.push(buildTree(childNode)); // 递归调用
           });
         }
   
         return treeNode;
       };
   
       // 构建树形结构的根节点
       const treeData = data.bh_mc.map(buildTree);
   
       console.log(treeData);
       GetDedhtreeData = treeData; // 假设这是外部可访问的变量
       GetDedhVisible.value = true; // 假设这是一个响应式引用
  }
}
//定额代号树形结构单机
const GetDedhhandleNodeClick = (nodeData, node, component) => {
  //存放当前节点的nodeId
  //存放当前节点的nodeId
  if (!nodeData.children || nodeData.children.length === 0) {
          // 如果节点没有子节点，打印节点名称
          console.log(nodeData.label.split("【")[0]);
		  formData.value.sczl_dedh=nodeData.label.split("【")[0]
		   GetDedhVisible.value = false
        }
}

//工序回车事件
const getGXsubmit = () => {
	 GetGxMc()
}
const selectData = reactive([])
const GXVisible = ref(false)
//查询印件工序及产品名称
const GetGxMc = async () => {
  console.log(formData.value.sczl_gdbh)
  const response = await productionGx({gdbh:formData.value.sczl_gdbh,yjno:formData.value.sczl_yjno});
  console.log(response) 
 
  if (response.code === 0) {
	  selectData.splice(0, selectData.length, ...response.data)
	  GXVisible.value=true
	  }
  }
  //工序选择
const SelectClick = (row, column, event) => {
  const {sczl_gxmc } = row
  formData.value.sczl_gxmc=sczl_gxmc
  formData.value.sczl_gxh=sczl_gxmc.split("-")[0]
  console.log(formData.value.sczl_gxmc)
  console.log(formData.value.sczl_gxh)
  GXVisible.value = false
}
//工单编号回车事件
const getCPMCsubmit = () => {
	 GetCPMC()
}
//获取工单名称
const GetCPMC = async () => {
  console.log(formData.value.sczl_gdbh)
  const response = await productionGdmc({gdbh:formData.value.sczl_gdbh});
  console.log(response) 
  if (response.code === 0) {
	  formData.value.Gd_cpmc=response.data.Gd_cpmc
	  }
  }
  
  //印件号回车事件
  const getYJMCsubmit = () => {
  	 GetYJMC()
  }
  //获取印件名称
  const GetYJMC = async () => {
    console.log(formData.value.sczl_gdbh)
    const response = await productionYjmc({gdbh:formData.value.sczl_gdbh,yjno:formData.value.sczl_yjno});
    console.log(response) 
    if (response.code === 0) {
  	  formData.value.yj_yjmc=response.data.yj_yjmc
  	  }
    }
// 搜索
function onSearch() {
    params.gdbh = positionvalue.value
	params.type = 'getLocateTable'
	page.value = 1
	GetLocate()
}
//删除
function onDel() {
	Del()
}
//删除
const Del = async () => {
  const response = await productiondel({UniqId:lastCellValue});
  if (response.code === 0) {
	console.log(333)
  }
  getTableData()
}
// 按工单显示
function onCountByGdbh() {
	CountByGdbh()
}
//按工单显示
const CountByGdbh = async () => {
  const response = await productionByGdbh();
  // let tree = {}; // 将 tree 声明为 let 变量，以便后续可以重新赋值
  // console.log(response)
  if (response.code === 0) {
	//   console.log(response)
	  
	// const transformedData = response.data.map(item => ({
	// 	      label: `${item.sys.value}`,	
			  
	// 	      // children: item.sys(sysItem => ({
	// 	        // label: `${sysItem.sys} 【记录数: ${sysItem.sys}张】`,
	// 	        params: {
	// 	          date: item.sczl_gdbh,
	// 	          sys_id: item.sczl_gdbh,
	// 	          total: '1',
	// 	        },
	// 	      // })),
	// 	    }));
	// 	    treeData.splice(0, treeData.length, ...transformedData);
			// 假设您有一个名为"tree"的空对象来存储树形结构
			
		treeData.splice(0, treeData.length);
		  // 遍历接口返回的数据
		  response.data.forEach(item => {
		    // 创建父节点
		    treeData[item.sczl_gdbh] = {
		      label: item.sczl_gdbh+'【'+item.yj_yjmc+'】',
		      children: [],
			  params:{
				date: item.sczl_gdbh,
				sys_id:'' ,
				total: '',
			  }
		    };
		
		    // 添加子节点
		    for (const key in item.sys) {
		      const childNode = {
		        name: key,
		        label: key+'  【记录数'+item.sys[key]+'张】',
				params:{
					date: item.sczl_gdbh,
					sys_id:key ,
					total: item.sys[key],
				}
		      };
		      treeData[item.sczl_gdbh].children.push(childNode);
		    }
		  });
		// console.log(treeData)
		// //   // 打印树形结构
		//   console.log(JSON.stringify(tree, null, 2));
		
		//   // 将父子关系转换为数组
		//   const transformedData = Object.values(tree);
		//   console.log(transformedData);
		//   treeData = transformedData;
  }
  // // 将父子关系转换为数组
  // const transformedData = Object.values(tree);
  // console.log(transformedData)
  // treeData = transformedData;
  getTableData()
}
// ============== 表格控制部分结束 ===============

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

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

// 多选数据
const multipleSelection = ref([])
// 多选
const handleSelectionChange = (val) => {
  // multipleSelection.value = 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_检验类别
  	// console.log(ScrapFactor)
  	lastCellValue=val[lenth-1].UniqId
  	// console.log(val)
  	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()
}
// 更新数据
const updateDetailData = async() => {
  const restoredData = {
   UniqId: lastCellValue,
   sczl_gdbh: formData.value.sczl_gdbh,
   Gd_cpmc: formData.value.Gd_cpmc,
   sczl_yjno: formData.value.sczl_yjno,
   yj_yjmc: formData.value.yj_yjmc,
   sczl_gxmc: formData.value.sczl_gxmc,
   sczl_gxh: formData.value.sczl_gxh,
   sczl_type: formData.value.sczl_type,
   sczl_rq: formData.value.sczl_rq,
   sczl_jtbh: formData.value.sczl_jtbh,
   sczl_bzdh: formData.value.sczl_bzdh,
   sczl_ms: formData.value.sczl_ms,
   sczl_ls: formData.value.sczl_ls,
   sczl_cl: formData.value.sczl_cl,
   sczl_zcfp: formData.value.sczl_zcfp,
   sczl_装版总工时: formData.value.sczl_装版总工时,
   sczl_装版工时: formData.value.sczl_装版工时,
   sczl_保养工时: formData.value.sczl_保养工时,
   sczl_异常停机工时: formData.value.sczl_异常停机工时,
   sczl_打样总工时: formData.value.sczl_打样总工时,
   sczl_打样工时: formData.value.sczl_打样工时,
   sczl_设备运行工时: formData.value.sczl_设备运行工时,
   拆片联拼系数: formData.value.拆片联拼系数,
   拆片条小盒系数: formData.value.拆片条小盒系数,
   sczl_dedh: formData.value.sczl_dedh,
   sczl_工价系数: formData.value.sczl_工价系数,
   sczl_计产系数: formData.value.sczl_计产系数,
   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_rate1: formData.value.sczl_rate1,
   sczl_rate2: formData.value.sczl_rate2,
   sczl_rate3: formData.value.sczl_rate3,
   sczl_rate4: formData.value.sczl_rate4,
   sczl_rate5: formData.value.sczl_rate5,
   sczl_rate6: formData.value.sczl_rate6,
   sczl_rate7: formData.value.sczl_rate7,
   sczl_rate8: formData.value.sczl_rate8,
   sczl_rate9: formData.value.sczl_rate9,
   sczl_rate10: formData.value.sczl_rate10,
  }
  // 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
  // })
  
   console.log(restoredData)
    console.log(lastCellValue)
    formData.value.UniqId=lastCellValue
    console.log(formData)
	restoredData.UniqId='5'
   const response = await productionedit(restoredData);
  // console.log(FormData)
  console.log(response)
}
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
   GetInfo(table.value)
}
//获取详细信息
const GetInfo = async (value) => {
  const response = await productionInfo({UniqId:value});
  console.log(response) 
  if (response.code === 0) {
	formData.value=response.data;
  }
}

// 导出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>