<template>
  <div>
    <layout>
      <layout-header>
        <div class="">
          <!--          按钮部分-->
          <el-form ref="elSearchFormRef"  :model="searchInfo" class="demo-form-inline" :rules="searchRule" @keyup.enter="onSubmit">
            <el-form-item>
              <!--按钮 clearable-->
              <el-input v-model="searchInfo" placeholder="搜索工单编号"  style="width: 180px;"></el-input>
              <el-button type="primary" icon="search"  @click="onSubmit"></el-button>
              <el-button type="primary" icon="edit" @click="onStatusClick" class="bt">工单状态设置</el-button>

              <div v-if="treeType === 'customTree'">
                <el-button type="primary" icon="edit" @click="ongxztgzClick" class="bt">工序状态更正</el-button>
                <el-button type="primary" icon="edit" disabled @click="pd_yysjcsonClick" class="bt">引用实际参数</el-button>
                <el-button type="primary" icon="edit" disabled @click="pd_pccswhonClick" class="bt">排程参数维护</el-button>
                <el-button type="primary" icon="edit" disabled @click="pd_pdcsfzonClick" class="bt">排单参数复制</el-button>
                <el-button type="primary" icon="edit" disabled @click="pd_editscjhonClick" class="bt">编辑生产计划</el-button>
              </div>

              <div v-else>
                <el-button type="primary" icon="edit"  @click="onjrpcClick" class="bt">加入排产</el-button>
                <el-button type="primary" icon="edit"  @click="onztwgClick" class="bt">暂停排产</el-button>
                <el-button type="primary" icon="edit"  @click="ongxwgClick" class="bt">工序完工</el-button>
                <el-button type="primary" icon="edit" @click="ongxztgzClick" class="bt">工序状态更正</el-button>
                <el-button type="primary" icon="edit" disabled @click="onjztzClick" style="margin: 5px">机组调整</el-button>
                <el-button type="primary" icon="edit"  @click="oncjsbpcClick" style="margin: 5px">车间设备排程</el-button>
              </div>

              <el-button type="primary" icon="edit" disabled @click="pd_gdprintonClick" class="bt">工单打印</el-button>
              <el-button type="primary" icon="edit" disabled @click="pd_gxclhconClick" class="bt">工序产量核查</el-button>
              <el-button type="primary" icon="edit" disabled @click="pd_lcdlistonClick" class="bt">流程单查询</el-button>

            </el-form-item>
          </el-form>

          <!-- 状态设置【弹窗】-->
          <el-dialog v-model="onstatuslist" title="工单状态设置" width="30%" style="top: 15%">
            <div style="width: 100%;height: 100%;">
              <div style="width: 100%; display: flex; align-items: center;">
                <el-form-item label="工单编号 :" prop="currentProcess">
                  <el-input v-model="statusformData['gdbh']" placeholder="" />
                </el-form-item>
              </div>
              <div style="width: 100%; display: flex; align-items: center; margin-top: 30px;">
                <span>状态设置：</span>
                <el-radio-group v-model="status" style="margin-left: 10px;">
                  <el-radio label="计划中">计划中</el-radio>
                  <el-radio label="生产中">生产中</el-radio>
                  <el-radio label="已完工">已完工</el-radio>
                </el-radio-group>
              </div>
              <div class="dialog-footer" style="text-align: right; margin-top: 40px;">
                <el-button @click="handleCancel">取消</el-button>
                <el-button type="primary"  @click="handleConfirm">确认</el-button>
              </div>
            </div>
          </el-dialog>
          <!-- 工序状态更正【弹窗】-->
          <el-dialog v-model="gxztgzzlist" title="工序状态更正" style="width: 100%;height: 100%;margin: 0px;padding: 0px">
            <el-button type="" @click="gxztgzzCancel">退出</el-button>
            <div style="width: 100%; height: 60px; padding: 0px; margin: 10px 0px 0px 0px; display: flex; align-items: center;">
              <el-form-item label="工单编号 :" prop="currentProcess" style="margin-right: 20px; padding: 0px">
                <el-input v-model="gxztgzzformData['gdbh']" @keyup.enter="gxztgzzgetProductValue" placeholder="" style="width: 200px;"/>
              </el-form-item>
            </div>
            <el-table ref="paichengRef"
                      :show-overflow-tooltip="true"
                      :row-style="{ height: '0px' }"
                      :cell-style="{ padding: '0px' }" :header-row-style="{ height: '0px' }"
                      :header-cell-style="{ padding: '0px' }"
                      style="width: 100%;height: 74vh" border tooltip-effect="dark"
                      :data="gxztgzztableData" row-key="ID"
                      :cell-class-name="gxztgzzCellClass">
              <template v-for="(item, idx) in gxztgzztableColumns">
                <el-table-column #default="{ row, column, $index }" align="left" :label="item.label" :width="item.width" >
<!--                  <div v-if="['完工时间'].includes(item.prop)">-->
<!--                    <el-input v-model="row[item.prop]"-->
<!--                              :id="`input${idx}${$index}`" @keyup="gxztgzz_handleKeyDown($event, idx, $index, item.prop)"/>-->
<!--                  </div>-->
                  <div v-if="['完工时间'].includes(item.prop)">
                    <el-date-picker
                        v-model="row[item.prop]"
                        type="datetime"

                        :id="`datepicker${idx}${$index}`"
                        placeholder="选择日期和时间">
                    </el-date-picker>
                  </div>
                  <div v-else>{{ row[item.prop] }}</div>
                </el-table-column>
              </template>
            </el-table>
          </el-dialog>

          <!--加入排产【弹窗】-->
          <!--暂停完工【弹窗】-->
          <!--暂停完工【弹窗】-->
          <!--机组调整【弹窗】-->
          <!--车间设备排程【弹窗】-->
          <el-dialog v-model="cjsbpclist" title="车间设备排程" style="width: 100%;height: 100%;margin: 0px;padding: 0px">
            <el-button type="" @click="cjsbpcCancel">退出</el-button>
            <div style="width: 100%; height: 60px; padding: 0px; margin: 10px 0px 0px 0px; ">
              <div style="width: 100%; height: 60px; padding: 0px;  display: flex; align-items: center;">
                <el-form-item label="设备代号 :" prop="currentProcess" style="margin-right: 20px; padding: 0px">
                  <el-input v-model="cjsbpcformData['sbdh']" disabled placeholder="" />
                </el-form-item>
                <el-form-item label="班次选择:" prop="originalName" style="margin-left: 20px;">
                  <el-select v-model="cjsbpcformData.banci" placeholder="请选择" allow-create filterable @change="setBanci">
                    <el-option
                        v-for="(option, index) in cjsbpcformData.bancis"
                        :key="index"
                        :label="option.value"
                        :value="option.value"
                    >
                      {{option.label}}
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="" prop="isBanciSelected" style="margin-left: 20px;">
                  <el-checkbox v-model="cjsbpcformData.isBanciSelected">所有班次</el-checkbox>
                </el-form-item>

                <el-form-item label="" prop="" style="margin-left: 25px;">
<!--                <el-button type="" icon="edit"  @click="oneditpcClick">更新排程</el-button>-->
                <el-button type="" icon="edit" disabled @click="oneditpcClick">更新排程</el-button>
                </el-form-item>
              </div>

              <el-table ref="paichengRef"
                :show-overflow-tooltip="true"
                :row-style="{ height: '0px' }"
                :cell-style="{ padding: '0px' }" :header-row-style="{ height: '0px' }"
                :header-cell-style="{ padding: '0px' }"
                style="width: 100%;height: 74vh" border tooltip-effect="dark"
                highlight-current-row="true"
                @row-click="cjpc_tableRowClick"
                :data="paichengData" row-key="ID"
              >
                <template v-for="(item, idx) in paichengColumns">
                  <el-table-column #default="{ row, column, $index }" align="left" :label="item.label" :width="item.width" >
                    <div v-if="['优先次序', '生产工时', '辅助工时', '班次安排', '排单备注','最早开工时间', '计划开工时间'].includes(item.prop)">
                      <el-input v-model="row[item.prop]" :clearable="false"
                        :id="`input${idx}${$index}`"
                        @keyup="handleKeyDown($event, idx, $index, item.prop)"
                      />
<!--                      <el-date-picker v-model="row[item.prop]" v-if="['最早开工时间', '计划开工时间'].includes(item.prop)" type="datetime" :clearable="false"-->
<!--                        :id="`input${idx}${$index}`"-->
<!--                        @keyup="handleKeyDown($event, idx, $index , item.prop)"-->
<!--                      />-->
                    </div>
                    <div v-else>
                      {{ row[item.prop] }}
                    </div>
                  </el-table-column>
                </template>
              </el-table>
            </div>

          </el-dialog>
          <!--工单打印【弹窗】-->
          <!--工序产量核查【弹窗】-->
          <el-dialog v-model="gxclhclist" title="工序产量核查" style="width: 100%;height: 100%;margin: 0px;padding: 0px">
            <el-button type="" @click="gxclhcCancel">退出</el-button>

            <div style="width: 100%; height: 60px; padding: 0px; margin: 10px 0px 0px 0px; display: flex; align-items: center;">
              <div style="width: 100%; height: 60px; padding: 0px;  display: flex; align-items: center;">
                <el-form-item label="工单编号" prop="currentProcess" style="margin-right: 20px; padding: 0px">
                  <el-input v-model="gxclhcformData['gdbh']"  @keyup.enter="gxclhcProductValue" placeholder="" />
                </el-form-item>
                <el-form-item label="" prop="currentProcess" style="margin-right: 20px; padding: 0px">
                  <el-input v-model="gxclhcformData['gdmc']" disabled placeholder="" style="width: 340px;"/>
                </el-form-item>
              </div>
            </div>
          </el-dialog>


        </div>
      </layout-header>

      <layout>
        <layout-sider :resize-directions="['right']" :width="190" style="margin-right: 10px;">
          <div class="JKWTree-tree" style="height: 200px">
            <el-tree :data="treeData" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
          </div>
        </layout-sider>
        <layout-content>
          <el-main>

            <div class="gva-table-box"  v-if="treeType === 'customTree'">
              <el-table ref="multipleTable" style="width: 100%;height: 25vh"
                        :row-style="{ height: '20px' }" :cell-style="{ padding: '0px' }" :header-row-style="{ height: '20px' }"
                        :header-cell-style="{ padding: '0px' }" border
                        tooltip-effect="dark" :data="tableData" row-key="ID"
                        :highlight-current-row="true" size="small" @row-click="gdtableRowClick"
                        @selection-change="handleSelectionChange" :show-overflow-tooltip="true">
                <template v-for="item in tableFields[currentNode]">
                  <el-table-column :align="item.align" :label="item.title" :prop="item.prop" :width="item.width" />
                </template>
              </el-table>
            </div>

            <el-tabs v-model="activeName" @tab-click="handleClick" v-if="(currentNode == '计划中' || currentNode == '已完工') &&  treeType === 'customTree'">
              <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: 50vh" border tooltip-effect="dark" :data="gytableData" row-key="ID" @selection-change="handleSelectionChange">
                  <el-table-column align="left" label="工单编号" prop="工单编号"  width="90"/>
                  <el-table-column align="left" label="重点工序" prop="重点工序"  width="90"/>
                  <el-table-column align="left" label="印件工序及名称" prop="印件工序及名称"  width="500"/>
                  <el-table-column align="left" label="工序备注" prop="工序备注"  width="150"/>
                  <el-table-column align="left" label="机组" prop="机组"  width="80"/>
                  <el-table-column align="left" label="小时产能" prop="小时产能"  width="90"/>
                  <el-table-column align="left" label="生产工时" prop="生产工时"  width="90"/>
                  <el-table-column align="left" label="辅助工时" prop="辅助工时"  width="90"/>
                  <el-table-column align="left" label="印刷方式" prop="印刷方式"  width="90"/>
                  <el-table-column align="left" label="版距" prop="版距"  width="70"/>
                  <el-table-column align="left" label="创建用户" prop="创建用户"  width="100"/>
                  <el-table-column align="left" label="创建时间" prop="创建时间"  width="110"/>
                  <el-table-column align="left" label="修改时间" prop="修改时间"  width="110"/>
                  <el-table-column align="left" label="UNIQID" prop="UNIQID"  width="90"/>
                </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: 50vh" border tooltip-effect="dark" :data="yjtableData" row-key="ID" @selection-change="handleSelectionChange">
                  <el-table-column align="left" label="工单编号" prop="工单编号"  width="90"/>
                  <el-table-column align="left" label="印件号" prop="印件号"  width="70"/>
                  <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="230"/>
                  <el-table-column align="left" label="投料规格" prop="投料规格"  width="100"/>
                  <el-table-column align="left" label="成品数量" prop="成品数量"  width="90"/>
                  <el-table-column align="left" label="实际投料" prop="实际投料"  width="90"/>
                  <el-table-column align="left" label="投料单位" prop="投料单位"  width="85"/>
                  <el-table-column align="left" label="平张投料" prop="平张投料"  width="90"/>
                  <el-table-column align="left" label="联数" prop="联数"  width="70"/>
                  <el-table-column align="left" label="开数" prop="开数"  width="70"/>
                  <el-table-column align="left" label="创建用户" prop="创建用户"  width="110"/>
                  <el-table-column align="left" label="创建时间" prop="创建时间"  width="110"/>
                  <el-table-column align="left" label="修改时间" prop="修改时间"  width="110"/>
                  <el-table-column align="left" label="UNIQID" prop="UNIQID"  width="90"/>
                </el-table>
              </el-tab-pane>
            </el-tabs>

            <div v-if="treeType === 'customTree'">
              <el-table ref="multipleTable2"
                        v-if="['排程中', '制程中'].includes(currentNode)"
                        :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: 50vh" border tooltip-effect="dark" :data="bottomData" row-key="ID" @selection-change="handleSelectionChange">
                <template v-for="item in bottomTableF[currentNode]">
                  <el-table-column :align="item.align" :label="item.title" :prop="item.prop" :width="item.width" />
                </template>
              </el-table>
            </div>

            <div v-if="treeType === 'dataTree'">
              <el-table ref="chejianRef"
                        :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"  @row-click="chejianRowClick"
                        style="width: 100%;height: 25vh" border tooltip-effect="dark" :data="chejianData" row-key="ID" @selection-change="PC_handleChange">
                <el-table-column type="selection" width="30" />
                <template v-for="item in [
                  { align:'left', title: '工单编号', prop: '工单编号', width: 85  },
                  { align:'left', title: '销售订单号', prop: '销售订单号', width: 200  },
                  { align:'left', title: '印件名称', prop: '印件名称', width: 320  },
                  { align:'left', title: '印件工序及名称', prop: '印件工序及名称', width: 200  },
                  { align:'left', title: '工序产量', prop: '工序产量', width: 90  },
                  { align:'left', title: '已完成产量', prop: '已完成产量', width: 100  },
                  { align:'left', title: '产品名称', prop: '产品名称', width: 320  },
                  { align:'left', title: '订单数量', prop: '订单数量', width: 120  },
                  { align:'left', title: '计量单位', prop: '计量单位', width: 120  },
                  { align:'left', title: '交货日期', prop: '交货日期', width: 115  },
                  { align:'left', title: '产品代号', prop: '产品代号', width: 140  },
                  { align:'left', title: '工序名称', prop: '工序名称', width: 120  },
                  { align:'left', title: '机组', prop: '机组', width: 90  },
                  { align:'left', title: '设备编号', prop: '设备编号', width: 90  },
                  { align:'left', title: 'UNIQID', prop: 'UNIQID', width: 90  },
                  { align:'left', title: '印件号', prop: '印件号', width: 90  },
                  { align:'left', title: '工序号', prop: '工序号', width: 90  },
              ]">
                  <el-table-column :align="item.align" :label="item.title" :prop="item.prop" :width="item.width" />
                </template>
              </el-table>
              <el-table ref="chejianfuRef"
                        :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"  @row-click="chejianfuRowClick"
                        style="width: 100%;height: 50vh;margin-top: 10px" border tooltip-effect="dark" :data="chejianfuData" row-key="ID" @selection-change="ZP_handleChange">
                <el-table-column type="selection" width="30" />
                <template v-for="item in [
                  { align:'left', title: '工单编号', prop: '工单编号', width: 85  },
                  { align:'left', title: '销售订单号', prop: '销售订单号', width: 200  },
                  { align:'left', title: '印件名称', prop: '印件名称', width: 320  },
                  { align:'left', title: '印件工序及名称', prop: '印件工序及名称', width: 200  },
                  { align:'left', title: '工序产量', prop: '工序产量', width: 90  },
                  { align:'left', title: '已完成产量', prop: '已完成产量', width: 100  },
                  { align:'left', title: '小时产能', prop: '小时产能', width: 90  },
                  { align:'left', title: '产能系数', prop: '产能系数', width: 90  },
                  { align:'left', title: '生产工时', prop: '生产工时', width: 90  },
                  { align:'left', title: '辅助工时', prop: '辅助工时', width: 90  },
                  { align:'left', title: '最早开工时间', prop: '最早开工时间', width: 160  },
                  { align:'left', title: '计划开工时间', prop: '计划开工时间', width: 160  },
                  { align:'left', title: '计划完工时间', prop: '计划完工时间', width: 160  },
                  { align:'left', title: '班次安排', prop: '班次安排', width: 90  },
                  { align:'left', title: '排单备注', prop: '排单备注', width: 120  },
                  { align:'left', title: '产品名称', prop: '产品名称', width: 180  },
                  { align:'left', title: '订单数量', prop: '订单数量', width: 120  },
                  { align:'left', title: '计量单位', prop: '计量单位', width: 120  },
                  { align:'left', title: '交货日期', prop: '交货日期', width: 115  },
                  { align:'left', title: '优先次序', prop: '优先次序', width: 90  },
                  { align:'left', title: '产品代号', prop: '产品代号', width: 100  },
                  { align:'left', title: '工序名称', prop: '工序名称', width: 120  },
                  { align:'left', title: '设备编号', prop: '设备编号', width: 90  },
                  { align:'left', title: '车间名称', prop: '车间名称', width: 90  },
                  { align:'left', title: 'GYUID', prop: 'GYUID', width: 90  },
                  { align:'left', title: '印件号', prop: '印件号', width: 90  },
                  { align:'left', title: '工序号', prop: '工序号', width: 90  },
              ]">
                  <el-table-column :align="item.align" :label="item.title" :prop="item.prop" :width="item.width" />
                </template>
              </el-table>
            </div>
          </el-main>
        </layout-content>

      </layout>
    </layout>
  </div>
</template>
<script>
//点击按钮显示下方表格
export default {
  data() {
    return {
      currentTable: '',
      activeName: 'first',
      // 其他表格数据...
    };
  },
  methods: {
    showTable(tableName) {
      // console.log("点击了".tableName)
      // 根据点击的按钮设置当前展示的表格
      this.currentTable = tableName;
    },
    showTableChange() {
      // 处理表格选中事件
    },
    // 其他方法...
  }
};
</script>

<script setup>
// 全量引入格式化工具 请按需保留
import { Layout, LayoutSider, LayoutContent } from '@arco-design/web-vue';
import {createCompany, deleteCompany, deleteCompanyByIds, updateCompany, findCompany, getCompanyList} from '@/api/company'
import { getDictFunc, formatDate, formatBoolean, filterDict, ReturnArrImg, onDownloadFile } from '@/utils/format'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ref, reactive } from 'vue'
import {
  DataList, getProduct, getProductData,scheduleProcess,ProductionSchedulingAdd,
  Project, StatusEdit, EquipmentScheduling, ScheduleSelection,MachineWorkOrderList,
  projectCraft, ProcessStatusCorrection,ProductionSchedulingPause,
  projectPrint, setProductStatus, workbench, ProcessFlow, Schedule,complete
} from "@/api/yunyin/yunying";
defineOptions({name: 'Company'})

const chejianData = ref([])
const chejianfuData = ref([])

// =========== 左侧树侧形结构 ===========
const sctreeData = ref([
  {
    label: '排产进程及参数设置',
    children:[
      {label: '1.计划中工单', number: "计划中", type: '__customer'},
      {label: '2.排程中工单', number: "排程中",type: '__customer'},
      {label: '3.制程中工单', number: "制程中", type: '__customer'},
      {label: '4.已完工工单', number: "已完工", type: '__customer'}
    ],
  }
]);
//上方表格
const tableFields = ref(
{
  "计划中": [
      { title:'获取状态', prop: 'statusColumn', width: 80, align:'center'},
      { title:'生产分类', prop: '生产分类', width: 80, align:'left', },
      { title: '工单编号', prop: '工单编号', width: 80, align:'center', },
      { title: '产品代号', prop: '产品代号', width: 90, align:'center', },
      { title: '产品名称', prop: '产品名称', width: 280, align:'left', },
      { title: '接单日期', prop: '接单日期', width: 110, align:'left', },
      { title: '交货日期', prop: '交货日期', width: 110, align:'left', },
      { title: '订单数量', prop: '订单数量', width: 80, align:'left', },
      { title: '计量单位', prop: '计量单位', width: 80, align:'center', },
      { title: '客户名称', prop: '客户名称', width: 200, align:'left', },
      { title: '客户编号', prop: '客户编号', width: 80, align:'center', },
      { title: '备注', prop: '备注', width: 230, align:'left', },
      { title: '客户料号', prop: '客户料号', width: 120, align:'left', },
      { title: '创建用户', prop: '创建用户', width: 110, align:'left', },
      { title: '创建时间', prop: '创建时间', width: 110, align:'left', },
      { title: '修改时间', prop: '修改时间', width: 110, align:'left', },
      { title: 'UNIQID', prop: 'UNIQID', width: 80  , align:'left', },
      { title: '投料率', prop: '投料率', width: 100, align:'left', },
      { title: '销售订单号', prop: '销售订单号', width: 120, align:'left', },
      ],
  "排程中": [
      // { title: '最早开工时间', prop: '最早开工时间', width: 120, align:'left', },
      { title: '工单编号', prop: '工单编号', width: 80, align:'left', },
      { title: '产品代号', prop: '产品代号', width: 90, align:'left', },
      { title: '产品名称', prop: '产品名称', width: 340, align:'left', },
      { title: '接单日期', prop: '接单日期', width: 110, align:'left', },
      { title: '交货日期', prop: '交货日期', width: 110, align:'left', },
      { title: '订单数量', prop: '订单数量', width: 80, align:'left', },
      { title: '计量单位', prop: '计量单位', width: 80, align:'left', },
      { title: '销售订单号', prop: '销售订单号', width: 200, align:'left', },
      // { title: '排程类型', prop: '排程类型', width: 120, align:'left', },
      { title: '客户编号', prop: '客户编号', width: 120, align:'left', },
      { title: '客户名称', prop: '客户名称', width: 230, align:'left', },
      { title: '创建用户', prop: '创建用户', width: 120, align:'left', },
      // { title: 'GDUID', prop: 'GDUID', width: 120, align:'left', },
      { title: 'GYUID', prop: 'GYUID', width: 100, align:'left', },
      ],
  "制程中": [
        // { title: '最早开工时间', prop: '最早开工时间', width: 120, align:'left', },
        { title: '工单编号', prop: '工单编号', width: 80, align:'left', },
        { title: '产品代号', prop: '产品代号', width: 90, align:'left', },
        { title: '产品名称', prop: '产品名称', width: 340, align:'left', },
        { title: '接单日期', prop: '接单日期', width: 110, align:'left', },
        { title: '交货日期', prop: '交货日期', width: 110, align:'left', },
        { title: '订单数量', prop: '订单数量', width: 80, align:'left', },
        { title: '计量单位', prop: '计量单位', width: 80, align:'left', },
        { title: '销售订单号', prop: '销售订单号', width: 200, align:'left', },
        // { title: '排程类型', prop: '排程类型', width: 120, align:'left', },
        { title: '客户编号', prop: '客户编号', width: 120, align:'left', },
        { title: '客户名称', prop: '客户名称', width: 120, align:'left', },
        { title: '客户料号', prop: '客户料号', width: 160, align:'left', },
        // { title: 'GDUID', prop: 'GDUID', width: 120, align:'left', },
        { title: 'GYUID', prop: 'GYUID', width: 100, align:'left', },
      ],
  "已完工": [
        { title: '工单编号', prop: '工单编号', width: 80, align:'left', },
        { title: '产品代号', prop: '产品代号', width: 110, align:'left', },
        { title: '产品名称', prop: '产品名称', width: 340, align:'left', },
        { title: '接单日期', prop: '接单日期', width: 110, align:'left', },
        { title: '交货日期', prop: '交货日期', width: 110, align:'left', },
        { title: '订单数量', prop: '订单数量', width: 80, align:'left', },
        { title: '计量单位', prop: '计量单位', width: 80, align:'left', },
        { title: '销售订单号', prop: '销售订单号', width: 120, align:'left', },
        { title: '客户编号', prop: '客户编号', width: 80, align:'left', },
        { title: '客户名称', prop: '客户名称', width: 120, align:'left', },
        { title: '客户料号', prop: '客户料号', width: 120, align:'left', },
        // { title: '排程类型', prop: '排程类型', width: 120, align:'left', },
        { title: 'GDUID', prop: 'GDUID', width: 80, align:'left', },
      ]
    }
)
//下方表格
const bottomTableF = ref({
  "排程中": [
    { title:'工单编号', prop: '工单编号', width: 90, align:'left', },
    { title:'印件工序及名称', prop: '印件工序及名称', width: 160, align:'left', },
    { title:'机组', prop: '机组', width: 120, align:'left', },
    { title:'设备编号', prop: '设备编号', width: 120, align:'left', },
    { title:'工序产量', prop: '工序产量', width: 120, align:'left', },
    { title:'已完成产量', prop: '已完成产量', width: 120, align:'left', },
    { title:'剩余产量', prop: '剩余产量', width: 120, align:'left', },
    { title:'小时产能', prop: '小时产能', width: 120, align:'left', },
    { title:'产能系数', prop: '产能系数', width: 120, align:'left', },
    { title:'生产工时', prop: '生产工时', width: 120, align:'left', },
    { title:'辅助工时', prop: '辅助工时', width: 120, align:'left', },
    { title:'最早开工时间', prop: '最早开工时间', width: 120, align:'left', },
    { title:'计划开工时间', prop: '计划开工时间', width: 120, align:'left', },
    { title:'计划完工时间', prop: '计划完工时间', width: 120, align:'left', },
    { title:'班次安排', prop: '班次安排', width: 120, align:'left', },
    { title:'设备名称', prop: '设备名称', width: 120, align:'left', },
    { title:'排单备注', prop: '排单备注', width: 120, align:'left', },
    { title:'工序完工', prop: '工序完工', width: 120, align:'left', },
    { title:'UNIQID', prop: 'UNIQID', width: 120, align:'left', },
  ],
  "制程中": [
    { title:'工单编号', prop: '工单编号', width: 90, align:'left', },
    { title:'印件工序及名称', prop: '印件工序及名称', width: 160, align:'left', },
    { title:'机组', prop: '机组', width: 120, align:'left', },
    { title:'设备编号', prop: '设备编号', width: 120, align:'left', },
    { title:'工序产量', prop: '工序产量', width: 120, align:'left', },
    { title:'已完成产量', prop: '已完成产量', width: 120, align:'left', },
    { title:'剩余产量', prop: '剩余产量', width: 120, align:'left', },
    { title:'小时产能', prop: '小时产能', width: 120, align:'left', },
    { title:'产能系数', prop: '产能系数', width: 120, align:'left', },
    { title:'生产工时', prop: '生产工时', width: 120, align:'left', },
    { title:'辅助工时', prop: '辅助工时', width: 120, align:'left', },
    { title:'最早开工时间', prop: '最早开工时间', width: 120, align:'left', },
    { title:'计划开工时间', prop: '计划开工时间', width: 120, align:'left', },
    { title:'计划完工时间', prop: '计划完工时间', width: 120, align:'left', },
    { title:'班次安排', prop: '班次安排', width: 120, align:'left', },
    { title:'设备名称', prop: '设备名称', width: 120, align:'left', },
    { title:'排单备注', prop: '排单备注', width: 120, align:'left', },
    { title:'工序完工', prop: '工序完工', width: 120, align:'left', },
    { title:'UNIQID', prop: 'UNIQID', width: 120, align:'left', },
      ],
})
//左侧左边栏
const treeData = ref([]);
//默认显示计划中表格
const currentNode = ref("计划中")
//计划中、已完工下方印件资料
const yjtableData = ref([])
//计划中、已完工下方工艺资料
const gytableData = ref([])
//排程中、制程中下方表格
const bottomData = ref([])
//工单侧边栏 设备定额及分配参数设置
const schandleNodeClick = async (node) => {
  currentNode.value = node.number
  bottomData.value = []
  yjtableData.value = []
  gytableData.value = []
  switch (node.number) {
    case "计划中":
      console.log(currentNode.value)
      const jhz_Projectdata = await Project({status:currentNode.value});
      console.log(jhz_Projectdata)
      for (let i = 0; i < jhz_Projectdata.data.length; i++) {
        const item = jhz_Projectdata.data[i];
        if (item.status === 0) {
          item.statusColumn = "*";
        }
        // 如果 status 为 1，可以在相应列中添加其他内容
        else if (item.status === 1) {
          item.statusColumn = "";
        }
      }
      tableData.value = jhz_Projectdata.data;
      break;
    case "排程中":
      console.log(currentNode.value)
      //  /Manufacture/Schedule
      const pc_Schedule = await Schedule({status:currentNode.value,search:''});
      console.log(pc_Schedule)
      tableData.value = pc_Schedule.data;
      break;
    case "制程中":
      console.log(currentNode.value)
      const zc_Schedule = await Schedule({status:currentNode.value,search:''});
      console.log(zc_Schedule)
      tableData.value = zc_Schedule.data;
      break;
    case "已完工":
      console.log(currentNode.value)
      const ywg_Project = await Project({status:currentNode.value});
      for (let i = 0; i < ywg_Project.data.length; i++) {
        const item = ywg_Project.data[i];
        // 如果 status 为 0，在某一列（比如 statusColumn）中添加 "*"
        if (item.status === 0) {
          item.statusColumn = "*";
        }
        else if (item.status === 1) {
          item.statusColumn = "";
        }
      }
      tableData.value = ywg_Project.data;
      break;
  }
};

//车间侧边栏 进入页面自动加载【车间】数据
const workbenchdata = async () => {
  try {
    const data = await workbench();
    const rawData = data.data;
    const dataArray =Object.keys(rawData).map(key => ({
      label: key,
      children: Object.keys(rawData[key]).map(subKey => ({
        label: subKey,
        children: rawData[key][subKey].map(item => ({
          label: item
        }))
      }))
    }));
    treeData.value = dataArray;
    treeData.value.unshift(sctreeData.value[0])
  } catch (error) {
    console.error(error);
  }
};
workbenchdata();
//全局获取工单编号
const _Gd_gdbh = ref(null)
//点击表格 通过上方表格【工单编号】获取下方表格数据
const chejianRowClick = async (row) => {
  _Gd_gdbh.value = row.工单编号;
  console.log(_Gd_gdbh.value);
}
const gdtableRowClick = async (row) => {
  _Gd_gdbh.value = row.工单编号;
  console.log(_Gd_gdbh.value);
  if (currentNode.value == "计划中") {
    if(row['statusColumn'] === "*"){
      gytableData.value = [];
      yjtableData.value = [];
      return false;
    }else{
      //计划中工单->工艺资料接口
      const gyres = await projectCraft({Gd_gdbh: _Gd_gdbh.value});
      //工艺资料表格
      gytableData.value.splice(0, gytableData.value.length, ...gyres.data);
      //计划中工单->印件资料接口
      const yjres = await projectPrint({Gd_gdbh: _Gd_gdbh.value});
      //印件资料表格
      yjtableData.value.splice(0, yjtableData.value.length, ...(yjres?.data ?? []));
    }
  }

  if (currentNode.value == "排程中") {
    const pc_scheduleProcess = await scheduleProcess({Gd_gdbh: _Gd_gdbh.value});
    bottomData.value = pc_scheduleProcess.data;
  }

  if (currentNode.value == "制程中") {
    const zc_scheduleProcess = await scheduleProcess({Gd_gdbh: _Gd_gdbh.value});
    bottomData.value = zc_scheduleProcess.data;
  }

  if (currentNode.value == "已完工") {
    //工艺资料
    const ywg_gyres = await projectCraft({Gd_gdbh: _Gd_gdbh.value});
    gytableData.value.splice(0, gytableData.value.length, ...ywg_gyres.data);

    //印件资料
    const ywg_yjres = await projectPrint({Gd_gdbh: _Gd_gdbh.value});
    yjtableData.value.splice(0, yjtableData.value.length, ...ywg_yjres.data);
  }
};

//点击左侧树形获取表格列表//机台侧边栏
const tableData = ref([]);
const _machine = ref(null);
const treeType = ref('customTree') // dataTree // 计划中，排产中 ,dataTree 车间
const handleNodeClick = async (node) => {
  if (node.type && node.type === '__customer') {
    treeType.value = 'customTree'
    schandleNodeClick(node)
  } else if (!node.children) {
    treeType.value = 'dataTree'
    const custom_code = node.label;
    // 使用字符串分割获取#前面的数据
    const dataBeforeHash = custom_code.split('#')[0].trim();
    _machine.value = dataBeforeHash + '#';
    console.log(_machine.value)
    const zhubiao = await MachineWorkOrderList({ machine:_machine.value})
    chejianData.value = zhubiao.data['排程'];
    chejianfuData.value = zhubiao.data['制程'];
  }
};
//计划中已完工搜索
const searchInfo = ref('');
// 提交搜索
const onSubmit = () => {
  if (!searchInfo.value || !_machine.value) {
    ElMessage({ type: 'warning', message: '请输入工单编号和具体条件' });
    return false;
  }
  const isPureNumber = /^\d+$/.test(searchInfo.value);
  if (!isPureNumber) {
    ElMessage({ type: 'warning', message: '请输入正确的工单编号' });
    return false;
  }
  if (currentNode.value === '计划中' || currentNode.value === '已完工') {
    _Project();
  } else if (currentNode.value === '排程中' || currentNode.value === '制程中') {
    _Schedule();
  } else {
    ElMessage({ type: 'warning', message: '查询不到具体条件的工单' });
  }
};
// const onSubmit = () => {
//   const isPureNumber = /^[\d]+$/.test(searchInfo.value);
//   if (isPureNumber) {
//     if(_machine.value){
//       _MachineWorkOrderList();
//     }else if(_machine.value === '' || _machine.value === null){
//       ElMessage({type: 'warning',message: '查询不到具体条件的工单'})
//       return false;
//     }else{
//       {
//         if(searchInfo.value === '' || searchInfo.value === null ){
//           ElMessage({type: 'warning',message: '查询不到具体条件的工单'})
//           return false;
//         }
//         if(currentNode.value === '计划中' || currentNode.value === '已完工'){
//           _Project();
//           return false;
//         }
//         if(currentNode.value === '排程中' || currentNode.value === '制程中'){
//           _Schedule();
//           return false;
//         }
//       }
//     }
//   } else {
//     ElMessage({type: 'warning',message: '请输入正确的工单编号'})
//   }
// };
// 搜索计划中、已完工一条工单
const _Project = async () => {
  const status = currentNode.value;
  const search = searchInfo.value;
  const Project_search = await Project({status:status,search:search});
  if(Project_search.msg === '成功'){
    tableData.value = Project_search.data;
  }else{
    ElMessage({type: 'warning',message: '查不到具体条件的工单'})
    return false;
  }
};
// 搜索排程、制程一条工单
const _Schedule = async () => {
  const status = currentNode.value;
  const search = searchInfo.value;
  const Schedule_search = await Schedule({status:status,search:search});
  if(Schedule_search.msg === '成功'){
    chejianData.value = Schedule_search.data;
  }else{
    ElMessage({type: 'warning',message: '查不到具体条件的工单'})
    return false;
  }
};
//机台搜索一条工单
const _MachineWorkOrderList = async () => {
  let params = {}
  params.search = searchInfo.value;
  params.machine = _machine.value;
  const MachineWorkOrderList_search = await MachineWorkOrderList(params);
  if(MachineWorkOrderList_search.msg === ''){
    ElMessage({type: 'warning',message: '查不到具体条件的工单'})
    return false;
  }else{
    chejianfuData.value = MachineWorkOrderList_search.data['制程'];
    chejianData.value = MachineWorkOrderList_search.data['排程'];
  }
};

// =========== 【工序状态更正】 ===========
const gxztgzztableColumns = ref(
    [
      { label: '印件及工序', prop: '印件及工序', width: '600' },
      { label: '计划产量/已完成', prop:['计划产量/已完成'], width: '500' },
      { label: '完成率', prop: '完成率', width: '240' },
      { label: '完工时间', prop: '完工时间', width: '300' },
      { label: '设备代号', prop: '设备代号', width: '240' },
    ]
)
const gxztgzz_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 < gxztgzztableData.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 gxztgzztableData = ref([]);
const gxztgzzlist = ref(false);
const gxztgzzformData = reactive({gdbh: '',});
//工序状态更正【按钮】
const ongxztgzClick = () => {
  if(_Gd_gdbh.value == null){
    gxztgzzlist.value = false;
    ElMessage({type: 'warning',message: '请选择树形后，再操作此功能'})
  }else{
    gxztgzzformData['gdbh'] = _Gd_gdbh.value;
    _ProcessStatusCorrection();
    gxztgzzlist.value = true;
  }
};
//工序状态更正【回车】
const gxztgzzgetProductValue = () => {
  _ProcessStatusCorrection();
};
//工序状态更正
const _ProcessStatusCorrection = async (row) => {
  const workOrder = gxztgzzformData['gdbh'];
  console.log(workOrder)
  const ProcessStatusCorrectiondata = await ProcessStatusCorrection({workOrder:workOrder});
  gxztgzztableData.value = ProcessStatusCorrectiondata.data;
};
//工序状态更正【退出】
const gxztgzzCancel = () => {
  gxztgzzlist.value = false;
};

//加入排产【按钮】
const onjrpcClick = async () => {
  searchInfo.value = '';
  if(_PC_gdbh.value == null || _PC_gdbh.value == ''){
    ElMessage({type: 'warning',message: '请选择排程中工单'})
  }else{
    console.log(_PC_xscn.value)
    if (_PC_xscn.value === '' || _PC_xscn.value === null || _PC_xscn.value === '0') {
      ElMessage({type: 'warning',message: '选择中小时产量为 0'})
      return false;
    }else{
      let params = {}
      params.workOrder = _PC_gdbh.value;
      params.machine = _machine.value;
      params.printCode = _PC_yjno.value;
      params.processCode =  _PC_gxh.value;
      console.log(params)
      const ProductionSchedulingAdd_add = await ProductionSchedulingAdd(params);
      if (ProductionSchedulingAdd_add.code === 0) {
        const  pc_zc_table = await MachineWorkOrderList({machine:_machine.value});
        chejianData.value = pc_zc_table.data['排程'];
        chejianfuData.value = pc_zc_table.data['制程'];
        ElMessage({type: 'success',message: '加入排产 更新成功'});
      } else {
        ElMessage({ type: 'error',message: '更新失败'})
      }
    }

  }
};
//暂停排产【按钮】
const onztwgClick = async () => {
  searchInfo.value = '';
  if(_ZC_gdbh.value == null || _ZC_gdbh.value == ''){
    ElMessage({type: 'warning', message: '请选择制程中工单'})
  }else{
      let params = {}
      params.workOrder = _ZC_gdbh.value;
      params.machine = _machine.value;
      params.printCode = _ZC_yjno.value;
      params.processCode =  _ZC_gxh.value;
      console.log(params)
      const ProductionSchedulingAdd_stop = await ProductionSchedulingPause(params);
      if (ProductionSchedulingAdd_stop.code === 0) {
        const pc_zc_table = await MachineWorkOrderList({machine:_machine.value});
        console.log(pc_zc_table)
        chejianData.value = pc_zc_table.data['排程'];
        chejianfuData.value = pc_zc_table.data['制程'];
        ElMessage({type: 'success',message: '暂停排产 更新成功'});
      } else {
        ElMessage({ type: 'error',message: '更新失败'})
      }
  }
};

//工序完工【按钮】
const ongxwgClick = async () => {
  searchInfo.value = '';
  if(_ZC_gdbh.value == null || _ZC_gdbh.value == ''){
    onstatuslist.value = false;
    ElMessage({
      type: 'warning',
      message: '请选择制程中工单'
    })
  }else{
    let params = {}
    params.workOrder = _ZC_gdbh.value;
    params.processCode = _ZC_gxh.value;
    const complete_get = await complete(params);
    if (complete_get.code === 0) {
      const  pc_zc_table = await MachineWorkOrderList({ machine:_machine.value});
      // chejianData.value = pc_zc_table.data['排程'];
      chejianfuData.value = pc_zc_table.data['制程'];
      ElMessage({type: 'success',message: '工序完工 更新成功'})
    } else {
      ElMessage({ type: 'error',message: '更新失败'})
    }
  }
};
//加入排程【上面到下面】
const _PC_gxh = ref(null)
const _PC_yjno = ref(null)
const _PC_gdbh = ref(null)
const _PC_xscn = ref(null)
const PC_handleChange = (arr) => {
  let gxh = arr.map((val) => val['gxh']).join(",");
  let yjno = arr.map((val) => val['yjno']).join(",");
  let str = arr.map((val) => val['工单编号']).join(",");
  let xscn = arr.map((val) => val['小时产能']).join(",");
  _PC_gxh.value = gxh;
  _PC_yjno.value = yjno;
  _PC_gdbh.value = str;
  _PC_xscn.value = xscn;
}
//加入制程【下面到上面】
const _ZC_gxh = ref(null)
const _ZC_yjno = ref(null)
const _ZC_gdbh = ref(null)
const _ZC_xscn = ref(null)
const ZP_handleChange = (arr) => {
  console.log(arr)
  let gxh = arr.map((val) => val['gxh']).join(",");
  let yjno = arr.map((val) => val['yjno']).join(",");
  let str = arr.map((val) => val['工单编号']).join(",");
  let xscn = arr.map((val) => val['小时产能']).join(",");
  _ZC_gxh.value = gxh;
  _ZC_yjno.value = yjno;
  _ZC_gdbh.value = str;
  _ZC_xscn.value = xscn;
}

//机组调整【按钮】
const onjztzClick = async () => {

};
//工序产量核查【按钮】
const onprintClick = async () => {

};

//=========工序产量核查===========
const gxclhclist = ref(false);
const gxclhcformData = reactive({
  gdbh: '',
  gdmc: '',
});

//工序产量核查【按钮】
const ongxclhcClick = async () => {
  gxclhclist.value = true;
};

//工序产量核查【回车】
const _gxclhcgdbh = ref(null)
const gxclhcProductValue = () => {
  if(fjformData['dqprocessName'] === ''){
    fjformData['dqprocessName'] = '';
  }
  _gxclhcgdbh.value = gxclhcformData['gdbh'];
  _ongetProductclick();
}

const paichengColumns = ref(
    [
      { label: '优先次序', prop: '优先次序', width: '120' },
      { label: '工单编号', prop: '工单编号', width: '200' },
      { label: '印件名称', prop: '印件名称', width: '220' },
      { label: '接货数', prop: '接货数', width: '110' },
      { label: '小时产能', prop: '小时产能', width: '110' },
      { label: '生产工时', prop: '生产工时', width: '110' },
      { label: '辅助工时', prop: '辅助工时', width: '110' },
      { label: '班次安排', prop: '班次安排', width: '110' },
      { label: '排单备注', prop: '排单备注', width: '110' },
      { label: '最早开工时间', prop: '最早开工时间', width: '200' },
      { label: '计划开工时间', prop: '计划开工时间', width: '200' },
      { label: '计划完工时间', prop: '计划完工时间', width: '200' },
      { label: '销售订单号', prop: '销售订单号', width: '120' },
      { label: '印件/工序', prop: '印件/工序', width: '120' },
    ]
)

const handleKeyDown = (event, x, y, prop) => {
  const currentElement = document.getElementById(`input${x}${y}`);
  if (currentElement === null && currentElement === undefined) return
  let move = 0
  switch (event.keyCode) {
    case 13: // Enter
    case 40: // 向下箭头
        if (y < paichengData.value.length ){
          document.getElementById(`input${x}${y + 1}`).focus();
        }
      break;
    case 38: // 向上箭头
      if ( y > 0) {
        document.getElementById(`input${x}${y - 1}`).focus();
      }
      break;
    case 39: // 向左箭头
      if ( x === 0) {
        move = x + 5
      } else if (x >= 5 && x <10) {
        move = x + 1
      }
      document.getElementById(`input${move}${y}`).focus();
      break;
    case 37: // 向右箭头
      if ( x === 5) {
        move = x -  5
      } else if (x >= 5 && x <=10) {
        move = x - 1
      }
      document.getElementById(`input${move}${y}`).focus();
      break;
    default:
      break;
  }
}


//工序产量核查【退出】
const gxclhcCancel = async () => {
  gxclhclist.value = false;
};



//流程单查询【按钮】
const onlcdlistClick = async () => {

};


//状态设置【按钮】
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 = "1-计划中";
  } else if (status.value === '生产中') {
    statusCode = "2-生产中";
  }else if (status.value === '已完工') {
    statusCode = "3-已完工";
  }
  const StatusEditdata = await StatusEdit({workOrder:workOrder,status:statusCode});
  if (StatusEditdata.code === 0) {
    ElMessage({
      type: 'success',
      message: '更新成功'
    })
  } else {
    ElMessage({
      type: 'error',
      message: '更新成功'
    })
  }
  onstatuslist.value = false;
};
// handleCancel(_stacode);


const page = ref(1)
const total = ref(0)
const pageSize = ref(10)
// 分页
const handleSizeChange = (val) => {
  pageSize.value = val
  getTableData()
}

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

// 查询
const getTableData = async() => {

}
getTableData()

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

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

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


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


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

//修改
const updateCompanyFunc = async (row) => {
  console.log(row);
  dialogFormVisible.value = true;
};

// 打开弹窗
const openDialog = () => {
  dialogFormVisible.value = true
}
// 弹窗确定
const enterDialog = async () => {
  console.log("弹窗确定")
}
// 关闭弹窗
const closeDialog = () => {dialogFormVisible.value = false}




//=============车间设备排程================
const cjsbpclist = ref(false);
const cjsbpcformData = reactive({
  //设备代号
  sbdh: '',
  // 下拉框选项数据
  bancis: [],
  // 设置默认值
  banci: '',
  isBanciSelected: false,
});
//车间设备排程【按钮】
const oncjsbpcClick = () => {
  cjsbpcformData['sbdh'] = _machine.value;
  _EquipmentSchedulingdata();
  _ScheduleSelectiondata();
  cjsbpclist.value = true;
};
//调用班次选择列表接口
const _ScheduleSelectiondata = async ()=>{
  try {
    const ScheduleSelectiondata = await ScheduleSelection();
    // 清空之前的数据
    cjsbpcformData.bancis = [];
    // 循环遍历数组并将每个班次的detail添加到bancis数组中
    for (const option of ScheduleSelectiondata.data) {
      cjsbpcformData.bancis.push({ label: option.detail, value: option.detail.split('||')[0], rename:option.detail});
    }
    //班次列表数据
    // console.log("赋值后的数据：", cjsbpcformData.bancis);
  } catch (error) {
    console.error(error);
  }
}
//车间设备排程->数据展示
const paichengData = ref([])
//点击车间排程行
const _bcxz_val = ref(null)

//点击表格行的时候触发的方法
const cjpc_tableRowClick = (row) => {
  _bcxz_val.value = row; // 保存点击的行数据
}
//班次选择列表下拉框
const setBanci = (v) => {
  if(cjsbpcformData['isBanciSelected'] === true){
    console.log("已选择所有班次")
    paichengData.value.map( item => item.班次安排 = v)
  }else{
    console.log("未选择所有班次")
    if (_bcxz_val.value) {
      _bcxz_val.value['班次安排'] = v;
    }
  }
}
const _EquipmentSchedulingdata = async ()=>{
  // let machine = 'WY01#';
  let machine = _machine.value;
  try {
    const EquipmentSchedulingdata = await EquipmentScheduling({machine:machine});
    if (EquipmentSchedulingdata.code === 0) {
      paichengData.value = EquipmentSchedulingdata.data
    }
  } catch (error) {
    console.error(error);
  }
}
//车间设备排程->数据编辑


//车间设备排程【更新排程】
const oneditpcClick = async () => {
  // console.log(paichengData)
  const rawValueArray = paichengData._rawValue;
  const formattedData = rawValueArray.map(item => {
    return {
      capacity: item.小时产能,
      ProductionHours: item.生产工时,
      AuxiliaryHours: item.辅助工时,
      shift: item.班次安排,
      remark: item.排单备注,
      start: item.计划开工时间,
      projectTime: item.计划完工时间,
      UniqId: item.UniqId
    };
  });
  console.log(formattedData)
  // const EquipmentSchedulingEdit_edit = await EquipmentSchedulingEdit(formattedData);
  // console.log(EquipmentSchedulingEdit_edit)
  // cjsbpclist.value = true;
};
//车间设备排程【退出】
const cjsbpcCancel = () => {
  cjsbpclist.value = false;
};


//工序状态更正颜色
const gxztgzzCellClass = ({row, column, rowIndex, columnIndex}) =>{
  if(row['完工时间'] === ''){
    return 'lan-plan-usage-low';
  }else{
    return 'hui-plan-usage-low';
  }

}

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

/*文字颜色*/
/*工序状态更正颜色【灰色】*/
:deep(.hui-plan-usage-low div) {
  color: #8c939d !important;
}
/*工序状态更正颜色【蓝色】*/
:deep(.lan-plan-usage-low div) {
  color: blue !important;
}

:deep(.el-tabs__header){
  margin-bottom: 0;
}
:deep(.el-table td .cell) {
  line-height: 30px !important;
}
.JKWTree-container {
  display: flex;
}
.JKWTree-tree {
  width: 300px;
  background-color: #fff;
  padding: 10px;
  margin-right: 20px;
}

.JKWTree-tree h3 {
  font-size: 15px;
  font-weight: 700;
  margin: 10px 0;
}
.JKWTree-content {
  flex: 1;
}
</style>
<style scoped>

: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;
}
.mab{
  margin-bottom: 5px;
}
</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;
}
.mab{
  margin-bottom: 5px;
}
.focusdiv:focus {
  border: 1px solid red;
}
</style>
