<template>
  <!-- 新增 预装箱单-成衣-->
  <div id="addAdvancePacking">
    <a-drawer
      :title="(editDecide == 'add')?'新增预装箱单-成衣':'编辑预装箱单-成衣'"
      width="89%"
      placement="right"
      :closable="true"
      :visible="visible"
      @close="handleCancel"
    >
      <!-- 主表信息 填写 -->
      <a-card :bordered="true">
        <div class="table-page-search-wrapper">
          <!-- :rules="validatorRules" -->
          <a-form-model layout="inline" ref="form" :model="addAdpacking">
            <a-row :gutter="24">
              <a-col :md="6" :sm="8">
                <a-form-model-item label="单据号" prop="documentNo">
                  {{addAdpacking.documentNo | ellipsis}}
                  <!-- <a-input placeholder="自动生成" v-model="addAdpacking.orderNumber" readOnly></a-input> -->
                </a-form-model-item>
              </a-col>
              <a-col :md="6" :sm="8">
                <a-form-model-item label="订单号" prop="orderNumber">
                  {{addAdpacking.orderNumber | ellipsis}}
                  <!-- <a-input placeholder="自动生成" v-model="addAdpacking.orderNumber" readOnly></a-input> -->
                </a-form-model-item>
              </a-col>
              <a-col :md="6" :sm="8">
                <a-form-model-item label="集装箱代号" prop="containerCode">
                  {{addAdpacking.containerCode | ellipsis}}
                  <!-- <a-input placeholder="请输入集装箱代号" v-model="addAdpacking.containerCode" readOnly></a-input> -->
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="集装箱号" prop="containerNumber">
                  {{addAdpacking.containerNumber | ellipsis}}
                  <!-- <a-input placeholder="请输入集装箱号" v-model="addAdpacking.containerNumber" readOnly></a-input> -->
                </a-form-model-item>
              </a-col>

              <!-- <a-col :md="6" :sm="8">
                <a-form-model-item label="预发货日期" prop="u8Remarks">
                  <j-date placeholder="请选择预发货日期" v-model="addAdpacking.preDeliveryDate" style="width:100%"></j-date>
                </a-form-model-item>
              </a-col> -->
              <a-col :md="6" :sm="8">
                <a-form-model-item label="u8备注" prop="u8Remarks">
                  <a-input placeholder="请输入u8备注" v-model="addAdpacking.u8Remarks"></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :md="6" :sm="8">
                <a-form-model-item label="款号" prop="itemNumber">
                  {{addAdpacking.itemNumber | ellipsis}}
                  <!-- <a-input placeholder="选择子表自动生成" v-model="addAdpacking.itemNumber"></a-input> -->
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="中文品名" prop="productName">
                  {{addAdpacking.productName | ellipsis}}
                  <!-- <a-input placeholder="选择子表自动生成" v-model="addAdpacking.productName"></a-input> -->
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="英文品名" prop="productName">
                  {{addAdpacking.englishProductName | ellipsis}}
                  <!-- <a-input placeholder="选择子表自动生成" v-model="addAdpacking.englishProductName"></a-input> -->
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="尺码范围" prop="sizeRange">
                  {{addAdpacking.sizeRange | ellipsis}}
                  <!-- <a-input placeholder="选择子表自动生成" v-model="addAdpacking.sizeRange" readOnly></a-input> -->
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="客户" prop="customer">
                  {{addAdpacking.customer  | ellipsis }}
                  <!-- <a-input placeholder="选择子表自动生成" v-model="addAdpacking.customer"></a-input> -->
                </a-form-model-item>
              </a-col>

              

              <!-- <a-col :md="6" :sm="8">
                <a-form-model-item label="成衣工厂" prop="garmentFactory">
                  <a-input placeholder="选择子表自动生成" v-model="addAdpacking.garmentFactory"></a-input>
                </a-form-model-item>
              </a-col> -->
              <a-col :md="6" :sm="8">
                <a-form-model-item label="总箱数" prop="totalBoxes">
                  {{addAdpacking.totalBoxes | ellipsis }}
                  <!-- <a-input placeholder="自动生成" v-model="addAdpacking.totalBoxes" readOnly></a-input> -->
                </a-form-model-item>
              </a-col>
              <a-col :md="6" :sm="8">
                <a-form-model-item label="总净重" prop="totalNetWeight">
                  {{addAdpacking.totalNetWeight | ellipsis}}
                  <!-- <a-input placeholder="自动生成" v-model="addAdpacking.totalNetWeight" readOnly></a-input> -->
                </a-form-model-item>
              </a-col>
              <a-col :md="6" :sm="8">
                <a-form-model-item label="总毛重" prop="totalGrossWeight">
                  {{addAdpacking.totalGrossWeight  | ellipsis}}
                  <!-- <a-input placeholder="自动生成" v-model="addAdpacking.totalGrossWeight" readOnly></a-input> -->
                </a-form-model-item>
              </a-col>
              <a-col :md="6" :sm="8">
                <a-form-model-item label="总体积" prop="totalVolume">
                  {{addAdpacking.totalVolume | ellipsis}}
                  <!-- <a-input placeholder="自动生成" v-model="addAdpacking.totalVolume" readOnly></a-input> -->
                </a-form-model-item>
              </a-col>
              <a-col :md="6" :sm="8">
                <a-form-model-item label="总价" prop="totalPrice">
                  {{addAdpacking.totalPrice  | ellipsis}}
                  <!-- <a-input placeholder="自动生成" v-model="addAdpacking.totalPrice" readOnly></a-input> -->
                </a-form-model-item>
              </a-col>
              <a-col :md="6" :sm="8">
                <a-form-model-item label="总件数" prop="totalNumber">
                  {{addAdpacking.total  | ellipsis}}
                  <!-- <a-input placeholder="自动生成" v-model="addAdpacking.total" readOnly></a-input> -->
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-form-model>
        </div>
      </a-card>

      <!-- 参照发运明细 増行-->
      <a-card :bordered="false" style="margin:10px 0 60px 0;">
        <div class="table-operator">
           <a-button type="primary" @click="referShipmentDetails" icon="ordered-list">参照出运明细</a-button>
        </div>
         <a-spin :spinning="confirmLoading">
          <a-form-model ref="formRef" :rules="validatorRules">
            <a-table
              bordered
              :row-key="record => record.id"
              :columns="columns"
              :data-source="addAdpacking.syPreAssembledPackingListItemList"
              :loading="loading"
              :pagination="ipagination"
              :scroll="{ x: 1500,y: 350 }"
              @change="handleTableChange"
            >
             <!-- itemCode -->
             <template slot="itemCode" slot-scope="text, record, index">
                <a-form-model-item prop="itemCode" :rules="rules.itemCode">
                  <a-input style="width:100%" type="text" v-model="record.itemCode"  />
                </a-form-model-item>
              </template>
             <!-- prepackSku  -->
             <template slot="prepackSku" slot-scope="text, record, index">
                <a-form-model-item prop="prepackSku" :rules="rules.prepackSku">
                  <a-input style="width:100%" type="text" v-model="record.prepackSku"  />
                </a-form-model-item>
              </template>
              <!-- 起始箱号 -->
              <template slot="startingBoxNumber" slot-scope="text, record, index">
                <a-form-model-item prop="startingBoxNumber" :rules="rules.startingBoxNumber">
                  <a-input style="width:100%" type="text" v-model="record.startingBoxNumber"  @change="handleValueChange(record)"/>
                </a-form-model-item>
              </template>
              <!-- 结束箱号 -->
              <template slot="endCaseNumber" slot-scope="text, record, index">
                <a-form-model-item prop="endCaseNumber" :rules="rules.endCaseNumber">
                  <a-input style="width:100%" type="text" v-model="record.endCaseNumber"  @change="handleValueChange(record)"/>
                </a-form-model-item>
              </template>
              <!-- 颜色 -->
              <template slot="colour" slot-scope="text, record, index">
                <a-form-model-item prop="colour" :rules="rules.colour">
                  <a-input style="width:100%" type="text" v-model="record.colour"  />
                </a-form-model-item>
              </template>
              <!-- 净重 -->
              <template slot="netWeight" slot-scope="text, record, index">
                <a-form-model-item prop="netWeight" :rules="rules.netWeight">
                  <a-input style="width:100%" type="text" v-model="record.netWeight"  @change="handleValueChange(record)"/>
                </a-form-model-item>
              </template>
              <!-- 毛重 -->
              <template slot="grossWeight" slot-scope="text, record, index">
                <a-form-model-item prop="grossWeight" :rules="rules.grossWeight">
                  <a-input style="width:100%" type="text" v-model="record.grossWeight"  @change="handleValueChange(record)"/>
                </a-form-model-item>
              </template>
              <!-- 外箱长度 -->
              <template slot="outerBoxLength" slot-scope="text, record, index">
                <a-form-model-item prop="outerBoxLength" :rules="rules.outerBoxLength">
                  <a-input style="width:100%" type="text" v-model="record.outerBoxLength"  @change="handleValueChange(record)"/>
                </a-form-model-item>
              </template>
              <!-- 外箱宽度 -->
               <template slot="outerBoxWidth" slot-scope="text, record, index">
                <a-form-model-item prop="outerBoxWidth" :rules="rules.outerBoxWidth">
                  <a-input style="width:100%" type="text" v-model="record.outerBoxWidth" @change="handleValueChange(record)" />
                </a-form-model-item>
              </template>
              <!-- 外箱高度 -->
              <template slot="outerBoxHeight" slot-scope="text, record, index">
                <a-form-model-item prop="outerBoxHeight" :rules="rules.outerBoxHeight">
                  <a-input style="width:100%" type="text" v-model="record.outerBoxHeight" @change="handleValueChange(record)" />
                </a-form-model-item>
              </template>
              <!-- 净净重 -->
              <template slot="netWeightToo" slot-scope="text, record, index">
                <a-form-model-item prop="netWeightToo" :rules="rules.netWeightToo">
                  <a-input style="width:100%" type="text" v-model="record.netWeightToo"  @change="handleValueChange(record)"/>
                </a-form-model-item>
              </template>

              <!-- 尺码字段 -->
             <template v-for="i in inputName" :slot="i" slot-scope="text, record, index">
               <a-form-model-item prop="i" :rules="rules.i" :key="i">
                   <a-input style="width:100%" type="text" v-model="record[i]"  @change="handleValueChange(record)"/>
                </a-form-model-item>
              </template>
             
              <!-- 操作 -->
              <span slot="action" slot-scope="text, record,index">
                 <a @click="copy(record)">复制</a>
                    <a-divider type="vertical"/>
                    <a-popconfirm title="确定删除吗？" @confirm="handleDelete(props,index)">
                    <a>删除</a>
              </a-popconfirm>
              </span>
            </a-table>
           
<!-- 
        子表 ipagination :rules="validatorRules"
        <a-spin :spinning="confirmLoading">
          <a-form-model ref="formRef">
            <j-vxe-table
              ref="vTable"
              toolbar
              row-number
              row-selection
              drag-sort
              keep-source
              :height="350"
              :loading="loading"
              :dataSource="addAdpacking.syPreAssembledPackingListItemList"
              :columns="columns"
              :alwaysEdit=true
              :bordered=true
              :scroll="{ x: 1500 }"
              style="margin-top: 5px;"
              :toolbarConfig="toolbarConfig"
              @valueChange="handleValueChange"
            > -->
            <!-- 起始箱号 -->
            <!-- <template v-slot:startingBoxNumber="record" >
              <a-input  v-model="record.startingBoxNumber"  style="border-color: red;"></a-input>
           </template> -->
           <!-- 结束箱号 -->
           <!-- <template v-slot:endCaseNumber="record" >
              <a-input  v-model="record.endCaseNumber"  style="border-color: red;"></a-input>
           </template> -->
           <!-- 净重/箱 -->
           <!-- <template v-slot:netWeight="record" >
              <a-input  v-model="record.netWeight"  style="border-color: red;"></a-input>
           </template> -->
           <!-- 毛重/箱 -->
           <!-- <template v-slot:grossWeight="record" >
              <a-input  v-model="record.grossWeight"  style="border-color: red;"></a-input>
           </template> -->
           <!-- 外箱长度 -->
           <!-- <template v-slot:outerBoxLength="record" >
              <a-input  v-model="record.outerBoxLength"  style="border-color: red;"></a-input>
           </template> -->
           <!-- 外箱高度 -->
           <!-- <template v-slot:outerBoxHeight="record" >
              <a-input  v-model="record.outerBoxHeight"  style="border-color: red;"></a-input>
           </template> -->
           <!-- 外箱宽度 -->
           <!-- <template v-slot:outerBoxWidth="record" >
              <a-input  v-model="record.outerBoxWidth"  style="border-color: red;"></a-input>
           </template>
            <template v-slot:action="props">
              <a @click="copy(props)">复制</a>
              <a-divider type="vertical"/>
              <a-popconfirm title="确定删除吗？" @confirm="handleDelete(props)">
                <a>删除</a>
              </a-popconfirm>
            </template>
            <template v-slot:toolbarSuffix>
              <a-button type="primary" @click="referShipmentDetails" icon="ordered-list">参照出运明细</a-button>
            </template>
            </j-vxe-table> -->
          </a-form-model>
        </a-spin>
      </a-card>

      <!-- 页面底部提交取消 -->
      <div
        :style="{
          position: 'absolute',
          right: 0,
          bottom: 0,
          width: '100%',
          borderTop: '1px solid #e9e9e9',
          padding: '10px 16px',
          background: '#fff',
          textAlign: 'right',
          zIndex: 999
        }"
      >
        <a-popconfirm title="确定放弃编辑？" @confirm="handleCancel" okText="确定" cancelText="取消">
          <a-button :style="{ marginRight: '8px' }">取消</a-button>
        </a-popconfirm>
        <a-button type="primary" @click="myHandSave" :loading="btnLoading" v-preventReClick="2000">
          保存
        </a-button>
        <a-button type="primary" @click="myHandSubmit" style="margin-left: 8px">
          保存并提交
        </a-button>
      </div>
    </a-drawer>

    <!-- 参照发运明细弹框 -->
    <referShipmentDetails-modal
      ref="referShipmentDetailsModal"
      @bao="getSon"
      @ok="modalFormOk"
    ></referShipmentDetails-modal>

  </div>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JEllipsis from '@/components/jeecg/JEllipsis'
import moment from 'moment'

import ReferShipmentDetailsModal from '@views/advance-packingList/referShipmentDetailsModal.vue'

import { addAdvPac, editById } from '@api/document/advance-packingList.js'
import { queryShippingDetails } from '@api/document/advance-packingList.js'
import { JVXETypes } from '@/components/jeecg/JVxeTable'
import { pushIfNotExist, randomNumber, randomUUID } from '@/utils/util'
import { getDotConfig, getDotValidExpress } from '@/utils/myutil'

export default {
  name: 'AddAdvancePacking', // 新增预装箱单
  mixins: [JeecgListMixin],
  components: { JEllipsis, moment, ReferShipmentDetailsModal }, // 参照发运明细弹框
  data() {
    let ellipsis = (v, l = 20) => <j-ellipsis value={v} length={l} /> // 省略

    return {
      toolbarConfig: {
          // add 新增按钮；remove 删除按钮；clearSelection 清空选择按钮
          btn: []
        },
      btnLoading:false,//按钮等待状态
      inputName:[],
      // 表头
      columns: [
        {
          title: '账套',
          dataIndex: 'acSetNo',
          width: 120,
          // fixed: 'left',
          className: 'replacecolor'
        },
        {
          title: '成衣工厂',
          dataIndex: 'garmentFactory',
          width: 120,
          // fixed: 'left',
          className: 'replacecolor'
        },
        {
          title: 'HOD',
          dataIndex: 'hod',
          width: 120,
          // fixed: 'left',
          className: 'replacecolor'
        },
        {
          title: 'STYLE NO.',
          dataIndex: 'styleNo',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: 'PO NO.',
          dataIndex: 'poNo',
          width: 120,
          className: 'replacecolor'
        },
         {
          title: 'ITEM NO./SKU NO./UPC NO./PACKS CODE',
          dataIndex: 'itemCode',
          ellipsis: true,
          scopedSlots: { customRender: 'itemCode' },
          width: 340,
          className: 'replacecolor'
        },
        {
          title: '分销点/DC/LABEL',
          dataIndex: 'distributionPoint',
          width: 180,
          className: 'replacecolor',
        },

        {
          title: 'PREPACK SKU',
          dataIndex: 'prepackSku',
          width: 140,
         className: 'replacecolor',
          insertAfter:true,
          scopedSlots: { customRender: 'prepackSku' },
        },

        {
          title: '起始箱号',
          dataIndex: 'startingBoxNumber',
          width: 120,
          className: 'replacecolor',
          scopedSlots: { customRender: 'startingBoxNumber' },

        },

        {
          title: '结束箱号',
          dataIndex: 'endCaseNumber',
          width: 140,
          className: 'replacecolor',
          scopedSlots: { customRender: 'endCaseNumber' },

        },

        {
          title: '颜色(中英文)',
          dataIndex: 'colour',
          width: 140,
          className: 'replacecolor',
          scopedSlots: { customRender: 'replacecolor' },
        },
        {
          title: '配码--根据U8订单来显示',
          dataIndex: 'withCode',
          width: 240,
          className: 'replacecolor',
        },
        {
          title: '计划尺码数量',
          dataIndex: 'planSize',
          width: 240,
          className: 'replacecolor',
        },
        {
          title: '计划装箱数量',
          dataIndex: 'planQuantity',
          width: 240,
          className: 'replacecolor',
        },
        {
          title: '件数/箱',
          dataIndex: 'piecesBox',
          width: 90,
          className: 'replacecolor',
        },
        {
          title: '箱数',
          dataIndex: 'boxNumber',
          width: 140,
          className: 'replacecolor',
        },

        {
          title: '总件数',
          dataIndex: 'total',          
          width: 140,
          className: 'replacecolor'
        },
        {
          title: '净重/箱',
          dataIndex: 'netWeight',
          width: 90,
          className: 'replacecolor',
          scopedSlots: { customRender: 'netWeight' },
        },
        {
          title: '总净重',
          dataIndex: 'totalNetWeight',
          width: 140,
          className: 'replacecolor'
        },

        {
          title: '毛重/箱',
          dataIndex: 'grossWeight',
          width: 120,
          className: 'replacecolor',
          scopedSlots: { customRender: 'grossWeight' },
        },
        {
          title: '总毛重',
          dataIndex: 'totalGrossWeight',
          width: 140,
          className: 'replacecolor'
        },
        {
          title: '外箱长度',
          dataIndex: 'outerBoxLength',
          width: 120,
          className: 'replacecolor',
          scopedSlots: { customRender: 'outerBoxLength' },
        },

        {
          title: '外箱宽度',
          dataIndex: 'outerBoxWidth',
          width: 140,
          className: 'replacecolor',
          scopedSlots: { customRender: 'outerBoxWidth' },
        },
        {
          title: '外箱高度',
          dataIndex: 'outerBoxHeight',
          className: 'replacecolor',
          width: 140,
          scopedSlots: { customRender: 'outerBoxHeight' },
        },

        {
          title: '总体积',
          dataIndex: 'totalVolume',
          className: 'replacecolor',
          width: 140,
          
        },
        {
          title: '净净重',
          dataIndex: 'netWeightToo',
          width: 120,
          className: 'replacecolor',
          scopedSlots: { customRender: 'netWeightToo' },
        },
        {
          title: '单价',
          dataIndex: 'unitPrice',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '总价',
          dataIndex: 'totalPrice',          
          width: 120,
          className: 'replacecolor'
        //    validateRules: [{ required: true, message: '${title}不能为空' },
        //     {pattern: /^\d+(\.\d{1,2})?$/, message: '小数点位数不能超过2位' }],
        },
        {
          title: '备注',
          dataIndex: 'memo',          
          width: 120,
          className: 'replacecolor'
        //    validateRules: [{ required: true, message: '${title}不能为空' },
        //     {pattern: /^\d+(\.\d{1,2})?$/, message: '小数点位数不能超过2位' }],
        },
        {
          title: '操作',
          dataIndex: 'action',
          className: 'replacecolor',
          fixed: 'right',
          width: 160,
          align: 'center',
          scopedSlots: { customRender: 'action' },
        }
      ],
      row:{},
      loading: false, // 表格加载
      visible: false,
      editDecide: 'add',
      dateFormat: 'YYYY-MM-DD',
      addAdpacking: {
        syPreAssembledPackingListItemList:[]
      }, //主表信息
      confirmLoading: false,
      msgFormSon: 'test', // 子组件传来数据的变量
      // state: '0', // 单据状态初始未【仅保存】
      // pushState: '0' // 推送状态初始未【仅保存】

      // 待确定还有哪些必填信息 ----------------------------
      validatorRules: {
        // orderNumber: [{ required: true, message: '订单号不能为空', trigger: 'blur' }],
        // styleNum: [{ required: true, message: '款号不能为空', trigger: 'blur' }],
        // name: [{ required: true, message: '品名不能为空', trigger: 'blur' }]
      },
      sizeFields:[], // 尺码字段
      dotConfig:{}, // 小数点配置
      judge : 0 ,
    }
  },
  // 接收父组件查询方法
  props: {
    fatherList: {
      type: Function,
      default: null
    }
  },

  methods: {
    getSon(val) {
      // console.log('勾选发运明细数据', val)
      // for (var i in val) {
      //   val[i]['orderQuantity'] = val[i].quantity
      //   val[i]['orderRemainingQuantity'] = val[i].surplusNum
      //   val[i]['salesUnitPrice'] = val[i].unitPriceIncludingTax
      //   val[i]['customerOrder'] = val[i].customerOrderNumber
      //   val[i]['shipmentQuantity'] = val[i].surplusNum //订单剩余数量 赋值给发货数量
      // }
      this.addAdpacking.syPreAssembledPackingListItemList = [];
      this.setHeadCalField();
      var selectData = val[0];      
      queryShippingDetails({id:selectData.id,groupId:selectData.groupId}).then(res => {
          if (res.success) {
           
            // 放在前面，有小数位数设置
            this.setHeadData(val[0], res.result);
            this.loadSizeTables(res.result.sizeTables);          
            var changedData = this.changeData(val[0], res.result);
            this.addAdpacking.syPreAssembledPackingListItemList.push(changedData);
          }else{
            this.$message.error("获取发运明细详情失败");
          }
        })
    },

    loadSizeTables(sizeTable){
      var newColums = this.columns.filter(item=>{
        return item.isSize != true;
      });            

      this.sizeFields = [];
      this.inputName = []
      if (sizeTable != null){
        var i=0;
        // 找到插入位置点
        for (; i<newColums.length;i++){
          if (newColums[i].insertAfter){
            break;
          }
        }
        // 插入数据
        for (var j=0;j<sizeTable.length;j++){
          this.sizeFields.push('size-'+sizeTable[j].size);
          var validExpress = getDotValidExpress(this.dotConfig.quantity);
          var field = {
              title: sizeTable[j].size,
              dataIndex: 'size-'+sizeTable[j].size,
              width: 80,
              isSize:true,
              validateRules: [validExpress],
               scopedSlots: { customRender: 'size-'+sizeTable[j].size },

          };
          this.inputName.push('size-'+sizeTable[j].size)
          
          newColums.splice(i+1+j,0,field);
        }
      }
      
      this.columns = newColums;  
    },
    // 参照发运明细
    referShipmentDetails() {
      // console.log('打开参照发运明细')
      this.$refs.referShipmentDetailsModal.referShipDetModVis = true
    },
    myHandSave(){
      this.addAdpacking.status=0;
      this.saveAdd(); 

    },
   async myHandSubmit(){
      this.addAdpacking.status=1;
      this.saveAdd(); 
    },
    //  保存
   async saveAdd() {
      var newObj = this.addAdpacking;
      if (this.sizeFields.length == 0){
        this.$message.error('当前记录没有尺码字段，无法保存');
        return;
      }
      // if (newObj.totalBoxes == 0){
      //   this.$message.error('总箱数为0，无法保存');
      //   return;
      // }
      await this.JudgeVluabled()
      //尺码赋值
      for(var i =0;i<newObj.syPreAssembledPackingListItemList.length;i++){
        var dataTable = newObj.syPreAssembledPackingListItemList[i]
        for (var j=0; j<dataTable.sizeTables.length; j++){
          var sizeTable = dataTable.sizeTables[j];
          var field = 'size-'+sizeTable.size;
         dataTable.sizeTables[j].proportion =  dataTable[field];
        }
      }
      // 日期格式转换
      if (newObj.preDeliveryDate != "" && newObj.preDeliveryDate != undefined){
        newObj.preDeliveryDate = newObj.preDeliveryDate+" 00:00:00";
      }
      // 推送状态、状态赋默认值。新增状态赋值
      if (newObj.id == undefined || newObj.id == ""){
          newObj.push_status = 0;
      }
      if(this.judge == 0){
        if(this.editDecide === 'edit'){
          editById(newObj).then(res => {
          this.btnLoading = true
          if (res.success) {
            if(newObj.status == '1'){
              this.$message.success('编辑并提交成功')
            }else {
              this.$message.success('编辑成功')
            }
             this.close()
             this.btnLoading = false
              //清空信息
             newObj = {syPreAssembledPackingListItemList:[]};
             this.row = res.result

             this.fatherList() // 调用父组件 查询方法
            // this.msgFormSon = {}  清空子表信息
           }else{
             this.$message.error(res.message)
              this.btnLoading = false
          }
         })
       }else {
         addAdvPac(newObj).then(res => {
          this.btnLoading = true
          if (res.success) {
             if(newObj.status == '1'){
              this.$message.success('新增并提交成功')
             }else {
              this.$message.success('新增成功')
             }
             this.close()
             this.btnLoading = false
             //清空信息
             newObj = {syPreAssembledPackingListItemList:[]};
             this.row = res.result
             this.fatherList() // 调用父组件 查询方法
          // this.msgFormSon = {}  清空子表信息
         }else{
          this.$message.error(res.message)
           this.btnLoading = false
        }
      })
      }
      }
      
      
      

      // const that = this
      // // 触发表单验证
      // this.$refs.form.validate(valid => {
      //   if (valid) {
      //     that.confirmLoading = true
      //   }
      // })
    },
   JudgeVluabled(){
          this.judge = 0
           for (var i=0; i<this.addAdpacking.syPreAssembledPackingListItemList.length;i++){
            var tableRow = this.addAdpacking.syPreAssembledPackingListItemList[i];
             tableRow = JSON.parse(JSON.stringify(tableRow))
            var allSizeSum = this.getAllSizeSum(tableRow);
            if (allSizeSum == 0){
              this.$message.error('第'+(i+1)+'行所有尺码数量为0，无法保存');
              this.judge += 1
              return;
            }
            if(tableRow.startingBoxNumber > tableRow.endCaseNumber) {
              this.$message.error('第'+(i+1)+'行起始箱号大于结束箱号，无法保存');
              this.judge += 1
              return;
            }
            //是否未填
            var required = [
            {key:'startingBoxNumber',value:'起始箱号'},
            {key:'endCaseNumber',value:'结束箱号'},
            {key:'netWeight',value:'净重/箱'},
            {key:'grossWeight',value:'毛重/箱'},
            {key:'outerBoxLength',value:'外箱长度'},
            {key:'outerBoxHeight',value:'外箱高度'},
            {key:'outerBoxWidth',value:'外箱宽度'},
            // {key:'netWeightToo',value:'净净重'},
            ]
             for(var j=0 ; j<required.length;j++){
                if(tableRow[required[j].key] == null || tableRow[required[j].key] == "" || tableRow[required[j].key] == undefined){
                  this.$message.error('第'+(i+1)+'行'+required[j].value+'无值，无法保存');
                  this.judge+=1
                  return
                }
             }
             

             //是否为整
             var integer = [
               {key:'startingBoxNumber',value:'起始箱号'},
               {key:'endCaseNumber',value:'结束箱号'},
               {key:'piecesBox',value:'件数/箱'},
             ]
             for(var v=0 ; v<integer.length;v++){
                if(!Number.isInteger(Number(tableRow[integer[v].key]))){
                  this.$message.error('第'+(i+1)+'行'+integer[v].value+'不为整数，无法保存');
                  this.judge+=1
                  return
                }
             }

            //判断小数位数
            var Several = [
               {key:'netWeight',value:'净重/箱'},
               {key:'grossWeight',value:'毛重/箱'},
               {key:'netWeightToo',value:'净净重'}
             ]
            for(var s=0 ; s<Several.length;s++){
              console.log(tableRow[Several[s].key])
              
                var position =(tableRow[Several[s].key]==0 || !tableRow[Several[s].key])?0:tableRow[Several[s].key].toString().indexOf('.')  + 1;   //小数点的位置
                
                var digit =(tableRow[Several[s].key]==0 || !tableRow[Several[s].key])?0: tableRow[Several[s].key].toString().length - position;  //小数的位值
                if(digit > 2 && position!==0 ){
                 this.$message.error('第'+(i+1)+'行'+Several[s].value+'小数超过两位，无法保存');
                this.judge+=1
                 return 
              }
             }   
           }
      
    },
    // 设置表头信息
   setHeadData(referData, mData){
      var itemData = {};
      if (mData.syPreAssembledPackingListItemList != null && mData.syPreAssembledPackingListItemList.size>0){
        itemData = mData.syPreAssembledPackingListItemList[0];
      }
      // 设置件数小数位数
      this.dotConfig = getDotConfig(itemData.masterMetering);
      this.addAdpacking.syDeclarationElementsId = mData.syDeclarationElementsId;    
      this.addAdpacking.elementsId = mData.elementsId
      this.addAdpacking.itemNumber = referData.itemNumber;
      // this.addAdpacking.productName = referData.chineseName;
      this.addAdpacking.productName = mData.productName;
      this.addAdpacking.englishProductName = mData.englishProductName;
      this.addAdpacking.u8Remarks = mData.u8Remarks;
      this.addAdpacking.sizeRange = "";
      if (mData.sizeTables != null){
        if (mData.sizeTables.length == 1){
            this.addAdpacking.sizeRange = mData.sizeTables[0].size;
        }else if (mData.sizeTables.length>1){
            this.addAdpacking.sizeRange = mData.sizeTables[0].size + " ~ " + mData.sizeTables[mData.sizeTables.length-1].size;
        }
      }
      this.addAdpacking.customer = mData.customer;
      this.addAdpacking.ompoId = mData.ompoId
      this.addAdpacking.salesman = mData.salesman
      this.addAdpacking.customerAbbreviation = mData.customerAbbreviation
      this.addAdpacking.spurOrSubOrder = mData.spurOrSubOrder
      this.addAdpacking.garmentFactory = mData.garmentFactory;
      this.addAdpacking.orderNumber = mData.orderNumber
    },
    // 发运明细详情成预装箱记录:mData-主表记录，itemData-子表记录
    changeData(referData, mData) {      
      var itemData = {};
      if (mData.syPreAssembledPackingListItemList != null && mData.syPreAssembledPackingListItemList.length>0){
        itemData = mData.syPreAssembledPackingListItemList[0];
      }
      var addrow = {
        syDeclarationElementsId:itemData.syDeclarationElementsId,
        syDeclarationElementsItemId:itemData.syDeclarationElementsItemId,
        acSetNo: itemData.acSetNo,
        garmentFactory: itemData.garmentFactory,
        hod: itemData.hod,
        styleNo:itemData.styleNo,
        poNo:itemData.poNo,
        itemCode:'',
        distributionPoint:referData.distributionPoint,
        prepackSku: '',
        size:"",
        startingBoxNumber: '',
        endCaseNumber: '',
        colour: itemData.colour,
        withCode: itemData.withCode,
        piecesBox: 0,
        boxNumber: '',
        total: '',
        netWeight: '',
        totalNetWeight: '',
        grossWeight: '',
        totalGrossWeight: '',
        outerBoxLength: '',
        outerBoxWidth: '',
        outerBoxHeight: '',
        totalVolume: '',
        netWeightToo: '',
        unitPrice: itemData.unitPrice,
        totalPrice: '',
        smallPo: referData.smallPo,
        inventoryName:referData.inventoryName,
        spurOrSubOrder:referData.purOrSubOrder,
        factoryUnitPrice:referData.factoryUnitPrice,
        customerAbbreviation:referData.customerAbbreviation,
        sizeTables : itemData.sizeTables,
        planSize : itemData.planSize,
        planQuantity:itemData.planQuantity,
        supplierCode:itemData.supplierCode,
        supplier:itemData.supplier,
        ompoAccount:itemData.ompoAccount,
        ompoId:itemData.ompoId,
        ompoIdItem:itemData.ompoIdItem,
        ymoney:itemData.ymoney
      }
      return addrow;
    },

    //  操作按钮 删除
    handleDelete(record,index) {
       var ret = this.addAdpacking.syPreAssembledPackingListItemList.splice(index, 1);
      this.setHeadCalField();
      return ret;
    },
    // 复制
    copy(record) {
      var newRow = JSON.parse(JSON.stringify(record));
      newRow.isAdd = 1
      this.addAdpacking.syPreAssembledPackingListItemList.push(newRow);
      this.setHeadCalField();
    },

    // 抽屉 取消
    handleCancel() {
      this.close()
    },
    close() {
      this.$emit('close')
      this.visible = false;
      this.btnLoading = false
      this.editDecide = 'add'
      this.addAdpacking = {syPreAssembledPackingListItemList:[]};
    },
    aa() {},
    modalFormOk() {
      this.$refs.referShipmentDetailsModal.referShipmentDetailsModVis = true
    },
    // 表格字段值变动时触发
    handleValueChange(record) {
      if (record.startingBoxNumber != undefined && record.startingBoxNumber != "" &&
      record.endCaseNumber != undefined && record.endCaseNumber != ""){
        record.boxNumber = record.endCaseNumber*1-record.startingBoxNumber*1+1;
      }
      var allSizeSum = this.getAllSizeSum(record);
      record.piecesBox = allSizeSum;
      record.total = (record.piecesBox*record.boxNumber);
      if (record.unitPrice != undefined && record.unitPrice != ""){
        record.totalPrice = (record.unitPrice*record.total).toFixed(2);
      }
      if (record.netWeight != "" && record.netWeight != undefined){
        record.totalNetWeight = (record.netWeight * record.boxNumber).toFixed(2);
      }
      if (record.grossWeight != "" && record.grossWeight != undefined){
        record.totalGrossWeight = (record.grossWeight * record.boxNumber).toFixed(2);
      }
      if (record.outerBoxLength != "" && record.outerBoxLength != undefined &&
      record.outerBoxWidth != "" && record.outerBoxWidth != undefined &&
      record.outerBoxHeight != "" && record.outerBoxHeight != undefined){
        record.totalVolume = ((record.outerBoxLength * record.outerBoxWidth * record.outerBoxHeight * record.boxNumber)/1000000).toFixed(3);
      }
      this.$forceUpdate()
      this.setHeadCalField();
      },
    // 获取不同尺码数量之和
    getAllSizeSum(record){
      var ret = 0;
      for (var i=0; i<this.sizeFields.length; i++){
        if (record[this.sizeFields[i]] != undefined && record[this.sizeFields[i]] != ""){
          ret += record[this.sizeFields[i]]*1;
        }
      }
      return ret;
    },
    // 设置表头计算值,直接设置表头值对象不能刷新，把表头对象换了就可以了
    setHeadCalField(){
      var headData = JSON.parse(JSON.stringify(this.addAdpacking));
      var totalBoxes = 0;
      var totalNetWeight = 0;
      var totalGrossWeight = 0;
      var totalVolume = 0;
      var totalPrice = 0;
      var total = 0;

      for (var i=0; i<headData.syPreAssembledPackingListItemList.length; i++){
        var rowData = headData.syPreAssembledPackingListItemList[i];
        totalBoxes += rowData.boxNumber;
        if (rowData.totalNetWeight != undefined && rowData.totalNetWeight != ""){
          totalNetWeight += rowData.totalNetWeight*1;
        }
        if (rowData.totalGrossWeight != undefined && rowData.totalGrossWeight != ""){
          totalGrossWeight += rowData.totalGrossWeight*1;
        }
        if (rowData.totalVolume != undefined && rowData.totalVolume != ""){
          totalVolume += rowData.totalVolume*1;
        }
        if (rowData.totalPrice != undefined && rowData.totalPrice != ""){
          totalPrice += rowData.totalPrice*1;
        }
        if (rowData.total != undefined && rowData.total != ""){
          total += rowData.total*1;
        }
      }
      
      headData.totalBoxes =Number(totalBoxes).toFixed(0);
      headData.totalNetWeight = totalNetWeight;
      headData.totalGrossWeight = totalGrossWeight;
      headData.totalVolume = totalVolume.toFixed(3);
      headData.totalPrice = totalPrice.toFixed(2); 
      headData.total = total.toFixed(0)
      this.addAdpacking = headData;
    },
  },
  computed: {},
  mounted() {}
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
/deep/ .ant-table-thead > tr > th {
  text-align: center;
  // font-weight: 700;
}
/deep/ .ant-table-tbody {
  text-align: center;
}
// /deep/ th.replacecolor {
//   background-color: #ccc;
// }
// 抽屉里的card样式
/deep/ .ant-drawer-content {
  background-color: #f0f2f5;
}
/deep/ .ant-drawer-body {
  padding: 10px;
}
</style>
