<template>
  <div class="customer-css">
    <el-dialog :title="titleCon" v-drag v-bind="$attrs" v-on="$listeners"
               width="920px" style="height: 680px;" class="customer-dialog">
      <el-form :inline="true" label-position="top" style="height: 495px;"
               label-width="80px">
        <!-- 菜单信息 -->
        <el-row>
          <el-col :span="24">
            <el-form-item :label="'当前时间'">
              <el-date-picker disabled="disabled" style="width: 145px;"
                              v-model="pageData.reportedTime"
                              format="yyyy-MM-dd HH:mm:ss"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="">
              </el-date-picker>
            </el-form-item>
            <el-form-item class="customer-button">
              <el-button type="primary" :disabled="buttonTags.createRollFlag" style="margin-left: 10px; margin-bottom: 5px;">
                列表</el-button>
            </el-form-item>
            <el-form-item class="customer-button">
              <el-button type="primary" @click="refreshPageData" style="margin-left: 10px; margin-bottom: 5px;">
              刷新</el-button>
            </el-form-item>
            <el-form-item class="customer-button">
              <el-button type="primary" @click="finishRollBun"  style="margin-left: 10px; margin-bottom: 5px;">
              结束卷</el-button>
            </el-form-item>
            <el-form-item class="customer-button">
              <el-button type="primary" @click="closeDialog" style="margin-left: 10px; margin-bottom: 5px;">
              关闭</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <!--  卷数量统计 班次信息  -->
        <el-form>
          <fieldset class="customer-fieldset" style="width: 505px;">
            <legend>卷数量统计</legend>
            <el-form-item class="customer-item">
              <el-checkbox disabled="disabled" style="margin-top: 15px;" true-label="Y" false-label="N"
                           v-model="pageData.reportedFlag">是否报告产量</el-checkbox>
            </el-form-item>
            <el-form-item class="customer-item" label="总良品数量:" style="margin-top: -10px;">
              <el-input v-model="pageData.approvedQty" type="number"  @blur="checkValidApprovedQty"
                        style="width: 80px;" ></el-input>
            </el-form-item>
            <el-form-item class="customer-item" label="总不良品数量:" style="margin-top: -10px;">
              <el-input v-model="pageData.defectedQty" disabled="disabled" style="width: 80px;"></el-input>
            </el-form-item>
            <el-form-item class="customer-item" label="总数量" style="margin-top: -10px;">
              <el-input v-model="pageData.totalQty" disabled="disabled" style="width: 80px;"></el-input>
            </el-form-item>
            <el-form-item class="customer-item" label="其他卷数量:" style="margin-top: -10px;">
              <el-input v-model="pageData.otherRollQty" disabled="disabled" style="width: 80px;"></el-input>
            </el-form-item>
          </fieldset>
          <!-- 操作员信息和班次信息 -->
          <fieldset class="customer-fieldset"
                    style="margin-left: 510px; margin-top: -70px; ;width: 390px;">
            <legend>人员排程班次信息</legend>
            <el-form-item class="customer-item" label="操作员:">
              <el-input v-model="operatorData.operatorId" disabled="disabled" style="width: 80px;" ></el-input>
            </el-form-item>
            <el-form-item class="customer-item" label="操作员姓名:">
              <el-input v-model="operatorData.operatorName" disabled="disabled" style="width: 80px;"></el-input>
            </el-form-item>
            <el-form-item class="customer-item" label="排产日期:">
              <el-input v-model="pageData.scheduledDate" disabled="disabled" style="width: 80px;" ></el-input>
            </el-form-item>
            <el-form-item class="customer-item" label="班次:">
              <el-input v-model="pageData.shiftDesc" disabled="disabled" style="width: 80px;"></el-input>
            </el-form-item>
          </fieldset>
        </el-form>
        <!-- 卷生产时间统计产量报告 -->
        <el-form style="margin-top: 5px;">
            <fieldset class="customer-fieldset" style="width: 320px;">
              <legend>卷生产时间统计</legend>
              <!-- 调机时间 -->
              <el-row>
                <el-col :span="24">
                  <el-form-item  label="总调机时间:">
                    <el-input v-model="pageData.totalSetupTime" disabled="disabled" style="width: 80px;" ></el-input>
                  </el-form-item>
                  <el-form-item  label="总调机过程停机时间:">
                    <el-input v-model="pageData.totalDowntimeTimeSetup" disabled="disabled" style="width: 100px;"></el-input>
                  </el-form-item>
                  <el-form-item  label="净调机时间:" >
                    <el-input v-model="pageData.totalPureSetupTime" disabled="disabled" style="width: 80px;"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- 生产时间 -->
              <el-row>
                <el-col :span="24">
                  <el-form-item  label="总生产时间">
                    <el-input v-model="pageData.totalProdTime" disabled="disabled" style="width: 80px;"></el-input>
                  </el-form-item>
                  <el-form-item  label="总生产过程停机时间:">
                    <el-input v-model="pageData.totalDowntimeTimeProd" disabled="disabled" style="width: 100px;"></el-input>
                  </el-form-item>
                  <el-form-item  label="净生产时间:" >
                    <el-input v-model="pageData.totalPureProdTime" disabled="disabled" style="width: 80px;"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- 制造时间 -->
              <el-row>
                <el-col :span="24">
                  <el-form-item  label="总制造时间:">
                    <el-input v-model="pageData.totalManufactureTime" disabled="disabled" style="width: 80px;"></el-input>
                  </el-form-item>
                  <el-form-item  label="总制造过程停机时间:">
                    <el-input v-model="pageData.totalManufactureDowntimeTime" disabled="disabled" style="width: 100px;"></el-input>
                  </el-form-item>
                  <el-form-item  label="净制造时间:" >
                    <el-input v-model="pageData.totalPureManufactureTime" disabled="disabled" style="width: 80px;"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </fieldset>
            <!-- 产量报告 -->
            <fieldset class="customer-fieldset"
                      style="margin-left: 325px; margin-top: -165px; width: 575px;">

              <legend>产量报告</legend>
              <!-- 开工时间 -->
              <el-row>
                <el-col :span="24">
                  <el-form-item  label="开工时间">
                    <el-input v-model="pageData.eventTime" disabled="disabled" style="width: 130px;"></el-input>
                  </el-form-item>
                  <el-form-item  label="完工时间">
                    <el-input v-model="pageData.tillTime" disabled="disabled" style="width: 130px;"></el-input>
                  </el-form-item>
                  <el-form-item  label="生产时间" >
                    <el-input v-model="pageData.sfdcProdTime" disabled="disabled" style="width: 80px;"></el-input>
                  </el-form-item>
                  <el-form-item  label="调机时间" >
                    <el-input v-model="pageData.sfdcSetupTime" disabled="disabled" style="width: 80px;"></el-input>
                  </el-form-item>
                  <el-form-item  label="制造时间" >
                    <el-input v-model="pageData.sfdcManufactureTime" disabled="disabled" style="width: 80px;"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- 合格数量 -->
              <el-row>
                <el-col :span="24">
                  <el-form-item  label="合格数量">
                    <el-input v-model="pageData.sfdcApprovedQty" disabled="disabled" style="width: 130px;"></el-input>
                  </el-form-item>
                  <el-form-item  label="不合格数量">
                    <el-input v-model="pageData.defectedQty" disabled="disabled" style="width: 130px;"></el-input>
                  </el-form-item>
                  <el-form-item  label="报告数量" >
                    <el-input v-model="pageData.sfdcReportedQty" disabled="disabled" style="width: 80px;"></el-input>
                  </el-form-item>
                  <el-form-item  label="调机停机">
                    <el-input v-model="pageData.sfdcSetupDownTime" style="width: 80px;"></el-input>
                  </el-form-item>
                  <el-form-item  label="生产调机" >
                    <el-input v-model="pageData.sfdcProdSetupTime" style="width: 80px;"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- 备注 -->
              <el-row>
                <el-col :span="24">
                  <el-form-item  label="remark">
                    <el-input v-model="pageData.remark" disabled="disabled" style="width: 430px;"></el-input>
                  </el-form-item>
                  <el-form-item  label="停机时间">
                    <el-input v-model="pageData.sfdcDownTime" style="width: 80px;"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </fieldset>
        </el-form>
        <!-- 主材料 -->
        <el-form>
          <fieldset class="customer-fieldset" style="width: 830px;">
            <legend>主材料</legend>
            <el-table
              height="180"
              :data="sfdcMaterialList"
              :cell-style="customerCellStyle" :cell-class-name="customerCellClassName"
              border
              v-loading="dataListLoading"
              style="width: 100%; margin-top: -5px;">
              <el-table-column
                v-for="(item,index) in columnMaterialArray" :key="index"
                :sortable="item.columnSortable"
                :prop="item.columnProp"
                :header-align="item.headerAlign"
                :show-overflow-tooltip="item.showOverflowTooltip"
                :align="item.align"
                :fixed="item.fixed"
                :width="item.columnWidth"
                :label="item.columnLabel">
                <template slot-scope="scope">
                  <el-input type="number" class="table-input" align="right" @blur="checkValidQty(scope.row)"
                            v-if="item.columnHidden" v-model="scope.row[item.columnProp]"></el-input>
                  <span v-else>{{scope.row[item.columnProp]}}</span>
                  <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                                     style="width: 100px; height: 80px"/></span>
                </template>
              </el-table-column>
            </el-table>
          </fieldset>
        </el-form>
      </el-form>


    </el-dialog>

    <!-- 异常原因录入的组件 -->
    <comExceptionReason ref="comExceptionReason" :close-on-click-modal="false"
                    :visible.sync="showExceptionFlag"
                    @initExceptionReason = "initExceptionReason">

    </comExceptionReason>
  </div>

</template>

<script>
  /*添加组件*/
  import comExceptionReason from "./com_exception_reason";//异常远远
import {
  getCurrentRollReportedQty,
  countSfdcTimeQty,
  getScheduleShiftData,
  getSfdcTimeMaxAndMinTime,
  getSfdcTimeData,
  getSfdcReportedData,
  getSfdcMaterialByRollNo,
  checkFinishRollWithNoFqc,
  finishRollWithNoFqc
} from '@/api/yieldReport/com_finish_roll.js';
export default {
  name: "com_finish_roll",
  data() {
    return {
      titleCon: '结束卷',
      showExceptionFlag: false,
      sfdcTimeList: [],
      scheduleData: {
        site: this.$store.state.user.site,
        userName: this.$store.state.user.name,
        seqNo: '',
        orderNo: '',
        itemNo: 0,
        partNo: '',
        workCenterNo: '',
        workCenterDesc: '',
        resourceDesc: '',
        rollNo: '',
        partDesc: '',
        planStartTime: '',
        planFinishTime: '',
        qtyRequiredOriginal: 0,
        scheduledDate: '',
        shiftNo: '',
        preItemDesc: '',
        nextItemDesc: '',
        nextItemNo: 0,
        operatorId: '',
        functionName: '',
        currentRollFlag: false
      },
      pageData: {
        site: this.$store.state.user.site,
        userName: this.$store.state.user.name,
        orderNo: '',
        itemNo: 0,
        seqNo: '',
        rollNo: '',
        resourceId: '',
        scheduledDate: '',
        shiftNo: '',
        reportedTime: this.dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss'),
        reportedFlag: 'N',
        approvedQty: 0,
        defectedQty: 0,
        totalQty: 0,
        editNewRollQty: 0,
        otherRollQty: '',
        shiftDesc: '',
        totalSetupTime: 0,
        totalDowntimeTimeSetup: 0,
        totalPureSetupTime: 0,
        totalProdTime: 0,
        totalDowntimeTimeProd: 0,
        totalPureProdTime: 0,
        totalManufactureTime: 0,
        totalManufactureDowntimeTime: 0,
        totalPureManufactureTime: 0,
        sfdcProdTime: 0,//生产时间
        sfdcSetupTime: 0,//调机时间
        sfdcManufactureTime: 0,//制造时间
        sfdcSetupDownTime: 0,//调机停机时间
        sfdcProdSetupTime: 0,//生产调机时间
        sfdcDownTime: 0,//停机时间
        eventTime: '',
        tillTime: '',
        sfdcApprovedQty: 0,
        sfdcDefectedQty: 0,
        sfdcReportedQty: 0,
        remark: '',
        exceptionFlag: 'N',
        exceptionReason: '',
      },
      operatorData: {
        site: this.$store.state.user.site,
        username: this.$store.state.user.name,
        operatorId: '',
        operatorName: '',
        status: '',
        seqNo: '',
        showFlag: false
      },
      sfdcMaterialList: [],
      columnMaterialArray: [
        {
          userId: this.$store.state.user.name,
          functionId: 5303,
          serialNumber: '5303MaterialReportDate',
          tableId: "5303Material",
          tableName: "派工单材料",
          columnProp: "reportDate",
          headerAlign: "center",
          align: "center",
          columnLabel: "报告时间",
          columnWidth: 125,
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: 5303,
          serialNumber: '5303MaterialReportedBy',
          tableId: "5303Material",
          tableName: "派工单材料",
          columnProp: "reportedBy",
          headerAlign: "center",
          align: "center",
          columnLabel: "报告人",
          columnWidth: 80,
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: 5303,
          serialNumber: '5303MaterialRmRollNo',
          tableId: "5303Material",
          tableName: "派工单材料",
          columnProp: "rmRollNo",
          headerAlign: "center",
          align: "center",
          columnLabel: "材料卷号",
          columnWidth: 100,
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: 5303,
          serialNumber: '5303MaterialPartNo',
          tableId: "5303Material",
          tableName: "派工单材料",
          columnProp: "partNo",
          headerAlign: "center",
          align: "center",
          columnLabel: "零部件编码",
          columnWidth: 100,
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: 5303,
          serialNumber: '5303MaterialStartDate',
          tableId: "5303Material",
          tableName: "派工单材料",
          columnProp: "startDate",
          headerAlign: "center",
          align: "center",
          columnLabel: "开始使用时间",
          columnWidth: 125,
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: 5303,
          serialNumber: '5303MaterialTransQty',
          tableId: "5303Material",
          tableName: "派工单材料",
          columnProp: "transQty",
          headerAlign: "center",
          align: "center",
          columnLabel: "数量",
          columnWidth: 80,
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: 5303,
          serialNumber: '5303MaterialNetIssueQty',
          tableId: "5303Material",
          tableName: "派工单材料",
          columnProp: "netIssueQty",
          headerAlign: "center",
          align: "center",
          columnLabel: "本卷耗用数量",
          columnWidth: 100,
          columnHidden: true,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: 5303,
          serialNumber: '5303MaterialKeyRMFlag',
          tableId: "5303Material",
          tableName: "派工单材料",
          columnProp: "keyRMFlag",
          headerAlign: "center",
          align: "center",
          columnLabel: "是否主材",
          columnWidth: 80,
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: 5303,
          serialNumber: '5303MaterialSAPBOMItemNo',
          tableId: "5303Material",
          tableName: "派工单材料",
          columnProp: "sAPBOMItemNo",
          headerAlign: "center",
          align: "center",
          columnLabel: "SAP BOM序号",
          columnWidth: 100,
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        }
      ],
      buttonTags:{
        createNewRollFlag: true,
        switchRollFlag: true,
        separatorRollFlag: true,
        finishRollFlag: true,
        mergeRollFlag: true,
        tuningFlag: true,
        produceFlag: true,
        defectFlag: true,
        toolFlag: true,
        materialFlag: true,
        downTimeFlag: true
      },
      dataListLoading: false,
    }
  },
  components: {
    comExceptionReason,/*异常原因的组件*/
  },
  methods: {
    /*初始化页面参数*/
    init(scheduleData, operatorData) {
      //初始化参数
      this.scheduleData = scheduleData;
      //初始化参数
      this.pageData.orderNo = scheduleData.orderNo;
      this.pageData.itemNo = scheduleData.itemNo;
      this.pageData.seqNo = scheduleData.seqNo;
      this.pageData.rollNo = scheduleData.rollNo;
      this.pageData.scheduledDate = scheduleData.scheduledDate;
      this.pageData.shiftNo = scheduleData.shiftNo;
      this.pageData.resourceId = scheduleData.resourceId;
      this.pageData.operatorId = operatorData.operatorId;
      //重置时间
      this.pageData.reportedTime = this.dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss');
      //初始化操作员对象
      this.operatorData = JSON.parse(JSON.stringify(operatorData));
      //初始化标题
      this.titleCon = '结束卷操作 \
       派工单号:'+scheduleData.seqNo;
      //处理异常的原因
      this.pageData.exceptionFlag = 'N';
      this.pageData.exceptionReason =  '';
      //刷新当前派工单的信息
      this.refreshPageData();
    },
    /*关闭modal*/
    closeDialog(){
      this.$emit('update:visible', false);
    },

    /*生产过程的停机组件*/
    exceptionReasonModal() {
      //1.首先调用菜单判断方式  打开生产过程的停机的页面
      //checkProduceButton('produceDownFlag');
      //打开生产过程的工具的页面
      this.$nextTick(() => {
        this.show = true;
        this.$refs.comProduceDown.init(this.scheduleData, this.operatorData)
      });
    },

    /*刷新当前的页面参数*/
    refreshPageData(){
      //1.刷新当前卷的报工数据
      getCurrentRollReportedQty(this.scheduleData).then(({data}) => {
        this.pageData.approvedQty = data.row.approvedQty;
        this.pageData.defectedQty = data.row.defectedQty;
        this.pageData.totalQty = data.row.totalQty;
        this.pageData.otherRollQty = data.row.otherRollQty;
      }).then(() => {
        //2.刷新当前卷的时间信息
        countSfdcTimeQty(this.scheduleData).then(({data}) => {
          this.pageData.totalSetupTime = data.row.totalSetupTime;
          this.pageData.totalDowntimeTimeSetup = data.row.totalDowntimeTimeSetup;
          this.pageData.totalPureSetupTime = data.row.totalPureSetupTime;
          this.pageData.totalProdTime = data.row.totalProdTime;
          this.pageData.totalDowntimeTimeProd = data.row.totalDowntimeTimeProd;
          this.pageData.totalPureProdTime = data.row.totalPureProdTime;
          this.pageData.totalManufactureTime = data.row.totalManufactureTime;
          this.pageData.totalManufactureDowntimeTime = data.row.totalManufactureDowntimeTime;
          this.pageData.totalPureManufactureTime = data.row.totalPureManufactureTime;
          //先预设一些参数  后期方法再计算
          //生产时间=总生产时间
          this.pageData.sfdcProdTime = this.pageData.totalProdTime;
          //调机时间=总调机时间
          this.pageData.sfdcSetupTime = this.pageData.totalSetupTime;
          //制造时间=总制造时间
          this.pageData.sfdcManufactureTime = this.pageData.totalManufactureTime;
          //调机停机=总调机过程停机时间
          this.pageData.sfdcSetupDownTime = this.pageData.totalDowntimeTimeSetup;
          //生产调机=总生产过程停机时间
          this.pageData.sfdcProdSetupTime = this.pageData.totalDowntimeTimeProd;
          //停机时间=总制造过程停机时间
          this.pageData.sfdcDownTime = this.pageData.totalManufactureDowntimeTime;
        });
      }).then(() => {
        //3.刷新派工单的班次信息
        getScheduleShiftData(this.scheduleData).then(({data}) => {
          this.pageData.shiftDesc = data.row.shiftDesc;//重置班次
          this.pageData.scheduledDate = data.row.scheduledDate.substring(0, 10);//重置排产日期
        });
      }).then(() => {
        //4.刷新当前卷的最早和最晚时间
        getSfdcTimeMaxAndMinTime(this.scheduleData).then(({data}) => {
          this.pageData.eventTime = data.row.eventTime;
          this.pageData.tillTime = data.row.tillTime;
        });
      }).then(() => {
        //5.刷新当前卷的Sfdc表的时间
        getSfdcTimeData(this.scheduleData).then(({data}) => {
          //先判断是否成功查询
          if(data.resultCode == 200){
            //判断是否操作成功
            this.pageData.eventTime = data.row.finishTime;
            this.pageData.sfdcProdTime = data.row.sfdcProdTime;
            this.pageData.sfdcSetupTime = data.row.sfdcSetupTime;
            this.pageData.sfdcManufactureTime = data.row.sfdcManufactureTime;
            this.pageData.sfdcDownTime = data.row.sfdcDownTime;
            this.pageData.sfdcSetupDownTime = data.row.sfdcSetupDownTime;
            this.pageData.sfdcProdSetupTime = data.row.sfdcProdSetupTime;
          }else{
            //暂时不处理数据
          }
        });
      }).then(() => {
        //6.刷新当前卷的报工数据
        getSfdcReportedData(this.scheduleData).then(({data}) => {
          this.pageData.sfdcApprovedQty = this.pageData.approvedQty - data.row.approveQty;
          this.pageData.sfdcDefectedQty = this.pageData.defectedQty - data.row.defectQty;
          this.pageData.sfdcReportedQty = this.pageData.sfdcApprovedQty + this.pageData.sfdcDefectedQty;
        });
      }).then(() => {
        //刷新当前卷的时间数据
        getSfdcMaterialByRollNo(this.scheduleData).then(({data}) => {
          this.sfdcMaterialList = data.rows;
        });
      });


    },

    /*刷新当前卷的报工数据汇总*/
    refreshCurrentRollReportedQty(){
      getCurrentRollReportedQty(this.scheduleData).then(({data}) => {
        this.pageData.approvedQty = data.row.approvedQty;
        this.pageData.defectedQty = data.row.defectedQty;
        this.pageData.totalQty = data.row.totalQty;
        this.pageData.otherRollQty = data.row.otherRollQty;
      })
    },

    //刷新当前卷的时间信息
    refreshCurrentRollTimeQty(){
      countSfdcTimeQty(this.scheduleData).then(({data}) => {
        this.pageData.totalSetupTime = data.row.totalSetupTime;
        this.pageData.totalDowntimeTimeSetup = data.row.totalDowntimeTimeSetup;
        this.pageData.totalPureSetupTime = data.row.totalPureSetupTime;
        this.pageData.totalProdTime = data.row.totalProdTime;
        this.pageData.totalDowntimeTimeProd = data.row.totalDowntimeTimeProd;
        this.pageData.totalPureProdTime = data.row.totalPureProdTime;
        this.pageData.totalManufactureTime = data.row.totalManufactureTime;
        this.pageData.totalManufactureDowntimeTime = data.row.totalManufactureDowntimeTime;
        this.pageData.totalPureManufactureTime = data.row.totalPureManufactureTime;
      });
    },

    //刷新派工单的班次信息
    refreshScheduleShiftData(){
      getScheduleShiftData(this.scheduleData).then(({data}) => {
        this.pageData.shiftDesc = data.row.shiftDesc;//重置班次
        this.pageData.scheduledDate = data.row.scheduledDate.substring(0, 10);//重置排产日期
      });
    },

    //刷新当前卷的时间信息
    refreshCurrentRollMaxAndMinTime(){
      getSfdcTimeMaxAndMinTime(this.scheduleData).then(({data}) => {
        this.pageData.eventTime = data.row.eventTime;
        this.pageData.tillTime = data.row.tillTime;
      });
    },

    //刷新当前卷的Sfdc的信息
    refreshSfdcTimeData(){
      getSfdcTimeData(this.scheduleData).then(({data}) => {
        //判断是否操作成功
        this.pageData.eventTime = data.row.finishTime;
        this.pageData.sfdcProdTime = data.row.sfdcProdTime;
        this.pageData.sfdcSetupTime = data.row.sfdcSetupTime;
        this.pageData.sfdcManufactureTime = data.row.sfdcManufactureTime;
        this.pageData.sfdcDownTime = data.row.sfdcDownTime;
        this.pageData.sfdcSetupDownTime = data.row.sfdcSetupDownTime;
        this.pageData.sfdcProdSetupTime = data.row.sfdcProdSetupTime;
      });
    },

    //刷新当前卷的报工数据
    refreshSfdcData(){
      getSfdcReportedData(this.scheduleData).then(({data}) => {
        this.pageData.sfdcApprovedQty = this.pageData.approvedQty - data.row.approveQty;
        this.pageData.sfdcDefectedQty = this.pageData.defectedQty - data.row.defectQty;
        this.pageData.sfdcReportedQty = this.pageData.sfdcApprovedQty + this.pageData.sfdcDefectedQty;
      });
    },

    //刷新当前卷的时间数据
    refreshSfdcMaterialTable(){
      getSfdcMaterialByRollNo(this.scheduleData).then(({data}) => {
        this.sfdcMaterialList = data.rows;
      });
    },



    /*检查数据是否有效*/
    checkValidQty(row){
      //判断当前是否为空
      if(row.netIssueQty == ''){
        this.$message.error('材料上本卷耗用数量不能为空!');
        row.netIssueQty = 0;//重新赋值
        return false;
      }
      //判断当前是否有效
      if(row.netIssueQty <= 0){
        this.$message.error('材料耗用数量必须大于0!');
        return false;
      }
      //判断是否超限
      if(row.netIssueQty > row.transQty){
        this.$message.error('材料耗用数量大于发料数量!');
        row.netIssueQty = 0;//重新赋值
        return false;
      }
    },

    /*添加定制的css类*/
    customerCellClassName({row, column, rowIndex, columnIndex}) {
      if(column.property == 'netIssueQty'){
        return 'customer-number-cell';
      }
    },

    /*添加定制的cess样式*/
    customerCellStyle({row, column, rowIndex, columnIndex}) {
      if(column.property == 'netIssueQty'){
        return 'padding: 0px 0px;';
      }
    },

    /*检验良品的总数量*/
    checkValidApprovedQty(){
      //调用刷新的方法
      this.refreshSfdcData();
    },

    /*结束当前的操作*/
    finishRollBun(){
      //首先判断数值是否通过判断
      let approvedQty = this.pageData.approvedQty;
      if(approvedQty == null || approvedQty == ''){
        this.$message.error('请输入良品总数量!');
        this.pageData.approvedQty = 0;//重新赋值
        return false;
      }
      if(approvedQty <= 0){
        this.$message.error('良品总数量必须大于0!');
        this.pageData.approvedQty = 0;//重新赋值
        return false;
      }
      //班次判断
      if(this.pageData.shiftDesc == '无班次'){
        this.$message.error('该时间段内没有匹配的班次信息,请联系相关人员！!');
        return false;
      }

      //验证通过提交到后台
      let postData = {'pageData': JSON.stringify(this.pageData), 'materialList': JSON.stringify(this.sfdcMaterialList)};

      //先调用检查方法
      checkFinishRollWithNoFqc(postData).then(({data}) => {
        //判断是否成功
        if(data.code == 500){
          this.$message.error(data.msg);
        }else if (data.resultMap.resultCode == '201'){
          //打开异常原因录入的界面
          this.$confirm(data.resultMap.resultMsg, '提示', {
            confirmButtonText: '确认',
            celButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.showExceptionReasonModal();
          });
        }else{
          //执行结束卷操作
          this.finishRollOperation();
        }
      });

    },

    /*结束卷的具体操作*/
    finishRollOperation(){
      //验证通过提交到后台
      let postData = {'pageData': JSON.stringify(this.pageData), 'materialList': JSON.stringify(this.sfdcMaterialList)};
      //处理信息
      finishRollWithNoFqc(postData).then(({data}) => {
        this.$message.error('qty_reported找不到!');
        //判断操作是否成功
        if(data.code == 500){
          this.$message.error(data.msg);
        }else{
          //刷新报工的页面
          this.$emit('refreshPageData');
          //关闭当前的页面
          this.closeDialog();
        }
      })
    },

    /*打开异常原因录入页面*/
    showExceptionReasonModal(){
      //1.首先调用菜单判断方式  打开生产过程的材料的页面
      //checkProduceButton('produceMaterialFlag');
      //打开生产过程的工具的页面
      this.$nextTick(() => {
        this.showExceptionFlag = true;
        this.$refs.comExceptionReason.init();
      });
    },

    /*处理异常的原因*/
    initExceptionReason(exceptionReason){
      //处理异常的原因
      this.pageData.exceptionFlag = 'Y';
      this.pageData.exceptionReason =  exceptionReason;
      //然后提交结束卷的数据
      this.finishRollOperation();
    }
  },
  created() {
    // this.factoryList()
    // this.getLanguageList()
  }
}

</script>

<style scoped lang="scss">
/*调节页面button和input的上下间距*/
.customer-css .customer-button{
  margin-top: 25px;
}

/*调节样式*/
.customer-item{
  margin-top: -10px;
}
/*fieldset下table的样式*/
.customer-fieldset /deep/ .el-table__header th.is-leaf{
  line-height: 16px;
}

/deep/ .customer-tab .el-tabs__content{
  padding: 0px !important;
}

/*table中input*/
div.table-input /deep/ input.el-input__inner{
  text-align: right;
}

</style>
