<template>
  <div>
    <layout>
      <layout-header>
        <div class="">
          <!--          按钮部分-->
          <el-form ref="elSearchFormRef"   class="demo-form-inline" :rules="searchRule" @keyup.enter="onSubmit">
            <el-form-item>
              <el-button  type="primary" icon="Download" @click="exportToExcel" style="margin: 5px;float: right;">导出到Excel(汇总)</el-button>
              <el-button  type="primary" icon="Download" @click="exportToExcel2" style="margin: 5px;float: right;">月度明细</el-button>
              <el-button  type="primary" icon="Download" @click="exportToExcel3" style="margin: 5px;float: right;">导出到Excel(明细)</el-button>
            </el-form-item>
          </el-form>
        </div>
      </layout-header>
      <layout>
        <!-- 左侧树形结构 -->
        <layout-sider :resize-directions="['right']" :width="190" style="margin-right: 10px;">
          <div class="JKWTree-tree" style="height: 200px">
            <h3>日期</h3>
            <el-tree :data="treeData" class="treecolor"   @node-click="handleNodeClick"></el-tree>
          </div>
        </layout-sider>

        <!-- 右侧内容区域 -->
        <layout-content >
          <el-main>

            <!-- 工单表格列表 -->
            <div class="gva-table-box">
              <el-table ref="multipleTable"
                        id="tab"
                        style="width: 100%;height: 28vh"
                        :row-style="{ height: '20px' }"
                        :cell-style="{ padding: '0px' }" :header-row-style="{ height: '20px' }"
                        :header-cell-style="{ padding: '0px' }"
                        border
                        show-summary
                        tooltip-effect="dark"
                        :data="tabledate2" row-key="ID"
                        @row-click="tableRowClick"
                        highlight-current-row="true"
                        :cell-class-name="tableDataCellClass"
                        @row-dblclick="updateCompanyFunc"
                        @selection-change="handleSelectionChange"
                        :show-overflow-tooltip="true">
                <el-table-column align="left" label="设备编号"   prop="设备编号"  width="81" />
                <el-table-column align="left" sortable label="设备名称"   prop="设备名称"  width="280" />
                <el-table-column align="left" sortable label="产量"   prop="产量" width="110" />
                <el-table-column align="left" sortable label="设备运行工时" prop="设备运行工时" width="150" />
                <el-table-column align="left" sortable label="打样总工时"   prop="打样总工时"  width="120" />
                <el-table-column align="left" sortable label="打样补产工时"   prop="打样补产工时" width="240" />
                <el-table-column align="left" sortable label="装板总工时"   prop="装板总工时" width="130" />
                <el-table-column align="left" sortable label="装板补产工时"       prop="装板补产工时"   width="140"/>
                <el-table-column align="left" sortable label="异常停机工时"   prop="异常停机工时" width="140" />
              </el-table>
              <!-- 分页 -->
              <div class="gva-pagination">
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="page"
                    :page-sizes="[10, 30, 50, 100]"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
                </el-pagination>
              </div>
            </div>

            <!-- 月度设备运行统计->机台生产工单数据详情列表  -->
            <el-tabs v-model="activeName" @tab-click="handleClick">
                <el-table ref="multipleTable"
                          id="tab2"
                          :row-style="{ height: '20px' }"
                          show-summary
                          :cell-style="{ padding: '0px' }" :header-row-style="{ height: '20px' }"
                          :header-cell-style="{ padding: '0px' }"
                          :show-overflow-tooltip="true"
                          highlight-current-row="true"
                          @selection-change="selectionChange($event, '印件资料')"
                          style="width: 100%;height: 36vh" border tooltip-effect="dark" :data="jqtabledata" row-key="ID">
                  <el-table-column type="selection" width="30" />
                  <el-table-column align="left" sortable label="设备编号" prop="设备编号"  width="100"/>
                  <el-table-column align="left" sortable label="设备名称" prop="设备名称"  width="340"/>
                  <el-table-column align="left" sortable label="日期" prop="日期"  width="100"/>
                  <el-table-column align="left" sortable label="印件名称" prop="印件名称"  width="340"/>
                  <el-table-column align="left" sortable label="工序名称" prop="工序名称"  width="110"/>
                  <el-table-column align="left" sortable label="产量" prop="产量"  width="110"/>
                  <el-table-column align="left" sortable label="设备运行工时" prop="设备运行工时"  width="110"/>
                  <el-table-column align="left" sortable label="保养工时" prop="保养工时"  width="110"/>
                  <el-table-column align="left" sortable label="打样总工时" prop="打样总工时"  width="120"/>
                  <el-table-column align="left" sortable label="打样补产工时" prop="打样补产工时"  width="110"/>
                  <el-table-column align="left" sortable label="装板补产工时" prop="装板补产工时"  width="160"/>
                  <el-table-column align="left" sortable label="异常停机工时" prop="异常停机工时"  width="160"/>
                  <el-table-column align="left" sortable label="墨色数" prop="墨色数"  width="160"/>
                </el-table>
            </el-tabs>

		

          </el-main>
        </layout-content>
      </layout>
    </layout>

    <PrintPage ref="printPageRef" />

    <AddGongYi ref="addGongYiRef" />
  </div>
</template>
<script>
//点击按钮显示下方表格
export default {
  data() {
    return {
      currentTable: '', // 当前展示的表格
      activeName: 'first',
    };
  },
  methods: {
    showTable(tableName) {
      this.currentTable = tableName;
    },
    showTableChange() {
      // 处理表格选中事件
    },
  }
};
</script>
<script setup>
// 全量引入格式化工具 请按需保留
import $script from 'scriptjs'
import $ from 'jquery';
import * as XLSX from 'xlsx'
import FileSaver from 'file-saver'
import LuckyExcel from 'luckyexcel';
import { Layout, LayoutSider, LayoutContent } from '@arco-design/web-vue';
import { ElMessage, ElMessageBox } from 'element-plus'
import { ref, reactive, computed, nextTick, watch } from 'vue'
import {OutputSstatisticsMenu,MachineOperation,MachineOperationProductDetail} from "@/api/DecisionSupport/decision.js"
defineOptions({name: 'Company'})
import { useUserStore } from '@/pinia/modules/user'
const userStore = useUserStore()
const _username = ref('')
_username.value = userStore.userInfo.userName + '/' + userStore.userInfo.nickName
//点击左侧获取工序显示右侧数据
const lcd_handleNodeClick = async (node) => {
  if (node.value === undefined || node.value === null){
      return false;
  }
  const order = gd_lcdformData['gdbh'];
  //5.2流程单查询-获取工单工序生产进程右侧【接口】
  const getOrderProcessRight_list = await getOrderProcessRight({order:order, gxNo:node.value});
  processList.value = getOrderProcessRight_list.data
};

// 流程单查询退出
const gd_lcdCancel = async () => {
  gd_lcdlist.value = false;
}

// =========== 新增工单资料 ===========
// 获取当前日期
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始，需要补零
const day = String(today.getDate()).padStart(2, '0');
const hours = String(today.getHours()).padStart(2, '0');
const minutes = String(today.getMinutes()).padStart(2, '0');
const seconds = String(today.getSeconds()).padStart(2, '0');
const currentDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;


const add_gddialogFormVisible = ref(false)
const add_gdscgdformData = reactive({
  重点工单: '',
  开单日期: '',
  工单编号: '',
  生产类型: '',
  客户代号: '',
  客户名称: '',
  产品代号: '',
  产品名称: '',
  印件代号: '',
  印件名称: '',
  订单数量: '',
  交货日期: '',
  投料率: '',
  平均合格率: '',
  平张投料: '',
  万小张: '',
  单位: '',
  投料大箱: '',
  库存大箱: '',
  销售订单号: '',
  警语版面: '',
  版本号: '',
  客户ERP编码: '',
  码源数量: '',
  进程备注: '',
  备注: '',
});
//清空对象的属性值
const gd_clearFormData = () => {
  Object.keys(add_gdscgdformData).forEach(key => {
    add_gdscgdformData[key] = '';
  });
};
//新增工单资料按钮
const addgd_onclick = () => {
  handleDoubleClick();
  gd_clearFormData();
  add_gdscgdformData['重点工单'] = '';
  add_gdscgdformData['订单数量'] = 0;
  add_gdscgdformData['平张投料'] = 0;
  add_gdscgdformData['万小张'] = 0;
  add_gdscgdformData['单位'] = "万张";
  add_gdscgdformData['投料大箱'] = 0;
  add_gdscgdformData['码源数量'] = 0;
  add_gdscgdformData['开单日期'] = currentDate;
  add_gddialogFormVisible.value = true
}
const handleDoubleClick = async ()=>{
  console.log(123)
}
//新增工单资料确定
const add_gdenterDialog = async ()=>{
  console.log(add_gdscgdformData)
  if(add_gdscgdformData['工单编号'] === ''){
    ElMessage({type: 'warning',message: '工单编号为空'})
    return false;
  }
  if(add_gdscgdformData['交货日期'] === ''){
    ElMessage({type: 'warning',message: '交货日期为空'})
    return false;
  }
  const startdeliveryDate = new Date(add_gdscgdformData['开单日期']);
  const start = startdeliveryDate.getFullYear() + '-' +
      (startdeliveryDate.getMonth() + 1).toString().padStart(2, '0') + '-' +
      startdeliveryDate.getDate().toString().padStart(2, '0') + ' ' +
      startdeliveryDate.getHours().toString().padStart(2, '0') + ':' +
      startdeliveryDate.getMinutes().toString().padStart(2, '0') + ':' +
      startdeliveryDate.getSeconds().toString().padStart(2, '0');

  const deliveryDate = new Date(add_gdscgdformData['交货日期']);
  const jhriqi = deliveryDate.getFullYear() + '-' +
      (deliveryDate.getMonth() + 1).toString().padStart(2, '0') + '-' +
      deliveryDate.getDate().toString().padStart(2, '0') + ' ' +
      deliveryDate.getHours().toString().padStart(2, '0') + ':' +
      deliveryDate.getMinutes().toString().padStart(2, '0') + ':' +
      deliveryDate.getSeconds().toString().padStart(2, '0');
  const formattedData = {
    zdgd: add_gdscgdformData['重点工单'],
    start: start,
    gdbh: add_gdscgdformData['工单编号'],
    sclx: add_gdscgdformData['生产类型'],
    khdh: add_gdscgdformData['客户代号'],
    khmc: add_gdscgdformData['客户名称'],
    cpdh: add_gdscgdformData['产品代号'],
    cpmc: add_gdscgdformData['产品名称'],
    yjno: add_gdscgdformData['印件代号'],
    yjmc: add_gdscgdformData['印件名称'],
    number: add_gdscgdformData['订单数量'],
    end: jhriqi,
    tll: add_gdscgdformData['投料率'],
    hgl: add_gdscgdformData['平均合格率'],
    pztl: add_gdscgdformData['平张投料'],
    wxz: add_gdscgdformData['万小张'],
    tldw: add_gdscgdformData['单位'],
    tldx: add_gdscgdformData['投料大箱'],
    kcdx: add_gdscgdformData['库存大箱'],
    xsddh: add_gdscgdformData['销售订单号'],
    jybm: add_gdscgdformData['警语版面'],
    bbh: add_gdscgdformData['版本号'],
    erp: add_gdscgdformData['客户ERP编码'],
    mysl: add_gdscgdformData['码源数量'],
    jcbz: add_gdscgdformData['进程备注'],
    remark: add_gdscgdformData['备注'],
    Sys_id: _username.value,
  };
  const WorkOrderAdd_add = await WorkOrderAdd(formattedData);
  if (WorkOrderAdd_add.code === 0) {
    ElMessage({type: 'success',message: '添加成功'})
  } else {
    ElMessage({type: 'error',message: '添加失败'})
  }
  add_gddialogFormVisible.value = false
}
//新增工单资料取消
const add_gdcloseDialog = () => {
  add_gddialogFormVisible.value = false
}
//获取客户代号，客户名称
const khdhModal = ref(false)
const cpdhModal = ref(false)
const khdhDataList = ref([])
const cpdhDataList = ref([])
const khdh_keyword = ref('')
const cpdh_keyword = ref('')

//新增工单资料客户代号【回车】
const khdh_ProductValue = async (v) => {
  await _gClientList(khdh_keyword.value)
};
//新增工单资料产品代号【回车】
const cpdh_ProductValue = async (v) => {
  await _ProductCodeList(cpdh_keyword.value)
};
//新增工单->客户列表
const _gClientList = async (v = '')=>{
  try {
      const ClientListdata = await ClientList({search: v});
    console.log("客户列表数据↓↓↓↓↓↓↓↓")
    console.log(ClientListdata)
    khdhDataList.value = ClientListdata.data
  } catch (error) {
    console.error(error);
  }
}
//新增工单->产品代号列表
const _ProductCodeList = async (v = '')=>{
  try {
      const ProductCodeListdata = await ProductCodeList({cilent: v});
    console.log("产品代号列表数据↓↓↓↓↓↓↓↓")
    console.log(ProductCodeListdata)
    cpdhDataList.value = ProductCodeListdata.data
  } catch (error) {
    console.error(error);
  }
}

const gongdanSearchHandle = async (v, type) => {
  if (type === '客户代号') {
      await _gClientList(v)
  }
  if (type === '产品代号') {
    await _ProductCodeList(v)
  }
}
//点击客户代号
const selectGongDanNode = (node, type) => {
  if (type === '客户代号') {
    add_gdscgdformData['客户代号'] = node.客户编号
    add_gdscgdformData['客户名称'] = node.客户名称
    scgdformData.value['客户代号'] = node.客户编号
    scgdformData.value['客户名称'] = node.客户名称
    khdhModal.value = false
  }
  if (type === '产品代号') {
    add_gdscgdformData['产品代号'] = node.产品编号
    add_gdscgdformData['产品名称'] = node.产品名称
    scgdformData.value['产品代号'] = node.产品编号
    scgdformData.value['产品名称'] = node.产品名称
    cpdhModal.value = false
  }
}

const xzgdzlInput =ref()
const addgdzlcpdhInput =ref()
const xzgdzlTree = ref()
const currentNodeKey = ref('')

//新增工单资料弹窗 键盘 input框跳转
const add_gdzlent = async (event,id1,id2,id3) => {
  if(event.keyCode === 40){
    if(id3!=''){
      document.getElementById(id3).focus()
    }
  }else if (event.keyCode === 13) { // Enter 或向下箭头
    if(id3!=''){
      document.getElementById(id3).focus()
    }
  } else if (event.keyCode === 38) { // 向上箭头
    if(id1!=''){
      document.getElementById(id1).focus()
    }
  }else if (event.keyCode === 8) { // 删除箭头
    if(id1!='' && document.getElementById(id2).value==''){
      document.getElementById(id1).focus()
    }
  }else if (event.keyCode === 37) { // 向左箭头
    if(id1!='' && document.getElementById(id2).selectionStart==0){
      document.getElementById(id1).focus()
    }
  }else if (event.keyCode === 39) { // 向右箭头
    if(id3!='' && document.getElementById(id2).selectionStart == document.getElementById(id2).value.length){
      document.getElementById(id3).focus()
    }
  }

  if (id2 === '客户代号' && event.key==='Tab' || id2 === '客户代号' && event.key=== 'Enter') {
    khdhModal.value = true
    await _gClientList(add_gdscgdformData['客户代号'])
    if (khdhDataList.value != null) {
      const row = khdhDataList.value.find(item => item.客户编号 === add_gdscgdformData['客户代号'])
      if (row) {
        add_gdscgdformData['客户名称'] = row.客户名称
      } else {
        khdhModal.value = true
      }
    } else {
      khdhModal.value = true
    }
    await nextTick(() => {
      setTimeout(() => {
        xzgdzlInput.value.focus()
      }, 200)
    })
  }

  if (id2 === '产品代号' && event.key==='Tab' || id2 === '产品代号' && event.key=== 'Enter') {
    await _ProductCodeList()
    cpdhModal.value = true
    //自动获取光标
    await nextTick(() => {
      setTimeout(() => {
        addgdzlcpdhInput.value.focus()
      }, 200)
    })
  }
}
let isdeFun = false
watch(() => khdhModal.value, async v => {
  await nextTick(() => {
    if (xzgdzlTree.value !== undefined) {
      const defun = (e) => {
        isdeFun = true
        if (e.code === 'Enter' && currentNodeKey.value !== '') {
          selectGongDanNode(khdhDataList.value.find(item => item['客户编号'] == currentNodeKey.value), '客户代号')
          return
        }
        if (e.code === 'ArrowDown') {
          if (currentNodeKey.value === '') {
            currentNodeKey.value = khdhDataList.value[0].客户编号
          } else {
            console.log(khdhDataList.value)
            for(let i = 0; i < khdhDataList.value.length; i++) {
              const item = khdhDataList.value[i]
              if (item['客户编号'] == currentNodeKey.value) {
                if (khdhDataList.value[i + 1]) {
                  currentNodeKey.value = khdhDataList.value[i + 1].客户编号
                  break;
                } else {
                  currentNodeKey.value = khdhDataList.value[0].客户编号
                }
              }
            }
          }
        }
        if (e.code === 'ArrowUp') {
          if (currentNodeKey.value === '') {
            currentNodeKey.value = khdhDataList.value[khdhDataList.value.length - 1].客户编号
          } else {
            for(let i = 0; i < khdhDataList.value.length; i++) {
              const item = khdhDataList.value[i]
              if (item['客户编号'] == currentNodeKey.value) {
                if (khdhDataList.value[i - 1]) {
                  currentNodeKey.value = khdhDataList.value[i - 1].客户编号
                  break;
                } else {
                  currentNodeKey.value = khdhDataList.value[khdhDataList.value.length - 1].客户编号
                }
              }
            }
          }
        }
      }
      if (v === true) {
        isdeFun || document.body.addEventListener('keydown', defun)
        isdeFun && document.body.removeEventListener('keydown', defun)
      } else {
        document.body.removeEventListener('keydown', defun)
      }
    }
  })
})

// =========== 新增印件资料 ===========
//默认弹窗关闭
const yjzuidahaoma = ref(0)
const add_gdyjdialogFormVisible = ref(false)
const searchModel = ref(false)
const searchZhiModel = ref(false)
const zzdhIndex = ref(null)
const getProductYjListdata = ref()
const getProductZhiListdata = ref()
const yjdh_keyword = ref('')
const zhi_keyword = ref('')

// 新增印件资料表单
const add_yjzlformdata = reactive({
  yjno: '',
  yjdh: '',
  yjmc: '',
  zzdh: '',
  zzdh1: '',
  zzdh2: '',
  zzdh3: '',
  zzdh4: '',
  zzmc: '',
  zzmc1: '',
  zzmc2: '',
  zzmc3: '',
  zzmc4: '',
  cpsl: '',
  sjtl: '',
  pztl: '',
  tlgg: '',
  klgg: '',
  hsgg: '',
  ks: '',
  ls: '',
  desc: '',
  万小张: '',
});

//清空对象的属性值
const gdyj_clearFormData = () => {
  Object.keys(add_yjzlformdata).forEach(key => {
    add_yjzlformdata[key] = '';
  });
  if (isNaN(yjzuidahaoma.value)) {
    add_yjzlformdata.yjno = 1;
  } else {
    add_yjzlformdata.yjno = yjzuidahaoma.value;
  }
  add_yjzlformdata['pztl'] = 0;
  add_yjzlformdata['ks'] = 0;
  add_yjzlformdata['ls'] = 0;
  add_yjzlformdata['万小张'] = 0;
  console.log(add_yjzlformdata.yjno)

};

//点击新增印件资料按钮
const addgdyj_onclick = () => {
  if(_Gd_gdbh.value == null){
    cgugdlist.value = false;
    ElMessage({type: 'warning',message: '请选择具体的工单后，再操作此功能' })
  }else{
    gdyj_clearFormData();
    add_gdyjdialogFormVisible.value = true
  }
}
//印件新增确定
const add_gdyjenterDialog =  async  () => {
  if(add_yjzlformdata['yjno'] === ''){
    ElMessage({type: 'warning',message: '印件号不能为空'})
    return false;
  }
  // if(add_yjzlformdata['yjdh'] === ''){
  //   ElMessage({type: 'warning',message: '印件代号不能为空'})
  //   return false;
  // }
  // if(add_yjzlformdata['zzdh'] === ''){
  //   ElMessage({type: 'warning',message: '纸张编号不能为空'})
  //   return false;
  // }
  const formattedData = {
    Yj_Gdbh: _Gd_gdbh.value,
    yj_cpdh: _Gd_cpdh.value,
    yj_Yjno: add_yjzlformdata['yjno'],
    yj_Yjdh: add_yjzlformdata['yjdh'],
    yj_yjmc: add_yjzlformdata['yjmc'],
    yj_zzdh: add_yjzlformdata['zzdh'],
    yj_zzdh1: add_yjzlformdata['zzdh1'],
    yj_zzdh2: add_yjzlformdata['zzdh2'],
    yj_zzdh3: add_yjzlformdata['zzdh3'],
    yj_zzdh4: add_yjzlformdata['zzdh4'],
    yj_zzmc: add_yjzlformdata['zzmc'],
    yj_zzmc1: add_yjzlformdata['zzmc1'],
    yj_zzmc2: add_yjzlformdata['zzmc2'],
    yj_zzmc3: add_yjzlformdata['zzmc3'],
    yj_zzmc4: add_yjzlformdata['zzmc4'],
    yj_tlgg: add_yjzlformdata['tlgg'],
    yj_klgg: add_yjzlformdata['klgg'],
    Yj_核算规格: add_yjzlformdata['hsgg'],
    yj_成品数量: add_yjzlformdata['cpsl'],
    yj_平张投料: add_yjzlformdata['pztl'],
    yj_ks: add_yjzlformdata['ks'],
    yj_ls: add_yjzlformdata['ls'],
    yj_desc: add_yjzlformdata['desc'],
    Sys_id  : _username.value,
  };
  const PrintDetailAdd_add = await PrintDetailAdd(formattedData);
  if(PrintDetailAdd_add.code === 0) {
    ElMessage({type: 'success',message: '添加成功'})
    add_gdyjdialogFormVisible.value = false
	let row = {
			 '工单编号':_Gd_gdbh.value,
			 '产品代号':_Gd_cpdh.value,
			 '产品名称':_Gd_cpmc.value,
	}
	tableRowClick (row)
  } else {
    ElMessage({type: 'error',message: '添加失败' })
  }
}
//印件新增取消
const add_dyjcloseDialog = () => {add_gdyjdialogFormVisible.value = false}

//印件新增【印件代码】树状图
const handleTreeData = (treeData) => {
 const data = Object.keys(treeData).map((key)=>({
   label:key,
    children: Object.keys(treeData[key]).map((keys)=>({
      label:keys,
      children:treeData[key][keys].map(item=>({
        label:`${item.物料代码} ${item.物料名称}`,
        物料代码:item.物料代码,
        物料名称:item.物料名称
      }))
    }))
  }))
  return data
}

//印件新增【纸张】树状图
const handleTreeDatas = (treeData) => {
  const data = Object.keys(treeData).map((key)=>({
    label:key,
    children: Object.keys(treeData[key]).map((keys)=>({
      label:keys,
      children:Object.keys(treeData[key][keys]).map((keyss)=>({
        label:keyss,
        children:treeData[key][keys][keyss].map(item=>({
          label:`${item.物料代码} ${item.物料名称}`,
          规格:item.规格,
          物料代码:item.物料代码,
          物料名称:item.物料名称
        }))
      }))
    }))
  }))
  return data
}

//3.4获取印件代码及名称
const _getProductYjList = async ()=>{
  try {
    const response = await getProductYjList({search:''});
    getProductYjListdata.value = handleTreeData(response.data)
  } catch (error) {
    console.error(error);
  }
}
//3.5获取纸张代号及名称
const _getProductZzList = async (v)=>{
  console.log(v)
  try {
    const response = await getProductZzList({search:v});
    getProductZhiListdata.value = handleTreeDatas(response.data)
  } catch (error) {
    console.error(error);
  }
}
//3.4获取印件代码及名称
const searchHandle = async (v) => {
  const response = await getProductYjList({search:v});
  getProductYjListdata.value = handleTreeData(response.data)
}
//3.5获取纸张代号及名称
const searchZhiHandle = async(v) => {
  const response = await getProductZzList({search:v});
  getProductZhiListdata.value = handleTreeDatas(response.data)
}
//印件代码tab 点击事件
const selectNode = (v) => {
  if(v.物料名称){
    add_yjzlformdata['yjdh'] = v.物料代码
      add_yjzlformdata['yjmc'] = v.物料名称
      searchModel.value= false
  }
}
//纸张tab 点击事件
const selectZhiNode = (v) => {
  if(v.物料名称){
    if (zzdhIndex.value == 0) {
          add_yjzlformdata['zzdh'] = v.物料代码
          add_yjzlformdata['zzmc'] = v.物料名称
          add_yjzlformdata['tlgg'] = v.规格
        } else {
          add_yjzlformdata['zzdh' + zzdhIndex.value] = v.物料代码
          add_yjzlformdata['zzmc' + zzdhIndex.value] = v.物料名称
        }
    searchZhiModel.value = false
  }
}
//新增印件表格input
const add_gdzlyjent = async (event,id1,id2,id3,idx) => {
  if (id2 === 'yjdh' && event.key==='Tab' || id2 === 'yjdh' && event.key=== 'Enter') {
    _getProductYjList();
    searchModel.value = true
  }
  if(id2=='pztl' && event.key==='Tab' || id2 === 'pztl' && event.key=== 'Enter'){
	  add_yjzlformdata.万小张 = add_yjzlformdata.pztl*add_yjzlformdata.ls/10000
  }
  if(id2=='ls' && event.key==='Tab' || id2 === 'ls' && event.key=== 'Enter'){
  	  add_yjzlformdata.万小张 = add_yjzlformdata.pztl*add_yjzlformdata.ls/10000
  }
  if (id2 === 'zzdh' && event.key==='Tab' || id2 === 'zzdh' && event.key=== 'Enter') {
    _getProductZzList(add_yjzlformdata['zzdh'])
    searchZhiModel.value = true
    zzdhIndex.value = idx
  }
  if (id2 === 'zzdh1' && event.key==='Tab' || id2 === 'zzdh1' && event.key=== 'Enter') {
    _getProductZzList(add_yjzlformdata['zzdh1'])
    searchZhiModel.value = true
    zzdhIndex.value = idx
  }
  if (id2 === 'zzdh2' && event.key==='Tab' || id2 === 'zzdh2' && event.key=== 'Enter') {
    _getProductZzList(add_yjzlformdata['zzdh2'])
    searchZhiModel.value = true
    zzdhIndex.value = idx
  }
  if (id2 === 'zzdh3' && event.key==='Tab' || id2 === 'zzdh3' && event.key=== 'Enter') {
    _getProductZzList(add_yjzlformdata['zzdh3'])
    searchZhiModel.value = true
    zzdhIndex.value = idx
  }
  if (id2 === 'zzdh4' && event.key==='Tab' || id2 === 'zzdh4' && event.key=== 'Enter') {
    _getProductZzList(add_yjzlformdata['zzdh4'])
    searchZhiModel.value = true
    zzdhIndex.value = idx
  }
  if(event.keyCode === 40){
    if(id3!=''){
      document.getElementById(id3).focus()
    }
  }else if (event.keyCode === 13) { // Enter 或向下箭头
    if(id3!=''){
      document.getElementById(id3).focus()
    }
  } else if (event.keyCode === 38) { // 向上箭头
    if(id1!=''){
      document.getElementById(id1).focus()
    }
  }else if (event.keyCode === 8) { // 删除箭头
    if(id1!='' && document.getElementById(id2).value==''){
      document.getElementById(id1).focus()
    }
  }else if (event.keyCode === 37) { // 向左箭头
    if(id1!='' && document.getElementById(id2).selectionStart==0){
      document.getElementById(id1).focus()
    }
  }else if (event.keyCode === 39) { // 向右箭头
    if(id3!='' && document.getElementById(id2).selectionStart == document.getElementById(id2).value.length){
      document.getElementById(id3).focus()
    }
  }
}


// =========== 新增工艺资料 ===========
const add_gdgydialogFormVisible = ref(false)
const add_gdgyformData = reactive({});
//清空对象的属性值
// const gdgy_clearFormData = () => {
//   Object.keys(add_gdgyformData).forEach(key => {
//     add_gdgyformData[key] = '';
//   });
// };
//新增工艺资料弹窗//
const addgdgy_onclick = () => {
  if(_Gd_gdbh.value == null){
    cgugdlist.value = false;
    ElMessage({
      type: 'warning',
      message: '请选择具体的工单后，再操作此功能'
    })
  }else{
    let gongxu = gytableData.value.map(item => {
      return item['印件-工序']
    })
    addGongYiRef.value.open(_Gd_gdbh.value, gongxu)
  }
}

//同步
const gdtb_onclick = async ()=>{
  const WorkOrderDatada = await WorkOrderData();
  console.log(WorkOrderDatada)
  ElMessage({ type: 'warning',message: WorkOrderDatada.msg});
}


// =========== 查改U8工单 ===========
const cgugdlist = ref(false);
const cgugdformData = reactive({
  gdbh: '',
  cpdh: '',
  gdmc: '',
});
const cgugdtableData = ref([]);
//查改U8工单【按钮】
const oneditugdclick = () => {
  if(_Gd_gdbh.value == null){
    cgugdlist.value = false;
    ElMessage({
      type: 'warning',
      message: '请选择具体的工单后，再操作此功能'
    })
  }else{
    cgugdformData['gdbh'] = _Gd_gdbh.value;
    cgugdformData['cpdh'] = _Gd_cpdh.value;
    cgugdformData['gdmc'] = _Gd_cpmc.value;
    _U8workOrder();
    cgugdlist.value = true;
  }
};

//查改U8工单【回车】
const cgugdProductValue = () => {
  _U8workOrder();
};

//查改U8工单->工单列表
const _U8workOrder = async ()=>{
  let workOrder = cgugdformData['gdbh'];
  // console.log(workOrder)
  try {
    const U8workOrderdata = await U8workOrder({workOrder:workOrder});
    cgugdtableData.value = U8workOrderdata.data;
  } catch (error) {
    console.error(error);
  }
}

// 多选数据
const multipleSelection = ref([]);

//查改U8工单多选
const cguzlgd_del = (val) => {
  if (Array.isArray(val) && val.length === 0) {
    multipleSelection.value = [];
  } else {
    multipleSelection.value = [];
    multipleSelection.value.push(...val.map(item => item.序号));
  }
}

//查改U8工单（工单删除）
const oncgugdclickdel = async ()=>{
  const Uniqid = multipleSelection.value.join(',');
  // console.log(Uniqid)
  try {
    const U8DataCorrection_del = await U8DataCorrection({Uniqid:Uniqid});
    if (U8DataCorrection_del.code === 0) {
      multipleSelection.value = [];
      ElMessage({type: 'success',message: '删除成功'})
      const U8workOrderdata = await U8workOrder({workOrder:cgugdformData['gdbh']});
      cgugdtableData.value = U8workOrderdata.data;
    } else {
      ElMessage({type: 'error',message: '删除失败'})
    }
    // 清空 multipleSelection 为空数组，只有在处理完数据后清空
  } catch (error) {
    console.error(error);
  }
}

//查改U8工单【退出】
const oncgugdcloneclick = () => {
  cgugdlist.value = false;
};

// =========== 工艺流程调整 ===========
const gylctztableColumns = ref(
    [
      { label: '方案', prop: '方案', width: '60' },
      { label: '印件号', prop: '印件号', width: '70' },
      { label: '工序号', prop: '工序号', width: '80' },
      { label: '工序名称', prop: '工序名称', width: '440' },
      { label: '工价系数', prop: '工价系数', width: '100' },
      { label: '损耗系数', prop: '损耗系数', width: '100' },
      { label: '开数', prop: 'ks', width: '60' },
      { label: '联数', prop: 'ls', width: '60' },
      { label: '备注', prop: '备注', width: '200' },
      { label: '车间', prop: '车间', width: '90' },
      { label: '设备编号', prop: '设备编号', width: '100' },
      { label: '设备名称', prop: '设备名称', width: '100' },
      { label: '建档用户', prop: '建档用户', width: '100' },
      { label: '建档时间', prop: '建档时间', width: '160' },
      { label: '更新时间', prop: '更新时间', width: '160' },
    ]
)
const gylctz_handleKeyDown = (event, x, y, prop) => {
  const currentElement = document.getElementById(`input${x}${y}`);
  if (currentElement === null && currentElement === undefined) return
  switch (event.keyCode) {
    case 13: // Enter
    case 40: // 向下箭头
      if (y < gylctztableData.value.length )
        document.getElementById(`input${x}${y + 1}`).focus();
      break;
    case 38: // 向上箭头
      if ( y > 0) {
        document.getElementById(`input${x}${y - 1}`).focus();
      }
      break;
    default:
      break;
  }
}
const gylctzlist = ref(false);
const gylctzformData = reactive({
  gdbh: '',
  gddh: '',
  gdmc: '',
});
const gylctztableData = ref([]);
//工艺流程调整【按钮】
const oneditgylctzclick = () => {
  if(_Gd_gdbh.value == null){
    gylctzlist.value = false;
    ElMessage({type: 'warning',message: '请选择具体的工单后，再操作此功能'})
  }else{
    gylctzformData['gdbh'] = _Gd_gdbh.value;
    _ProcessFlow();
    gylctzlist.value = true;
  }
};
////工艺流程调整【回车】
const gylctzProductValue = () => {
  if(gylctzformData['gdbh'] == '' || gylctzformData['gdbh'] === null){
    ElMessage({type: 'warning',message: '工单编号为空'})
    return false;
  }
  _ProcessFlow();
};

// 工艺流程调整->获取当前工单工艺资料
const _ProcessFlow = async ()=>{
  let workOrder = gylctzformData['gdbh'];
  try {
    const ProcessFlowdata = await ProcessFlow({workOrder:workOrder});
    if(ProcessFlowdata.msg === '未找到工单信息'){
      ElMessage({type: 'warning',message: '未找到工单信息'});
      gylctztableData.value = [];
      return false;
    }
    gylctzformData["gddh"] = ProcessFlowdata.data.成品编号;
    gylctzformData["gdmc"] = ProcessFlowdata.data.成品名称;
    gylctztableData.value = ProcessFlowdata.data.process;
  } catch (error) {
    console.error(error);
  }
}
//附加标准工序【按钮】
const gdzlfjxx = ref(false);
const gdzlfjxxformData = reactive({
  gdbh: '',
  cpmc: '',
  // 下拉框选项数据
  cpgyfans: [],
  // 设置默认值
  cpgyfan: '',
});
//点击下拉框获取输入框的值
const ongdzlfanclick = () => {
  const workOrder = gdzlfjxxformData.cpgyfan;
  _ProcessFlow_xiala(workOrder);
}
// 工艺流程调整->获取当前工单工艺资料
const gdzlfjxxtableData = ref([]);
const _ProcessFlow_xiala = async (workOrder)=>{
  try {
    const ProcessFlow_xiala = await ProcessFlow({ workOrder });
    if (ProcessFlow_xiala.data) {
      gdzlfjxxtableData.value = ProcessFlow_xiala.data.process;
    } else {
      console.log("工艺流程调整->获取当前工单工艺资料 中缺少 data 属性");
    }
  } catch (error) {
    console.error(error);
  }
}
//工艺方案附加【下拉框工单编号数据】
const attachList = ref([])
const attachChange = (val) => {
  attachList.value = val
}
//工艺方案附加【执行】
const addGongyiAttach = () => {
  attachList.value.map(row => gylctztableData.value.push(row))
  gdzlfjxx.value = false
}
const gdzlfjxxtableColumns = ref(
    [
      { label: '方案', prop: '方案', width: '60' },
      { label: '印件号', prop: '印件号', width: '70' },
      { label: '工序号', prop: '工序号', width: '70' },
      { label: '工序名称', prop: '工序名称', width: '370' },
      { label: '工价系数', prop: '工价系数', width: '87' },
      { label: '损耗系数', prop: '损耗系数', width: '87' },
      { label: '开数', prop: 'ks', width: '65' },
      { label: '联数', prop: 'ls', width: '65' },
      { label: '备注', prop: '备注', width: '240' },
      { label: '车间', prop: '车间', width: '105' },
      { label: '设备编号', prop: '设备编号', width: '100' },
      { label: '设备名称', prop: '设备名称', width: '100' },
      { label: '建档用户', prop: '建档用户', width: '100' },
      { label: '建档时间', prop: '建档时间', width: '160' },
      { label: '更新时间', prop: '更新时间', width: '160' },
    ]
)
//工艺方案附加【放弃】
const gylcfj_fangqi = () => {
  gdzlfjxx.value = false
}

//点击附加标准工序【按钮】
const gylctz_fjbzgx = async () => {
  gdzlfjxxformData['cpdh'] = gylctzformData['gddh'];
  gdzlfjxxformData['cpmc'] = gylctzformData['gdmc'];
  gdzlfjxxtableData.value = [];
  await _ReferenceWorkOrder();
  gdzlfjxx.value = true;
};
// 工艺流程调整->参照工单列表获取【展示下拉框的数据】
const _ReferenceWorkOrder = async ()=>{
  let params = {};
  params.productCode = gylctzformData['gddh'];
  params.workOrder = _Gd_gdbh.value;
  try {
    const ReferenceWorkOrder_data = await ReferenceWorkOrder(params);
    if(ReferenceWorkOrder_data.code === 0){
      // 从数据中提取方案
      const schemes = ReferenceWorkOrder_data.data || [];
      // 直接将数组作为工艺方案数组
      gdzlfjxxformData.cpgyfans = schemes;
      if (gdzlfjxxformData.cpgyfans.length > 0) {
        gdzlfjxxformData.cpgyfan = [gdzlfjxxformData.cpgyfans[0]];
      }
      //默认获取下拉框第一个值
      const workOrder = gdzlfjxxformData.cpgyfan[0]
      gdzlfjxxformData.cpgyfan = gdzlfjxxformData.cpgyfans[0]
      _ProcessFlow_xiala(workOrder)
    }else{
      console.log("该产品下没有工单")
    }
  } catch (error) {
    console.error(error);
  }
}

//更新当前产品工序【按钮】
const gylctz_gxdqcpgx = async () => {
  console.log(gylctztableData)
  const rawValueArray = gylctztableData.value;
  const formattedData = rawValueArray.map(item => {
    return {
      workOrder:gylctzformData['gdbh'],
      UniqId:item.UniqId,
      gxh:item['工序号']
    }
  });
  const ProcessCopy_edit = await ProcessCopy(formattedData);
  if(ProcessCopy_edit.code === 0) {
    ElMessage({type: 'success',message: '更新成功'})
  } else {
    ElMessage({type: 'error',message: '更新失败' })
  }
  gylctzlist.value = false;
};

//放弃操作【按钮】
const gylctzhandleCancel = () => {
  gylctzlist.value = false;
};

// =========== 工序产量核算 ===========
const gxclhslist = ref(false);
const gxclhsformData = reactive({
  gdbh: '',
});
//工序产量核算【按钮】
const oneditgxclhsclick = () => {
  if(_Gd_gdbh.value == null){
    gxclhslist.value = false;
    ElMessage({type: 'warning',message: '请选择具体的工单后，再操作此功能'})
  }else{
    gxclhsformData['gdbh'] = _Gd_gdbh.value;
    gxclhslist.value = true;
  }
};
//工序产量核算【确定】(未完成)
const gxclhshandleConfirm = async () => {
  console.log(gxclhsformData['gdbh'])
  // const  = await ({:gxclhsformData['gdbh']});
  // if (.code === 0) {
  //   ElMessage({type: 'success', message: '更新成功'})
  // } else {
  //   ElMessage({type: 'error',message: '更新失败'})
  // }
  // gxclhslist.value = false;
};
//工序产量核算【取消】
const gxclhshandleCancel = () => {gxclhslist.value = false;};
// =========== U8投料试算 ===========
const tlsslist = ref(false);
const tlsstableData = ref([]);
const tlssformData = reactive({
  cpdh: '',
  cpmc: '',
  cpzs: '',
  zytldzs: '',
  mbhgl: '',
  shs: '',
});
//点击U8投料试算【按钮】
const ontlssclick = () => {
  //工单编号
  if(_Gd_gdbh.value == null){
    tlsslist.value = false;
    ElMessage({type: 'warning',message: '请选择具体的工单后，再操作此功能'})
  }else{
    //产品代号
    if( _Gd_cpdh.value === ''){
      tlsslist.value = false;
      ElMessage({type: 'warning',message: '该产品号未查询到'})
    }else{
      tlssformData['cpdh'] =  _Gd_cpdh.value;
      tlssformData['cpmc'] = _Gd_cpmc.value;
      tlsslist.value = true;
      _U8Trial();
    }
  }
};
//点击U8投料试算【回车】
const tlssgetProductValue = async () => {
  _U8Trial();
};
//点击U8投料试算【成品张数回车】
const tlsscpzsgetProductValue = async () => {
  console.log("成品张数回车")
};
//U8投料试算
const _U8Trial = async ()=>{
  let productCode = tlssformData['cpdh'];
  try {
    const U8Trialdata = await U8Trial({productCode:productCode});
    tlsstableData.value = U8Trialdata.data;
  } catch (error) {
    console.error(error);
  }
}
//U8投料试算【退出】
const oncloneclick = () => {tlsslist.value = false;};


//===========工单状态设置按钮=======
const onstatuslist = ref(false);
const statusformData = reactive({gdbh: '',});
const status = ref('计划中'); // 默认选择
const onStatusClick = () => {
  if(_Gd_gdbh.value === null || _Gd_gdbh.value === ''){
    onstatuslist.value = false;
    ElMessage({
      type: 'warning',
      message: '请选择树形后，再操作此功能'
    })
  }else{
    statusformData['gdbh'] = _Gd_gdbh.value;
    onstatuslist.value = true;
  }
};
//工单状态设置【放弃按钮】
const handleCancel = () => {
  onstatuslist.value = false;
};
//工单状态设置【执行按钮】
const handleConfirm = async () => {
  //工单编号
  let workOrder = statusformData['gdbh'];
  //状态
  let statusCode;
  if (status.value === '计划中') {
    statusCode = "3-计划中";
  } else if (status.value === '生产中') {
    statusCode = "2-生产中";
  }else if (status.value === '已完工') {
    statusCode = "1-已完工";
  }
  const StatusEditdata = await StatusEdit({workOrder:workOrder,status:statusCode});
  if (StatusEditdata.code === 0) {
    ElMessage({type: 'success',message: '更新成功'})
  } else {
    ElMessage({type: 'error',message: '更新失败'})
  }
  onstatuslist.value = false;
};





// =========== 引用产品资料 ===========
const yycpzlformData = reactive({
  gdbh: '',
  khdh: '',
  khmc: '',
  cpdh: '',
  cpmc: '',
  yjzl:true,
  gyap: true,
  gyfa: '',
  fangan: 'A',
});
const onyycpzllist = ref(false);
const fanganRef = ref();
const yyzltableData = ref([]);

//引用产品资料【按钮】
const onyycpzlclick = () => {
  if(_Gd_gdbh.value == null){
    onyycpzllist.value = false;
    ElMessage({type: 'warning',message: '请选择具体的工单后，再操作此功能'})
  }else{
    yycpzlformData['gdbh'] = _Gd_gdbh.value;
    // yycpzlformData['cpdh'] = _Gd_cpdh.value;
    yyzltableData.value = [];
    _WorkOrderDetailCopedata();
    onyycpzllist.value = true;
  }
};
//引用产品资料工单编号【回车】
const yycpzlProductValue = async (e) => {
  if (e.code === 'Enter') {
    if (yycpzlformData['gdbh'] == null || yycpzlformData['gdbh'] == '') {
      ElMessage({ type: 'warning', message: '工单编号不能为空' })
      return false;
    }
    await _DetailCope();
  }
  if (e.code === 'Tab') {
    await  _WorkOrderDetailCopedata()
    fanganKeyDown()
  }
};
// const fanganProductValue = async (e) => {
//   if (e.code === 'Tab') {
//     console.log(123)
//     await  _WorkOrderDetailCopedata()
//     fanganRef.value.focus()
//   }
// };

const WorkOrderDetailCopesFangan = ref([])
const defaultSelectionFangan = ref()
//引用产品资料->获取产品资料
const _WorkOrderDetailCopedata = async ()=>{
  let search = yycpzlformData['gdbh'];
  // 2403725 是带两个方案的
  const WorkOrderDetailCopes = await ProductCopeDetail({workorder:search});
  console.log(WorkOrderDetailCopes)
  // fanganRef.value.focus()
  if(WorkOrderDetailCopes.msg === '未找到工单信息'){
    yycpzlformData['khdh'] = '';
    yycpzlformData['khmc'] = '';
    yycpzlformData['cpdh'] = '';
    yycpzlformData['cpmc'] =  '';
    // ElMessage({type: 'warning',message: '未找到工单信息'})
    return false;
  }else{
    yycpzlformData['gdbh'] = WorkOrderDetailCopes.data['工单编号'];
    yycpzlformData['khdh'] = WorkOrderDetailCopes.data['客户编号'];
    yycpzlformData['khmc'] = WorkOrderDetailCopes.data['客户名称'];
    yycpzlformData['cpdh'] = WorkOrderDetailCopes.data['产品编号'];
    yycpzlformData['cpmc'] = WorkOrderDetailCopes.data['产品名称'];
    yycpzlformData['fangan'] = WorkOrderDetailCopes.data['方案'][0]['方案'];
    defaultSelectionFangan.value = WorkOrderDetailCopes.data['方案'][0]['方案']
    WorkOrderDetailCopesFangan.value = WorkOrderDetailCopes.data['方案']
  }
}

// const yycppshuaxin_click = async ()=>{
//   let search = yycpzlformData['gdbh'];
//   console.log(search)
//   const WorkOrderDetailCope_table = await WorkOrderDetailCope({search:search});
//   console.log(WorkOrderDetailCope_table)
//   yyzltableData.value = WorkOrderDetailCope_table.data
// }
const _DetailCope = async (row)=>{
  let search = yycpzlformData['gdbh'];
  console.log(search)
  const WorkOrderDetailCope_table = await WorkOrderDetailCope({search:search});
  console.log(WorkOrderDetailCope_table)
  yyzltableData.value = WorkOrderDetailCope_table.data
}
const yyzltableRowClick = async (row)=>{
  yycpzlformData['gdbh'] = row['工单编号'];
  _WorkOrderDetailCopedata();
}

const setFangan = (node) => {
  yycpzlformData['fangan'] = node['方案']
  defaultSelectionFangan.value = node['方案']
  document.removeEventListener('keydown', () => {})
  openFangan.value = false
}

const openFangan = ref(false)
const fanganKeyDown = () => {
  //2403725
  if (WorkOrderDetailCopesFangan.value.length > 1) {
    openFangan.value = true
    document.addEventListener('keydown', (e) => {
      let currentIndex
      WorkOrderDetailCopesFangan.value.map( (item, index) => {
        if (item['方案'] === defaultSelectionFangan.value[0]) {
          currentIndex = index
        }
      })
      if (e.code === 'ArrowDown') {
        if (WorkOrderDetailCopesFangan.value[currentIndex + 1]) {
          defaultSelectionFangan.value = WorkOrderDetailCopesFangan.value[currentIndex + 1]['方案']
        } else {
          defaultSelectionFangan.value = WorkOrderDetailCopesFangan.value[0]['方案']
        }
      }
      if (e.code === 'ArrowUp') {
        if (WorkOrderDetailCopesFangan.value[currentIndex - 1]) {
          defaultSelectionFangan.value = WorkOrderDetailCopesFangan.value[currentIndex - 1]['方案']
        } else {
          defaultSelectionFangan.value = WorkOrderDetailCopesFangan.value[WorkOrderDetailCopesFangan.value.length - 1]['方案']
        }
      }
      if (e.code === 'Enter') {
        yycpzlformData['fangan'] = defaultSelectionFangan.value
        console.log(12312312312312321321321321)
        document.removeEventListener('keydown', (e) => {
          console.log(e)
        })
        openFangan.value = false
      }
    })
  }
}
//引用产品资料【执行】按钮
const yycpzlhandleConfirm = async () => {
  _ProductInformationEdit();
};
//引用产品资料->获取产品资料
const _ProductInformationEdit = async ()=>{
  console.log(yycpzlformData)
  if(yycpzlformData['gdbh'] === null || yycpzlformData['gdbh'] === undefined){
    ElMessage({type: 'warning', message: '工单编号为空'});
    return false;
  }
  if(yycpzlformData['cpdh'] === null || yycpzlformData['cpdh'] === undefined){
    ElMessage({type: 'warning', message: '产品代号为空'});
    return false;
  }
  if(yycpzlformData['fangan'] === null || yycpzlformData['fangan'] === undefined){
    ElMessage({type: 'warning', message: '工艺方案为空'});
    return false;
  }
  let params = {}
  params.workorder = _Gd_gdbh.value;
  params.productCode = yycpzlformData['cpdh'];
  params.option = yycpzlformData['fangan'];
  console.log(params)
  try {
    const ProductInformationEditdata = await WorkOrderDetailListCope(params);
    if (ProductInformationEditdata.code === 0) {
      const workOrderListDetail_data = await workOrderListDetail({Gd_gdbh:_Gd_gdbh.value});
      yjtableData.value = workOrderListDetail_data.data.printList;
      ElMessage({type: 'success', message: '更新成功'})
      onyycpzllist.value = false;
    }
    // else {
    //   ElMessage({type: 'error',message: '更新失败'})
    // }
  } catch (error) {
    console.error(error);
  }
}
//引用产品资料【放弃】
const yycpzlhandleCancel = () => {onyycpzllist.value = false;};

// =========== 左侧树侧形结构 ===========
const treeData = ref([]);

//工单资料菜单列表
const DataListdata = async () => {
  try {
	  
	  const response = await OutputSstatisticsMenu();
	  const dataList = response.data;
	  dataList.forEach((item) => {
	      let obj = {};
	      obj.label = item.date;
	      obj.children = [];
	      item.sbbh.forEach((child, index) => {
	          obj.children.push({
	              label: child,
	              parentDate: item.date // 添加上级日期并避免重复
	          });
	      });
	      console.log(obj);
	      treeData.value.push(obj);
	  
 //    const response = await OutputSstatisticsMenu();
 //    const dataList = response.data;
 //    dataList.forEach((item) => {
 //    let obj = {};
 //    obj.label = item.date;
 //    obj.children = [];
 //    item.sbbh.forEach((child) => {
 //        obj.children.push({label: child});
 //    });
	// console.log(obj)
 //    treeData.value.push(obj);
});
  } catch (error) {
    console.error(error);
  }
};

// const DataListdata = async () => {
//   try {
//     const data = await DataList();
//     for (let key in data.data) {
//       // 忽略 "productingAll" 和 "progressAll"
//       if (key !== "productingAll" && key !== "progressAll") {
//         let temp = data.data[key];
//         let object = {};
//         object.id = temp[0];
//         object.label = data.data[key];
//         object.children = [];
//         treeData.data.push(object);
//       }
//     }
//   } catch (error) {
//     console.error(error);
//   }
// };
DataListdata();

//点击左侧树形获取编号
const tableData = reactive([])
const _Gd_khdh = ref(null)
const params = ref({})
const params2 = ref({})
//左侧
const tabledate2 = ref([])
//右侧
const jqtabledata = ref()
const exportTableRef = ref(null);
const handleNodeClick = async (node) => {
  // 取消所有节点的颜色
  const allNodes = document.querySelectorAll('.treecolor .el-tree-node');
  allNodes.forEach(node => {
    node.querySelector('.el-tree-node__label').style.color = '';
  });
  // 获取点击的节点
  const clickedNodeId = node['$treeNodeId'];
  const clickedNode = document.querySelector(`.treecolor .el-tree-node[data-key="${clickedNodeId}"]`);
  if (clickedNode) {
    // 给当前点击的节点改变颜色
    clickedNode.querySelector('.el-tree-node__label').style.color = 'red';
  }
  console.log(node)
  tabledate2.value=[]
  if(node.children !==undefined ){
    // params.value.mouth= node.label
	params.value.mouth= node.parentDate
  }
 if (node.children === undefined){
	 params.value.mouth = node.parentDate
   params.value.sist = node.label
    MachineList(params.value)
 }
 // console.log();
  // _WorkList_page(); 
};
  const MachineList = async(params)=>{
  try {
	  console.log(params)
	  console.log(12312312321)
    const MachineListData = await MachineOperation(params);
    let data = MachineListData.data
    for (var key in data){
       if (data.hasOwnProperty(key) && key !== 'total') {  
        // 将每个设备对象添加到新数组中  
        tabledate2.value.push(data[key]);  
        }  
    }
console.log(tabledate2.value);
  } catch (error) {
    console.error(error);
  }
  }
//导出按钮（汇总）
const exportToExcel = async () => {
  const data =  await MachineOperation({mouth:params.value.mouth})
  const data2 = data.data
  const de = Object.values(data2)
  const worksheet = XLSX.utils.json_to_sheet(de);
  const workbook = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
  XLSX.writeFile(workbook, '设备数据.xlsx');
    }
//月度明细
const exportToExcel2 = () => {
  if (jqtabledata.value){
  const el = document.getElementById('tab2');
  console.log(el);
  // 文件名
  const filename = '月度明细.xlsx';
  const wb = XLSX.utils.table_to_book(el, { raw: true });
  const wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
  try {
    FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), filename);
  } catch (e) {
    console.log(e);
  }
  return wbout;
}
    }
//导出到EXCEL(明细)
const exportToExcel3 = ()=>{
  const el = document.getElementById('tab');
  // 文件名
  const filename = '导出到EXCEL(汇总).xlsx';
  const wb = XLSX.utils.table_to_book(el, { raw: true });
  const wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
  try {
    FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), filename);
  } catch (e) {
    console.log(e);
  }
  return wbout;
}

//查询
const searchInfo = ref('')
//查询按钮
const onSubmit = () => {
  _cha_WorkList();
};
const handleSearch = () => {
  console.log(1231)
  _cha_WorkList();
};

const _cha_WorkList = async (node) => {
  if(searchInfo.value === ''){
    ElMessage({type: 'warning',message: '请输入搜索的信息'})
    return false;
  }
  const search = searchInfo.value;
  var regex = /^[a-zA-Z0-9]+$/;
  try {
    if (regex.test(search)) {
      // 符合条件，执行搜索操作
      console.log('搜索内容为纯数字加字母');
      const WorkListdata = await WorkList({search:search,limit:100,page:1});//接口调用函数
      if(WorkListdata.data.total === 0){
        ElMessage({type: 'warning',message: '未搜索具体查询条件'})
      }
      tableData.splice(0,tableData.length,...WorkListdata.data.data);//表格数据
      total.value = WorkListdata.data.total;//共多少条
    } else {
      // 不符合条件，给出提示
      console.log('搜索内容包含非字母和数字的字符');
      const WorkListdata = await WorkList({Gd_khdh:'',search:search,limit:100,page:1});//接口调用函数
      if(WorkListdata.data.total === 0){
        ElMessage({type: 'warning',message: '未搜索具体查询条件'})
      }
      tableData.splice(0,tableData.length,...WorkListdata.data.data);//表格数据
      total.value = WorkListdata.data.total;//共多少条
    }
  } catch (error) {
    console.error(error);
  }
};

// 分页
const page = ref(1)
const total = ref(0)
const pageSize = ref(50)
const handleCurrentChange = (val) => {
  page.value = val;
  _WorkList_page();
};

// 修改页面容量 点击多少条/页
const handleSizeChange = (val) => {
  // page.value = 10;
  pageSize.value = val;
  _WorkList_page();
};

//点击表格行获取下方表格数据列表
//印件资料
const yjtableData = ref([])
//工艺资料
const gytableData = ref([])
//BOM资料
const bomtableData = ref([])
//技术资料附件【暂时为空】
const jstableData = reactive([])
//全局调用工单编号
const _Gd_gdbh = ref(null)
//全局调用产品代号
const _Gd_cpdh = ref(null)
//全局调用产品名称
const _Gd_cpmc = ref(null)
//机台生产工单
const tableRowClick = async (row) => {
  jqtabledata.value=null
  params2.value.machine= row.设备编号
  params2.value.mouth = params.value.mouth
   const Machineoutput = await MachineOperationProductDetail (params2.value)
   jqtabledata.value = Machineoutput.data
   console.log(jqtabledata.value);
  // _Gd_gdbh.value = row.工单编号;
  // _Gd_cpdh.value = row.产品代号;
  // _Gd_cpmc.value = row.产品名称;
  // const workOrderListDetail_data = await workOrderListDetail({Gd_gdbh:_Gd_gdbh.value});
  // yjtableData.value = workOrderListDetail_data.data.printList;
  // gytableData.value = workOrderListDetail_data.data.processList;
  // bomtableData.value = workOrderListDetail_data.data.BOM;
  // jstableData.splice(0, jstableData.length, ...workOrderListDetail_data.data.jsData);
  // jstableData.value = workOrderListDetail_data.data.jsData;
  let tmp = yjtableData.value.map(item => item.印件号)
  tmp = tmp.sort((a,b)=>b-a)
  yjzuidahaoma.value = Number(tmp[0]) + 1
};


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

//=========表格列表修改========
let scgdformData = ref({})
//双击修改
const updateCompanyFunc = async(row) => {
  console.log(row)
  // if(row['status'] === '*'){
  //   ElMessage({ type: 'warning', message: '未找到该工单印件资料' });
  //   return false;
  // }else{
    const DataCorrection_list = await DataCorrection({ Gd_gdbh:row['工单编号']});
    console.log(DataCorrection_list)
    scgdformData.value = DataCorrection_list.data;
    dialogFormVisible.value = true
  // }
}
// 弹窗控制标记
const dialogFormVisible = ref(false)
// 修改工单资料确定
const enterDialog = async () => {
  const zdgx = /^[A-Za-z0-9\u4e00-\u9fa5\s]*$/.test(scgdformData.value['重点工单']);
  if (!zdgx) {
    ElMessage({ type: 'warning', message: '重点工单数据中 只允许出现中文、数字、空格' });
    return false;
  }
  const kdrqdeliveryDate = new Date(scgdformData.value['开单日期']);
  const kdrq = kdrqdeliveryDate.getFullYear() + '-' +
      (kdrqdeliveryDate.getMonth() + 1).toString().padStart(2, '0') + '-' +
      kdrqdeliveryDate.getDate().toString().padStart(2, '0') + ' ' +
      kdrqdeliveryDate.getHours().toString().padStart(2, '0') + ':' +
      kdrqdeliveryDate.getMinutes().toString().padStart(2, '0') + ':' +
      kdrqdeliveryDate.getSeconds().toString().padStart(2, '0');
  const jhrqdeliveryDate = new Date(scgdformData.value['交货日期']);
  const jhrq = jhrqdeliveryDate.getFullYear() + '-' +
      (jhrqdeliveryDate.getMonth() + 1).toString().padStart(2, '0') + '-' +
      jhrqdeliveryDate.getDate().toString().padStart(2, '0') + ' ' +
      jhrqdeliveryDate.getHours().toString().padStart(2, '0') + ':' +
      jhrqdeliveryDate.getMinutes().toString().padStart(2, '0') + ':' +
      jhrqdeliveryDate.getSeconds().toString().padStart(2, '0');
  const formattedData = {
    lx: scgdformData.value['重点工单'],
    kdrq: kdrq,
    gdbh: scgdformData.value['工单编号'],
    scfl: scgdformData.value['生产类型'],
    khdh: scgdformData.value['客户代号'],
    khmc: scgdformData.value['客户名称'],
    cpdh: scgdformData.value['产品代号'],
    cpmc: scgdformData.value['产品名称'],
    ddsl: scgdformData.value['订单数量'],
    jhrq: jhrq,
    tll: scgdformData.value['投料率'],
    jhtl: scgdformData.value['平张投料'],
    sjtl: scgdformData.value['万小张'],
    jldw: scgdformData.value['单位'],
    tldx: scgdformData.value['投料大箱'],
    xsddh: scgdformData.value['销售订单号'],
    jymb: scgdformData.value['警语版面'],
    bbh: scgdformData.value['版本号'],
    erp: scgdformData.value['客户ERP编码'],
    ymsl: scgdformData.value['码源数量'],
    jcbz: scgdformData.value['进程备注'],
    desc: scgdformData.value['备注'],
    Uniqid: scgdformData.value['Uniqid'],
    yjdh: scgdformData.value['印件代号'],
    yjmc: scgdformData.value['印件名称'],
    kc: scgdformData.value['库存大箱'],
    avg:scgdformData.value['平均合格率'] === undefined ? '' : scgdformData.value['平均合格率'],
    printID: scgdformData.value['印件ID'],
  };
  console.log(formattedData)
  const WorkOrderEdit_edit = await WorkOrderEdit(formattedData);
  if (WorkOrderEdit_edit.code === 0) {
    dialogFormVisible.value = false
    ElMessage({type: 'success',message: '更新成功' })
  } else {
    ElMessage({type: 'error', message: '更新失败'})
  }
}
// 关闭弹窗
const closeDialog = () => {dialogFormVisible.value = false}

//=========印件列表修改========
// 弹窗控制标记
const gdyjdialogFormVisible = ref(false)
const gdyjformData = reactive({})
const edit_searchModel = ref(false)
const edit_searchZhiModel = ref(false)
const edit_zzdhIndex = ref(null)
const edit_getProductYjListdata = ref()
const edit_getProductZhiListdata = ref()
const edit_yjdh_keyword = ref('')
const edit_zhi_keyword = ref('')

//双击打开印件列表修改
const gdyjupdateCompanyFunc = async(row) => {
  gdyjformData['开数'] = row['开数'];
  gdyjformData['联数'] = row['联数'];
  Object.assign(gdyjformData,row);
  gdyjdialogFormVisible.value = true
}

//印件列表修改【确定】
const gdyjenterDialog = async () => {
  const formattedData = {
    Uniqid: gdyjformData['Uniqid'],
    yjno: gdyjformData['印件号'] ? gdyjformData['印件号'] : "",
    yjdh: gdyjformData['印件代号'] ? gdyjformData['印件代号'] : "",
    yjmc: gdyjformData['印件名称'] ? gdyjformData['印件名称'] : "",
    zzdh:gdyjformData['纸张代号'] ? gdyjformData['纸张代号'] : "",
    zzmc:gdyjformData['纸张名称'] ? gdyjformData['纸张名称'] : "",
    zzdh1:gdyjformData['zzdh1'] ? gdyjformData['zzdh1'] : "",
    zzdh2:gdyjformData['zzdh2'] ? gdyjformData['zzdh2'] : "",
    zzdh3:gdyjformData['zzdh3'] ? gdyjformData['zzdh3'] : "",
    zzdh4:gdyjformData['zzdh4'] ? gdyjformData['zzdh4'] : "",
    zzmc1:gdyjformData['zzmc1'] ? gdyjformData['zzmc1'] : "",
    zzmc2:gdyjformData['zzmc2'] ? gdyjformData['zzmc2'] : "",
    zzmc3:gdyjformData['zzmc3'] ? gdyjformData['zzmc3'] : "",
    zzmc4:gdyjformData['zzmc4'] ? gdyjformData['zzmc4'] : "",
    cpsl:gdyjformData['订单数量'] ? gdyjformData['订单数量'] : "",
    pztl:gdyjformData['平张投料'] ? gdyjformData['平张投料'] : "",
    sjtl:gdyjformData['万小张'] ? gdyjformData['万小张'] : "",
    tlgg:gdyjformData['投料规格'] ? gdyjformData['投料规格'] : "",
    klgg:gdyjformData['开料规格'] ? gdyjformData['开料规格'] : "",
    ks:gdyjformData['开数'] ? gdyjformData['开数'] : "",
    ls:gdyjformData['联数'] ? gdyjformData['联数'] : "",
    hsgg:gdyjformData['核算规格'] ? gdyjformData['核算规格'] : "",
    desc:gdyjformData['备注'] ? gdyjformData['备注'] : "",
  };
  const PrintedEdit_edit = await PrintedEdit(formattedData);
  if (PrintedEdit_edit.code === 0) {
    gdyjdialogFormVisible.value = false
    ElMessage({type: 'success',message: '更新成功' })
	let row = {
			 '工单编号':_Gd_gdbh.value,
			 '产品代号':_Gd_cpdh.value,
			 '产品名称':_Gd_cpmc.value,
	}
	tableRowClick (row)
  } else {
    ElMessage({type: 'error', message: '更新失败'})
  }
}

// 印件列表修改【关闭弹窗】
const gdyjcloseDialog = () => {
  gdyjdialogFormVisible.value = false
}

//印件修改【印件代码】树状图
const edit_handleTreeData = (treeData) => {
  const data = Object.keys(treeData).map((key)=>({
    label:key,
    children: Object.keys(treeData[key]).map((keys)=>({
      label:keys,
      children:treeData[key][keys].map(item=>({
        label:`${item.物料代码} ${item.物料名称}`,
        物料代码:item.物料代码,
        物料名称:item.物料名称
      }))
    }))
  }))
  return data
}

//印件修改【纸张】树状图
const edit_handleTreeDatas = (treeData) => {
  const data = Object.keys(treeData).map((key)=>({
    label:key,
    children: Object.keys(treeData[key]).map((keys)=>({
      label:keys,
      children:Object.keys(treeData[key][keys]).map((keyss)=>({
        label:keyss,
        children:treeData[key][keys][keyss].map(item=>({
          label:`${item.物料代码} ${item.物料名称}`,
          规格:item.规格,
          物料代码:item.物料代码,
          物料名称:item.物料名称
        }))
      }))
    }))
  }))
  return data
}

//3.4获取印件代码及名称
const edit_getProductYjList = async ()=>{
  try {
    const response = await getProductYjList({search:''});
    edit_getProductYjListdata.value = edit_handleTreeData(response.data)
  } catch (error) {
    console.error(error);
  }
}

//3.5获取纸张代号及名称
const edit_getProductZzList = async (v)=>{
  console.log(v)
  try {
    const response = await getProductZzList({search:v});
    edit_getProductZhiListdata.value = edit_handleTreeDatas(response.data)
  } catch (error) {
    console.error(error);
  }
}

//3.4获取印件代码及名称
const edit_searchHandle = async (v) => {
  const response = await getProductYjList({search:v});
  edit_getProductYjListdata.value = edit_handleTreeData(response.data)
}

//3.5获取纸张代号及名称
const edit_searchZhiHandle = async(v) => {
  const response = await getProductZzList({search:v});
  edit_getProductZhiListdata.value = edit_handleTreeDatas(response.data)
}

//印件代码tab 点击事件
const edit_selectNode = (v) => {
  if(v.物料名称){
    gdyjformData['印件代号'] = v.物料代码
    gdyjformData['印件名称'] = v.物料名称
    edit_searchModel.value= false
  }
}
//纸张tab 点击事件
const edit_selectZhiNode = (v) => {
  if(v.物料名称){
    if (edit_zzdhIndex.value == 0) {
      gdyjformData['纸张代号'] = v.物料代码
      gdyjformData['纸张名称'] = v.物料名称
      gdyjformData['投料规格'] = v.规格
    } else {
      gdyjformData['备用纸张' + edit_zzdhIndex.value] = v.物料代码
      gdyjformData['纸张名称' + edit_zzdhIndex.value + edit_zzdhIndex.value] = v.物料名称
    }
    edit_searchZhiModel.value = false
  }
}

//修改印件表格input
const edit_gdyjent = (event,id1,id2,id3,idx) => {
  if (id2 === '印件代号' && event.key==='Tab' || id2 === '印件代号' && event.key=== 'Enter') {
    edit_getProductYjList();
    edit_searchModel.value = true
  }
  if(id2=='平张投料' && event.key==='Tab' || id2 === '平张投料' && event.key=== 'Enter'){
  	  gdyjformData.万小张 = gdyjformData.平张投料*gdyjformData.联数/10000
  }
  if(id2=='联数' && event.key==='Tab' || id2 === '联数' && event.key=== 'Enter'){
  	  gdyjformData.万小张 = gdyjformData.平张投料*gdyjformData.联数/10000
  }
  if (id2 === '纸张代号' && event.key==='Tab' || id2 === '纸张代号' && event.key=== 'Enter') {
    edit_getProductZzList(gdyjformData['纸张代号'])
    edit_searchZhiModel.value = true
    edit_zzdhIndex.value = idx
  }
  if (id2 === '备用纸张1' && event.key==='Tab' || id2 === '备用纸张1' && event.key=== 'Enter') {
    edit_getProductZzList(gdyjformData['备用纸张1'])
    edit_searchZhiModel.value = true
    edit_zzdhIndex.value = idx
  }
  if (id2 === '备用纸张2' && event.key==='Tab' || id2 === '备用纸张2' && event.key=== 'Enter') {
    edit_getProductZzList(gdyjformData['备用纸张2'])
    edit_searchZhiModel.value = true
    edit_zzdhIndex.value = idx
  }
  if (id2 === '备用纸张3' && event.key==='Tab' || id2 === '备用纸张3' && event.key=== 'Enter') {
    edit_getProductZzList(gdyjformData['备用纸张3'])
    edit_searchZhiModel.value = true
    edit_zzdhIndex.value = idx
  }
  if (id2 === '备用纸张4' && event.key==='Tab' || id2 === '备用纸张4' && event.key=== 'Enter') {
    edit_getProductZzList(gdyjformData['备用纸张4'])
    edit_searchZhiModel.value = true
    edit_zzdhIndex.value = idx
  }
  if(event.keyCode === 40){
    if(id3!=''){
      document.getElementById(id3).focus()
    }
  }else if (event.keyCode === 13) { // Enter 或向下箭头
    if(id3!=''){
      document.getElementById(id3).focus()
    }
  } else if (event.keyCode === 38) { // 向上箭头
    if(id1!=''){
      document.getElementById(id1).focus()
    }
  }else if (event.keyCode === 8) { // 删除箭头
    if(id1!='' && document.getElementById(id2).value==''){
      document.getElementById(id1).focus()
    }
    // console.log(document.getElementById(id2).value)
  }else if (event.keyCode === 37) { // 向左箭头
    if(id1!='' && document.getElementById(id2).selectionStart==0){
      document.getElementById(id1).focus()
    }
  }else if (event.keyCode === 39) { // 向右箭头
    if(id3!='' && document.getElementById(id2).selectionStart == document.getElementById(id2).value.length){
      document.getElementById(id3).focus()
    }
  }
}

//=========修改工艺资料========
const gdgydialogFormVisible = ref(false)
const _capacityListsbbh = ref(null)
const gdgyformData = reactive({})
const gdzl_MachineList_address = reactive({
  data: []
});
const _cjmc = ref(null);
// //双击修改
// const gdgyupdateCompanyFunc = async(row) => {
//   gdgydialogFormVisible.value = true

//   Object.assign(gdgyformData,row);
  
// const apiData = await getDepartName()
//   function transformDataToTreeFormat(data) {
//     return Object.entries(data).map(([key, value]) => {
//       // key是车间名称，value是车间内的操作列表
//       const children = Object.entries(value).map(([workshop, operations]) => ({
//         label: workshop,
//         children: operations.map(operation => ({
//           label: operation,
//           value: operation // 可以根据需要添加更多属性
//         }))
//       }));
//       return { label: key, children };
//     });
//   }
//   // 使用ref来管理转换后的数据
//   cjList.value = ref(transformDataToTreeFormat(apiData.data));
//   const res = await PrintDetailList({workOrder: _Gd_gdbh.value})
//   yjList.value = res.data
  
//   if(row['车间名称']){
//     _cjmc.value = row['车间名称']
//   }else{
//     _cjmc.value = '';
//   }
//   gdgyformData['设备编号'] = []
//   //通过车间名称查询机台
//   const MachineList_jitai = await gdzl_MachineList({address:_cjmc.value});
//   if(MachineList_jitai.data === null || MachineList_jitai.data === ''){
//     ElMessage({type: 'warning', message: '未找到该车间机台'})
//     return false;
//   }
//   const jitai = row['机台编号'].split(' ')
//   jitai.map(item => {
//     MachineList_jitai.data.map(jt => {
//       if (jt.indexOf(item) > -1 && item !== '') {
//         gdgyformData['设备编号'].push(item)
//       }
//     })
//   })
//   gdzl_MachineList_address.data = MachineList_jitai.data;
//   // 示例字符串
//   const processName = row['工序名称'];
//   // 初始化工艺名称和工序名称
//   let technologyName = '';
//   let operationName = '';
//   // 检查字符串中是否包含【】
//   const bracketIndex = processName.indexOf('【');
//   if (bracketIndex !== -1) {
//     // 如果包含【】，则分割字符串
//     technologyName = processName.substring(0, bracketIndex).trim();
//     operationName = processName.substring(bracketIndex + 1, processName.indexOf('】')).trim();
//   } else {
//     // 如果没有【】，则整个字符串是工艺名称，工序名称为空
//     technologyName = processName.trim();
//   }

//   // 示例字符串
//   const printProcess = row['印件-工序'];
//   // 初始化印件和工序
//   let yinjian = '';
//   let gongxu = '';
//   // 检查字符串中是否包含 "-"
//   const dashIndex = printProcess.indexOf('-');
//   if (dashIndex !== -1) {
//     // 如果包含 "-"，则分割字符串
//     yinjian = printProcess.substring(0, dashIndex).trim();
//     gongxu = printProcess.substring(dashIndex + 1).trim();
//   } else {
//     // 如果没有 "-"，则整个字符串是印件，工序为空
//     yinjian = printProcess.trim();
//   }
  
//   gdgyformData['印件'] = yinjian;
//   gdgyformData['工序'] = gongxu;
//   gdgyformData['工艺名称'] = technologyName;
//   gdgyformData['工序名称'] = operationName;
//   if(row.备选工序==1){
// 	  gdgyformData.备选工序 = true
//   }
// }

//工艺列表修改【确定】
const gdgyenterDialog = async () => {
	
  if(_Gd_gdbh.value){
    const selectedValuesAsString = gdgyformData['设备编号'].join(' ');
    // if(gdgyformData['shdh'] === ''){
    //   ElMessage({type: 'warning', message: '工序损耗不能为空'})
    //   return false;
    // }
    // if(gdgyformData['小时产能'] === '' || gdgyformData['小时产能'] === "0"){
    //   ElMessage({type: 'warning', message: '排产小时产能 不能为空或0'})
    //   return false;
    // }
    // if(gdgyformData['设备编号'] === '' || gdgyformData['设备编号'] === "0"){
    //   ElMessage({type: 'warning', message: '设备编号 不能为空'})
    //   return false;
    // }
	let sbbh = gdgyformData['设备编号'].join(' ');
    const formattedData = {
      UniqId: gdgyformData['UniqId'],
	  
	  Gy0_gdbh: _Gd_gdbh.value,
	  Gy0_方案: 'A',
	  Gy0_yjno: gdgyformData['印件'] ? gdgyformData['印件'] : "",
	  Gy0_gxh: gdgyformData['工序'] ? gdgyformData['工序'] : "",
	  Gy0_gxmc:gdgyformData['工艺名称'] ? gdgyformData['工艺名称'] : "",
	  Add_gxmc:gdgyformData['工序名称'] ? gdgyformData['工序名称'] : "",
	  备选工序: gdgyformData['备选工序'] ? "1" : "0",
	  重点工序: gdgyformData['重点工序'] ? gdgyformData['重点工序'] : "",
	  Gy0_sbbh: sbbh ? sbbh : "",
	  Gy0_sbmc: "",
	  Gy0_SITE: gdgyformData['车间名称'] ? gdgyformData['车间名称'] : "",
	  Gy0_ks: gdgyformData['开数'] ? gdgyformData['开数'] : "",
	  Gy0_ls: gdgyformData['联数'] ? gdgyformData['联数'] : "",
	  Gy0_ms: gdgyformData['计损色数'] ? gdgyformData['计损色数'] : 0,
	  Sys_id  : _username.value,
	  工价系数: gdgyformData['难度系数'] ? gdgyformData['难度系数'] : 0,
	  损耗系数: gdgyformData['损耗系数'] ? gdgyformData['损耗系数'] : 0,
	  Gy0_shdh: gdgyformData['shdh'] ? gdgyformData['shdh'] : "",
	  Gy0_Rate1: "",
	  Gy0_小时产能: gdgyformData['小时产能'] ? gdgyformData['小时产能'] : "",
	  Gy0_辅助工时: gdgyformData['辅助工时'] ? gdgyformData['辅助工时'] : "",
	  工序备注: gdgyformData['备注'] ? gdgyformData['备注'] : "",
	  质量要求: gdgyformData['质量要求'] ? gdgyformData['质量要求'] : "",
	  质量隐患: gdgyformData['质量隐患'] ? gdgyformData['质量隐患'] : "",
    };
    const ProcessDetailEdit_edit = await ProcessDetailEdit(formattedData);
    if (ProcessDetailEdit_edit.code === 0) {
      ElMessage({type: 'success',message: '更新成功' })
	  gdgydialogFormVisible.value = false
	  let row = {
		 '工单编号':_Gd_gdbh.value,
		 '产品代号':_Gd_cpdh.value,
		 '产品名称':_Gd_cpmc.value,
	  }
	  tableRowClick (row)
    } else {
      ElMessage({type: 'error', message: '更新失败'})
    }
  }else{
    ElMessage({type: 'error', message: '更新失败'})
  }
  gdgyformData['设备编号'] = [];
}

//工艺列表修改【关闭弹窗】
const gdgycloseDialog = () => {
  gdgyformData['设备编号'] = [];
  gdgydialogFormVisible.value = false
}

//点击设备编号
const sbbhclick = () => {
  _capacityList();
}

const _capacityList = async () => {
  if(gdgyformData['设备编号'] === ''){
    return false;
  }else{
    _capacityListsbbh.value = gdgyformData['设备编号'].join(' ');
    const editProductedit_machine = await capacityList({machine:_capacityListsbbh.value});
    gdgyformData['小时产能'] = editProductedit_machine.data;
  }

};
//截取印件前两位
const clickybupdate2 = (row,column,event) => {
  currentGy0_yjno.value = row['印件-工序'].substr(0, 2)
}

const yjdisplay = ref(false)
const yjList = ref()
const shxsdisplay = ref(false)
const cjList = ref([])
const cjdisplay = ref(false)
//修改工艺资料弹窗 键盘 input框跳转
const gyzlent = (event,id1,id2,id3) => {
	if (id2==='印件编号' && event.key==='Tab' || id2 === '印件编号' && event.key=== 'Enter') {
	  console.log(id.value)
	  console.log(form['yjno'])
	  const response = getCouplet({ gdbh:id.value,yjno:form['yjno']});
	  console.log(response)
	  gdgyformData['开数'] = response.data['开数']
	  gdgyformData['联数'] = response.data['联数']
	  if(yjList.value !== undefined){
	    const node = yjList.value.find(item => item.no ===gdgyformData['yjno'])
	    if (! node) {
	      yjdisplay.value = true
	    }
	    document.getElementById(id3).focus()
	  }
	}
	if (id2 === '车间名称' && event.key==='Tab') {
	  document.getElementById(id3).focus()
	  cjdisplay.value = true
	}
	if (id2 === '工序损耗' &&  event.key==='Tab') {
	  if(gdgyformData['车间名称']){
	     getGxshList();
	    _getSH()
	    shxsdisplay.value = true
	  }
	}
	if (id2 === '工序名称' &&  event.key==='Tab' || event.key==='Enter') {
	  if(gdgyformData['工艺名称'] === undefined){
	    gdgyformData['工艺名称'] = '';
	  }
	  if(gdgyformData['工序名称'] === undefined){
	    gdgyformData['工序名称'] = '';
	  }
	  gdgyformData['工序损耗名称'] = `${gdgyformData['工艺名称']} ${gdgyformData['工序名称']}`;
	}
  if (event.keyCode === 13 || event.keyCode === 40) { // Enter 或向下箭头
    if(id3!=''){
      document.getElementById(id3).focus()
    }
  } else if (event.keyCode === 38) { // 向上箭头
    if(id1!=''){
      document.getElementById(id1).focus()
    }
  }else if (event.keyCode === 8) { // 删除箭头
    if(id1!='' && document.getElementById(id2).value==''){
      document.getElementById(id1).focus()
    }
    // console.log(document.getElementById(id2).value)
  }else if (event.keyCode === 37) { // 向左箭头
    if(id1!='' && document.getElementById(id2).selectionStart==0){
      document.getElementById(id1).focus()
    }
  }else if (event.keyCode === 39) { // 向右箭头
    if(id3!='' && document.getElementById(id2).selectionStart == document.getElementById(id2).value.length){
      document.getElementById(id3).focus()
    }
  }
}

const selectHandle = async (node)=>{
  console.log(node)
  if(node.value){
    gdgyformData['工艺名称'] = node.value
    gdgyformData['工序损耗名称'] = node.value
    cjdisplay.value = false
  }else{
    gdgyformData['车间名称'] = node.label
    return false;
  }
  gdgyformData['设备编号'] = []
console.log(gdgyformData['车间名称'])
  //通过车间名称查询机台
  const MachineList_jitai = await gdzl_MachineList({address:gdgyformData['车间名称']});
  gdzl_MachineList_address.value = MachineList_jitai.data;
  gdgyformData['shdh'] = ''
  //通过车间名称查询工序损耗
  // await getGxshList()
  if(gdgyformData['工艺名称'] === undefined){
    gdgyformData['工艺名称'] = '';
  }
  if(gdgyformData['工序名称'] === undefined){
    gdgyformData['工序名称'] = '';
  }
  await InSH()
}
const InSH = async (value) => {
  if(gdgyformData['工艺名称']){
    const response = await getLossCode({ code:gdgyformData['工艺名称']});
    console.log(response)
    if(response.code===0){
      gdgyformData['shdh']=response.data[0].sys_bh
      // gdgyformData.工序损耗名称= node.sys_mc
      gdgyformData['工序损耗名称'] = `${response.data[0].sys_mc} ${gdgyformData['工序名称']}`;
      gdgyformData.损耗系数='1.00'
      gdgyformData.难度系数='1.00'
    }
  }

}

const getSHListdata = ref([]);
const _shdh = ref('');

//工序损耗列表
const gxshList = ref([])
const getGxshList = async ()=>{
  const WastageList_data = await WastageList({process: gdgyformData.工艺名称})
  console.log(WastageList_data)
  if(WastageList_data.data === null || WastageList_data.data === ''){
    gdgyformData['shdh'] = '';
    ElMessage({
      type: 'warning',
      message: '未获取到工序损耗'
    })
  }
  // const response = await getLossCode({ code: WastageList_data.data });
  // console.log(response)
  gdgyformData['shdh'] = WastageList_data.data
}
//点击工序损耗列表数据
const gxshselectHandle = async (node)=>{
  if(node.label2){
    gdgyformData['shdh'] = node.value
    gdgyformData['工序损耗名称'] = node.label2
    gxshdisplay.value = false
  }
}

//填充树形结构
const _getSH = async () => {
  const response = await getLossCode({ code:'' });
  if (response.code === 0) {
    const data = response.data;
    const treeData = [];
    const map = {};
    // 构建树形结构
    data.forEach(item => {
      map[item.sys_bh] = { ...item, children: [], label: `${item.sys_bh}---${item.sys_mc}---${item.sys_rate0}---${item.sys_rate1}` };
    });
    data.forEach(item => {
      if (item.sys_bh.length === 3) {
        map[item.sys_bh].level = 1;
        treeData.push(map[item.sys_bh]);
      } else {
        map[item.sys_bh].level = 2;
        map[item.sys_bh.substring(0, 3)].children.push(map[item.sys_bh]);
      }
    });
    getSHListdata.value = treeData;
    shxsdisplay.value = true;
  } else {
    // 处理错误情况
    console.error('获取损耗列表失败');
  }
};

//损耗树形结构点击
const selectSHNode = (node,check) => {
  console.log(node.level)
  if(node.level==1){
    console.log(node.label)
  }
  if(node.level==2){
    if(gdgyformData['工艺名称'] === undefined){
      gdgyformData['工艺名称'] = '';
    }
    if(gdgyformData['工序名称'] === undefined){
      gdgyformData['工序名称'] = '';
    }

    gdgyformData['shdh']=node.sys_bh
    // gdgyformData.工序损耗名称= node.sys_mc
    gdgyformData['工序损耗名称'] = `${node.sys_mc} ${gdgyformData['工序名称']}`;
    gdgyformData.损耗系数='1.00'
    gdgyformData.难度系数='1.00'
    shxsdisplay.value = false;
  }
}

const changeHandle = (v) => {
  const no = '0' + v.no
  let list = gxList.value.map(item => {
    const yj = item.split('-')[0]
    if (yj === no) return Number(item.split('-')[1])
  })
  gdgyformData['yjno'] = v.no
  gdgyformData['工序'] = (list.sort((a, b) => b-a)[0] + 1)
  yjdisplay.value = false
}

//===============颜色==================================
//工艺资料背景颜色变黄
const currentGy0_yjno = ref(null)
const rowClassStyle2 = ({row,rowIndex}) =>{
  if(row['印件-工序'].substr(0, 2)==currentGy0_yjno.value){
    return "warning-row"
  }
  return "warning-row"
}
//表格文字颜色
const tableDataCellClass = ({row, column, rowIndex, columnIndex}) =>{
  if (column.property === '订单数量') {
    return 'plan-usage-low';
  }
}
//工艺流程调整颜色
const gylctzCellClass = ({row, column, rowIndex, columnIndex}) =>{
  if (column.label === '工序号') {
    return 'background-plan-usage-low';
  }
}
//修正核算参数颜色
const sxzhscsCellClass = ({row, column, rowIndex, columnIndex}) =>{
  if (column.label === '新难度系数' || column.label === '新损耗代号' || column.label === '新印刷方式' || column.label === '新来版距' || column.label === '新计损色数'  || column.label === '新损耗系数') {
    return 'background-plan-usage-low';
  }
}
//质检废品系数颜色
const scfjfpxsCellClass = ({row, column, rowIndex, columnIndex}) =>{
  if (column.label === '人工正品板' || column.label === '人工次品板' || column.label === '人工废检' || column.label === '机检正品板' || column.label === '机检次品板'  || column.label === '机检废检') {
    return 'background-plan-usage-low';
  }
}
//根据工艺状态文字颜色
const gysatusCellClass = ({row, column, rowIndex, columnIndex}) =>{
  if(row['status'] === '未完工'){
    return 'status-plan-usage-low';
  }
  if(row['status'] === '已完工'){
    return 'statusy-plan-usage-low';
  }
}
//bom颜色
const planUsageCellClass = ({row, column, rowIndex, columnIndex}) =>{
  if (column.property === '计划用量') {
    return 'plan-usage-low';
  }
}

//修改工单资料弹窗 键盘 input框跳转
const gdzlent =async (event,id1,id2,id3) => {
  if (id2 === '客户代号' && event.key==='Tab') {
    await _gClientList(scgdformData.value['客户代号'])
    if (khdhDataList.value != null) {
      const row = khdhDataList.value.find(item => item.客户编号 === scgdformData.value['客户代号'])
      if (row) {
        scgdformData.value['客户名称'] = row.客户名称
      } else {
        khdhModal.value = true
      }
    } else {
      khdhModal.value= true
    }
  }
  if (id2 === '产品代号' && event.key==='Tab') {
    await _ProductCodeList()
    cpdhModal.value = true
  }
  if (event.keyCode === 13 || event.keyCode === 40) { // Enter 或向下箭头
    if(id3!=''){
      document.getElementById(id3).focus()
    }
  } else if (event.keyCode === 38) { // 向上箭头
    if(id1!=''){
      document.getElementById(id1).focus()
    }
  }else if (event.keyCode === 8) { // 删除箭头
    if(id1!='' && document.getElementById(id2).value==''){
      document.getElementById(id1).focus()
    }
    // console.log(document.getElementById(id2).value)
  }else if (event.keyCode === 37) { // 向左箭头
    if(id1!='' && document.getElementById(id2).selectionStart==0){
      document.getElementById(id1).focus()
    }
  }else if (event.keyCode === 39) { // 向右箭头
    if(id3!='' && document.getElementById(id2).selectionStart == document.getElementById(id2).value.length){
      document.getElementById(id3).focus()
    }
  }
}

const gdSelection = ref('')
const yjSelection = ref('')
const gySelection = ref('')
// 印件资料多选、工艺资料多选
const selectionChange = (selection, type) => {
  const ids = selection.map(item => {
    return type === '印件资料' ? item.Uniqid: item.UniqId
  })
  if (type === '印件资料') {
    yjSelection.value = ids.join(',')
  }
  if (type === '工艺资料') {
    gySelection.value = ids.join(',')
  }
}
const handleSelectionChange = (selection, type) => {
  const ids = selection.map(item => {
    return item.Uniqid
  })
  console.log(ids.join(','))
  gdSelection.value = ids.join(',')
}

// ===========删除工单资料 ===========
const delgdzl_onclick = async () => {
  console.log(gdSelection.value)
  if (gdSelection.value !== '') {
    try {
      const res1 = await WorkOrderDel({UniqId: gdSelection.value})
      if(res1.code === 0){
        ElMessage.success('印件资料删除成功')

        console.log(_Gd_khdh.value)
        const WorkListdata = await WorkList({Gd_khdh:_Gd_khdh.value,limit:pageSize.value,page:page.value});
        console.log(WorkListdata)
        tableData.splice(0,tableData.length,...WorkListdata.data.data);//表格数据
        total.value =WorkListdata.data.total;//共多少条
        yjtableData.value = [];
        gytableData.value = [];
        bomtableData.value = [];
      }

    } catch(err) {
      ElMessage.error(err)
    }
  }
}


// ===========删除印件资料、工艺资料 ===========
const delgd_delclick = async () => {
  if (yjSelection.value !== '') {
    try {
      const res1 = await PrintDetailDel({UniqId: yjSelection.value})
      res1.code === 0 && ElMessage.success('印件资料删除成功')
    } catch(err) {
      ElMessage.error(err)
    }
  }
  if (gySelection.value !== ''){
    try {
      const res2 = await ProcessDetailDel({UniqId: gySelection.value})
      res2.code === 0 && ElMessage.success('工艺资料删除成功')
    } catch(err) {
      ElMessage.error(err)
    }
  }

  const workOrderListDetail_data = await workOrderListDetail({Gd_gdbh:_Gd_gdbh.value});
  yjtableData.value = workOrderListDetail_data.data.printList;
  gytableData.value = workOrderListDetail_data.data.processList;
  bomtableData.value = workOrderListDetail_data.data.BOM;
}

//点击技术附件按钮
const jsfjClick = () => {
	if(_Gd_gdbh.value == null){
	  cgugdlist.value = false;
	  ElMessage({type: 'warning',message: '请选择具体的工单后，再操作此功能'})
	}else{
	  initJsfjformdata();
	  jsfjformdata.value.关联编号 = _Gd_gdbh.value
	  jsfjdialogFormVisible.value = true
	}
}
//技术附件弹窗
const jsfjdialogFormVisible = ref(false)
const jsfjformdata = ref({
	sys_id: _username.value,
	附件备注: '',
	附件内容: '',
	附件类型: '',
	关联编号: '',
});
//技术附件弹窗取消
const initJsfjformdata = () => {
  jsfjformdata.value = {
	sys_id: _username.value,
	附件备注: '',
	附件内容: '',
	附件类型: '',
	关联编号: '',
  }
}
//技术附件弹窗取消
const jsfjcloseDialog = () => {
  jsfjdialogFormVisible.value = false
}
const uploadExcel = (event) =>{
	const files = event.target.files;
	let suffixArr = name.split("."), suffix = suffixArr[suffixArr.length-1];
	// if(suffix!="xlsx"){
	// 	alert("Currently only supports the import of xlsx files");
	// 	return;
	// }
	jsfjformdata.value.附件内容 = files[0]
	jsfjformdata.value.附件类型 = 'XLSX'
}

const yulan = (event) =>{
	if(!jsfjformdata.value.附件内容) return
	$.getScript('/luckysheet/plugins/js/plugin.js', () => {
			$script('/luckysheet/luckysheet.umd.js', () => {
			luckyexcelVisible.value = true
			LuckyExcel.transformExcelToLucky(jsfjformdata.value.附件内容, function(exportJson, luckysheetfile){
				if(exportJson.sheets==null || exportJson.sheets.length==0){
					alert("Failed to read the content of the excel file, currently does not support xls files!");
					return;
				}
				if(luckyExcel) luckyExcel.destroy();
				luckysheet.create({
					container: 'luckyexcel', //容器的ID
					data: exportJson.sheets,
					title: exportJson.info.name, // 工作簿名称
					lang: "zh", // 设定表格语言 国际化设置，允许设置表格的语言，支持中文("zh")和英文("en")
					showtoolbar: false, // 是否显示工具栏
					showinfobar: false, // 是否显示顶部信息栏
					allowEdit: false, // 是否允许前台编辑
					enableAddRow: false, // 允许增加行
					enableAddCol: false, // 允许增加列
					userInfo: false, // 右上角的用户信息展示样式
					showRowBar: false, // 是否显示行号区域
					showColumnBar: false, // 是否显示列号区域
					sheetFormulaBar: false, // 是否显示公式栏
					enableAddBackTop: false,//返回头部按钮
				});
				luckyExcel = luckysheet;
			})
		})
		})
		$('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', '/luckysheet/plugins/css/pluginsCss.css'));
		$('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', '/luckysheet/plugins/plugins.css'));
		$('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', '/luckysheet/css/luckysheet.css'));
		$('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', '/luckysheet/assets/iconfont/iconfont.css'));

}
const jsfj_del = (row) =>{
	ElMessageBox.confirm('确定要删除吗?', '提示', {
	    confirmButtonText: '确定',
	    cancelButtonText: '取消',
	    type: 'warning'
	}).then(() => {
		gdAnnexDel({'UniqId':row.UniqId,'gdbh':_Gd_gdbh.value}).then(response => {
			 if(response.code==0){
				 ElMessage({
				   type: 'success',
				   message: '删除成功',
				 })

				 let row = {
					 '工单编号':_Gd_gdbh.value,
					 '产品代号':_Gd_cpdh.value,
					 '产品名称':_Gd_cpmc.value,
				 }
				 tableRowClick (row)
			  }
		   })
	})

}

//技术附件弹窗确定
const jsfjenterDialog = () => {
	if(jsfjformdata.value.附件备注==''){
		ElMessage({
			type: 'error',
			message: '请填写附件备注'
		});
		return;
	}
	if(jsfjformdata.value.附件内容==''){
		ElMessage({
			type: 'error',
			message: '请上传文件'
		});
		return;
	}
	if(jsfjformdata.value.关联编号==''){
		ElMessage({
			type: 'error',
			message: '请填写关联编号'
		});
		return;
	}

	let fr = new FileReader();
	fr.readAsDataURL(jsfjformdata.value.附件内容);
	fr.onload = function () {
	  const restoredData = new FormData();
	  restoredData.append('sys_id', jsfjformdata.value.sys_id);
	  restoredData.append('附件备注', jsfjformdata.value.附件备注);
	  restoredData.append('附件内容', fr.result);
	  restoredData.append('附件类型', jsfjformdata.value.附件类型);
	  restoredData.append('关联编号', jsfjformdata.value.关联编号);

	   gdAnnexAdd(restoredData).then(response => {
		 if(response.code==0){
			 ElMessage({
			   type: 'success',
			   message: '新增成功',
			 })
			 jsfjdialogFormVisible.value = false
			 let row = {
				 '工单编号':_Gd_gdbh.value,
				 '产品代号':_Gd_cpdh.value,
				 '产品名称':_Gd_cpmc.value,
			 }
			 tableRowClick (row)
		 }
	   })
	}
}

//技术资料excel展示
const ExcelShow = (row) =>{
	if(!row.附件内容) return
	$.getScript('/luckysheet/plugins/js/plugin.js', () => {
		$script('/luckysheet/luckysheet.umd.js', () => {
					function dataURLtoBlob(dataUrl) {
					    const byteString = atob(dataUrl.split(',')[1]);
					    const ab = new ArrayBuffer(byteString.length);
					    const ia = new Uint8Array(ab);

					    for (let i = 0; i < byteString.length; i++) {
					        ia[i] = byteString.charCodeAt(i);
					    }

					    return new Blob([ab], { type: 'application/octet-stream' });
					}

					const blob = dataURLtoBlob(row.附件内容);
					luckyexcelVisible.value = true
					LuckyExcel.transformExcelToLucky(blob, function(exportJson, luckysheetfile){
						if(exportJson.sheets==null || exportJson.sheets.length==0){
							alert("Failed to read the content of the excel file, currently does not support xls files!");
							return;
						}
						if(luckyExcel) luckyExcel.destroy();
						luckysheet.create({
							container: 'luckyexcel', //容器的ID
							data: exportJson.sheets,
							title: exportJson.info.name, // 工作簿名称
							lang: "zh", // 设定表格语言 国际化设置，允许设置表格的语言，支持中文("zh")和英文("en")
							showtoolbar: false, // 是否显示工具栏
							showinfobar: false, // 是否显示顶部信息栏
							allowEdit: false, // 是否允许前台编辑
							enableAddRow: false, // 允许增加行
							enableAddCol: false, // 允许增加列
							userInfo: false, // 右上角的用户信息展示样式
							showRowBar: false, // 是否显示行号区域
							showColumnBar: false, // 是否显示列号区域
							sheetFormulaBar: false, // 是否显示公式栏
							enableAddBackTop: false,//返回头部按钮
						});
						luckyExcel = luckysheet;
					})
		})
	})
	$('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', '/luckysheet/plugins/css/pluginsCss.css'));
	$('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', '/luckysheet/plugins/plugins.css'));
	$('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', '/luckysheet/css/luckysheet.css'));
	$('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', '/luckysheet/assets/iconfont/iconfont.css'));

}

let luckyExcel = null

const luckyexcelVisible = ref(false)
const luckyexcelCloseDialog = () => {
  luckyexcelVisible.value = false
}
</script>
<style scoped>
/* 在样式表中使用媒体查询 */
@media (max-width: 768px) {
  /* 在小屏幕下的样式设置 */
  .dialog-footer {
    text-align: center;
  }
}
/*工序产量核查*/
:deep(.gxclhc—color-column-red div) {
  color: red !important;
}
:deep(.lan-plan-usage-lows div) {
  color: blue !important;
  font-weight: bold;
}
:deep(.lan-plan-usage-lowshui div) {
  color: #8c939d !important;
}

/*背景颜色*/
/*印件背景颜色变黄*/
:deep(.el-table__body .warning-row) {
  background: #FFFF80 !important;
}
/*修正工单核算参数背景*/
:deep(.el-table__body .background-plan-usage-low div div div) {
  background: #80FA80 !important;
}
/* 选中某行时的背景色 */
:deep(.el-table__body tr.current-row) > td {
  background: #ff80ff !important;
}
/*文字颜色*/
/*bom计划用量文字变色【表格中单独文字变色】*/
:deep(.plan-usage-low div) {
  color: red !important;
}
/*根据工艺状态文字变色*/
:deep(.status-plan-usage-low div) {
  color: blue !important;
}
:deep(.statusy-plan-usage-low div) {
  color: #8c939d !important;
}
/* 在样式表中添加以下样式 */
.el-input__textarea {
  resize: none; /* 禁止调整大小 */
}
.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-textarea textarea {
  resize: none !important;
}

</style>
<style scoped>
:deep(.el-table td .cell) {
  line-height: 20px !important;
}
:deep(.el-tabs__header){
  margin-bottom: 0;
}
.search{
  margin-left: 0px !important;
  margin-right: 10px !important;
}
.bt{
  margin-left: 2px !important;
  padding: 3px !important;
  font-size: 12px;
}
.el-tabs__header{
  margin: 0px !important;
}
.gva-table-box{
  padding: 0px !important;
}
.el-pagination{
  margin-top: 0px !important;
}
.mab{
  margin-bottom: 5px;
}
</style>
