<template>
<div class="mod-config">
  <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;">
    <el-form-item :label="'工厂编号：'">
      <el-input v-model="dataForm.site" readonly style="width: 120px;" ></el-input>
    </el-form-item>
    <el-form-item :label="'采购订单号：'">
      <el-input v-model="dataForm.orderNo"  style="width: 120px;" ></el-input>
    </el-form-item>
    <el-form-item >
      <span slot="label" style="" @click="getBaseList(3,0)"><a herf="#">供应商编码：</a></span>
      <el-input v-model="dataForm.supplierID" @change="getSupplier()" style="width: 120px;" onblur="this.value=this.value.toUpperCase()"></el-input>
    </el-form-item>
    <el-form-item :label="'供应商名称：'">
      <el-input v-model="dataForm.supplierName" readonly style="width: 255px;"></el-input>
      <el-button @click="saveCRoll()" type="primary" style="width: 108px;margin-left: 20px;">创建分卷</el-button>
    </el-form-item>
  </el-form>
  <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;">
    <el-form-item >
      <span slot="label" style="" @click="getBaseList(5,2)"><a herf="#">物料编码：</a></span>
      <el-input v-model="dataForm.partNo" @change="getPartNo2()" style="width: 120px;" ></el-input>
    </el-form-item>
    <el-form-item :label="'物料名称：'">
      <el-input v-model="dataForm.partDescription" readonly style="width: 195px;"></el-input>
    </el-form-item>
    <el-form-item :label="'规格型号：'">
      <el-input v-model="dataForm.spec" readonly style="width: 180px;"></el-input>
    </el-form-item>
<!--    <el-form-item style="margin-top: 30px">-->
<!--      <el-button @click="modelFlag=false" type="primary" style="width: 80px;margin-left: 95px;">关闭</el-button>-->
<!--    </el-form-item>-->
    <el-form-item :label="'接收日期：'">
      <el-date-picker
        style="width: 120px"
        v-model="dataForm.receive"
        value-format="yyyy-MM-dd"
        placeholder="选择日期">
      </el-date-picker>
      <el-button @click="getSaveModel()" type="primary" style="margin-left: 20px;">供应商批号录入</el-button>
    </el-form-item>
  </el-form>
  <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;">
    <el-form-item :label="'供应商批次号：'" style="">
      <el-input v-model="dataForm.suppRollNo" style="width: 120px;"></el-input>
    </el-form-item>
    <el-form-item :label="'送货单号：'" style="">
      <el-input v-model="dataForm.suppDeliveryNote" style="width: 120px;"></el-input>
    </el-form-item>
    <el-form-item :label="'每卷数量：'">
      <el-input v-model="dataForm.rollQty" type="number" style="width: 120px;"></el-input>
    </el-form-item>
    <el-form-item :label="'卷数：'">
      <el-input v-model="dataForm.rollNumber" type="number" style="width: 120px;"></el-input>
    </el-form-item>
    <el-form-item :label="' '">
      <el-button @click="insertData()" type="primary">插入</el-button>
      <el-checkbox style="margin-left: 60px" v-model="dataForm.checked">自动打印标签</el-checkbox>
    </el-form-item>
  </el-form>
  <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;">
    <el-form-item >
      <span slot="label" style="" @click="getBaseList(92,0)"><a herf="#">客户编号：</a></span>
      <el-input v-model="dataForm.customerID" style="width: 120px;" @change="getReferenceData()"></el-input>
    </el-form-item>
    <el-form-item >
      <span slot="label" style="" @click="getBaseList(5,1)"><a herf="#">产品编码：</a></span>
      <el-input v-model="dataForm.fGPartNo" style="width: 120px;" @change="getReferenceData()"></el-input>
    </el-form-item>
    <el-form-item :label="'参照名称：'">
      <el-input v-model="dataForm.referencePartDesc" readonly style="width: 200px;"></el-input>
    </el-form-item>
    <el-form-item :label="'供应商编码：'">
      <el-input v-model="dataForm.referenceSupplierID" readonly style="width: 100px;" ></el-input>
    </el-form-item>
    <el-form-item :label="'供应商名称：'">
      <el-input v-model="dataForm.referenceSupplierName" readonly style="width: 200px;"></el-input>
    </el-form-item>
  </el-form>
  <el-tabs v-model="activeName" style="font-size: 12px"  class="customer-tab" type="border-card">
    <el-tab-pane label="待分卷" name="first">
      <div style="width: 1000px;margin-top: 0px;">
        <div style="width: 100%;float: left">
          <el-table
            :height="height"
            :data="dataList1"
            border
            :vertical-align="'middle'"
            style="width: 100%;">
            <el-table-column
              v-for="(item,index) in columnList1" :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"
              :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-column
              fixed="right"
              header-align="center"
              align="center"
              width="150"
              :label="'操作'">
              <template slot-scope="scope">
                <a type="text" size="small" @click="remove(scope.row)" herf="#">删除卷</a>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;">
          <span style="margin-left: 5px;">合计：卷数</span>
          <el-input v-model="sum1" style="width: 50px;" readonly></el-input>
          <span>总数量</span>
          <el-input v-model="sum2" style="width: 80px;" readonly></el-input>
        </el-form>
      </div>
    </el-tab-pane>
    <el-tab-pane label="已分卷" name="second">
      <div style="width: 1000px;margin-top: 0px">
        <el-table
          :height="height"
          :data="dataList3"
          border
          :vertical-align="'middle'"
          style="width: 100%;">
          <el-table-column
            v-for="(item,index) in columnList3" :key="index"
            :prop="item.columnProp"
            :header-align="item.headerAlign"
            :align="item.align"
            :vertical-align="'middle'"
            :min-width="item.columnWidth"
            :label="item.columnLabel">
          </el-table-column>
        </el-table>
        <el-form :inline="true" label-position="top" label-width="100px">

            <span style="margin-left: 5px">合计：卷数</span>
            <el-input v-model="sum3" style="width: 50px;" readonly></el-input>
            <span>总卷数量</span>
            <el-input v-model="sum4" style="width: 80px;" readonly></el-input>

        </el-form>
      </div>
    </el-tab-pane>
  </el-tabs>
  <el-footer style="height:10px;margin-top: 0px;text-align:center">
  </el-footer>
  <el-dialog width="430px" :title="'供应商批号录入'" :close-on-click-modal="false" v-drag :visible.sync="modelFlag2">
    <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;">
      <el-form-item :label="'工厂编码：'">
        <el-input v-model="saveData.site" style="width: 80px"></el-input>
      </el-form-item>
      <el-form-item :label="'卷号：'">
        <el-input v-model="saveData.rollNo" style="width: 150px"></el-input>
        <el-button @click="goSaveSuppRollNo()" type="primary" style="margin-left: 10px;">保存</el-button>
        <el-button @click="modelFlag2=false" type="primary" style="margin-left: 10px;">关闭</el-button>
      </el-form-item>
    </el-form>
    <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;">
      <el-form-item :label="'供应商批号：'">
        <el-input v-model="saveData.suppRollNo" style="width: 369px"></el-input>
      </el-form-item>
    </el-form>
    <el-footer style="height:10px;margin-top: 20px;text-align:center">
    </el-footer>
  </el-dialog>

  <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>
</div>
</template>

<script>
  import {
    getPartNoDetail,
    checkCustomerID,
    getSupplierDetail,
  } from "@/api/base/site.js"
  /*打印标签专用的js*/
  import {
    printMaterialLabel,
  } from "@/views/modules/yieldReport/print_roll_label.js"

  import {
    searchSAPPurchaseOrder,
    searchCRollInfoDetail,
    saveCRollData,
    saveSuppRollNo,
    doSaveSuppRollNo,
    getReferenceData
  } from "@/api/purchasingManagement/materialSplit.js"
  import Chooselist from '@/views/modules/common/Chooselist'
  export default {
    name: "BeginMaterialSlittedSet",
    components: {
      Chooselist
    },
    data() {
      return {
        height: 200,
        modelFlag: false,
        modelFlag2: false,
        modelInputFlag: true,
        selectList: [],
        activeName: 'first',
        buttons: {
          search: '查询',
        },
        saveData: {
          site:'',
          rollNo:'',
          suppRollNo:''
        },
        dataForm: {
          site: this.$store.state.user.site,
          orderNo: '',
          orderItemNo: '',
          supplierID: '',
          supplierName: '',
          partNo: '',
          partDescription: '',
          spec: '',
          receive: new Date(),
          suppDeliveryNote: '*',
          rollQty: '',
          rollNumber: '',
          customerID: '全部',
          fGPartNo: '全部',
          referencePartDesc: '',
          checked: false,
          referenceSupplierID:'',
          referenceSupplierName:'',
          suppRollNo: ''
        },
        sum1: 0,
        sum2: 0,
        sum3: 0,
        sum4: 0,
        dataList: [],
        dataList3: [],
        dataList1: [],
        dataListLoading: false,
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034TableOrderNo',
            tableId: "6034Table",
            tableName: "查询SAP采购订单表",
            columnProp: "orderNo",
            headerAlign: "center",
            align: "left",
            columnLabel: "采购订单号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034TableOrderDate',
            tableId: "6034Table",
            tableName: "查询SAP采购订单表",
            columnProp: "orderDate",
            headerAlign: "center",
            align: "left",
            columnLabel: "订单日期",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034TablePlanReceiptDate',
            tableId: "6034Table",
            tableName: "查询SAP采购订单表",
            columnProp: "planReceiptDate",
            headerAlign: "center",
            align: "left",
            columnLabel: "要求交货日期",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034TableSupplierID',
            tableId: "6034Table",
            tableName: "查询SAP采购订单表",
            columnProp: "supplierID",
            headerAlign: "center",
            align: "left",
            columnLabel: "供应商编码",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034TableStatus',
            tableId: "6034Table",
            tableName: "查询SAP采购订单表",
            columnProp: "status",
            headerAlign: "center",
            align: "left",
            columnLabel: "订单状态",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 70
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034TableSupplierName',
            tableId: "6034Table",
            tableName: "查询SAP采购订单表",
            columnProp: "supplierName",
            headerAlign: "center",
            align: "left",
            columnLabel: "供应商名称",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 300
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034TableOrderItemNo',
            tableId: "6034Table",
            tableName: "查询SAP采购订单表",
            columnProp: "orderItemNo",
            headerAlign: "center",
            align: "left",
            columnLabel: "订单序号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 70
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034TablePartNo',
            tableId: "6034Table",
            tableName: "查询SAP采购订单表",
            columnProp: "partNo",
            headerAlign: "center",
            align: "left",
            columnLabel: "物料编码",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 160
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034TablePartDescription',
            tableId: "6034Table",
            tableName: "查询SAP采购订单表",
            columnProp: "partDescription",
            headerAlign: "center",
            align: "left",
            columnLabel: "物料名称",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 300
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034TableQuantity',
            tableId: "6034Table",
            tableName: "查询SAP采购订单表",
            columnProp: "quantity",
            headerAlign: "center",
            align: "right",
            columnLabel: "订单数量",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034TableCancelledFlag',
            tableId: "6034Table",
            tableName: "查询SAP采购订单表",
            columnProp: "cancelledFlag",
            headerAlign: "center",
            align: "left",
            columnLabel: "是否取消",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 70
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034TableSAPOrderNo',
            tableId: "6034Table",
            tableName: "查询SAP采购订单表",
            columnProp: "sAPOrderNo",
            headerAlign: "center",
            align: "left",
            columnLabel: "SAP订单标识号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034TableSite',
            tableId: "6034Table",
            tableName: "查询SAP采购订单表",
            columnProp: "site",
            headerAlign: "center",
            align: "left",
            columnLabel: "工厂编号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 70
          }
        ],
        columnList1: [
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034Table1Number',
            tableId: "6034Table1",
            tableName: "查询SAP采购订单待分卷左表",
            columnProp: "number",
            headerAlign: "center",
            align: "right",
            columnLabel: "次序号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034Table1RollQty',
            tableId: "6034Table1",
            tableName: "查询SAP采购订单待分卷左表",
            columnProp: "rollQty",
            headerAlign: "center",
            align: "right",
            columnLabel: "每卷数量",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 250
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034Table1RollNumber',
            tableId: "6034Table1",
            tableName: "查询SAP采购订单待分卷左表",
            columnProp: "rollNumber",
            headerAlign: "center",
            align: "left",
            columnLabel: "卷数",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 250
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034Table1ALLRollQty',
            tableId: "6034Table1",
            tableName: "查询SAP采购订单待分卷左表",
            columnProp: "allRollQty",
            headerAlign: "center",
            align: "left",
            columnLabel: "总数量",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 249
          }
        ],
        columnList3: [
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034Table3RollNo',
            tableId: "6034Table",
            tableName: "查询SAP采购订单已分卷表",
            columnProp: "rollNo",
            headerAlign: "center",
            align: "left",
            columnLabel: "卷号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034Table3RollQty',
            tableId: "6034Table",
            tableName: "查询SAP采购订单已分卷表",
            columnProp: "rollQty",
            headerAlign: "center",
            align: "right",
            columnLabel: "卷数量",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 60
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034Table3SuppDeliveryNote',
            tableId: "6034Table",
            tableName: "查询SAP采购订单已分卷表",
            columnProp: "suppDeliveryNote",
            headerAlign: "center",
            align: "left",
            columnLabel: "供应商送货单号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034Table3RollDate',
            tableId: "6034Table",
            tableName: "查询SAP采购订单已分卷表",
            columnProp: "rollDate",
            headerAlign: "center",
            align: "left",
            columnLabel: "入库日期",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034Table3CreatedDate',
            tableId: "6034Table",
            tableName: "查询SAP采购订单已分卷表",
            columnProp: "createdDate",
            headerAlign: "center",
            align: "left",
            columnLabel: "分卷日期",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034Table3CreatedBy',
            tableId: "6034Table",
            tableName: "查询SAP采购订单已分卷表",
            columnProp: "createdBy",
            headerAlign: "center",
            align: "left",
            columnLabel: "分卷人",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 60
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034Table3SuppRollNoFlag',
            tableId: "6034Table",
            tableName: "查询SAP采购订单已分卷表",
            columnProp: "suppRollNoFlag",
            headerAlign: "center",
            align: "left",
            columnLabel: "已录入供应商批号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 6034,
            serialNumber: '6034Table3SuppRollNo',
            tableId: "6034Table",
            tableName: "查询SAP采购订单已分卷表",
            columnProp: "suppRollNo",
            headerAlign: "center",
            align: "left",
            columnLabel: "供应商批号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 300
          }
        ],
        tagNo:'',
        tagNo2:'',
      }
    },
    watch: {
      dataForm: {
        deep: true,
        handler: function (newV, oldV) {
          this.dataForm.orderNo = this.dataForm.orderNo.toUpperCase()
          this.dataForm.supplierID = this.dataForm.supplierID.toUpperCase()
          this.dataForm.fGPartNo = this.dataForm.fGPartNo.toUpperCase()
          this.dataForm.customerID = this.dataForm.customerID.toUpperCase()
          this.dataForm.partNo = this.dataForm.partNo.toUpperCase()
        }
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.height = window.innerHeight - 330;
      })
    },
    methods: {
      getBaseData(val){
        if (this.tagNo === 92){
          this.dataForm.customerID = val.ConfigurationTemplateID
          this.getReferenceData()
        }
        if (this.tagNo === 5){
          if(this.tagNo2===1){
            this.dataForm.fGPartNo = val.PartNo
            this.getReferenceData();
            // this.getFGPartNo();
          }else {
            this.dataForm.partNo = val.PartNo
            this.getPartNo2()
          }
        }
        if (this.tagNo === 3){
          this.dataForm.supplierID = val.SupplierID
          this.dataForm.supplierName=val.SupplierName
        }
      },
      // 获取基础数据列表
      getBaseList(val1,val2){
        this.tagNo = val1
        this.$nextTick(() => {
          let strVal = "";
          if (val1 === 92){
            strVal = this.dataForm.customerID
          }
          if (val1 === 5){
            if(val2 === 1){
              strVal = this.dataForm.fGPartNo
              this.tagNo2=1;
            }else {
              strVal = this.dataForm.partNo
              this.tagNo2=2;
            }
          }
          if (val1 === 3){
            strVal = this.dataForm.supplierID
          }
          this.$refs.baseList.init(val1,strVal)
        })
      },
      insertData() {
        if (this.dataForm.orderNo == '' || this.dataForm.orderNo == null) {
          this.$alert("请输入采购订单号！", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        if (this.dataForm.supplierID == '' || this.dataForm.supplierID == null) {
          this.$alert("请输入供应商编码！", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        if (this.dataForm.partNo == '' || this.dataForm.partNo == null) {
          this.$alert("请输入材料编码！", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        if (this.dataForm.suppDeliveryNote == '' || this.dataForm.suppDeliveryNote == null) {
          this.$alert("请输入送货单号！", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        if (this.dataForm.rollQty == '' || this.dataForm.rollQty == null || this.dataForm.rollQty <= 0) {
          this.$alert("请输入正确的每卷数量！", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        if (this.dataForm.rollNumber == '' || this.dataForm.rollQty == null || this.dataForm.rollNumber <= 0) {
          this.$alert("请输入正确的卷数！", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        let newDate = {
          number: this.dataList1.length + 1,
          allRollQty: this.dataForm.rollQty * this.dataForm.rollNumber,
          site: this.dataForm.site,
          rollQty: this.dataForm.rollQty,
          rollNumber: this.dataForm.rollNumber,
          partNo: this.dataForm.partNo,
          supplierID: this.dataForm.supplierID,
          orderRef1: this.dataForm.orderNo,
          orderRef2: this.dataForm.orderNo,
          orderRef3: 0,
          orderRef4: 'B',
          suppDeliveryNote: this.dataForm.suppDeliveryNote,
          rollDate: this.dataForm.receive,
          createdBy: this.$store.state.user.name,
          statusDb: 'I',
          status: '已入库',
          suppRollNoFlag: 'N',
          sourceType: '期初入库',
          rolltype: '合格卷',
          rolltypeDb: 0,
          parttypeFlag: 'R',
          customerID: this.dataForm.customerID,
          fGPartNo: this.dataForm.fGPartNo,
          refPartDesc:this.dataForm.referencePartDesc,
          refSupplierID:this.dataForm.referenceSupplierID,

        }
        this.dataList1.push(newDate)
        this.sum1 = Number(this.sum1)+  Number(newDate.rollNumber);
        this.sum2 = Number(this.sum2)+ Number(newDate.allRollQty);
      },
      remove(row){
        this.$confirm('确认删除记录吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.sum1 = Number(this.sum1) - Number(row.rollNumber);
          this.sum2 = Number(this.sum2) - Number(row.allRollQty);
          this.dataList1 = this.dataList1.filter(item => item.number!=row.number)
        })

      },
      saveCRoll() {
        if(this.dataForm.checked==true){
          this.$alert('打印机连接失败！', '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        let inData = {
          site: this.dataForm.site,
          partNo: this.dataForm.partNo
        }
        getPartNoDetail(inData).then(({data}) => {
          if (data.total > 0) {
            this.dataForm.partDescription=data.rows[0].partDescription;
            //this.dataForm = JSON.parse(JSON.stringify(this.dataForm));
            let inData2={
              site : this.dataForm.site,
              supplierID : this.dataForm.supplierID
            }
            getSupplierDetail(inData2).then(({data}) => {
              let outList = data.rows
              if (outList.length>0){
                this.dataForm.supplierName=outList[0].supplierName;
                // this.$set(this.dataForm,'supplierName',outList[0].supplierName)
                let inData3 = {
                  site: this.dataForm.site,
                  partNo: this.dataForm.fGPartNo
                }
                getPartNoDetail(inData3).then(({data}) => {
                  if (data.total > 0||this.dataForm.fGPartNo=='无') {
                    let inData4 = {
                      site: this.dataForm.site,
                      configurationTemplateID: this.dataForm.customerID,
                    }
                    checkCustomerID(inData4).then(({data}) => {
                      if (data.total > 0) {
                        if (this.dataList1.length == 0&&this.dataForm.customerID!='无') {
                          this.$alert("没有待分卷信息！", '错误', {
                            confirmButtonText: '确定'
                          })
                          return false;
                        }else {
                          this.doSaveCRoll()
                        }
                      } else {
                        this.dataForm.customerID = '';
                        this.dataForm = JSON.parse(JSON.stringify(this.dataForm));
                        this.$alert('该客户编号不存在或不可用', '错误', {
                          confirmButtonText: '确定'
                        })
                        return false;
                      }
                    })
                  } else {
                    this.dataForm.fGPartNo = '';
                    this.dataForm = JSON.parse(JSON.stringify(this.dataForm));
                    this.$alert('该物料编码不存在或不可用', '错误', {
                      confirmButtonText: '确定'
                    })
                    return false;
                  }
                })
              }
              else {
                this.dataForm.supplierName='';
                this.dataForm.supplierID='';
                this.$alert('该供应商不存在或不可用', '错误', {
                  confirmButtonText: '确定'
                })
                return false;
              }
            })
          }
         else {
            this.dataForm.partNo = '';
            this.$alert('该物料编码不存在或不可用', '错误', {
              confirmButtonText: '确定'
            })
            return false;
         }
        })



      },
      doSaveCRoll() {
        let dto = this.dataList1.map(item => {
            item.suppRollNo =  this.dataForm.suppRollNo
            item.suppRollNoFlag = 'Y'
            return item;
          })
        saveCRollData(dto).then(({data}) => {
          if (data && data.code == 200) {
            this.dataList1 = [];
            this.sum1 = 0;
            this.sum2 = 0;
            let inData = {
              site: this.dataForm.site,
              orderRef1: this.dataForm.orderNo,
              orderRef3: 0,
            }
            searchCRollInfoDetail(inData).then(({data}) => {
              this.dataList3 = data.rows
              for (let i = 0; i < data.total; i++) {
                this.sum4 += Number(this.dataList3[i].rollQty);
              }
              this.sum3 = data.total;
            })
            this.$message.success('操作成功')
            //打印材料卷标签
            let printList = data.obj;
            printMaterialLabel(printList);
            //调用打印的方法
            /*for(let i = 0; i < printList.length; i++){
              printMaterialLabel(printList[i]);
            }*/
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
          this.dataForm={}
          this.dataForm.site=this.$store.state.user.site
          this.dataForm.receive=new Date();
          this.dataForm.fGPartNo='无';
          this.dataForm.customerID='无';
          this.dataForm.suppDeliveryNote='*';
          this.dataForm=JSON.parse(JSON.stringify(this.dataForm))
        })
      },
      getPartNo() {
        let inData = {
          site: this.dataForm.site,
          partNo: this.dataForm.fGPartNo
        }
        getPartNoDetail(inData).then(({data}) => {
          if (data.total > 0) {
          } else {
            this.dataForm.fGPartNo = '';
            this.dataForm = JSON.parse(JSON.stringify(this.dataForm));
            this.$alert('该物料编码不存在或不可用', '错误', {
              confirmButtonText: '确定'
            })
            return false;
          }
        })
      },
      getPartNo2() {
        let inData = {
          site: this.dataForm.site,
          partNo: this.dataForm.partNo
        }
        getPartNoDetail(inData).then(({data}) => {
          if (data.total > 0) {
            this.dataForm.partDescription=data.rows[0].partDescription;
            this.dataForm.spec=data.rows[0].spec;
            //this.dataForm = JSON.parse(JSON.stringify(this.dataForm));
          }
          // else {
          //   this.dataForm.partNo = '';
          //   this.$alert('该物料编码不存在', '错误', {
          //     confirmButtonText: '确定'
          //   })
          // }
        })
        this.getReferenceData();
      },
      getCustomerID() {
        let inData = {
          site: this.dataForm.site,
          configurationTemplateID: this.dataForm.customerID,
        }
        checkCustomerID(inData).then(({data}) => {
          if (data.total > 0) {
          } else {
            this.dataForm.customerID = '';
            this.dataForm = JSON.parse(JSON.stringify(this.dataForm));
            this.$alert('该客户编号不存在', '错误', {
              confirmButtonText: '确定'
            })
            return false;
          }
        })
      },
      getSupplier(){
        let inData={
          site : this.dataForm.site,
          supplierID : this.dataForm.supplierID
        }
        getSupplierDetail(inData).then(({data}) => {
          let outList = data.rows
          if (outList.length>0){
             this.dataForm.supplierName=outList[0].supplierName;
           // this.$set(this.dataForm,'supplierName',outList[0].supplierName)
          }
          // else {
          //   this.dataForm.supplierName='';
          //   this.dataForm.supplierID='';
          //   this.$alert('该供应商不存在', '错误', {
          //     confirmButtonText: '确定'
          //   })
          // }
        })
      },
      //供应商批号录入
      getSaveModel() {
        this.saveData = {
          site:this.$store.state.user.site,
          rollNo:'',
          suppRollNo:''
        };
        this.modelFlag2 = true;
      },
      goSaveSuppRollNo() {
        if (this.saveData.site == '' || this.saveData.site == null) {
          this.$alert("请输入工厂编码！", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        if (this.saveData.rollNo == '' || this.saveData.rollNo == null) {
          this.$alert("请输入卷号！", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        if (this.saveData.suppRollNo == '' || this.saveData.suppRollNo == null) {
          this.$alert("请输入供应商批号！", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        saveSuppRollNo(this.saveData).then(({data}) => {
            if (data.rows == null) {
              this.$alert("该卷号不存在，请输入！", '错误', {
                confirmButtonText: '确定'
              })
              return false;
            } else {
              if (data.rows.suppRollNoFlag == 'Y') {
                this.$confirm(`该卷已经录入供应商批号,确认要重新录入吗？`, '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'

                }).then(() => {
                  doSaveSuppRollNo(this.saveData).then(({data}) => {
                    if (data && data.code == 200) {
                      this.modelFlag2 = false
                      this.$message.success( '操作成功')
                    } else {
                      this.$alert(data.msg, '错误', {
                        confirmButtonText: '确定'
                      })
                    }
                  })
                })
              }else{
                doSaveSuppRollNo(this.saveData).then(({data}) => {
                  if (data && data.code == 200) {
                    this.modelFlag2 = false
                    this.$message.success( '操作成功')
                  } else {
                    this.$alert(data.msg, '错误', {
                      confirmButtonText: '确定'
                    })
                  }
                })
              }
            }
          }
        )
      },
      getReferenceData(){
        let inData = {
          site: this.dataForm.site,
          partNo: this.dataForm.partNo,
          partDescription: this.dataForm.partDescription,
          customerID: this.dataForm.customerID,
          fGPartNo: this.dataForm.fGPartNo,
          supplierID: '*',
        }
        getReferenceData(inData).then(({data}) => {
          if (data.success) {
            if (data.rows.length > 0) {
              this.dataForm.referenceSupplierID = data.rows[0].SupplierID;
              this.dataForm.referencePartDesc = data.rows[0].PartDescription;
              this.dataForm.referenceSupplierName = data.rows[0].SupplierDesc;
            }
          }
        })
      },

    },
    created() {

    }
  }
</script>

<style scoped>

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

  }

  /deep/  .el-tabs__item {
    padding: 0 20px;
    height: 30px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    line-height: 30px;
    display: inline-block;
    list-style: none;
    font-size: 12px;
    font-weight: 500;
    color: #303133;
    position: relative;
  }
</style>

