<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.seqNo" type="number" style="width: 130px"></el-input>
      </el-form-item>
      <el-form-item :label="'生产订单号'">
        <el-input v-model="searchData.orderNo" 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.itemDesc" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'派工单是否关闭'">
        <el-select v-model="searchData.reportFlag" style="width: 120px">
          <el-option label="全部" value=""></el-option>
          <el-option label="是" value="closedFlag='Y'"></el-option>
          <el-option label="否" value="closedFlag='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.sShiftNo" 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-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>
        <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="initUseModal(scope.row)">查看工具记录</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="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="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>
    <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;" @keyup.enter.native="startSeqNo()"></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   :close-on-click-modal="false" :close-on-press-escape="false" v-drag :title="pageTitle" :visible.sync="setUp.reviewFlag" width="615px">
      <el-form :inline="true" label-position="top">
        <el-form-item label="派工单号">
          <el-input style="width: 130px;" readonly  onkeyup="this.value = this.value.toUpperCase()"  v-model="saveHeaderData.seqNo"></el-input>
        </el-form-item>
        <el-form-item label="产品编码">
          <el-input style="width: 130px;" readonly v-model="saveHeaderData.partNo"></el-input>
        </el-form-item>
        <el-form-item label="产品名称/规格型号">
          <el-input style="width: 275px;" readonly  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;" readonly  v-model="saveHeaderData.itemNo"></el-input>
        </el-form-item>
        <el-form-item label="工序名称">
          <el-input style="width: 130px;" readonly  v-model="saveHeaderData.operationDesc"></el-input>
        </el-form-item>
        <el-form-item label="加工中心编码">
          <el-input style="width: 130px;" readonly  v-model="saveHeaderData.workCenterNo"></el-input>
        </el-form-item>
        <el-form-item label="加工中心名称">
          <el-input style="width: 130px;" readonly  v-model="saveHeaderData.workCenterDesc"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top">
        <el-form-item label="生产订单">
          <el-input style="width: 130px;" readonly v-model="saveHeaderData.orderNo"></el-input>
        </el-form-item>
        <el-form-item label="请扫描工具条码">
          <el-input v-if="!toolReportFlag" style="width: 130px;" ref="issuance"   v-model="toolInstanceID" @keyup.enter.native="toolIssuance()"></el-input>
          <el-input v-if="toolReportFlag" style="width: 130px;" ref="report"   v-model="toolInstanceID" @keyup.enter.native="toolReportCheck()"></el-input>
        </el-form-item>
      </el-form>
      <el-table
        height="200"
        :data="toolList1"
        border
        style="width: 100%">
        <el-table-column
          prop="toolInstanceId"
          header-align="center"
          align="left"
          min-width="100"
          label="工具实例编码">
        </el-table-column>
        <el-table-column
          prop="reportedby"
          header-align="center"
          align="left"
          min-width="100"
          label="领用人">
        </el-table-column>
        <el-table-column
          prop="startDate"
          header-align="center"
          align="left"
          min-width="100"
          label="领用日期">
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="setUp.reviewFlag = false">取消</el-button>
      </span>
    </el-dialog>
    <el-dialog title="工具报工" :close-on-click-modal="false" v-drag :visible.sync="reportModalFlag" width="330px">
      <el-form :inline="true" label-position="top">
        <el-form-item label="工具实例编码">
          <el-input style="width: 130px;" readonly    v-model="toolReportData.toolInstanceID"></el-input>
        </el-form-item>
        <el-form-item label="工具编码">
          <el-input style="width: 130px;" readonly    v-model="toolReportData.toolId"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top">
        <el-form-item label="模数">
          <el-input style="width: 130px;" readonly   v-model="toolReportData.moQty"></el-input>
        </el-form-item>
        <el-form-item label="生产数量">
          <el-input style="width: 130px;" type="number" ref="reportDo"   v-model="toolReportData.finishQty"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="saveToolReport()">保存</el-button>
        <el-button type="primary" @click="reportModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>
    <el-dialog   :close-on-click-modal="false" :close-on-press-escape="false" v-drag title="工具使用记录" :visible.sync="toolUseDetailFlag" width="805px">
      <el-form :inline="true" label-position="top">
        <el-form-item label="派工单号">
          <el-input style="width: 130px;" readonly  onkeyup="this.value = this.value.toUpperCase()"  v-model="saveHeaderData.seqNo"></el-input>
        </el-form-item>
        <el-form-item label="生产订单">
          <el-input style="width: 130px;" readonly v-model="saveHeaderData.orderNo"></el-input>
        </el-form-item>
        <el-form-item label="产品编码">
          <el-input style="width: 130px;" readonly v-model="saveHeaderData.partNo"></el-input>
        </el-form-item>
        <el-form-item label="产品名称/规格型号">
          <el-input style="width: 275px;" readonly  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;" readonly  v-model="saveHeaderData.itemNo"></el-input>
        </el-form-item>
        <el-form-item label="工序名称">
          <el-input style="width: 130px;" readonly  v-model="saveHeaderData.operationDesc"></el-input>
        </el-form-item>
        <el-form-item label="加工中心编码">
          <el-input style="width: 130px;" readonly  v-model="saveHeaderData.workCenterNo"></el-input>
        </el-form-item>
        <el-form-item label="加工中心名称">
          <el-input style="width: 130px;" readonly  v-model="saveHeaderData.workCenterDesc"></el-input>
        </el-form-item>
      </el-form>
      <el-table
        height="300"
        :data="toolList2"
        border
        style="width: 100%">
        <el-table-column
          prop="toolInstanceId"
          header-align="center"
          align="left"
          min-width="100"
          label="工具实例编码">
        </el-table-column>
        <el-table-column
          prop="reportedby"
          header-align="center"
          align="left"
          min-width="60"
          label="领用人">
        </el-table-column>
        <el-table-column
          prop="startDate"
          header-align="center"
          align="left"
          min-width="100"
          label="领用日期">
        </el-table-column>
        <el-table-column
          prop="finishDate"
          header-align="center"
          align="left"
          min-width="100"
          label="报工日期">
        </el-table-column>
        <el-table-column
          prop="finishQty"
          header-align="center"
          align="right"
          min-width="60"
          label="产量">
        </el-table-column>
        <el-table-column
          prop="moQty"
          header-align="center"
          align="right"
          min-width="60"
          label="模数">
        </el-table-column>
        <el-table-column
          prop="useQty"
          header-align="center"
          align="right"
          min-width="60"
          label="消耗寿命">
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="toolUseDetailFlag = false">关闭</el-button>
      </span>
    </el-dialog>
    <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>
  </div>
</template>

<script>
  import {
    getSOScheduleRoutingData,
    toolStart,
    toolIssuance,
    toolReport,
    toolReportCheck,
    toolUseDetail,
  } from '@/api/production/schedule.js'
  import Chooselist from '@/views/modules/common/Chooselist'
  export default {
    name: 'generateReport',
    components: {
      Chooselist
    },
    data () {
      return {
        cavity:'',
        setUp: {
          reviewFlag: false,
          saveButton: false,
          readonlyFlag: false,
          disabled: false
        },
        toolReportFlag:'',
        toolInstanceID:'',
        toolList1:[],
        factorFlag:false,
        abnormalList:[],
        saveHeaderData: {
          site: '',
          seqNo: '',
          itemNo: '',
          partNo: '',
          partDescription: '',
          operationDesc: '',
          workCenterNo: '',
          workCenterDesc: '',
          orderNo:'',
          userId:'',
        },
        reportModalFlag:false,
        toolReportData:{
          toolInstanceID:'',
          toolId:'',
          moQty:'',
          finishQty:'',
        },
        scanSeqNo:'',
        stopModalFlag:false,
        continueModalFlag:false,
        qty1:'',
        qty2:'',
        site: '',
        operatorType: 0,
        toolList2:[],
        toolUseDetailFlag:false,
        // 导出 start
        exportData: [],
        exportDataStandard: {
          '派工单号': 'seqNo',
          '关联单号': 'orderNo',
          '关联单号类型': 'scheduleType',
          '工序号': 'itemNo',
          '工序名称': 'itemDesc',
          '派工数量': 'qtyRequired',
          '报工数量': 'qtyReported',
          '合格数量': 'qtyApprove',
          '需求时间': 'timeRequired',
          '派工日期': 'sScheduledDate',
          '操作员姓名': 'operatorName',
          '产品编码': 'partNo',
          '产品名称': 'partDesc',
          '机台ID': 'sResourceID',
          '班次': 'sShiftNo',
          '加工中心': 'sWorkCenterNo',

        },
        exportName: '派工单列表' + this.getStrDate(),
        exportHeader: ['派工单列表'],
        exportFooter: [],
        exportDefaultValue: '这一行这一列没有数据',
        // 导出 end
        height: 200,
        tableData: [],
        searchData: {
          userId:this.$store.state.user.name,
          orderNo: '',
          sWorkCenterNo: '',
          partNo: '',
          site: '',
          itemDesc:'',
          scheduleType:'',
          reportFlag:"closedFlag='N'",
          startDate:'',
          endDate:'',
          operatorName:'',
          sResourceID:'',
          sShiftNo:'',
          seqNo:'',
        },
        scanModalFlag:false,
        currentData:'',
        tagNo2:'',
        startModalFlag:false,
        pageTitle:'',

      }
    },
    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight - 210
      })
    },

    methods: {
      // 获取基础数据列表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
        }
      },
      search () {
        getSOScheduleRoutingData(this.searchData).then(({data}) => {
          this.tableData = data.rows
        })
      },
      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
      },

      openScan(){
        this.scanSeqNo='';
        this.scanModalFlag=true;
        this.$nextTick(() => { this.$refs.input.focus();})
      },
      openStart(){
        this.scanSeqNo='';
        this.startModalFlag=true;
        this.$nextTick(() => { this.$refs.start.focus();})
      },
      searchSeqNo(){
        let inData={
          username:this.$store.state.user.name,
          seqNo:this.scanSeqNo,
        }
        toolStart(inData).then(({data}) => {
          if (data && data.code === 0) {
            this.scanModalFlag=false;
            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.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.orderNo =currentData.orderNo;
            this.toolList1=data.rows;
            this.setUp.reviewFlag=true;
            this.toolReportFlag=true;
            this.toolInstanceID='';
            this.pageTitle='工具报工'
            this.$nextTick(() => { this.$refs.report.focus();})
          } else {
            this.scanSeqNo='';
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      startSeqNo(){
        let inData={
          username:this.$store.state.user.name,
          seqNo:this.scanSeqNo,
        }
        toolStart(inData).then(({data}) => {
          if (data && data.code === 0) {
            this.startModalFlag=false;
            if(data.row==null){
              this.scanSeqNo=''
              this.$alert("派工单不存在！",'错误', {
                confirmButtonText: '确定'
              })
              return false;
            }
            let currentData = data.row;
            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.orderNo =currentData.orderNo;
            this.toolList1=data.rows;
            this.setUp.reviewFlag=true;
            this.toolReportFlag=false;
            this.toolInstanceID='';
            this.pageTitle='工具领用'
            this.$nextTick(() => { this.$refs.issuance.focus();})
          } else {
            this.scanSeqNo='';
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      toolIssuance(){
        this.$confirm(`确定领用此工具?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let inData={
            site:this.saveHeaderData.site,
            orderNo:this.saveHeaderData.orderNo,
            seqNo:this.saveHeaderData.seqNo,
            toolInstanceId:this.toolInstanceID,
            itemNo:this.saveHeaderData.itemNo,
            reportedby:this.$store.state.user.name,
          }
          toolIssuance(inData).then(({data}) => {
            if (data && data.code === 0) {
              let data2={
                username:this.$store.state.user.name,
                seqNo:this.saveHeaderData.seqNo,
              }
              toolStart(data2).then(({data}) => {
                if (data && data.code === 0) {
                  this.toolList1=data.rows;
                }
              })
              this.toolInstanceID='';
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.$nextTick(() => { this.$refs.issuance.focus();})
                }
              })
            } else {
              this.toolInstanceID='';
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },
      toolReportCheck(){
        let inData={
          site:this.saveHeaderData.site,
          orderNo:this.saveHeaderData.orderNo,
          seqNo:this.saveHeaderData.seqNo,
          toolInstanceId:this.toolInstanceID,
          itemNo:this.saveHeaderData.itemNo,
          reportedby:this.$store.state.user.name,
        }
        toolReportCheck(inData).then(({data}) => {
          if (data && data.code === 0) {
            this.toolInstanceID='';
            this.toolReportData={
              toolInstanceID:data.row.toolInstanceId,
              toolId:data.row.toolId,
              moQty:data.row.moQty,
              finishQty:'',
            }
            this.reportModalFlag=true;
            this.$nextTick(() => { this.$refs.reportDo.focus();})
          } else {
            this.toolInstanceID='';
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          } })
      },
      saveToolReport(){
        if(this.toolReportData.finishQty==null||this.toolReportData.finishQty==''){
          this.$alert("请输入生产数量！",'错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        if(this.toolReportData.finishQty<0){
          this.$alert("生产数量不能小于0！",'错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        this.$confirm(`确定报工?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let inData={
            site:this.saveHeaderData.site,
            orderNo:this.saveHeaderData.orderNo,
            seqNo:this.saveHeaderData.seqNo,
            toolInstanceId:this.toolReportData.toolInstanceID,
            itemNo:this.saveHeaderData.itemNo,
            reportedby:this.$store.state.user.name,
            moQty:this.toolReportData.moQty,
            finishQty:this.toolReportData.finishQty,
          }
          toolReport(inData).then(({data}) => {
            if (data && data.code === 0) {
              let data2={
                username:this.$store.state.user.name,
                seqNo:this.saveHeaderData.seqNo,
              }
              toolStart(data2).then(({data}) => {
                if (data && data.code === 0) {
                  this.toolList1=data.rows;
                }
              })
              this.reportModalFlag=false;
              this.toolInstanceID='';
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
              this.$nextTick(() => { this.$refs.report.focus();})
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },
      initUseModal(row){
        let currentData = row;
        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.orderNo =currentData.orderNo;
        this.toolUseDetailFlag=true;
        toolUseDetail(this.saveHeaderData).then(({data}) => {
          if (data && data.code === 0) {
            this.toolList2=data.rows;
          }
        })
      },
    },
    created () {

    }
  }
</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;
  }
</style>
