<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" title="搜索" icon="search"  @click="onSubmit"></el-button>
              <el-button type="primary" title="设置工单的状态-->【计划中】 【生产中】 【已完成】" icon="edit" @click="onStatusClick" class="bt">工单状态设置</el-button>

              <div v-if="treeType === 'customTree'">
                <el-button type="primary" title="设置工单各个工序的 【完工】 状态" icon="edit" @click="ongxztgzClick" class="bt">工序状态更正</el-button>
                <el-button type="primary" title="引用当前产品最近一次的生产参数【设备、显示产能、辅助工时】" icon="edit" @click="pd_yysjcsonClick" class="bt">引用实际参数</el-button>
                <!--                <el-button type="primary" title="批量维护工序生产的排程参数" icon="edit" disabled @click="pd_pccswhonClick" class="bt">排程参数维护</el-button>-->
                <!--                <el-button type="primary" title="将已经维护好的排产参数，复制给对应产品的对应工艺" icon="edit" disabled @click="pd_pdcsfzonClick" class="bt">排单参数复制</el-button>-->
                <!--                <el-button type="primary" title="根据当前生产任务设备状态排程 编辑生产计划" icon="edit" disabled @click="pd_editscjhonClick" class="bt">编辑生产计划</el-button>-->
              </div>

              <div v-else>
                <el-button type="primary" title="将当前已选的生产任务，【加入到设备生产任务清单中】" icon="edit"  @click="onjrpcClick" class="bt">加入排产</el-button>
                <el-button type="primary" title="暂停工序生产任务，【返回当前设备待产任务清单中】" icon="edit"  @click="onztwgClick" class="bt">暂停排产</el-button>
                <el-button type="primary" title="将工序佘总为【完工状态】" icon="edit"  @click="ongxwgClick" class="bt">工序完工</el-button>
                <el-button type="primary" title="设置工单各个工序的【完工】状态" icon="edit" @click="ongxztgzClick" class="bt">工序状态更正</el-button>
                <el-button type="primary" title="可【批量设置】所选择的生产任务的生产机台" icon="edit"  @click="onjztzClick" class="bt">机组调整</el-button>
                <el-button type="primary" title="给担负起那设备做生产任务排程" icon="edit"  @click="oncjsbpcClick" class="bt">车间设备制程排序</el-button>
              </div>

              <el-button type="primary" title="打印生产工单" icon="edit" @click="pd_gdprintonClick" class="bt">工单打印</el-button>
              <el-button type="primary" icon="edit" @click="pd_gxclhconClick" class="bt">工序产量核查</el-button>
              <el-button type="primary" icon="edit" @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="primary" @click="edit_gxztgzzCancel">更新时间</el-button>
            <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="jizuDisplay" title="机组调整" style="width: 600px;">
            <el-row class="">
              <el-col :span="18">
                <el-tree :data="jizuList"
                         :props="{label:'label', value: 'value', chidlren: 'children'}"
                         node-key="value"
                         show-checkbox
                         :default-expanded-keys="jizuList[0].value"
                         @check="checkTreeHandle"
                         style="margin-right: 10px; padding: 10px; border-1px solid #ececec"></el-tree>
              </el-col>
              <el-col :span="6">
                <div><el-button type="primary" @click="saveJizuTiaozheng">确定</el-button></div>
                <div style="margin-top: 20px"><el-button @click="()=>jizuDisplay = false">取消</el-button>                </div>
              </el-col>
            </el-row>
          </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="请选择" style="width: 230px;" 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-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"
                        :cell-class-name="cjzcCellClass"
              >
                <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="pd_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>
              </div>
            </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: 70vh" border tooltip-effect="dark"
                      highlight-current-row="true"
                      @row-click="gxclhc_tableRowClick"
                      :data="gxclhc_Data" row-key="ID"
                      :cell-class-name="gxclhcCellClass"
            >
              <template v-for="(item, idx) in gxclhc_Columns">
                <el-table-column #default="{ row, column, $index }" align="left" :label="item.label" :width="item.width" >
                  {{row[item.prop]}}
                </el-table-column>
              </template>
            </el-table>
          </el-dialog>

          <!--流程单查询【弹窗】-->
          <el-dialog v-model="pd_lcdlist" title="工单工序生产进程" style="width: 100%;height: 100%;margin: 0px;padding: 0px;">
            <div style="width: 100%;height: 100%;">
              <el-button type="" @click="pd_lcdCancel">退出</el-button>
            </div>
            <div style="width: 100%; height: 100%; display: flex; align-items: center;">
              <el-form-item label="工单编号" style="margin-right: 20px; padding: 0;">
                <el-input v-model="pd_lcdformData['gdbh']" @keyup.enter="pd_lcdProductValue"/>
              </el-form-item>
              <el-form-item label="" style="margin-right: 5px; padding: 0;">
                <el-input v-model="pd_lcdformData['code']" disabled/>
              </el-form-item>
              <el-form-item label="" style="margin-right: 5px; padding: 0;">
                <el-input v-model="pd_lcdformData['name']" disabled style="width: 500px"/>
              </el-form-item>
            </div>
            <div style="width: 100%; height: 70vh; display: flex;">
              <layout>
                <layout-sider :resize-directions="['right']" :width="240" style="margin-right: 10px;height: 70vh;">
                  <div class="JKWTree-tree">
                    <el-tree :data="pd_lcd_treeData" @node-click="pd_lcd_handleNodeClick" default-expand-all></el-tree>
                  </div>
                </layout-sider>
                <layout-main>
                  <!-- 这里放右侧的内容 -->
                  <el-space wrap>
                    <!-- 右侧内容 -->
                    <template v-for="item in processList.total_process">
                      <el-button disabled :type="! processList.process.includes(item) ? 'danger' : 'info'" plain style="width: 50px">{{ item }}</el-button>
                    </template>
                  </el-space>
                </layout-main>
              </layout>
            </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 class="gva-pagination" v-if="(currentNode == '计划中' || currentNode == '已完工') &&  treeType === 'customTree'">
                <el-pagination
                    @size-change="jhz_handleSizeChange"
                    @current-change="jhz_handleCurrentChange"
                    :current-page="jhz_page"
                    :page-sizes="[10,30,50,100]"
                    :page-size="30"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="jhz_total">
                </el-pagination>
              </div>
            </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: 42vh" 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: 42vh" 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"
                        :cell-class-name="pczc_planUsageCellClass"
                        style="width: 100%;height: 42vh" 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: 49vh;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>

    <PrintPage ref="printPageRef" />
  </div>
</template>
<script>
//点击按钮显示下方表格
export default {
  data() {
    return {
      currentTable: '',
      activeName: 'first',
      // 其他表格数据...
    };
  },
  methods: {
    showTable(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,
  ProcessStatusCorrectionEdit,
  projectPrint,
  setProductStatus,
  workbench,
  ProcessFlow,
  Schedule,
  complete,
  getOrderProcessCount,
  getOrderProcessLeft,
  getOrderProcessRight,
  gdzl_MachineList,
  EquipmentSchedulingEdit,
  MachineTeamEdit
} from "@/api/yunyin/yunying";

import PrintPage from './components/print.vue'
defineOptions({name: 'Company'})

const printPageRef = 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: 160, 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: 160, align:'left', },
    { title:'UNIQID', prop: 'UNIQID', width: 120, align:'left', },
  ],
})
//左侧左边栏
const treeData = ref([]);
//车间侧边栏 进入页面自动加载【车间】数据
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.工单编号;
}
const gdtableRowClick = async (row) => {
  _Gd_gdbh.value = row.工单编号;
  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 currentNode = ref("计划中")
//计划中、已完工下方印件资料
const yjtableData = ref([])
//计划中、已完工下方工艺资料
const gytableData = ref([])
//排程中、制程中下方表格
const bottomData = ref([])
//车间机台排程列表
const chejianData = ref([])
//车间机台制程列表
const chejianfuData = ref([])
//点击侧边栏获取参数
const _cname = ref(null)
//工单侧边栏 设备定额及分配参数设置
const schandleNodeClick = async (node) => {
  currentNode.value = node.number
  bottomData.value = []
  yjtableData.value = []
  gytableData.value = []
  console.log(node.number)
  switch (node.number) {
    case "计划中":
      const jhz_Projectdata = await Project({status:currentNode.value,search:'',page:1,limit:30});
      for (let i = 0; i < jhz_Projectdata.data.data.length; i++) {
        const item = jhz_Projectdata.data.data[i];
        if (item.status === 0) {
          //获取状态
          item.statusColumn = "*";
        }
        else if (item.status === 1) {
          item.statusColumn = "";
        }
      }
      tableData.value = jhz_Projectdata.data.data;
      //共多少条数据
      jhz_total.value = jhz_Projectdata.data.total;
      _cname.value = '计划中';
      _jhz_Projectdata_page();
      break;
    case "排程中":
      const pc_Schedule = await Schedule({status:currentNode.value,search:''});
      tableData.value = pc_Schedule.data;
      break;
    case "制程中":
      const zc_Schedule = await Schedule({status:currentNode.value,search:''});
      tableData.value = zc_Schedule.data;
      break;
    case "已完工":
      const ywg_Project = await Project({status:currentNode.value,search:'',page:1,limit:30});
      jhz_total.value = ywg_Project.data.total;//共多少条
      for (let i = 0; i < ywg_Project.data.data.length; i++) {
        const item = ywg_Project.data.data[i];
        // 如果 status 为 0，在某一列（比如 statusColumn）中添加 "*"
        if (item.status === 0) {
          item.statusColumn = "*";
        }
        else if (item.status === 1) {
          item.statusColumn = "";
        }
      }
      tableData.value = ywg_Project.data.data;
      jhz_total.value = ywg_Project.data.total;//共多少条
      _cname.value = '已完工';
      break;
  }
};
//分页
const jhz_page = ref(1)//前往多少页
const jhz_total = ref(0)//共多少条
const jhz_pageSize = ref(30)//一页多少条
const jhz_handleCurrentChange = (val) => {
  jhz_page.value = val;
  _jhz_Projectdata_page();
};
// 修改页面容量 点击多少条/页
const jhz_handleSizeChange = (val) => {
  jhz_pageSize.value = val;
  _jhz_Projectdata_page();
};
//分页查询调用接口
const _jhz_Projectdata_page = async () => {
  if( _cname.value === null ||  _cname.value === ''){
    return false;
  }
  const jhz_Projectdata = await Project({status: _cname.value,search:'',page:jhz_page.value,limit:jhz_pageSize.value});
  for (let i = 0; i < jhz_Projectdata.data.data.length; i++) {
    const item = jhz_Projectdata.data.data[i];
    if (item.status === 0) {
      //获取状态
      item.statusColumn = "*";
    }
    // 如果 status 为 1，可以在相应列中添加其他内容
    else if (item.status === 1) {
      item.statusColumn = "";
    }
  }
  tableData.value = jhz_Projectdata.data.data;
  jhz_total.value = jhz_Projectdata.data.total;//共多少条
};

//左上角搜索计划中、已完工工单编号
const searchInfo = ref('');
//搜索按钮
const onSubmit = () => {
  if (!searchInfo.value) {
    ElMessage({ type: 'warning', message: '搜索条件为空' });
    return false;
  }
  if(!_machine.value){
    if (currentNode.value === '计划中' || currentNode.value === '已完工') {
      _Project();
    } else if (currentNode.value === '排程中' || currentNode.value === '制程中') {
      _Schedule();
    } else {
      ElMessage({ type: 'warning', message: '查询不到具体条件的工单' });
    }
  }else{
    _MachineWorkOrderList();
  }
};
//搜索计划中、已完工一条工单接口
const _Project = async () => {
  const status = currentNode.value;
  const search = searchInfo.value;
  const Project_search = await Project({status:status,search:search,page:1,limit:30});
  if(Project_search.msg === '成功'){
    tableData.value = Project_search.data.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 === '成功'){
    tableData.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 onjrpcClick = async () => {
  searchInfo.value = '';
  if(_PC_gdbh.value == null || _PC_gdbh.value == ''){
    ElMessage({type: 'warning',message: '请勾选排程中工单'})
  }else{
    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;
      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;
    const ProductionSchedulingAdd_stop = await ProductionSchedulingPause(params);
    if (ProductionSchedulingAdd_stop.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 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 jitaiArr = ref([])
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;
  jitaiArr.value = arr
}
//加入制程【下面到上面】
const _ZC_gxh = ref(null)
const _ZC_yjno = ref(null)
const _ZC_gdbh = ref(null)
const _ZC_xscn = ref(null)
const ZP_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(",");
  _ZC_gxh.value = gxh;
  _ZC_yjno.value = yjno;
  _ZC_gdbh.value = str;
  _ZC_xscn.value = xscn;
}

//=========工序产量核查===========
const pd_gxclhclist = ref(false);
const gxclhc_Data = ref([]);
const gxclhc_Columns = ref(
    [
      { label: '印件及工序名称', prop: 'concatenatedData', width: '380' },
      // { label: '印件', prop: 'Gy0_yjno', width: '130' },
      // { label: '工序', prop: 'Gy0_gxh', width: '130' },
      // { label: '名称', prop: 'Gy0_gxmc', width: '130' },
      { label: '工序计划产量', prop: 'Gy0_计划接货数', width: '120' },
      { label: '联数', prop: 'Gy0_ls', width: '70' },
      { label: '折算车头产量', prop: '折算车头产量', width: '120' },
      { label: '实际上报产量', prop: 'sczl_cl', width: '120' },
      { label: '制程废品', prop: 'sczl_zcfp', width: '120' },
      { label: '制程废品率', prop: '制程废品率', width: '120' },
      { label: '来料异常', prop: '来料异常', width: '90' },
      { label: '流程单数', prop: 'process_num', width: '90' },
      { label: '当前设备', prop: 'Gy0_sbbh', width: '120' },
      { label: '工序状态', prop: 'PD_WG', width: '90'},
      { label: '首板生产日期', prop: 'sczl_rq', width: '160' },
    ]
)
const gxclhcformData = reactive({
  gdbh: '',
  gdmc: '',
});
// 工序产量核查按钮
const pd_gxclhconClick = async () => {
  if(_Gd_gdbh.value === '' || _Gd_gdbh.value === null){
    ElMessage({type: 'warning',message: '请选择具体的工单，在进行操作'})
    return false;
  }
  gxclhcformData['gdbh'] = _Gd_gdbh.value;
  pd_gxclhclist.value = true;
  _getOrderProcessCount();
};
//工序产量核查回车
const gxclhcProductValue = async () => {
  _getOrderProcessCount();
}
//工序产量核查退出
const gxclhcCancel = async () => {
  pd_gxclhclist.value = false;
};
//工序产量核查方法接口
const _getOrderProcessCount = async () => {
  const order = gxclhcformData['gdbh'];
  const getOrderProcessCount_list = await getOrderProcessCount({order:order});
  const concatenatedData = getOrderProcessCount_list.data.map(item => {
    // 优化后的代码，使用模板字符串连接字段值并在单个数字前添加零
    const formattedYjno = item.Gy0_yjno.length === 1 ? `0${item.Gy0_yjno}` : item.Gy0_yjno;
    const formattedGxh = item.Gy0_gxh.length === 1 ? `0${item.Gy0_gxh}` : item.Gy0_gxh;
    const concatenatedValue = `${formattedYjno}-${formattedGxh} ${item.Gy0_gxmc}`;
    return {
      ...item,
      concatenatedData: concatenatedValue, // 使用新属性名
    };
  });
  gxclhc_Data.value = concatenatedData;
};
//工序产量核查
const gxclhcCellClass = ({row, column, rowIndex, columnIndex}) =>{
  if (column.label === '实际上报产量' ||column.label === '制程废品'  || column.label === '制程废品率' ||
      column.label === '来料异常' || column.label === '流程单数' || column.label === '当前设备') {
    return 'lan-plan-usage-lows';
  }
  if (column.label === '折算车头产量') {
    return 'gxclhc—color-column-red';
  }
  // 如果不是 'PD_WG' 列，返回空字符串或其他样式类
  if (column.label === '工序状态'){
    if(row['PD_WG'] === '完工'){
      return 'lan-plan-usage-lowshui';
    }else{
      return 'pczccolor-column-lan';
    }
  }
}


//===========工单状态设置按钮=======
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;
};


// =========== 【工序状态更正】 ===========
const gxztgzztableColumns = ref(
    [
      { label: '印件及工序', prop: '印件及工序', width: '600' },
      { label: '计划产量/已完成', prop:['计划产量/已完成'], width: '500' },
      { label: '完成率', prop: '完成率', width: '240' },
      { label: '完工时间', prop: '完工时间', width: '300' },
      { label: '设备代号', prop: '设备代号', width: '240' },
    ]
)
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'];
  const ProcessStatusCorrectiondata = await ProcessStatusCorrection({workOrder:workOrder});
  gxztgzztableData.value = ProcessStatusCorrectiondata.data;
};
//工序状态更正更新
const edit_gxztgzzCancel = async () => {
  const formatDate = (inputDateString) => {
    const timestamp = Date.parse(inputDateString);
    if (isNaN(timestamp)) {
      return ''; // 返回空字符串表示日期无效
    }
    const date = new Date(timestamp);
    const year = date.getFullYear();
    const month = ('0' + (date.getMonth() + 1)).slice(-2);
    const day = ('0' + date.getDate()).slice(-2);
    const hour = ('0' + date.getHours()).slice(-2);
    const minute = ('0' + date.getMinutes()).slice(-2);
    const second = ('0' + date.getSeconds()).slice(-2);
    return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
  };
  const formattedData = gxztgzztableData.value.map(item => {
    return {
      UniqId: item['UniqId'],
      PD_WG: formatDate(item['完工时间']),
    };
  });
  const ProcessStatusCorrectionEdit_status = await ProcessStatusCorrectionEdit(formattedData);
  if (ProcessStatusCorrectionEdit_status.code === 0) {
    ElMessage({ type: 'success',message: '更新成功' })
  } else {
    ElMessage({type: 'error',message: '更新失败'})
  }
  gxztgzzlist.value = false;
};
//工序状态更正退出
const gxztgzzCancel = () => {
  gxztgzzlist.value = false;
};


//机组调整按钮
const jizuDisplay = ref(false)
const jizuList = ref([])
const jizuSelection = ref([])
const onjztzClick = async () => {
  if (jitaiArr.value.length === 0) {
    ElMessage.warning('请选择数据')
    return
  }
  jizuList.value = [
    {
      label: jitaiArr.value[0].车间名称,
      value: jitaiArr.value[0].车间名称,
      disabled: true,
      children: []
    }
  ]
  const res = await gdzl_MachineList({address:jitaiArr.value[0].车间名称})
  jizuList.value[0].children = res.data.map(item => {
    return { label: item, value: item.match(/^\w+#/)[0]}
  })
  jizuDisplay.value = true
};

const checkTreeHandle = (data, tree) => {
  jizuSelection.value = tree.checkedNodes
}

const saveJizuTiaozheng = async () => {
  if (jizuSelection.value.length === 0) {
    ElMessage.warning('请先勾选机组')
    return
  }
  const uid = jitaiArr.value.map(item => item.GYUID).join(' ')
  const jizu = jizuSelection.value.map(item=>item.value).join(' ')
  try {
    const res = await MachineTeamEdit({UniqId: uid, machine: jizu})
    if (res.code == 0) ElMessage.success('调整成功')
    const  pc_zc_table = await MachineWorkOrderList({machine:_machine.value});
    chejianData.value = pc_zc_table.data['排程'];
    chejianfuData.value = pc_zc_table.data['制程'];
    jizuDisplay.value = false
  } catch(e) {
    ElMessage.error(e)
  }
}

//=============引用实际参数================
const pd_yysjcsonClick = () => {
  if(_Gd_gdbh.value == null){
    gxztgzzlist.value = false;
    ElMessage({type: 'warning',message: '请选择树形后，再操作此功能'})
  }else{
    console.log(_Gd_gdbh.value)
    ElMessage({type: 'warning',message: '没有找到该产品的入仓完工记录，不能继续进行'})
  }
};

//=============车间设备排程================
const paichengColumns = ref(
    [
      { label: '优先次序', prop: '优先次序', width: '105' },
      { label: '工单编号', prop: '工单编号', width: '100' },
      { label: '印件名称', prop: '印件名称', width: '220' },
      { label: '接货数', prop: '接货数', width: '105' },
      { label: '小时产能', prop: '小时产能', width: '100' },
      { label: '生产工时', prop: '生产工时', width: '100' },
      { label: '辅助工时', prop: '辅助工时', width: '100' },
      { label: '班次安排', prop: '班次安排', width: '100' },
      { label: '排单备注', prop: '排单备注', width: '150' },
      { label: '最早开工时间', prop: '最早开工时间', width: '180' },
      { label: '计划开工时间', prop: '计划开工时间', width: '180' },
      { label: '计划完工时间', prop: '计划完工时间', width: '180' },
      { label: '销售订单号', prop: '销售订单号', width: '120' },
      { label: '印件/工序', prop: '印件/工序', width: '110' },
    ]
)
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
      if (x === 0 && y === +y) {
        console.log("排序前的值");
        console.log(paichengData.value);
        paichengData.value.sort((a, b) => {
          const priorityA = parseFloat(a['优先次序']);
          const priorityB = parseFloat(b['优先次序']);
          // 将空白值放在最后
          if (isNaN(priorityA)) return 1;
          if (isNaN(priorityB)) return -1;
          // 按优先次序升序排序
          return priorityA - priorityB;
        });
        console.log("排序后的值");
        console.log(paichengData.value);

        // 封装时间格式化函数
        function formatTimestamp(timestamp) {
          const date = new Date(timestamp * 1000);
          const year = date.getFullYear();
          const month = (date.getMonth() + 1).toString().padStart(2, '0');
          const day = date.getDate().toString().padStart(2, '0');
          const hours = date.getHours().toString().padStart(2, '0');
          const minutes = date.getMinutes().toString().padStart(2, '0');
          const seconds = date.getSeconds().toString().padStart(2, '0');

          const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
          return formattedDate;
        }
        // 获取第一行数据
        const firstRow = paichengData.value[+y];
        // 初始化上一行的计划完工时间为第一行的计划开工时间
        let prevCompletionTime = new Date(firstRow['计划开工时间']).getTime() / 1000;
        // 遍历每一行数据
        paichengData.value.forEach(row => {
          const roundedValue = (Math.floor(row['生产工时'] * 10) % 10 === 5) ? row['生产工时'] : Math.round(row['生产工时']);
          const result = parseFloat(roundedValue) + parseFloat(row['辅助工时']);
          const resultTimestamp = result * 3600;
          // 计算【计划开工时间】最终时间戳，使用上一行的计划完工时间
          const finalTimestamp = prevCompletionTime + resultTimestamp;
          // 将计划完工时间赋值到当前行
          row['计划完工时间'] = formatTimestamp(finalTimestamp);
          // 更新上一行的计划完工时间为当前行的计划完工时间
          prevCompletionTime = finalTimestamp;

          console.log("=============================");
          console.log("x是 y是 生产工时 + 辅助工时 * 3600 + 计划开工时间 = 时间戳↓↓↓↓↓↓↓↓↓");
          console.log(`x是 ${x}  Y是 ${y} --- ${roundedValue} + ${row['辅助工时']} * 3600 + ${new Date(row['计划开工时间']).getTime() / 1000} = ${finalTimestamp}`);
          console.log("=============================");

        });
      }
      const nextInputElement = document.getElementById(`input${x}${y + 1}`);
      if (nextInputElement) {
        nextInputElement.focus();
      }
      break;
    case 40: // 向下箭头
      if (y < paichengData.value.length ){
        const nextInputElement = document.getElementById(`input${x}${y + 1}`);
        if (nextInputElement) {
          nextInputElement.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
      }
      const nextInputElements = document.getElementById(`input${move}${y}`);
      if (nextInputElements) {
        nextInputElements.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 cjsbpclist = ref(false);
const cjsbpcformData = reactive({
  //设备代号
  sbdh: '',
  // 下拉框选项数据
  bancis: [],
  // 设置默认值
  banci: '',
  isBanciSelected: false,
});

const pd_gdprintonClick = () => {
  printPageRef.value.open(_Gd_gdbh.value)
}

//车间设备排程【按钮】
const oncjsbpcClick = () => {
  cjsbpcformData['sbdh'] = _machine.value;
  paichengData.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});
    }
  } 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){
    paichengData.value.map( item => item.班次安排 = v)
  }else{
    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 () => {
  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)
  if (EquipmentSchedulingEdit_edit.code === 0) {
    ElMessage({ type: 'success', message: '更新成功' });
    cjsbpclist.value = false;
  } else {
    ElMessage({ type: 'error', message: '更新失败' });
  }
  // cjsbpclist.value = true;
};
//车间设备制程【退出】
const cjsbpcCancel = () => {
  cjsbpclist.value = false;
};


// =========== 流程单查询 ===========

const pd_lcdlist = ref(false);
const pd_lcdformData = reactive({
  gdbh: '',
  code: '',
  name: '',
});
// 流程单查询按钮
const processList = ref([]);
const pd_lcdlistonClick = async () => {
  if(_Gd_gdbh.value === '' || _Gd_gdbh.value === null){
    ElMessage({type: 'warning',message: '请选择具体的工单，在进行操作'})
    return false;
  }else{
    pd_lcdformData['gdbh'] = _Gd_gdbh.value;
    pd_lcdlist.value = true;
    processList.value = []
    _getOrderProcessLeft_list();
  }
}
const pd_lcdProductValue = async () => {
  _getOrderProcessLeft_list();
}
const pd_lcd_treeData = ref([]);
const _getOrderProcessLeft_list = async () => {
  const order = pd_lcdformData['gdbh'];
  // console.log(order)
  try {
    //5.1流程单查询-工单工序生产进程菜单栏
    const getOrderProcessLeft_list = await getOrderProcessLeft({ order:order});
    console.log(getOrderProcessLeft_list)
    pd_lcdformData['code'] = getOrderProcessLeft_list.data.Gd_info['code'];
    pd_lcdformData['name'] = getOrderProcessLeft_list.data.Gd_info['name'];
    pd_lcd_treeData.value = [{
      label: order + '-' + getOrderProcessLeft_list.data.Gd_info['name'],
      // label: order + '-' + getOrderProcessLeft_list.data.Gd_info['code'] + '-' + getOrderProcessLeft_list.data.Gd_info['name'],
      value: undefined,
      children: []
    }]
    const newData = [];
    for (let key in getOrderProcessLeft_list.data.Gy_info) {
      let temp = getOrderProcessLeft_list.data.Gy_info[key];
      let concatenatedValue = `${temp.Gy0_yjno}-${temp.Gy0_gxh} ---> ${temp.Gy0_gxmc}`;
      newData.push({ label: concatenatedValue,value: temp.Gy0_gxh });
    }
    pd_lcd_treeData.value[0].children = newData;
    //5.2流程单查询-获取工单工序生产进程右侧【进入页面默认显示第一个】
    const getOrderProcessRight_list = await getOrderProcessRight({order:order, gxNo:newData[0].value});
    processList.value = getOrderProcessRight_list.data
  } catch (error) {
    console.error(error);
  }
};

const pd_lcd_handleNodeClick = async (node) => {
  if (node.value === undefined) return
  const order = pd_lcdformData['gdbh'];
  ////5.2流程单查询-获取工单工序生产进程右侧
  const getOrderProcessRight_list = await getOrderProcessRight({order:order, gxNo:node.value});
  console.log(getOrderProcessRight_list)
  processList.value = getOrderProcessRight_list.data
};

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


//颜色
//工序状态更正颜色
const gxztgzzCellClass = ({row, column, rowIndex, columnIndex}) =>{
  if(row['完工时间'] === ''){
    return 'lan-plan-usage-low';
  }else{
    return 'hui-plan-usage-low';
  }
}
//车间设备制程排序背景
const cjzcCellClass = ({row, column, rowIndex, columnIndex}) =>{
  if (column.label === '优先次序' || column.label === '生产工时' || column.label === '辅助工时' || column.label === '班次安排' || column.label === '排单备注' || column.label === '最早开工时间'  || column.label === '计划开工时间') {
    return 'background-color-column-fen';
  }
  if (row) {
    return 'color-column-lan';
  }
}

//排程中、制程中 下方表格文字变色
const pczc_planUsageCellClass = ({row, column, rowIndex, columnIndex}) =>{
  if (row['工序完工'].substring(0, 2) === "20") {
    return 'pczccolor-column-hui';
  } else {
    return 'pczccolor-column-lan';
  }
}


// 右键勾选
const rowContextMenu = (row) => {
  // console.log(row)

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

/*工序产量核查*/
: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(.pczccolor-column-hui div) {
  color: #8c939d !important;
}
:deep(.pczccolor-column-lan div) {
  color: blue !important;
}
/*车间设备制程背景粉色*/
/*:deep(.el-table__body .background-color-column-fen div div div) {*/
/*  background: #ff80ff !important;*/
/*}*/
/*文字蓝色*/
:deep(.color-column-lan div) {
  color: red !important;
}
:deep(.color-column-lan div div div) {
  color: blue !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;
}
/*分页*/
.el-pagination{
  margin-top: 0px !important;
}
</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>
