<template>
  <div class="mod-config">
    <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;" >
      <el-row>
        <el-col :span="24" style="">
          <el-form-item :label="'物料编码:'">
            <el-input v-model="searchData.partNo" style="width: 130px"></el-input>
          </el-form-item>
          <el-form-item :label="'物料名称:'">
            <el-input v-model="searchData.partDesc" 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.poOrderNo" style="width: 130px"></el-input>
          </el-form-item>
          <el-form-item :label="'采购单行号:'">
            <el-input v-model="searchData.poItemNo" style="width: 130px"></el-input>
          </el-form-item>
          <el-form-item label="检验日期">
            <el-date-picker
              style="width: 130px"
              v-model="searchData.startDate"
              value-format="yyyy-MM-dd"
             >
            </el-date-picker>
            -
            <el-date-picker
              style="width: 130px"
              v-model="searchData.endDate "
              value-format="yyyy-MM-dd"
           >
            </el-date-picker>
          </el-form-item>
          <el-form-item :label="' '" >
            <el-button class="customer-bun-min" type="primary" @click="getMainData" style="">Query</el-button>
            <el-button @click="exportExcel()" type="primary" style="margin-left: 2px">{{'导出'}}</el-button>

          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-table
      :height="height"
      :data="mainDataList"
      border
      ref="mainTable"
      highlight-current-row
      @row-click="changeData"
      v-loading="dataListLoading"
      style="margin-top: 0px; width: 100%;">
      <el-table-column
        header-align="center"
        align="center"
        width="100"
        label="操作">
        <template slot-scope="scope">
          <a type="text" size="small" @click="addOrUpdateHandle(scope.row)">生成标签</a>
        </template>
      </el-table-column>
      <el-table-column
        v-for="(item,index) in columnArray1" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed==''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden"> {{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>

    <el-pagination style="margin-top: 0px"
                   @size-change="sizeChangeHandle"
                   @current-change="currentChangeHandle"
                   :current-page="pageIndex"
                   :page-sizes="[20, 50, 100, 200, 500]"
                   :page-size="pageSize"
                   :total="totalPage"
                   layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;" >
    <el-form-item >
      <el-button  type="primary" @click="printLabels" style="">打印</el-button>
      <el-button @click="deleteLabels()" type="primary" style="margin-left: 2px">删除</el-button>
      <el-button type="primary" icon="el-icon-upload" @click="openUpload()" style="margin-left: 2px">导入</el-button>
    </el-form-item>
    </el-form>
    <el-table
      :height="height"
      :data="table2List"
      border
      ref="table3"
      highlight-current-row
      @selection-change="handleSelectionChange"
      v-loading="dataListLoading"
      style="margin-top: 0px; width: 100%;">
      <el-table-column
        type="selection"
        width="55"
        align="center">
      </el-table-column>
      <el-table-column
        v-for="(item,index) in columnArray2" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed==''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden"> {{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>

    <el-dialog title="标签发行" :close-on-click-modal="false" v-drag :visible.sync="addModelFlag" width="800px">
      <el-form :model="addModelData" label-position="top" style="margin-top: -5px;">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="物料编码" >
              <el-input v-model="addModelData.partNo" disabled style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="物料名称" >
              <el-input v-model="addModelData.partDesc" disabled style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="采购订单" >
              <el-input v-model="addModelData.poOrderNo" disabled style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="采购订单行号">
              <el-input v-model="addModelData.poItemNo" disabled style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="通知单">
              <el-input v-model="addModelData.orderNo"  disabled style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="本次到货数量">
              <el-input v-model="addModelData.orderQty"  disabled style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="本次到货卷数">
              <el-input v-model="addModelData.orderRollCount"  disabled style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="检验合格数量">
              <el-input v-model="addModelData.batchQualifiedQty"  disabled style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="超入比例" >
              <el-input v-model="addModelData.exceedInRatio" disabled style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="有效期管理">
              <el-input v-model="addModelData.expirationFlag"  disabled style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生产日期" required>
              <el-date-picker
                v-model="addModelData.productionDate"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                style="width: 100%">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="批次号">
              <el-input v-model="addModelData.batchNo" style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发行张数" required>
              <el-input v-model="addModelData.rollCount" @blur="getNowRollQty()" @input="handleInput" type="number" style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="每张数量" required>
              <el-input v-model="addModelData.rollQty" @blur="getNowRollQty()" type="number"  style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="尾卷数量">
              <el-input v-model="addModelData.tailRollQty" @blur="getNowRollQty()" type="number"  style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="本次发行数量"  >
              <el-input v-model="addModelData.nowRollQty" disabled style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="本次可发行数量">
              <el-input v-model="addModelData.remainingIssuableQty"  disabled style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer" style="text-align: center;">
        <el-button type="success" @click="submitDataNoClose()">应用</el-button>
        <el-button type="success" @click="submitData()">确定</el-button>
        <el-button type="primary" @click="addModelFlag=false">取消</el-button>
      </div>
    </el-dialog>

    <!-- 导入 -->
    <qcUpload ref="qcUpload" @refreshPageTables="getDetailTableList()" v-drag></qcUpload>

  </div>
</template>

<script>
/*组件*/
import excel from "@/utils/excel-util.js";
import qcUpload from "@/views/modules/qc/qc_upload";
import {
  deletePoPartLabelData,
  getInboundQcResultData,
  getInboundQcResultOtherData,
  getPoOrderRollNoOutData, getPoPartLabelData,
  submitPoOrderRollNo
} from '../../../api/wms/wms'
import {poPartLabelPrint} from '../clodopLabel/poPartLabel'
export default {
  data() {
    return {
      functionId: this.$route.meta.menuId,
      height: 200,
      currentRow: {},
      searchData:{
        site:this.$store.state.user.site,
        orderNo:'',
        partNo:'',
        partDesc:'',
        poOrderNo:'',
        poItemNo:'',
        startDate:'',
        endDate:'',
        page: 1,
        limit: 10,
      },
      selectionDataList:[],
      pageIndex: 1,
      pageSize: 50,
      totalPage: 0,
      mainDataList:[],
      table2List:[],
      dataListLoading: false,
      addModelFlag:false,
      addModelData:{
        expirationWarningDay:'',
        site:'',
        buNo:'',
        partNo: '',
        partDesc: '',
        poOrderNo: '',
        poItemNo: '',
        orderNo: '',
        orderQty: '',
        supplierId: '',
        supplierName: '',
        orderRollCount: '',
        batchQualifiedQty: '',
        remainingIssuableQty: '',
        exceedInRatio: '',
        expirationFlag: '',
        expirationDay: '',
        nowRollQty: '',
        productionDate: '',
        batchNo: '',
        rollCount: '1',
        rollQty: '',
        tailRollQty: '0'
      },
      columnArray1: [
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table1BuNo',
          tableId: "670Table1",
          tableName: "采购检验合格单",
          columnProp: "buNo",
          headerAlign: "center",
          align: "center",
          columnLabel: "BU",
          columnWidth: '70',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table1OrderNo',
          tableId: "670Table1",
          tableName: "采购检验合格单",
          columnProp: "orderNo",
          headerAlign: "center",
          align: "left",
          columnLabel: "通知单号",
          columnWidth: '120',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 1,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table1OrderStatus',
          tableId: "670Table1",
          tableName: "采购检验合格单",
          columnProp: "orderStatus",
          headerAlign: "center",
          align: "center",
          columnLabel: "单据状态",
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 2,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table1PartNo',
          tableId: "670Table1",
          tableName: "采购检验合格单",
          columnProp: "partNo",
          headerAlign: "center",
          align: "left",
          columnLabel: "物料编码",
          columnWidth: '120',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 3,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table1PartDesc',
          tableId: "670Table1",
          tableName: "采购检验合格单",
          columnProp: "partDesc",
          headerAlign: "center",
          align: "left",
          columnLabel: "物料名称",
          columnWidth: '200',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 4,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table1PoOrderNo',
          tableId: "670Table1",
          tableName: "采购检验合格单",
          columnProp: "poOrderNo",
          headerAlign: "center",
          align: "left",
          columnLabel: "采购订单号",
          columnWidth: '120',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 5,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table1PoItemNo',
          tableId: "670Table1",
          tableName: "采购检验合格单",
          columnProp: "poItemNo",
          headerAlign: "center",
          align: "center",
          columnLabel: "行号",
          columnWidth: '80',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 6,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table1SupplierName',
          tableId: "670Table1",
          tableName: "采购检验合格单",
          columnProp: "supplierName",
          headerAlign: "center",
          align: "left",
          columnLabel: "供应商",
          columnWidth: '120',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 7,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table1InspectorDate',
          tableId: "670Table1",
          tableName: "采购检验合格单",
          columnProp: "inspectorDate",
          headerAlign: "center",
          align: "center",
          columnLabel: "检验日期",
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 8,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table1InspectorNo',
          tableId: "670Table1",
          tableName: "采购检验合格单",
          columnProp: "inspectorNo",
          headerAlign: "center",
          align: "left",
          columnLabel: "检验员",
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 9,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table1OrderQty',
          tableId: "670Table1",
          tableName: "采购检验合格单",
          columnProp: "orderQty",
          headerAlign: "center",
          align: "right",
          columnLabel: "到货数量",
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 10,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table1RollCount',
          tableId: "670Table1",
          tableName: "采购检验合格单",
          columnProp: "rollCount",
          headerAlign: "center",
          align: "right",
          columnLabel: "到货卷数",
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 11,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table1InspectionResult',
          tableId: "670Table1",
          tableName: "采购检验合格单",
          columnProp: "inspectionResult",
          headerAlign: "center",
          align: "center",
          columnLabel: "检验结论",
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 12,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table1DisposalMeasures',
          tableId: "670Table1",
          tableName: "采购检验合格单",
          columnProp: "disposalMeasures",
          headerAlign: "center",
          align: "left",
          columnLabel: "处置措施",
          columnWidth: '120',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 13,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table1BatchQualifiedQty',
          tableId: "670Table1",
          tableName: "采购检验合格单",
          columnProp: "batchQualifiedQty",
          headerAlign: "center",
          align: "right",
          columnLabel: "允许入库数",
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 14,
          status: true,
          fixed: false
        }
      ],
      columnArray2: [
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table2OrderId',
          tableId: "670Table2",
          tableName: "采购物料标签清单",
          columnProp: "orderId",
          headerAlign: "center",
          align: "right",
          columnLabel: "No .",
          columnWidth: '50',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table2RollNo',
          tableId: "670Table2",
          tableName: "采购物料标签清单",
          columnProp: "rollNo",
          headerAlign: "center",
          align: "left",
          columnLabel: "标签条码",
          columnWidth: '150',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 1,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table2RollQty',
          tableId: "670Table2",
          tableName: "采购物料标签清单",
          columnProp: "rollQty",
          headerAlign: "center",
          align: "right",
          columnLabel: "标签数量",
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 2,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table2HardtagInFlag',
          tableId: "670Table2",
          tableName: "采购物料标签清单",
          columnProp: "hardtagInFlag",
          headerAlign: "center",
          align: "center",
          columnLabel: "标签状态",
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 3,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table2PrintFla',
          tableId: "670Table2",
          tableName: "采购物料标签清单",
          columnProp: "printFlag",
          headerAlign: "center",
          align: "right",
          columnLabel: "打印次数",
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 4,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table2BatchNo',
          tableId: "670Table2",
          tableName: "采购物料标签清单",
          columnProp: "batchNo",
          headerAlign: "center",
          align: "center",
          columnLabel: "批次号",
          columnWidth: '120',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 6,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table2ProductionDate',
          tableId: "670Table2",
          tableName: "采购物料标签清单",
          columnProp: "productionDate",
          headerAlign: "center",
          align: "center",
          columnLabel: "生产日期",
          columnWidth: '120',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 6,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table2ExpirationDate',
          tableId: "670Table2",
          tableName: "采购物料标签清单",
          columnProp: "expirationDate",
          headerAlign: "center",
          align: "center",
          columnLabel: "失效日期",
          columnWidth: '120',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 6,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table2ExpirationWarningDate',
          tableId: "670Table2",
          tableName: "采购物料标签清单",
          columnProp: "expirationWarningDate",
          headerAlign: "center",
          align: "center",
          columnLabel: "失效预警日期",
          columnWidth: '120',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 6,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: '670Table2OCreatedBy',
          tableId: "670Table2",
          tableName: "采购物料标签清单",
          columnProp: "createdBy",
          headerAlign: "center",
          align: "left",
          columnLabel: "操作员",
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 7,
          status: true,
          fixed: false
        }
      ],
      exportName: '采购检验合格单'+this.dayjs().format('YYYYMMDDHHmmss'),
      exportName2: '采购物料标签清单'+this.dayjs().format('YYYYMMDDHHmmss'),
    }
  },
  /*组件*/
  components: {
    excel,
    qcUpload,
  },

  mounted() {
    this.$nextTick(() => {
      this.height = ( window.innerHeight - 220)/2;
    })
  },
  methods: {

    getMainData(){
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      getInboundQcResultData(this.searchData).then(({data}) => {
        if (data.code === 0) {
          this.mainDataList = data.page.list
          this.pageIndex = data.page.currPage
          this.pageSize = data.page.pageSize
          this.totalPage = data.page.totalCount
          //判断是否全部存在数据
          if (this.totalPage > 0) {
            //设置选中行
            this.$refs.mainTable.setCurrentRow(this.mainDataList[0])
            this.changeData(this.mainDataList[0])

          }else {
            this.changeData(null)
          }
        }
        this.dataListLoading = false
      })
    },

    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getMainData()
    },

    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getMainData()
    },

    async exportExcel() {
      this.searchData.limit = -1
      this.searchData.page = 1
      excel.exportTable({
        url: "/wmsPrint/getInboundQcResultData",
        columnMapping:  this.columnArray1,//可以直接用table，不需要的列就剔除
        mergeSetting: [],//需要合并的列
        params: this.searchData,
        fileName: this.exportName+".xlsx",
        rowFetcher: res => res.data,
        columnFormatter: [],
        dropColumns: [],//需要剔除的列，例如dropColumns: ["netWeight"]，即剔除净重列
      });
    },
    changeData(row){
      this.currentRow=JSON.parse(JSON.stringify(row))
      // let inData={
      //   site:this.currentRow.site,
      //   buNo:this.currentRow.buNo,
      //   inspectionNo:this.currentRow.orderNo,
      // }
      // getPoOrderRollNoOutData(inData).then(({data}) => {
      //   //区分请求成功和失败的状况
      //   if (data && data.code == 0) {
      //     this.table2List = data.rows
      //
      //   } else {
      //     this.table2List = [];
      //   }
      // });
      this.getDetailTableList();
    },
    getDetailTableList () {
      let inData={
        site:this.currentRow.site,
        buNo:this.currentRow.buNo,
        inspectionNo:this.currentRow.orderNo,
      }
      getPoOrderRollNoOutData(inData).then(({data}) => {
        //区分请求成功和失败的状况
        if (data && data.code == 0) {
          this.table2List = data.rows

        } else {
          this.table2List = [];
        }
      });
    },
    handleSelectionChange(val){
      this.selectionDataList = val
      console.log(this.selectionDataList)
    },
    addOrUpdateHandle(row) {
      getInboundQcResultOtherData(row).then(({data}) => {
        //区分请求成功和失败的状况
        if (data && data.code=== 0) {
          let outData = data.row
          console.log(data.row);
          this.addModelData={
            site:row.site,
            buNo:row.buNo,
            partNo: row.partNo,
            partDesc: row.partDesc,
            poOrderNo: row.poOrderNo,
            poItemNo: row.poItemNo,
            orderNo: row.orderNo,
            orderQty: row.orderQty,
            supplierId: row.supplierId,
            supplierName: row.supplierName,
            orderRollCount: row.rollCount,
            batchQualifiedQty: row.batchQualifiedQty,
            remainingIssuableQty: outData.remainingIssuableQty,
            exceedInRatio: outData.exceedInRatio,
            expirationFlag: outData.expirationFlag? outData.expirationFlag:'N',
            expirationDay:outData.expirationDay?Number(outData.expirationDay):0,
            nowRollQty: row.rollQty,
            productionDate: this.dayjs().format("YYYY-MM-DD"),
            batchNo: '',
            rollCount: '1',
            rollQty: row.rollQty,
            expirationWarningDay: outData.expirationWarningDay,
            tailRollQty: '0'
          }
          if(this.addModelData.exceedInRatio==""||this.addModelData.exceedInRatio==null){
            this.addModelData.exceedInRatio=0
          }

        }
      });


      this.addModelFlag = true;

    },

    submitData() {
      // 验证必填字段


      if (!this.addModelData.productionDate||this.addModelData.productionDate==='') {
        this.$message.error('请选择生产日期');
        return;
      }
      if (!this.addModelData.rollCount||this.addModelData.rollCount==='') {
        this.$message.error('请输入发行张数');
        return;
      }
      if (!this.addModelData.rollQty||this.addModelData.rollQty==='') {
        this.$message.error('请输入每张数量');
        return;
      }
      if ( this.addModelData.nowRollQty>Number(this.addModelData.remainingIssuableQty)+((Number(this.addModelData.exceedInRatio)*Number(this.addModelData.orderQty))/100)) {
        this.$message.error('本次发行数量大于剩余可发行数量和超入数量');
        return;
      }

      // 这里可以添加提交逻辑
      submitPoOrderRollNo(this.addModelData).then(({data}) => {
        if (data && data.code === 0) {
          this.$message.success( '操作成功')
          this.changeData(this.currentRow);
          this.addModelFlag = false;
        }else {

          this.$message.error(data.msg);
        }
      })
    },
    submitDataNoClose() {
      // 验证必填字段


      if (!this.addModelData.productionDate||this.addModelData.productionDate==='') {
        this.$message.error('请选择生产日期');
        return;
      }
      if (!this.addModelData.rollCount||this.addModelData.rollCount==='') {
        this.$message.error('请输入发行张数');
        return;
      }
      if (!this.addModelData.rollQty||this.addModelData.rollQty==='') {
        this.$message.error('请输入每张数量');
        return;
      }
      if ( this.addModelData.nowRollQty>Number(this.addModelData.remainingIssuableQty)+((Number(this.addModelData.exceedInRatio)*Number(this.addModelData.orderQty))/100)) {
        this.$message.error('本次发行数量大于剩余可发行数量和超入数量');
        return;
      }

      // 这里可以添加提交逻辑
      submitPoOrderRollNo(this.addModelData).then(({data}) => {
        if (data && data.code === 0) {
          this.$message.success( '操作成功')
          this.changeData(this.currentRow);
          let row=this.currentRow;
          getInboundQcResultOtherData(row).then(({data}) => {
            //区分请求成功和失败的状况
            if (data && data.code=== 0) {
              let outData = data.row
              console.log(data.row);
              this.addModelData.remainingIssuableQty= outData.remainingIssuableQty
            }
          });
        }else {

          this.$message.error(data.msg);
        }
      })
    },
    getNowRollQty(){
      if(this.addModelData.tailRollQty==''||this.addModelData.tailRollQty==null||this.addModelData.tailRollQty<0){
        this.addModelData.tailRollQty=0
      }
      if(this.addModelData.tailRollQty==0){
        this.addModelData.nowRollQty=Number(this.addModelData.rollQty)*Number(this.addModelData.rollCount)
      }else {
        this.addModelData.nowRollQty=Number(this.addModelData.rollQty)*(Number(this.addModelData.rollCount)-1)+Number(this.addModelData.tailRollQty)

      }


    },
    handleInput(value) {
      // 1. 只保留数字
      value = value.replace(/\D/g, '')
      // 2. 去除前导零（0, 00, 0123 → 123）
      value = value.replace(/^0+/, '')
      // 3. 更新数据（触发 Vue 响应式）
      this.addModelData.rollCount = value
    },
    printLabels(){
      if(this.selectionDataList.length===0){
        this.$message.error('未选择标签！');
        return false;
      }
      getPoPartLabelData(this.selectionDataList).then(({data}) => {
        if (data && data.code === 0) {
          console.log(data.rows)
          poPartLabelPrint(data.rows)
          this.getDetailTableList();
        }else {

          this.$message.error(data.msg);
        }

      })

    },
    deleteLabels(){
      if(this.selectionDataList.length===0){
        this.$message.error('未选择标签！');
        return false;
      }
      for (let i = 0; i <this.selectionDataList.length ; i++) {
        if(this.selectionDataList[i].hardtagInFlag!=='未入库'){
          this.$message.error('存在不是未入库状态的标签无法删除！');
          return false;
        }
      }
      deletePoPartLabelData(this.selectionDataList).then(({data}) => {
        if (data && data.code === 0) {
          this.getDetailTableList();
          this.$message.success('删除成功！');

        }else {

          this.$message.error(data.msg);
        }

      })

    },
    openUpload(){
      if(!this.currentRow || !this.currentRow.site){
        this.$message.error('请先选择上方的检验合格单！');
        return false;
      }
      let pageData = {
        flag: 'poPartPrint',
        createBy: this.$store.state.user.name,
        site: this.currentRow.site,
        buNo: this.currentRow.buNo,
        orderNo: this.currentRow.orderNo,
        partNo: this.currentRow.partNo,
        partDesc: this.currentRow.partDesc,
        poOrderNo: this.currentRow.poOrderNo,
        poItemNo: this.currentRow.poItemNo,
        supplierId: this.currentRow.supplierId,
        supplierName: this.currentRow.supplierName,
        orderQty: this.currentRow.orderQty,
        inspectionNo: this.currentRow.orderNo
      }
      this.$refs.qcUpload.init(pageData);
    },
  },
  created() {
    //查询报表的类型
    this.getMainData();
  },


}
</script>

<!--当前页面的标签样式-->
<style scoped lang="scss">

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

/deep/ .el-form-item__label {
  font-weight: 500;
}

/deep/ .el-form-item.is-required .el-form-item__label:before {
  content: '*';
  color: #f56c6c;
  margin-right: 4px;
}

/deep/ .dialog-footer {
  padding: 20px 0 0 0;
  text-align: center;
}

/deep/ .el-dialog__body {
  padding: 20px;
}

/deep/ .el-input.is-disabled .el-input__inner {
  background-color: #f5f7fa;
  border-color: #e4e7ed;
  color: #c0c4cc;
}



</style>
