<template>
  <div class="app-container">
    <el-card class="topCard">
      <div class="topDiv">
        <span style="margin-left: 10px">订单号：</span>
        <el-select v-model="orderNumberValue" clearable placeholder="请选择订单" size="small" style="width: 150px">
          <el-option v-for="item in orderNumber" :key="item.value" :label="item.label" :value="item.value" size="mini"/>
        </el-select>
        <span style="margin-left: 10px">零件类型：</span>
        <el-select v-model="engineTypeValue" clearable placeholder="请选择零件类型" size="small" style="width: 150px">
          <el-option v-for="item in engineType" :key="item.value" :label="item.label" :value="item.value" size="mini"/>
        </el-select>
        <span style="margin-left: 10px">计划装配日期：</span>
        <el-date-picker
          v-model="startPlanTime"
          placeholder="选择计划装配日期"
          size="small"
          type="date"
          value-format="yyyy-MM-dd"/>
        <!--        <span style="margin-left: 10px">结束日期：</span>-->
        <!--        <el-date-picker v-model="endPlanTime" type="date" size="small" value-format="yyyy-MM-dd" placeholder="选择结束日期" />-->
        <el-button
          icon="el-icon-search"
          plain
          size="small"
          style="margin-left: 10px"
          type="primary"
          @click="pageSize = 15; pageCurrent = 1; searchOrder()">查询订单
        </el-button>
        <el-button
          icon="el-icon-circle-plus"
          size="small"
          type="distribution"
          @click="creatOrder('form')">创建订单
        </el-button>
        <!--        <el-button type="info" plain size="small" icon="el-icon-upload2" @click="importOrder('form')">订单导入</el-button>-->
        <!--        <el-button type="info" plain size="small" icon="el-icon-download" @click="exportExcel()">订单导出</el-button>-->
      </div>
      <el-table
        v-loading="loading"
        ref="multipleTable"
        :cell-class-name="tableRowClassName"
        :data="tableData"
        :expand-row-keys="expandsDetail"
        :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
        :row-key="getRowKeys"
        border
        class="main"
        element-loading-background="rgba(0, 0, 0, 0.2)"
        element-loading-spinner="el-icon-loading"
        element-loading-text="数据加载中"
        height="800px"
        size="mini"
        style="width: 100%;max-height: 700px"
        tooltip-effect="dark"
        @expand-change="selectPlan"
        @selection-change="handleSelectionChange">
        <el-table-column align="center" label="排序" type="index"/>
        <!--        <el-table-column align="center" type="expand" label="" fixed width="35">-->
        <!--          <template slot-scope="scope" >-->
        <!--            <div style="display: flex">-->
        <!--              &lt;!&ndash; 计划数据盒子&ndash;&gt;-->
        <!--              <div style="margin: 5px 10px;width: 400px">-->
        <!--                <el-table-->
        <!--                  :data="tableDataPrint"-->
        <!--                  :header-cell-style="{ background: '#e5e7f8', color: '#606266' }"-->
        <!--                  element-loading-text="数据加载中"-->
        <!--                  element-loading-spinner="el-icon-loading"-->
        <!--                  element-loading-background="rgba(0, 0, 0, 0.2)"-->
        <!--                  class="main"-->
        <!--                  tooltip-effect="dark"-->
        <!--                  style="width: 100%"-->
        <!--                  max-height="400px"-->
        <!--                  border-->
        <!--                  size="mini">-->
        <!--                  <el-table-column align="center" label="总成号">-->
        <!--                    <template slot-scope="scope">-->
        <!--                      {{ scope.row.零件号 }}-->
        <!--                    </template>-->
        <!--                  </el-table-column>-->
        <!--                  <el-table-column align="center" label="日期" width="100">-->
        <!--                    <template slot-scope="scope">-->
        <!--                      {{ scope.row.打印日期 }}-->
        <!--                    </template>-->
        <!--                  </el-table-column>-->
        <!--                  <el-table-column align="center" label="序列号">-->
        <!--                    <template slot-scope="scope">-->
        <!--                      {{ scope.row.打印起始号 }}-->
        <!--                    </template>-->
        <!--                  </el-table-column>-->
        <!--                  <el-table-column align="center" label="数量">-->
        <!--                    <template slot-scope="scope">-->
        <!--                      {{ scope.row.打印数量 }}-->
        <!--                    </template>-->
        <!--                  </el-table-column>-->
        <!--                </el-table>-->
        <!--              </div>-->
        <!--              &lt;!&ndash; 详细数据盒子 &ndash;&gt;-->
        <!--              <div style="margin: 5px 10px;width: 1000px">-->
        <!--                <el-table-->
        <!--                  :data="tableDataPrintDetail"-->
        <!--                  :header-cell-style="{ background: '#e5e7f8', color: '#606266' }"-->
        <!--                  element-loading-text="数据加载中"-->
        <!--                  element-loading-spinner="el-icon-loading"-->
        <!--                  element-loading-background="rgba(0, 0, 0, 0.2)"-->
        <!--                  class="main"-->
        <!--                  tooltip-effect="dark"-->
        <!--                  style="width: 100%;"-->
        <!--                  max-height="400px"-->
        <!--                  border-->
        <!--                  size="mini">-->
        <!--                  <el-table-column align="center" label="变速箱总成号" width="250">-->
        <!--                    <template slot-scope="scope">-->
        <!--                      {{ scope.row.变速箱总成号 }}-->
        <!--                    </template>-->
        <!--                  </el-table-column>-->
        <!--                  <el-table-column align="center" label="序列号" width="150">-->
        <!--                    <template slot-scope="scope">-->
        <!--                      {{ scope.row.变速箱总成号.split('*')[2] }}-->
        <!--                    </template>-->
        <!--                  </el-table-column>-->
        <!--                  <el-table-column align="center" label="总装上线时间">-->
        <!--                    <template slot-scope="scope">-->
        <!--                      {{ scope.row.上线时间 ? scope.row.上线时间 : '未上线' }}-->
        <!--                    </template>-->
        <!--                  </el-table-column>-->
        <!--                  <el-table-column align="center" label="总装下线时间">-->
        <!--                    <template slot-scope="scope">-->
        <!--                      {{ scope.row.下线时间 ? scope.row.下线时间 : '未下线' }}-->
        <!--                    </template>-->
        <!--                  </el-table-column>-->
        <!--                  <el-table-column align="center" label="测试上线时间">-->
        <!--                    <template slot-scope="scope">-->
        <!--                      {{ scope.row.测试上线时间 ? scope.row.测试上线时间 : '未上线' }}-->
        <!--                    </template>-->
        <!--                  </el-table-column>-->
        <!--                  <el-table-column align="center" label="测试下线时间">-->
        <!--                    <template slot-scope="scope">-->
        <!--                      {{ scope.row.测试下线时间 ? scope.row.测试下线时间 : '未下线' }}-->
        <!--                    </template>-->
        <!--                  </el-table-column>-->
        <!--                </el-table>-->
        <!--              </div>-->
        <!--            </div>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <el-table-column align="center" label="任务编号">
          <template slot-scope="scope">
            {{ scope.row.任务码 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="订单号">
          <template slot-scope="scope">
            {{ scope.row.订单号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="零件类型">
          <template slot-scope="scope">
            {{ scope.row.产品型号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="零件类型名称">
          <template slot-scope="scope">
            {{ scope.row.零件名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="零件数量">
          <template slot-scope="scope">
            {{ scope.row.计划数量 }}
          </template>
        </el-table-column>
        <!--<el-table-column align="center" label="批次号">-->
        <!--  <template slot-scope="scope">-->
        <!--    {{ scope.row.批次号 }}-->
        <!--  </template>-->
        <!--</el-table-column>-->
        <el-table-column align="center" label="设备号">
          <template slot-scope="scope">
            {{ scope.row.设备号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="工序号">
          <template slot-scope="scope">
            {{ scope.row.工序号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="加工人">
          <template slot-scope="scope">
            {{ scope.row.加工人 }}
          </template>
        </el-table-column>
        <!--        <el-table-column align="center" label="完成数量">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ scope.row.完成数量 }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column align="center" label="状态">-->
        <!--          <template slot-scope="scope">-->
        <!--            <el-tag v-if="parseInt(scope.row.订单状态) === 0" effect="plain" style="width: 70px" type="info">已结束</el-tag>-->
        <!--            <el-tag v-if="parseInt(scope.row.订单状态) === 1" effect="plain" style="width: 70px" type="success">生产中</el-tag>-->
        <!--            <el-tag v-if="parseInt(scope.row.订单状态) === 2" effect="plain" style="width: 70px" type="text">未上线</el-tag>-->
        <!--            <el-tag v-if="parseInt(scope.row.订单状态) === 3" effect="plain" style="width: 70px" type="warning">未完成</el-tag>-->
        <!--            <el-tag v-if="parseInt(scope.row.订单状态) === 4" effect="plain" style="width: 70px" type="danger">已超额</el-tag>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <el-table-column align="center" label="计划装配日期">
          <template slot-scope="scope">
            {{ scope.row.计划开始时间 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="下达时间" min-width="130">
          <template slot-scope="scope">
            {{ scope.row.下发时间 }}
          </template>
        </el-table-column>
        <!--        <el-table-column align="center" label="总装上线" width="100px">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ scope.row.总装上线 }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column align="center" label="总装下线" width="100px">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ scope.row.总装下线 }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column align="center" label="测试上线" width="100px">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ scope.row.测试上线 }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column align="center" label="测试下线" width="100px">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ scope.row.测试下线 }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <el-table-column align="center" label="操作" min-width="120">
          <template slot-scope="scope">
            <el-button
              :disabled="parseInt(scope.row.订单状态) !== 2"
              icon="el-icon-edit"
              size="mini"
              type="text"
              @click="handleEdit(scope.row)">修改
            </el-button>
            <el-button
              :disabled="parseInt(scope.row.订单状态) !== 2"
              icon="el-icon-delete"
              size="mini"
              style="color: #ff0000"
              type="text"
              @click="deleteOrder(scope.row)">删除
            </el-button>
            <!--            <el-button-->
            <!--              :disabled="parseInt(scope.row.订单状态) !== 2 "-->
            <!--              size="mini"-->
            <!--              type="text"-->
            <!--              icon="el-icon-success"-->
            <!--              @click="ordersIssuedEditor(scope.row)">订单下发</el-button>-->
            <!--            <el-button-->
            <!--              :disabled="parseInt(scope.row.订单状态) !== 1 "-->
            <!--              size="mini"-->
            <!--              type="text"-->
            <!--              icon="el-icon-success"-->
            <!--              @click="ordersIssuedEditor1(scope.row)">取消下达</el-button>-->
            <!--            <el-button size="mini" type="text" icon="el-icon-success" @click="printShow(scope.row)">打印条码</el-button>-->
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          v-if="!loading"
          :current-page="pageCurrent"
          :page-size="pageSize"
          :page-sizes="[15, 30, 40]"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
    </el-card>
    <el-dialog
      v-el-drag-dialog
      :visible.sync="dialogFormVisible"
      center
      style="min-height: 200px;"
      title="创建生产订单"
      width="800px">
      <el-form ref="form" :model="form" :rules="rules" label-position="right" label-width="110px">
        <el-col :span="12">
          <el-form-item label="订单号" prop="orderNumber" style="display: inline-block">
            <el-input v-model="form.orderNumber" clearable placeholder="请输入订单号" size="small"/>
          </el-form-item>
          <el-form-item label="零件类型" prop="engineTypeValue" style="display: inline-block">
            <el-select
              v-model="form.engineTypeValue"
              placeholder="请选择零件类型"
              size="small"
              @change="engineTypeValueChange">
              <el-option v-for="item in engineType" :key="item.value" :label="item.label" :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="零件名称" prop="engineTypeName" style="display: inline-block">
            <el-input v-model="form.engineTypeName" readonly size="small"/>
          </el-form-item>
          <el-form-item label="零件数量" prop="planQuantity" style="display: inline-block">
            <el-input-number
              v-model="form.planQuantity"
              :min="1"
              :step="1"
              placeholder="请输入零件数量"
              size="small"
              style="width: 200px;"/>
          </el-form-item>
          <!--<el-form-item label="批次号" prop="batchNo" style="display: inline-block">-->
          <!--  <el-input v-model="form.batchNo" clearable placeholder="请输入批次号" size="small"/>-->
          <!--</el-form-item>-->
        </el-col>
        <el-col :span="12">
          <el-form-item label="设备号" prop="deviceNo" style="display: inline-block">
            <el-select v-model="form.deviceNo" placeholder="请选择设备号" size="small">
              <el-option v-for="item in stationNumber" :key="item.value" :label="item.label" :value="item.value"/>
            </el-select>
          </el-form-item>
          <!--<el-form-item label="工序号" prop="craftNo" style="display: inline-block">-->
          <!--  <el-select v-model="form.craftNo" size="small" placeholder="请选择工序号">-->
          <!--    <el-option v-for="item in stationNumber" :key="item.value" :label="item.label" :value="item.value" />-->
          <!--  </el-select>-->
          <!--</el-form-item>-->
          <el-form-item label="加工人" prop="personNo" style="display: inline-block">
            <el-input
              v-model="form.personNo"
              clearable
              placeholder="请双击选择"
              readonly
              size="small"
              style="width:200px"
              @dblclick.native="dialogTableVisible()"/>
          </el-form-item>
          <el-form-item label="计划装配日期" prop="startPlanTime" style="display: inline-block">
            <el-date-picker
              v-model="form.startPlanTime"
              placeholder="请选择计划装配日期"
              size="small"
              type="date"
              value-format="yyyy-MM-dd"/>
          </el-form-item>
          <el-form-item label="." prop="123" style="display: inline-block"/>
        </el-col>
        <!--        <el-form-item label="计划结束时间" prop="endPlanTime" style="display: inline-block">-->
        <!--          <el-date-picker-->
        <!--            v-model="form.endPlanTime"-->
        <!--            size="small"-->
        <!--            type="date"-->
        <!--            value-format="yyyy-MM-dd"-->
        <!--            placeholder="选择结束时间" />-->
        <!--        </el-form-item>-->
      </el-form>
      <br>
      <div style="text-align: center;">
        <el-button size="small" @click="callOff('form')">取消</el-button>
        <el-button size="small" type="primary" @click="submitAdd('form')">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      v-el-drag-dialog
      :visible.sync="dialogFormVisible1"
      center
      style="min-height: 200px"
      title="编辑生产订单"
      width="800px">
      <el-form ref="form1" :model="form1" :rules="rules1" label-position="right" label-width="110px">
        <el-col :span="12">
          <el-form-item label="订单号" prop="orderNumber" style="display: inline-block">
            <el-input v-model="form1.orderNumber" disabled placeholder="请输入订单号" size="small"/>
          </el-form-item>
          <el-form-item label="零件类型" prop="engineTypeValue" style="display: inline-block">
            <el-select
              v-model="form1.engineTypeValue"
              disabled
              placeholder="请选择零件类型"
              size="small"
              @change="engineTypeValueChange">
              <el-option v-for="item in engineType" :key="item.value" :label="item.label" :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="零件名称" prop="engineTypeName" style="display: inline-block">
            <el-input v-model="form1.engineTypeName" readonly size="small"/>
          </el-form-item>
          <el-form-item label="零件数量" prop="planQuantity" style="display: inline-block">
            <el-input-number
              v-model="form1.planQuantity"
              :min="1"
              :step="1"
              placeholder="请输入零件数量"
              size="small"
              style="width: 200px;"/>
          </el-form-item>
          <!--<el-form-item label="批次号" prop="batchNo" style="display: inline-block">-->
          <!--  <el-input v-model="form1.batchNo" clearable placeholder="请输入批次号" size="small"/>-->
          <!--</el-form-item>-->
        </el-col>
        <el-col :span="12">
          <el-form-item label="设备号" prop="deviceNo" style="display: inline-block">
            <el-select v-model="form1.deviceNo" placeholder="请选择设备号" size="small">
              <el-option v-for="item in stationNumber" :key="item.value" :label="item.label" :value="item.value"/>
            </el-select>
          </el-form-item>
          <!--<el-form-item label="工序号" prop="craftNo" style="display: inline-block">-->
          <!--  <el-select v-model="form1.craftNo" size="small" placeholder="请选择工序号">-->
          <!--    <el-option v-for="item in stationNumber" :key="item.value" :label="item.label" :value="item.value" />-->
          <!--  </el-select>-->
          <!--</el-form-item>-->
          <el-form-item label="加工人" prop="personNo" style="display: inline-block">
            <el-input
              v-model="form1.personNo"
              clearable
              placeholder="请双击选择"
              readonly
              size="small"
              style="width:200px"
              @dblclick.native="dialogTableVisible()"/>
          </el-form-item>
          <el-form-item label="计划装配日期" prop="startPlanTime" style="display: inline-block">
            <el-date-picker
              v-model="form1.startPlanTime"
              placeholder="请选择计划装配日期"
              size="small"
              type="date"
              value-format="yyyy-MM-dd"/>
          </el-form-item>
          <el-form-item label="." prop="123" style="display: inline-block"/>
        </el-col>
        <!--        <el-form-item label="计划结束时间" prop="endPlanTime" style="display: inline-block">-->
        <!--          <el-date-picker-->
        <!--            v-model="form.endPlanTime"-->
        <!--            size="small"-->
        <!--            type="date"-->
        <!--            value-format="yyyy-MM-dd"-->
        <!--            placeholder="选择结束时间" />-->
        <!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="callOff1()">取消</el-button>
        <el-button size="small" type="primary" @click="submitAdd1()">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible3" center style="min-height: 200px" title="订单导入" width="900px">
      <div class="app-container">
        <upload-excel-component style="margin-left: 15%" @on-selected-file="selected"/>
        <div style="margin-left: 395px">
          <span v-show="worksheet.length > 1" style="cursor: pointer;width: 50px;" @click="removeAll"><i
            class="el-icon-close"/></span>
          <el-upload :file-list="itemFile" :on-remove="handleRemove" action="" style="width: 220px"/>
        </div>
        <div v-if="worksheet.length !== 0" style="margin: 3px 0 0 395px">
          <el-button icon="el-icon-upload2" size="small" type="primary" @click="basicPartsToSQL">导入到数据库
          </el-button>
        </div>
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="dialogFormVisible4"
      center
      style="min-height: 200px;"
      title="打印变速器条码"
      width="400px">
      <el-form ref="printForm" :model="printForm" :rules="printRules" label-position="right" label-width="110px">
        <el-form-item label="产品型号" prop="产品型号" style="display: inline-block">
          <el-input v-model="printForm.产品型号" placeholder="请输入产品型号" readonly size="small"/>
        </el-form-item>
        <el-form-item label="总成号" prop="零件号" style="display: inline-block">
          <el-input v-model="printForm.零件号" placeholder="请输入总成号" readonly size="small"/>
        </el-form-item>
        <el-form-item label="序列号" prop="起始号码" style="display: inline-block">
          <el-input
            v-model="printForm.起始号码"
            :disabled="printCountPlanIsShow"
            placeholder="请输入八位序列号"
            size="small"
            @blur="startKeyChange(printForm.起始号码)"/>
            <!--          <el-input-number-->
            <!--            v-model="printForm.起始号码"-->
            <!--            :min="1"-->
            <!--            :step="1"-->
            <!--            size="small"-->
            <!--            style="width: 200px;"-->
            <!--            placeholder="请输入计划数量" />-->
        </el-form-item>
        <el-form-item label="打印日期" prop="打印日期" style="display: inline-block">
          <el-date-picker
            v-model="printForm.打印日期"
            :disabled="printCountPlanIsShow"
            placeholder="选择打印日期"
            size="small"
            type="date"
            value-format="yyyy-MM-dd"
            @change="getPrintDate"/>
        </el-form-item>
        <el-form-item label="打印数量" prop="打印数量" style="display: inline-block">
          <el-input-number
            v-model="printForm.打印数量"
            :disabled="printCountPlanIsShow"
            :min="1"
            :step="1"
            placeholder="请输入打印数量"
            size="small"
            style="width: 200px;"/>
        </el-form-item>
        <div v-if="printCountPlanIsShow" style="text-align: center;color: #3c9445;font-size: 20px">
          打印进度：{{ printCountPlan }} / {{ printForm.打印数量 }}
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="callOffPrint()">取消</el-button>
        <el-button :disabled="isAllowAddClike" size="small" type="primary" @click="submitAddPrint('printForm')">确定
        </el-button>
      </div>
    </el-dialog>
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisiblePerson" center title="人员信息" width="750px">
      <div style="height: 410px">
        <div
          style="float: left;margin-top: 3px;margin-left: 20px;overflow-y: scroll;height: 400px;border: 1px solid #c2c2c2">
          <el-tree
            :data="data2"
            accordion
            height="400"
            node-key="id"
            style="width: 150px;float: left"
            @node-click="handleNodeClick"
          />
        </div>
        <el-table
          :data="List1"
          height="400"
          highlight-current-row
          style="width: 400px;float: left;margin-left: 30px;border: 1px solid #c2c2c2"
          @row-click="handleCurrentChange_person">
          <el-table-column align="center" label="考勤编号">
            <template slot-scope="scope">
              {{ scope.row.考勤编号 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="姓名">
            <template slot-scope="scope">
              {{ scope.row.姓名 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="性别">
            <template slot-scope="scope">
              {{ scope.row.性别 }}
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-button style="margin-left: 260px" @click="dialogFormVisiblePerson = false">取消</el-button>
      <el-button style="margin-top: 20px" type="primary" @click="getName_person">确认</el-button>
    </el-dialog>
  </div>
</template>

<script>
import UploadExcelComponent from './UploadExcel.vue'
import { sleep } from '../../../utils/tool'
import { fn } from '@/api/BasicData/WorkshopPersonnelRoleMana'
// import { Mqtt } from '../../../utils/mqtt.js'
export default {
  name: 'UploadExcel',
  components: { UploadExcelComponent },
  data() {
    return {
      staffName: '', // 员工姓名
      attendanceNumber: '', // 考勤编号
      List1: [], // 人员列表
      department: '', // 部门
      number: '', // 考勤编号
      data2: [], // 部门树
      expands: [],
      expandsDetail: [],
      mqttClient: null,
      mqttConnection: {
        host: window.g.mqttIP,
        port: window.g.mqttPortNumber,
        endpoint: '/mqtt',
        clean: true, // 保留会话
        connectTimeout: 4000, // 超时时间
        reconnectPeriod: 4000, // 重连时间间隔
        clientId: '', // 同一个ID 无法二次连接
        username: 'MES_Manager',
        password: '123456'
      },
      subscription: {
        topic: '',
        qos: 0
      },
      publication: {
        topic: '',
        qos: 0,
        payload: ''
      },
      worksheet: [],
      itemFile: [],
      unSpecification: [],
      method1: '', // 机床1加工方式
      method2: '', // 机床2加工方式
      method1Explain: '', // 机床1加工方式说明
      method2Explain: '', // 机床2加工方式说明
      stockQuantity: '', // 库存数量
      stockNum: '', // 库位号
      explain: false,
      orderNumber: [],
      orderNumberValue: '',
      OrderNumber_check: 0,
      engineTypeValue: '',
      engineType: [],
      engineTypeList2: new Map(),
      partCodeList: [],
      OKWarehouseValue: '',
      OKWarehouse: [],
      NGWarehouseValue: '',
      NGWarehouse: [],
      engineType_check: 0,
      printForm: { // 创建订单
        订单号: '',
        零件号: '',
        产品型号: '',
        产品型号代码: '',
        起始号码: '',
        打印日期: '',
        打印数量: 1
      },
      printRules: { // 打印条码验证
        零件号: [{ required: true, message: '请输入总成号', trigger: 'blur' }],
        订单号: [{ required: true, message: '请输入订单号', trigger: 'blur' }],
        产品型号: [{ required: true, message: '请输入产品型号', trigger: 'blur' }],
        起始号码: [{ required: true, min: 8, message: '长度最少为八位', trigger: 'blur' }],
        打印日期: [{ required: true, message: '请选择打印日期', trigger: 'blur' }],
        打印数量: [{ required: true, message: '请输入打印数量', trigger: 'blur' }]
      },
      form: { // 创建订单
        planQuantity: '', // 零件数量
        orderNumber: '', // 订单号
        engineTypeValue: '', // 零件号
        engineTypeName: '', // 零件名称
        partCode: '',
        personNo: '', // 加工人
        startPlanTime: '', // 计划装配日期
        endPlanTime: '',
        quantityCompletion: '',
        batchNo: '', // 批次号
        deviceNo: '', // 设备号
        craftNo: '' // 工序号
      },
      rules: { // 创建订单验证
        planQuantity: [{ required: true, message: '请输入零件数量', trigger: 'blur' }],
        orderNumber: [{ required: true, message: '请输入订单号', trigger: 'blur' }],
        engineTypeValue: [{ required: true, message: '请选择零件类型', trigger: 'blur' }],
        partCode: [{ required: true, message: '请选择总成号', trigger: 'blur' }],
        startPlanTime: [{ required: true, message: '请选择计划装配日期', trigger: 'blur' }],
        endPlanTime: [{ required: true, message: '请选择计划结束时间', trigger: 'blur' }],
        personNo: [{ required: true, message: '请选择加工人', trigger: 'change' }],
        // batchNo: [{ required: true, message: '请输入批次号', trigger: 'blur' }],
        deviceNo: [{ required: true, message: '请选择设备号', trigger: 'blur' }],
        // craftNo: [{ required: true, message: '请选择工序号', trigger: 'blur' }],
        quantityCompletion: [{ required: true, message: '请输入计划完成数量', trigger: 'blur' }]
      },
      form1: { // 修改订单
        planQuantity: '', // 零件数量
        orderNumber: '', // 订单号
        engineTypeValue: '', // 零件号
        engineTypeName: '', // 零件名称
        partCode: '',
        personNo: '', // 加工人
        startPlanTime: '', // 计划装配日期
        endPlanTime: '',
        quantityCompletion: '',
        batchNo: '', // 批次号
        deviceNo: '', // 设备号
        craftNo: '', // 工序号
        MID: '',
        rank: ''
      },
      rules1: { // 修改订单验证
        planQuantity: [{ required: true, message: '请输入零件数量', trigger: 'blur' }],
        orderNumber: [{ required: true, message: '请输入订单号', trigger: 'blur' }],
        engineTypeValue: [{ required: true, message: '请选择零件类型', trigger: 'blur' }],
        partCode: [{ required: true, message: '请选择总成号', trigger: 'blur' }],
        startPlanTime: [{ required: true, message: '请选择计划装配日期', trigger: 'blur' }],
        endPlanTime: [{ required: true, message: '请选择计划结束时间', trigger: 'blur' }],
        personNo: [{ required: true, message: '请选择加工人', trigger: 'blur' }],
        // batchNo: [{ required: true, message: '请输入批次号', trigger: 'blur' }],
        deviceNo: [{ required: true, message: '请选择设备号', trigger: 'blur' }],
        // craftNo: [{ required: true, message: '请选择工序号', trigger: 'blur' }],
        quantityCompletion: [{ required: true, message: '请输入计划完成数量', trigger: 'blur' }]
      },
      form2: { // 订单下发
        planQuantity: '',
        orderNumber: '',
        engineTypeValue: '',
        MID: '',
        IssuedQuantity: 1
      },
      rules2: { // 订单下发验证
        planQuantity: [{ required: true, message: '请输入计划数量', trigger: 'blur' }],
        orderNumber: [{ required: true, message: '请输入订单号', trigger: 'blur' }],
        engineTypeValue: [{ required: true, message: '请选择机型', trigger: 'blur' }],
        IssuedQuantity: [{ required: true, message: '请输入订单下发数量', trigger: 'blur' }]
      },
      form3: { // 订单下发
        planQuantity: '',
        orderNumber: '',
        engineTypeValue: '',
        MID: '',
        IssuedQuantity: 1
      },
      rules3: { // 订单下发验证
        planQuantity: [{ required: true, message: '请输入计划数量', trigger: 'blur' }],
        orderNumber: [{ required: true, message: '请输入订单号', trigger: 'blur' }],
        engineTypeValue: [{ required: true, message: '请选择机型', trigger: 'blur' }],
        IssuedQuantity: [{ required: true, message: '请输入订单下发数量', trigger: 'blur' }]
      },
      // planTime: [new Date(new Date().getTime() - 3600 * 1000 * 24 * 3000), new Date(new Date().getTime())],
      planTime: [],
      startPlanTime: '',
      startPlanTime_check: 0,
      endPlanTime: '',
      endPlanTime_check: 0,
      tableData: [],
      tableDataPrint: [],
      tableDataPrintDetail: [],
      stationNumber: [],
      stationNumberValue: '',
      importData: [],
      dialogFormVisible: false, // 创建订单
      dialogFormVisible1: false, // 修改订单
      dialogFormVisible3: false, // 订单导入
      dialogFormVisible4: false, // 打印
      dialogFormVisiblePerson: false, // 人员选择的
      isAllowAddClike: false, // 打印按钮是否禁用
      states: '', // 当前库存状态
      printCountPlan: 0, // 打印进度条
      printCountPlanIsShow: false, // 打印进度条是否显示
      MIDGroup: [],
      total: 0, // 总条数
      pageList: 15, // 每页显示条数
      pageSize: 15, // 每页显示条数
      pageCurrent: 1, // 后台获取页
      loading: false
    }
  },
  created() {
    this.fetchData()
    this.getStationNumber()
    this.getOrderNumber()
    this.getEndStation()
    this.getPartCodeList()
    this.searchOrder()
  },
  mounted() {
    // if (window.g.mqttClient) {
    //   window.g.mqttClient.destroyConnection()
    // }
    // this.mqttConnection.username = 'MES_Manager_Plan'
    // window.g.mqttClient = new Mqtt(this.mqttConnection)
    // window.g.mqttClient.createConnection()
    // window.g.mqttClient.client.on('connect', () => {
    //   console.log('MQTT Connection succeeded!')
    // })
    // // this.subscription.topic = window.g.mqttSubscriptionTopic
    // // window.g.mqttClient.doSubscribe(this.subscription)
    //
    // // 使用过程中的报错 断开连接 服务端出问题
    // window.g.mqttClient.client.on('error', error => {
    //   console.log('Connection failed', error)
    // })
    // window.g.mqttClient.client.on('message', (topic, message) => {
    //   console.log('Received message:', topic, message.toString())
    // })
  },
  beforeDestroy() {
    // if (window.g.mqttClient.client.connected) {
    //   const destroyConnection = window.g.mqttClient.destroyConnection()
    //   if (destroyConnection) {
    //     this.$message({
    //       message: 'MQTT断开成功！',
    //       type: 'success'
    //     })
    //   } else {
    //     this.$message({
    //       message: 'MQTT断开失败！',
    //       type: 'error'
    //     })
    //   }
    // }
  },
  methods: {
    engineTypeValueChange() {
      this.form.engineTypeName = this.engineTypeList2.get(this.form.engineTypeValue)
      this.form1.engineTypeName = this.engineTypeList2.get(this.form1.engineTypeValue)
    },
    printShow(row) {
      this.printForm.订单号 = row.订单号
      this.printForm.产品型号 = row.产品型号
      this.printForm.产品型号代码 = row.机型代码
      this.printForm.零件号 = row.零件号
      this.printForm.打印日期 = this.getNowFormatDate()
      this.printForm.打印数量 = 1
      this.dialogFormVisible4 = true
    },
    removeAll() {
      this.worksheet = []
      this.itemFile = []
    },
    async selected(data) { // 选择需要导入的文件
      console.log(data, 1111)
      this.worksheet = data.worksheet // 获取每个多选文件的表格坐标及值
      this.itemFile = data.itemFile
    },
    handleRemove(file) { // 移除文件
      for (let i = 0; i < this.itemFile.length; i++) {
        if (this.itemFile[i].name === file.name) {
          this.worksheet.splice(i, 1)
          this.itemFile.splice(i, 1)
        }
      }
    },
    /* 验证内容是否英文数字以及下划线*/
    // isPassword(rule, value, callback) {
    //   const reg = /^[_a-zA-Z0-9]+$/
    //   if (value === '' || value === undefined || value == null) {
    //     callback()
    //   } else {
    //     if (!reg.test(value) || value.length !== 7) {
    //       callback(new Error('订单仅由数字和字母组成，且只能位7位'))
    //     } else {
    //       callback()
    //     }
    //   }
    // },
    // 获取人员信息
    fetchData() {
      var param = []
      param[0] = ['子节点', 0]
      var Data = this.CreateData('11', '人事档案管理_部门关系_查询节点', param)
      this.ExecDatabase(Data).then(response => {
        const data = response.data
        this.data2 = fn(data, 0)
      })
    },
    handleNodeClick(data) { // 树节点点击
      this.department = data.label
      var param = []
      param[0] = ['考核部门编号', data.id]
      var Data = this.CreateData('11', '人事档案管理_人员_部门与人员_查询数据_根据部门编号', param)
      this.ExecDatabase(Data).then(response => {
        this.List1 = response.data
      })
    },
    // 初始化获取产品型号
    getEndStation() {
      this.engineType = []
      this.engineTypeList2 = new Map()
      var param = []
      var Data = this.CreateData('11', 'MES_基本变量_机型代码_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.engineType.push({
            label: response.data[i].发动机型号,
            value: response.data[i].发动机型号
          })
          this.engineTypeList2.set(response.data[i].发动机型号, response.data[i].总成物料号)
        }
      })
    },
    getStationNumber() {
      this.stationNumber = []
      var param = []
      var Data = this.CreateData('11', 'MES_计划BOM_工位与名称_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.stationNumber.push({
            label: response.data[i].工位号,
            value: response.data[i].工位号
          })
        }
        this.stationNumberValue = response.data[0].工位号
      })
    },
    // 日期框点击事件
    getPrintDate(date) {
      this.printForm.打印日期 = date
    },
    // 获取当前日期函数
    getNowFormatDate() {
      const date = new Date()
      const year = date.getFullYear() // 获取完整的年份(4位)
      let month = date.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
      let strDate = date.getDate() // 获取当前日(1-31)
      if (month < 10) month = `0${month}` // 如果月份是个位数，在前面补0
      if (strDate < 10) strDate = `0${strDate}` // 如果日是个位数，在前面补0

      return `${year}-${month}-${strDate}`
    },
    // 初始化获取产品型号
    getPartCodeList() {
      this.partCodeList = []
      var param = []
      param[0] = ['基本机型', this.form.engineTypeValue]
      var Data = this.CreateData('11', '北汽福田订单创建零件号_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length === 0) {
          this.$message({
            type: 'error',
            message: '该机型没有对应的零件号'
          })
          return false
        } else {
          for (let i = 0; i < response.data.length; i++) {
            this.partCodeList.push({
              label: response.data[i].零件号,
              value: response.data[i].零件号
            })
          }
          this.form.partCodeValue = this.partCodeList[0].value
        }
      })
    },
    // 初始化获取订单号
    getOrderNumber() {
      this.orderNumber = []
      var param = []
      param[0] = ['开始时间', this.planTime[0]]
      param[1] = ['结束时间', this.planTime[1]]
      var Data = this.CreateData('11', '订单计划_订单号_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.orderNumber.push({
            label: response.data[i].订单号,
            value: response.data[i].订单号
          })
        }
      })
    },
    // 控制展开列
    selectPlan(row, expandedRows) {
      if (expandedRows.length) {
        this.expands = []
        this.expandsDetail = []
        if (row) {
          this.tableDataPrint = []
          var param = []
          param[0] = ['工单号', row.订单号]
          var Data = this.CreateData('11', '生产计划_派工订单_打印_查询', param)
          this.ExecDatabase(Data).then(response => {
            console.log(response.data)
            if (response.data.length !== 0) {
              this.tableDataPrint = response.data
            }
            this.expands.push(row.订单号)
          })

          this.tableDataPrintDetail = []
          var Data2 = this.CreateData('11', '生产计划_派工订单_打印详细_查询', param)
          this.ExecDatabase(Data2).then(response => {
            console.log(response.data)
            if (response.data.length !== 0) {
              this.tableDataPrintDetail = response.data
            }
            this.expandsDetail.push(row.订单号)
          })
        }
      } else {
        this.expands = []
        this.expandsDetail = []
      }
    },
    // 获取展开列的工单号
    getRowKeys(row) {
      return row.订单号
    },
    // 查询订单
    searchOrder() {
      this.expands = []
      this.tableData = []
      this.startPlanTime ? this.startPlanTime_check = 1 : this.startPlanTime_check = 0
      this.endPlanTime ? this.endPlanTime_check = 1 : this.endPlanTime_check = 0
      this.orderNumberValue ? this.OrderNumber_check = 1 : this.OrderNumber_check = 0
      this.engineTypeValue ? this.engineType_check = 1 : this.engineType_check = 0
      if (this.startPlanTime === null) {
        this.startPlanTime = ''
      }
      if (this.endPlanTime === null) {
        this.endPlanTime = ''
      }
      var param = []
      param[0] = ['计划开始时间_check', this.startPlanTime_check]
      param[1] = ['计划开始时间', this.startPlanTime]
      param[2] = ['计划完成时间_check', this.endPlanTime_check]
      param[3] = ['计划完成时间', this.endPlanTime]
      param[4] = ['订单号_check', this.OrderNumber_check]
      param[5] = ['订单号', this.orderNumberValue]
      param[6] = ['产品型号_check', this.engineType_check]
      param[7] = ['产品型号', this.engineTypeValue]
      param[8] = ['PageCurrent', this.pageCurrent]
      param[9] = ['PageSize', this.pageSize]
      param[10] = ['PageCount', '1111', 'int', '1']
      param[11] = ['ItemCount', '1111', 'int', '1']
      var Data = this.CreateData('11', 'MES_计划BOM_发动机订单计划_查询分页', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.result.length !== 0) {
          this.tableData = response.data.result
        }
        this.total = parseInt(response.data.output[0].ItemCount)
        this.loading = false
      })
    },
    // 显示人员的
    dialogTableVisible() {
      this.dialogFormVisiblePerson = true
    },
    handleCurrentChange_person(row) { // 获取当前行人员信息
      this.name = row.姓名
      console.log(row)
    },
    getName_person() { // 提交人员
      this.dialogFormVisiblePerson = false
      console.log(this.name)
      this.form.personNo = this.name
      this.form1.personNo = this.name
    },
    // 创建订单
    creatOrder(formName) {
      if (this.$refs[formName] !== undefined) {
        this.$refs[formName].resetFields()
      }
      this.form.planQuantity = ''
      this.form.orderNumber = ''
      this.form.startPlanTime = ''
      this.form.endPlanTime = ''
      this.form.engineTypeName = ''
      this.form.personNo = ''
      this.form.batchNo = ''
      this.form.deviceNo = this.stationNumberValue
      this.form.craftNo = this.stationNumberValue
      this.dialogFormVisible = true
    },
    // 提交新增订单
    submitAdd(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['订单号', this.form.orderNumber]
          param[1] = ['产品型号', this.form.engineTypeValue]
          param[2] = ['计划开始时间', this.form.startPlanTime]
          param[3] = ['计划完成时间', this.form.endPlanTime]
          param[4] = ['计划数量', this.form.planQuantity]
          param[5] = ['排序', this.form.quantityCompletion]
          param[6] = ['零件名称', this.form.engineTypeName]
          param[7] = ['加工人', this.form.personNo]
          param[8] = ['批次号', this.form.batchNo]
          param[9] = ['设备号', this.form.deviceNo]
          // param[10] = ['工序号', this.form.craftNo]
          param[10] = ['工序号', this.form.deviceNo]
          param[11] = ['零件号', this.form.engineTypeValue]
          var Data = this.CreateData('11', 'MES_计划BOM_发动机订单计划_订单手动增加', param)
          this.ExecDatabase(Data).then(response => {
            console.log(response)
            if (response.data[0].result === 1) {
              this.$message({
                message: '订单创建成功',
                type: 'success'
              })
              this.pageCurrent = 1
              this.pageSize = 15
              this.searchOrder()
            } else if (response.data[0].result === 2) {
              this.$message.error('订单重复，创建失败！')
            } else {
              this.$message.error('订单创建失败！')
            }
          })
          this.dialogFormVisible = false
        } else {
          return false
        }
      })
    },
    submitAddPrint(formName) {
      if (this.printForm.起始号码.length < 8) return
      this.$refs[formName].validate((valid) => {
        const scope = this
        var param = []
        param[0] = ['工单号', this.printForm.订单号]
        param[1] = ['零件号', this.printForm.零件号]
        param[2] = ['打印起始号', this.printForm.起始号码]
        param[3] = ['打印数量', this.printForm.打印数量]
        param[4] = ['打印日期', this.printForm.打印日期]
        var Data = this.CreateData('12', '生产计划_派工订单_打印_增加', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message({
              message: '开始打印变速器条码',
              type: 'success'
            })
            // 置空进度条进度
            this.printCountPlan = 0
            this.printCountPlanIsShow = true
            this.searchPrintListFinal()
            const printPartCode = this.printForm.零件号
            const printTemplate = window.g.printTemplate
            const printStartNum = parseInt(this.printForm.起始号码)
            const printDate = typeof (this.printForm.打印日期) === 'string' ? new Date(this.printForm.打印日期) : this.printForm.打印日期
            const printCount = this.printForm.打印数量
            const printDateFinal = printDate.getFullYear() + '' + ((printDate.getMonth() + 1) >= 10 ? (printDate.getMonth() + 1) : '0' + (printDate.getMonth() + 1)) + '' + (printDate.getDate() >= 10 ? printDate.getDate() : '0' + printDate.getDate())
            for (let i = 0; i < printCount; i++) {
              (function(t) { // 注意这里是形参
                setTimeout(function() {
                  const printCountFinal = (printStartNum + t).toString().padStart(8, '0')
                  const printFinal = printPartCode + '*' + printDateFinal + '*' + printCountFinal
                  scope.publication.topic = window.g.mqttPublishTopic
                  scope.publication.payload = `J07MA000~1~${printTemplate}|BarCode^Code0^${printFinal}|TEXT^TEXT0^${printFinal}`
                  const result = window.g.mqttClient.doPublish(scope.publication)
                  console.log(result, printFinal)
                  scope.submitAddPrintList(scope.printForm.订单号, scope.printForm.产品型号, scope.printForm.产品型号代码, scope.printForm.零件号, printFinal)
                }, 100 * t)
              })(i)
            }
          } else {
            this.$message.error('打印变速器条码失败!')
          }
        })
      })
    },
    // 判断起始号是否重复打印
    startKeyChange() {
      var param = []
      param[0] = ['起始号', this.printForm.起始号码]
      param[1] = ['机型', this.printForm.产品型号]
      var Data = this.CreateData('11', '生产计划_派工订单_打印记录_是否重复_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === 2) {
          this.$message.error(response.data[0].msg)
          this.isAllowAddClike = true
        } else {
          this.isAllowAddClike = false
        }
      })
    },
    // 提交新增订单
    submitAddPrintList(orderCode, engineType, engineTypeValue, partCode, engineId) {
      var param = []
      param[0] = ['订单号', orderCode]
      param[1] = ['零件号', partCode]
      param[2] = ['变速箱总成号', engineId]
      param[3] = ['机型代码', engineTypeValue]
      param[4] = ['机型', engineType]
      var Data = this.CreateData('12', '生产计划_派工订单_打印记录_增加', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          // this.$message({
          //   message: '订记录成功',
          //   type: 'success'
          // })
          this.printCountPlan++
          if (this.printCountPlan === Number(this.printForm.打印数量)) {
            this.$message({
              message: '全部条码打印完成',
              type: 'success'
            })
            // 关闭进度条 关闭打印窗口
            this.printCountPlanIsShow = false
            this.dialogFormVisible4 = false
          }
        } else {
          this.$message.error('记录失败！')
        }
      })
    },
    callOffPrint() {
      this.searchPrintListFinal()
      this.dialogFormVisible4 = false
    },
    searchPrintListFinal() {
      this.tableDataPrint = []
      const param = []
      param[0] = ['工单号', this.printForm.订单号]
      const Data = this.CreateData('11', '生产计划_派工订单_打印_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length !== 0) {
          this.tableDataPrint = response.data
        }
      })
    },
    // 取消新增订单
    callOff(formName) {
      this.dialogFormVisible = false
      this.$refs[formName].resetFields()
    },
    // 导入订单
    importOrder() {
      this.dialogFormVisible3 = true
    },
    // 删除订单
    deleteOrder(row) {
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var param = []
        param[0] = ['MID', row.MID]
        var Data = this.CreateData('12', '订单计划_删除', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message({
              message: '订单删除成功',
              type: 'success'
            })
            this.pageCurrent = 1
            this.pageSize = 15
            this.searchOrder()
          } else {
            this.$message.error('订单删除失败！')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 修改订单
    handleEdit(row) {
      if (this.$refs['form1'] !== undefined) {
        this.$refs['form1'].resetFields()
      }
      this.form1.planQuantity = row.计划数量
      this.form1.orderNumber = row.订单号
      this.form1.partCode = row.零件号
      this.form1.startPlanTime = row.计划开始时间
      this.form1.endPlanTime = row.计划完成时间
      this.form1.quantityCompletion = row.完成数量
      this.form1.engineTypeValue = row.产品型号
      this.form1.batchNo = row.批次号
      this.form1.deviceNo = row.设备号
      // this.form1.craftNo = row.工序号
      this.form1.personNo = row.加工人
      this.engineTypeValueChange()
      this.form1.rank = row.排序
      this.form1.MID = row.MID
      this.dialogFormVisible1 = true
    },
    // 提交修改订单
    submitAdd1() {
      this.$refs['form1'].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['计划开始时间', this.form1.startPlanTime]
          param[1] = ['计划完成时间', this.form1.endPlanTime]
          param[2] = ['计划数量', this.form1.planQuantity]
          param[3] = ['MID', this.form1.MID]
          param[4] = ['加工人', this.form1.personNo]
          param[5] = ['批次号', this.form1.batchNo]
          param[6] = ['设备号', this.form1.deviceNo]
          // param[7] = ['工序号', this.form1.craftNo]
          param[7] = ['工序号', this.form1.deviceNo]
          var Data = this.CreateData('12', '订单计划_修改', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message({
                message: '订单修改成功',
                type: 'success'
              })
              this.pageCurrent = 1
              this.pageSize = 15
              this.searchOrder()
            } else {
              this.$message.error('订单修改失败！')
            }
          })
          this.dialogFormVisible1 = false
        } else {
          return false
        }
      })
    },
    // 取消修改订单
    callOff1() {
      this.dialogFormVisible1 = false
      this.$refs['form1'].resetFields()
    },
    // 多选
    handleSelectionChange(val) {
      this.MIDGroup = []
      for (let i = 0; i < val.length; i++) {
        this.MIDGroup.push(val[i].MID)
      }
    },
    // 订单下发编辑
    ordersIssuedEditor(row) {
      this.$confirm(`确定下达订单<p style="color: deepskyblue;display: inline-block"> ${row.订单号}</p> 吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        dangerouslyUseHTMLString: true
      }).then(() => {
        var param = []
        param[0] = ['MID', row.MID]
        var Data = this.CreateData('12', 'MES_计划BOM_发动机订单计划_订单下发', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message({
              message: '订单下发成功！',
              type: 'success'
            })
            this.pageCurrent = 1
            this.pageSize = 15
            this.searchOrder()
          } else {
            this.$message.error('订单下发失败！')
          }
        })
      })
    },
    // 取消下发编辑
    ordersIssuedEditor1(row) {
      this.$confirm(`确定取消订单<p style="color: deepskyblue;display: inline-block"> ${row.订单号}</p> 吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        dangerouslyUseHTMLString: true
      }).then(() => {
        var param = []
        param[0] = ['MID', row.MID]
        var Data = this.CreateData('12', 'MES_计划BOM_发动机订单计划_订单下发取消', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message({
              message: '订单下发取消成功！',
              type: 'success'
            })
            this.pageCurrent = 1
            this.pageSize = 15
            this.searchOrder()
          } else {
            this.$message.error('订单下发取消失败！')
          }
        })
      })
    },
    handleAdd() {
      if (this.tableData.length === 0) {
        this.$message.error('内容为空')
      } else {
        var param = []
        var Data = this.CreateData('11', '确认导入物料字典_新增', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data.length > 0) {
            this.notes = ''
            for (var i = 0; i < response.data.length; i++) {
              this.notes = response.data[i].导入结果 + '、 ' + this.notes
            }
            this.$message({
              message: '物料字典信息更新成功',
              type: 'warning'
            })
            this.isShow = true
            this.tableData = []
          } else {
            this.tableData = []
            this.$message({
              message: '物料字典信息更新成功',
              type: 'success'
            })
          }
        })
      }
    },
    // 查询
    searchTable() {
      var param = []
      var Data = this.CreateData('11', '生产计划导入_确认导入前临时表_查询', param, this.pageSize, this.pageList)
      this.ExecDatabase(Data).then(response => {
        console.log(response.data)
        this.tableData = response.data.rows
        this.total = response.data.total
        this.loading = false
      })
    },
    // 表格颜色变化
    tableRowClassName({ row, rowIndex }) {
      // console.log(row, rowIndex)
      if (rowIndex % 2 === 0) {
        return 'black'
      } else {
        return 'red'
      }
    },
    async basicPartsToSQL() {
      try {
        this.loading = true
        this.err = 0
        for (let j = this.worksheet.length - 1; j >= 0; j--) {
          let sort,
            orderNumber,
            productModel,
            numberPlan,
            startDate,
            endDate
          var param = []
          param[0] = ['订单号', this.worksheet[j].B2.v]
          console.log('订单号', this.worksheet[j].B2.v)
          var Data = this.CreateData('11', 'MES_计划BOM_发动机订单计划_订单导入校验', param)
          const response = await this.ExecDatabase(Data)
          const res = response.data
          if (res[0].Column1 !== 0) {
            this.$notify.error(`${this.worksheet[j].C2.v}已经存在，请确认文件是否正确`)
            this.loading = false
            this.disabled = false
            return
          } else {
            for (let i = 0; i < 999; i++) {
              const attr = i + 2
              sort = this.worksheet[j][`A${attr}`] ? this.worksheet[j][`A${attr}`].v : ''
              orderNumber = this.worksheet[j][`B${attr}`] ? this.worksheet[j][`B${attr}`].v : ''
              productModel = this.worksheet[j][`C${attr}`] ? this.worksheet[j][`C${attr}`].v : ''
              numberPlan = this.worksheet[j][`D${attr}`] ? this.worksheet[j][`D${attr}`].v : ''
              startDate = this.worksheet[j][`E${attr}`] ? this.worksheet[j][`E${attr}`].v : ''
              endDate = this.worksheet[j][`F${attr}`] ? this.worksheet[j][`F${attr}`].v : ''
              console.log(sort, orderNumber, productModel, numberPlan, startDate, endDate)
              if (!sort && !orderNumber && !productModel && !numberPlan && !startDate && !endDate) {
                break
              } else if (!orderNumber) { // 名称不能为空
                this.$notify.error(`订单号不能为空`)
                break
              } else if (Number(numberPlan) <= 0) { // 数量不能为0
                this.$notify.error(`计划数量不能为空`)
                break
              } else {
                if (orderNumber) {
                  await sleep(50)
                  await this.insertToSQL(sort, orderNumber, productModel, numberPlan, startDate, endDate)
                } else {
                  this.loading = false
                  this.disabled = false
                  this.$notify.error(`请确认导入文件是否正确`)
                  return
                }
              }
            }
          }
          this.itemFile.splice(j, 1)
          this.worksheet.splice(j, 1)
          this.err === 0 ? this.$message.success(`导入完成`) : this.$message.error(`导入失败零件个数为${this.err}，请检查文件是否正确`)
        }
        this.loading = false
        this.searchOrder()
      } catch (e) {
        this.err++
        this.loading = false
        this.$notify.error(`导入数据错误,请检查导入文件是否正确`)
        console.log(`导入数据错误${e}`)
      }
    },
    async insertToSQL(sort, orderNumber, productModel, numberPlan, startDate, endDate) {
      console.log(startDate, endDate, 'startDate, endDate')
      try {
        var param = []
        param[0] = ['排序', sort]
        param[1] = ['订单号', orderNumber]
        param[2] = ['产品型号', productModel]
        param[3] = ['计划数量', numberPlan]
        param[4] = ['计划开始时间', startDate]
        param[5] = ['计划完成时间', endDate]
        param[6] = ['导入类型', '1', 'int', '1']
        var Data = this.CreateData('12', 'MES_计划BOM_发动机订单计划_订单导入', param)
        const response = await this.ExecDatabase(Data)
        const res = response.data
        if (res.hasOwnProperty('output') === false) {
          if (res[0].result === '0') {
            this.$notify.error(`${orderNumber}导入失败`)
          }
        } else {
          if (res.result[0].result === '0') {
            this.$notify.error(`${numberPlan}导入失败`)
          }
          if (res.output[0].导入类型 === '2') {
            this.$notify.warning(`${numberPlan}存在重复数据`)
          }
        }
      } catch (e) {
        this.err++
        this.$message.error(`导入数据错误`)
        console.log(`导入数据错误${e}`)
      }
    },
    exportExcel() {
      if (this.tableData.length !== 0) {
        this.startPlanTime ? this.startPlanTime_check = 1 : this.startPlanTime_check = 0
        this.endPlanTime ? this.endPlanTime_check = 1 : this.endPlanTime_check = 0
        this.orderNumberValue ? this.OrderNumber_check = 1 : this.OrderNumber_check = 0
        this.engineTypeValue ? this.engineType_check = 1 : this.engineType_check = 0
        if (this.startPlanTime === null) {
          this.startPlanTime = ''
        }
        if (this.endPlanTime === null) {
          this.endPlanTime = ''
        }
        var param = []
        param[0] = ['计划开始时间_check', this.startPlanTime_check]
        param[1] = ['计划开始时间', this.startPlanTime]
        param[2] = ['计划完成时间_check', this.endPlanTime_check]
        param[3] = ['计划完成时间', this.endPlanTime]
        param[4] = ['订单号_check', this.OrderNumber_check]
        param[5] = ['订单号', this.orderNumberValue]
        param[6] = ['产品型号_check', this.engineType_check]
        param[7] = ['产品型号', this.engineTypeValue]
        var Data = this.CreateData('2001', 'MES_计划BOM_发动机订单计划_订单导出', param)
        this.exportExcel_NPOI(Data)
      } else {
        this.$message.warning('暂无数据')
      }
    },
    // 分页
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.expands = []
      this.searchOrder()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.expands = []
      this.searchOrder()
    }
  }
}
</script>

<style scoped>
.topCard {
  margin: 5px;
}

.topDiv {
  margin-bottom: 10px;
}

.el-select {
  width: 200px
}

.el-input {
  width: 200px
}

.text {
  font-size: 14px;
}

.item {
  padding: 18px 0;
}

.box-card {
  position: absolute;
  right: 6px;
  top: 80px;
  width: 300px;
}

.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>

