<template>
  <div class="mod-config">
    <fieldset class="customer-field" style="width: 825px; padding: 0.35em 0.75em 0.425em;" >
      <legend>查询条件</legend>
      <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: -2px;" >
        <el-form-item label="订单号">
          <el-input v-model="searchData.orderNo" style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="要求完工日期">
          <el-date-picker
            style="width: 120px"
            v-model="searchData.date1"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="至">
          <el-date-picker
            style="width: 120px"
            v-model="searchData.date2"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="产品编码">
          <el-input v-model="searchData.partNo" style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="录入日期">
          <el-date-picker
            style="width: 120px"
            v-model="searchData.date3"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="至">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.date4"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
        </el-form-item>
      </el-form>
    </fieldset>
    <!--  排序规则  -->
    <fieldset class="customer-field" style="margin-left: 680px; margin-top: 0px; width: 135px;height: 108px" >
      <legend>排序</legend><br>
      <el-form :inline="true" style="margin-top: -10px; margin-bottom: 15px;" label-position="top" label-width="100px" >
        <el-form-item :label="''" style="margin-bottom: 5px;margin-top: 8px">
          <el-radio-group v-model="searchData.sortField">
            <el-radio label="order by needDate">要求完工日期</el-radio>
            <el-radio label="order by orderNo">订单号</el-radio>
            <el-radio label="order by partNo">产品编码</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
    </fieldset>
    <fieldset class="customer-field" style="width: 450px; padding: 0.35em 0.75em 0.425em;margin-top: -107px;" >
      <legend>排产信息</legend>
      <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: -2px;" >

        <el-form-item label="工厂编号">
          <el-input v-model="searchData.site" style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="加工中心">
          <el-input v-model="searchData.workCenterNo" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item >
          <span slot="label" style="" @click="getBaseList(88,1)"><a herf="#">机台：</a></span>
          <el-input v-model="searchData.resourceId" style="width: 120px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: -2px;" >
        <el-form-item label="排产日期">
          <el-date-picker
            style="width: 120px"
            v-model="searchData.scheduleDate"
            type="date"
            value-format="yyyy-MM-dd"
            @change="getTodayShiftNo()"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="班次">
          <el-select v-model="searchData.shiftNo" style="width: 105px"
                     placeholder="请选择">
            <el-option
              v-for="(item,index) in shiftNoList"
              :key="index"
              :label="item.shiftno+'('+item.shiftdesc+')'"
              :value="item.shiftno"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </fieldset>
    <!--  记录示意图  -->
    <fieldset style="margin-left: 460px; margin-top: -108px; width: 180px;height: 108px">
      <legend>记录示意图</legend>
      <el-form :inline="true" label-position="top" label-width="100px" class="customer-card">
        <el-form-item :label="'已关闭,已达数量'">
          <el-card class="customer-el-card customer-el-card-pink"></el-card>
        </el-form-item>
        <el-form-item :label="'已关闭,未达数量'">
          <el-card class="customer-el-card customer-el-card-orange"></el-card>
        </el-form-item>
        <el-form-item :label="'未关闭,未达数量'">
          <el-card class="customer-el-card customer-el-card-blue"></el-card>
        </el-form-item>
      </el-form>
    </fieldset>
    <div style="margin-top: -170px;margin-left: 830px;">
      <el-table
        height="171"
        :data="calendarDateTypeShiftData"
        border
        style="width: 100%">
        <el-table-column
          prop="scheduleDate"
          header-align="center"
          align="left"
          min-width="50"
          label="日期">
        </el-table-column>
        <el-table-column
          prop="info"
          header-align="center"
          align="left"
          min-width="200"
          label="休息时间览表">
        </el-table-column>
      </el-table>

    </div>
    <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 3px;margin-left: 2px" >
      <el-button type="primary" @click="searchAllData()">查询</el-button>
<!--      <el-button type="primary" @click="rescheduled()">重新排产</el-button>-->
      <el-button type="primary" @click="changeModal()">修改计划顺序</el-button>
    </el-form>
    <div class="mainTable">
    <el-table
      :height="height"
      :data="ShopOrderTableData"
      @row-click="setCurrentRoutingRow"
      :row-class-name="routingRowClassName"
      @row-dblclick="startScheduleOperation"
      border
      style="width: 100%">
      <el-table-column
        prop=""
        header-align="center"
        align="center"
        width="70"
        label="操作">
        <template slot-scope="scope" class="foo_container">
          <a type="text" size="small" @click="scheduledModal(scope.row)">多日排产</a>
        </template>
      </el-table-column>
      <el-table-column
        prop="orderNo"
        header-align="center"
        align="left"
        min-width="100"
        label="订单号">
      </el-table-column>
      <el-table-column
        prop="itemNo"
        header-align="center"
        align="left"
        min-width="60"
        label="工序号">
      </el-table-column>
      <el-table-column
        prop="itemDesc"
        header-align="center"
        align="left"
        min-width="200"
        label="工序名称">
      </el-table-column>
      <el-table-column
        prop="needDate"
        header-align="center"
        align="left"
        min-width="100"
        label="要求完成日期">
      </el-table-column>
      <el-table-column
        prop="partNo"
        header-align="center"
        align="left"
        min-width="100"
        label="产品编码">
      </el-table-column>
      <el-table-column
        prop="customerName"
        header-align="center"
        align="left"
        min-width="100"
        label="客户名称">
      </el-table-column>
      <el-table-column
        prop="custPartNo"
        header-align="center"
        align="left"
        min-width="100"
        label="客户产品料号">
      </el-table-column>
      <el-table-column
        prop="partDesc"
        header-align="center"
        align="left"
        min-width="100"
        label="产成品名称">
      </el-table-column>
      <el-table-column
        prop="lotSize"
        header-align="center"
        align="right"
        min-width="80"
        label="订单量">
      </el-table-column>
      <el-table-column
        prop="qtyToSchedule"
        header-align="center"
        align="right"
        min-width="80"
        label="待排产数量">
      </el-table-column>
      <el-table-column
        prop="qtyScheduled"
        header-align="center"
        align="right"
        min-width="80"
        label="已排产数量">
      </el-table-column>
      <el-table-column
        prop="qtyReported"
        header-align="center"
        align="right"
        min-width="80"
        label="已报工数量">
      </el-table-column>
      <el-table-column
        prop="spec"
        header-align="center"
        align="left"
        min-width="100"
        label="规格型号">
      </el-table-column>
      <el-table-column
        prop="site"
        header-align="center"
        align="left"
        min-width="80"
        label="工厂编号">
      </el-table-column>
      <el-table-column
        prop="workCenterNo"
        header-align="center"
        align="left"
        min-width="80"
        label="加工中心">
      </el-table-column>
      <el-table-column
        prop="scheduledFlag"
        header-align="center"
        align="left"
        min-width="80"
        label="是否排产">
      </el-table-column>
      <el-table-column
        prop="availResource"
        header-align="center"
        align="left"
        min-width="80"
        label="可用机台">
      </el-table-column>
      <el-table-column
        prop="enterDate"
        header-align="center"
        align="left"
        min-width="100"
        label="录入日期">
      </el-table-column>
      <el-table-column
        prop="machRunFactor"
        header-align="center"
        align="right"
        min-width="80"
        label="单位产出">
      </el-table-column>
<!--      <el-table-column-->
<!--        prop="timeRequired"-->
<!--        header-align="center"-->
<!--        align="right"-->
<!--        min-width="80"-->
<!--        label="待排产时间">-->
<!--      </el-table-column>-->
      <el-table-column
        prop="efficiency"
        header-align="center"
        align="right"
        min-width="80"
        label="效率">
      </el-table-column>
    </el-table>
    <el-table
      :height="170"
      :data="scheduleTableData"
      @row-dblclick="cancelSchedule"
      :row-class-name="routingRowClassName2"
      border
      style="width: 100%">
      <el-table-column
        prop="scheduledSeqNo"
        header-align="center"
        align="right"
        min-width="70"
        label="排序序号">
      </el-table-column>
<!--      <el-table-column-->
<!--        prop="planStartTime"-->
<!--        header-align="center"-->
<!--        align="left"-->
<!--        min-width="100"-->
<!--        label="计划开工时间">-->
<!--      </el-table-column>-->
<!--      <el-table-column-->
<!--        prop="planFinishTime"-->
<!--        header-align="center"-->
<!--        align="left"-->
<!--        min-width="100"-->
<!--        label="计划完工时间">-->
<!--      </el-table-column>-->
      <el-table-column
        prop="timeRequired"
        header-align="center"
        align="left"
        min-width="100"
        label="计划时间">
      </el-table-column>
      <el-table-column
        prop="orderNo"
        header-align="center"
        align="left"
        min-width="100"
        label="订单号">
      </el-table-column>
      <el-table-column
        prop="needDate"
        header-align="center"
        align="left"
        min-width="100"
        label="需求日期">
      </el-table-column>
      <el-table-column
        prop="itemNo"
        header-align="center"
        align="left"
        min-width="60"
        label="工序号">
      </el-table-column>
      <el-table-column
        prop="itemDesc"
        header-align="center"
        align="left"
        min-width="200"
        label="工序名称">
      </el-table-column>
      <el-table-column
        prop="partNo"
        header-align="center"
        align="left"
        min-width="100"
        label="产品编码">
      </el-table-column>
      <el-table-column
        prop="scheduledDate"
        header-align="center"
        align="left"
        min-width="100"
        label="排产日期">
      </el-table-column>
      <el-table-column
        prop="partDesc"
        header-align="center"
        align="left"
        min-width="100"
        label="产品名称">
      </el-table-column>
      <el-table-column
        prop="spec"
        header-align="center"
        align="left"
        min-width="100"
        label="规格型号">
      </el-table-column>
      <el-table-column
        prop="lotSize"
        header-align="center"
        align="right"
        min-width="80"
        label="待生产数量">
      </el-table-column>
      <el-table-column
        prop="lotSize"
        header-align="center"
        align="right"
        min-width="80"
        label="派工单需求">
      </el-table-column>
      <el-table-column
        prop="qtyReported"
        header-align="center"
        align="right"
        min-width="80"
        label="已报告数量">
      </el-table-column>
      <el-table-column
        prop="resourceId"
        header-align="center"
        align="left"
        min-width="80"
        label="机台号">
      </el-table-column>
      <el-table-column
        prop="customerName"
        header-align="center"
        align="left"
        min-width="120"
        label="客户名称">
      </el-table-column>
      <el-table-column
        prop="enterDate"
        header-align="center"
        align="left"
        min-width="100"
        label="录入日期">
      </el-table-column>
      <el-table-column
        prop="availResource"
        header-align="center"
        align="left"
        min-width="80"
        label="可用机台">
      </el-table-column>
      <el-table-column
        prop="workCenterNo"
        header-align="center"
        align="left"
        min-width="80"
        label="加工中心">
      </el-table-column>
      <el-table-column
        prop="machRunFactor"
        header-align="center"
        align="right"
        min-width="80"
        label="单位产出">
      </el-table-column>
      <el-table-column
        prop="machSetupTime"
        header-align="center"
        align="right"
        min-width="80"
        label="调机时间">
      </el-table-column>
      <el-table-column
        prop="factorUnit"
        header-align="center"
        align="right"
        min-width="80"
        label="产出单位">
      </el-table-column>
      <el-table-column
        prop="site"
        header-align="center"
        align="left"
        min-width="80"
        label="工厂编号">
      </el-table-column>
      <el-table-column
        prop="closedFlag"
        header-align="center"
        align="left"
        min-width="80"
        label="是否关闭">
      </el-table-column>
      <el-table-column
        prop="parkFlag"
        header-align="center"
        align="left"
        min-width="60"
        label="暂停">
      </el-table-column>
      <el-table-column
        prop="eficiency"
        header-align="center"
        align="right"
        min-width="80"
        label="效率">
      </el-table-column>
    </el-table>
    </div>
    <el-dialog title="多日排产" :close-on-click-modal="false" v-drag :visible.sync="scheduledModalFlag" width="700px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="订单号:">
          <el-input v-model="schedulingModalData.orderNo" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="工厂编号:">
          <el-input v-model="schedulingModalData.site" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="要求完工日期:">
          <el-input v-model="schedulingModalData.needDate" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="订单数量:">
          <el-input v-model="schedulingModalData.lotSize" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="待排产数:">
          <el-input v-model="schedulingModalData.qtyToSchedule" disabled style="width: 120px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="产品编码:">
          <el-input v-model="schedulingModalData.partNo" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="产品名称:">
          <el-input v-model="schedulingModalData.partDesc" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="工序号:">
          <el-input v-model="schedulingModalData.itemNo" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="工序名称:">
          <el-input v-model="schedulingModalData.itemDesc" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="加工中心:">
          <el-input v-model="schedulingModalData.workCenterNo" disabled style="width: 120px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="排产机台:">
          <el-select v-model="schedulingModalData.resourceId" style="width: 120px"
                     placeholder="请选择">
            <el-option
              v-for="(item,index) in availableResourceList"
              :key="index"
              :label="item.resourceID"
              :value="item.resourceID"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="排产班次:">
          <el-select v-model="schedulingModalData.shiftNo" style="width: 120px"
                     placeholder="请选择">
            <el-option
              v-for="(item,index) in allShiftNoList"
              :key="index"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="本次累计排产数量:">
          <el-input v-model="schedulingModalData.sumQty" type="number" disabled style="width: 120px"></el-input>
          <el-button type="primary" @click="addPlans()" style="margin-left: 10px;">添加</el-button>
          <el-button type="primary" @click="savePlans()">保存</el-button>
          <el-button type="primary" @click="scheduledModalFlag = false">关闭</el-button>
        </el-form-item>
      </el-form>
      <div class="inputTable">
      <el-table
        height="200"
        :data="schedulingModalTableData"
        border
        style="width: 100%">
        <el-table-column
          prop="scheduleDate"
          header-align="center"
          align="left"
          min-width="100"
          label="排产日期">
          <template slot-scope="scope">
            <el-date-picker
              style="width: 95%"
              class="sl-input"
              v-model="scope.row.scheduleDate"
              type="date"
              value-format="yyyy-MM-dd"
              @change="getTodayShiftNo2(scope.$index)"
              placeholder="选择日期">
            </el-date-picker>
          </template>
        </el-table-column>
        <el-table-column
          prop="scheduleQty"
          header-align="center"
          align="right"
          min-width="80"
          label="排产数量">
          <template slot-scope="scope">
            <el-input v-model="scope.row.scheduleQty" type="number" @change="changeSum" style="width:98%"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="resourceId"
          header-align="center"
          align="left"
          min-width="80"
          label="排产机台">
          <template slot-scope="scope">
            <el-select v-model="scope.row.resourceId" placeholder="请选择" style="height: 12px;padding: 0px " filterable allow-create>
              <el-option v-for="item in availableResourceList " :key="index" :label="item.resourceID" :value="item.resourceID">

              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop="shiftNo"
          header-align="center"
          align="left"
          min-width="80"
          label="排产班次">
          <template slot-scope="scope">
            <el-select v-model="scope.row.shiftNo" placeholder="请选择" style="height: 12px;padding: 0px " filterable allow-create>
              <el-option v-for="item in schedulingModalTableData[scope.$index].selectList " :key="index" :label="item.shiftno" :value="item.shiftno">

              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop=""
          header-align="center"
          align="center"
          width="100"
          label="操作">
          <template slot-scope="scope" class="foo_container">
            <a type="text" size="small" @click="splitScheduleTable(scope.$index)">删除</a>
            <a type="text" size="small" @click="getHasScheduledData(scope.row)">当日负荷</a>
          </template>
        </el-table-column>
      </el-table>
      </div>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="scheduledModalFlag = false">关闭</el-button>
        <!--        <el-button type="primary" :disabled="bannersBut" @click="saveBanners()">确定</el-button>-->
      </el-footer>
    </el-dialog>
    <el-dialog title="查看负荷" :close-on-click-modal="false" v-drag :visible.sync="hasScheduledModalFlag" width="400px">
      <el-table
        height="300"
        :data="hasScheduledData"
        border
        style="width: 100%">
        <el-table-column
          prop="orderNo"
          header-align="center"
          align="left"
          min-width="100"
          label="订单编号">
        </el-table-column>
        <el-table-column
          prop="itemNo"
          header-align="center"
          align="left"
          min-width="80"
          label="工序号">
        </el-table-column>
        <el-table-column
          prop="qtyRequired"
          header-align="center"
          align="right"
          min-width="80"
          label="排产数量">
        </el-table-column>
        <el-table-column
          prop="sShiftNo"
          header-align="center"
          align="left"
          min-width="80"
          label="班次编码">
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog title="修改顺序" :close-on-click-modal="false" v-drag :visible.sync="changeModalFlag" width="700px">
      <div class="inputTable">
      <el-table
        height="200"
        :data="changeTableData"
        border
        style="width: 100%">
        <el-table-column
          prop="scheduledSeqNo"
          header-align="center"
          align="right"
          min-width="80"
          label="排产序号">
          <template slot-scope="scope">
            <el-input v-model="scope.row.scheduledSeqNo" type="number"     onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')"  style="width:98%;text-align: right"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="orderNo"
          header-align="center"
          align="left"
          min-width="80"
          label="订单号">
        </el-table-column>
        <el-table-column
          prop="itemNo"
          header-align="center"
          align="left"
          min-width="80"
          label="工序号">
        </el-table-column>
        <el-table-column
          prop="scheduledDate"
          header-align="center"
          align="left"
          min-width="100"
          label="排产日期">
        </el-table-column>
        <el-table-column
          prop="lotSize"
          header-align="center"
          align="right"
          min-width="80"
          label="排产数量">
        </el-table-column>
      </el-table>
      </div>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="changeSeqNo">保存</el-button>
        <el-button type="primary" @click="changeModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>
    <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>
  </div>
</template>

<script>
  import {
    getWeekShiftData,
    getShopOrderOutData,
    getOrderScheduleList,
    getWorkCenterNoWithSiteResourceId,
    getTodayShiftNoList,
    getSORoutingAvailableResourceList,
    getHasScheduledData,
    scheduleOne,
    scheduleDatas,
    cancelScheduleData,
    rescheduleData,
    changeSoScheduledListSeqNo,
  } from '@/api/production/dailyPlan.js'
  import {

    getShiftData,

  } from '@/api/prd.js'
  import Chooselist from '@/views/modules/common/Chooselist'
  export default {
    name: 'dailyPlan',
    components: {
      Chooselist
    },
    data () {
      return {
        shiftNoList: [],
        tagNo:'',
        tagNo2:'',
        height:200,
        searchData:{
          orderNo:'',
          date1:'',
          date2:'',
          partNo:'',
          date3:'',
          date4:'',
          sortField:'',
          scheduleDate:new Date(),
          site:this.$store.state.user.site,
          workCenterNo:'',
          resourceId:'',
          shiftNo:'',
          itemNo:'',
        },
        schedulingModalData:{
          orderNo:'',
          site:'',
          needDate:'',
          lotSize:'',
          qtyToSchedule:'',
          partNo:'',
          partDesc:'',
          itemNo:'',
          itemDesc:'',
          workCenterNo:'',
          scheduleDate:'',
          scheduleQty:'',
          resourceId:'',
          shiftNo:'',
          sumQty:'',
        },
        scheduledModalFlag:false,
        hasScheduledModalFlag:false,
        changeModalFlag:false,
        allShiftNoList:[],
        scheduleTableData:[],
        ShopOrderTableData:[],
        availableResourceList:[],
        calendarDateTypeShiftData:[],
        schedulingModalTableData:[],
        hasScheduledData:[],
        currentRoutingRow:null,
        changeTableData:[],
      }
    },
    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight - 480
      })
    },
    methods: {
      getAllShiftNoList () {
        this.selectList = []
        getShiftData().then(({data}) => {
          let list = data.rows
          for (let i = 0; i < list.length; i++) {
            let resultData = {
              value: list[i].shiftno,
              label: list[i].shiftno+'('+list[i].shiftdesc+')'
            }
            this.allShiftNoList.push(resultData)
          }
          if(list.length>0){
            this.schedulingModalData.shiftNo=data.rows[0].shiftno
          }
        })
      },
      getBaseData(val){
        if (this.tagNo === 24){
          if(this.tagNo2===1) {
            this.searchData.workCenterNo = val.WorkCenterNo

          }else {
            this.searchData.workCenterNo = val.WorkCenterNo
          }
        }
        if (this.tagNo === 88){
          if(this.tagNo2===1) {
            this.searchData.resourceId = val.ResourceID
            this.getWorkCenterNo();
          }else {
            this.searchData.resourceId = val.ResourceID
          }
        }
      },
      // 获取基础数据列表
      getBaseList(val,val2){
        this.tagNo = val
        this.tagNo2 = val2
        this.$nextTick(() => {
          let strVal = "";
          if (val === 24){
            if(val2===1) {
              strVal = this.searchData.workCenterNo
            }else {
              strVal = this.searchData.workCenterNo
            }
          }
          if (val === 88){
            if(val2===1) {
              strVal = this.searchData.resourceId
            }else {
              strVal = this.searchData.resourceId
            }
          }

          this.$refs.baseList.init(val,strVal)
        })
      },
      getWeekShiftData(){
        let inData={
          site:this.searchData.site,
          workCenterNo:this.searchData.workCenterNo,
          resourceID:this.searchData.resourceId,
          scheduleDate:this.searchData.scheduleDate,
        }
        getWeekShiftData(inData).then(({data}) => {
          this.calendarDateTypeShiftData = data.rows
        })
      },
      getShopOrderOutData(){
        getShopOrderOutData(this.searchData).then(({data}) => {
          this.ShopOrderTableData = data.rows
        })
      },
      getOrderScheduleList(){
        let inData={
          scheduleDate:this.searchData.scheduleDate,
          site:this.searchData.site,
          workCenterNo:this.searchData.workCenterNo,
          resourceId:this.searchData.resourceId,
        }
        getOrderScheduleList(inData).then(({data}) => {
          this.scheduleTableData = data.rows
        })
      },
      scheduledModal(row){
        if(row.qtyToSchedule==0){
          this.$alert('该订单已排产完毕！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        this.schedulingModalData={
            orderNo:row.orderNo,
            site:row.site,
            needDate:row.needDate,
            lotSize:row.lotSize,
            qtyToSchedule:row.qtyToSchedule,
            partNo:row.partNo,
            partDesc:row.partDesc,
            itemNo:row.itemNo,
            itemDesc:row.itemDesc,
            workCenterNo:row.workCenterNo,
            scheduleDate:'',
            scheduleQty:'',
            resourceId:'',
            shiftNo:'',
            sumQty:0,
        };
        this.schedulingModalTableData=[];
        this.getAvailableResourceList(row);
        this.getAllShiftNoList();
        this.scheduledModalFlag=true;
      },
      searchAllData(){
        if(this.searchData.site==""||this.searchData.site==null){
          this.$alert('请输入工厂！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if(this.searchData.resourceId==""||this.searchData.resourceId==null){
          this.$alert('请输入机台！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        this.getShopOrderOutData();
        this.getOrderScheduleList();
      },
      addPlans(){

        if (this.schedulingModalData.resourceId == '') {
          this.$alert('请选择机台！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.schedulingModalData.shiftNo == '') {
          this.$alert('请选择排产班次！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        this.schedulingModalTableData.push({ scheduleQty:0,
          resourceId:this.schedulingModalData.resourceId,
          shiftNo:this.schedulingModalData.shiftNo,
          scheduleDate:null,
          selectList:[]})
        this.sumQty+=this.schedulingModalData.scheduleQty;
      },
      splitScheduleTable(index){

        this.schedulingModalTableData.splice(index,1);
        this.changeSum();
      },
      getWorkCenterNo(){
        let inData={
          site:this.$store.state.user.site,
          resourceID:this.searchData.resourceId
        }
        getWorkCenterNoWithSiteResourceId(inData).then(({data}) => {
          this.searchData.workCenterNo = data.rows[0].workCenterNo
          this.getWeekShiftData();
          this.getOrderScheduleList();
        })
      },
      getTodayShiftNo(){
        let inData={
          scheduledate:this.searchData.scheduleDate,
          site:this.searchData.site,
        };
        this.getOrderScheduleList();
          getTodayShiftNoList(inData).then(({data}) => {
          this.shiftNoList = data.rows
        })
      },
      getTodayShiftNo2(index){
        let inData={
          scheduledate:this.schedulingModalTableData[index].scheduleDate,
          site:this.searchData.site,
        };
        getTodayShiftNoList(inData).then(({data}) => {
          this.schedulingModalTableData[index].selectList = data.rows
          //如果当天不存在默认班次就删除
          if(data.rows.length>0){
            let flag=true;
            for (let i = 0; i <data.rows.length ; i++) {
              if(data.rows[i].shiftno==this.schedulingModalTableData[index].shiftNo){
                flag=false;
              }
            }
            if (flag){
              this.schedulingModalTableData[index].shiftNo='';
            }
          }else {
            this.schedulingModalTableData[index].shiftNo='';
          }

        })
      },
      getAvailableResourceList(row){
        let inData={
          orderNo:row.orderNo,
          site:row.site,
          itemNo:row.itemNo,
        };
        getSORoutingAvailableResourceList(inData).then(({data}) => {
          this.availableResourceList = data.rows
          if(data.rows.length>0){
            this.schedulingModalData.resourceId=data.rows[0].resourceID
          }
        })
      },
      getHasScheduledData(row){
        if(row.scheduleDate==null||row.scheduleDate==''){
          this.$alert('请选择排产日期！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        let inData={
          site:row.site,
          sResourceID:row.resourceId,
          sScheduledDate:row.scheduleDate,
          sShiftNo:row.shiftNo,
        }
        getHasScheduledData(inData).then(({data}) => {
          this.hasScheduledData = data.rows
        })
        this.hasScheduledModalFlag=true;
      },
      /*设置工艺的行*/
      setCurrentRoutingRow(row, column, event) {
        this.currentRoutingRow = JSON.parse(JSON.stringify(row));
      },
      /*设置当前行的下标*/
      routingRowClassName({row, rowIndex}){
        //判断当前行颜色参数
        if(row.qtyScheduled  > 0){
          return 'customer-row-gray';
        }
      },
      /*开始排产的操作*/
      routingRowClassName2({row, rowIndex}){
        let date=new Date();
        let planDate=new Date(row.planFinishTime.replace("-","/"))
        //判断当前行颜色参数
        if(row.closedFlag=="Y" && row.qtyReported>=row.lotSize){
          return 'customer-row-1';
        }else if(row.closedFlag=="Y" && row.qtyReported<row.lotSize){
          return 'customer-row-2';
        }else if(planDate<date){
          return 'customer-row-3';
        }
      },
      startScheduleOperation(row, $event, column){
        if(this.searchData.site==""||this.searchData.site==null){
          this.$alert('请输入工厂！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if(this.searchData.resourceId==""||this.searchData.resourceId==null){
          this.$alert('请输入机台！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if(this.searchData.scheduleDate==""||this.searchData.scheduleDate==null){
          this.$alert('请选择排产日期！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if(this.searchData.shiftNo==""||this.searchData.shiftNo==null){
          this.$alert('请选择班次！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
       let inData={
         site:this.$store.state.user.site,
         orderNo:row.orderNo,
         itemNo:row.itemNo,
         workCenterNo:this.searchData.workCenterNo,
         resourceID:this.searchData.resourceId,
         qtyToSchedule:row.qtyToSchedule,
         scheduleDate:this.searchData.scheduleDate,
         scheduleTime:this.searchData.scheduleDate,
         userId:this.$store.state.user.name,
       }
       scheduleOne(inData).then(({data}) => {
         if(data.code===0){
             row.qtyToSchedule = 0;
             row.qtyScheduled = row.lotSize
           this.getOrderScheduleList();
         }else {
           this.$alert(data.msg, '错误', {
             confirmButtonText: '确定'
           })
         }
       })

        //自己赋值给自己
        //this.shopOrderList = JSON.parse(JSON.stringify(this.shopOrderList));
        //this.$message.error('字段time_required找不到!');
      },
      changeSum(){
        let sum=0;
        if(this.schedulingModalTableData.length>0) {
          for (let i = 0; i < this.schedulingModalTableData.length; i++) {
            if (this.schedulingModalTableData[i].scheduleQty != "" && this.schedulingModalTableData[i].scheduleQty != null) {
              sum += Number(this.schedulingModalTableData[i].scheduleQty);
            }
          }
        }
        this.schedulingModalData.sumQty = sum;
      },
      savePlans(){
        if(this.schedulingModalTableData.length==0){
          this.$alert('未添加排产记录！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if(this.schedulingModalData.sumQty>this.schedulingModalData.qtyToSchedule){
          this.$alert('排产数量超出可排产数量！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        let inList=[];
        for (let i = 0; i < this.schedulingModalTableData.length; i++) {
          if (this.schedulingModalTableData[i].scheduleQty == "" || this.schedulingModalTableData[i].scheduleQty == null || this.schedulingModalTableData[i].scheduleQty ==0) {
            this.$alert('未输入排产数量！', '错误', {
              confirmButtonText: '确定'
            })
            return false
          }
          if (this.schedulingModalTableData[i].scheduleDate == "" || this.schedulingModalTableData[i].scheduleDate == null) {
            this.$alert('未选择排产日期！', '错误', {
              confirmButtonText: '确定'
            })
            return false
          }
          if (this.schedulingModalTableData[i].shiftNo == "" || this.schedulingModalTableData[i].shiftNo == null) {
            this.$alert('未选择排产班次！', '错误', {
              confirmButtonText: '确定'
            })
            return false
          }
          let thisData={
            site:this.$store.state.user.site,
            orderNo:this.schedulingModalData.orderNo,
            itemNo:this.schedulingModalData.itemNo,
            workCenterNo:this.schedulingModalData.workCenterNo,
            resourceID:this.schedulingModalTableData[i].resourceId,
            qtyToSchedule:this.schedulingModalTableData[i].scheduleQty,
            scheduleDate:this.schedulingModalTableData[i].scheduleDate,
            userId:this.$store.state.user.name,
          }
          inList.push(thisData);
        }
        scheduleDatas(inList).then(({data}) => {
          if(data.code===0){
            for (let i = 0; i <this.ShopOrderTableData.length ; i++) {
              if(inList[0].orderNo==this.ShopOrderTableData[i].orderNo && inList[0].itemNo==this.ShopOrderTableData[i].itemNo){
                this.ShopOrderTableData[i].qtyToSchedule=Number(this.ShopOrderTableData[i].qtyToSchedule)-Number(this.schedulingModalData.sumQty)
                this.ShopOrderTableData[i].qtyScheduled=Number(this.ShopOrderTableData[i].qtyScheduled)+Number(this.schedulingModalData.sumQty)
              }
            }
            this.getOrderScheduleList();
            this.schedulingModalTableData=[];
            this.scheduledModalFlag=false;
            this.$message({
              message: '保存成功',
              type: 'success',
              duration: 1500,

              onClose: () => {
              }
            })
          }else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      cancelSchedule(row, $event, column){
        this.$confirm(`是否取消排产此条记录?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let inData={
            site:row.site,
            orderNo:row.orderNo,
            itemNo:row.itemNo,
            seqNo:row.seqNo,
            workCenterNo:row.workCenterNo,
            resourceID:row.resourceId,
            scheduledQty:row.lotSize,
          }
          cancelScheduleData(inData).then(({data}) => {
            if(data.code===0){
              for (let i = 0; i <this.ShopOrderTableData.length ; i++) {
                if(row.orderNo==this.ShopOrderTableData[i].orderNo && row.itemNo==this.ShopOrderTableData[i].itemNo){
                  this.ShopOrderTableData[i].qtyToSchedule=Number(this.ShopOrderTableData[i].qtyToSchedule)+Number(row.lotSize)
                  this.ShopOrderTableData[i].qtyScheduled=Number(this.ShopOrderTableData[i].qtyScheduled)-Number(row.lotSize)

                }
              }
              this.getOrderScheduleList();
            }else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        })
      },
      rescheduled(){
        if(this.searchData.site==""||this.searchData.site==null){
          this.$alert('请输入工厂！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if(this.searchData.resourceId==""||this.searchData.resourceId==null){
          this.$alert('请输入机台！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if(this.searchData.scheduleDate==""||this.searchData.scheduleDate==null){
          this.$alert('请选择排产日期！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        let inData={
          site:this.$store.state.user.site,
          workCenterNo:this.searchData.workCenterNo,
          resourceID:this.searchData.resourceId,
          scheduleDate:this.searchData.scheduleDate,
          scheduleTime:this.searchData.scheduleDate,
        }
        this.$confirm(`是否重新排产该机台当日日计划?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() =>{
          rescheduleData(inData).then(({data}) =>{
            if(data.code===0){
              for (let i = 0; i <this.ShopOrderTableData.length ; i++) {
                if(inList[0].orderNo==this.ShopOrderTableData[i].orderNo && inList[0].itemNo==this.ShopOrderTableData[i].itemNo){
                  this.ShopOrderTableData[i].qtyToSchedule=Number(this.ShopOrderTableData[i].qtyToSchedule)-Number(this.schedulingModalData.sumQty)
                  this.ShopOrderTableData[i].qtyScheduled=Number(this.ShopOrderTableData[i].qtyScheduled)+Number(this.schedulingModalData.sumQty)
                }
              }
              this.getOrderScheduleList();
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,

                onClose: () => {
                }
              })
            }else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        })
      },
      changeModal(){
        if(this.searchData.site==""||this.searchData.site==null){
          this.$alert('请输入工厂！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if(this.searchData.resourceId==""||this.searchData.resourceId==null){
          this.$alert('请输入机台！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if(this.searchData.scheduleDate==""||this.searchData.scheduleDate==null){
          this.$alert('请选择排产日期！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        let inData={
          scheduleDate:this.searchData.scheduleDate,
          site:this.searchData.site,
          workCenterNo:this.searchData.workCenterNo,
          resourceId:this.searchData.resourceId,
        }
        getOrderScheduleList(inData).then(({data}) => {
          this.changeTableData = data.rows
          if(this.changeTableData.length==0){
            this.$alert('该机台无排产计划！', '错误', {
              confirmButtonText: '确定'
            })
            return false
          }
          this.changeModalFlag=true;
        })

      },
      changeSeqNo(){
        if(this.changeTableData.length==0){
          this.$alert('该机台无排产计划！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        let inList=[];
        for (let i = 0; i <this.changeTableData.length ; i++) {
          let data1={
            site:this.changeTableData[i].site,
            workCenterNo:this.changeTableData[i].workCenterNo,
            resourceID:this.changeTableData[i].resourceId,
            linkedSeqNo:this.changeTableData[i].linkedSeqNo,
            scheduledSeqNo:this.changeTableData[i].scheduledSeqNo,
          }
          inList.push(data1);
        }
        this.$confirm(`是否修改计划顺序?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() =>{
          changeSoScheduledListSeqNo(inList).then(({data}) =>{
            if(data.code===0){
              this.changeModalFlag=false;
              this.getOrderScheduleList();
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {

                }
              })
            }else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        })
      },
    },
    created () {
      this.getTodayShiftNo();
    }
  }
</script>

<style scoped>
  /* 控制el-card标签的数据*/
  div.customer-el-card {
    margin-left: 110px;
    margin-top: -15px;
    height: 20px;
    width: 60px;
  }

</style>
