<template>
  <div class="app-container" style="width: 100%;">
    <el-tabs type="border-card" @tab-click="tabClick" v-model="selectedWorkshop">

      <!--南车间-->
      <el-tab-pane label="南车间计划" name="南车间">
        <!--表格-->
        <el-table
          :data="tableData"
          ref="tableRef"
          :span-method="spanMethod2">
          <el-table-column prop="machineId" fixed label="机台号" header-align="center" align="center" width="111px" ></el-table-column>
          <el-table-column prop="productType" fixed label="产品类别" header-align="center" align="center" width="111.2px"></el-table-column>
          <el-table-column label="在机产品" header-align="center" >
            <el-table-column prop="productTypeName" fixed label="产品类型" header-align="center" align="center" width="111.2px"></el-table-column>
            <el-table-column prop="currentColorCode" label="色号" header-align="center" width="90px" align="center"></el-table-column>
            <el-table-column prop="currentSpecification" label="规格" header-align="center" width="90px" align="center"></el-table-column>
            <el-table-column prop="currentLotNumber" label="批号" header-align="center"  width="90px" align="center"></el-table-column>
            <el-table-column prop="currentSpindleCount" label="锭数" header-align="center" width="90px" align="center"></el-table-column>
            <el-table-column prop="startTime" label="上机时间" header-align="center" width="90px" align="center"></el-table-column>
            <el-table-column prop="plannedEndTime" label="下机时间" header-align="center" width="90px" align="center"></el-table-column>
          </el-table-column>
<!--          <el-table-column  label="待上机产品" header-align="center" align="center">-->
<!--            <el-table-column prop="djCurrentColorCode" label="色号" header-align="center" align="center"></el-table-column>-->
<!--            <el-table-column prop="djCurrentSpecification" label="规格" header-align="center" align="center"></el-table-column>-->
<!--            <el-table-column prop="djNumber" label="数量" header-align="center" align="center"></el-table-column>-->
<!--            <el-table-column prop="djCurrentLotNumber" label="原丝批号" header-align="center" align="center"></el-table-column>-->
<!--          </el-table-column>-->
          <el-table-column prop="listOfPendingProduction" label="待生产产品列表" header-align="center" align="center"  >
            <template slot-scope="scope">
              <div v-if="scope.row.listOfPendingProduction">
                <span v-for="(item, index) in scope.row.listOfPendingProduction.split(',')">
                  {{ item }},
                  <br v-if="(index + 1) % 5 === 0 && index !== scope.row.listOfPendingProduction.split(',').length - 1" />
                </span>
              </div>
            </template>
          </el-table-column>
          <el-table-column   fixed="right" label="操作" header-align="center" align="center" width="150px" >
            <template slot-scope="scope">
              <el-dropdown>
                <el-button type="primary">
                  操作
                  <i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item @click.native.prevent="handleAddPlan(scope.row)">新增计划</el-dropdown-item>
                  <el-dropdown-item @click.native.prevent="handleEditPlan(scope.row)">修改计划</el-dropdown-item>
                  <el-dropdown-item @click.native.prevent="handleStopProductionLine(scope.row)">机台状态</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>
        <!--新增计划弹窗-->
        <el-dialog title="南车间新增计划"  :visible.sync="nanInsertDialogTableVisible" width="1200px">
          <el-table :data="tableData2" @row-click.self="handleRowClick">
            <el-table-column prop="productId" label="产品" header-align="center" align="center" width="150px">
                <template v-slot:default="scope">
                     <el-select  v-model="scope.row.productId" placeholder="请选择待排产产品" @change="selectedChangeDate(scope.row,scope.row.productId)">
                           <el-option v-for="product in productsInfo" :key="product.id" :label="product.productName" :value="product.id" ></el-option>
                     </el-select>
                </template>
            </el-table-column>
            <el-table-column prop="currentColorCode" label="色号" header-align="center" align="center">
              <template v-slot:default="scope">
                <!-- 如果当前行正在编辑，则显示输入框 -->
                <el-input v-if="scope.row.isEditing"  disabled="disabled"  v-model="scope.row.currentColorCode" placeholder="请输入色号" @blur.stop.prevent="handleInputBlur(scope.row)" ></el-input>
                <!-- 否则显示普通文本 -->
                <span v-else>{{ scope.row.currentColorCode }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="currentSpecification" label="规格" header-align="center" align="center">
              <template v-slot:default="scope">
                <!-- 如果当前行正在编辑，则显示输入框 -->
                <el-input v-if="scope.row.isEditing" disabled="disabled" v-model="scope.row.currentSpecification" placeholder="请输入规格" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <!-- 否则显示普通文本 -->
                <span v-else>{{ scope.row.currentSpecification }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="productType" label="产品类别" header-align="center" align="center"  width="100px">
              <template v-slot:default="scope">
                <el-select  v-model="scope.row.productType" placeholder="请选择产品类别" >
                  <el-option v-for="product in productTypeList" :key="product.value" :label="product.lable" :value="product.value" ></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column prop="currentLotNumber" label="批号"  header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing"  :disabled="isDisabled" v-model="scope.row.currentLotNumber" placeholder="请输入批号" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.currentLotNumber }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="currentSpindleCount" label="锭数" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing" v-model="scope.row.currentSpindleCount" placeholder="请输入锭数" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.currentSpindleCount }}</span>
              </template>
            </el-table-column>

            <el-table-column prop="djNumber" label="数量" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing" v-model="scope.row.number" placeholder="请输入数量" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.number }}</span>
              </template>
            </el-table-column>

            <el-table-column prop="startTime" label="上机时间" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing" v-model="scope.row.startTime" placeholder="请输入上机时间" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.startTime }}</span>
              </template>
            </el-table-column>

            <el-table-column prop="plannedEndTime" label="计划下机时间" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing" :ref="'input'+scope.$index" v-model="scope.row.plannedEndTime" placeholder="请输入计划下机时间" @blur="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.plannedEndTime }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="planStatus" label="计划状态" header-align="center" align="center" width="100px">
              <template v-slot:default="scope">
                <el-select  v-model="scope.row.planStatus" placeholder="计划状态">
                  <el-option v-for="stateItem in stateList0" :key="stateItem.id" :label="stateItem.name" :value="stateItem.id" ></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="danger"
                  @click.stop.prevent="handleDelete(scope.$index, scope.row)">删除</el-button>
              </template>
            </el-table-column>

          </el-table>
          <el-button type="primary" style="width: 100%;margin-top: 30px"  @click="addEditableRow">新增计划产品</el-button>
          <span slot="footer" class="dialog-footer">
            <el-button @click="nanInsertDialogTableVisible = false">取 消</el-button>
            <el-button type="primary" @click="addPlanInfo">确 定</el-button>
           </span>
        </el-dialog>
        <!--修改计划弹窗-->
        <el-dialog title="修改计划"  :visible.sync="nanUpdateDialogTableVisible" width="1400px">
          <!--查询条件-->
          <el-form ref="form"  :model="formData" label-width="80px" :inline="true">
             <el-form-item label="产品类别:">
                <el-select v-model="formData.productType" placeholder="请选择产品类别">
                  <el-option v-for="product in productTypeList" :key="product.value" :label="product.lable" :value="product.value" ></el-option>
                </el-select>
             </el-form-item>
              <el-form-item label="计划状态:">
                <el-select v-model="formData.planStatus" placeholder="请选择计划状态">
                  <el-option v-for="stateListItem in stateList2" :key="product.id" :label="stateListItem.name" :value="stateListItem.id" ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
                <el-button @click="reset">重置</el-button>
              </el-form-item>
          </el-form>
          <!--表格-->
          <el-table :data="tableData2" @row-click.self="handleRowClick">
            <el-table-column prop="productId" label="产品" header-align="center" align="center" width="150px">
              <template slot-scope="scope">
                {{ getProductChineseName(scope.row.productId) }}
              </template>
            </el-table-column>
            <el-table-column prop="currentColorCode" label="色号" header-align="center" align="center">
              <template v-slot:default="scope">
                <!-- 如果当前行正在编辑，则显示输入框 -->
                <el-input v-if="scope.row.isEditing"   disabled="disabled"  v-model="scope.row.currentColorCode" placeholder="请输入色号" @blur.stop.prevent="handleInputBlur(scope.row)" ></el-input>
                <!-- 否则显示普通文本 -->
                <span v-else>{{ scope.row.currentColorCode }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="currentSpecification" label="规格" header-align="center" align="center">
              <template v-slot:default="scope">
                <!-- 如果当前行正在编辑，则显示输入框 -->
                <el-input v-if="scope.row.isEditing" disabled="disabled" v-model="scope.row.currentSpecification" placeholder="请输入规格" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <!-- 否则显示普通文本 -->
                <span v-else>{{ scope.row.currentSpecification }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="productType" label="产品类别" header-align="center" align="center"  width="100px">
              <template v-slot:default="scope">
                <el-select  v-model="scope.row.productType" placeholder="请选择产品类别" >
                  <el-option v-for="product in productTypeList" :key="product.value" :label="product.lable" :value="product.value" ></el-option>
                </el-select>
              </template>
            </el-table-column>

            <el-table-column prop="currentLotNumber" label="批号" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing"  disabled="disabled" v-model="scope.row.currentLotNumber" placeholder="请输入批号" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.currentLotNumber }}</span>
              </template>
            </el-table-column>

            <el-table-column prop="currentSpindleCount" label="锭数" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing" v-model="scope.row.currentSpindleCount" placeholder="请输入锭数" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.currentSpindleCount }}</span>
              </template>
            </el-table-column>

            <el-table-column prop="number" label="数量" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing" v-model="scope.row.number" placeholder="请输入数量" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.number }}</span>
              </template>
            </el-table-column>

            <el-table-column prop="startTime" label="上机时间" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing" v-model="scope.row.startTime" placeholder="请输入上机时间" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.startTime }}</span>
              </template>
            </el-table-column>

            <el-table-column prop="plannedEndTime" label="计划下机时间" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing" :ref="'input'+scope.$index" v-model="scope.row.plannedEndTime" placeholder="请输入计划下机时间" @blur="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.plannedEndTime }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="planStatus" label="计划状态" header-align="center" align="center" width="100px">
              <template v-slot:default="scope">
                <!--上机变停机待机-->
                <el-select v-if="scope.row.planStatus==1" v-model="scope.row.planStatus" placeholder="计划状态">
                  <el-option v-for="stateItem in stateList1" :key="stateItem.id" :label="stateItem.name" :value="stateItem.id" ></el-option>
                </el-select>
                <!--待机可以上机-->
                <el-select v-if="scope.row.planStatus==0" v-model="scope.row.planStatus" placeholder="计划状态" >
                  <el-option v-for="stateItem in stateList0" :key="stateItem.id" :label="stateItem.name" :value="stateItem.id" ></el-option>
                </el-select>
                <!--停机变上机-->
                <el-select v-if="scope.row.planStatus==2" v-model="scope.row.planStatus" placeholder="计划状态" >
                  <el-option v-for="stateItem in stateList2" :key="stateItem.id" :label="stateItem.name" :value="stateItem.id" ></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="操作"   align="center" width="200px">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="danger"
                  @click.stop.prevent="updateStatus(scope.$index, scope.row)">更新状态</el-button>
                <el-button
                  size="mini"
                  type="danger"
                  @click.stop.prevent="deletePlan(scope.$index, scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <!--操作按钮-->
          <span slot="footer" class="dialog-footer">
            <el-button @click="nanUpdateDialogTableVisible = false">取 消</el-button>
            <el-button type="primary" @click="nanUpdateDialogTableVisible = false">确 定</el-button>
           </span>
        </el-dialog>
      </el-tab-pane>
      <!--北车间-->
      <el-tab-pane label="北车间计划" name="北车间">
        <!--表格-->
        <el-table
          :data="tableData"
          ref="tableRef"
          :span-method="spanMethod2">
          <el-table-column prop="machineId" fixed label="机台号" header-align="center" align="center" width="111px" ></el-table-column>
          <el-table-column prop="productType" fixed label="产品类别" header-align="center" align="center" width="111.2px"></el-table-column>
          <el-table-column label="在机产品" header-align="center" >
            <el-table-column prop="productTypeName" fixed label="产品类型" header-align="center" align="center" width="111.2px"></el-table-column>
            <el-table-column prop="currentColorCode" label="色号" header-align="center" width="90px" align="center"></el-table-column>
            <el-table-column prop="currentSpecification" label="规格" header-align="center" width="90px" align="center"></el-table-column>
            <el-table-column prop="currentLotNumber" label="批号" header-align="center"  width="90px" align="center"></el-table-column>
            <el-table-column prop="currentSpindleCount" label="锭数" header-align="center" width="90px" align="center"></el-table-column>
            <el-table-column prop="startTime" label="上机时间" header-align="center" width="90px" align="center"></el-table-column>
            <el-table-column prop="plannedEndTime" label="下机时间" header-align="center" width="90px" align="center"></el-table-column>
          </el-table-column>
          <!--          <el-table-column  label="待上机产品" header-align="center" align="center">-->
          <!--            <el-table-column prop="djCurrentColorCode" label="色号" header-align="center" align="center"></el-table-column>-->
          <!--            <el-table-column prop="djCurrentSpecification" label="规格" header-align="center" align="center"></el-table-column>-->
          <!--            <el-table-column prop="djNumber" label="数量" header-align="center" align="center"></el-table-column>-->
          <!--            <el-table-column prop="djCurrentLotNumber" label="原丝批号" header-align="center" align="center"></el-table-column>-->
          <!--          </el-table-column>-->
          <el-table-column prop="listOfPendingProduction" label="待生产产品列表" header-align="center" align="center"  >
            <template slot-scope="scope">
              <div v-if="scope.row.listOfPendingProduction">
                <div v-for="(item, index) in scope.row.listOfPendingProduction.split(',')">
                  {{ item }}
                  <span v-if="(index + 1) % 5 === 0 && index !== scope.row.listOfPendingProduction.split(',').length - 1">,</span>
                  <br v-if="(index + 1) % 5 === 0 && index !== scope.row.listOfPendingProduction.split(',').length - 1" />
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column   fixed="right" label="操作" header-align="center" align="center" width="150px" >
            <template slot-scope="scope">
              <el-dropdown>
                <el-button type="primary">
                  操作
                  <i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item @click.native.prevent="handleAddPlan(scope.row)">新增计划</el-dropdown-item>
                  <el-dropdown-item @click.native.prevent="handleEditPlan(scope.row)">修改计划</el-dropdown-item>
                  <el-dropdown-item @click.native.prevent="handleStopProductionLine(scope.row)">机台状态</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>
        <!--新增计划弹窗-->
        <el-dialog title="北车间新增计划"  :visible.sync="beiInsertDialogTableVisible" width="1200px">
          <el-table :data="tableData2" @row-click.self="handleRowClick">
<!--            <el-table-column prop="salesmanId" label="业务员" header-align="center" align="center" width="100px">-->
<!--              <template v-slot:default="scope">-->
<!--                <el-select  v-model="scope.row.salesmanId" placeholder="请选择业务员" @change="selectedSalesmanItem(scope.row,scope.row.salesmanId)">-->
<!--                  <el-option v-for="salesmanItem in salesmanInfo" :key="salesmanItem.saleNo" :label="salesmanItem.salesman" :value="salesmanItem.saleNo" ></el-option>-->
<!--                </el-select>-->
<!--              </template>-->
<!--            </el-table-column>-->
            <el-table-column prop="productId" label="产品" header-align="center" align="center" width="150px">
              <template v-slot:default="scope">
                <el-select  v-model="scope.row.productId" placeholder="请选择待排产产品" @change="selectedChangeDate(scope.row,scope.row.productId)">
                  <el-option v-for="product in productsInfo" :key="product.id" :label="product.productName" :value="product.id" ></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column prop="currentColorCode" label="色号" header-align="center" align="center">
              <template v-slot:default="scope">
                <!-- 如果当前行正在编辑，则显示输入框 -->
                <el-input v-if="scope.row.isEditing"  disabled="disabled"  v-model="scope.row.currentColorCode" placeholder="请输入色号" @blur.stop.prevent="handleInputBlur(scope.row)" ></el-input>
                <!-- 否则显示普通文本 -->
                <span v-else>{{ scope.row.currentColorCode }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="currentSpecification" label="规格" header-align="center" align="center">
              <template v-slot:default="scope">
                <!-- 如果当前行正在编辑，则显示输入框 -->
                <el-input v-if="scope.row.isEditing" disabled="disabled" v-model="scope.row.currentSpecification" placeholder="请输入规格" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <!-- 否则显示普通文本 -->
                <span v-else>{{ scope.row.currentSpecification }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="productType" label="产品类别" header-align="center" align="center"  width="100px">
              <template v-slot:default="scope">
                <el-select  v-model="scope.row.productType" placeholder="请选择产品类别" >
                  <el-option v-for="product in productTypeList" :key="product.value" :label="product.lable" :value="product.value" ></el-option>
                </el-select>
              </template>
            </el-table-column>

            <el-table-column prop="currentLotNumber" label="批号" header-align="center" align="center">
              <template v-slot:default="scope">

                <el-input v-if="scope.row.isEditing" :disabled="isDisabled"  v-model="scope.row.currentLotNumber" placeholder="请输入批号" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.currentLotNumber }}</span>
              </template>
            </el-table-column>

            <el-table-column prop="currentSpindleCount" label="锭数" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing" v-model="scope.row.currentSpindleCount" placeholder="请输入锭数" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.currentSpindleCount }}</span>
              </template>
            </el-table-column>

            <el-table-column prop="number" label="数量" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing" v-model="scope.row.number" placeholder="请输入数量" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.number }}</span>
              </template>
            </el-table-column>

            <el-table-column prop="startTime" label="上机时间" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing" v-model="scope.row.startTime" placeholder="请输入上机时间" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.startTime }}</span>
              </template>
            </el-table-column>

            <el-table-column prop="plannedEndTime" label="计划下机时间" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing" :ref="'input'+scope.$index" v-model="scope.row.plannedEndTime" placeholder="请输入计划下机时间" @blur="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.plannedEndTime }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="planStatus" label="计划状态" header-align="center" align="center" width="100px">
              <template v-slot:default="scope">
                <el-select  v-model="scope.row.planStatus" placeholder="计划状态" >
                  <el-option v-for="stateItem in stateList0" :key="stateItem.id" :label="stateItem.name" :value="stateItem.id" ></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="操作" >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="danger"
                  @click.stop.prevent="handleDelete(scope.$index, scope.row)">删除</el-button>
              </template>
            </el-table-column>

          </el-table>
          <el-button type="primary" style="width: 100%;margin-top: 30px"  @click="addEditableRow">新增计划产品</el-button>
          <span slot="footer" class="dialog-footer">
            <el-button @click="beiInsertDialogTableVisible = false">取 消</el-button>
            <el-button type="primary" @click="addPlanInfo">确 定</el-button>
           </span>
        </el-dialog>
        <!--修改计划弹窗-->
        <el-dialog title="北车间修改计划"  :visible.sync="beiUpdateDialogTableVisible" width="1200px">
          <!--查询条件-->
          <el-form ref="form"  :model="formData" label-width="80px" :inline="true">
            <el-form-item label="产品类别:">
              <el-select v-model="formData.productType" placeholder="请选择产品类别">
                <el-option v-for="product in productTypeList" :key="product.value" :label="product.lable" :value="product.value" ></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="计划状态:">
              <el-select v-model="formData.planStatus" placeholder="请选择计划状态">
                <el-option v-for="stateListItem in stateList2" :key="product.id" :label="stateListItem.name" :value="stateListItem.id" ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="onSubmit">查询</el-button>
              <el-button @click="reset">重置</el-button>
            </el-form-item>
          </el-form>
          <!--表格-->
          <el-table :data="tableData2" @row-click.self="handleRowClick">
            <el-table-column prop="productId" label="产品" header-align="center" align="center" width="150px">
              <template slot-scope="scope">
                {{ getProductChineseName(scope.row.productId) }}
              </template>
            </el-table-column>
            <el-table-column prop="currentColorCode" label="色号" header-align="center" align="center">
              <template v-slot:default="scope">
                <!-- 如果当前行正在编辑，则显示输入框 -->
                <el-input v-if="scope.row.isEditing"  disabled="disabled"  v-model="scope.row.currentColorCode" placeholder="请输入色号" @blur.stop.prevent="handleInputBlur(scope.row)" ></el-input>
                <!-- 否则显示普通文本 -->
                <span v-else>{{ scope.row.currentColorCode }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="currentSpecification" label="规格" header-align="center" align="center">
              <template v-slot:default="scope">
                <!-- 如果当前行正在编辑，则显示输入框 -->
                <el-input v-if="scope.row.isEditing" disabled="disabled" v-model="scope.row.currentSpecification" placeholder="请输入规格" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <!-- 否则显示普通文本 -->
                <span v-else>{{ scope.row.currentSpecification }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="productType" label="产品类别" header-align="center" align="center"  width="100px">
              <template v-slot:default="scope">
                <el-select  v-model="scope.row.productType" placeholder="请选择产品类别">
                  <el-option v-for="product in productTypeList" :key="product.value" :label="product.lable" :value="product.value" ></el-option>
                </el-select>
              </template>
            </el-table-column>

            <el-table-column prop="currentLotNumber" label="批号" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing"  disabled="disabled" v-model="scope.row.currentLotNumber" placeholder="请输入批号" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.currentLotNumber }}</span>
              </template>
            </el-table-column>

            <el-table-column prop="currentSpindleCount" label="锭数" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing"  v-model="scope.row.currentSpindleCount" placeholder="请输入锭数" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.currentSpindleCount }}</span>
              </template>
            </el-table-column>

            <el-table-column prop="number" label="数量" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing" v-model="scope.row.number" placeholder="请输入数量" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.number }}</span>
              </template>
            </el-table-column>

            <el-table-column prop="startTime" label="上机时间" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing" v-model="scope.row.startTime" placeholder="请输入上机时间" @blur.stop.prevent="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.startTime }}</span>
              </template>
            </el-table-column>

            <el-table-column prop="plannedEndTime" label="计划下机时间" header-align="center" align="center">
              <template v-slot:default="scope">
                <el-input v-if="scope.row.isEditing" :ref="'input'+scope.$index" v-model="scope.row.plannedEndTime" placeholder="请输入计划下机时间" @blur="handleInputBlur(scope.row)">></el-input>
                <span v-else>{{ scope.row.plannedEndTime }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="planStatus" label="计划状态" header-align="center" align="center" width="100px">
              <template v-slot:default="scope">
                <!--上机变停机待机-->
                <el-select v-if="scope.row.planStatus==1" v-model="scope.row.planStatus" placeholder="计划状态" >
                  <el-option v-for="stateItem in stateList1" :key="stateItem.id" :label="stateItem.name" :value="stateItem.id" ></el-option>
                </el-select>
                <!--待机可以上机-->
                <el-select v-if="scope.row.planStatus==0" v-model="scope.row.planStatus" placeholder="计划状态" >
                  <el-option v-for="stateItem in stateList0" :key="stateItem.id" :label="stateItem.name" :value="stateItem.id" ></el-option>
                </el-select>
                <!--停机变上机-->
                <el-select v-if="scope.row.planStatus==2" v-model="scope.row.planStatus" placeholder="计划状态" >
                  <el-option v-for="stateItem in stateList2" :key="stateItem.id" :label="stateItem.name" :value="stateItem.id" ></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="操作"  align="center" width="200px">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="danger"
                  @click.stop.prevent="updateStatus(scope.$index, scope.row)">更新状态</el-button>
                <el-button
                  size="mini"
                  type="danger"
                  @click.stop.prevent="deletePlan(scope.$index, scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <span slot="footer" class="dialog-footer">
            <el-button @click="beiUpdateDialogTableVisible = false">取 消</el-button>
            <el-button type="primary" @click="beiUpdateDialogTableVisible = false">确 定</el-button>
           </span>
        </el-dialog>
      </el-tab-pane>
      <!--停机弹窗-->
      <el-dialog title="修改机台状态"  :visible.sync="modifyMachineStatus" width="500px">
                  <el-form :model="modifyMachineStatusFrom"  ref="modifyMachineStatusFrom" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="机台状态" prop="type">
                      <el-checkbox-group v-model="modifyMachineStatusFrom.type">
                        <el-checkbox label="1" name="type">A面停机</el-checkbox>
                        <el-checkbox label="2" name="type">B面停机</el-checkbox>
                      </el-checkbox-group>
                    </el-form-item>
                    <el-form-item>
                      <el-button type="primary" @click="confirmStopProductionLine">确定</el-button>
                      <el-button>取消</el-button>
                    </el-form-item>
                  </el-form>
      </el-dialog>
    </el-tabs>

  </div>
</template>
<script>
import {
  ammunitionPlanInfo,
  getProductsInfo,
  removeBombLoadingPlan,
  getMaterielInfo,
  addMaterielInfo,
  getProductsAll,
  getAllPlanListByMachineId,
  getAllPlanListByProductTypeAndStatus,
  updatePlanOne,
  whetherTheFeederIsShutDown,
  updateLineStates,
  getIsTheOrderProductProduced, getJtIsTheOrderProductProduced
} from "@/api/plan/paln.js";
export default {
  data() {
    return {
      modifyMachineStatusFrom:{
        type: [],
      },
      modifyMachineStatus:false,
      //选中的是那个车间
      selectedWorkshop:"南车间",
      tableData:[],
      isDisabled:true,
      form: {
        product:"",
      },
      previousMachineId: undefined,
      currentRowspan: 1,
      prevRow: {},
      tableData2: [],
      nanInsertDialogTableVisible:false,
      nanUpdateDialogTableVisible:false,
      beiInsertDialogTableVisible:false,
      beiUpdateDialogTableVisible:false,
      editingRowIndex: -1,
      lastEditLine:0,
      queryParams:{ productionLineDepartment:"加弹部",
                    productionLineWorkshop:"南车间"},
      isEditLine:false,
      productsInfo:[],
      salesmanInfo:[],
      product:{},
      materiel:{},
      // 机台号
      machineId:"",
      macId:"",//机台id
      // 待机/上机/停产
      stateList0:[
        {"id":0,"name":"待机"},
        {"id":1,"name":"上机"},
      ],
      stateList1:[
        {"id":0,"name":"待机"},
        {"id":2,"name":"停机"},
        {"id":1,"name":"上机"},
      ],
      stateList2:[
        {"id":0,"name":"待机"},
        {"id":2,"name":"停机"},
        {"id":1,"name":"上机"},
      ],
      formData:{
        updateSelectedProductCategory:"",
        updateSelectedProductState:""
      },
      // 产品类别
      productTypeList:[{value:"A面",lable:"A面"},{value:"B面",lable:"B面"}],
    }
  },
  mounted() {
    // 得到排产计划信息
    this.getAmmunitionPlanInfo();
  },
  methods: {
    getProductChineseName(productId) {
      return  this.productsInfo.find(product => product.id == productId).productName;
    },
    //删除计划
    deletePlan($index,row){
      console.log(row)
      //判断当前计划是否已经投产
      getJtIsTheOrderProductProduced({"id":row.id}).then(resp=>{
          if(resp.data.length>0){
            this.$message({message: '当前计划订单产品在生产中已经不能删除', type: 'warning'});
            return;//证明有在上级的产品--zhi能有一个上级产品
          }
          removeBombLoadingPlan(row.id).then(res=>{
              if(res.code==200){
                this.$message({
                  message: '删除成功',
                  type: 'success'
                });
              }else{
                this.$message({message:"删除失败",type: 'error'})
              }
              this.onSubmit();
              this.getAmmunitionPlanInfo();
          })
      });


    },
    //打开修改机台信息
    handleStopProductionLine(row){
      this.modifyMachineStatus=true;
      this.machineId=row.machineId;
      this.macId=row.macId;//机台id
      //查询当前机台A、面B面的状态
      whetherTheFeederIsShutDown(this.macId).then(res=>{
        this.modifyMachineStatusFrom.type=res.data;
      })
    },
    //确认修改产线信息
    confirmStopProductionLine(){
      // console.log(this.modifyMachineStatusFrom.type);
      if(this.modifyMachineStatusFrom.type.length==0){
        this.modifyMachineStatusFrom.type.push("3")
      }
      //更改状态
      updateLineStates(this.macId,this.modifyMachineStatusFrom.type.join(",")).then(res=>{
        if(res.code==200){
          this.$message({
            message: '修改状态成功',
            type: 'success'
          });
        }else{
          this.$message({message:"修改状态成功",type: 'error'})
        }
        this.modifyMachineStatus=false;
        this.getAmmunitionPlanInfo();
      })
      // //如果为空代表都不停机
      // if(this.modifyMachineStatusFrom.type.length<=0){
      //   this.modifyMachineStatus=false;
      //   //发送请求删除,A面-timestampRandomCode="停机" B-timestampRandomCode="停机"的数据、并把所有上机产品的状态改为上机
      //   return;
      // }
      // // 包含1A停机---插入一条 timestampRandomCode=停机,状态为停机的数据
      // if (this.modifyMachineStatusFrom.type.includes("1")) {
      //     //查询当前机台A、面B面的状态
      //     whetherTheFeederIsShutDown(this.machineId).then(res=>{
      //      //后台没有虚拟的假数据，就插入
      //      if(!res.data.includes("1")){
      //        console.log('数组中不包含数字 1');
      //        //新增一条数据,
      //        let aStopInfo=   {
      //          currentColorCode: '1',
      //          //产品规格
      //          currentSpecification: '1',
      //          currentLotNumber: '1',
      //          currentSpindleCount: '1',
      //          number: '1',
      //          productType:'A面',
      //          startTime: '1',
      //          plannedEndTime:'1',
      //          planStatus:2,
      //          productId:'1',
      //          machineId:this.machineId,
      //          salesmanId:'1',
      //          timestampRandomCode:"停机",
      //        }
      //        let aStoptableList=[];
      //        aStoptableList.push(aStopInfo)
      //        //时间戳
      //        let data={
      //          //机台号
      //          machineId: this.machineId,
      //          //计划信息
      //          detailsOfTheRefuelingPlans: aStoptableList
      //        }
      //        //添加计划信息
      //        addMaterielInfo(data).then(response => {
      //          if (response.code == 200) {
      //            this.$message({
      //              message: '停机成功',
      //              type: 'success'
      //            });
      //            this.getAmmunitionPlanInfo();
      //            //最后把弹窗关掉
      //            this.nanInsertDialogTableVisible=false
      //            //更改订单投产信息的批号,
      //          } else {
      //            this.$message({
      //              message: '停机失败,请联系管理员',
      //              type: 'error'
      //            });
      //            //最后把弹窗关掉
      //            this.nanInsertDialogTableVisible=false
      //          }
      //        });
      //      }
      //     })
      // }
      // if(this.modifyMachineStatusFrom.type.includes("2")) {
      //   whetherTheFeederIsShutDown(this.machineId).then(res=>{
      //     if(!res.data.includes("2")) {
      //       console.log('数组中不包含数字2');
      //       //新增一条数据,
      //       let aStopInfo= {
      //         currentColorCode: '1',
      //         //产品规格
      //         currentSpecification: '1',
      //         currentLotNumber: '1',
      //         currentSpindleCount: '1',
      //         number: '1',
      //         productType:'B面',
      //         startTime: '1',
      //         plannedEndTime:'1',
      //         planStatus:2,
      //         productId:'1',
      //         machineId:this.machineId,
      //         salesmanId:'1',
      //         timestampRandomCode:"停机",
      //       }
      //       let aStoptableList=[];
      //       aStoptableList.push(aStopInfo)
      //       //时间戳
      //       let data={
      //         //机台号
      //         machineId: this.machineId,
      //         //计划信息
      //         detailsOfTheRefuelingPlans: aStoptableList
      //       }
      //       //添加计划信息
      //       addMaterielInfo(data).then(response => {
      //         if (response.code == 200) {
      //           this.$message({
      //             message: '停机成功',
      //             type: 'success'
      //           });
      //           this.getAmmunitionPlanInfo();
      //           //最后把弹窗关掉
      //           this.nanInsertDialogTableVisible=false
      //           //更改订单投产信息的批号,
      //         } else {
      //           this.$message({
      //             message: '停机失败,请联系管理员',
      //             type: 'error'
      //           });
      //           //最后把弹窗关掉
      //           this.nanInsertDialogTableVisible=false
      //         }
      //       });
      //     }
      //   })
      // }
    },
    // 查询排产信息
    getAmmunitionPlanInfo() {
      ammunitionPlanInfo(this.queryParams).then((response) => {
        this.tableData = response.data
      });
    },
    // 合并单元格
    spanMethod2({ row, column, rowIndex, columnIndex }) {
      //第二列合并
      if (columnIndex === 1) {
        if(row.productType == null) {
          return;
        }
        const prevRow2 = this.tableData[rowIndex - 1]; // 上一行数据
        let nextRow2 = this.tableData[rowIndex + 1]; // 下一行数据

        // 当上一行的数据（machineId和productType）等于当前行数据时，当前行单元格隐藏
        if (
          prevRow2 &&
          prevRow2.machineId === row.machineId &&
          prevRow2.productType === row.productType
        ) {
          return { rowspan: 0, colspan: 0 };
        } else {
          // 反之，则循环判断若下一行数据（machineId和productType）等于当前行数据，则当前行开始进行合并单元格
          let countRowspan2 = 1; // 用于合并计数多少单元格
          while (
            nextRow2 &&
            nextRow2.machineId === row.machineId &&
            nextRow2.productType === row.productType
            ) {
            nextRow2 = this.tableData[++countRowspan2 + rowIndex];
          }
          if (countRowspan2 > 1) {
            return { rowspan: countRowspan2, colspan: 1 };
          }
        }
      }
      //待生产列表
      if (columnIndex === 9) {
        const prevRow2 = this.tableData[rowIndex - 1] //上一行数据
        let nextRow2 = this.tableData[rowIndex + 1] //下一行数据
        // 当上一行的数据等于当前行数据时，当前行单元格隐藏

        if(row.listOfPendingProduction==null||row.listOfPendingProduction==undefined|| row.listOfPendingProduction==""){
          return;
        }
        if (prevRow2 &&
          prevRow2.machineId === row.machineId &&
          prevRow2.productType === row.productType
        ) {
          return { rowspan: 0, colspan: 0 }
        } else {
          // 反之，则循环判断若下一行数据等于当前行数据，则当前行开始进行合并单元格
          let countRowspan2 = 1 //用于合并计数多少单元格
          while (nextRow2 &&
                 nextRow2.listOfPendingProduction === row.listOfPendingProduction&&
                  nextRow2.machineId === row.machineId &&
                  nextRow2.productType === row.productType
            ) {
            nextRow2 = this.tableData[++countRowspan2 + rowIndex]
          }
          if (countRowspan2 > 1) {
            return { rowspan: countRowspan2, colspan: 1 }
          }
        }
      }
      //合并最后一列操作列
      const lastColumnIndex = this.$refs.tableRef.store.states.columns.length - 1; // 获取表格最后一列的索引
      if (columnIndex === lastColumnIndex && column.label === '操作') { // 判断是否为最后一列且标签为'操作'
        const machineIdColumnIndex = 0; // 机台号列的索引假定为0
        const currentMachineId = row.machineId;

        let countRowspan = 1;
        const prevRow = this.tableData[rowIndex - 1];

        if (prevRow && prevRow.machineId === currentMachineId) {
          return { rowspan: 0, colspan: 0 };
        } else {
          let nextRow = this.tableData[rowIndex + 1];

          while (
            nextRow &&
            nextRow.machineId === currentMachineId
            ) {
            nextRow = this.tableData[++countRowspan + rowIndex];
          }

          if (countRowspan > 1) {
            return { rowspan: countRowspan, colspan: 1 };
          }
        }
      }
      //第一列机台号合并
      if (columnIndex === 0) {
        //定义需要合并的列字段，有哪些列需要合并，就自定义添加字段即可
        const fields = ['machineId']
        // 当前行的数据
        const cellValue = row[column.property]
        let countRowspan = 1 //用于合并计数多少单元格
        // 判断只合并定义字段的列数据
        if (cellValue && fields.includes(column.property)) {
          const prevRow = this.tableData[rowIndex - 1] //上一行数据
          let nextRow = this.tableData[rowIndex + 1] //下一行数据
          // 当上一行的数据等于当前行数据时，当前行单元格隐藏
          if (prevRow && prevRow[column.property] === cellValue) {
            return { rowspan: 0, colspan: 0 }
          } else {
            // 反之，则循环判断若下一行数据等于当前行数据，则当前行开始进行合并单元格
            let countRowspan = 1 //用于合并计数多少单元格
            while (nextRow && nextRow[column.property] === cellValue) {
              nextRow = this.tableData[++countRowspan + rowIndex]
            }
            if (countRowspan > 1) {
              return { rowspan: countRowspan, colspan: 1 }
            }
          }
        }
      }
    },
    getProductsInfo() {
      getProductsInfo("JT-").then((response) => {
        this.productsInfo = response.data;
        this.productsInfo.forEach(item => {
          item.productName = item.productName+"—"+item.materieEncoding+item.materieColorNumber
        });
      })
    },
    // 下拉框数据改变查询色号批号信息
    selectedChangeDate(row,selectedProduct) {
      //选择的那个销售产品
      this.product = this.productsInfo.find(product => product.id === selectedProduct);
      this.form.product=selectedProduct;
      //通过母粒编码查询到对应的母粒信息
      let queryParams = {
        "materielCode": this.product.colourNumber
      }
      //得到对应的母粒信息
      getMaterielInfo(queryParams).then((response) => {
        if (response.data!=null) {
          this.materiel = response.data;
          //色号 母粒编码+色号
          row.currentColorCode = this.materiel.materieEncoding+"("+this.materiel.materieColorNumber+")";
        }
      });
      //isDisabled(有批号就用，没批号就自己输入)
      if(this.product.lotNumber!=undefined&&this.product.lotNumber!=""){
        row.currentLotNumber=this.product.lotNumber;
        this.isDisabled=true;
      }else {
        this.isDisabled=false;
        row.currentLotNumber="";
      }
      //产品规格
      row.currentSpecification= this.product.productSpecifications;
      //销售单编号（以前打算存的是业务员信息后来存的是销售单编号）
      row.salesmanId=this.product.saleOrderNo;
      //数量
      row.number=this.product.productNumber;
      // console.log(this.product,'ddddddddddddddd')
    },
    // 新增计划产品信息
    handleAddPlan(row) {
      //查询当前机台A、面B面的状态(这个不用改,因为这个是唯一的)
      whetherTheFeederIsShutDown(row.macId).then(res=>{
        this.modifyMachineStatusFrom.type=res.data;
        if(this.modifyMachineStatusFrom.type.includes("2")&&this.modifyMachineStatusFrom.type.includes("1")){
          this.$message({
            message: 'AB都已停机请更改机台状态',
            type: 'warning'
          });
          return;
        }else {
          if(this.modifyMachineStatusFrom.type.includes("1")){
            this.productTypeList=[]
            this.productTypeList.push({value:"B面",lable:"B面"})
          }
          if(this.modifyMachineStatusFrom.type.includes("2")){
            this.productTypeList=[]
            this.productTypeList.push({value:"A面",lable:"A面"})
          }
          if(this.modifyMachineStatusFrom.type.length<=0){
            this.productTypeList=[]
            this.productTypeList.push({value:"A面",lable:"A面"})
            this.productTypeList.push({value:"B面",lable:"B面"})
          }
          //否则就打开弹窗添加计划
          if(this.selectedWorkshop=="南车间"){
            this.nanInsertDialogTableVisible = true
          }else{
            this.beiInsertDialogTableVisible = true
          }
          //查询可以添加的产品信息
          this.getProductsInfo();
          //清空添加的数组对象
          this.tableData2=[]
          //先清空
          this.machineId=""
          //当前操作机台号
          this.machineId=row.machineId;
          this.macId=row.macId;
        }
      })
    },
    // tab栏点击切换
    tabClick(tab, event) {
      // console.log('当前点击的标签名称：', tab.name);
      this.selectedWorkshop = tab.name;
      // productionLineName getProductionLineNo productionLineDepartment productionLineWorkshop
      this.queryParams.productionLineWorkshop = tab.name;
      this.getAmmunitionPlanInfo();
    },
    // 删除行
    handleDelete(index, row) {
      // console.log(index,row)
      // this.tableData2[a];
      this.tableData2.splice(index, 1);
      // 把上一编辑行置回-1
      this.editingRowIndex = -1;
    },
    // 点击编辑行
    handleRowClick(row) {
      this.isEditLine = true;
      // alert(this.lastEditLine+"编辑行")
      //找到当前行的编辑索引
      var rowIndex = this.tableData2.indexOf(row);

      if (this.lastEditLine != 0 &&
        this.editingRowIndex !== rowIndex &&
        this.editingRowIndex !== -1 &&
        !this.isRowFilled(this.tableData2[this.lastEditLine])) {
        this.$message({
          message: '请先完成上一条数据的填写',
          type: 'warning'
        });
        return;
      }
      //编辑索引不等于当前编辑行索引
      if (this.editingRowIndex !== rowIndex) {
        // alert(this.editingRowIndex);
        if (this.editingRowIndex !== -1) {
          //把当前行变成不可编辑的
          this.tableData2[this.editingRowIndex].isEditing = false;
        }
        //把当前行变成可编辑的
        row.isEditing = true;
        this.editingRowIndex = rowIndex;
      }

    },
    // 光标失去焦点变成不可编辑
    handleInputBlur(row) {
      let rowIndex = this.tableData2.indexOf(row);
      //编辑索引不等于当前编辑行索引
      if (this.editingRowIndex !== rowIndex) {
        if (this.isRowFilled(row)) {
          row.isEditing = false;
          //对于整个表格来说
          this.isEditLine = false;
          //当前编辑行置为-1
          this.editingRowIndex = -1;
        }
      }
    },
    // 检查行是否填写完毕的示例方法
    isRowFilled(row) {
      return row.currentSpecification &&
        row.currentSpindleCount &&
        row.currentColorCode &&
        row.productType &&
        row.currentLotNumber &&
        row.number &&
        row.startTime &&
        row.plannedEndTime;
    },
    // 新增一行标记为可编辑
    addEditableRow() {
      // 检查当前编辑行是否已填写完毕
      if(this.tableData2.length!=0){
        if (this.editingRowIndex !== -1 && !this.isRowFilled(this.tableData2[this.editingRowIndex])) {
          this.$message({
            message: '请先完成上一条数据的填写',
            type: 'warning'
          });
          return;
        }
        //新增行之前先让以前的行不能编辑
        this.tableData2.forEach(item => {
          item.isEditing = false;
        })
      }
      this.tableData2.push({
        currentColorCode: '',
        currentSpecification: '',
        currentLotNumber: '',
        currentSpindleCount: '',
        number: '',
        startTime: '',
        plannedEndTime:'',
        planStatus:0,
        productId:'',
        salesmanId:'',
        isEditing: true // 标记为正在编辑状态

      });
      this.editingRowIndex = this.tableData2.length - 1; // 更新当前编辑的行索引
      this.lastEditLine = this.tableData2.length - 1
    },
    // 添加计划
    addPlanInfo(){
      if(this.tableData2.length>0){
        var flag=true;
        this.tableData2.forEach(item=>{
          if(!this.isRowFilled(item)){
            this.$message({
              message: '请先完善表格数据',
              type: 'warning'
            });
            flag=false
          }
        })
        if(flag){
          const datatime=Date.now()+this.machineId;
          //处理表格数据
          this.tableData2.forEach(item=>{
            item.timestampRandomCode=datatime;
            item.machineId=this.machineId;
          })
          //时间戳
          let data={
            //机台号
            machineId: this.machineId,
            macId:this.macId,
            timestampRandomCode:datatime,
            //计划信息
            detailsOfTheRefuelingPlans: this.tableData2
          }
          //添加计划信息
          addMaterielInfo(data).then(response => {
            if (response.code == 200) {
              this.$message({
                message: '添加成功',
                type: 'success'
              });
              this.getAmmunitionPlanInfo();
              //最后把弹窗关掉
              this.nanInsertDialogTableVisible = false
              this.beiInsertDialogTableVisible = false
              //更改订单投产信息的批号,
            } else {
              this.$message({
                message: '添加失败',
                type: 'error'
              });
              this.nanInsertDialogTableVisible = false
              this.beiInsertDialogTableVisible = false
              //最后把弹窗关掉
            }
          });
        }
      }else {
        this.$message({
          message: '请先添加表格数据',
          type: 'warning'
        });
        return;
      }
    },
    // 修改产品计划
    handleEditPlan(row) {
      //已经在待机列表了，isNull过滤掉了
      getProductsAll(row.macId).then((response) => {
          this.productsInfo = response.data;
          this.productsInfo.forEach(item => {
            item.productName = item.productName+"—"+item.materieEncoding+item.materieColorNumber
          });
          this.tableData2=[];
          //弹窗
          if(this.selectedWorkshop=="南车间"){
            this.nanUpdateDialogTableVisible = true
          }else{
            this.beiUpdateDialogTableVisible = true
          }
          //先清空--当前操作机台号
          this.machineId=""
          this.machineId=row.machineId;
          this.macId=row.macId;
          //查询当前机台下的计划信息
          getAllPlanListByMachineId(this.macId).then((response) => {
            //得到生产中，停产的，待产的
            response.data.forEach(item => {
              item.isEditing=false;
              item.planStatus=parseInt(item.planStatus);
              item.productId=parseInt(item.productId)
            })
            this.tableData2=response.data;
            // console.log( this.tableData2)
          })
      })
    },
    //重置按钮
    reset(){
      this.tableData2=[];
      //弹窗
      if(this.selectedWorkshop=="南车间"){
        this.nanUpdateDialogTableVisible = true
      }else{
        this.beiUpdateDialogTableVisible = true
      }
      console.log(this.machineId,"dddd")
      getAllPlanListByMachineId(this.machineId).then((response) => {
        //得到生产中，停产的，待产的
        response.data.forEach(item => {
          item.isEditing=false;
          item.planStatus=parseInt(item.planStatus);
          item.productId=parseInt(item.productId)
        })
        this.tableData2=response.data;
        // console.log( this.tableData2)
        // 在数据加载完成后，手动触发每个行的第一个下拉框的 change 事件
        this.$nextTick(() => {
          // 获取第一个业务员选择框（假设表格只有一行）
          for (let i = 0; i < this.tableData2.length; i++) {
            const firstSalesmanSelect = this.$refs['salesmanSelect'+i];
            // 触发 change 事件
            if (firstSalesmanSelect) {
              firstSalesmanSelect.$emit('change', {
                target: {value: "ddd"},
              });
            }
          }

        });
      })
    },
    //弹窗里边的点击查询
    onSubmit(){
      this.formData.macId=this.macId;
      getAllPlanListByProductTypeAndStatus(this.formData).then(response => {
        //得到生产中，停产的，待产的
        response.data.forEach(item => {
          item.isEditing=false;
          item.planStatus=parseInt(item.planStatus);
        })
        this.tableData2=response.data;
      });
    },
    //更新状态
    updateStatus(ind, row){
      if(!this.isRowFilled(row)){
        this.$message({message: '请完善当前行数据', type: 'warning'});
        return;
      }
      //判断当前计划是否已经投产
      getJtIsTheOrderProductProduced({"id":row.id}).then(resp=>{
        if(resp.data.length>0) {
          this.$message({message: '当前计划订单产品在生产中已经不能修改', type: 'warning'});
          return;//证明有在上级的产品--zhi能有一个上级产品
        }
        //不是投产中就可以更新了.
        updatePlanOne(row).then(response=>{
          if (response.code == 200) {
            this.$message({
              message: '修改成功',
              type: 'success'
            });
            this.getAmmunitionPlanInfo();
            //最后把弹窗关掉
            this.nanInsertDialogTableVisible=false
            this.beiUpdateDialogTableVisible=false
          } else {
            this.$message({
              message: '修改失败',
              type: 'error'
            });
            //最后把弹窗关掉
            this.nanInsertDialogTableVisible=false
            this.beiUpdateDialogTableVisible=false
          }
        })
      })


    }
  }
}
</script>

<style scoped>
.el-tabs--border-card >>> .el-tabs__content {
  padding: 0 !important;
}
.el-table__body-wrapper {
  cursor: grab;
}
.el-table__body-wrapper.grabbing {
  cursor: grabbing;
}
.container >>> .el-table .cell {
  white-space: pre-line;
}

</style>
