<template>
  <div>
    
    <el-container>
      <el-aside width="200px">
        <div class="JKWTree-tree">

          <h3  > 组织列表</h3>
          <el-tree :data="treeData" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
        </div>

      </el-aside>
      <el-container>
<!--        <el-header>dd</el-header>-->
        <el-main>

          <div class="gva-search-box">
            <el-row :gutter="500">
              <el-col :span="25">
				  <el-row :gutter="20">
				    <el-col :span="6">
				      <el-form-item label="工单编号" prop="name">
				        <el-row :gutter="20">
				          <el-col :span="12">
				            <el-input v-model="formData.code" :clearable="true" placeholder="ZT01733" />							
				          </el-col>
						  <el-col :span="12">
						    <el-input v-model="formData.code" :clearable="true" placeholder="ZT01733" />
						  </el-col>
				        </el-row>
						
				      </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_cl" :clearable="true" placeholder="2023.12.14" />
					 </el-form-item>
				    </el-col>
				  <el-col :span="3">
					 <el-form-item label="工序名称" prop="name">
					   <el-input v-model="formData.sczl_PgCl" :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-form-item>
				    </el-col>				  			    
				  </el-row>
				  
				  <el-row :gutter="1">
				  			     <el-col :span="1">
				  			         <el-input v-model="formData.address" :clearable="true" placeholder="2023.12.14" />
				  			     </el-col>
				  							 <el-col :span="1">
				  							   <el-input v-model="formData.流程单号1" :clearable="true" placeholder="ZT01733" />
				  							 </el-col>
				  				            <el-col :span="1">
				  				              <el-input v-model="formData.流程单号2" :clearable="true" placeholder="ZT01733" />
				  				            </el-col>
				  			  				  <el-col :span="1">			  			
				  			  				    <el-input v-model="formData.流程单号3" :clearable="true" placeholder="ZT01733" />
				  			  				  </el-col>
				  							  
				  			  				  <el-col :span="1">
				  			  				    <el-input v-model="formData.流程单号4" :clearable="true" placeholder="ZT01733" />
				  			  				  </el-col>
				  			  				  <el-col :span="1">
				  			  				    <el-input v-model="formData.流程单号5" :clearable="true" placeholder="ZT01733" />
				  			  				  </el-col>
				  			  				  <el-col :span="1">
				  			  				    <el-input v-model="formData.流程单号6" :clearable="true" placeholder="ZT01733" />
				  			  				  </el-col>
				  			  				  <el-col :span="1">
				  			  				    <el-input v-model="formData.流程单号7" :clearable="true" placeholder="ZT01733" />
				  			  				  </el-col>
				  			  				  <el-col :span="1">
				  			  				    <el-input v-model="formData.流程单号8" :clearable="true" placeholder="ZT01733" />
				  			  				  </el-col>
				  							  <el-col :span="1">
				  			  				    <el-input v-model="formData.流程单号9" :clearable="true" placeholder="ZT01733" />
				  			  				  </el-col>				  			     
				  			   </el-row>
							   
							   <el-row :gutter="1">
							   			     <el-col :span="1">
							   			         <el-input v-model="formData.address" :clearable="true" placeholder="2023.12.14" />
							   			     </el-col>
							   							 <el-col :span="1">
							   							   <el-input v-model="formData.流程单号1" :clearable="true" placeholder="ZT01733" />
							   							 </el-col>
							   				            <el-col :span="1">
							   				              <el-input v-model="formData.流程单号2" :clearable="true" placeholder="ZT01733" />
							   				            </el-col>
							   			  				  <el-col :span="1">			  			
							   			  				    <el-input v-model="formData.流程单号3" :clearable="true" placeholder="ZT01733" />
							   			  				  </el-col>
							   							  
							   			  				  <el-col :span="1">
							   			  				    <el-input v-model="formData.流程单号4" :clearable="true" placeholder="ZT01733" />
							   			  				  </el-col>
							   			  				  <el-col :span="1">
							   			  				    <el-input v-model="formData.流程单号5" :clearable="true" placeholder="ZT01733" />
							   			  				  </el-col>
							   			  				  <el-col :span="1">
							   			  				    <el-input v-model="formData.流程单号6" :clearable="true" placeholder="ZT01733" />
							   			  				  </el-col>
							   			  				  <el-col :span="1">
							   			  				    <el-input v-model="formData.流程单号7" :clearable="true" placeholder="ZT01733" />
							   			  				  </el-col>
							   			  				  <el-col :span="1">
							   			  				    <el-input v-model="formData.流程单号8" :clearable="true" placeholder="ZT01733" />
							   			  				  </el-col>
							   							  <el-col :span="1">
							   			  				    <el-input v-model="formData.流程单号9" :clearable="true" placeholder="ZT01733" />
							   			  				  </el-col>				  			     
							   			   </el-row>
				  
			  </el-col>
              <el-col >

			  </el-col>
            </el-row>
          </div>
          <div class="gva-table-box">
            <div class="gva-btn-list">
              <el-button type="primary" icon="plus" @click="openDialog">新增</el-button>
              <el-popover v-model:visible="deleteVisible" :disabled="!multipleSelection.length" placement="top" width="160">
                <p>确定要删除吗？</p>
                <div style="text-align: right; margin-top: 8px;">
                  <el-button type="primary" link @click="deleteVisible = false">取消</el-button>
                  <el-button type="primary" @click="onDelete">确定</el-button>
                </div>
                <template #reference>
                  <el-button icon="delete" style="margin-left: 10px;" :disabled="!multipleSelection.length" @click="deleteVisible = true">删除</el-button>
                </template>
              </el-popover>
            </div>
            <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
            
                        <el-tab-pane label="设备作业清单"  @click="showTable('印件资料')"  name="first">
                          <el-table ref="multipleTable"
                                    :show-overflow-tooltip="true"
                                    highlight-current-row="true"
                                    :row-style="{ height: '20px' }"
                                    :cell-style="{ padding: '0px' }" :header-row-style="{ height: '20px' }"
                                    :header-cell-style="{ padding: '0px' }"
                                    @row-dblclick="yjupdateCompanyFunc"
                                    style="width: 100%;height: 330px" border tooltip-effect="dark" :data="yjtableData" row-key="ID" @selection-change="handleSelectionChange">
            <!--                <el-table-column type="selection" width="55" />-->
                            <el-table-column align="left" label="选择" prop="yj_yjno"  width="80"/>
                            <el-table-column align="left" label="工单编号|质量信息" prop="yj_yjdh" width="180" />
							<el-table-column align="left" label="印件资料" prop="yj_yjdh" width="240" />
                            <el-table-column align="left" label="工序名称" prop="yj_yjmc" width="100" />
                            <el-table-column align="left" label="计划产量/已完成" prop="yj_zzdh" width="180"/>
                            <el-table-column align="left" label="装版时数" prop="yj_zzmc" width="100"/>
                            <el-table-column align="left" label="工序产能" prop="yj_tlgg" width="100"/>
                            <el-table-column align="left" label="计划工时" prop="yj_klgg" width="100"/>
                            <el-table-column align="left" label="计划生产时段" prop="yj_ks" width="240" />
                            <el-table-column align="left" label="排产备注" prop="yj_ls" width="100" />
                            <el-table-column align="left" label="产品名称" prop="yj_desc" width="240" />
                          </el-table>
                        </el-tab-pane>
            
                        <el-tab-pane label="班组人员及分配比例" @click="showTable('工艺资料')" name="second">
                          <el-table ref="multipleTable"
                                    highlight-current-row="true"
                                    :show-overflow-tooltip="true"
                                    :row-style="{ height: '20px' }"
                                    :cell-style="{ padding: '0px' }" :header-row-style="{ height: '20px' }"
                                    :header-cell-style="{ padding: '0px' }"
                                    @row-dblclick="gyupdateCompanyFunc"
                                    :row-class-name="rowClassStyle"
                                    style="width: 100%;height: 400px" border tooltip-effect="dark" :data="gytableData" row-key="ID" @selection-change="handleSelectionChange"
                                    @row-click="clickybupdate">
            <!--                <el-table-column type="selection" width="55" />-->
                            <el-table-column align="left" label="选择" prop="方案"  width="70"/>
                            <el-table-column align="left" label="班组号" prop="Gy0_yjno" width="80" />
                            <el-table-column align="left" label="组员1" prop="Gy0_gxh" width="240" />
                            <el-table-column align="left" label="组员2" prop="gy0_gxmc" width="240" />
                            <el-table-column align="left" label="组员3" prop="add_gxmc" width="240" />
                            <el-table-column align="left" label="组员4" prop="Gy0_Ks" width="240" />
                            <el-table-column align="left" label="组员5" prop="Gy0_ls" width="100" />
                            <el-table-column align="left" label="组员6" prop="备注" width="100" />
                            <el-table-column align="left" label="组员7" prop="工价系数" width="100" />
                            <el-table-column align="left" label="组员8" prop="损耗系数" width="100" />
                            <el-table-column align="left" label="组员9" prop="Gy0_Ms" width="100" />
                            <el-table-column align="left" label="组员10" prop="人工检_正品版" width="120" />
                          </el-table>
                        </el-tab-pane>
            
                        <el-tab-pane label="当班产量明细" @click="showTable('印版资料')" name="third">
                        <el-table ref="multipleTable"
                                  highlight-current-row="true"
                                  :show-overflow-tooltip="true"
                                  :row-style="{ height: '20px' }"
                                  :cell-style="{ padding: '0px' }" :header-row-style="{ height: '20px' }"
                                  :header-cell-style="{ padding: '0px' }"
                                  @row-dblclick="ybupdateCompanyFunc"
                                  style="width: 100%;height: 400px" border tooltip-effect="dark" :data="ybtableData" row-key="ID" @selection-change="handleSelectionChange"
                                  >
            <!--              <el-table-column type="selection" width="55" />-->
                          <el-table-column align="left" label="生产时段" prop="YB_方案"  width="180"/>
                          <el-table-column align="left" label="工单编号" prop="YB_Yjno" width="120" />
                          <el-table-column align="left" label="产品名称" prop="印版类别" width="240" />
                          <el-table-column align="left" label="印件及工序" prop="存货编码" width="320"/>
                          <el-table-column align="left" label="标牌号" prop="印版名称"  width="80"/>
                          <el-table-column align="left" label="产量" prop="考核印数" width="100"/>
                          <el-table-column align="left" label="制程废品" prop="Sys_id" width="100" />
                          <el-table-column align="left" label="制程次品" prop="建档日期" width="100" />
                          <el-table-column align="left" label="前工序废" prop="更新日期" width="100" />
						  <el-table-column align="left" label="来料异常" prop="YB_方案"  width="100"/>
						  <el-table-column align="left" label="装版工时" prop="YB_Yjno" width="100" />
						  <el-table-column align="left" label="保养工时" prop="印版类别" width="100" />
						  <el-table-column align="left" label="打样工时" prop="存货编码" width="100"/>
						  <el-table-column align="left" label="异常停机工时" prop="印版名称"  width="120"/>
						  <el-table-column align="left" label="通电工时" prop="考核印数" width="100"/>
						  <el-table-column align="left" label="码开始行" prop="Sys_id" width="100" />
						  <el-table-column align="left" label="码结束行" prop="建档日期" width="100" />
						  <el-table-column align="left" label="码包" prop="更新日期" width="100" />
						  <el-table-column align="left" label="主电表" prop="YB_方案"  width="100"/>
						  <el-table-column align="left" label="辅电表" prop="YB_Yjno" width="100" />
						  <el-table-column align="left" label="色度数" prop="印版类别" width="100" />
                        </el-table>
                        </el-tab-pane>
            
                        <el-tab-pane label="检验记录" @click="showTable('技术资料附件')" name="fourth">
                        <el-table ref="multipleTable"
                                  :row-style="{ height: '20px' }"
                                  :cell-style="{ padding: '0px' }" :header-row-style="{ height: '20px' }"
                                  :header-cell-style="{ padding: '0px' }"
                                  :show-overflow-tooltip="true"
                                  highlight-current-row="true"
                                  style="width: 100%;height: 400px" border tooltip-effect="dark" :data="jstableData" row-key="ID" @selection-change="handleSelectionChange">
            <!--              <el-table-column type="selection" width="55" />-->
                          <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="备注" width="330" />
                          <el-table-column align="left" label="检验项目" prop="文件类型" width="120"/>
                          <el-table-column align="left" label="12:39" prop="关联产品"  width="100"/>
                          <el-table-column align="left" label="13:08" prop="建档用户" width="100"/>
                          <el-table-column align="left" label="13:25" prop="建档日期" width="100" />
                          <el-table-column align="left" label="14:31" prop="更新日期" width="100" />
                        </el-table>
                        </el-tab-pane>
            
                      </el-tabs>
            <!-- <div class="gva-pagination">
              <el-pagination
                  layout="total, sizes, prev, pager, next, jumper"
                  :current-page="page"
                  :page-size="pageSize"
                  :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>
          <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
            <el-tab-pane label="当日上报产量"  @click="showTable('工艺资料')"  name="first">
              <el-table ref="multipleTable"
                        :show-overflow-tooltip="true"
                        :row-style="{ height: '20px' }"
                        :cell-style="{ padding: '0px' }" :header-row-style="{ height: '20px' }"
                        :header-cell-style="{ padding: '0px' }"
                        highlight-current-row="true"
                        style="width: 100%;height: 400px" border tooltip-effect="dark" :data="gytableData" row-key="ID" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55" />
                <el-table-column align="left" label="选择" prop="工单编号"  width="100"/>
                <el-table-column align="left" label="产品名称" prop="重点工序"  width="100"/>
                <el-table-column align="left" label="工序" prop="工序备注"  width="240"/>
                <el-table-column align="left" label="备注" prop="机组"  width="100"/>
                <el-table-column align="left" label="产量" prop="小时产能"  width="100"/>
                <el-table-column align="left" label="千件工价" prop="生产工时"  width="100"/>
                <el-table-column align="left" label="日定额" prop="辅助工时"  width="100"/>
                <el-table-column align="left" label="补产标准" prop="印刷方式"  width="100"/>
                <el-table-column align="left" label="难度系数" prop="版距"  width="100"/>
                <el-table-column align="left" label="印刷方式" prop="创建用户"  width="120"/>
                <el-table-column align="left" label="组员1" prop="Gy0_gxh" width="240" />
                <el-table-column align="left" label="组员2" prop="gy0_gxmc" width="240" />
                <el-table-column align="left" label="组员3" prop="add_gxmc" width="240" />
                <el-table-column align="left" label="组员4" prop="Gy0_Ks" width="240" />
                <el-table-column align="left" label="组员5" prop="Gy0_ls" width="100" />
                <el-table-column align="left" label="组员6" prop="备注" width="100" />
                <el-table-column align="left" label="组员7" prop="工价系数" width="100" />
                <el-table-column align="left" label="组员8" prop="损耗系数" width="100" />
                <el-table-column align="left" label="组员9" prop="Gy0_Ms" width="100" />
                <el-table-column align="left" label="组员10" prop="人工检_正品版" width="120" />
				<el-table-column align="left" label="制程废品" prop="Sys_id" width="100" />
				<el-table-column align="left" label="制程次品" prop="建档日期" width="100" />
				<el-table-column align="left" label="前工序废" prop="更新日期" width="100" />
				<el-table-column align="left" label="来料异常" prop="YB_方案"  width="100"/>
				<el-table-column align="left" label="装版工时" prop="YB_Yjno" width="100" />
				<el-table-column align="left" label="保养工时" prop="印版类别" width="100" />
				<el-table-column align="left" label="打样工时" prop="存货编码" width="100"/>
				<el-table-column align="left" label="异常停机工时" prop="印版名称"  width="120"/>
				<el-table-column align="left" label="通电工时" prop="考核印数" width="100"/>
				<el-table-column align="left" label="码开始行" prop="Sys_id" width="100" />
				<el-table-column align="left" label="码结束行" prop="建档日期" width="100" />
				<el-table-column align="left" label="码包" prop="更新日期" width="100" />
				<el-table-column align="left" label="主电表" prop="YB_方案"  width="100"/>
				<el-table-column align="left" label="辅电表" prop="YB_Yjno" width="100" />
				<el-table-column align="left" label="色度数" prop="印版类别" width="100" />
				<el-table-column align="left" label="用户" prop="YB_Yjno" width="100" />
				<el-table-column align="left" label="更新时间" prop="印版类别" width="100" />
              </el-table>
            </el-tab-pane>
          
            <el-tab-pane label="当日制程检验记录"  @click="showTable('印件资料')"  name="second">
              <el-table ref="multipleTable"
                        :row-style="{ height: '20px' }"
                        :cell-style="{ padding: '0px' }" :header-row-style="{ height: '20px' }"
                        :header-cell-style="{ padding: '0px' }"
                        :show-overflow-tooltip="true"
                        highlight-current-row="true"
                        style="width: 100%;height: 400px" border tooltip-effect="dark" :data="yjtableData" row-key="ID" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55" />
                <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="备注" width="330" />
                <el-table-column align="left" label="检验项目" prop="文件类型" width="120"/>
                <el-table-column align="left" label="12:39" prop="关联产品"  width="100"/>
                <el-table-column align="left" label="13:08" prop="建档用户" width="100"/>
                <el-table-column align="left" label="13:25" prop="建档日期" width="100" />
                <el-table-column align="left" label="14:31" prop="更新日期" width="100" />
              </el-table>
            </el-tab-pane>
          </el-tabs>
          </el-dialog>

          <el-dialog v-model="detailShow" style="width: 800px" lock-scroll :before-close="closeDetailShow" title="查看详情" destroy-on-close>
            <el-scrollbar height="550px">
              <el-descriptions column="1" border>
                <el-descriptions-item label="address字段">
                  {{ formData.address }}
                </el-descriptions-item>
                <el-descriptions-item label="image字段">
                  {{ formData.image }}
                </el-descriptions-item>
                <el-descriptions-item label="name字段">
                  {{ formData.name }}
                </el-descriptions-item>
              </el-descriptions>
            </el-scrollbar>
          </el-dialog>

        </el-main>

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





  </div>
</template>

<script setup>
import {
  createCompany,
  deleteCompany,
  deleteCompanyByIds,
  updateCompany,
  findCompany,
  getCompanyList
} from '@/api/company'


import {
  demoCustomer
} from "@/api/demo";

// 全量引入格式化工具 请按需保留
import { getDictFunc, formatDate, formatBoolean, filterDict, ReturnArrImg, onDownloadFile } from '@/utils/format'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ref, reactive } from 'vue'

defineOptions({
    name: 'Company'
})

const treeData=ref([{
  label: '胶印车间',
  children: [{
    label: 'JY01# 【海德堡对开八色平板胶印机】',
    children: [{
      label: '2024.01.18', 
    },{
		label:'2024.01.17'},{
		label:'2024.01.16'}],  
  },{
    label: 'JY02# 【海德堡对开八色平板胶印机】',
    children: [{
      label: '2024.01.18', 
    },{
    	label:'2024.01.17'},{
    	label:'2024.01.16'}]
  },{
    label: 'JY03# 【海德堡对开八色平板胶印机】',
    children: [{
      label: '2024.01.18', 
    },{
    	label:'2024.01.17'},{
    	label:'2024.01.16'}]
  },{
    label: 'JY04# 【海德堡对开八色平板胶印机】',
    children: [{
      label: '2024.01.18', 
    },{
    	label:'2024.01.17'},{
    	label:'2024.01.16'}]
  },], 
}, {
  label: '凹印车间',
  children: [{
    label: 'DW01# 【多功能凹版印刷机】',
    children: [{
      label: '2024.01.18', 
    },{
		label:'2024.01.17'},{
		label:'2024.01.16'}],  
  },{
    label: 'DW02# 【多功能凹版印刷机】',
    children: [{
      label: '2024.01.18', 
    },{
    	label:'2024.01.17'},{
    	label:'2024.01.16'}]
  },{
    label: 'DW03# 【多功能凹版印刷机】',
    children: [{
      label: '2024.01.18', 
    },{
    	label:'2024.01.17'},{
    	label:'2024.01.16'}]
  },{
    label: 'DW04# 【多功能凹版印刷机】',
    children: [{
      label: '2024.01.18', 
    },{
    	label:'2024.01.17'},{
    	label:'2024.01.16'}]
  },], 
}, {
  label: '丝印车间',
  children: [{
    label: 'PM01# 【尚浩高速大单张】',
    children: [{
      label: '2024.01.18', 
    },{
		label:'2024.01.17'},{
		label:'2024.01.16'}],  
  },{
    label: 'PM02# 【尚浩高速大单张】',
    children: [{
      label: '2024.01.18', 
    },{
    	label:'2024.01.17'},{
    	label:'2024.01.16'}]
  },{
    label: 'PM03# 【尚浩高速大单张】',
    children: [{
      label: '2024.01.18', 
    },{
    	label:'2024.01.17'},{
    	label:'2024.01.16'}]
  },{
    label: 'PM04# 【尚浩高速大单张】',
    children: [{
      label: '2024.01.18', 
    },{
    	label:'2024.01.17'},{
    	label:'2024.01.16'}]
  },], 
},{
  label: '烫膜车间',
  children: [{
    label: 'MQ01# 【众益自动模切】',
    children: [{
      label: '2024.01.18', 
    },{
		label:'2024.01.17'},{
		label:'2024.01.16'}],  
  },{
    label: 'MQ02# 【众益自动模切】',
    children: [{
      label: '2024.01.18', 
    },{
    	label:'2024.01.17'},{
    	label:'2024.01.16'}]
  },{
    label: 'MQ03# 【众益自动模切】',
    children: [{
      label: '2024.01.18', 
    },{
    	label:'2024.01.17'},{
    	label:'2024.01.16'}]
  },{
    label: 'MQ04# 【众益自动模切】',
    children: [{
      label: '2024.01.18', 
    },{
    	label:'2024.01.17'},{
    	label:'2024.01.16'}]
  },], 
},{
  label: '检验车间',
  children: [{
    label: 'JP01# 【印品质量检测】',
    children: [{
      label: '2024.01.18', 
    },{
		label:'2024.01.17'},{
		label:'2024.01.16'}],  
  },{
    label: 'JP02# 【印品质量检测】',
    children: [{
      label: '2024.01.18', 
    },{
    	label:'2024.01.17'},{
    	label:'2024.01.16'}]
  },{
    label: 'JP03# 【印品质量检测】',
    children: [{
      label: '2024.01.18', 
    },{
    	label:'2024.01.17'},{
    	label:'2024.01.16'}]
  },{
    label: 'JP04# 【印品质量检测】',
    children: [{
      label: '2024.01.18', 
    },{
    	label:'2024.01.17'},{
    	label:'2024.01.16'}]
  },], 
}])
const handleNodeClick = (node,check) => {
  //存放当前节点的nodeId
  console.log(node,check);

}
// 自动化生成的字典（可能为空）以及字段
const formData = ref({
        address: '',
        image: '',
        name: '',
        })


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

const searchRule = reactive({
  createdAt: [
    { validator: (rule, value, callback) => {
      if (searchInfo.value.startCreatedAt && !searchInfo.value.endCreatedAt) {
        callback(new Error('请填写结束日期'))
      } else if (!searchInfo.value.startCreatedAt && searchInfo.value.endCreatedAt) {
        callback(new Error('请填写开始日期'))
      } else if (searchInfo.value.startCreatedAt && searchInfo.value.endCreatedAt && (searchInfo.value.startCreatedAt.getTime() === searchInfo.value.endCreatedAt.getTime() || searchInfo.value.startCreatedAt.getTime() > searchInfo.value.endCreatedAt.getTime())) {
        callback(new Error('开始日期应当早于结束日期'))
      } else {
        callback()
      }
    }, trigger: 'change' }
  ],
})

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

// =========== 表格控制部分 ===========
const page = ref(1)
const total = ref(0)
const pageSize = ref(10)
const tableData = ref([])
const searchInfo = ref({})

// 重置
const onReset = () => {
  searchInfo.value = {}
  getTableData()
}

// 搜索
const onSubmit = () => {
  elSearchFormRef.value?.validate(async(valid) => {
    if (!valid) return
    page.value = 1
    pageSize.value = 10
    getTableData()
  })
}

// 分页
const handleSizeChange = (val) => {
  pageSize.value = val
  getTableData()
}

// 修改页面容量
const handleCurrentChange = (val) => {
  page.value = val
  getTableData()
}

// 查询
const getTableData = async() => {
  const table = await getCompanyList({ page: page.value, pageSize: pageSize.value, ...searchInfo.value })
  if (table.code === 0) {
    tableData.value = table.data.list
    total.value = table.data.total
    page.value = table.data.page
    pageSize.value = table.data.pageSize
  }
}

getTableData()

// ============== 表格控制部分结束 ===============

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

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


// 多选数据
const multipleSelection = ref([])
// 多选
const handleSelectionChange = (val) => {
    multipleSelection.value = val
}

// 删除行
const deleteRow = (row) => {
    ElMessageBox.confirm('确定要删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(() => {
            deleteCompanyFunc(row)
        })
    }


// 批量删除控制标记
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 deleteCompanyFunc = async (row) => {
    const res = await deleteCompany({ ID: row.ID })
    if (res.code === 0) {
        ElMessage({
                type: 'success',
                message: '删除成功'
            })
            if (tableData.value.length === 1 && page.value > 1) {
            page.value--
        }
        getTableData()
    }
}

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


// 查看详情控制标记
const detailShow = ref(false)


// 打开详情弹窗
const openDetailShow = () => {
  detailShow.value = true
}


// 打开详情
const getDetails = async (row) => {
  // 打开弹窗
  const res = await findCompany({ ID: row.ID })
  if (res.code === 0) {
    formData.value = res.data.recompany
    openDetailShow()
  }
}


// 关闭详情弹窗
const closeDetailShow = () => {
  detailShow.value = false
  formData.value = {
          address: '',
          image: '',
          name: '',
          }
}


// 打开弹窗
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()
              }
      })
}

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