<template>
  <div>
    <el-card>
      <div class="search-container">
        <span class="show-text">销售订单:</span>
        <el-input v-model="contractNo" placeholder="请输入销售订单" clearable style="width: 150px;margin-right: 10px" />
        <span class="show-text">生产订单:</span>
        <el-input v-model="orderNo" placeholder="请输入生产订单" clearable style="width: 150px;margin-right: 10px" />
        <span class="show-text">产品编码:</span>
        <el-input v-model="productCode" placeholder="请输入产品编码" clearable style="width: 150px;margin-right: 10px" />
        <span class="show-text">产品名称:</span>
        <el-input v-model="productName" placeholder="请输入产品名称" clearable style="width: 150px;margin-right: 10px" />
        <span class="show-text">工序名称:</span>
        <el-input v-model="processName" placeholder="请输入工序名称" clearable style="width: 150px;margin-right: 10px" />
        <br>
        <br>
        <span class="show-text">性质:&nbsp;&nbsp;&nbsp;</span>
        <el-input v-model="nature" placeholder="请输入性质" clearable style="width: 150px;margin-right: 10px" />
        <span class="show-text">要求完工日期:</span>
        <el-date-picker v-model="completionTime" :clearable="false" end-placeholder="结束时间" format="yyyy-MM-dd"
          range-separator="-" start-placeholder="开始时间" style="width: 230px;"type="datetimerange" value-format="yyyy-MM-dd" />
        <span class="show-text">指派对象:</span>
        <el-select v-model="Doing" multiple  @change = "Doingform">
          <el-option v-for="item in Doingoptions"
          :key="item.指南工位号"
          :label="item.指南工位号"
          :value="item.工位号" />
        </el-select>
        <el-button :disabled="loading" icon="el-icon-search" plain type="primary"
          @click="searchTable()">查询</el-button>
      </div>
      
      <!-- <div style="margin-top: 20px;">
        <el-button :disabled="loading" plain type="primary" @click="openTaskAdjust()"
          style="width: 100px;margin-left: 10px;">表单</el-button>
        <el-button :disabled="loading" plain type="primary" @click="openTaskAdjust()"
          style="width: 100px;">日程</el-button>
      </div> -->
      <el-tabs v-model="activeTab" type="card" class="custom-tabs">
        <el-tab-pane label="表单"  name="form">
          <el-table v-loading="loading" :data="tableData" :height="'67vh'" border
          element-loading-background="rgba(0, 0, 0, 0.2)" element-loading-spinner="el-icon-loading"
          highlight-current-row size="mini" style="width: 100%;margin-top: 20px;" tooltip-effect="dark"
          @row-click="handleRowClick">
          <el-table-column align="center" label="序号" type="index" width="50" fixed />
          <el-table-column align="center" prop="合同号" label="销售订单" width="120" fixed />
          <el-table-column align="center" prop="订单号" label="生产订单" width="100" fixed />
          <el-table-column align="center" prop="产品编码" label="零件编码" width="220" />
          <el-table-column align="center" prop="产品名称" label="产品名称" width="190" />
          <el-table-column align="center" prop="计划数量" label="计划数" width="80" />
          <el-table-column align="center" prop="工序名称" label="工序名称" width="120" />
          <el-table-column align="center" prop="性质" label="性质" width="100" />
          <el-table-column align="center" prop="总工时" label="总工时" width="120" />
          <el-table-column align="center" prop="占用情况" label="占用情况" width="120" />
          <el-table-column align="center" prop="指派对象编号" label="指派对象编号" width="120" />
          <el-table-column align="center" prop="指派对象" label="指派对象" width="120" />
          <el-table-column align="center" prop="指派数量" label="指派数量" width="120" />
          <el-table-column align="center" prop="计划开始时间" label="计划开始时间" width="120" />
          <el-table-column align="center" prop="计划完成时间" label="计划完成时间" width="120" />
          <el-table-column align="center" prop="最晚开始时间" label="最晚开始时间" width="120" />
          <el-table-column align="center" label="要求完工日期" width="120">
            <template slot-scope="scope">
              {{ formatDate(scope.row.要求完工日期) }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="可执行" width="70">
            <template slot-scope="scope">
              <div class="status-light" :class="scope.row.可执行 ? 'status-light-green' : 'status-light-gray'" />
            </template>
          </el-table-column>
          <el-table-column align="center" label="收料" width="70">
            <template slot-scope="scope">
              <div v-if =" scope.row.收料数量 < scope.row.计划数量 & scope.row.收料 == 1 "  class="status-light status-light-orange"  />
              <div v-if  =" scope.row.收料数量 >= scope.row.计划数量 & scope.row.收料 == 1 "class="status-light status-light-green " />
              <div v-if ="!scope.row.收料"class="status-light status-light-gray" />
            </template>
          </el-table-column>
          <el-table-column align="center" label="开工" width="70">
            <template slot-scope="scope">
              <div class="status-light" :class="scope.row.开工 ? 'status-light-green' : 'status-light-gray'" />
            </template>
          </el-table-column>
          <el-table-column align="center" label="首检" width="70">
            <template slot-scope="scope">
              <div class="status-light" :class="scope.row.首检 ? 'status-light-green' : 'status-light-gray'" />
            </template>
          </el-table-column>
          <el-table-column align="center" label="巡检" width="70">
            <template slot-scope="scope">
              <div class="status-light" :class="scope.row.巡检 ? 'status-light-green' : 'status-light-gray'" />
            </template>
          </el-table-column>
          <el-table-column align="center" label="外协" width="70">
            <template slot-scope="scope">
              <div class="status-light" :class="scope.row.外协通知 ? 'status-light-orange' : 'status-light-gray'" />
            </template>
          </el-table-column>
          <el-table-column align="center" label="派工调整" width="130">
            <template slot-scope="scope">
              <el-button type="primary" size="mini"
                @click.stop="clickadjust(scope.row)">派工调整</el-button>
            </template>
          </el-table-column>
          <el-table-column align="center" label="外协通知" width="130">
            <template slot-scope="scope">
              <el-button type="primary" size="mini" v-if="scope.row.外协通知==0"
                @click.stop="handleOutsourceNotify(scope.row)">外协通知</el-button>
              <el-button type="primary" size="mini" v-if="scope.row.外协通知==1">已发起</el-button>
            </template>
          </el-table-column>
          <el-table-column align="center" label="进度" width="200">
            <template slot-scope="scope">
              <el-progress :percentage="scope.row.进度" />
            </template>
          </el-table-column>
          <el-table-column align="center" prop="不合格数量" label="报废数" width="70" />
          <el-table-column align="center" label="序检" width="70">
            <template slot-scope="scope">
              <div v-if =" scope.row.进度 == 100 & scope.row.序检 == 0 "  class="status-light status-light-orange"  />
              <div v-else class="status-light" :class="scope.row.序检 ? 'status-light-green' : 'status-light-gray'" />
            </template>
          </el-table-column>
          <!-- <el-table-column align="center" label="测试" width="70">
            <template slot-scope="scope">
              <div class="status-light" :class="scope.row.测试 ? 'status-light-green' : 'status-light-gray'" />
            </template>
          </el-table-column> -->
          <el-table-column align="center" label="入库" width="70">
            <template slot-scope="scope">
              <div class="status-light" :class="scope.row.入库 ? 'status-light-green' : 'status-light-gray'" />
            </template>
          </el-table-column>
          <el-table-column align="center" label="优先级" width="80">
            <template slot-scope="scope">
              <div class="status-light"
                :class="scope.row.优先级 === '是' ? 'status-light-green' : 'status-light-gray'" />
            </template>
          </el-table-column>
          <el-table-column align="center" prop="未完成说明" label="未完成说明" width="120" />
          <el-table-column align="center" prop="派工特殊说明" label="派工特殊备注" width="120" />
          <el-table-column align="center" label="编辑" width="120">
            <template slot-scope="scope">
              <el-button type="text" size="mini" @click="editTask(scope.row)">编辑</el-button>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="最后编辑人" label="最后编辑人" width="100" />
          <el-table-column align="center" label="最后编辑时间" width="170">
            <template slot-scope="scope">
              {{ scope.row.最后编辑时间 }}
            </template>
          </el-table-column>
        </el-table>
        </el-tab-pane>
        <el-tab-pane label="日程" name="schedule">
          <div class="schedule-container">
            <FullCalendar ref="fullCalendar" :options="calendarOptions" />
          </div>
        </el-tab-pane>
      </el-tabs>
        
      
    </el-card>
    <!-- 派工调整 -->
    <el-dialog :visible.sync="dialogadjust" :close-on-click-modal="false" :close-on-press-escape="false"
      title="派工调整" center width="850px">
      <el-form ref="formData" :model="formData" label-width="120px" size="mini">
        
        <el-row>
          <el-col :span="12">
            <el-form-item label="指派对象" prop="指派对象">
              <el-select v-model="formData.指派对象" placeholder="请选择" style="width: 100%" @change="handleStationChange">
                <el-option v-for="item in stationOptions" :key="item.code" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="分配数量" prop="指派数量">
              <el-input-number v-model="formData.指派数量" :min="1" :max="currentRow.计划数量" style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
        
        <el-row>
          <el-col :span="12">
            <el-form-item label="计划开始时间" prop="计划开始时间">
              <el-date-picker v-model="formData.计划开始时间" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"
                style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计划完成时间" prop="计划完成时间">
              <el-date-picker v-model="formData.计划完成时间" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"
                style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="最晚开始时间" prop="最晚开始时间">
              <el-date-picker v-model="formData.最晚开始时间" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"
                style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="派工特殊说明" prop="派工特殊说明">
              <el-input v-model="formData.派工特殊说明" :rows="3" type="textarea" placeholder="请输入派工特殊说明" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogadjust = false">取 消</el-button>
        <el-button type="primary" @click="submitadjust">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 编辑备注弹窗 -->
    <el-dialog :visible.sync="editDialogVisible" title="编辑任务信息" width="600px" center>
      <el-form ref="editForm" :model="editForm" label-width="140px" size="mini">
        <el-form-item label="优先级">
          <el-select v-model="editForm.优先级" placeholder="请选择优先级" style="width: 100%">
            <el-option label="是" value="是" />
            <el-option label="否" value="否" />
          </el-select>
        </el-form-item>
        <el-form-item label="未完成说明">
          <el-input v-model="editForm.未完成说明" :rows="2" type="textarea" placeholder="请输入未完成说明" />
        </el-form-item>
        <el-form-item label="派工特殊备注">
          <el-input v-model="editForm.派工特殊说明" :rows="3" type="textarea" placeholder="请输入派工特殊备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button :loading="editSubmitLoading" type="primary" @click="submitEditForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
<script>
// 这三个组件用于绘制日历
import FullCalendar from '@fullcalendar/vue'
import dayGridPlugin from '@fullcalendar/daygrid'
import interactionPlugin from '@fullcalendar/interaction'
export default {
  components: { FullCalendar },
  data() {
    return {
      activeTab: 'form',
      orderNo: '',
      contractNo: '',
      productCode: '',
      productName: '',
      processName: '',
      nature: '',
      station: '',
      productionStatus: '全部',
      completionTime: [],
      loading: false,
      tableData: [],
      selectedRow: null,
      editDialogVisible: false,
      editSubmitLoading: false,
      currentRow: {},
      editForm: {
        优先级: '',
        未完成说明: '',
        派工特殊说明: ''
      },
      taskAdjustVisible: false,
      taskSubmitLoading: false,
      stationOptions: [],
      taskForm: {
        指派对象: '',
        指派对象编号: '',
        指派数量: 0,
        计划开始时间: '',
        计划完成时间: '',
        最晚开始时间: '',
        派工特殊说明: ''
      },
      checkList: [],
      Doingoptions:[],
      Doing:"",
      dialogadjust:false,
      formData:[],
      // FullCalendar 配置选项
      calendarOptions: {
        plugins: [dayGridPlugin, interactionPlugin], // 加载日视图和交互插件
        initialView: 'dayGridMonth',
        locale: 'zh-cn',
        headerToolbar: {
          left: 'prev,next today',
          center: 'title',
          right: 'today'
        },
        editable: true, // 允许通过拖拽或调整大小来修改事件
        droppable: true,
        events: [],
        eventDrop: this.handleEventDrop, // 拖拽完成后回调
        eventResize: this.handleEventResize, // 调整大小完成后回调
        height: 'auto', // 设置高度为auto，使其自适应内容
        dayMaxEvents: true // 限制每天显示的事件数量
      }
    }
  },
  computed: {
    calendarEvents() {
      return this.tableData.map(item => ({
        id: `${item.订单号}-${item.订单行号}-${item.拆分内码}`,
        title: `${item.进度} | ${item.订单号} | ${item.产品名称} | ${item.产品编码} | 分配数量：${item.指派数量} | 序:${item.工序名称}`,
        start: this.formatDateForCalendar(item.计划开始时间),
        end: this.formatDateForCalendar(item.计划完成时间, true),
        extendedProps: {
          订单号: item.订单号,
          订单行号: item.订单行号,
          拆分内码: item.拆分内码,
          
        }
      }))
      
    }
  },
  watch: {
    activeTab(newVal) {
      if (newVal === 'schedule') {
        this.$nextTick(() => {
          // 判断日历的HTML Dom 是否存在
          const calendarApi = this.$refs.fullCalendar && this.$refs.fullCalendar.getApi()
          if (calendarApi) {
            // 重新绘制日历界面 避免出现未渲染问题
            calendarApi.updateSize()
          }
          this.calendarOptions.events = this.calendarEvents
        })
      }
    },
    tableData: {
      handler() {
        this.calendarOptions.events = this.calendarEvents
        if (this.activeTab === 'schedule') {
          this.$nextTick(() => {
            const calendarApi = this.$refs.fullCalendar && this.$refs.fullCalendar.getApi()
            if (calendarApi) {
              calendarApi.refetchEvents()
            }
          })
        }
      },
      deep: true
    }
  },
  created() {
    var now = new Date()
    var start = new Date(Date.UTC(now.getFullYear() - 1, now.getMonth(), now.getDate(), 0, 0, 0)).toISOString().replace('T', ' ').replace('.000Z', '')
    var end = new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59)).toISOString().replace('T', ' ').replace('.000Z', '')
    this.completionTime = [start, end]
    this.searchTable()
    this.getDoing()
  },
  methods: {
    getDoing(){
      var Data = this.CreateData('11', 'MES_登录_工位与名称_查询')
      this.ExecDatabase(Data).then(response => {
          this.loading = false
          if (response.data.length !== 0) {
              this.Doingoptions= response.data
              
          }
      })
    },
    Doingform(value){
      console.log(value)
    },
    clickadjust(row){
      this.dialogadjust = true
      console.log(this)
      this.formData = {
        指派对象: row.指派对象,
        指派对象编号: row.指派对象编号,
        指派数量: row.计划数量,
        计划开始时间: row.计划开始时间,
        计划完成时间: row.计划完成时间,
        最晚开始时间: row.最晚开始时间,
        派工特殊说明: row.派工特殊说明
      }
    },
    submitadjust(){
      var row = this.selectedRow
      const params = []
      params.push(['订单号', row.订单号])
      params.push(['订单行号', row.订单行号])
      params.push(['订单拆分内码', row.拆分内码])
      params.push(['指派对象编号', this.$refs.formData.model.指派对象编号])
      params.push(['指派对象', this.$refs.formData.model.指派对象])
      params.push(['指派数量', this.$refs.formData.model.指派数量])
      params.push(['派工特殊说明', this.$refs.formData.model.派工特殊说明])
      params.push(['计划开始时间', this.$refs.formData.model.计划开始时间])
      params.push(['计划完成时间', this.$refs.formData.model.计划完成时间])
      params.push(['最晚开始时间', this.$refs.formData.model.最晚开始时间])
      params.push(['派工操作人', this.$store.state.user.name])

      const Data = this.CreateData('12', 'MES_OrderPlanned_SingleTaskPlanned', params)
      this.ExecDatabase(Data).then(response => {
        this.dialogadjust = false
        if (response.data[0].result !== '1') {
          this.$message.error('派工失败')
          return
        }
        this.$message.success('派工成功')
        
      }).catch(() => {
        
      })
    },
    formatDate(date) {
      if (!date) return ''
      return date.split(' ').length > 1 ? date.split(' ')[0] : date
    },
    WorkTimeSum(tdata) {
      var param = []
      param.push(['计划开工_Start', this.completionTime ? this.completionTime[0] : ''])
      param.push(['计划开工_End', this.completionTime ? this.completionTime[1] : ''])
      var Data = this.CreateData('11', 'MES_ProductTask_WorkTimeSum', param)
      this.ExecDatabase(Data).then(response => {
        this.loading = false
        tdata.forEach(item => {
          response.data.forEach(itemtime => {
            if (itemtime.TaskAID == item.TaskAID & itemtime.工序名称 == item.工序名称) {
              item.总工时 = itemtime.总工时
            }
          })
        })
        this.tableData = tdata
      }).catch(() => {
          this.loading = false
      })

    },
    searchTable() {
      this.loading = true
      this.tableData = []
      var param = []
      console.log(this.Doing.toString())
      param.push(['订单号', this.orderNo || 0])
      param.push(['物料类型', '自制件'])
      param.push(['合同号', this.contractNo])
      param.push(['产品编码', this.productCode])
      param.push(['产品名称', this.productName])
      param.push(['工序名称', this.processName])
      param.push(['性质', this.nature])
      param.push(['要求完工日期1', this.completionTime ? this.completionTime[0] : ''])
      param.push(['要求完工日期2', this.completionTime ? this.completionTime[1] : ''])
      param.push(['排产状态', this.productionStatus])
      param.push(['工位', this.Doing.toString()])
      var Data = this.CreateData('11', 'MES_ProductAdmin_Query', param)
      this.ExecDatabase(Data).then(response => {
        this.loading = false
        if (response.data.length !== 0) {
          this.WorkTimeSum(response.data)
          // this.tableData = response.data
        }
      }).catch(() => {
        this.loading = false
      })
    },
    handleRowClick(row) {
      this.selectedRow = row
    },
    // 获取工位列表
    getStationList() {
      const params = []
      const Data = this.CreateData('11', 'Prog_MES_LoadStations', params)
      this.ExecDatabase(Data).then(response => {
        if (response.data && response.data.length > 0) {
          this.stationOptions = response.data.map(item => ({
            label: item.OPName,
            value: item.OPName,
            code: item.VisCode
          }))
        }
      })
    },
    // 处理工位选择
    handleStationChange(value) {
      const selected = this.stationOptions.find(item => item.value === value)
      this.taskForm.指派对象编号 = selected ? selected.code : ''
    },

    // 提交派工调整
    submitTaskForm() {
      if (!this.selectedRow) {
        this.$message.warning('未选择任务')
        return
      }

      if (!this.taskForm.指派对象 || !this.taskForm.指派数量) {
        this.$message.warning('请选择指派对象并设置指派数量')
        return
      }

      this.taskSubmitLoading = true
      const params = []
      params.push(['订单号', this.selectedRow.订单号])
      params.push(['订单行号', this.selectedRow.订单行号])
      params.push(['订单拆分内码', this.selectedRow.拆分内码])
      params.push(['指派对象编号', this.taskForm.指派对象编号])
      params.push(['指派对象', this.taskForm.指派对象])
      params.push(['指派数量', this.taskForm.指派数量])
      params.push(['派工特殊说明', this.taskForm.派工特殊说明 || ''])
      params.push(['计划开始时间', this.taskForm.计划开始时间 || ''])
      params.push(['计划完成时间', this.taskForm.计划完成时间 || ''])
      params.push(['最晚开始时间', this.taskForm.最晚开始时间 || ''])
      params.push(['派工操作人', this.$store.state.user.name])

      const Data = this.CreateData('12', 'Prog_MES_SingleTaskPlanned', params)
      this.ExecDatabase(Data).then(response => {
        if (response.data && response.data.length > 0 && response.data[0] && response.data[0].length > 0) {
          this.$message.error('派工失败: ' + response.data[0])
          return
        }
        this.$message.success('派工调整成功')
        this.taskAdjustVisible = false
        this.searchTable()
      }).catch(() => {
        this.$message.error('派工调整失败')
      }).finally(() => {
        this.taskSubmitLoading = false
      })
    },
    editTask(row) {
      this.currentRow = row
      this.editForm = {
        优先级: row.优先级 || '',
        未完成说明: row.未完成说明 || '',
        派工特殊说明: row.派工特殊说明 || ''
      }
      this.editDialogVisible = true
    },
    submitEditForm() {
      this.editSubmitLoading = true
      const params = []
      params.push(['订单号', this.currentRow.订单号])
      params.push(['订单行号', this.currentRow.订单行号])
      params.push(['订单拆分内码', this.currentRow.拆分内码])
      params.push(['优先级', this.editForm.优先级])
      params.push(['未完成说明', this.editForm.未完成说明])
      params.push(['派工特殊说明', this.editForm.派工特殊说明])
      params.push(['最后编辑人', this.$store.state.user.name])

      const Data = this.CreateData('12', 'MES_OrderPlanned_DescriptionEdit', params)
      this.ExecDatabase(Data).then(() => {
        this.$message.success('保存成功')
        this.editDialogVisible = false
        this.searchTable()
      }).catch(() => {
        this.$message.error('保存失败')
      }).finally(() => {
        this.editSubmitLoading = false
      })
    },
    handleOutsourceNotify(row) {
      this.$confirm('确认同计划发起外协通知吗?', '确认', {
        confirmButtonText: '是',
        cancelButtonText: '否',
        type: 'warning',
        center: true
      }).then(() => {
        const params = []
        params.push(['TaskAID', row.TaskAID])
        params.push(['外协通知', 1])
        const Data = this.CreateData('12', 'MES_ProductTask_Notice', params)
        this.ExecDatabase(Data).then(() => {
          this.$message.success('外协通知已发送')
          this.searchTable()
        })
        
      }).catch(() => {
      })
    },
    openTaskAdjust() {
      console.log('123')
    },
    // 格式化日期以适应 FullCalendar (需要 'yyyy-MM-dd')
    formatDateForCalendar(date, isEnd = false) {
      if (!date) return null
      try {
        let d
        if (typeof date === 'string') {
          // 如果是字符串，解析日期部分
          const datePart = date.split(' ')[0]
          const [year, month, day] = datePart.split('-').map(Number)
          d = new Date(Date.UTC(year, month - 1, day))
        } else if (date instanceof Date) {
          d = new Date(date.getTime())
        }

        if (isEnd) {
          d.setUTCDate(d.getUTCDate() + 1)
        }
        // 转换为 ISO 格式并取日期部分
        const isoString = d.toISOString()
        return isoString.split('T')[0]
      } catch (error) {
        console.error('Error formatting date for calendar:', date, error)
        return null
      }
    },

    // 处理日历事件拖拽完成后的逻辑
    handleEventDrop(info) {
      const event = info.event
      const newStart = this.formatDateForCalendar(event.startStr)
      const endDate = new Date(event.endStr)
      endDate.setUTCDate(endDate.getUTCDate() - 1)
      const newEnd = this.formatDateForCalendar(endDate)

      this.updateTaskTime(event.extendedProps, newStart, newEnd, info.revert)
    },

    // 处理日历事件调整大小完成后
    handleEventResize(info) {
      const event = info.event
      const newStart = this.formatDateForCalendar(event.startStr)
      const endDate = new Date(event.endStr)
      endDate.setUTCDate(endDate.getUTCDate() - 1)
      const newEnd = this.formatDateForCalendar(endDate)

      if (!newStart || !newEnd) {
        this.$message.error('日期格式错误，无法更新')
        info.revert()
        return
      }

      this.updateTaskTime(event.extendedProps, newStart, newEnd, info.revert)
    },
    // 更新时间 传入 revert 回调用于失败时恢复事件位置
    updateTaskTime(taskInfo, startTime, endTime, revertCallback) {
      this.$confirm('确认修改计划时间?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const params = []
        var editstr = "[计划开始时间] = '"+ startTime+"' , [计划完成时间] = '"+ endTime+"'"
        params.push(['editstr', editstr])
        params.push(['订单号', taskInfo.订单号])
        params.push(['订单行号', taskInfo.订单行号])
        params.push(['订单拆分内码', taskInfo.拆分内码])
        // params.push(['计划开始时间', startTime])
        // params.push(['计划完成时间', endTime])
        
        const Data = this.CreateData('12', 'MES_OrderPlanned_EditTaskPlanned', params)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result !== '1') {
            this.$message.error('计划时间更新失败')
            if (revertCallback) revertCallback()
            return
          }
          this.$message.success('计划时间更新成功')
          this.searchTable()
          this.donesearchTable()
        })
      }).catch(() => {
        if (revertCallback) revertCallback()
      })
    }
  }
}
</script>
  
<style scoped>
.search-container {
  margin-bottom: 20px;
}

.show-text {
  margin-right: 5px;
  line-height: 32px;
}

.status-light {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.status-light-orange {
  background-color: #e4a629;
}

.status-light-green {
  background-color: #67C23A;
}

.status-light-gray {
  background-color: #909399;
}

.dialog-footer {
  text-align: right;
}
.schedule-container {
  min-height: 67vh;
}

.schedule-container ::v-deep .fc-daygrid-day-frame {
  padding: 2px;
  min-height: auto;
}

.schedule-container ::v-deep .fc-event {
  font-size: 12px;
  padding: 1px 2px;
  margin-bottom: 1px;
  line-height: 1.4;
}

.schedule-container ::v-deep .fc-daygrid-event-harness {
  margin-bottom: 1px;
}

.schedule-container ::v-deep .fc-daygrid-day-top {
  padding: 2px;
}

.schedule-container ::v-deep .fc-daygrid-more-link {
  font-size: 12px;
  padding: 0 2px;
}
</style>
  