<template>
  <div class="app-container">

    <el-card>
      <div style="margin-top: -10px;">
        <el-row>
          <span>机床号:</span>
          <el-select v-model="toolNumValue" filterable clearable size="small" style="margin-top:10px;width: 220px" placeholder="机床号" @change="typeChange1()">
            <el-option
              v-for="item in toolNum"
              :key="item.value"
              :label="item.label"
              :value="item.value">
              <div style="float: left">{{ item.label }}</div>
              <div style="float: right; color: #8492a6; font-size: 13px">{{ item.value2 }}</div>
            </el-option>
          </el-select>

          <span>分组:</span>
          <el-select v-model="NumValue" size="small" style="margin-top:10px;width: 220px" filterable clearable placeholder="机床组号">
            <el-option
              v-for="item in Num"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <span>零件图号:</span>
          <el-input v-model="partNumber" clearable size="small" placeholder="零件图号" style="width: 200px;"/>

          <el-button v-if="是否扫描 === false" size="small" type="success" icon="el-icon-search" style="margin: 10px 0 0 10px" @click="total = 0;pageList = 1;getTable()">查询</el-button>
          <el-button v-if="是否扫描 === true" size="small" type="success" icon="el-icon-search" style="margin: 10px 0 0 10px" @click="total5 = 0;pageList5 = 1;getTable5()">查询</el-button>
          <el-checkbox v-if="false" v-model="是否扫描">是否扫描查询</el-checkbox>

        </el-row>
      </div>
    </el-card>

    <el-card>
      <span class="demonstration">开始日期: </span>
      <el-date-picker
        v-model="startTime"
        size="small"
        type="date"
        value-format="yyyy-MM-dd"
        style="top: 1px;"
        placeholder="选择开始日期"/>
      <span class="demonstration">结束日期: </span>
      <el-date-picker
        v-model="endTime"
        size="small"
        type="date"
        value-format="yyyy-MM-dd"
        style="top: 1px;"
        placeholder="选择开始日期"/>
      <el-button size="small" type="primary" style="margin: 10px" @click="PartPlan()">零件计划变更</el-button>
      <el-button v-if="false" size="small" type="primary" icon="el-icon-download" @click="Export()">导出Excel</el-button>
      <el-table
        v-loading="listLoading"
        :data="tableData"
        :row-class-name="tableRowClassName"
        border
        style="max-height: 400px;margin-top:10px"
        height="400"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          align="center"
          width="35"/>
        <el-table-column label="零件图号" align="center" width="300">
          <template slot-scope="scope">
            {{ scope.row.零件图号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件名称" align="center" width="200">
          <template slot-scope="scope">
            {{ scope.row.零件名称 }}
          </template>
        </el-table-column>
        <el-table-column label="零件数量" align="center" width="100">
          <template slot-scope="scope">
            {{ scope.row.投产数量 }}
          </template>
        </el-table-column>
        <el-table-column label="机加工开始时间" align="center">
          <template slot-scope="scope">
            {{ scope.row.机加工开始时间 }}
          </template>
        </el-table-column>
        <el-table-column label="机加工结束时间" align="center">
          <template slot-scope="scope">
            {{ scope.row.机加工结束时间 }}
          </template>
        </el-table-column>
        <el-table-column label="工序数量" align="center">
          <template slot-scope="scope">
            {{ scope.row.工序数量 }}
          </template>
        </el-table-column>
        <!--<el-table-column label="是否超负荷" align="center" width="100">-->
        <!--<template slot-scope="scope">-->
        <!--{{ scope.row.是否超负荷 }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="外协" width="100" align="center">-->
        <!--<template slot-scope="scope">-->
        <!--<el-checkbox v-model="scope.row.是否预计外协" @change="table1Out(scope.row)">外协</el-checkbox>-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="加工件合格" align="center" width="230">-->
        <!--<template slot-scope="scope">-->
        <!--<el-date-picker-->
        <!--v-model="tableData[scope.$index].加工件合格时间"-->
        <!--size="mini"-->
        <!--type="date"-->
        <!--value-format="yyyy-MM-dd"-->
        <!--placeholder="选择加工件合格时间"-->
        <!--@change="timeChange(scope.row)"/>-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="板焊结束" width="150" align="center">-->
        <!--<template slot-scope="scope">-->
        <!--{{ scope.row.板焊 }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="操作" width="200px" align="center" fixed="right">-->
        <!--<template slot-scope="scope" align="center">-->
        <!--<el-button-->
        <!--size="mini"-->
        <!--type="primary"-->
        <!--class="el-icon-edit"-->
        <!--@click="PlateWelding(scope.$index, scope.row, 'form1')">板焊</el-button>-->
        <!--&lt;!&ndash;<el-button size="mini" type="primary" @click="inBatches">分批</el-button>&ndash;&gt;-->
        <!--</template>-->
        <!--</el-table-column>-->
      </el-table>
      <div v-if="是否扫描 === false" class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="10"
          :total="total"
          style="float:left"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
        <el-button type="warning" size="small" icon="el-icon-download" style="float:right;margin:5px 50px 10px 10px" @click="Selection">选入</el-button>
        <el-button type="warning" size="small" icon="el-icon-download" style="float:right;margin:5px 20px 10px 10px" @click="SelectionAll">全部选入</el-button>
      </div>
      <div v-if="是否扫描 === true" class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="currentPage5"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="10"
          :total="total5"
          style="float:left"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange5"
          @current-change="handleCurrentChange5"/>
        <el-button type="warning" size="small" icon="el-icon-download" style="float:right;margin:5px 50px 10px 10px" @click="Selection">选入</el-button>
      </div>
    </el-card>

    <el-card>
      <div>
        <el-table
          v-loading="listLoading1"
          :data="tableData1"
          class="table"
          borde
          style="max-height: 500px"
          height="500">
          <el-table-column label="零件图号" align="center" width="240">
            <template slot-scope="scope">
              {{ 零件图号[scope.$index] }}
            </template>
          </el-table-column>
          <el-table-column label="零件名称" align="center" width="160">
            <template slot-scope="scope">
              {{ 零件名称[scope.$index] }}
            </template>
          </el-table-column>
          <el-table-column label="零件数量" align="center" width="100">
            <template slot-scope="scope">
              {{ 投产数量[scope.$index] }}
            </template>
          </el-table-column>
          <el-table-column label="机加工开始时间" align="center" width="120">
            <template slot-scope="scope">
              {{ 机加工开始时间[scope.$index] }}
            </template>
          </el-table-column>
          <el-table-column label="机加工结束时间" align="center" width="120">
            <template slot-scope="scope">
              {{ 机加工结束时间[scope.$index] }}
            </template>
          </el-table-column>
          <!--<el-table-column label="是否预计外协" align="center" width="110">-->
          <!--<template slot-scope="scope">-->
          <!--{{ 预计外协[scope.$index] }}-->
          <!--</template>-->
          <!--</el-table-column>-->
          <el-table-column label="零件加工计划进度（工艺名称、计划日期、工序工时）" align="">
            <el-table-column label="[1]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][0]">
                  <h4>{{ process[scope.$index][0] }}</h4><h4>{{ planDate[scope.$index][0] }} </h4><h4> {{ realDate[scope.$index][0] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[2]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][1]">
                  <h4>{{ process[scope.$index][1] }}</h4><h4>{{ planDate[scope.$index][1] }} </h4><h4> {{ realDate[scope.$index][1] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[3]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][2]">
                  <h4>{{ process[scope.$index][2] }}</h4><h4>{{ planDate[scope.$index][2] }} </h4><h4> {{ realDate[scope.$index][2] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[4]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][3]">
                  <h4>{{ process[scope.$index][3] }}</h4><h4>{{ planDate[scope.$index][3] }} </h4><h4> {{ realDate[scope.$index][3] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[5]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][4]">
                  <h4>{{ process[scope.$index][4] }}</h4><h4>{{ planDate[scope.$index][4] }} </h4><h4> {{ realDate[scope.$index][4] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[6]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][5]">
                  <h4>{{ process[scope.$index][5] }}</h4><h4>{{ planDate[scope.$index][5] }} </h4><h4> {{ realDate[scope.$index][5] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[7]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][6]">
                  <h4>{{ process[scope.$index][6] }}</h4><h4>{{ planDate[scope.$index][6] }} </h4><h4> {{ realDate[scope.$index][6] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[8]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][7]">
                  <h4>{{ process[scope.$index][7] }}</h4><h4>{{ planDate[scope.$index][7] }} </h4><h4> {{ realDate[scope.$index][7] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[9]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][8]">
                  <h4>{{ process[scope.$index][8] }}</h4><h4>{{ planDate[scope.$index][8] }} </h4><h4> {{ realDate[scope.$index][8] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[10]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][9]">
                  <h4>{{ process[scope.$index][9] }}</h4><h4>{{ planDate[scope.$index][9] }} </h4><h4> {{ realDate[scope.$index][9] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[11]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][10]">
                  <h4>{{ process[scope.$index][10] }}</h4><h4>{{ planDate[scope.$index][10] }} </h4><h4> {{ realDate[scope.$index][10] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[12]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][11]">
                  <h4>{{ process[scope.$index][11] }}</h4><h4>{{ planDate[scope.$index][11] }} </h4><h4> {{ realDate[scope.$index][11] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[13]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][12]">
                  <h4>{{ process[scope.$index][12] }}</h4><h4>{{ planDate[scope.$index][12] }} </h4><h4> {{ realDate[scope.$index][12] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[14]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][13]">
                  <h4>{{ process[scope.$index][13] }}</h4><h4>{{ planDate[scope.$index][13] }} </h4><h4> {{ realDate[scope.$index][13] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[15]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][14]">
                  <h4>{{ process[scope.$index][14] }}</h4><h4>{{ planDate[scope.$index][14] }} </h4><h4> {{ realDate[scope.$index][14] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[16]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][15]">
                  <h4>{{ process[scope.$index][15] }}</h4><h4>{{ planDate[scope.$index][15] }} </h4><h4> {{ realDate[scope.$index][15] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[17]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][16]">
                  <h4>{{ process[scope.$index][16] }}</h4><h4>{{ planDate[scope.$index][16] }} </h4><h4> {{ realDate[scope.$index][16] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[18]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][17]">
                  <h4>{{ process[scope.$index][17] }}</h4><h4>{{ planDate[scope.$index][17] }} </h4><h4> {{ realDate[scope.$index][17] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[19]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][18]">
                  <h4>{{ process[scope.$index][18] }}</h4><h4>{{ planDate[scope.$index][18] }} </h4><h4> {{ realDate[scope.$index][18] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[20]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][19]">
                  <h4>{{ process[scope.$index][19] }}</h4><h4>{{ planDate[scope.$index][19] }} </h4><h4> {{ realDate[scope.$index][19] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[21]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][20]">
                  <h4>{{ process[scope.$index][20] }}</h4><h4>{{ planDate[scope.$index][20] }} </h4><h4> {{ realDate[scope.$index][20] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[22]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][21]">
                  <h4>{{ process[scope.$index][21] }}</h4><h4>{{ planDate[scope.$index][21] }} </h4><h4> {{ realDate[scope.$index][21] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[23]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][22]">
                  <h4>{{ process[scope.$index][22] }}</h4><h4>{{ planDate[scope.$index][22] }} </h4><h4> {{ realDate[scope.$index][22] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[24]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][23]">
                  <h4>{{ process[scope.$index][23] }}</h4><h4>{{ planDate[scope.$index][23] }} </h4><h4> {{ realDate[scope.$index][23] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[25]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][24]">
                  <h4>{{ process[scope.$index][24] }}</h4><h4>{{ planDate[scope.$index][24] }} </h4><h4> {{ realDate[scope.$index][24] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[26]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][25]">
                  <h4>{{ process[scope.$index][25] }}</h4><h4>{{ planDate[scope.$index][25] }} </h4><h4> {{ realDate[scope.$index][25] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[27]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][26]">
                  <h4>{{ process[scope.$index][26] }}</h4><h4>{{ planDate[scope.$index][26] }} </h4><h4> {{ realDate[scope.$index][26] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[28]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][27]">
                  <h4>{{ process[scope.$index][27] }}</h4><h4>{{ planDate[scope.$index][27] }} </h4><h4> {{ realDate[scope.$index][27] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[29]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][28]">
                  <h4>{{ process[scope.$index][28] }}</h4><h4>{{ planDate[scope.$index][28] }} </h4><h4> {{ realDate[scope.$index][28] }}</h4>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="[30]" align="center" width="120px">
              <template slot-scope="scope">
                <div :class="colorCode[scope.$index][29]">
                  <h4>{{ process[scope.$index][29] }}</h4><h4>{{ planDate[scope.$index][29] }} </h4><h4> {{ realDate[scope.$index][29] }}</h4>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="操作" width="200px" align="center" fixed="right">
            <template slot-scope="scope" align="center">
              <el-button size="mini" type="primary" @click="adjustFunc(scope.$index)">调整</el-button>
              <el-button size="mini" type="danger" icon="el-icon-upload2" @click="xuanChu(scope.$index)">选出</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="block" style="margin-top: 10px;">
          <el-pagination
            :current-page="currentPage1"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="10"
            :total="total1"
            style="float:left"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange1"
            @current-change="handleCurrentChange1"/>
          <div style="float:right">
            <el-button type="primary" size="small" style="margin:5px 10px 10px 10px" @click="Discharge">虚拟排产</el-button>
            <el-button :disabled="listLoading1" type="primary" size="small" style="margin:5px 10px 10px 10px" @click="Plan" >确定零件计划</el-button>
            <el-button type="danger" size="small" icon="el-icon-upload2" style="float:right;margin:5px 50px 10px 10px" @click="allOut">全部选出</el-button>
          </div>
        </div>
      </div>
    </el-card>

    <el-dialog :visible.sync="dialogFormVisible1" title="板焊" center width="27%">
      <el-form ref="form1" :model="form1" :rules="rules" label-position="left" label-width="110px">
        <el-row>
          <el-form-item label="是否焊接">
            <el-radio v-model="form1.radio" label="1">是</el-radio>
            <el-radio v-model="form1.radio" label="0">否</el-radio>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item v-if="form1.radio === '1'" label="板焊结束时间" prop="enddate">
            <el-date-picker
              v-model="form1.enddate"
              size="small"
              type="date"
              value-format="yyyy-MM-dd"
              style="top: 1px;"
              placeholder="选择开始日期"/>
          </el-form-item>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="callOff1('form1')">取消</el-button>
        <el-button size="small" type="primary" @click="submit1('form1')">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog
      v-el-drag-dialog
      :visible.sync="dialogTableVisible520"
      title="调整工序计划"
      width="45%">
      <div style="overflow: auto;max-height: 450px;">
        <el-row v-if="false">
          <span>开始时间:</span>
          <el-date-picker
            v-model="adjustStartTime"
            size="mini"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            type="date"
            placeholder="选择日期"/>
          <span>结束时间:</span>
          <el-date-picker
            v-model="adjustEndTime"
            size="mini"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            type="date"
            placeholder="选择日期"/>
          <el-button size="mini" type="success" icon="el-icon-search" style="margin: 10px 0 10px 10px" @click="searchChart1">查询</el-button>
        </el-row>
        <div v-if="false" id="myChart1" style="width: 58%;height: 300px;display: inline-block"/>
        <el-table
          v-if="false"
          :data="tableData01"
          border
          style="max-height: 300px;width:40%;display: inline-block"
          height="300">
          <el-table-column label="名称" align="center">
            <template slot-scope="scope">
              {{ scope.row.设备名称 }}
            </template>
          </el-table-column>
          <el-table-column label="工作日期" align="center" width="100">
            <template slot-scope="scope">
              {{ scope.row.工作日期 }}
            </template>
          </el-table-column>
          <el-table-column label="总剩余" align="center" width="80">
            <template slot-scope="scope">
              {{ scope.row.总剩余加工能力 }}
            </template>
          </el-table-column>
          <el-table-column label="正常剩余" align="center" width="80">
            <template slot-scope="scope">
              {{ scope.row.正常剩余加工能力 }}
            </template>
          </el-table-column>
          <el-table-column label="整改剩余" align="center" width="80">
            <template slot-scope="scope">
              {{ scope.row.整改剩余加工能力 }}
            </template>
          </el-table-column>
          <el-table-column label="预留能力" align="center" width="80">
            <template slot-scope="scope">
              {{ scope.row.预留能力 }}
            </template>
          </el-table-column>
        </el-table>
        <el-row v-if="false">
          <el-radio v-model="radio" label="1">月：</el-radio>
          <el-select v-model="month1" size="mini" style="width:60px" placeholder="月">
            <el-option
              v-for="item in months"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>～<el-select v-model="month2" size="mini" style="width:60px" placeholder="月">
            <el-option
              v-for="item in months"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <el-radio v-model="radio" label="2">周：</el-radio>
          <el-select v-model="week1" size="mini" style="width:60px" placeholder="周">
            <el-option
              v-for="item in weeks"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>～<el-select v-model="week2" size="mini" style="width:60px" placeholder="周">
            <el-option
              v-for="item in weeks"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <el-button size="mini" type="success" icon="el-icon-search" style="margin: 10px 0 10px 10px" @click="searchChart2">查询</el-button>
          <el-button size="mini" type="primary" icon="el-icon-refresh" style="margin: 10px 20px;float:right" @click="refreshTable">刷新</el-button>
          <span>零件类型：</span>{{ partType }}
        </el-row>
        <div v-if="false" id="myChart2" style="width: 58%;height: 300px;display: inline-block"/>
        <!--@row-click="rowClick"-->
        <el-table
          :data="tableData02"
          :row-class-name="rowClassName"
          border
          style="max-height: 300px;display: inline-block"
          height="300">
          <el-table-column label="工序顺序" align="center" width="80" type="index">
            <template slot-scope="scope">
              {{ 工序顺序[scope.$index] }}
            </template>
          </el-table-column>
          <el-table-column label="工序名称" align="center">
            <template slot-scope="scope">
              {{ 工序名称[scope.$index] }}
            </template>
          </el-table-column>
          <el-table-column label="工时" align="center" width="80">
            <template slot-scope="scope">
              {{ 工时[scope.$index] }}
            </template>
          </el-table-column>
          <el-table-column label="计划日期" align="center" width="200">
            <template slot-scope="scope">
              <el-date-picker
                v-model="计划日期[scope.$index]"
                style="width:150px"
                size="mini"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"/>
            </template>
          </el-table-column>
          <el-table-column label="更新" size="mini" align="center" width="90">
            <template slot-scope="scope">
              <el-button size="mini" type="primary" style="" @click="updateDate(scope.$index)">更新</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--<div slot="footer" class="dialog-footer" style="margin-right: 20px;float:right">-->
        <!--<el-button size="mini" type="primary" @click="refreshTable" icon="el-icon-refresh"  style="margin-left: 750px">确定</el-button>-->
        <!--</div>-->
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { selection10086, timeChange, table1Out, Export, han, allOut, updateDate, searchChart1, searchChartTable1, searchChart2, getEntryNameValue, getToolNum, getNum, getTable, getTable5, selection, selection1, discharge, plan, out, xuanchu, platewelding, partPlan, selection2, getTable12580 } from '@/api/ManufacturingCenter/ProductionCapacityBalance'
import elDragDialog from '@/directive/el-dragDialog' // 可移动对话框
import echarts from 'echarts'
import { mapGetters } from 'vuex'

export default {
  directives: { elDragDialog },
  data() {
    return {
      bianliang1: [],
      count: 0,
      是否扫描: false,
      dataX1: [], // 图表1横坐标
      Occupy: [], // 占用
      Surplus: [], // 剩余
      Beyond: [], // 超出
      workSerialNumber: '', // 工序流水号
      partType: '',
      工序顺序: [],
      工序流水号: [],
      工序名称: [],
      工时: [],
      计划日期: [],
      indexAdjust: '', // 被调整的那行索引
      totalAblity: [],
      totalTime: [],
      tableData01: [],
      tableData02: [],
      radio: '1',
      weeks: [],
      week1: '',
      week2: '',
      months: [],
      month1: '',
      month2: '',
      adjustStartTime: '',
      adjustEndTime: '',
      dialogTableVisible520: false,
      q: 0,
      listLoading1: false,
      预计外协: [],
      零件图号: [],
      工艺计划流水号: [],
      零件名称: [],
      投产数量: [],
      机加工开始时间: [],
      机加工结束时间: [],
      是否焊接: [],
      平衡次数: [],
      result: [],
      process: [[]],
      planDate: [[]],
      colorCode: [[]],
      realDate: [[]],
      multipleSelection: [],
      shijiancuo1: 0,
      shijiancuo: 0,
      jieguo: 0,
      startTime: '',
      endTime: '',
      dialogFormVisible1: false,
      liushui: '', // 工艺计划流水号 板焊修改里
      form1: {
        radio: '1',
        enddate: ''
      },
      rules: { // 表单验证规则
        enddate: [{ required: true, message: '请选择板焊结束时间', trigger: 'change' }]
      },
      listLoading: false,
      result1: 0,
      time: '',
      entryNameValue: '',
      entryName: [], // 项目名称
      toolNumValue: '',
      toolNum: [], // 机床号
      NumValue: '',
      Num: [], // 组号
      partNumber: '',
      checked_partNumber: false,
      checked_entryName: false,
      checked_toolNum: false,
      checked_Num: false,
      tableData: [],
      tableData1: [],
      tableData2: [], // 导出临时表
      length: 0, // 记TABLEDATA1的长度
      total: 0, // 总条数
      pageSize: 10, // 每页显示条数
      pageList: 1, // 后台获取页
      currentPage: 1, // 显示当前页
      total1: 0, // 总条数
      pageSize1: 10, // 每页显示条数
      pageList1: 1, // 后台获取页
      currentPage1: 1, // 显示当前页
      total5: 0, // 总条数
      pageSize5: 10, // 每页显示条数
      pageList5: 1, // 后台获取页
      currentPage5: 1 // 显示当前页
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name',
      'id'
    ])
  },
  created() {
    this.typeChange()
    this.Selection1()
    this.getTable()
  },
  methods: {
    // TABLE每行颜色
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex === 1) {
        return 'warning-row'
      } else if (rowIndex === 3) {
        return 'success-row'
      }
      return ''
    },
    // 修改加工件合格时间
    timeChange(row) {
      timeChange(row.工艺计划流水号, row.加工件合格时间).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('加工件合格时间修改成功')
        } else {
          this.$message.error('加工件合格时间修改失败')
        }
      })
    },
    // 修改外协状态
    table1Out(row) {
      if (row.是否预计外协 === true) {
        table1Out(row.工艺计划流水号, 2).then(() => {
          this.$message.success('修改外协成功')
        })
      } else {
        table1Out(row.工艺计划流水号, 1).then(() => {
          this.$message.success('修改外协成功')
        })
      }
    },
    // 外协跳转
    inBatches() {
      this.$confirm('是否跳转到生产中分批页面?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '跳转成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消跳转'
        })
      })
    },
    rowClassName({ rowIndex }) {
      if (this.colorCode[this.indexAdjust][rowIndex] === 'red') {
        return 'red'
      } else if (this.colorCode[this.indexAdjust][rowIndex] === 'white') {
        return 'white'
      } else {
        return ''
      }
    },
    // rowClick(row) {
    //   this.workSerialNumber = row.工序流水号
    //   this.searchChart1()
    // },
    // 刷新
    refreshTable() {
      this.partType = ''
      this.tableData02 = []
      this.工序顺序 = []
      this.工序流水号 = []
      this.工序名称 = []
      this.工时 = []
      this.计划日期 = []
      this.Selection2()
    },
    // 更新
    updateDate(index) {
      if (this.计划日期[index] === '' || this.计划日期[index] === null) {
        this.$message.error('请选择日期')
      } else {
        updateDate(this.工序流水号[index], this.id, this.计划日期[index]).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('更新成功')
            this.refreshTable()
          } else {
            this.$message.error('更新失败')
          }
        })
      }
    },
    searchChart1() {
      var myChart1 = echarts.init(document.getElementById('myChart1'))
      myChart1.clear()
      searchChart1(this.workSerialNumber, this.adjustStartTime, this.adjustEndTime).then(response => {
        this.drawLine1(response.data)
      })
      searchChartTable1(this.workSerialNumber, this.adjustStartTime, this.adjustEndTime).then(response => {
        this.tableData01 = response.data
      })
    },
    // 查图表2的数据
    searchChart2() {
      var myChart2 = echarts.init(document.getElementById('myChart2'))
      myChart2.clear()
      if (this.radio === '1') {
        searchChart2(this.month1, this.month2, 2).then(response => {
          this.drawLine2(response.data)
        })
      } else {
        searchChart2(this.week1, this.week2, 1).then(response => {
          this.drawLine2(response.data)
        })
      }
    },
    drawLine1(data) {
      this.dataX1 = []
      this.Occupy = []
      this.Surplus = []
      this.Beyond = []
      for (let i = 0; i < data.length; i++) {
        this.dataX1.push(data[i].工作日期)
        this.Occupy.push(data[i].余量)
        this.Surplus.push(data[i].总剩余加工能力)
        this.Beyond.push(data[i].超出工时)
      }
      var myChart1 = echarts.init(document.getElementById('myChart1'))
      myChart1.setOption({
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        legend: {
          data: ['占用', '剩余', '超出']
        },
        xAxis: {
          type: 'category',
          name: '工作日期',
          data: this.dataX1,
          axisLabel: {
            interval: 0,
            rotate: 0,
            margin: 10
          }
        },
        yAxis: {
          type: 'value',
          name: '工时',
          min: 0,
          scale: 'true'
        },
        series: [
          {
            name: '占用',
            type: 'bar',
            data: this.Occupy
          },
          {
            name: '剩余',
            type: 'bar',
            data: this.Surplus
          },
          {
            name: '超出',
            type: 'bar',
            data: this.Beyond
          }
        ]
      })
    },
    drawLine2(data) {
      this.dataX = []
      this.totalAblity = []
      this.totalTime = []
      for (let i = 0; i < data.length; i++) {
        this.dataX.push(data[i].日期)
        this.totalAblity.push(data[i].设备总能力)
        this.totalTime.push(data[i].总工时)
      }
      var myChart2 = echarts.init(document.getElementById('myChart2'))
      myChart2.setOption({
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        legend: {
          data: ['设备总能力', '总工时']
        },
        // 实现缩放功能
        dataZoom: {
          show: true,
          realtime: true,
          start: 0,
          end: 100
        },
        xAxis: {
          type: 'category',
          name: '日期',
          data: this.dataX,
          axisLabel: {
            interval: 0,
            rotate: 0,
            margin: 10
          }
        },
        yAxis: {
          type: 'value',
          name: '工时',
          min: 0,
          scale: 'true'
        },
        series: [
          {
            name: '设备总能力',
            type: 'bar',
            data: this.totalAblity
          },
          {
            name: '总工时',
            type: 'bar',
            data: this.totalTime
          }
        ]
      })
    },
    // 初始化获取项目名称
    fetchData() {
      for (let i = 0; i < 12; i++) {
        this.months.push({
          label: i + 1,
          value: i + 1
        })
      }
      for (let i = 0; i < 52; i++) {
        this.weeks.push({
          label: i + 1,
          value: i + 1
        })
      }
      getEntryNameValue().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.entryName.push({
            label: response.data[i].项目名称,
            value: response.data[i].项目流水号
          })
        }
      })
    },
    typeChange() {
      this.toolNumValue = ''
      this.toolNum = []
      this.NumValue = ''
      this.Num = []
      getToolNum(this.entryNameValue).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.toolNum.push({
            label: response.data[i].机床图号,
            value: response.data[i].机床流水号,
            value2: response.data[i].项目名称
          })
        }
      })
    },
    typeChange1() {
      this.NumValue = ''
      this.Num = []
      getNum(this.toolNumValue).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.Num.push({
            label: response.data[i].组号,
            value: response.data[i].组件流水号
          })
        }
      })
    },
    getTable() {
      this.listLoading = true
      this.tableData = []
      if (this.entryNameValue === '') {
        this.checked_entryName = false
      } else {
        this.checked_entryName = true
      }
      if (this.toolNumValue === '') {
        this.checked_toolNum = false
      } else {
        this.checked_toolNum = true
      }
      if (this.NumValue === '') {
        this.checked_Num = false
      } else {
        this.checked_Num = true
      }
      if (this.partNumber !== '' && this.partNumber !== null) {
        this.checked_partNumber = true
      } else {
        this.checked_partNumber = false
      }
      getTable(this.checked_entryName, this.entryNameValue, this.checked_toolNum, this.toolNumValue, this.checked_Num, this.NumValue, this.checked_partNumber, this.partNumber, this.pageList, this.pageSize).then(response => {
        for (let i = 0; i < response.data.rows.length; i++) {
          response.data.rows[i].机加工开始时间_长日期 = response.data.rows[i].机加工开始时间_长日期.substring(0, response.data.rows[i].机加工开始时间_长日期.indexOf(' '))
          response.data.rows[i].机加工结束时间_长日期 = response.data.rows[i].机加工结束时间_长日期.substring(0, response.data.rows[i].机加工结束时间_长日期.indexOf(' '))
        }
        this.total = parseInt(response.data.total)
        for (let i = 0; i < response.data.rows.length; i++) {
          if (response.data.rows[i].是否预计外协 === 'true') {
            response.data.rows[i].是否预计外协 = true
          } else {
            response.data.rows[i].是否预计外协 = false
          }
          this.tableData.push({
            零件图号: response.data.rows[i].零件图号,
            零件名称: response.data.rows[i].零件名称,
            投产数量: response.data.rows[i].投产数量,
            机加工开始时间: response.data.rows[i].机加工开始时间_长日期,
            机加工结束时间: response.data.rows[i].机加工结束时间_长日期,
            加工件合格时间: response.data.rows[i].加工件合格时间,
            工序数量: response.data.rows[i].工序数量,
            是否超负荷: response.data.rows[i].是否超负荷,
            板焊: response.data.rows[i].板焊工段计划完成时间,
            工艺计划流水号: response.data.rows[i].工艺计划流水号,
            时间差: response.data.rows[i].时间差,
            是否是分件: response.data.rows[i].是否是分件,
            是否临时件: response.data.rows[i].是否临时件,
            是否预计外协: response.data.rows[i].是否预计外协,
            checked_banhan1: response.data.rows[i].是否焊接,
            排序顺序: parseFloat(response.data.rows[i].是否是分件) * 100 + parseFloat(response.data.rows[i].时间差) * 100 + parseFloat(response.data.rows[i].工序数量) * 5
          })
        }
        this.listLoading = false
      })
    },
    // 导出
    getTable5() {
      this.tableData = []
      this.listLoading = true
      getTable5(this.pageList5, this.pageSize5).then(response => {
        for (let i = 0; i < response.data.rows.length; i++) {
          this.tableData.push({
            零件图号: response.data.rows[i].零件图号,
            零件名称: response.data.rows[i].零件名称,
            投产数量: response.data.rows[i].投产数量,
            机加工开始时间: response.data.rows[i].机加工开始时间,
            机加工结束时间: response.data.rows[i].机加工结束时间,
            加工件合格时间: response.data.rows[i].加工件合格时间,
            工序数量: response.data.rows[i].工序数量,
            是否超负荷: response.data.rows[i].是否超负荷,
            板焊: response.data.rows[i].板焊工段计划完成时间,
            工艺计划流水号: response.data.rows[i].工艺计划流水号,
            时间差: response.data.rows[i].时间差,
            是否是分件: response.data.rows[i].是否是分件,
            是否临时件: response.data.rows[i].是否临时件,
            是否预计外协: response.data.rows[i].是否预计外协,
            checked_banhan1: response.data.rows[i].是否焊接,
            排序顺序: parseFloat(response.data.rows[i].是否是分件) * 100 + parseFloat(response.data.rows[i].时间差) * 100 + parseFloat(response.data.rows[i].工序数量) * 5
          })
        }
        this.listLoading = false
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 选入
    Selection() {
      if (this.multipleSelection.length === 0) {
        this.$message.error('请至少选择一个零件')
      } else {
        this.result1 = 0
        for (let i = 0; i < this.multipleSelection.length; i++) {
          selection(this.multipleSelection[i].工艺计划流水号, this.multipleSelection[i].工序数量, this.multipleSelection[i].排序顺序, this.id).then(response => {
            this.result1 += parseInt(response.data[0].result)
            if (this.result1 === this.multipleSelection.length) {
              this.result1 = 0
              this.total1 = 0
              this.pageList1 = 1
              this.Selection1()
              this.total = 0
              this.pageList = 1
              this.getTable()
            }
          })
        }
      }
    },
    // 全部选入
    SelectionAll() {
      this.$confirm('是否将全部零件选入?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        getTable12580(this.checked_entryName, this.entryNameValue, this.checked_toolNum, this.toolNumValue, this.checked_Num, this.NumValue, this.checked_partNumber, this.partNumber).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            selection(response.data[i].工艺计划流水号, response.data[i].工序数量, response.data[i].排序顺序, this.id)
          }
        }).then(() => {
          this.total = 0
          this.pageList = 1
          this.getTable()
          this.total1 = 0
          this.pageList1 = 1
          this.Selection1()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消选入'
        })
      })
    },
    // 选出
    xuanChu(index) {
      xuanchu(this.工艺计划流水号[index]).then(response => {
      }).then(() => {
        this.pageList = 1
        this.total = 0
        this.getTable()
      }).then(() => {
        this.Selection1()
      })
    },
    // 选入后查询
    Selection1() {
      this.listLoading1 = true
      this.tableData1 = []
      this.零件图号 = []
      this.工艺计划流水号 = []
      this.预计外协 = []
      this.零件名称 = []
      this.投产数量 = []
      this.机加工开始时间 = []
      this.机加工结束时间 = []
      this.是否焊接 = []
      this.平衡次数 = []
      this.result = []
      this.process = [[]]
      this.planDate = [[]]
      this.colorCode = [[]]
      this.realDate = [[]]
      selection1(this.id, this.pageList1, this.pageSize1).then(response => {
        for (let i = 0; i < response.data.rows.length; i++) {
          response.data.rows[i].机加工开始时间 = response.data.rows[i].机加工开始时间.substring(0, response.data.rows[i].机加工开始时间.indexOf(' '))
          response.data.rows[i].机加工结束时间 = response.data.rows[i].机加工结束时间.substring(0, response.data.rows[i].机加工结束时间.indexOf(' '))
        }
        for (let i = 0; i < response.data.rows.length; i++) {
          if (response.data.rows[i].是否预计外协 === '1') {
            response.data.rows[i].是否预计外协 = '否'
          } else {
            response.data.rows[i].是否预计外协 = '是'
          }
          this.预计外协.push(response.data.rows[i].是否预计外协)
          this.零件图号.push(response.data.rows[i].零件图号)
          this.工艺计划流水号.push(response.data.rows[i].工艺计划流水号)
          this.零件名称.push(response.data.rows[i].零件名称)
          this.投产数量.push(response.data.rows[i].投产数量)
          this.机加工开始时间.push(response.data.rows[i].机加工开始时间)
          this.机加工结束时间.push(response.data.rows[i].机加工结束时间)
          this.是否焊接.push(response.data.rows[i].是否焊接)
          this.平衡次数.push(response.data.rows[i].平衡次数)
          this.process[i] = []
          this.planDate[i] = []
          this.colorCode[i] = []
          this.realDate[i] = []
          this.result.push(response.data.rows[i])
          this.total1 = parseInt(response.data.total)
        }
        if (this.零件图号.length !== 0) {
          for (let i = 0; i < this.零件图号.length; i++) {
            selection2(this.工艺计划流水号[i]).then(response => {
              for (let k = 0; k < response.data.length; k++) {
                this.process[i][k] = response.data[k].工艺名称简称
                this.planDate[i][k] = response.data[k].计划日期_短
                this.colorCode[i][k] = response.data[k].颜色代码
                this.realDate[i][k] = response.data[k].工序工时
              }
              for (let m = 0; m < this.colorCode.length; m++) {
                for (let j = 0; j < this.colorCode[i].length; j++) {
                  if (this.process[m][j] === null) {
                    this.colorCode[m][j] = 'blank'
                  }
                  if (this.colorCode[m][j] === '') {
                    this.colorCode[m][j] = 'white'
                  }
                }
              }
            }).then(() => {
              this.tableData1.push(this.result[i])
              selection2(this.工艺计划流水号[this.indexAdjust]).then(response => { // 刷新对话框显示和颜色
                for (let i = 0; i < response.data.length; i++) {
                  this.partType = response.data[i].零件类型
                  this.tableData02 = response.data
                  this.工序顺序.push(response.data[i].工序顺序)
                  this.工序流水号.push(response.data[i].工序流水号)
                  this.工序名称.push(response.data[i].工艺名称简称)
                  this.工时.push(response.data[i].工序工时)
                  this.计划日期.push(response.data[i].计划日期)
                }
              })
            })
          }
        } else {
          this.tableData1 = []
          this.listLoading1 = false
          this.total1 = 0
        }
      }).then(() => {
        this.listLoading1 = false
      })
    },
    // 调整
    adjustFunc(index) {
      this.indexAdjust = index
      this.partType = ''
      this.tableData02 = []
      this.工序顺序 = []
      this.工序流水号 = []
      this.工序名称 = []
      this.工时 = []
      this.计划日期 = []
      selection2(this.工艺计划流水号[index]).then(response => {
        this.partType = response.data[0].零件类型
        this.tableData02.push(response.data)
        this.工序顺序.push(response.data[0].工序顺序)
        this.工序流水号.push(response.data[0].工序流水号)
        this.工序名称.push(response.data[0].工艺名称简称)
        this.工时.push(response.data[0].工序工时)
        this.计划日期.push(response.data[0].计划日期)
        for (let i = 1; i < response.data.length; i++) {
          // if (response.data[i].工序流水号 !== response.data[i - 1].工序流水号) {}
          this.工序顺序.push(response.data[i].工序顺序)
          this.工序流水号.push(response.data[i].工序流水号)
          this.工序名称.push(response.data[i].工艺名称简称)
          this.工时.push(response.data[i].工序工时)
          this.计划日期.push(response.data[i].计划日期)
          this.tableData02.push(response.data)
        }
      })
      this.dialogTableVisible520 = true
    },
    // 全部选出
    allOut() {
      this.$confirm('是否将零件全部选出?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        selection10086(this.id).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            allOut(response.data[i].工艺计划流水号)
          }
        }).then(() => {
          this.total = 0
          this.pageList = 1
          this.getTable()
          this.total1 = 0
          this.pageList1 = 1
          this.Selection1()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消选出'
        })
      })
    },
    // 刷新里刷新
    Selection2() {
      this.listLoading1 = true
      this.tableData1 = []
      this.零件图号 = []
      this.工艺计划流水号 = []
      this.预计外协 = []
      this.零件名称 = []
      this.投产数量 = []
      this.机加工开始时间 = []
      this.机加工结束时间 = []
      this.是否焊接 = []
      this.平衡次数 = []
      this.result = []
      this.process = [[]]
      this.planDate = [[]]
      this.colorCode = [[]]
      this.realDate = [[]]
      selection1(this.id, this.pageList1, this.pageSize1).then(response => {
        for (let i = 0; i < response.data.rows.length; i++) {
          response.data.rows[i].机加工开始时间 = response.data.rows[i].机加工开始时间.substring(0, response.data.rows[i].机加工开始时间.indexOf(' '))
          response.data.rows[i].机加工结束时间 = response.data.rows[i].机加工结束时间.substring(0, response.data.rows[i].机加工结束时间.indexOf(' '))
        }
        for (let i = 0; i < response.data.rows.length; i++) {
          if (response.data.rows[i].是否预计外协 === '1') {
            response.data.rows[i].是否预计外协 = '否'
          } else {
            response.data.rows[i].是否预计外协 = '是'
          }
          this.预计外协.push(response.data.rows[i].是否预计外协)
          this.零件图号.push(response.data.rows[i].零件图号)
          this.工艺计划流水号.push(response.data.rows[i].工艺计划流水号)
          this.零件名称.push(response.data.rows[i].零件名称)
          this.投产数量.push(response.data.rows[i].投产数量)
          this.机加工开始时间.push(response.data.rows[i].机加工开始时间)
          this.机加工结束时间.push(response.data.rows[i].机加工结束时间)
          this.是否焊接.push(response.data.rows[i].是否焊接)
          this.平衡次数.push(response.data.rows[i].平衡次数)
          this.process[i] = []
          this.planDate[i] = []
          this.colorCode[i] = []
          this.realDate[i] = []
          this.result.push(response.data.rows[i])
          this.total1 = parseInt(response.data.total)
        }
        if (this.零件图号.length !== 0) {
          for (let i = 0; i < this.零件图号.length; i++) {
            selection2(this.工艺计划流水号[i]).then(response => {
              for (let k = 0; k < response.data.length; k++) {
                this.process[i][k] = response.data[k].工艺名称简称
                this.planDate[i][k] = response.data[k].计划日期_短
                this.colorCode[i][k] = response.data[k].颜色代码
                this.realDate[i][k] = response.data[k].工序工时
              }
              for (let m = 0; m < this.colorCode.length; m++) {
                for (let j = 0; j < this.colorCode[i].length; j++) {
                  if (this.process[m][j] === null) {
                    this.colorCode[m][j] = 'blank'
                  }
                  if (this.colorCode[m][j] === '') {
                    this.colorCode[m][j] = 'white'
                  }
                }
              }
            }).then(() => {
              this.tableData1.push(this.result[i])
              selection2(this.工艺计划流水号[this.indexAdjust]).then(response => { // 刷新对话框显示和颜色
                for (let i = 0; i < response.data.length; i++) {
                  this.partType = response.data[i].零件类型
                  this.tableData02 = response.data
                  this.工序顺序.push(response.data[i].工序顺序)
                  this.工序流水号.push(response.data[i].工序流水号)
                  this.工序名称.push(response.data[i].工艺名称简称)
                  this.工时.push(response.data[i].工序工时)
                  this.计划日期.push(response.data[i].计划日期)
                }
              })
              this.listLoading1 = false
            })
          }
        } else {
          this.tableData1 = []
          this.listLoading1 = false
          this.total1 = 0
        }
      })
    },
    // 板焊表单
    PlateWelding(index, row, formName) {
      this.count = this.count + 1
      if (this.count !== 1) {
        this.$refs[formName].resetFields()
      }
      this.form1.enddate = ''
      this.dialogFormVisible1 = true
      this.liushui = row.工艺计划流水号
      this.form1.enddate = row.板焊
    },
    // 板焊确定
    plateWelding() {
      platewelding(this.liushui, this.form1.enddate, this.form1.radio).then(response => {
        if (response.data[0].result === '1') {
          this.dialogFormVisible1 = false
          this.$message({
            type: 'success',
            message: '板焊结束时间修改成功!'
          })
          this.pageList = 1
          this.total = 0
          this.getTable()
        } else {
          this.dialogFormVisible1 = false
          this.$message.error('板焊结束时间修改失败')
        }
      })
    },
    submit1(formName) {
      if (this.form1.radio === '1') {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.plateWelding()
            this.$refs[formName].resetFields()
          } else {
            return false
          }
        })
      } else {
        this.plateWelding()
      }
    },
    // 重置表单
    callOff1(formName) {
      this.dialogFormVisible1 = false
      // this.$refs[formName].resetFields()
    },
    // 虚拟排产
    Discharge() {
      for (let i = 0; i < this.tableData1.length; i++) {
        this.bianliang1.push(this.tableData1[i].工艺计划流水号)
      }
      discharge(this.bianliang1).then(response => {
        this.Selection1()
      })
    },
    // 4.1 确定零件计划
    Plan() {
      if (this.tableData1.length === 0) {
        this.$message.error('请至少选择一个零件')
      } else {
        this.result1 = 0
        for (let i = 0; i < this.tableData1.length; i++) {
          this.length = this.tableData1.length
          out(this.tableData1[i].工艺计划流水号, 1).then(response => {
          }).then(() => {
            plan(this.tableData1[i].工艺计划流水号).then(response => {
              if (this.tableData1[i].平衡次数 !== 0 || this.tableData1[i].是否焊接 !== 1) {
                this.result1 += parseInt(response.data[0].result)
                if (this.result1 === this.length) {
                  this.$message.success('零件计划制定成功')
                  this.total1 = 0
                  this.pageList1 = 1
                  this.Selection1()
                } else if (response.data[0].result === '0') {
                  this.$message.error('第' + (i + 1) + '行制定失败')
                }
              }
            }).then(() => {
              if (this.tableData1[i].平衡次数 === 0 && this.tableData1[i].是否焊接 === 1) {
                han(this.tableData1[i].工艺计划流水号)
              }
            })
          })
        }
      }
    },
    // 零件计划变更2.1
    PartPlan() {
      if (this.startTime !== '' && this.startTime !== null) {
        if (this.endTime !== '' && this.endTime !== null) {
          this.shijiancuo1 = Date.parse(this.startTime)
          this.shijiancuo = Date.parse(this.endTime)
          this.jieguo = this.shijiancuo1 - this.shijiancuo
          if (this.jieguo >= 0) {
            this.$message.error('加工结束时间应大于开始时间')
          } else {
            if (this.multipleSelection.length === 0) {
              this.$message.error('请至少选择一个零件')
            } else {
              for (let i = 0; i < this.multipleSelection.length; i++) {
                partPlan(this.multipleSelection[i].工艺计划流水号, this.startTime, this.endTime).then(response => {
                  if (response.data.output[0].state === '0') {
                    if (i === this.multipleSelection.length - 1) {
                      this.$message.success('零件计划制定成功')
                      this.pageList = 1
                      this.total = 0
                      this.getTable()
                    }
                  } else if (response.data.output[0].state === '1') {
                    this.$message.error('请选择有效时间')
                  }
                })
              }
            }
          }
        } else {
          this.$message.error('请输入结束时间')
        }
      } else {
        this.$message.error('请输入开始时间')
      }
    },
    // 导出
    Export() {
      if (this.entryNameValue === '' && this.partNumber === '') {
        this.$message.error('请至少选择一个条件')
      } else {
        this.tableData2 = []
        if (this.entryNameValue === '') {
          this.checked_entryName = false
        } else {
          this.checked_entryName = true
        }
        if (this.toolNumValue === '') {
          this.checked_toolNum = false
        } else {
          this.checked_toolNum = true
        }
        if (this.NumValue === '') {
          this.checked_Num = false
        } else {
          this.checked_Num = true
        }
        if (this.partNumber !== '' && this.partNumber !== null) {
          this.checked_partNumber = true
        } else {
          this.checked_partNumber = false
        }
        Export(this.checked_entryName, this.entryNameValue, this.checked_toolNum, this.toolNumValue, this.checked_Num, this.NumValue, this.checked_partNumber, this.partNumber).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            this.tableData2.push({
              零件图号: response.data[i].零件图号,
              零件名称: response.data[i].零件名称,
              投产数量: response.data[i].投产数量,
              材质: response.data[i].材质,
              单价: response.data[i].单价,
              是否带料: response.data[i].是否带料,
              项目: response.data[i].项目,
              机加工结束时间: response.data[i].机加工结束时间,
              关注度: response.data[i].关注度,
              备注: response.data[i].备注
            })
          }
        }).then(() => {
          require.ensure([], () => {
            const { export_json_to_excel } = require('@/vendor/Export2Excel')
            const tHeader = ['零件图号', '零件名称', '投产数量', '材质', '单价', '是否带料', '项目', '机加工结束时间', '关注度', '备注']
            const filterVal = ['零件图号', '零件名称', '投产数量', '材质', '单价', '是否带料', '项目', '机加工结束时间', '关注度', '备注']
            const list = this.tableData2
            const data = this.formatJson(filterVal, list)
            export_json_to_excel(tHeader, data, 'OutPart')
          }).then(() => {
            this.total = 0
            this.pageList = 1
            this.getTable()
          })
        })
      }
    },
    // 导出方法
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    },
    // 分页
    handleSizeChange(val) {
      this.pageSize = val
      this.getTable()
    },
    handleCurrentChange(val) {
      this.pageList = val
      this.getTable()
    },
    handleSizeChange1(val) {
      this.pageSize1 = val
      this.Selection1()
    },
    handleCurrentChange1(val) {
      this.pageList1 = val
      this.Selection1()
    },
    handleSizeChange5(val) {
      this.pageSize5 = val
      this.getTable5()
    },
    handleCurrentChange5(val) {
      this.pageList5 = val
      this.getTable5()
    }
  }
}
</script>

<style scoped>
  .el-card{
    margin-bottom: 15px;
  }
  .el-date-editor{
    width: 200px;
  }
  span{
    margin: 10px 0 10px 10px;
  }
  .table h4{
    border: 1px solid transparent;
    margin: 0;
    font-weight: normal;
    width: 100px;
    height: 24px;
  }
</style>
<style>
  .white{
    background-color: ghostwhite!important;
    border: 1px solid #1f2d3d;
  }
  .red{
    background-color: orangered!important;
    border: 1px solid #1f2d3d;
  }
  .lightblue{
    background-color: #00afff!important;
    border: 1px solid #1f2d3d;
  }
  .yellow{
    background-color: yellow!important;
    border: 1px solid #1f2d3d;
  }
  .blank{
    background-color: transparent!important;
    border: 0px solid white;
  }
  .lightgreen{
    background-color: lightgreen!important;
    border: 1px solid #1f2d3d;
  }
</style>
