loulijun2021
2023-04-17 f6edee889e34cc5de979e05eac4dffe81e29a9f9
1.多排备份
已修改2个文件
2806 ■■■■■ 文件已修改
src/views/deviceManager/deviceGroup.vue 321 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/deviceManager/deviceType.vue 2485 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/deviceManager/deviceGroup.vue
@@ -1,3 +1,5 @@
<!--多排非页签形式-->
<template>
  <div>
    <div class="body" :style="{height:mainHeight+'px'}">
@@ -1178,7 +1180,9 @@
          startdate: handleDatetime(new Date()), // 当前日期(今天)
          enddate: row.AdvaScheEndDate //  要求交付时间
        })
        row.AdvaSchePiroQueNumber = row.AdvaSchePiroQue === '正常' ? 3 : row.AdvaSchePiroQue === '紧急' ? 2 : 1
      })
      const res = await NewOnclickAdvancedSchedulingDevice(DATA)
      // 如果Message有报错信息则终止执行后面逻辑
      if (res.rus.Message) {
@@ -1346,6 +1350,9 @@
        allCapacity.forEach(it => {
          if (item.wo_code === it.wo_code) {
            this.pushCapacity(everyEqpCapacity, it.id, it.gtArray)
            it.gtArray = it.gtArray.filter((currentValue, currentIndex, selfArr) => {
              return selfArr.findIndex(item => item.start === currentValue.start) === currentIndex
            })
            // it.gtArray.sort((a, b) => new Date(a.end).getTime() - new Date(b.end).getTime())
          }
        })
@@ -1367,14 +1374,34 @@
          }
        }
      }
      // 将工单的优先级进行排序,先以时间排,再以优先级排
      this.getMultipleSelectionOrder()
      // this.eqpTopTempData = JSON.parse(JSON.stringify(this.schedulingData))
      console.log(waitingForScheduling, 'waitingForScheduling')
      console.log(allCapacity, 'allCapacity')
      console.log(this.schedulingData, 'schedulingData')
      // console.log(JSON.stringify(this.schedulingData), 'schedulingData')
      console.log(this.schedulingAllData, 'schedulingAllData')
      console.log(everyEqpCapacity, 'everyEqpCapacity')
      // console.log(waitingForScheduling, 'waitingForScheduling')
      // console.log(allCapacity, 'allCapacity')
      // console.log(this.schedulingData, 'schedulingData')
      // // console.log(JSON.stringify(this.schedulingData), 'schedulingData')
      // console.log(this.schedulingAllData, 'schedulingAllData')
      // console.log(everyEqpCapacity, 'everyEqpCapacity')
    },
    // 将工单的优先级进行排序,先以时间排,再以优先级排
    getMultipleSelectionOrder() {
      // 1.先通过时间去重知道有哪几天的时间       // 2.遍历这几天的时间,过滤出相对应的工单
      const newArr = []
      this.multipleSelection.filter((currentValue, currentIndex, selfArr) => {
        return selfArr.findIndex(item => item.AdvaScheEndDate === currentValue.AdvaScheEndDate) === currentIndex
      }).map(i => i.AdvaScheEndDate).forEach(i => {
        newArr.push(this.multipleSelection.filter(j => j.AdvaScheEndDate === i))
      })
      // 根据日期相同的,工单优先级进行排序
      newArr.filter(i => {
        i.sort((a, b) => b.AdvaSchePiroQueNumber - a.AdvaSchePiroQueNumber)
      })
      // 排好之后  工单顺序就是整个的优先级
      this.multipleSelection = newArr.flat()// 二维转一维
    },
    // 时间/设备优先排程
    prepareArrange() {
@@ -1387,7 +1414,7 @@
      // 设备优先或者时间优先 对数据进行的格式转换
      if (this.schedulingData !== '' && this.formBottom.types === 'N') { // 设备优先
        this.eqpDataTransition()
        this.editLastValue(this.schedulingData)
        // this.editLastValue(this.schedulingData)
      } else if (this.timeTopTempData !== '' && this.formBottom.types === 'Y') { // 时间优先
        this.filterAlreadyScheduleTime() // 手动过滤所有时间已排程
        this.timeDataTransition()
@@ -1397,144 +1424,180 @@
    },
    // 设备优先   数据格式转换
    eqpDataTransition() {
      let needNumber = this.formBottom.needArrangeNumber // 需排数量
      let flag1 = 0
      console.log(this.schedulingData, 33)
      console.log(this.schedulingData.length, 33)
      for (const i in this.schedulingData) {
        console.log(i, '中国移动')
        let end_arr = [] // 已排程的数组
        let need_arr = [] // 待排程的数组
      const needNumber = this.formBottom.needArrangeNumber // 需排数量
        let capacity_arr = [] // 要排程的数组
        this.schedulingData[i].gtArray.sort((a, b) => new Date(a.end).getTime() - new Date(b.end).getTime())
      // 将产能的所有值与多选框的选中的行时间进行匹配校验 以便后续计算
      this.multipleSelection.forEach(item => {
        this.schedulingAllData.forEach(it => {
          // 找到工单所对应的设备进行计算排程   写出计算逻辑  这部分比较上头
          if (it.wo_code === item.AdvaScheWorkCode) {
            it.gtArray.forEach(i => {
              const t = i.start.split(' ')[0]
              // 代表当前工单下的产能是否可排
              i.status = new Date(t).getTime() <= new Date(item.AdvaScheEndDate).getTime()
        end_arr = JSON.parse(JSON.stringify(this.schedulingData[i].gtArray.filter(item => item.type === 'h_schedule'))) // 已排程数组
        need_arr = JSON.parse(JSON.stringify(this.schedulingData[i].gtArray.filter(item => item.type === 'capacity'))) // 容量
        console.log(need_arr, 5)
        console.log(JSON.stringify(need_arr))
              console.log(i)
        if (end_arr && end_arr.length > 0) {
          capacity_arr = need_arr.map(item => {
            // 排除掉已经排程的存在hshedule,start,end都相等的情况
            const schedule = end_arr.filter(it => {
              return new Date(item.start).getTime() <= new Date(it.start).getTime() &&
                new Date(item.end).getTime() >= new Date(it.end).getTime()
            })
              // 目前计算逻辑还不太清楚怎么写 太上头了
            if (schedule && schedule.length > 0) {
              item.start = this.MinutesTest(schedule[schedule.length - 1]['end'])
            }
              console.log(it.id, 'it')
            const schedule1 = end_arr.filter(schedule => {
              return new Date(item.start).getTime() === new Date(schedule.start).getTime() &&
                new Date(item.end).getTime() === new Date(schedule.end).getTime()
            })
            if (schedule1 && schedule1.length > 0) {
              item.capacity = false
            }
              const end_time = ''
              const mistiming = ''
              // 工单相同之后   应该根据时间优先或者设备优先  对设备进行一一排程
            return item
          }).filter(item => item.capacity !== false)
        } else {
          capacity_arr = need_arr
        }
        const id_obj = {
          id: '',
          start_time: ''
        }
        if (end_arr != '') {
          (id_obj.id = end_arr[0].id), (id_obj.start_time = end_arr[0].end)
        }
        capacity_arr = this.filterOutTime(capacity_arr) // 过滤掉当前时间之前的不能排程
        for (const w in capacity_arr) {
          console.log(capacity_arr[w], 'capacity_arr')
          let end_time = ''
          let mistiming = ''
              // 产能有几段 data的个数最多就有几个
          const data = {
            id: capacity_arr[w].id,
            start: '',
            end: '',
                id: it.id,
                start: '2023-04-17 13:00:00',
                end: '2023-04-17 16:00:00',
            type: 'schedule',
            cl_name: capacity_arr[w].partname, // 产品名称
            cl_code: capacity_arr[w].partcode, // 产品编码
            work_order: capacity_arr[w].work_order,
            AdvaScheUom: capacity_arr[w].AdvaScheUom,
                cl_name: item.AdvaSchePartName,
                cl_code: item.AdvaSchePartNumber,
                work_order: item.AdvaScheWorkCode,
                AdvaScheUom: item.AdvaScheUom,
            number: 0,
            real_number: 0
          }
          if (
            id_obj.start_time !== '' &&
            flag1 === 0 &&
            new Date(id_obj.start_time).getTime() >= new Date(capacity_arr[w].start).getTime()
          ) {
            data.start = this.MinutesTest(id_obj.start_time)
            flag1 = 1
          } else {
            data.start = capacity_arr[w].start
          }
          let nowTime = (this.schedulingData[i].AdvaDevicRhythm * needNumber) / capacity_arr[w].mod
          end_time = this.formSeconds(nowTime, data.start, capacity_arr[w].mod) // 总共的结束时间
          data.end = end_time
          mistiming = this.compareTime(
            end_time,
            capacity_arr[w].end,
            capacity_arr[w].mod
          ) // 总共的结束时间-当前的结束时间 = 剩下多久时间
          if (mistiming >= 0) {
            data.number =
              ((new Date(data.end) - new Date(data.start)) *
                capacity_arr[w].mod) /
              this.schedulingData[i].AdvaDevicRhythm /
              1000
            data.real_number =
              ((new Date(data.end) - new Date(data.start)) *
                capacity_arr[w].mod) /
              this.schedulingData[i].AdvaDevicRhythm /
              1000
            data.number = data.number.toFixed(0)
            data.end_num = true
            if (new Date(data.start) >= new Date(data.end)) {
            } else {
              this.schedulingData[i].gtArray.push(data)
            }
              // 这个地方不对   写不出来了
              // data.start = it.gtArray[0].start // 先只考虑一种情况
              // data.start = it.gtArray[0].start // 先只考虑一种情况
              data.number = '230'
              data.real_number = '230'
              const index = this.schedulingData.findIndex(i => i.id === it.id)
              this.schedulingData[index].gtArray.push(data)
            return false
          } else {
            data.end = capacity_arr[w].end
            if (new Date(data.end).getTime() < new Date(data.start)) {
              continue // 因为开始时间比结束时间大 需要跳过后面步骤
            })
            }
        })
      })
            // 这里除以一千是因为 new Date() 得到的是毫秒  毫秒转化为秒是千进制
            // 一段时间段内的生产量=两者时间差(毫秒)/1000  / 生产节拍 * 稼动率
            data.number =
              ((new Date(data.end) - new Date(data.start)) *
                capacity_arr[w].mod) /
              this.schedulingData[i].AdvaDevicRhythm /
              1000
      // 这个是计算出来的数值,需要push到schedulingData中
            data.real_number =
              ((new Date(data.end) - new Date(data.start)) *
                capacity_arr[w].mod) /
              this.schedulingData[i].AdvaDevicRhythm /
              1000
      //         'id': 'JG002',
      //         'start': '2023-04-17 10:10:21',
      //         'end': '2023-04-17 11:30:00',
      //         'type': 'schedule',
      //         'cl_name': '主机',
      //         'cl_code': '201',
      //         'work_order': 'MO-2023-04-0001_1',
      //         'AdvaScheUom': '个',
      //         'number': '64',
      //         'real_number': 63.72
            data.number = data.number.toFixed(0)
      // this.schedulingData = [
      //   {
      //     'id': 'JG002',
      //     'name': '精工设备2#',
      //     'AdvaDevicRhythm': '15.0',
      //     'status': true,
      //     'colorPair': {
      //       'dark': 'rgb(83, 186, 241,0.8)',
      //       'light': 'rgb(83, 186, 241,0.1)',
      //       'light_capacity': 'rgb(209,239,237,0.8)',
      //       'h_schedule': 'rgb(100,255,192,0.8)',
      //       'scheduleing': 'rgb(20,182,231,0.8)'
      //     },
      //     'gtArray': [
      //       {
      //         'start': '2023-04-17 08:00:00',
      //         'end': '2023-04-17 11:30:00',
      //         'id': 'JG002',
      //         'mod': 0.2,
      //         'type': 'capacity'
      //       },
      //       {
      //         'start': '2023-04-17 13:00:00',
      //         'end': '2023-04-17 18:00:00',
      //         'id': 'JG002',
      //         'mod': 0.2,
      //         'type': 'capacity'
      //       },
      //       {
      //         'id': 'JG002',
      //         'start': '2023-04-17 10:10:21',
      //         'end': '2023-04-17 11:30:00',
      //         'type': 'schedule',
      //         'cl_name': '主机',
      //         'cl_code': '201',
      //         'work_order': 'MO-2023-04-0001_1',
      //         'AdvaScheUom': '个',
      //         'number': '64',
      //         'real_number': 63.72
      //       },
      //       {
      //         'id': 'JG002',
      //         'start': '2023-04-17 13:00:00',
      //         'end': '2023-04-17 18:00:00',
      //         'type': 'schedule',
      //         'cl_name': '主机',
      //         'cl_code': '201',
      //         'work_order': 'MO-2023-04-0001_1',
      //         'AdvaScheUom': '个',
      //         'number': '240',
      //         'real_number': 240
      //       }
      //     ]
      //   },
      //   {
      //     'id': 'SB001',
      //     'name': '设备001',
      //     'AdvaDevicRhythm': '15.0',
      //     'status': true,
      //     'colorPair': {
      //       'dark': 'rgb(83, 186, 241,0.8)',
      //       'light': 'rgb(83, 186, 241,0.1)',
      //       'light_capacity': 'rgb(209,239,237,0.8)',
      //       'h_schedule': 'rgb(100,255,192,0.8)',
      //       'scheduleing': 'rgb(20,182,231,0.8)'
      //     },
      //     'gtArray': [
      //       {
      //         'start': '2023-04-17 08:00:00',
      //         'end': '2023-04-17 11:30:00',
      //         'id': 'SB001',
      //         'mod': 0.3,
      //         'type': 'capacity'
      //       },
      //       {
      //         'start': '2023-04-17 13:00:00',
      //         'end': '2023-04-17 18:00:00',
      //         'id': 'SB001',
      //         'mod': 0.3,
      //         'type': 'capacity'
      //       },
      //       {
      //         'id': 'SB001',
      //         'start': '2023-04-17 10:10:21',
      //         'end': '2023-04-17 11:30:00',
      //         'type': 'schedule',
      //         'cl_name': '主机',
      //         'cl_code': '201',
      //         'work_order': 'MO-2023-04-0001_1',
      //         'AdvaScheUom': '个',
      //         'number': '96',
      //         'real_number': 95.58
      //       },
      //       {
      //         'id': 'SB001',
      //         'start': '2023-04-17 13:00:00',
      //         'end': '2023-04-17 18:00:00',
      //         'type': 'schedule',
      //         'cl_name': '主机',
      //         'cl_code': '201',
      //         'work_order': 'MO-2023-04-0001_1',
      //         'AdvaScheUom': '个',
      //         'number': '360',
      //         'real_number': 360
      //       }
      //     ]
      //   }
      // ]
            nowTime = (needNumber - data.real_number) * this.schedulingData[i].AdvaDevicRhythm
            needNumber = needNumber - data.real_number
            if (new Date(data.start) >= new Date(data.end)) {
            } else {
              this.schedulingData[i].gtArray.push(data)
            }
          }
        }
      }
      console.log(this.schedulingData, 'schedulingData')
      console.log(this.schedulingAllData, 'schedulingAllData')
    },
    // 获取排程日期最大值
    getMaxPayDate() {
@@ -1733,7 +1796,7 @@
      }
    },
    // 设备优先   数据格式转换
    eqpDataTransition2() {
    eqpDataTransition2() { // 这里是原先的写法
      let needNumber = this.formBottom.needArrangeNumber // 需排数量
      let flag1 = 0
      console.log(this.schedulingData, 33)
src/views/deviceManager/deviceType.vue
@@ -1,11 +1,2490 @@
<template />
<!--多排页签形式-->
<template>
  <div>
    <div class="body" :style="{height:mainHeight+'px'}">
      <div class="bodyTopFormGroup" style="margin-top: 10px;padding-top: 10px">
        <el-form
          ref="form"
          :model="formTop"
          label-width="100px"
          inline
          style="display: flex;"
        >
          <div class="elForm">
            <el-form-item label="车间编码" style=" display: flex;">
              <el-input v-model="formTop.workshop" placeholder="请输入" style="width: 200px" />
            </el-form-item>
            <el-form-item label="生产工单号" style=" display: flex;">
              <el-input v-model="formTop.wocode" placeholder="请输入" style="width: 200px" />
            </el-form-item>
            <el-form-item label="物料编码" style=" display: flex;">
              <el-input v-model="formTop.partcode" placeholder="请输入" style="width: 200px" />
            </el-form-item>
            <el-form-item label="物料名称" style=" display: flex;">
              <el-input v-model="formTop.partname" placeholder="请输入" style="width: 200px" />
            </el-form-item>
          </div>
          <div
            class="bodySearchReset"
            :style="{marginLeft:$store.state.app.sidebar.opened? $store.state.settings.menuIsHorizontal?'15%':'3%':'10%'}"
          >
            <el-button v-waves type="primary" icon="el-icon-search" @click="search">查询</el-button>
            <el-button v-waves type="info" icon="el-icon-refresh" @click="reset">重置</el-button>
          </div>
        </el-form>
        <div
          class="bodyTopFormExpand"
          style="height: 5px"
        />
      </div>
      <div class="elTableDiv" style="margin-top: 0">
        <el-table
          ref="tableDataRef"
          class="tableFixed"
          :data="tableData"
          :height="(tableHeight-400)+'px'"
          border
          :row-class-name="tableRowClassName"
          :style="{width: 100+'%',height:(tableHeight-400)+'px',}"
          highlight-current-row
          :header-cell-style="this.$headerCellStyle"
          :cell-style="this.$cellStyle"
          @sort-change="sortChangeTop"
          @selection-change="handleSelectionChange"
        >
          <!--          @row-click="getCurrentRow"-->
          <!--          @selection-change="handleSelectionChange"-->
          <el-table-column
            type="selection"
            width="55"
          />
          <el-table-column
            prop="RowNum"
            width="50"
            fixed
            label="序号"
          />
          <el-table-column
            prop="AdvaSchePiroQue"
            show-tooltip-when-overflow
            label="优先级"
            width="90"
            sortable="custom"
          />
          <el-table-column
            prop="AdvaScheWorkShop"
            label="生产车间"
            width="110"
            show-tooltip-when-overflow
            sortable="custom"
          />
          <el-table-column
            prop="AdvaScheWorkCode"
            label="工单编号"
            min-width="160"
            show-tooltip-when-overflow
            sortable="custom"
          />
          <el-table-column
            prop="AdvaSchePartNumber"
            label="产品编码"
            min-width="110"
            show-tooltip-when-overflow
            sortable="custom"
          >
            <!--            <template slot-scope="{row}">-->
            <!--              <div v-if="row.AdvaSchePartNumber">{{ row.AdvaSchePartNumber }}</div>-->
            <!--              <div v-else>/</div>-->
            <!--            </template>-->
          </el-table-column>
          <el-table-column
            prop="AdvaSchePartName"
            min-width="160"
            show-tooltip-when-overflow
            label="产品名称"
            sortable="custom"
          />
          <el-table-column
            prop="AdvaSchePartSpec"
            label="产品规格"
            width="110"
            show-tooltip-when-overflow
            sortable="custom"
          >
            <template slot-scope="{row}">
              <div v-if="row.AdvaSchePartSpec">{{ row.AdvaSchePartSpec }}</div>
              <div v-else>/</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="AdvaScheQty"
            label="数量"
            show-tooltip-when-overflow
            width="110"
            sortable="custom"
          />
          <el-table-column
            prop="AdvaScheEndDate"
            label="要求交付时间"
            sortable="custom"
            show-tooltip-when-overflow
            width="160"
          />
          <el-table-column
            prop="AdvaScheStus"
            label="排程状态"
            show-tooltip-when-overflow
            width="110"
            sortable="custom"
          >
            <template slot-scope="{row}">
              <div v-if="row.AdvaScheStus==='NOSCHED'">待排程</div>
              <div v-if="row.AdvaScheStus==='SCHED'">已排程</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="AdvaScheBotProcName"
            label="排程工序"
            show-tooltip-when-overflow
            width="110"
            sortable="custom"
          />
          <el-table-column
            prop="AdvaSchePCStartDate"
            label="计划排程时间"
            width="200"
            sortable="custom"
            show-tooltip-when-overflow
          >
            <template slot-scope="{row}">
              <div v-if="row.AdvaSchePCStartDate">{{ row.AdvaSchePCStartDate }} ~ {{ row.AdvaSchePCEndDate }}</div>
              <div v-else>/</div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--分页-->
      <pagination
        :total="totalTop"
        :page.sync="formTop.page"
        :limit.sync="formTop.rows"
        align="right"
        layout="total,prev, pager, next,sizes"
        popper-class="select_bottom"
        @pagination="getAdvancedSchedulingSearch"
      />
      <!--      自动排程部分的代码-->
      <div class="autoScheduling">
        <div class="bodyTopFormGroup">
          <el-form
            ref="form"
            :model="formBottom"
            inline
            label-width="100px"
            style="display: flex;"
          >
            <div class="elForm">
              <el-form-item label="排程日期" style=" display: flex;">
                <el-date-picker
                  v-model="formBottom.scheDate"
                  :disabled="multipleSelection.length===0"
                  type="daterange"
                  range-separator="~"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  size="small"
                  :picker-options="pickerOptions1"
                  :clearable="false"
                  @change="dateChange"
                />
              </el-form-item>
              <el-form-item label="排程方式" style=" display: flex;">
                <el-select
                  v-model="formBottom.types"
                  :disabled="multipleSelection.length===0"
                  style="width:120px"
                  @change="typesChange"
                >
                  <el-option value="N" label="设备优先" />
                  <el-option value="Y" label="时间优先" />
                </el-select>
              </el-form-item>
              <el-form-item label="时间刻度(分钟)" label-width="110" style=" display: flex;">
                <el-select
                  v-model.number="formBottom.scale"
                  :disabled="multipleSelection.length===0"
                  style="width: 120px;"
                >
                  <el-option v-for="item in scaleList" :key="item" :value="item" :label="item" />
                </el-select>
              </el-form-item>
              <el-form-item label="换型时间(分钟)" label-width="110" style=" display: flex;">
                <el-input
                  id="scale"
                  v-model="formBottom.times"
                  :disabled="multipleSelection.length===0"
                  type="number"
                  style="display:inline-block;width:80px;"
                  @change="no_zero"
                />
              </el-form-item>
              <el-form-item label="预排进度" style=" display: flex;">
                <span>
                  <span style="text-decoration:underline;">{{ formBottom.canArrangeNumber }}</span> /
                  <span style="text-decoration:underline">{{ formBottom.needArrangeNumber }}</span>
                </span>
              </el-form-item>
            </div>
            <div
              class="bodySearchReset"
              :style="{marginLeft:$store.state.app.sidebar.opened? $store.state.settings.menuIsHorizontal?'15%':'3%':'10%'}"
            >
              <el-button
                v-waves
                :disabled="multipleSelection.length===0"
                type="primary"
                icon="el-icon-document-remove"
                @click="prepareArrange"
              >预排
              </el-button>
              <el-button
                v-waves
                type="primary"
                :disabled="multipleSelection.length===0"
                icon="el-icon-document-checked"
                @click="prepareSubmit"
              >提交
              </el-button>
            </div>
          </el-form>
          <div class="colorDescription">
            <div class="colorDescriptionItem"><i
              class="el-icon-s-opportunity"
              style="margin-right: 5px;color: rgba(5, 185, 100, 0.5)"
            />产能
            </div>
            <div class="colorDescriptionItem"><i
              class="el-icon-s-opportunity"
              style="margin-right: 5px;color: rgba(5, 185, 100, 1)"
            />已排
            </div>
            <div class="colorDescriptionItem"><i
              class="el-icon-s-opportunity"
              style="margin-right: 5px;color:rgba(128,0,128,0.7)"
            />预排
            </div>
            <div>
              <el-tag
                v-for="item in multipleSelection"
                :key="item.AdvaScheId"
                :effect="item.isPlain"
                style="margin-right: 10px"
                @click="isPlainClick(item)"
              >
                {{ item.AdvaScheWorkCode }}
              </el-tag>
            </div>
            <!--            <div class="colorDescriptionItem"><i class="el-icon-s-opportunity" style="margin-right: 5px;color: #a7a7a7" />失效产能</div>-->
          </div>
          <div
            class="bodyTopFormExpand"
            style="height: 5px"
          />
        </div>
        <!--
    字段描述:
        1.schedulingData:数组,是所有产能的每一行的汇总
        2.data:对象,是一行内每一个产能的汇总
        3.item:对象,是每一个产能条
        -->
        <!--        {{ schedulingData }}-->
        <div class="container" style="margin: 10px;">
          <v-gantt-chart
            :start-time="time_data[0]"
            :end-time="time_data[1]"
            :cell-width="cellWidth"
            :cell-height="cellHeight"
            :title-height="titleHeight"
            :scale="formBottom.scale"
            :title-width="titleWidth"
            show-current-time
            :hide-header="hideHeader"
            :data-key="dataKey"
            :array-keys="arrayKeys"
            :datas="schedulingData"
          >
            <!--            暂时用不到-->
            <!--            :time-lines="timeLines"-->
            <!--            @scrollLeft="scrollLeftA"-->
            <!--            :scroll-to-postion="positionA"-->
            <template slot="block" slot-scope="{data,item}">
              <Scheduling
                :data="data"
                :cell-height="cellHeight"
                :item="item"
              />
              <!--              暂时用不到-->
              <!--              :update-time-lines="updateTimeLines"-->
              <!--              :current-time="currentTime"-->
            </template>
            <template slot="left" slot-scope="{data}">
              <div class="name">
                <div class="carId">
                  <el-checkbox
                    v-model="data.status"
                    style="margin-right:5px;"
                    @change="checkboxSingle(data)"
                  />
                  {{ data.id }} {{ data.name }}
                </div>
                <div class="speed">
                  <!--                  <el-tooltip class="item" effect="dark" content="查看" placement="top">-->
                  <!--                    <el-button v-waves type="text" size="mini" @click="look(data)">-->
                  <!--                      <i class="el-icon-document size i-color"  />-->
                  <!--                    </el-button>-->
                  <!--                  </el-tooltip>-->
                </div>
              </div>
            </template>
            <template slot="title">
              <span class="tc">工位列表</span>
              <el-checkbox
                v-model="ganttCheckboxAll"
                class="box_style"
                :disabled="multipleSelection.length===0"
                @change="checkboxAll()"
              />
              <input
                v-model.number="cellWidth"
                type="range"
                min="20"
                max="100"
                class="box_styles"
                :disabled="multipleSelection.length===0"
              >
            </template>
          </v-gantt-chart>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
import Scheduling from '@/components/Scheduling'
import dayjs from 'dayjs'
import {
  AdvancedSchedulingSearch, NewOnclickAdvancedSchedulingDevice,
  OnclickAdvancedSchedulingDevice,
  SubmitAlreadyScheduling
} from '@/api/produceManager'
import { handleDatetime, handleDatetime2 } from '@/utils/global'
import waves from '@/directive/waves'
import template from '@/views/template'
export default {
  name: 'Sblx'
  name: 'Zzjg',
  components: {
    Pagination, Scheduling
  },
  directives: { waves },
  data() {
    return {
      mouseHoverType: 'mouseout',
      isExpandForm: false,
      mainHeight: 0,
      tableHeight: 0,
      formTop: {
        workshop: '', // 车间编码
        wocode: '', // 生产工单号
        partcode: '', // 物料编码
        partname: '', // 物料名称
        prop: 'AdvaScheWorkCode', // 排序字段
        order: 'desc', // 排序字段
        page: 1, // 第几页
        rows: 20 // 每页多少条
      },
      totalTop: 10, // 总共多少条
      tableData: [],
      multipleSelection: [],
      /*
    排程部分的属性
    * */
      show: false,
      pickerOptions1: {
        disabledDate(time) {
          return time.getTime() <= Date.now() - 24 * 60 * 60 * 1000
        }
      },
      ganttCheckboxAll: true, // 甘特图左侧复选框是否选中或者取消
      ganttLeftArrId: [], // 甘特图左侧的数组id
      cl_name: '', // 产品名称
      cl_code: '', // 产品编码
      work_order: '', // 工单编号
      AdvaScheUom: '', // 产品单位
      time_data: [[handleDatetime(new Date()) + ' 00:00:00'], [handleDatetime(new Date()) + ' 00:00:00']], // 甘特图初始渲染的时间范围
      forms: { // 点击行获取信息 请求接口 的数据对象
        wocode: '', // 工单编号
        wkshpcode: '', // 车间编码
        partcode: '', // 物料编码
        botproccode: '', // 瓶颈工序编码(首道工序)
        startdate: '', // 开始日期
        enddate: ''// 结束日期
      },
      formsTempArr: [], // 表单数组形式存储
      formBottom: { // 底部表单的 数据对象
        scheDate: [handleDatetime(new Date()), handleDatetime(new Date())], // 排程日期
        types: 'N', // 排程方式
        scale: 60, // 时间刻度
        times: 0, // 换型时间
        canArrangeNumber: 0, // 可排数量
        needArrangeNumber: 0// 需排数量
      },
      schedulingAllData: [], // 排程的所有数据
      schedulingData: [], // 排程的最终数据
      timeTopTempData: [], // 时间优先的临时数据
      eqpTopTempData: [], //  设备优先的临时数据
      formUpdate: {
        WorkCode: '',
        BotProceCode: '',
        json: []
      },
      // currentTime: dayjs(),
      cellWidth: 50,
      cellHeight: 30,
      titleHeight: 40,
      titleWidth: 250,
      dataKey: 'id', // 相当于是设备code做唯一字符
      scaleList: `30,60,240,360`.split(',').map(n => parseInt(n)), // 时间刻度(分钟)
      hideHeader: false,
      arrayKeys: ['gtArray', 'error']
    }
  },
  created() {
    const loading = this.$loading({
      lock: true,
      text: '正在加载数据,请稍等...',
      spinner: 'el-icon-loading',
      customClass: 'osloading',
      background: 'rgba(0, 0, 0, 0.7)'
    })
    setTimeout(() => {
      if (this.getAdvancedSchedulingSearch()) {
        loading.close()
      }
    }, 3000)
    // this.getAdvancedSchedulingSearch()
  },
  mounted() {
    window.addEventListener('resize', this.getHeight)
    this.getHeight()
  },
  methods: {
    async getAdvancedSchedulingSearch() {
      const res = await AdvancedSchedulingSearch(this.formTop)
      this.tableData = res.data
      this.totalTop = res.count
      this.tableData.forEach(row => {
        row.AdvaSchePiroQueNumber = row.AdvaSchePiroQue === '正常' ? 3 : row.AdvaSchePiroQue === '紧急' ? 2 : 1
      })
      const newArr = []
      this.tableData.filter((currentValue, currentIndex, selfArr) => {
        return selfArr.findIndex(item => item.AdvaScheEndDate === currentValue.AdvaScheEndDate) === currentIndex
      }).map(i => i.AdvaScheEndDate).forEach(i => {
        newArr.push(this.tableData.filter(j => j.AdvaScheEndDate === i))
      })
      // 根据日期相同的,工单优先级进行排序
      newArr.filter(i => {
        i.sort((a, b) => b.AdvaSchePiroQueNumber - a.AdvaSchePiroQueNumber)
      })
      // 排好之后  工单顺序就是整个的优先级
      this.tableData = newArr.flat()// 二维转一维
      this.tableData.reverse()
      return true
    },
    // 排序改变时
    sortChangeTop({ column, prop, order }) {
      if (order === 'descending') {
        order = 'desc'
      } else if (order === 'ascending') {
        order = 'asc'
      } else {
        order = 'desc'
      }
      this.formTop.order = order
      this.formTop.prop = prop
      this.getAdvancedSchedulingSearch()
    },
    // 查询
    search() {
      this.getAdvancedSchedulingSearch()
    },
    // 重置
    reset() {
      this.formTop.workshop = ''
      this.formTop.wocode = ''
      this.formTop.partcode = ''
      this.formTop.partname = ''
      this.getAdvancedSchedulingSearch()
      this.schedulingData = [] // 排程数据置空
    },
    // 获取页面高度
    getHeight() {
      this.$nextTick(() => {
        this.mainHeight = window.innerHeight - 85
        this.tableHeight = this.mainHeight - 255
        this.$refs.tableDataRef.doLayout()
      })
    },
    tableRowClassName({ row, rowIndex }) {
      return 'custom-row'
    },
    /*
     排程部分的方法
     */
    // 确保换型时间为非负数
    no_zero() {
      if (this.formBottom.times < 0) {
        this.formBottom.times = 0
      }
    },
    // 排程方式改变
    typesChange() {
      this.getOnclickAdvancedSchedulingDevice()
    },
    // 排程日期值改变时
    dateChange() {
      this.time_data[0] = this.formBottom.scheDate[0] + ' 00:00'
      this.time_data[1] = this.formBottom.scheDate[1] + ' 23:59'
      this.forms.startdate = this.formBottom.scheDate[0]
      this.forms.enddate = this.formBottom.scheDate[1]
      this.getOnclickAdvancedSchedulingDevice()
    },
    // 工位列表复选框操作  (全选、全不选)
    checkboxAll() {
      if (this.ganttCheckboxAll) { // 复选框从取消到选中
        console.log('003')
        this.ganttLeftArrId = []
        // 这里要进行forEach循环遍历
        // 先用一个临时数组对象存储需请求接口的forms信息
        let tempArr = []
        this.schedulingData.forEach(val => {
          val.status = true
          tempArr.push({
            wocode: val.wocode, // 工单编号
            wkshpcode: val.wkshpcode, // 车间编码
            partcode: val.partcode, // 产品编码
            botproccode: val.botproccode, // 工艺路线编码
            startdate: val.startdate, // 当前日期(今天)
            enddate: val.enddate //  要求交付时间
          })
        })
        // 数组对象去重
        tempArr = tempArr.filter((currentValue, currentIndex, selfArr) => {
          return selfArr.findIndex(item => item.wocode === currentValue.wocode) === currentIndex
        })
        tempArr.forEach(i => {
          setTimeout(() => {
            console.log('国宾府', i)
            this.forms = i
            this.getOnclickAdvancedSchedulingDevice()
            // this.$forceUpdate()
          })
        })
      } else { // 复选框从选中到取消
        console.log('004')
        for (const i in this.schedulingData) {
          this.schedulingData[i].status = false
          this.schedulingData[i].gtArray = []
        }
        for (const i in this.timeTopTempData) {
          this.timeTopTempData[i].gtArray = []
        }
      }
      // this.prepareArrange()
    },
    // 甘特图左侧checkbox值选中或者取消时
    // checkboxSingle(val) {
    //   console.log(val, 'xaxaxa')
    //   console.log(val.status)
    // },
    checkboxSingle(val) {
      console.log(val, 'xaxaxa')
      if (!val.status) { // 复选框状态从选中到取消
        console.log('001')
        for (const i in this.timeTopTempData) {
          const new_arr = []
          for (const j in this.timeTopTempData[i].gtArray) {
            if (this.timeTopTempData[i].gtArray[j].id === val.id) {
            } else {
              new_arr.push(this.timeTopTempData[i].gtArray[j])
            }
          }
          this.timeTopTempData[i].gtArray = new_arr
        }
      } else { // 复选框状态从取消到选中
        console.log('002')
        this.ganttLeftArrId = []
        for (const i in this.schedulingData) {
          if (!this.schedulingData[i].status) {
            this.ganttLeftArrId.push(this.schedulingData[i].id)
          }
        }
        this.forms = {
          wocode: val.wocode, // 工单编号
          wkshpcode: val.wkshpcode, // 车间编码
          partcode: val.partcode, // 产品编码
          botproccode: val.botproccode, // 工艺路线编码
          startdate: val.startdate, // 当前日期(今天)
          enddate: val.enddate //  要求交付时间
        }
        this.getOnclickAdvancedSchedulingDevice()
      }
      if (!val.status) { // 复选框状态从选中到取消
        console.log('005')
        for (const i in this.schedulingData) {
          if (!this.schedulingData[i].status) {
            this.schedulingData[i].gtArray = []
          }
        }
      } else { // 复选框状态从取消到选中
        console.log('006')
        this.ganttLeftArrId = []
        for (const i in this.schedulingData) {
          if (!this.schedulingData[i].status) {
            this.ganttLeftArrId.push(this.schedulingData[i].id)
          }
        }
        this.getOnclickAdvancedSchedulingDevice()
      }
      for (const i in this.schedulingData) {
        const arr = []
        for (const j in this.schedulingData[i].gtArray) {
          if (this.schedulingData[i].gtArray[j].type !== 'schedule') {
            arr.push(this.schedulingData[i].gtArray[j])
          }
        }
        this.schedulingData[i].gtArray = arr
      }
      this.formBottom.canArrangeNumber = 0
      // this.prepareArrange()
    },
    // 点击带出数据
    async getOnclickAdvancedSchedulingDevice2() {
      console.log(this.forms, 302)
      this.formsTempArr.push(this.forms)
      this.formsTempArr = this.formsTempArr.filter((currentValue, currentIndex, selfArr) => {
        return selfArr.findIndex(item => item.wocode === currentValue.wocode) === currentIndex
      })
      console.log(JSON.stringify(this.formsTempArr))
      const res = await OnclickAdvancedSchedulingDevice(this.forms)
      if (res.rus.Message) {
        return this.$message.error(res.rus.Message)
      }
      const data = res.rows // 拿到待排数据  对数据进行改造
      const cont = res.Cont // 拿到已排数据  对数据进行改造
      this.formBottom.canArrangeNumber = 0
      // 找到index值
      // const index = this.formsTempArr.findIndex(i => i.wocode === this.forms.wocode)
      // 将五个时间段进行赋值    拿到后端的接口格式,改成前端所需的格式
      data.forEach(item => {
        item.children.forEach(it => {
          if (it.OneStartDate !== '') {
            it.OneStartDate = it.OneStartDate.split('~')
            it.OneStartDate[0] = item.YearDate + ' ' + it.OneStartDate[0] + ':00'
            it.OneStartDate[1] = item.YearDate + ' ' + it.OneStartDate[1] + ':00'
          }
          if (it.TwoStartDate !== '') {
            it.TwoStartDate = it.TwoStartDate.split('~')
            it.TwoStartDate[0] = item.YearDate + ' ' + it.TwoStartDate[0] + ':00'
            it.TwoStartDate[1] = item.YearDate + ' ' + it.TwoStartDate[1] + ':00'
          }
          if (it.ThreeStartDate !== '') {
            it.ThreeStartDate = it.ThreeStartDate.split('~')
            it.ThreeStartDate[0] = item.YearDate + ' ' + it.ThreeStartDate[0] + ':00'
            it.ThreeStartDate[1] = item.YearDate + ' ' + it.ThreeStartDate[1] + ':00'
          }
          if (it.FourStartDate !== '') {
            it.FourStartDate = it.FourStartDate.split('~')
            it.FourStartDate[0] = item.YearDate + ' ' + it.FourStartDate[0] + ':00'
            it.FourStartDate[1] = item.YearDate + ' ' + it.FourStartDate[1] + ':00'
          }
          if (it.FiveStartDate !== '') {
            it.FiveStartDate = it.FiveStartDate.split('~')
            it.FiveStartDate[0] = item.YearDate + ' ' + it.FiveStartDate[0] + ':00'
            it.FiveStartDate[1] = item.YearDate + ' ' + it.FiveStartDate[1] + ':00'
          }
        })
      })
      // 构建 按设备优先排程的 数据格式 schedulingData
      const list = [] // 临时list  暂存    代表的是所有的产能
      console.log(this.forms.wocode, ' this.forms.wocode')
      console.log(data, 'xxx1')
      data[0].children.forEach(item => {
        const obj = {
          // 新增五个参数
          // wocode: this.formsTempArr[index].wocode, // 工单编号
          // wkshpcode: this.formsTempArr[index].wkshpcode, // 车间编码
          // partcode: this.formsTempArr[index].partcode, // 产品编码
          // botproccode: this.formsTempArr[index].botproccode, // 工艺路线编码
          // startdate: this.formsTempArr[index].startdate, // 当前日期(今天)
          // enddate: this.formsTempArr[index].enddate, //  要求交付时间
          wocode: this.forms.wocode, // 工单编号
          wkshpcode: this.forms.wkshpcode, // 车间编码
          partcode: this.forms.partcode, // 产品编码
          botproccode: this.forms.botproccode, // 工艺路线编码
          startdate: this.forms.startdate, // 当前日期(今天)
          enddate: this.forms.enddate, //  要求交付时间
          id: '', // 设备的code
          name: '', // 设备名称
          AdvaDevicRhythm: '', // 节拍多少秒生产一个(生产节拍)
          status: true, // 甘特图左侧复选框是否是选中状态   当为true时渲染  为false时 不渲染产能
          colorPair: { // 颜色集    不同状态下的甘特图的颜色  (目前的理解)
            dark: 'rgb(83, 186, 241,0.8)',
            light: 'rgb(83, 186, 241,0.1)',
            light_capacity: 'rgb(209,239,237,0.8)',
            h_schedule: 'rgb(100,255,192,0.8)',
            scheduleing: 'rgb(20,182,231,0.8)'
          },
          gtArray: [] // 甘特图的每一个子项
        }
        // 将接口返回的设备编码,设备名称,生产节拍赋值给obj
        obj.id = item.AdvaDevicNumber
        obj.name = item.AdvaDevicName
        obj.AdvaDevicRhythm = item.AdvaDevicRhythm
        list.push(obj)
      })
      // 组合新的结构     浅绿色背景条
      const newList = []
      for (const i in data) {
        for (const j in data[i].children) {
          if (data[i].children[j].OneStartDate !== '') {
            const data1 = {
              id: '',
              start: '',
              end: '',
              mod: ''
            }
            data1.id = data[i].children[j].AdvaDevicNumber
            data1.start = data[i].children[j].OneStartDate[0]
            data1.end = data[i].children[j].OneStartDate[1]
            // AdvaDevicCropMob 稼动率     AdvaDevicRhythm  生产节拍
            data1.mod = (data[i].children[j].AdvaDevicCropMob * 1) / 100 // 稼动率
            newList.push(data1)
          }
          if (data[i].children[j].TwoStartDate !== '') {
            const data2 = {
              id: '',
              start: '',
              end: '',
              mod: ''
            }
            data2.id = data[i].children[j].AdvaDevicNumber
            data2.start = data[i].children[j].TwoStartDate[0]
            data2.end = data[i].children[j].TwoStartDate[1]
            data2.mod = (data[i].children[j].AdvaDevicCropMob * 1) / 100
            newList.push(data2)
          }
          if (data[i].children[j].ThreeStartDate !== '') {
            const data3 = {
              id: '',
              start: '',
              end: '',
              mod: ''
            }
            data3.id = data[i].children[j].AdvaDevicNumber
            data3.start = data[i].children[j].ThreeStartDate[0]
            data3.end = data[i].children[j].ThreeStartDate[1]
            data3.mod = (data[i].children[j].AdvaDevicCropMob * 1) / 100
            newList.push(data3)
          }
          if (data[i].children[j].FourStartDate !== '') {
            const data4 = {
              id: '',
              start: '',
              end: '',
              mod: ''
            }
            data4.id = data[i].children[j].AdvaDevicNumber
            data4.start = data[i].children[j].FourStartDate[0]
            data4.end = data[i].children[j].FourStartDate[1]
            data4.mod = (data[i].children[j].AdvaDevicCropMob * 1) / 100
            newList.push(data4)
          }
          if (data[i].children[j].FiveStartDate !== '') {
            const data5 = {
              id: '',
              start: '',
              end: '',
              mod: ''
            }
            data5.id = data[i].children[j].AdvaDevicNumber
            data5.start = data[i].children[j].FiveStartDate[0]
            data5.end = data[i].children[j].FiveStartDate[1]
            data5.mod = (data[i].children[j].AdvaDevicCropMob * 1) / 100
            newList.push(data5)
          }
        }
      }
      // 插入产能时间段    产能数据都在gtArray里面
      for (const i in list) {
        this.pushItem(newList, list[i].id, list[i].gtArray)
      }
      // this.schedulingData = list
      // 上面注释代码只适合list数组长度为一的时候,是不对的,下面逻辑进行优化
      // 判断当前点击行的数据请求接口数据   是否已经在排程数组内
      list.forEach((item, index) => {
        const flag = this.schedulingData.map(i => i.id).includes(list[index].id)
        if (!flag) { // 当设备code不在排程数组内时   直接push排程数组即可
          this.schedulingData.push(list[index])
        } else { // 当已经在排程数组内时   应该判断时间取并集
          const ind = this.schedulingData.findIndex(i => i.id === list[index].id)
          const tempGtArray = [...new Set(this.schedulingData[ind].gtArray.concat(list[index].gtArray))]
          // 数组中对象相同的去重
          this.schedulingData[ind].gtArray = tempGtArray.filter((currentValue, currentIndex, selfArr) => {
            return selfArr.findIndex(item => item.start === currentValue.start) === currentIndex
          })
        }
      })
      if (cont !== '') { // 对已排的产能进行数组重组
        for (const i in cont) {
          for (const j in this.schedulingData) {
            if (this.schedulingData[j].id === cont[i].eqp_code) { // 当设备code相等时
              const data = {
                id: cont[i].eqp_code,
                number: cont[i].alloc_qty,
                cl_name: cont[i].part_name,
                cl_code: cont[i].part_code,
                AdvaScheUom: cont[i].uom_name, // 单位
                work_order: cont[i].wo_code,
                start: cont[i].time_start,
                end: cont[i].time_end,
                // type: cont[i].status === 'S' ? 'h_schedule' : 'bm_schedule'
                type: 'h_schedule'
              }
              this.schedulingData[j].gtArray.unshift(data)
            }
          }
        }
      }
      // console.log(this.ganttLeftArrId)
      if (this.ganttLeftArrId !== '') {
        // console.log('ykxkd')
        for (const j in this.schedulingData) {
          // console.log(this.ganttLeftArrId.indexOf(this.schedulingData[j].id) >= 0)  //false
          if (this.ganttLeftArrId.indexOf(this.schedulingData[j].id) >= 0) {
            this.schedulingData[j].gtArray = []
            this.schedulingData[j].status = false
          }
        }
      }
      // 设备优先的数据格式
      // this.eqpTopTempData = []
      // console.log(this.schedulingData, 30)
      // console.log(data, 30)
      // for (const i in data[0].children) {
      //   console.log(i, '特斯拉')
      //   const obj = {
      //     id: '',
      //     name: '',
      //     status: true,
      //     AdvaDevicRhythm: '',
      //     // mod:'',
      //     colorPair: {
      //       dark: 'rgb(83, 186, 241,0.8)',
      //       light: 'rgb(83, 186, 241,0.1)',
      //       light_capacity: 'rgb(209,239,237,0.8)',
      //       h_schedule: 'rgb(100,255,192,0.8)',
      //       scheduleing: 'rgb(20,182,231,0.8)'
      //     },
      //     gtArray: []
      //   }
      //   obj.id = data[0].children[i].AdvaDevicNumber
      //   obj.name = data[0].children[i].AdvaDevicName
      //   obj.AdvaDevicRhythm = data[0].children[i].AdvaDevicRhythm
      //   // obj.mod =data[0].children[i].AdvaDevicCropMob *1
      //
      //   this.eqpTopTempData.push(obj)
      // }
      // 上面的注释代码可以换成下面这行代码
      this.eqpTopTempData = JSON.parse(JSON.stringify(this.schedulingData))
      // 更改格式
      // this.timeTopTempData = []
      console.log(data, 31)
      // 构建按时间优先的排程数据格式 timeTopTempData
      for (const i in data) {
        const time = {
          date: data[i].YearDate, // 日期
          AdvaDevicRhythm: '', // 生产节拍
          gtArray: []
        }
        if (data[i].children !== '') {
          time.AdvaDevicRhythm = data[i].children[0].AdvaDevicRhythm
        }
        for (const j in data[i].children) {
          if (data[i].children[j].OneStartDate !== '') {
            const icu1 = {
              name: data[i].children[j].AdvaDevicName,
              id: data[i].children[j].AdvaDevicNumber,
              type: 'capacity',
              rhythm: data[i].children[j].AdvaDevicRhythm, // 生产节拍
              start: data[i].children[j].OneStartDate[0],
              end: data[i].children[j].OneStartDate[1],
              mod: (data[i].children[j].AdvaDevicCropMob * 1) / 100
            }
            time.gtArray.push(icu1)
          }
          if (data[i].children[j].TwoStartDate !== '') {
            const icu2 = {
              name: data[i].children[j].AdvaDevicName,
              id: data[i].children[j].AdvaDevicNumber,
              type: 'capacity',
              rhythm: data[i].children[j].AdvaDevicRhythm,
              start: data[i].children[j].TwoStartDate[0],
              end: data[i].children[j].TwoStartDate[1],
              mod: (data[i].children[j].AdvaDevicCropMob * 1) / 100
            }
            time.gtArray.push(icu2)
          }
          if (data[i].children[j].ThreeStartDate !== '') {
            const icu3 = {
              name: data[i].children[j].AdvaDevicName,
              id: data[i].children[j].AdvaDevicNumber,
              type: 'capacity',
              rhythm: data[i].children[j].AdvaDevicRhythm,
              start: data[i].children[j].ThreeStartDate[0],
              end: data[i].children[j].ThreeStartDate[1],
              mod: (data[i].children[j].AdvaDevicCropMob * 1) / 100
            }
            time.gtArray.push(icu3)
          }
          if (data[i].children[j].FourStartDate !== '') {
            const icu4 = {
              name: data[i].children[j].AdvaDevicName,
              id: data[i].children[j].AdvaDevicNumber,
              type: 'capacity',
              rhythm: data[i].children[j].AdvaDevicRhythm,
              start: data[i].children[j].FourStartDate[0],
              end: data[i].children[j].FourStartDate[1],
              mod: (data[i].children[j].AdvaDevicCropMob * 1) / 100
            }
            time.gtArray.push(icu4)
          }
          if (data[i].children[j].FiveStartDate !== '') {
            const icu5 = {
              name: data[i].children[j].AdvaDevicName, // 设备名称
              id: data[i].children[j].AdvaDevicNumber, // 设备code
              type: 'capacity', // 产能
              rhythm: data[i].children[j].AdvaDevicRhythm, // 生产节拍
              start: data[i].children[j].FiveStartDate[0], // 开始时间
              end: data[i].children[j].FiveStartDate[1], // 结束时间
              mod: (data[i].children[j].AdvaDevicCropMob * 1) / 100 // 稼动率
            }
            time.gtArray.push(icu5)
          }
        }
        this.timeTopTempData.push(time)
        // console.log(this.timeTopTempData)
      }
      if (cont !== '') {
        for (const i in cont) {
          for (const j in this.timeTopTempData) {
            const data = {
              id: cont[i].eqp_code,
              date: cont[i].time_start.split(' ')[0],
              number: cont[i].alloc_qty,
              cl_name: cont[i].part_name,
              cl_code: cont[i].part_code,
              AdvaScheUom: cont[i].uom_name, // 单位
              work_order: cont[i].wo_code,
              start: cont[i].time_start,
              end: cont[i].time_end,
              type: 'h_schedule'
            }
            if (this.timeTopTempData[j].date === data.date) {
              this.timeTopTempData[j].gtArray.unshift(data)
            }
          }
        }
      }
      console.log(JSON.parse(JSON.stringify(this.eqpTopTempData)), 7)
      console.log(this.timeTopTempData, 8)
      this.$forceUpdate()
    },
    // 换型时间
    MinutesTest(time) {
      const t = new Date(time)
      t.setMinutes(t.getMinutes() + this.formBottom.times * 1)
      const now =
        t.getFullYear() +
        '-' +
        (t.getMonth() + 1).toString().padStart(2, '0') +
        '-' +
        t.getDate().toString().padStart(2, '0') +
        ' ' +
        t.getHours().toString().padStart(2, '0') +
        ':' +
        t.getMinutes().toString().padStart(2, '0') +
        ':' +
        t.getSeconds().toString().padStart(2, '0')
      return now
    },
    // 插入产能时间段
    pushItem(newList, id, arr) {
      for (const i in newList) {
        if (newList[i].id === id) {
          const data = {
            start: newList[i].start,
            end: newList[i].end,
            id: newList[i].id,
            mod: newList[i].mod,
            type: 'capacity'
          }
          arr.push(data)
        }
      }
    },
    isPlainClick(val) {
      console.log(val)
      this.tableData.forEach(i => {
        if (val.AdvaScheWorkCode === i.AdvaScheWorkCode) {
          i.isPlain = 'dark'
        } else {
          i.isPlain = 'plain'
        }
      })
      this.getOnclickAdvancedSchedulingDevice('getApi')
      this.$forceUpdate()
    },
    // checkbox 点击改变事件
    handleSelectionChange(val) {
      console.log(val, '009')
      this.multipleSelection = val
      this.getOnclickAdvancedSchedulingDevice()
    },
    // 勾选表格复选框带出数据     获取NEW高级排程点击工单任务带出瓶颈工序设备、已排程任务数据
    async getOnclickAdvancedSchedulingDevice(val) {
      // 拿到复选框勾选的数据请求接口
      let DATA = []
      if (val === 'getApi') { // 代表是从切换页签过来的
        console.log(this.tableData, 333)
        const row = this.tableData.find(i => i.isPlain === 'dark')
        console.log(row, 334)
        DATA = [
          {
            isPlain: row.isPlain, // 代表是否是选中状态
            wocode: row.AdvaScheWorkCode, // 工单编号
            wkshpcode: row.AdvaScheWorkShopid, // 车间编码
            partcode: row.AdvaSchePartNumber, // 产品编码
            botproccode: row.AdvaScheBotProcid, // 工艺路线编码
            startdate: handleDatetime(new Date()), // 当前日期(今天)
            enddate: row.AdvaScheEndDate //  要求交付时间
          }
        ]
        console.log(DATA)
      } else {
        this.multipleSelection.forEach((row, index) => {
          row.isPlain = index !== 0 ? 'plain' : 'dark'
          row.AdvaSchePiroQueNumber = row.AdvaSchePiroQue === '正常' ? 3 : row.AdvaSchePiroQue === '紧急' ? 2 : 1
          DATA.push({
            isPlain: row.isPlain, // 代表是否是选中状态
            wocode: row.AdvaScheWorkCode, // 工单编号
            wkshpcode: row.AdvaScheWorkShopid, // 车间编码
            partcode: row.AdvaSchePartNumber, // 产品编码
            botproccode: row.AdvaScheBotProcid, // 工艺路线编码
            startdate: handleDatetime(new Date()), // 当前日期(今天)
            enddate: row.AdvaScheEndDate //  要求交付时间
          })
        })
      }
      const res = await NewOnclickAdvancedSchedulingDevice(DATA.filter(i => i.isPlain === 'dark'))
      // 如果Message有报错信息则终止执行后面逻辑
      if (res.rus.Message) {
        return this.$message.error(res.rus.Message)
      }
      // 获取预排进度值和最大的要求交付日期
      this.getMaxPayDate()
      let waitingForScheduling = res.rows // 拿到待排数据,对数据进行改造
      const alreadyForScheduling = res.Cont // 拿到已排数据  对数据进行改造
      this.formBottom.canArrangeNumber = 0 // 预排进度的可排数量置零
      // 将五个时间段进行赋值    拿到后端的接口格式,改成前端所需的格式
      waitingForScheduling.forEach(item => {
        item.children.forEach(it => {
          if (it.OneStartDate !== '') {
            it.OneStartDate = it.OneStartDate.split('~')
            it.OneStartDate[0] = item.YearDate + ' ' + it.OneStartDate[0] + ':00'
            it.OneStartDate[1] = item.YearDate + ' ' + it.OneStartDate[1] + ':00'
          }
          if (it.TwoStartDate !== '') {
            it.TwoStartDate = it.TwoStartDate.split('~')
            it.TwoStartDate[0] = item.YearDate + ' ' + it.TwoStartDate[0] + ':00'
            it.TwoStartDate[1] = item.YearDate + ' ' + it.TwoStartDate[1] + ':00'
          }
          if (it.ThreeStartDate !== '') {
            it.ThreeStartDate = it.ThreeStartDate.split('~')
            it.ThreeStartDate[0] = item.YearDate + ' ' + it.ThreeStartDate[0] + ':00'
            it.ThreeStartDate[1] = item.YearDate + ' ' + it.ThreeStartDate[1] + ':00'
          }
          if (it.FourStartDate !== '') {
            it.FourStartDate = it.FourStartDate.split('~')
            it.FourStartDate[0] = item.YearDate + ' ' + it.FourStartDate[0] + ':00'
            it.FourStartDate[1] = item.YearDate + ' ' + it.FourStartDate[1] + ':00'
          }
          if (it.FiveStartDate !== '') {
            it.FiveStartDate = it.FiveStartDate.split('~')
            it.FiveStartDate[0] = item.YearDate + ' ' + it.FiveStartDate[0] + ':00'
            it.FiveStartDate[1] = item.YearDate + ' ' + it.FiveStartDate[1] + ':00'
          }
        })
      })
      // 格式转换,根据wo_code再套一层children
      waitingForScheduling = this.listToTree(waitingForScheduling)
      // 构建 按设备优先排程的 数据格式 schedulingData
      const allCapacity = [] // 代表的是所有的产能
      waitingForScheduling.forEach(item => {
        item.children[0].children.forEach(it => {
          const obj = {
            wo_code: item.wo_code, // 工单号
            id: it.AdvaDevicNumber, // 设备的code
            name: it.AdvaDevicName, // 设备名称
            AdvaDevicRhythm: it.AdvaDevicRhythm, // 节拍多少秒生产一个(生产节拍)
            status: true, // 甘特图左侧复选框是否是选中状态   当为true时渲染  为false时 不渲染产能
            colorPair: { // 颜色集    不同状态下的甘特图的颜色  (目前的理解)
              dark: 'rgb(83, 186, 241,0.8)',
              light: 'rgb(83, 186, 241,0.1)',
              light_capacity: 'rgb(209,239,237,0.8)',
              h_schedule: 'rgb(100,255,192,0.8)',
              scheduleing: 'rgb(20,182,231,0.8)'
            },
            gtArray: [] // 甘特图的每一个子项
          }
          allCapacity.push(obj)
        })
      })
      //  每一个设备的产能
      const everyEqpCapacity = []
      waitingForScheduling.forEach(item => {
        item.children.forEach(it => {
          const maxDate = this.multipleSelection.find(i => i.AdvaScheWorkCode === it.wo_code).AdvaScheEndDate // 当前工单的最大排程日期
          it.children.forEach(i => {
            if (i.OneStartDate !== '') {
              const obj = {
                maxDate,
                work_order: item.wo_code,
                id: '',
                start: '',
                end: '',
                mod: ''
              }
              obj.id = i.AdvaDevicNumber
              obj.start = i.OneStartDate[0]
              obj.end = i.OneStartDate[1]
              // AdvaDevicCropMob 稼动率     AdvaDevicRhythm  生产节拍
              obj.mod = (i.AdvaDevicCropMob * 1) / 100 // 稼动率
              everyEqpCapacity.push(obj)
            }
            if (i.TwoStartDate !== '') {
              const obj = {
                maxDate,
                work_order: item.wo_code,
                id: '',
                start: '',
                end: '',
                mod: ''
              }
              obj.id = i.AdvaDevicNumber
              obj.start = i.TwoStartDate[0]
              obj.end = i.TwoStartDate[1]
              // AdvaDevicCropMob 稼动率     AdvaDevicRhythm  生产节拍
              obj.mod = (i.AdvaDevicCropMob * 1) / 100 // 稼动率
              everyEqpCapacity.push(obj)
            }
            if (i.ThreeStartDate !== '') {
              const obj = {
                maxDate,
                work_order: item.wo_code,
                id: '',
                start: '',
                end: '',
                mod: ''
              }
              obj.id = i.AdvaDevicNumber
              obj.start = i.ThreeStartDate[0]
              obj.end = i.ThreeStartDate[1]
              // AdvaDevicCropMob 稼动率     AdvaDevicRhythm  生产节拍
              obj.mod = (i.AdvaDevicCropMob * 1) / 100 // 稼动率
              everyEqpCapacity.push(obj)
            }
            if (i.FourStartDate !== '') {
              const obj = {
                maxDate,
                work_order: item.wo_code,
                id: '',
                start: '',
                end: '',
                mod: ''
              }
              obj.id = i.AdvaDevicNumber
              obj.start = i.FourStartDate[0]
              obj.end = i.FourStartDate[1]
              // AdvaDevicCropMob 稼动率     AdvaDevicRhythm  生产节拍
              obj.mod = (i.AdvaDevicCropMob * 1) / 100 // 稼动率
              everyEqpCapacity.push(obj)
            }
            if (i.FiveStartDate !== '') {
              const obj = {
                maxDate,
                work_order: item.wo_code,
                id: '',
                start: '',
                end: '',
                mod: ''
              }
              obj.id = i.AdvaDevicNumber
              obj.start = i.FiveStartDate[0]
              obj.end = i.FiveStartDate[1]
              // AdvaDevicCropMob 稼动率     AdvaDevicRhythm  生产节拍
              obj.mod = (i.AdvaDevicCropMob * 1) / 100 // 稼动率
              everyEqpCapacity.push(obj)
            }
          })
        })
      })
      // 插入产能时间段    产能数据都在gtArray里面
      waitingForScheduling.forEach(item => {
        allCapacity.forEach(it => {
          if (item.wo_code === it.wo_code) {
            this.pushCapacity(everyEqpCapacity, it.id, it.gtArray)
            it.gtArray = it.gtArray.filter((currentValue, currentIndex, selfArr) => {
              return selfArr.findIndex(item => item.start === currentValue.start) === currentIndex
            })
            // it.gtArray.sort((a, b) => new Date(a.end).getTime() - new Date(b.end).getTime())
          }
        })
      })
      // console.log(allCapacity, 'allCapacity')
      this.schedulingAllData = JSON.parse(JSON.stringify(allCapacity))
      // 去重设备id(code)
      this.schedulingData = allCapacity.filter((currentValue, currentIndex, selfArr) => {
        return selfArr.findIndex(item => item.id === currentValue.id) === currentIndex
      })
      // 排程复选框的选中与取消
      if (this.ganttLeftArrId !== '') {
        for (const j in this.schedulingData) {
          if (this.ganttLeftArrId.indexOf(this.schedulingData[j].id) >= 0) {
            this.schedulingData[j].gtArray = []
            this.schedulingData[j].status = false
          }
        }
      }
      // 将工单的优先级进行排序,先以时间排,再以优先级排
      // this.getMultipleSelectionOrder()
      // this.eqpTopTempData = JSON.parse(JSON.stringify(this.schedulingData))
      // console.log(waitingForScheduling, 'waitingForScheduling')
      // console.log(allCapacity, 'allCapacity')
      // console.log(this.schedulingData, 'schedulingData')
      // // console.log(JSON.stringify(this.schedulingData), 'schedulingData')
      // console.log(this.schedulingAllData, 'schedulingAllData')
      // console.log(everyEqpCapacity, 'everyEqpCapacity')
    },
    // 将工单的优先级进行排序,先以时间排,再以优先级排
    getMultipleSelectionOrder() {
      // 1.先通过时间去重知道有哪几天的时间       // 2.遍历这几天的时间,过滤出相对应的工单
      const newArr = []
      this.multipleSelection.filter((currentValue, currentIndex, selfArr) => {
        return selfArr.findIndex(item => item.AdvaScheEndDate === currentValue.AdvaScheEndDate) === currentIndex
      }).map(i => i.AdvaScheEndDate).forEach(i => {
        newArr.push(this.multipleSelection.filter(j => j.AdvaScheEndDate === i))
      })
      // 根据日期相同的,工单优先级进行排序
      newArr.filter(i => {
        i.sort((a, b) => b.AdvaSchePiroQueNumber - a.AdvaSchePiroQueNumber)
      })
      // 排好之后  工单顺序就是整个的优先级
      this.multipleSelection = newArr.flat()// 二维转一维
    },
    // 设备优先   数据格式转换
    eqpDataTransition2() {
      const needNumber = this.formBottom.needArrangeNumber // 需排数量
      // 将产能的所有值与多选框的选中的行时间进行匹配校验 以便后续计算
      this.multipleSelection.forEach(item => {
        this.schedulingAllData.forEach(it => {
          // 找到工单所对应的设备进行计算排程   写出计算逻辑  这部分比较上头
          if (it.wo_code === item.AdvaScheWorkCode) {
            it.gtArray.forEach(i => {
              const t = i.start.split(' ')[0]
              // 代表当前工单下的产能是否可排
              i.status = new Date(t).getTime() <= new Date(item.AdvaScheEndDate).getTime()
            })
            // 目前计算逻辑还不太清楚怎么写 太上头了
            console.log(it.id, 'it')
            const end_time = ''
            const mistiming = ''
            const data = {
              id: it.id,
              start: '2023-04-17 14:00:00',
              end: '2023-04-17 16:00:00',
              type: 'schedule',
              cl_name: item.AdvaSchePartName,
              cl_code: item.AdvaSchePartNumber,
              work_order: item.AdvaScheWorkCode,
              AdvaScheUom: item.AdvaScheUom,
              number: 0,
              real_number: 0
            }
            // 工单相同之后   应该根据时间优先或者设备优先  对设备进行一一排程
            // 这个地方不对   写不出来了
            // data.start = it.gtArray[0].start // 先只考虑一种情况
            // data.start = it.gtArray[0].start // 先只考虑一种情况
            data.number = '230'
            data.real_number = '230'
            const index = this.schedulingData.findIndex(i => i.id === it.id)
            this.schedulingData[index].gtArray.push(data)
            console.log(JSON.stringify(it))
          }
        })
      })
      // 这个是计算出来的数值,需要push到schedulingData中
      //         'id': 'JG002',
      //         'start': '2023-04-17 10:10:21',
      //         'end': '2023-04-17 11:30:00',
      //         'type': 'schedule',
      //         'cl_name': '主机',
      //         'cl_code': '201',
      //         'work_order': 'MO-2023-04-0001_1',
      //         'AdvaScheUom': '个',
      //         'number': '64',
      //         'real_number': 63.72
      // this.schedulingData = [
      //   {
      //     'id': 'JG002',
      //     'name': '精工设备2#',
      //     'AdvaDevicRhythm': '15.0',
      //     'status': true,
      //     'colorPair': {
      //       'dark': 'rgb(83, 186, 241,0.8)',
      //       'light': 'rgb(83, 186, 241,0.1)',
      //       'light_capacity': 'rgb(209,239,237,0.8)',
      //       'h_schedule': 'rgb(100,255,192,0.8)',
      //       'scheduleing': 'rgb(20,182,231,0.8)'
      //     },
      //     'gtArray': [
      //       {
      //         'start': '2023-04-17 08:00:00',
      //         'end': '2023-04-17 11:30:00',
      //         'id': 'JG002',
      //         'mod': 0.2,
      //         'type': 'capacity'
      //       },
      //       {
      //         'start': '2023-04-17 13:00:00',
      //         'end': '2023-04-17 18:00:00',
      //         'id': 'JG002',
      //         'mod': 0.2,
      //         'type': 'capacity'
      //       },
      //       {
      //         'id': 'JG002',
      //         'start': '2023-04-17 10:10:21',
      //         'end': '2023-04-17 11:30:00',
      //         'type': 'schedule',
      //         'cl_name': '主机',
      //         'cl_code': '201',
      //         'work_order': 'MO-2023-04-0001_1',
      //         'AdvaScheUom': '个',
      //         'number': '64',
      //         'real_number': 63.72
      //       },
      //       {
      //         'id': 'JG002',
      //         'start': '2023-04-17 13:00:00',
      //         'end': '2023-04-17 18:00:00',
      //         'type': 'schedule',
      //         'cl_name': '主机',
      //         'cl_code': '201',
      //         'work_order': 'MO-2023-04-0001_1',
      //         'AdvaScheUom': '个',
      //         'number': '240',
      //         'real_number': 240
      //       }
      //     ]
      //   },
      //   {
      //     'id': 'SB001',
      //     'name': '设备001',
      //     'AdvaDevicRhythm': '15.0',
      //     'status': true,
      //     'colorPair': {
      //       'dark': 'rgb(83, 186, 241,0.8)',
      //       'light': 'rgb(83, 186, 241,0.1)',
      //       'light_capacity': 'rgb(209,239,237,0.8)',
      //       'h_schedule': 'rgb(100,255,192,0.8)',
      //       'scheduleing': 'rgb(20,182,231,0.8)'
      //     },
      //     'gtArray': [
      //       {
      //         'start': '2023-04-17 08:00:00',
      //         'end': '2023-04-17 11:30:00',
      //         'id': 'SB001',
      //         'mod': 0.3,
      //         'type': 'capacity'
      //       },
      //       {
      //         'start': '2023-04-17 13:00:00',
      //         'end': '2023-04-17 18:00:00',
      //         'id': 'SB001',
      //         'mod': 0.3,
      //         'type': 'capacity'
      //       },
      //       {
      //         'id': 'SB001',
      //         'start': '2023-04-17 10:10:21',
      //         'end': '2023-04-17 11:30:00',
      //         'type': 'schedule',
      //         'cl_name': '主机',
      //         'cl_code': '201',
      //         'work_order': 'MO-2023-04-0001_1',
      //         'AdvaScheUom': '个',
      //         'number': '96',
      //         'real_number': 95.58
      //       },
      //       {
      //         'id': 'SB001',
      //         'start': '2023-04-17 13:00:00',
      //         'end': '2023-04-17 18:00:00',
      //         'type': 'schedule',
      //         'cl_name': '主机',
      //         'cl_code': '201',
      //         'work_order': 'MO-2023-04-0001_1',
      //         'AdvaScheUom': '个',
      //         'number': '360',
      //         'real_number': 360
      //       }
      //     ]
      //   }
      // ]
      console.log(this.schedulingData, 'schedulingData')
      console.log(this.schedulingAllData, 'schedulingAllData')
    },
    // 获取排程日期最大值
    getMaxPayDate() {
      this.formBottom.needArrangeNumber = 0
      let maxPayDate = handleDatetime(new Date())
      if (this.multipleSelection.length > 0) {
        this.multipleSelection.forEach(i => {
          this.formBottom.needArrangeNumber += i.AdvaScheQty * 1 - i.AdvaScheYPQty * 1
          if (new Date(i.AdvaScheEndDate).getTime() > new Date(maxPayDate).getTime()) {
            maxPayDate = i.AdvaScheEndDate
          }
        })
      }
      this.formBottom.scheDate = [] // 排程日期置空
      this.formBottom.scheDate.push(handleDatetime(new Date())) //  当前日期(今天)
      this.formBottom.scheDate.push(maxPayDate) //  要求交付时间
      if (this.formBottom.scheDate !== '') {
        this.time_data[0] = this.formBottom.scheDate[0] + ' 00:00' // 排程开始时间
        this.time_data[1] = this.formBottom.scheDate[1] + ' 23:59' // 排程结束时间
      }
    },
    // 插入产能时间段
    pushCapacity(newList, id, arr) {
      for (const i in newList) {
        if (newList[i].id === id) {
          // console.log(JSON.stringify(newList[i]))
          const t = this.multipleSelection.find(j => j.AdvaScheWorkCode === newList[i].work_order)
          const data = {
            work_order: t.AdvaScheWorkCode,
            AdvaScheUom: t.AdvaScheUom,
            partname: t.AdvaSchePartName,
            partcode: t.AdvaSchePartNumber,
            start: newList[i].start,
            end: newList[i].end,
            id: newList[i].id,
            mod: newList[i].mod,
            type: 'capacity'
          }
          arr.push(data)
        }
      }
    },
    // 递归构建树形并返回
    listToTree(list) {
      const pid = [...new Set(list.map(i => i.wo_code))]
      const newArr = []
      pid.forEach(i => {
        const arr = []
        list.forEach(j => {
          if (i === j.wo_code) {
            arr.push(j)
          }
        })
        newArr.push({ children: arr, wo_code: i })
      })
      return newArr
    },
    // 提交排程
    async prepareSubmit() {
      if (this.formBottom.canArrangeNumber !== this.formBottom.needArrangeNumber) {
        this.$message.error('数量未排完,请设置产能时间!')
      } else {
        const list = [] // 提交数组
        for (const i in this.schedulingData) {
          const arr = []
          for (const j in this.schedulingData[i].gtArray) {
            if (this.schedulingData[i].gtArray[j].type === 'schedule') {
              arr.push(this.schedulingData[i].gtArray[j])
            }
          }
          if (arr !== '') {
            for (const i in arr) {
              const data = {
                AlreDevicNumber: '',
                AlreStartDate: '',
                AlreEndDate: '',
                AlreQty: ''
              }
              data.AlreDevicNumber = arr[i].id
              data.AlreStartDate = arr[i].start
              data.AlreEndDate = arr[i].end
              data.AlreQty = arr[i].number
              list.push(data)
            }
          }
        }
        // 排程相同设备获取开始时间 结束时间 数量的总和
        // 过滤
        let update = []
        for (const i in list) {
          if (list[i].AlreStartDate !== '') {
            update.push(list[i])
          }
        }
        update = JSON.stringify(update)
        this.formUpdate.json = update
        if (list === '') {
          this.$message.error('请先预排')
          return false
        }
        const formData = new FormData()
        formData.append('wocode', this.formUpdate.WorkCode)
        formData.append('botprocecode', this.formUpdate.BotProceCode)
        formData.append('json', this.formUpdate.json)
        const res = await SubmitAlreadyScheduling(formData)
        if (res.code === '200') {
          this.$message.success(res.Message)
        }
        this.formBottom.needArrangeNumber = 0
        this.formBottom.canArrangeNumber = 0
        await this.getOnclickAdvancedSchedulingDevice()
        await this.getAdvancedSchedulingSearch()
      }
    },
    prepareArrange() {
      const timestamp = new Date().toLocaleDateString()
      if (new Date(this.formBottom.scheDate[1]) < new Date(timestamp)) {
        this.$message.error('排程日期不可以小于当前时间!')
        return false
      }
      this.filterAlreadyScheduleEqp()// 手动过滤所有设备已排程
      // 设备优先或者时间优先 对数据进行的格式转换
      if (this.schedulingData !== '' && this.formBottom.types === 'N') { // 设备优先
        this.eqpDataTransition()
        this.editLastValue(this.schedulingData)
      } else if (this.timeTopTempData !== '' && this.formBottom.types === 'Y') { // 时间优先
        this.filterAlreadyScheduleTime() // 手动过滤所有时间已排程
        this.timeDataTransition()
        this.dataTransition()
        this.editLastValue(this.schedulingData)
      }
    },
    // 手动过滤所有时间已排程
    filterAlreadyScheduleTime() {
      this.timeTopTempData.forEach(item => {
        if (item.gtArray && item.gtArray.length > 0) {
          item.gtArray = item.gtArray.filter(it => it.type !== 'schedule')
        }
      })
    },
    // 手动过滤所有设备已排程
    filterAlreadyScheduleEqp() {
      this.schedulingData.forEach(item => {
        if (item.gtArray && item.gtArray.length > 0) {
          item.gtArray = item.gtArray.filter(it => it.type !== 'schedule')
        }
      })
    },
    // 给排程最后一个修改数量
    editLastValue(arr) {
      this.formBottom.canArrangeNumber = 0 // 真实已排数量
      let num = 0 // 取整已排数量
      const arr_num = [] // 已排数据
      let need_num = 0
      for (const i in arr) {
        for (const j in arr[i].gtArray) {
          if (arr[i].gtArray[j].type === 'schedule') {
            arr_num.unshift(arr[i].gtArray[j])
          }
        }
      }
      for (const n in arr_num) {
        this.formBottom.canArrangeNumber += arr_num[n].real_number
        num += arr_num[n].number * 1
      }
      this.formBottom.canArrangeNumber = Math.ceil(this.formBottom.canArrangeNumber)
      const y10 = this.formBottom.needArrangeNumber - this.formBottom.canArrangeNumber
      if (y10 <= 10) {
        this.formBottom.canArrangeNumber = this.formBottom.needArrangeNumber
        need_num = this.formBottom.needArrangeNumber - num
      } else {
      }
      for (const i in this.schedulingData) {
        for (const j in this.schedulingData[i].gtArray) {
          if (
            this.schedulingData[i].gtArray[j].type === 'schedule' &&
            this.schedulingData[i].gtArray[j].end_num
          ) {
            this.schedulingData[i].gtArray[j].number =
              this.schedulingData[i].gtArray[j].number * 1 + need_num
          }
        }
      }
    },
    // 设备优先   数据格式转换
    eqpDataTransition() { // 这里是原先的写法
      let needNumber = this.formBottom.needArrangeNumber // 需排数量
      let flag1 = 0
      console.log(this.schedulingData, 33)
      console.log(this.schedulingData.length, 33)
      for (const i in this.schedulingData) {
        console.log(i, '中国移动')
        let end_arr = [] // 已排程的数组
        let need_arr = [] // 待排程的数组
        let capacity_arr = [] // 要排程的数组
        this.schedulingData[i].gtArray.sort((a, b) => new Date(a.end).getTime() - new Date(b.end).getTime())
        end_arr = JSON.parse(JSON.stringify(this.schedulingData[i].gtArray.filter(item => item.type === 'h_schedule'))) // 已排程数组
        need_arr = JSON.parse(JSON.stringify(this.schedulingData[i].gtArray.filter(item => item.type === 'capacity'))) // 容量
        // console.log(need_arr, 5)
        // console.log(JSON.stringify(need_arr))
        // need_arr = [
        //   {
        //     'start': '2023-03-25 08:00:00',
        //     'end': '2023-03-25 11:30:00',
        //     'id': 'SB001',
        //     'mod': 0.3,
        //     'type': 'capacity'
        //   },
        //   {
        //     'start': '2023-03-25 13:00:00',
        //     'end': '2023-03-25 18:00:00',
        //     'id': 'SB001',
        //     'mod': 0.3,
        //     'type': 'capacity'
        //   },
        //   {
        //     'start': '2023-03-26 06:00:00',
        //     'end': '2023-03-26 11:00:00',
        //     'id': 'SB001',
        //     'mod': 0.3,
        //     'type': 'capacity'
        //   },
        //   {
        //     'start': '2023-03-26 14:00:00',
        //     'end': '2023-03-26 20:00:00',
        //     'id': 'SB001',
        //     'mod': 0.3,
        //     'type': 'capacity'
        //   },
        //   {
        //     'start': '2023-03-26 21:30:00',
        //     'end': '2023-03-26 23:00:00',
        //     'id': 'SB001',
        //     'mod': 0.3,
        //     'type': 'capacity'
        //   },
        //   {
        //     'start': '2023-03-27 05:30:00',
        //     'end': '2023-03-27 17:30:00',
        //     'id': 'SB001',
        //     'mod': 0.3,
        //     'type': 'capacity'
        //   },
        //   {
        //     'start': '2023-03-28 08:00:00',
        //     'end': '2023-03-28 11:30:00',
        //     'id': 'SB001',
        //     'mod': 0.3,
        //     'type': 'capacity'
        //   },
        //   {
        //     'start': '2023-03-28 13:00:00',
        //     'end': '2023-03-28 18:00:00',
        //     'id': 'SB001',
        //     'mod': 0.3,
        //     'type': 'capacity'
        //   },
        //   {
        //     'start': '2023-03-29 08:00:00',
        //     'end': '2023-03-29 11:30:00',
        //     'id': 'SB001',
        //     'mod': 0.3,
        //     'type': 'capacity'
        //   },
        //   {
        //     'start': '2023-03-29 13:00:00',
        //     'end': '2023-03-29 18:00:00',
        //     'id': 'SB001',
        //     'mod': 0.3,
        //     'type': 'capacity'
        //   },
        //   {
        //     'start': '2023-03-30 08:00:00',
        //     'end': '2023-03-30 11:30:00',
        //     'id': 'SB001',
        //     'mod': 0.3,
        //     'type': 'capacity'
        //   },
        //   {
        //     'start': '2023-03-30 13:00:00',
        //     'end': '2023-03-30 18:00:00',
        //     'id': 'SB001',
        //     'mod': 0.3,
        //     'type': 'capacity'
        //   },
        //   {
        //     'start': '2023-03-31 08:00:00',
        //     'end': '2023-03-31 11:30:00',
        //     'id': 'SB001',
        //     'mod': 0.3,
        //     'type': 'capacity'
        //   },
        //   {
        //     'start': '2023-03-31 13:00:00',
        //     'end': '2023-03-31 18:00:00',
        //     'id': 'SB001',
        //     'mod': 0.3,
        //     'type': 'capacity'
        //   }
        // ]
        if (end_arr && end_arr.length > 0) {
          capacity_arr = need_arr.map(item => {
            // 排除掉已经排程的存在hshedule,start,end都相等的情况
            const schedule = end_arr.filter(it => {
              return new Date(item.start).getTime() <= new Date(it.start).getTime() &&
                new Date(item.end).getTime() >= new Date(it.end).getTime()
            })
            if (schedule && schedule.length > 0) {
              item.start = this.MinutesTest(schedule[schedule.length - 1]['end'])
            }
            const schedule1 = end_arr.filter(schedule => {
              return new Date(item.start).getTime() === new Date(schedule.start).getTime() &&
                new Date(item.end).getTime() === new Date(schedule.end).getTime()
            })
            if (schedule1 && schedule1.length > 0) {
              item.capacity = false
            }
            return item
          }).filter(item => item.capacity !== false)
        } else {
          capacity_arr = need_arr
        }
        const id_obj = {
          id: '',
          start_time: ''
        }
        if (end_arr != '') {
          (id_obj.id = end_arr[0].id), (id_obj.start_time = end_arr[0].end)
        }
        capacity_arr = this.filterOutTime(capacity_arr) // 过滤掉当前时间之前的不能排程
        for (const w in capacity_arr) {
          let end_time = ''
          let mistiming = ''
          const data = {
            id: capacity_arr[w].id,
            start: '',
            end: '',
            type: 'schedule',
            cl_name: this.cl_name,
            cl_code: this.cl_code,
            work_order: this.work_order,
            AdvaScheUom: this.AdvaScheUom,
            number: 0,
            real_number: 0
          }
          if (
            id_obj.start_time !== '' &&
            flag1 === 0 &&
            new Date(id_obj.start_time).getTime() >= new Date(capacity_arr[w].start).getTime()
          ) {
            data.start = this.MinutesTest(id_obj.start_time)
            flag1 = 1
          } else {
            data.start = capacity_arr[w].start
          }
          let nowTime = (this.schedulingData[i].AdvaDevicRhythm * needNumber) / capacity_arr[w].mod
          end_time = this.formSeconds(nowTime, data.start, capacity_arr[w].mod) // 总共的结束时间
          data.end = end_time
          mistiming = this.compareTime(
            end_time,
            capacity_arr[w].end,
            capacity_arr[w].mod
          ) // 总共的结束时间-当前的结束时间 = 剩下多久时间
          if (mistiming >= 0) {
            data.number =
              ((new Date(data.end) - new Date(data.start)) *
                capacity_arr[w].mod) /
              this.schedulingData[i].AdvaDevicRhythm /
              1000
            data.real_number =
              ((new Date(data.end) - new Date(data.start)) *
                capacity_arr[w].mod) /
              this.schedulingData[i].AdvaDevicRhythm /
              1000
            data.number = data.number.toFixed(0)
            data.end_num = true
            if (new Date(data.start) >= new Date(data.end)) {
            } else {
              this.schedulingData[i].gtArray.push(data)
            }
            return false
          } else {
            data.end = capacity_arr[w].end
            if (new Date(data.end).getTime() < new Date(data.start)) {
              continue // 因为开始时间比结束时间大 需要跳过后面步骤
            }
            // 这里除以一千是因为 new Date() 得到的是毫秒  毫秒转化为秒是千进制
            // 一段时间段内的生产量=两者时间差(毫秒)/1000  / 生产节拍 * 稼动率
            data.number =
              ((new Date(data.end) - new Date(data.start)) *
                capacity_arr[w].mod) /
              this.schedulingData[i].AdvaDevicRhythm /
              1000
            data.real_number =
              ((new Date(data.end) - new Date(data.start)) *
                capacity_arr[w].mod) /
              this.schedulingData[i].AdvaDevicRhythm /
              1000
            data.number = data.number.toFixed(0)
            nowTime = (needNumber - data.real_number) * this.schedulingData[i].AdvaDevicRhythm
            needNumber = needNumber - data.real_number
            if (new Date(data.start) >= new Date(data.end)) {
            } else {
              this.schedulingData[i].gtArray.push(data)
            }
          }
        }
      }
    },
    // 时间优先  数据格式转换
    timeDataTransition() {
      // 排除未勾选项
      for (const i in this.timeTopTempData) {
        const newArr = []
        for (const j in this.timeTopTempData[i].gtArray) {
          if (this.ganttLeftArrId.indexOf(this.timeTopTempData[i].gtArray[j].id) < 0) {
            newArr.push(this.timeTopTempData[i].gtArray[j])
          }
        }
        this.timeTopTempData[i].gtArray = newArr
      }
      let needNumber = this.formBottom.needArrangeNumber // 需排数量
      //  里面逻辑要搞清楚 很重要
      for (const i in this.timeTopTempData) {
        let end_arr = []
        let need_arr = [] // 排程的数组
        let capacity_arr = [] // 要排程的数组
        this.timeTopTempData[i].gtArray.sort((a, b) => new Date(a.end).getTime() - new Date(b.end).getTime())
        end_arr = JSON.parse(JSON.stringify(this.timeTopTempData[i].gtArray.filter(item => item.type === 'h_schedule'))) // 已排程数据
        need_arr = JSON.parse(JSON.stringify(this.timeTopTempData[i].gtArray.filter(item => item.type === 'capacity'))) // 容量
        capacity_arr = JSON.parse(JSON.stringify(need_arr)) // 容量
        // 获取可排程的时间   以便接着往后排程    遍历结束要得到的是 当前日期可排容量
        end_arr.forEach((item, index) => { // 已排程的数组
          capacity_arr.forEach((it, ind) => { // 容量(日产能)
            if (item.id === it.id &&
              new Date(item.start).getTime() >= new Date(it.start).getTime() &&
              new Date(item.end).getTime() === new Date(it.end).getTime() // new Date(item.end).getTime() <= new Date(it.end).getTime()
            ) {
              capacity_arr.splice(ind, 1)
            }
          })
        })
        // continue:表示跳出本次循环,也就是不执行本次循环continue之后的操作
        // break:表示跳出当前的循环,针对整个循环体终止后续的遍历;
        if (!capacity_arr || capacity_arr.length === 0) {
          continue
        }
        const schedule_arr = end_arr.filter(item => {
          const remain = need_arr.some(it => {
            return (new Date(item.start).getTime() >= new Date(it.start).getTime() &&
              new Date(item.end).getTime() < new Date(it.end).getTime())
          })
          return remain
        })
        // 下面逻辑很重要
        if (schedule_arr && schedule_arr.length > 0) {
          const scheduleCan = schedule_arr.map(item => {
            const temp = need_arr.filter(it => {
              if (it.id === item.id) {
                return (new Date(item.start).getTime() >= new Date(it.start).getTime() &&
                  new Date(item.end).getTime() < new Date(it.end).getTime())
                //   ||
                // (new Date(item.start).getTime() > new Date(it.start).getTime() &&
                // new Date(item.end).getTime() < new Date(it.end).getTime())
              }
            })[0]
            temp.start = this.MinutesTest(item.end)
            return temp
          })
          const newSchedule = JSON.parse(JSON.stringify(scheduleCan))
          capacity_arr.forEach(item => {
            newSchedule.forEach(it => {
              if (item.id === it.id && new Date(item.start).getTime() < new Date(it.start).getTime()) {
                item.start = it.start
              }
            })
          })
        }
        const id_obj = {}
        if (end_arr != '') {
          (id_obj.id = end_arr[0].id), (id_obj.start_time = end_arr[0].end)
        }
        capacity_arr = this.filterOutTime(capacity_arr) // 过滤掉当前时间之前的不能排程
        for (const w in capacity_arr) {
          const data = {
            id: capacity_arr[w].id,
            start: '',
            end: '',
            type: 'schedule',
            cl_name: this.cl_name,
            cl_code: this.cl_code,
            work_order: this.work_order,
            AdvaScheUom: this.AdvaScheUom, // 单位
            number: 0,
            real_number: 0
          }
          if (
            id_obj &&
            new Date(id_obj.start_time).getTime() >=
            new Date(capacity_arr[w].start).getTime()
          ) {
            if (data.id === id_obj.id) {
              data.start = this.MinutesTest(id_obj.start_time)
            } else {
              data.start = capacity_arr[w].start
            }
          } else {
            data.start = capacity_arr[w].start
          }
          let nowTime = (capacity_arr[w].rhythm * needNumber) / capacity_arr[w].mod
          const end_time = this.formSeconds(nowTime, data.start)
          data.end = end_time
          const mistiming = this.compareTime(end_time, capacity_arr[w].end)
          if (mistiming >= 0) {
            data.number = ((new Date(data.end) - new Date(data.start)) * capacity_arr[w].mod) / capacity_arr[w].rhythm / 1000
            data.real_number = ((new Date(data.end) - new Date(data.start)) * capacity_arr[w].mod) / capacity_arr[w].rhythm / 1000
            data.number = data.number.toFixed(0)
            data.end_num = true
            if (new Date(data.start) >= new Date(data.end)) {
            } else {
              this.timeTopTempData[i].gtArray.push(data)
            }
            return false
          } else {
            data.end = capacity_arr[w].end
            data.number = ((new Date(data.end) - new Date(data.start)) * capacity_arr[w].mod) / capacity_arr[w].rhythm / 1000
            data.real_number = ((new Date(data.end) - new Date(data.start)) * capacity_arr[w].mod) / capacity_arr[w].rhythm / 1000
            data.number = data.number.toFixed(0)
            nowTime = (needNumber - data.real_number) * capacity_arr[w].rhythm
            needNumber = needNumber - data.real_number
            if (new Date(data.start) >= new Date(data.end)) {
            } else {
              this.timeTopTempData[i].gtArray.push(data)
            }
          }
        }
      }
    },
    // 过滤掉当前时间之前的不能排程
    filterOutTime(capacity_arr) {
      // 这里要将容量和当前时间做对比   做时间处理   如果在当前时间之前的不能排程
      capacity_arr.forEach((item, index) => {
        // 当前时间 大于等于开始时间   且小于等于结束时间
        if (new Date(item.start).getTime() <= new Date(handleDatetime2(new Date())).getTime() && new Date(item.end).getTime() >= new Date(handleDatetime2(new Date())).getTime()) {
          item.start = handleDatetime2(new Date())
        }
        // 当前时间比开始时间大  比结束时间也大
        if (new Date(item.start).getTime() < new Date(handleDatetime2(new Date())).getTime() && new Date(item.end).getTime() < new Date(handleDatetime2(new Date())).getTime()) {
          item.capacity = false
        }
      })
      return capacity_arr.filter(item => item.capacity !== false)
    },
    // 时间优先 给设备转换格式
    dataTransition() {
      this.schedulingData = []
      const data = this.timeTopTempData
      const all = []
      // const list = this.eqpTopTempData
      const list = this.eqpTopTempData
      console.log(this.eqpTopTempData, 212)
      for (const i in data) {
        for (const j in data[i].gtArray) {
          all.push(data[i].gtArray[j])
        }
      }
      for (const i in list) {
        list[i].gtArray = []
        this.pushTimes(all, list[i].id, list[i].gtArray)// 插入产能时间段
      }
      for (const n in list) {
        if (list[n].gtArray.length === 0) {
          list[n].status = false
        }
      }
      this.schedulingData = list
    },
    // 插入产能时间段
    pushTimes(newList, id, arr) {
      for (const i in newList) {
        if (newList[i].id === id) {
          arr.push(newList[i])
        }
      }
    },
    // 排程方法
    formSeconds(s1, start, mod) {
      const nowData = new Date(start)
      // 算出当前排程的结束时间
      return this.transitionTime(
        new Date(nowData.setSeconds(nowData.getSeconds() + s1))
      )
    },
    // 转化标准时间
    transitionTime(time) {
      const d = new Date(time)
      return (
        d.getFullYear() +
        '-' +
        (d.getMonth() + 1).toString().padStart(2, '0') +
        '-' +
        d.getDate().toString().padStart(2, '0') +
        ' ' +
        d.getHours().toString().padStart(2, '0') +
        ':' +
        d.getMinutes().toString().padStart(2, '0') +
        ':' +
        d.getSeconds().toString().padStart(2, '0')
      )
    },
    // 时间比较
    compareTime(d1, d2, mod) {
      // d1 排除结束时间  d2 当前产能结束时间
      const time1 = new Date(d1)
      const time2 = new Date(d2)
      return parseInt(time2 - time1) / 1000
    }
  }
}
</script>
<!--排程部分的样式-->
<style scoped>
body {
  font-size: 12px;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
}
.box_style {
  position: relative;
  top: 40px;
  left: -91px;
}
.box_styles {
  position: relative;
  top: 40px;
  left: 0;
}
/*自动排程部分*/
.autoScheduling {
  display: flex;
  flex-direction: column;
  /*padding: 0 10px;*/
  /* height: calc(100vh - 100px); */
  /*background-color: #f8f8fa;*/
  background-color: #fff;
  margin-top: 20px;
  height: 490px;
}
.colorDescription {
  display: flex;
  padding: 5px 30px 0;
  align-items: center;
}
.colorDescriptionItem {
  display: flex;
  margin-right: 20px;
}
label {
  margin-left: 10px;
}
input {
  width: 40px;
  height: 20px;
  vertical-align: middle;
}
input[type="range"] {
  width: 100px;
}
.container {
  display: flex;
  flex-direction: column;
  flex: 1;
}
.tc {
  text-align: center;
}
.name {
  display: flex;
  box-sizing: border-box;
  overflow: hidden;
  height: 100%;
  width: 100%;
  padding: 0 5px 0 0;
  border-radius: 8px 0 0 8px;
  align-items: center;
}
.carId {
  flex: 1;
}
.tc {
  color: #909399;
  font-size: 14px;
}
</style>
<!--公共页面样式-->
<style lang="scss" scoped>
$main_color: #42b983;
.elTableDiv {
  ::v-deep .el-radio__label {
    display: none;
  }
}
::v-deep .el-button--text {
  font-size: 14px;
  cursor: pointer;
}
.el-icon-share, .el-icon-delete, .el-icon-edit-outline {
  color: $main_color;
  cursor: pointer;
}
.el-icon-edit-outline {
  margin-right: 15px;
}
::v-deep .el-button--primary, .el-button--default, .el-button--info {
  height: 34px;
  display: flex;
  align-items: center;
  padding: 0 15px;
}
::v-deep .el-button--primary {
  //background-color: $main_color !important;
}
::v-deep .el-button--default {
  background-color: #f8f8fa;
  border: none;
}
::v-deep .el-input__inner {
  height: 34px;
  line-height: 34px;
  //color: #a7a7a7;
}
::v-deep .el-dialog__body {
  padding: 20px 100px !important;
}
::v-deep .dialogVisibleRoles .el-dialog__body {
  padding: 20px 20px !important;
}
::v-deep .importPickerClass .el-dialog__body {
  padding: 20px 20px !important;
}
::v-deep .el-dialog__footer {
  display: flex;
  justify-content: flex-end;
}
::v-deep .el-table .caret-wrapper {
  transform: scale(0.8);
}
::v-deep .cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
::v-deep .el-table::before {
  height: 0;
}
::v-deep .el-table__body-wrapper {
  background-color: #f8f8fa;
}
::v-deep .el-table__body .el-table__row.hover-row td {
  background-color: #eaecef;
}
::v-deep .el-form--inline .el-form-item__label {
  color: #a7a7a7;
}
.body ::v-deep .el-divider {
  border: 1px solid #eee;
  width: 99%;
  margin: 10px auto;
}
.body ::v-deep .el-form-item {
  margin-bottom: 0;
}
.userDialogVisible ::v-deep .el-form-item {
  margin-bottom: 0;
}
::v-deep .el-select__caret {
  display: flex;
  align-items: center;
  justify-content: center;
}
.tableFixed {
  ::v-deep .el-table__fixed-right {
    height: 100% !important;
  }
  ::v-deep .el-table__fixed {
    height: 100% !important;
  }
}
::v-deep .gantt-header-title {
  background-color: #fff;
  //border-left: 1px solid #eee !important;
  //border-bottom: 1px solid #eee !important;
}
</style>
<style>
.el-table .custom-row {
  background: #f8f8fa;
}
</style>
<!--<style>-->
<!--input[type=range]:focus {-->
<!--  display: none;-->
<!--}-->
<!--input[type=range] {-->
<!--  -webkit-appearance: none;-->
<!--  width: 500px;-->
<!--  border-radius: 10px;-->
<!--  /*这个属性设置使填充进度条时的图形为圆角*/-->
<!--}-->
<!--input[type=range]::-webkit-slider-runnable-track {-->
<!--  height: 20px;-->
<!--  border-radius: 10px;-->
<!--  /*将轨道设为圆角的*/-->
<!--  /* box-shadow: 0 1px 1px #def3f8, inset 0 .125em .125em #0d1112; */-->
<!--  border: solid 1px red;-->
<!--}-->
<!--input[type=range]::-webkit-slider-thumb {-->
<!--  -webkit-appearance: none;-->
<!--  height: 30px;-->
<!--  width: 120px;-->
<!--  margin-top: -5px;-->
<!--  /*使滑块超出轨道部分的偏移量相等*/-->
<!--  background: #ffffff;-->
<!--  /* border-radius: 50%; */-->
<!--  /*外观设置为圆形*/-->
<!--  border: solid 0.125em rgba(205, 224, 230, 0.5);-->
<!--  /*设置边框*/-->
<!--  /* box-shadow: 0 .125em .125em #3b4547; */-->
<!--  /*添加底部阴影*/-->
<!--}-->
<!--</style>-->