<template>
  <div class="mod-config">
    <el-form :inline="true"  label-position="top" label-width="100px" >
      <el-form-item :label="'工厂编码'">
        <el-input v-model="searchData.site" style="width: 130px"></el-input>
      </el-form-item>
      <el-form-item :label="'生产订单号'">
        <el-input v-model="searchData.orderNo" style="width: 130px"></el-input>
      </el-form-item>
      <el-form-item :label="'派工单号'">
        <el-input v-model="searchData.seqNo" type="number" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item >
        <span slot="label" style="" @click="getBaseList(24)"><a herf="#">加工中心编码</a></span>
        <el-input v-model="searchData.sWorkCenterNo" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item >
        <span slot="label" style="" @click="getBaseList(5)"><a herf="#">产品编码</a></span>
        <el-input v-model="searchData.partNo" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'规格型号'">
        <el-input v-model="searchData.partDesc" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'派工单类型'">
        <el-select v-model="searchData.scheduleType" style="width: 120px">
          <el-option label="全部" value=""></el-option>
          <el-option label="生产订单派工单" value="生产订单派工单"></el-option>
          <el-option label="日计划派工单" value="日计划派工单"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'派工单是否关闭'">
        <el-select v-model="searchData.closedFlag" style="width: 120px">
          <el-option label="全部" value=""></el-option>
          <el-option label="是" value="Y"></el-option>
          <el-option label="否" value="N"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <el-form :inline="true"  label-position="top" label-width="100px" style="margin-top: 0px;">
      <el-form-item :label="'派工日期：'">
        <el-date-picker
          style="width: 130px"
          v-model="searchData.startDate"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="'至: '">
        <el-date-picker
          style="width: 130px"
          v-model="searchData.endDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item >
        <span slot="label" style="" @click="getBaseList(26,3)"><a herf="#">操作员姓名</a></span>
        <el-input v-model="searchData.operatorName" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item >
        <span slot="label" style="" @click="getBaseList(88)"><a herf="#">机台ID</a></span>
        <el-input v-model="searchData.sResourceID" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="是否返修">
        <el-select v-model="searchData.repairSOFlag" style="width: 120px">
          <el-option label="全部" value=""></el-option>
          <el-option label="返修" value="Y"></el-option>
          <el-option label="非返修" value="N"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'班次'">
        <el-select v-model="searchData.sShiftNo" style="width: 120px">
          <el-option label="全部" value=""></el-option>
          <el-option label="白班" value="白班"></el-option>
          <el-option label="晚班" value="晚班"></el-option>
          <el-option label="加班" value="加班"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'上道派工单'">
        <el-input v-model="searchData.previousSeqNo" style="width: 130px"></el-input>
      </el-form-item>
      <el-form-item :label="'发料派工单'">
        <el-input v-model="searchData.materSeqNo" style="width: 130px"></el-input>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button @click="search()" style="margin-left: 0px;margin-top:0px" type="primary">查询</el-button>
        <download-excel
          :fields="exportDataStandard"
          :data="tableData"
          type="xlsx"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :defaultValue="exportDefaultValue"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{'导出'}}
        </download-excel>
      </el-form-item>
    </el-form>
    <el-form :inline="true"  label-position="top" label-width="100px" style="margin-top: 0px;">
      <el-form-item :label="' '">
        <el-button @click="openStart()" style="margin-left: 0px;margin-top:0px" type="primary">派工单开始</el-button>
        <el-button @click="openScan()" style="margin-left: 0px;margin-top:0px" type="primary">派工单报工</el-button>
        <el-button @click="stopScan()" style="margin-left: 0px;margin-top:0px" type="primary">派工单异常暂停 </el-button>
        <el-button @click="continueScan()" style="margin-left: 0px;margin-top:0px" type="primary">派工单异常继续</el-button>
        <download-excel
          :fields="exportDataStandard"
          :data="tableData"
          type="xlsx"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :defaultValue="exportDefaultValue"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{'导出'}}
        </download-excel>
      </el-form-item>
    </el-form>
    <el-table
      :height="height"
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        prop=""
        header-align="center"
        align="center"
        min-width="100"
        label="操作">
        <template slot-scope="scope" class="foo_container">
          <a type="text" size="small" @click="initReportModal(scope.row)">报工</a>
          <a type="text" size="small" @click="SOPModal2(scope.row)">查看SOP</a>
        </template>
      </el-table-column>
      <el-table-column
        prop="site"
        header-align="center"
        align="left"
        min-width="60"
        label="工厂编码">
      </el-table-column>
      <el-table-column
        prop="seqNo"
        header-align="center"
        align="left"
        min-width="70"
        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="sScheduledDate"
        header-align="center"
        align="left"
        min-width="80"
        label="派工日期">
      </el-table-column>
      <el-table-column
        prop="operatorName"
        header-align="center"
        align="left"
        min-width="80"
        label="操作员姓名">
      </el-table-column>
      <el-table-column
        prop="partNo"
        header-align="center"
        align="left"
        min-width="80"
        label="产品编码">
      </el-table-column>
      <el-table-column
        prop="partDesc"
        header-align="center"
        align="left"
        min-width="200"
        label="产品名称">
      </el-table-column>
      <el-table-column
        prop="scheduleType"
        header-align="center"
        align="left"
        min-width="100"
        label="派工单类型">
      </el-table-column>
      <el-table-column
        prop="itemNo"
        header-align="center"
        align="left"
        min-width="70"
        label="工序号">
      </el-table-column>
      <el-table-column
        prop="itemDesc"
        header-align="center"
        align="left"
        min-width="160"
        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="jobType"
        header-align="center"
        align="center"
        min-width="70"
        label="派工类型">
      </el-table-column>
      <el-table-column
        prop="weight"
        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="qtyApprove"
        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="sResourceID"
        header-align="center"
        align="left"
        min-width="70"
        label="机台ID">
      </el-table-column>
      <el-table-column
        prop="sShiftNo"
        header-align="center"
        align="left"
        min-width="70"
        label="班次">
      </el-table-column>
      <el-table-column
        prop="sWorkCenterNo"
        header-align="center"
        align="left"
        min-width="100"
        label="加工中心编码">
      </el-table-column>
      <el-table-column
        prop="previousSeqNo"
        header-align="center"
        align="center"
        min-width="80"
        label="上道派工单">
      </el-table-column>
      <el-table-column
        prop="previousBatchNo"
        header-align="center"
        align="center"
        min-width="120"
        label="发料批号">
      </el-table-column>
      <el-table-column
        prop="materSeqNo"
        header-align="center"
        align="center"
        min-width="80"
        label="发料派工单">
      </el-table-column>
    </el-table>
    <el-dialog title="扫描派工单" :close-on-click-modal="false" v-drag :visible.sync="scanModalFlag" width="215px" >
      <el-form :inline="true" label-position="top" style="margin-left: 22px;margin-top: -5px;" @submit.native.prevent>
        <el-form-item :label="'派工单号：'">
          <el-input v-model="scanSeqNo" ref="input" type="number" style="width: 130px;"  @keyup.enter.native="searchSeqNo()"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="searchSeqNo()">搜索</el-button>
        <el-button type="primary" @click="scanModalFlag = false">取消</el-button>
      </el-footer>
    </el-dialog>
    <el-dialog title="开始派工单" :close-on-click-modal="false" v-drag :visible.sync="startModalFlag" width="215px">
      <el-form :inline="true" label-position="top" style="margin-left: 22px;margin-top: -5px;" @submit.native.prevent>
        <el-form-item :label="'派工单号：'">
          <el-input v-model="scanSeqNo" ref="start" type="number" style="width: 130px;" ></el-input>
        </el-form-item>
        <el-form-item label="工位：" >
          <el-select v-model="tvId" style="width: 130px">
            <el-option label="无" value="" ></el-option>
            <el-option
              v-for="(item,index) in tvList"
              :key="index"
              :label="item.tvId+'-'+item.workStation"
              :value="item.tvId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="'上道派工单：'">
          <el-input v-model="previousSeqNo" type="number" style="width: 130px;" ></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="startSeqNo()">开始</el-button>
        <el-button type="primary" @click="startModalFlag = false">取消</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="派工单暂停" :close-on-click-modal="false" v-drag :visible.sync="stopModalFlag" width="620px" >
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="'派工单号：'">
          <el-input v-model="stopData.seqNo" ref="stop" type="number"  @keyup.enter.native="seqNoCheck()" style="width: 85px"></el-input>
        </el-form-item>
        <el-form-item :label="'生产订单：'">
          <el-input v-model="stopData.orderNo" disabled style="width: 100px"></el-input>
        </el-form-item>
        <el-form-item :label="'机台：'">
          <el-input v-model="stopData.resourceDesc" disabled style="width: 100px"></el-input>
        </el-form-item>
        <el-form-item :label="'班次：'">
          <el-input v-model="stopData.shiftNo" disabled style="width: 100px"></el-input>
        </el-form-item>
        <el-form-item :label="'异常原因：'">
          <el-select v-model="stopData.abnormalCode"  style="width: 120px">
            <el-option
              v-for="(item,index) in abnormalList"
              :key="index"
              :label="item.abnormalDesc"
              :value="item.abnormalCode"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 0px;">
        <el-form-item :label="'异常数量：'">
          <el-input v-model="stopData.abnormalQty"  type="number" style="width: 85px"></el-input>
        </el-form-item>
        <el-form-item :label="'异常情况影响分析：'">
          <el-input v-model="stopData.abnormalInfluence"  style="width: 350px"></el-input>
        </el-form-item>
        <el-form-item :label="'下一步派工单：'">
          <el-input v-model="stopData.nextSeqNo"  type="number" style="width: 85px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 0px;">
        <el-form-item label="异常情况描述">
          <el-input v-model="stopData.abnormalRemark" type="textarea"  :rows="3" resize='none' style="width: 562px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 50px;">
        <el-upload drag :file-list="fileList"
                   action="javascript:void(0);" ref="uploadFile"
                   :on-change="onChange"
                   multiple :auto-upload="false"
                   style="text-align: left;">
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        </el-upload>
      </el-form>
      <el-footer style="height:30px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="stopWork()" >保存</el-button>
        <el-button type="primary" @click="stopModalFlag = false">取消</el-button>
      </el-footer>
    </el-dialog>
    <el-dialog title="派工单继续" :close-on-click-modal="false" v-drag :visible.sync="continueModalFlag" width="215px">
      <el-form :inline="true" label-position="top" style="margin-left: 22px;margin-top: -5px;" @submit.native.prevent>
        <el-form-item :label="'派工单号：'">
          <el-input v-model="scanSeqNo" ref="continue" type="number" style="width: 130px;"  @keyup.enter.native="continueWork()"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="continueWork()">开始</el-button>
        <el-button type="primary" @click="continueModalFlag = false">取消</el-button>
      </el-footer>
    </el-dialog>
    <el-dialog class="big" @close="closeDialog" top="10vh" :close-on-click-modal="false" :close-on-press-escape="false" v-drag title="报告信息" :visible.sync="setUp.reviewFlag" width="615px">
      <el-form :inline="true" label-position="top">
        <el-form-item label="派工单号">
          <el-input style="width: 130px;" :disabled="setUp.disabled"  onkeyup="this.value = this.value.toUpperCase()"  v-model="saveHeaderData.seqNo"></el-input>
        </el-form-item>
        <el-form-item label="产品编码">
          <el-input style="width: 130px;" :disabled="setUp.disabled" v-model="saveHeaderData.partNo"></el-input>
        </el-form-item>
        <el-form-item label="产品名称/规格型号">
          <el-input style="width: 275px;" :disabled="setUp.disabled"  v-model="saveHeaderData.partDescription"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top">
        <el-form-item label="工序号">
          <el-input style="width: 130px;" :disabled="setUp.disabled"  v-model="saveHeaderData.itemNo"></el-input>
        </el-form-item>
        <el-form-item label="工序名称">
          <el-input style="width: 130px;" :disabled="setUp.disabled"  v-model="saveHeaderData.operationDesc"></el-input>
        </el-form-item>
        <el-form-item label="加工中心编码">
          <el-input style="width: 130px;" :disabled="setUp.disabled"  v-model="saveHeaderData.workCenterNo"></el-input>
        </el-form-item>
        <el-form-item label="加工中心名称">
          <el-input style="width: 130px;" :disabled="setUp.disabled"  v-model="saveHeaderData.workCenterDesc"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top">
        <el-form-item>
          <span slot="label" style="" @click="getBaseList(26 ,1)"><a herf="#">操作员</a></span>
          <el-input style="width: 130px;"  v-model="saveHeaderData.operatorId"></el-input>
        </el-form-item>
        <el-form-item label="操作员姓名">
          <el-input style="width: 130px;"  v-model="saveHeaderData.operatorName"></el-input>
        </el-form-item>
        <el-form-item label="生产日期">
          <el-date-picker
            style="width: 130px"
            v-model="saveHeaderData.planStartTime"
            type="date"
            value-format="yyyy-MM-dd"
            format = "yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="报告日期">
          <el-date-picker
            style="width: 130px"
            v-model="saveHeaderData.planFinishTime"
            type="date"
            value-format="yyyy-MM-dd"
            format = "yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top">
<!--        <el-form-item label="本工序报工数">-->
        <el-form-item label="本订单已报工数">
          <el-input style="width: 130px;" :disabled="setUp.disabled"  v-model="qty1"></el-input>
        </el-form-item>
        <el-form-item label="上工序报工数">
          <el-input style="width: 130px;" :disabled="setUp.disabled"  v-model="qty2"></el-input>
        </el-form-item>
        <el-form-item label="单位重量">
          <el-input style="width: 130px;" disabled  v-model="qty3"></el-input>
        </el-form-item>
        <el-form-item label="本派工单数量">
          <el-input style="width: 130px;" disabled  v-model="saveHeaderData.qtyRequire"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top">
        <el-form-item label="合格数量">
          <el-input type="number" style="width: 178px;" :disabled="approveFlag"  class="input_reight"  v-model="saveHeaderData.qtyApprove" @blur="qtyApproveBlur()"></el-input>
        </el-form-item>
        <el-form-item label="不合格/缺失数量" >
          <el-input type="number"  class="input_left" style="width: 178px;"   v-model="saveHeaderData.qtyUnApprove" @blur="qtyReportedBlur()"></el-input>
        </el-form-item>
        <el-form-item label="生产模数">
          <el-input type="number" style="width: 178px;"  v-model="moQty"  @blur="moQtyBlur()"></el-input>
        </el-form-item>

      </el-form>
      <el-form :inline="true" label-position="top">
        <el-form-item label="带框合格重量(KG)">
          <el-input type="number" style="width: 178px;"  class="input_reight" :disabled="factorFlag"  v-model="KGApprove" @blur="KGApproveBlur()"></el-input>
        </el-form-item>
        <el-form-item label="不合格/缺失重量(KG)">
          <el-input type="number"  class="input_left" style="width: 178px;" :disabled="factorFlag"  v-model="KGReported" @blur="KGReportedBlur()"></el-input>
        </el-form-item>
        <el-form-item label="模具孔数">
          <el-input type="number"  class="input_left" style="width: 178px;" disabled  v-model="cavity" ></el-input>
        </el-form-item>
<!--        <el-form-item label="返工重量(KG)" >-->
<!--          <el-input type="number" style="width: 178px;"  v-model="KGRework" :disabled="factorFlag"  @blur="KGReworkBlur()"></el-input>-->
<!--        </el-form-item>-->
      </el-form>
      <el-form :inline="true" label-position="top">
        <el-form-item label="框重(KG)">
          <el-input  type="number"  class="input_left" style="width: 178px;" :disabled="factorFlag"  v-model="saveHeaderData.boxWeight"  @blur="boxWeightBlur()"></el-input>
        </el-form-item>
        <el-form-item label="废边重量(G)">
          <el-input style="width: 178px;"  v-model="saveHeaderData.wasteWeight"></el-input>
        </el-form-item>
        <el-form-item label="理论数量">
          <el-input type="number"  class="input_left" style="width: 178px;" disabled  v-model="saveHeaderData.liLunQty" ></el-input>
        </el-form-item>
      </el-form>
      <fieldset class="customer-fieldset" style="width: 597px;margin-left: -3px;">
        <legend class="customer-legend">不良处理</legend>
        <el-form :inline="true" label-position="top">
          <el-form-item label="报废数量">
            <el-input style="width: 80px;" type="number" :disabled="unapproveFlag"   v-model="saveHeaderData.scrapQty"></el-input>
          </el-form-item>
          <el-form-item label="报废原因">
            <el-input style="width: 480px;"  v-model="saveHeaderData.scrapRemark"></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top">
          <el-form-item label="接收数量">
            <el-input style="width: 80px;" type="number" :disabled="unapproveFlag" v-model="saveHeaderData.acceptQty"></el-input>
          </el-form-item>
          <el-form-item label="瑕疵原因">
            <el-input style="width: 480px;"   v-model="saveHeaderData.acceptRemark"></el-input>
          </el-form-item>
        </el-form>
      </fieldset>
      <el-form :inline="true" label-position="top">
        <el-form-item label="准备时间">
          <el-input type="number" style="width: 178px;text-align: right;"   v-model="saveHeaderData.preparationTime" ></el-input> <!--oninput ="value=value.replace(/[^0-9.]/g,'')"-->
<!--          <el-input-number style="width: 178px;text-align: right;" v-model="saveHeaderData.preparationTime" size="medium" :min="0" :controls="false"></el-input-number>-->
        </el-form-item>
        <el-form-item label="制造时间">
          <el-input type="number" style="width: 178px;" disabled  v-model="saveHeaderData.manufacturingTime"></el-input> <!--oninput ="value=value.replace(/[^0-9.]/g,'')"-->
<!--          <el-input-number style="width: 178px;text-align: right;" v-model="saveHeaderData.manufacturingTime" size="medium" :min="0" :controls="false"></el-input-number>-->
        </el-form-item>
        <el-form-item label="打印检验标签数" label-width="0px">
          <el-input type="number" style="width: 178px;" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="saveHeaderData.printQty"></el-input> <!--oninput ="value=value.replace(/[^0-9.]/g,'')"-->
          <!--            :min="0" 最小值  :controls="false" 隐藏减价按钮 -->
<!--          <el-input-number style="width: 178px;text-align: right;"  v-model="saveHeaderData.cleaningTime" size="medium" :min="0" :controls="false"></el-input-number>-->
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top">
        <el-form-item label="备注">
          <el-input style="width: 560px;"  v-model="saveHeaderData.remark"></el-input>
        </el-form-item>
      </el-form>
      <el-table
        height="150"
        :data="toolHistList"
        border>
        <el-table-column label="工具实例" prop="toolInstanceID"></el-table-column>
        <el-table-column label="工具名称" prop="toolDescription"></el-table-column>
        <el-table-column label="生产模数">
          <template slot-scope="{row,$index}">
            <el-input type="number" v-model="row.finishQty"></el-input>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
      <el-button @click="SOPModal()" type="primary">查看SOP</el-button>
      <el-button @click="setUp.reviewFlag = false">取消</el-button>
      <el-button type="primary" :disabled="setUp.saveButton" @click="saveReport('N')">分批报工确定</el-button>
      <el-button type="danger" :disabled="setUp.saveButton" style="margin-left: 200px" @click="saveReport('Y')">整单完工确定</el-button>
    </span>
    </el-dialog>

    <el-dialog  :close-on-click-modal="false" :close-on-press-escape="false" v-drag title="查看SOP" :visible.sync="sopFlag" width="80%">
       <el-row>
         <el-col :span="8">
           <div  style="margin-top: 2%">
             <h5 style="margin-left: 0px;font-size: 20px">产品图片</h5>
             <el-form inline="true" style="margin-top: -5px;margin-left: 0px" label-position="top">
               <el-form-item :label="'工厂编号：'">
                 <el-input v-model="sopData.site" readonly style="width: 120px"></el-input>
               </el-form-item>
               <el-form-item :label="'产品编码：'" style="margin-left: 20px">
                 <el-input v-model="sopData.partNo" readonly style="width: 120px"></el-input>
               </el-form-item>
             </el-form>
             <el-form inline="true" style="margin-top: 20px;margin-left: 0px" label-position="top">
               <el-form-item :label="'产品名称/规格型号：'" style="font-size: 20px">
                 <el-input v-model="partDescription" readonly style="width: 374px"></el-input>
               </el-form-item>
             </el-form>
             <el-form inline="true" style="margin-top: 20px;margin-left: 0px" label-position="top">
               <el-form-item :label="fileTitle">
                 <el-input v-model="fileName" style="width: 374px" readonly></el-input>
               </el-form-item>
             </el-form>
             <el-form inline="true" style="margin-top: 20px;margin-left: 20px" label-position="top">
               <el-form-item :label="' '">
                 <el-button @click="lastPicture()"  type="primary">上一张</el-button>
               </el-form-item>
               <el-form-item :label="' '">
                 <el-button @click="nextPicture()"  type="primary">下一张</el-button>
               </el-form-item>
               <el-form-item :label="' '">
                 <el-button @click="sopFlag=false"  type="primary">取消</el-button>
               </el-form-item>
             </el-form>
           </div>
         </el-col>
         <el-col :span="16">
           <div id="padPhoto" style="text-align: center;vertical-align:middle;" >
             <iframe :src="photoUrl" frameborder="0" width="100%" :height="height2"></iframe>
           </div>
         </el-col>
       </el-row>
    </el-dialog>
    <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>
  </div>
</template>


<script>
  import {
    printTransNoLabel,
  } from "@/views/modules/print/print_transNo_label.js"
  import {
    getSOScheduleRoutingData,
    saveGenerateReportForSchedule,
    searchReportedQty,
    searchSeqNo,
    startSeqNo,
    stopWork,
    continueWork,
    getTvList,
    getBadCodeList,
    selectSFDCToolHist
  } from '@/api/production/generateReport.js'
  import Chooselist from '@/views/modules/common/Chooselist'
  import {
    getPhotoAddressData
  } from '@/api/pad.js'
  import {
    getAbnormalCodeList,
    getShopOrderData,
  } from "@/api/abnormal.js"
  import {Decimal} from 'decimal.js'
  import {getPackagePrintDataList} from "../../../api/production/generateReport";
  import {printPackageLabelNoPreview} from "../print/print_package_label-NOOREVIEW";
  export default {
    name: 'generateReport',
    components: {
      Chooselist
    },
    watch: {
      saveHeaderData: {
        deep: true,
        handler: function (newV, oldV) {
         if(this.saveHeaderData.qtyUnApprove==0||this.saveHeaderData.qtyUnApprove===null||this.saveHeaderData.qtyUnApprove===''){
           this.unapproveFlag=true
           this.saveHeaderData.scrapQty=''
           this.saveHeaderData.acceptQty=''
         }else {
           this.unapproveFlag=false
         }
        }
      }
    },
    data () {
      return {
        pageData: {
          site: this.$store.state.user.site,
          username: this.$store.state.user.name,
          projectId: '',
          projectName: '',
          fileType: '',
        },
        folder: 'abnormal',
        fileList: [],
        toolHistList:[],// 工具
        cavity:'',
        setUp: {
          reviewFlag: false,
          saveButton: false,
          readonlyFlag: false,
          disabled: false
        },
        factorFlag:false,
        unapproveFlag:false,
        KGReported:'',
        KGApprove:'',
        KGRework:'',
        approveFlag:false,
        abnormalList:[],
        moQty:'',
        tvList:[],
        tvId:'',
        badCodeList:'',
        saveHeaderData: {
          closedFlag: '',
          scrapQty:0,
          scrapRemark:'',
          acceptQty:'',
          acceptRemark:0,
          wasteWeight:0,
          printQty:'',
          boxWeight:0,
          qtyRequire:'',
          qtyUnApprove:'',
          site: '',
          seqNo: '',
          itemNo: '',
          partNo: '',
          partDescription: '',
          operationDesc: '',
          workCenterNo: '',
          workCenterDesc: '',
          operatorId: '',
          operatorName: '',
          planStartTime: '',
          planFinishTime: '',
          qtyReported: 0,
          qtyApprove: 0,
          qtyRework: 0,
          operatorId2: '',
          operatorIdName2: '',
          scrapReason: '',
          preparationTime: 0,
          manufacturingTime: 0,
          cleaningTime: 0,
          shutdownReason: '',
          remark: '',
          orderRef1:'',
          scheduleType:'',
          userId:'',
          liLunQty:'',
          reportWeight:'',
          approveWeight:'',
          moldQty:'',
        },
        scanSeqNo:'',
        previousSeqNo:'',
        stopModalFlag:false,
        continueModalFlag:false,
        qty1:'',
        qty2:'',
        qty3:'',
        sopFlag:false,
        site: '',
        operatorType: 0,
        // 导出 start
        exportData: [],
        exportDataStandard: {
          '派工单号': 'seqNo',
          '关联单号': 'orderNo',
          '关联单号类型': 'scheduleType',
          '工序号': 'itemNo',
          '工序名称': 'itemDesc',
          '派工数量': 'qtyRequired',
          '报工数量': 'qtyReported',
          '合格数量': 'qtyApprove',
          '需求时间': 'timeRequired',
          '派工日期': 'sScheduledDate',
          '操作员姓名': 'operatorName',
          '产品编码': 'partNo',
          '产品名称': 'partDesc',
          '机台ID': 'sResourceID',
          '班次': 'sShiftNo',
          '加工中心': 'sWorkCenterNo',
          '派工类型': 'jobType',
        },
        exportName: '派工单列表' + this.getStrDate(),
        exportHeader: ['派工单列表'],
        exportFooter: [],
        exportDefaultValue: '',
        // 导出 end
        height: 200,
        tableData: [],
        date1: '',
        searchData: {
          seqNo:'',
          userId:this.$store.state.user.name,
          orderNo: '',
          sWorkCenterNo: '',
          partNo: '',
          site: '',
          partDesc:'',
          scheduleType:'',
          closedFlag:'N',
          startDate:'',
          endDate:'',
          operatorName:'',
          sResourceID:'',
          sShiftNo:'',
          previousSeqNo:'',
          materSeqNo:'',
          repairSOFlag:'',
        },
        photoUrl:'',
        sopData:{
          site:'',
          partNo:'',
        },
        currentRow:'',
        scanModalFlag:false,
        partDescription:'',
        fileTitle:'',
        fileName:'',
        num:1,
        currentData:'',
        photoDatas:[],
        uploadImg:[],
        showviewer: false,
        url: '',
        height2:600,
        tagNo2:'',
        startModalFlag:false,
        stopData:{
          site:'',
          seqNo:'',
          orderNo:'',
          shiftNo:'',
          resourceDesc:'',
          feedbackBy:this.$store.state.user.name,
          abnormalCode:'',
          abnormalRemark:'',
          abnormalInfluence:'',
          abnormalQty:'',
          nextSeqNo:'',
        },
      }
    },
    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight - 210
        this.height2 = window.innerHeight -100
      })
    },

    methods: {
      getAllAbnormalItem(){
        getAbnormalCodeList().then(({data}) => {
          this.abnormalList = data.rows;
        })
      },
       saveReport (flag) {
        this.saveHeaderData.qtyReported=Number(this.saveHeaderData.qtyUnApprove)+Number(this.saveHeaderData.qtyApprove);
        if (this.saveHeaderData.qtyUnApprove == null || this.saveHeaderData.qtyUnApprove < 0) {
          this.$alert('不合格数量错误！', '错误信息', {
            confirmButtonText: '确定'
          })
          return
        }
        if (this.saveHeaderData.qtyApprove == null || this.saveHeaderData.qtyApprove < 0) {
          this.$alert('合格数量错误！', '错误信息', {
            confirmButtonText: '确定'
          })
          return
        }
        if (this.saveHeaderData.qtyRework == null || this.saveHeaderData.qtyRework <0) {
          this.$alert('返工数量错误！', '错误信息', {
            confirmButtonText: '确定'
          })
          return
        }
        if (this.saveHeaderData.preparationTime == null || this.saveHeaderData.preparationTime < 0) {
          this.$alert('准备时间错误！', '错误信息', {
            confirmButtonText: '确定'
          })
          return
        }
        if (this.saveHeaderData.manufacturingTime == null || this.saveHeaderData.manufacturingTime < 0) {
          this.$alert('制造时间错误！', '错误信息', {
            confirmButtonText: '确定'
          })
          return
        }
        if (this.saveHeaderData.cleaningTime == null || this.saveHeaderData.cleaningTime < 0) {
          this.$alert('清理时间错误！', '错误信息', {
            confirmButtonText: '确定'
          })
          return
        }
        if (this.saveHeaderData.planStartTime == null || this.saveHeaderData.planStartTime === '') {
          this.$alert('请选择生产日期！', '错误信息', {
            confirmButtonText: '确定'
          })
          return
        }
        if (this.saveHeaderData.planFinishTime == null || this.saveHeaderData.planFinishTime === '') {
          this.$alert('请选择报告日期！', '错误信息', {
            confirmButtonText: '确定'
          })
          return
        }
        if (this.saveHeaderData.boxWeight == null || this.saveHeaderData.boxWeight === '') {
          this.$alert('请输入框重！', '错误信息', {
            confirmButtonText: '确定'
          })
          return
        }

         if(this.saveHeaderData.printQty>30){
           this.$alert('打印标签数最多为30张！', '错误信息', {
             confirmButtonText: '确定'
           })
           return
         }
        if(this.moQty==null||this.moQty==''){
          this.saveHeaderData.moldQty=0
        }else {
          this.saveHeaderData.moldQty=this.moQty
        }
        let boxWeightKG=0
        if(this.saveHeaderData.boxWeight!=null&&this.saveHeaderData.boxWeight!=''){
          boxWeightKG=this.saveHeaderData.boxWeight
        }
        if(this.KGApprove!=null&&this.KGApprove!=''&&this.KGApprove>=0){
          this.saveHeaderData.approveWeight=Number(this.KGApprove)-boxWeightKG
          if(this.KGReported!=null&&this.KGReported!=''){
            this.KGReported=0
          }
          this.saveHeaderData.reportWeight=Number(this.KGApprove)-boxWeightKG+Number(this.KGReported)
        }
        if(this.saveHeaderData.scrapQty==null||this.saveHeaderData.scrapQty==''){
          this.saveHeaderData.scrapQty=0
        }
         if(this.saveHeaderData.acceptQty==null||this.saveHeaderData.acceptQty==''){
           this.saveHeaderData.acceptQty=0
         }
         // 判断生产模数
         if (this.toolHistList.length > 0){
           if (!this.toolHistList.some(item => item.finishQty && item.finishQty !== 0)) {
             this.$alert('至少填写一条工具的生产模数！', '错误信息', {
               confirmButtonText: '确定'
             })
             return
           }
           this.saveHeaderData.toolingHistDataList = this.toolHistList
           this.saveHeaderData.createBy = this.$store.state.user.name
           this.saveHeaderData.moQty = this.toolHistList.reduce((prev, cur)=>{
             return new Decimal(prev).add(new Decimal(cur.finishQty)).toNumber()
           },0)
         }
         this.setUp.saveButton=true;
         this.saveHeaderData.closedFlag=flag
         saveGenerateReportForSchedule(this.saveHeaderData).then(({data}) => {
             this.setUp.saveButton = false
            if (data.code == 0) {
              this.$message.success(data.msg)
              this.setUp.reviewFlag = false
              // this.search()
              let inList=[];
              // 入库通知单
              if(data.transData!=null){
                // 生成袋装标签
                let params = {
                  site:this.saveHeaderData.site,
                  seqNo:this.saveHeaderData.seqNo,
                  previousSeqNo:this.saveHeaderData.seqNo,
                  orderNo:this.saveHeaderData.orderNo,
                  number:this.saveHeaderData.qtyApprove,
                }
                // if (data.transData.partNo.substring(0, 2) === 'SP'){
                //
                // }
                getPackagePrintDataList(params).then(({data}) => {
                  if (data && data.code === 0) {
                    data.rows[0].tcpValue = 0
                    printPackageLabelNoPreview(data.rows);
                  }
                })
                //他们要打印2张
                // 2025-04-08加上打印袋装标签后，只需要一张入库通知单标签
                // inList.push(data.transData)
                inList.push(data.transData)
              }
              // 不良数据
              if(data.badData!=null){
                inList.push(data.badData)
              }
              // 报工数据
              if(data.reportData!=null&&data.transData==null){
                inList.push(data.reportData)
              }
              if(this.saveHeaderData.printQty>0){
                for (let i = 0; i <this.saveHeaderData.printQty ; i++) {
                  inList.push(this.currentRow)
                }
              }
              if(inList.length>0){
                printTransNoLabel(inList);
              }

              this.$nextTick(() => {
                setTimeout(() => {
                  if(data.feedBackId&&data.feedBackId>0){
                    let inData={id:data.feedBackId};
                    localStorage.setItem('feedBackId', JSON.stringify(inData))
                    this.$router.push('Abnormal-AbnormalFeedBack')
                  }

                },1000)
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
              this.setUp.saveButton = false
            }
        }).error((error)=>{
           this.setUp.saveButton = false
         })
      },
      // 获取基础数据列表S
      getBaseList (val, type) {
        this.tagNo = val
        this.tagNo2 = type
        this.$nextTick(() => {
          let strVal = ''
          if (val === 24) {
            strVal = this.searchData.sWorkCenterNo
          }
          if (val === 5) {
            strVal = this.searchData.partNo
          }
          if (val === 26) {
            if(type==1) {
              strVal = this.saveHeaderData.operatorId
            }else if(type==2){
              strVal = this.saveHeaderData.operatorId2
            }else {
              strVal = this.searchData.operatorName
            }
          }
          if (val === 88) {
            strVal = this.searchData.sResourceID
          }
          this.$refs.baseList.init(val, strVal)
        })
      },
      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 24) {
          this.searchData.sWorkCenterNo = val.WorkCenterNo
        }  else if (this.tagNo === 5) {
          this.searchData.partNo = val.PartNo
        }
        if (this.tagNo === 26) {
          if(this.tagNo2==1) {
            this.saveHeaderData.operatorId = val.OperatorID
            this.saveHeaderData.operatorName = val.OperatorName
          }else if(this.tagNo2==2){
            this.saveHeaderData.operatorId2 = val.OperatorID
            this.saveHeaderData.operatorIdName2 = val.OperatorName
          }else {
            this.searchData.operatorName = val.OperatorName
          }
        }
        if (this.tagNo === 88) {
          this.searchData.sResourceID = val.ResourceID
        }
      },
      initReportModal (row) {
        this.scanSeqNo=row.seqNo
        this.searchSeqNo()
        this.selectSFDCToolHist(row)
      },
      closeDialog () {
        Object.assign(this.$data.saveHeaderData, this.$options.data.call(this).saveHeaderData)
      },
      search () {
        getSOScheduleRoutingData(this.searchData).then(({data}) => {
          this.tableData = data.rows
        })
        // let inData={id:50};
        // localStorage.setItem('feedBackId', JSON.stringify(inData))
        // this.$router.push('Abnormal-AbnormalFeedBack')

      },
      selectSFDCToolHist(row){
        let params = {
          site:row.site,
          orderNo:row.orderNo,
          itemNo:row.itemNo,
          seqNo:row.seqNo,
          finishFlag:"N"
        }
        selectSFDCToolHist(params).then(({data})=>{
          if (data && data.code === 0){
            this.toolHistList = data.rows
          }else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        }).catch((error)=>{
          this.$alert(error, '错误', {
            confirmButtonText: '确定'
          })
        })
      },
      createExportData () {
        return this.tableData
      },
      startDownload () {
        //  this.exportData = this.dataList

      },
      finishDownload () {

      },
      getStrDate () {
        let dd = new Date()
        let Y = dd.getFullYear()
        let M = (dd.getMonth() + 1) < 10 ? '0' + (dd.getMonth() + 1) : (dd.getMonth() + 1)// 获取当前月份的日期，不足10补0
        let D = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate()// 获取当前几号，不足10补0
        let H = dd.getHours() < 10 ? '0' + dd.getHours() : dd.getHours()
        let MM = dd.getMinutes() < 10 ? '0' + dd.getMinutes() : dd.getMinutes()
        let S = dd.getSeconds() < 10 ? '0' + dd.getSeconds() : dd.getSeconds()
        return Y + M + D + H + MM + S
      },
      SOPModal(){
        this.sopData.partNo = this.saveHeaderData.partNo;
        this.sopData.site=  this.saveHeaderData.site;
        this.partDescription= this.saveHeaderData.partDescription;
        // var div1=document.getElementById("padPhoto");
        // div1.style.cssText= "height:"+this.height2+"px;";
        this.getPhoto();
        this.sopFlag=true;
      },
      SOPModal2(row){
        this.sopData.partNo = row.partNo;
        this.sopData.site=  row.site;
        this.partDescription= row.partDesc;
        // var div1=document.getElementById("padPhoto");
        // div1.style.cssText= "height:"+this.height2+"px;";
        this.getPhoto();
        this.sopFlag=true;
      },
      getPhoto(){
        getPhotoAddressData(this.sopData).then(({data}) => {
          this.photoDatas = data.rows;
          if(this.photoDatas.length==0){
            this.fileTitle="文件名   （"+0+"/"+0+")";
            this.$alert('该物料没有上传图片！', '错误', {
              confirmButtonText: '确定'
            })
            return false;
          }
          this.fileName=this.photoDatas[this.num-1].attaFileNameDb;
          this.fileTitle="文件名   （"+this.num+"/"+this.photoDatas.length+")";
          this.photoUrl=this.$store.state.user.padSopUrl+this.photoDatas[this.num-1].attaFileNameDb;
          // this.photoUrl='http://192.168.1.83:81/upload/'+this.photoDatas[this.num-1].attaFileNameDb;
        })
      },
      nextPicture(){
        if(this.photoDatas.length==0){
          this.fileTitle="文件名   （"+0+"/"+0+")";
          this.$alert('该物料没有上传图片！', '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        if(this.num==this.photoDatas.length){
          this.num=1;
        }else{
          this.num=this.num+1;
        }
        this.fileName=this.photoDatas[this.num-1].attaFileNameDb;
        this.fileTitle="文件名   ("+this.num+"/"+this.photoDatas.length+")";
        this.photoUrl=this.$store.state.user.padSopUrl+this.photoDatas[this.num-1].attaFileNameDb;
        // this.photoUrl='http://192.168.1.83:81/upload/'+this.photoDatas[this.num-1].attaFileNameDb;
      },
      lastPicture(){
        if(this.photoDatas.length==0){
          this.fileTitle="文件名   ("+0+"/"+0+")";
          this.fileName='';
          this.photoUrl='';
          this.$alert('该物料没有上传图片！', '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        if(this.num==1){
          this.num=this.photoDatas.length;
        }else{
          this.num=this.num-1;
        }
        this.fileName=this.photoDatas[this.num-1].attaFileNameDb;
        this.fileTitle="文件名   ("+this.num+"/"+this.photoDatas.length+")";
        this.photoUrl=this.$store.state.user.padSopUrl+this.photoDatas[this.num-1].attaFileNameDb;
        // this.photoUrl='http://192.168.1.83:81/upload/'+this.photoDatas[this.num-1].attaFileNameDb;
      },
      openScan(){
        this.scanSeqNo='';
        this.scanModalFlag=true;
        this.$nextTick(() => { this.$refs.input.focus();})
      },
      openStart(){
        this.scanSeqNo='';
        this.tvId='';
        this.previousSeqNo='';
        this.startModalFlag=true;
        this.$nextTick(() => { this.$refs.start.focus();})
      },
      seqNoCheck(){
        let inData={
          seqNo:this.stopData.seqNo
        }
        getShopOrderData(inData).then(({data}) => {
          let rows=data.rows;
          if(rows.length==0){
            this.stopData.seqNo='',
              this.stopData.shiftNo='',
              this.stopData.site='',
              this.stopData.resourceDesc='',
              this.stopData.orderNo='',
              this.$alert('该派工单不存在！', '错误', {
                confirmButtonText: '确定'
              })
            this.$nextTick(() => { this.$refs.stop.focus();})
            return false
          }else {
            this.stopData.shiftNo=data.rows[0].sShiftNo
            this.stopData.site=data.rows[0].site
            this.stopData.resourceDesc=data.rows[0].resourceDesc
            this.stopData.orderNo=data.rows[0].orderNo
          }
        })
      },
      stopScan(){
        this.getAllAbnormalItem();
        this.stopData.seqNo='';
        this.stopData.shiftNo='';
        this.stopData.site='';
        this.stopData.resourceDesc='';
        this.stopData.orderNo='';
        this.stopData.abnormalRemark='';
        this.stopData.abnormalCode='';
        this.stopData.nextSeqNo='';
        this.stopModalFlag=true;
        this.fileList = [];
        this.$nextTick(() => { this.$refs.stop.focus();})
      },
      continueScan(){
        this.scanSeqNo='';
        this.continueModalFlag=true;
        this.$nextTick(() => { this.$refs.continue.focus();})
      },
      searchSeqNo(){
        if(this.scanSeqNo==''){
          this.$alert("请扫描派工单！",'错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        let inData={
          userId:this.$store.state.user.name,
          seqNo:this.scanSeqNo
        }
        searchSeqNo(inData).then(({data}) => {
          if (data.code == 0) {
            if(data.row==null){
              this.scanSeqNo=''
              this.$alert("派工单不存在！",'错误', {
                confirmButtonText: '确定'
              })
              return false;
            }
            let currentData = data.row;
            if(currentData.closedFlag=='Y'){
              this.scanSeqNo=''
              this.$alert("该派工单已关闭！",'错误', {
                confirmButtonText: '确定'
              })
              return false;
            }
            this.KGReported=0
            this.KGApprove=0
            this.KGRework=0
            this.saveHeaderData.qtyApprove=0
            this.saveHeaderData.qtyUnApprove=0
            this.saveHeaderData.acceptRemark= ''
            this.saveHeaderData.acceptQty= 0
            this.saveHeaderData.scrapRemark= ''
            this.saveHeaderData.scrapQty= 0
            this.saveHeaderData.qtyRework=0
            this.saveHeaderData.moldQty=0
            this.saveHeaderData.reportWeight=0
            this.saveHeaderData.approveWeight=0
            this.saveHeaderData.site = currentData.site;
            this.saveHeaderData.seqNo = currentData.seqNo;
            this.saveHeaderData.itemNo = currentData.itemNo;
            this.saveHeaderData.operationDesc = currentData.itemDesc;
            this.saveHeaderData.partNo = currentData.partNo;
            this.saveHeaderData.partDescription = currentData.partSpec;
            this.saveHeaderData.workCenterNo = currentData.sWorkCenterNo;
            this.saveHeaderData.workCenterDesc = currentData.workCenterDesc;
            this.saveHeaderData.orderRef1=currentData.orderRef1;
            this.saveHeaderData.orderNo=currentData.orderNo;
            this.saveHeaderData.scheduleType=currentData.scheduleType;
            this.saveHeaderData.operatorId=currentData.operatorId;
            this.saveHeaderData.operatorName=currentData.operatorName;
            this.saveHeaderData.qtyRequire=currentData.qtyRequired;
            this.saveHeaderData.userId=this.$store.state.user.name;
            this.saveHeaderData.boxWeight=0;
            this.saveHeaderData.printQty=0;
            this.saveHeaderData.wasteWeight=0;
            this.qty1='';
            this.qty2 ='';
            this.moQty ='';
            this.liLunQty ='';
            this.saveHeaderData.planStartTime = this.dayjs(new Date()).format('YYYY-MM-DD 00:00:00')
            this.saveHeaderData.planFinishTime = this.dayjs(new Date()).format('YYYY-MM-DD 00:00:00')
            this.selectSFDCToolHist(this.saveHeaderData)
            searchReportedQty(this.saveHeaderData).then(({data}) => {
              if(data.code===0) {
                this.cavity= data.row.cavity
                this.qty1 = data.row.qtyReported;
                this.qty2 = data.row.lastApproveQty;
                this.saveHeaderData.manufacturingTime = data.row.timeReported;
                if (data.row.weightFactor == 0) {
                  this.qty3 = "erp未维护数据"
                  this.KGReported = ''
                  this.KGApprove = ''
                  this.KGRework = ''
                  this.factorFlag = true;
                } else {
                  this.qty3 = data.row.weightFactor
                  this.factorFlag = false;
                }
              }else {
                this.$alert(data.msg, '错误', {
                  confirmButtonText: '确定'
                })
                return false;
              }
            })
            this.approveFlag=false;
            this.scanModalFlag=false;
            this.setUp.reviewFlag = true;
            this.setUp.saveButton=false;
            this.setUp.disabled = true;
            getSOScheduleRoutingData(inData).then(({data}) => {
              if( data.rows){
                if(data.rows.length>0){
                  data.rows[0].weight= Number(data.rows[0].weight.toFixed(2))
                  data.rows[0].type='jianyan'
                  this.currentRow=data.rows[0]

                }
              }
            })
          } else {
            this.scanSeqNo=''
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      qtyReportedBlur(){
        if(this.qty3&&this.qty3!=0&&this.qty3!='erp未维护数据'&&this.saveHeaderData.qtyUnApprove!=''){
          this.KGReported=(this.saveHeaderData.qtyUnApprove*this.qty3).toFixed(1)
        }
        if(this.saveHeaderData.qtyUnApprove==''){
          this.KGReported=''
        }
      },
      moQtyBlur(){
        if(this.cavity&&this.cavity!=0&&this.cavity!='erp未维护数据'&&this.moQty!=''){
          this.saveHeaderData.liLunQty=(this.cavity*this.moQty).toFixed(1)
        }
      },
      qtyApproveBlur(){
        if(this.qty3&&this.qty3!=0&&this.qty3!='erp未维护数据'&&this.saveHeaderData.qtyApprove!=''){
          if(this.saveHeaderData.boxWeight!=null&&this.saveHeaderData.boxWeight!='') {
            this.KGApprove = (this.saveHeaderData.qtyApprove * this.qty3+Number(this.saveHeaderData.boxWeight)).toFixed(1)
          }else {
            this.KGApprove = (this.saveHeaderData.qtyApprove * this.qty3).toFixed(1)
          }
          this.factorFlag=true
        }
        if(this.saveHeaderData.qtyApprove==''){
          this.KGApprove=''
        }
      },
      boxWeightBlur(){
          if(this.saveHeaderData.boxWeight==null||this.saveHeaderData.boxWeight==''){
            this.saveHeaderData.boxWeight=0
          }
          if(this.approveFlag){
            if(this.qty3&&this.qty3!=0&&this.qty3!='erp未维护数据'&&this.KGApprove!=''){
              this.saveHeaderData.qtyApprove=((this.KGApprove-this.saveHeaderData.boxWeight)/this.qty3).toFixed(0)
            }
          }else {
            if(this.qty3&&this.qty3!=0&&this.qty3!='erp未维护数据'&&this.saveHeaderData.qtyApprove!=''){
              this.KGApprove = (this.saveHeaderData.qtyApprove * this.qty3+Number(this.saveHeaderData.boxWeight)).toFixed(1)
            }
          }
      },
      KGApproveBlur(){
        if(this.qty3&&this.qty3!=0&&this.qty3!='erp未维护数据'&&this.KGApprove!=''){
          if(this.saveHeaderData.boxWeight!=null&&this.saveHeaderData.boxWeight!=''){
            this.saveHeaderData.qtyApprove=((this.KGApprove-this.saveHeaderData.boxWeight)/this.qty3).toFixed(0)
          }else {
            this.saveHeaderData.qtyApprove=(this.KGApprove/this.qty3).toFixed(0)
          }
          this.approveFlag=true;

        }
        if(this.KGApprove==''){
          this.saveHeaderData.qtyApprove=''
          this.approveFlag=false;
        }
      },
      qtyReworkBlur(){
        if(this.qty3&&this.qty3!=0&&this.qty3!='erp未维护数据'&&this.saveHeaderData.qtyRework!=''){
          this.KGRework=(this.saveHeaderData.qtyRework*this.qty3).toFixed(1)
        }
        if(this.saveHeaderData.qtyRework==''){
          this.KGRework=''
        }
      },
      KGReportedBlur(){
        if(this.qty3&&this.qty3!=0&&this.qty3!='erp未维护数据'&&this.KGReported!=''){
          this.saveHeaderData.qtyUnApprove=(this.KGReported/this.qty3).toFixed(0)
        }
        if(this.KGReported==''){
          this.saveHeaderData.qtyUnApprove=''
        }
      },
      KGReworkBlur(){
        if(this.qty3&&this.qty3!=0&&this.qty3!='erp未维护数据'&&this.KGRework!=''){
          this.saveHeaderData.qtyRework=(this.KGRework/this.qty3).toFixed(0)
        }
        if(this.KGRework==''){
          this.saveHeaderData.qtyRework=''
        }
      },
      startSeqNo(){
        let inData={
          username:this.$store.state.user.name,
          seqNo:this.scanSeqNo,
          previousSeqNo:this.previousSeqNo,
          tvId:this.tvId,
        }
        startSeqNo(inData).then(({data}) => {
          if (data && data.code === 0) {
            this.scanSeqNo='';
            this.previousSeqNo='';
            this.startModalFlag=false;
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.scanSeqNo='';
            this.previousSeqNo='';
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      stopWork(){
        if( this.stopData.seqNo==null||this.stopData.seqNo==''){
          this.$alert("请输入派工单号", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        if( this.stopData.abnormalCode==null||this.stopData.abnormalCode==''){
          this.$alert("请选择异常原因", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        if( this.stopData.abnormalRemark==null||this.stopData.abnormalRemark==''){
          this.$alert("请输入描述", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        const formData = new FormData();
        //片接文件
        for (let i = 0; i < this.fileList.length; i++) {
          formData.append("file",this.fileList[i].raw)
        }
        formData.append("folder", this.folder);
        formData.append("site", this.stopData.site);
        formData.append("seqNo", this.stopData.seqNo);
        formData.append("orderNo", this.stopData.orderNo);

        formData.append("resourceDesc", this.stopData.resourceDesc);
        formData.append("feedbackBy", this.stopData.feedbackBy);
        formData.append("abnormalCode", this.stopData.abnormalCode);
        formData.append("abnormalRemark", this.stopData.abnormalRemark);
        formData.append("abnormalInfluence", this.stopData.abnormalInfluence);
        formData.append("abnormalQty", this.stopData.abnormalQty);
        formData.append("nextSeqNo", this.stopData.nextSeqNo);
        // let inData={
        //   username:this.$store.state.user.name,
        //   seqNo:this.scanSeqNo
        // }
        stopWork(formData).then(({data}) => {
          if (data && data.code === 0) {
            this.stopModalFlag=false;
            this.$refs.uploadFile.clearFiles();
            this.fileList = [];
            this.$message({
              message: '派工单已暂停',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.scanSeqNo='';
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      continueWork(){
        let inData={
          username:this.$store.state.user.name,
          seqNo:this.scanSeqNo
        }
        continueWork(inData).then(({data}) => {
          if (data && data.code === 0) {
            this.scanSeqNo='';
            this.continueModalFlag=false;
            this.$message({
              message: '派工单已继续',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.scanSeqNo='';
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      searchAllTV(){
        getTvList().then(({data}) => {
          this.tvList = data.rows;
        })
      },
      getBadCodeList(){
        getBadCodeList().then(({data}) => {
          this.badCodeList = data.rows;
        })
      },
      /*选择上传文件时*/
      onChange(file,fileList){
        this.fileList = fileList;
      },

    },
    created () {
      this.getBadCodeList();
      this.searchAllTV();
    }
  }
</script>

<style scoped>
  .input_left{
    text-align: left;
  }
  .input_reight{
    text-align: right;
  }
  /deep/ input::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
  }
  input[type='number'] {
    -moz-appearance: textfield !important;
  }
  .big /deep/ .el-form-item__label {
    font-size: 17px;
  }

  .big /deep/ .el-input__inner {
    height: 22px !important;
    font-size: 17px;
  }

  .big /deep/ .el-dialog__title {
    font-size: 17px;
    font-weight: bold;
  }

  .big /deep/ .el-table .cell{
    height: auto !important;
  }
</style>
