小小儁爺
2026-01-21 527250b10d6ecda0a8f3f9ea426dbe0bbc630a2c
src/views/gantt/index.vue
@@ -15,6 +15,20 @@
          :value="item.code"
        />
      </el-select>
      <el-select
        v-model="priorityMethod"
        size="mini"
        style="margin-left: 10px;"
        placeholder="请选择"
        @change="prepareArrange"
      >
        <el-option
          v-for="item in priorityMethodArr"
          :key="item.code"
          :label="item.name"
          :value="item.code"
        />
      </el-select>
      <el-date-picker
        v-model="ganttDateRange"
        style="margin-left: 10px;"
@@ -32,13 +46,6 @@
      </el-button>
      <el-button size="mini" @click="handleClearSelection">
        清空复选框选择
      </el-button>
      <el-button size="mini" type="primary" @click="prepareArrange('device')">
        按设备优先预排
      </el-button>
      <el-button size="mini" type="primary" @click="prepareArrange('time')">
        按时间优先预排
      </el-button>
    </div>
@@ -87,7 +94,11 @@
      fivePeriodsTimeName: ['OneStartDate', 'TwoStartDate', 'ThreeStartDate', 'FourStartDate', 'FiveStartDate'], // 五个时间段的键名
      needArrangeNumber: 5000, // 假设需要排产数量5000
      priorityMethod: 'device'// device 设备   time  时间
      priorityMethod: 'device', // device 设备   time  时间
      priorityMethodArr: [
        { code: 'device', name: '设备优先' },
        { code: 'time', name: '时间优先' }
      ]
    }
  },
  mounted() {
@@ -255,7 +266,11 @@
        // console.log(JSON.parse(JSON.stringify(task)))
        // return '<b>任务:</b> ' + task.text + '<br/><b>开始时间:</b> ' + `${gantt.date.date_to_str('%Y-%m-%d')(start)}` + '<br/><b>结束时间:</b> ' + handleDateReduceOneDay(end)
        // return '<b>任务:</b> ' + task.text + '<br/><b>开始时间:</b> ' + handleDatetime2(start) + '<br/><b>结束时间:</b> ' + handleDateReduceOneDay(end) + '<br/><b>进度:</b> ' + task.progress * 100 + '%'
        return '<b>任务:</b> ' + task.text + '<br/><b>开始时间:</b> ' + handleDatetime2(start) + '<br/><b>结束时间:</b> ' + handleDatetime2(end) + '<br/><b>进度:</b> ' + task.progress * 100 + '%'
        return '<b>任务:</b> ' + task.text +
          '<br/><b>生产数量:</b> ' + task.producedCount +
          '<br/><b>进度:</b> ' + task.progress * 100 + '%' +
          '<br/><b>开始时间:</b> ' + handleDatetime2(start) +
          '<br/><b>结束时间:</b> ' + handleDatetime2(end)
      }
      gantt.templates.task_text = function(start, end, task) {
@@ -768,9 +783,9 @@
        }
      ]
      this.totalTasks = this.allTasks.length
      this.updatePaginatedTasks()
      this.renderGanttChart()
      // this.totalTasks = this.allTasks.length
      // this.updatePaginatedTasks()
      // this.renderGanttChart()
      this.prepareArrange()
    },
@@ -933,51 +948,57 @@
      this.$notify.success('已清空所有选择')
    },
    // 预排
    prepareArrange(type) {
    prepareArrange() {
      this.allTasks = this.allTasks.filter(i => i.type !== 'task2')
      // 优先方式  time  device
      if (type === 'time') {
      if (this.priorityMethod === 'time') {
        this.allTasks.sort((a, b) => a.start_date - b.start_date)
      }
      if (type === 'device') {
        console.log(JSON.parse(JSON.stringify(this.allTasks)), '9999')
      if (this.priorityMethod === 'device') {
        this.allTasks.sort((a, b) => Number(a.partCode.replace(/\D/g, '')) - Number(b.partCode.replace(/\D/g, '')))
        // this.allTasks.sort((a, b) => Number(b.partCode.replace(/\D/g, '')) - Number(a.partCode.replace(/\D/g, '')))
        // this.allTasks.sort((a, b) => a.producedCount - b.producedCount)
      }
      // console.log(JSON.parse(JSON.stringify(this.allTasks)), '9999')
      const newArr = []
      let needArrangeNumber = this.needArrangeNumber
      this.allTasks.forEach(item => {
        if (item.type === 'task') {
          // console.log(JSON.parse(JSON.stringify(item)))
          const count = this.needArrangeNumber > 0 && this.needArrangeNumber <= item.producedCount ? this.needArrangeNumber : item.producedCount
          this.needArrangeNumber = this.needArrangeNumber - item.producedCount // 剩余待排值
          if (count > 0 && (this.needArrangeNumber > 0 || Math.abs(this.needArrangeNumber) < item.producedCount)) { // 一定是大于零且小于整条的生产值的
          console.log(JSON.parse(JSON.stringify(item)))
          const count = needArrangeNumber > 0 && needArrangeNumber <= item.producedCount ? needArrangeNumber : item.producedCount
          needArrangeNumber = needArrangeNumber - item.producedCount // 剩余待排值
          if (count > 0 && (needArrangeNumber > 0 || Math.abs(needArrangeNumber) < item.producedCount)) { // 一定是大于零且小于整条的生产值的
            // duration  最后一条的数据应该是通过计算得出时间长度的
            const duration = (count / (item.AdvaDevicCropMob / 100)) * item.AdvaDevicRhythm / 60
            newArr.push({
              id: nanoid(),
              type: 'task2',
              text: '任务名称预留',
              partName: item.AdvaDevicName,
              partCode: item.AdvaDevicNumber,
              text: '任务名称111',
              partName: item.partName,
              partCode: item.partCode,
              start_date: handleDatetime2(item.start_date),
              // duration: item.duration,
              duration: duration,
              checked: false,
              progress: 0,
              parent: item.parent,
              saleOrder: 'SO-2026-01001',
              saleOrder: item.saleOrder,
              producedCount: count <= item.producedCount ? count : item.producedCount
            })
          }
        }
      })
      console.log(JSON.parse(JSON.stringify(newArr)), 'newArr')
      // for (let i = 0; i < this.allTasks.length; i++) {
      //
      // }
      this.allTasks = [...this.allTasks, ...newArr]
      // console.log(JSON.parse(JSON.stringify(this.allTasks)), '9999')
      // console.log(JSON.parse(JSON.stringify(this.allTasks)), '77')
      console.log(JSON.parse(JSON.stringify(this.allTasks)), '888')
      this.totalTasks = this.allTasks.length
      this.updatePaginatedTasks()