<template>
  <!-- 编辑发运明细 -->
  <div id="editShipDetDrawer">
    <a-drawer title="编辑" width="89%" placement="right" :closable="true" :visible="visible" @close="handleCancel">
      <!-- 主表信息 编辑 :rules="validatorRules"-->
      <a-card :bordered="true">
        <div class="table-page-search-wrapper">
          <a-form-model layout="inline" ref="form" :model="editShipDet" :rules="validatorRules">
            <a-row :gutter="24">
              <a-col :md="6" :sm="8">
                <!-- required必填项 disabled 禁用  -->
                <a-form-model-item label="单据号" prop="documentNo">
                  <a-input placeholder="请输入单据号" v-model="editShipDet.documentNo" readOnly></a-input>
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="单据日期" prop="documentDate">
                  <a-date-picker
                    placeholder="请选择单据日期"
                    :format="dateFormat"
                    style="width:100%;"
                    v-model="editShipDet.documentDate"
                  />
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="客户" prop="customer">
                  <a-input placeholder="请输入客户" v-model="editShipDet.customer" readOnly></a-input>
                </a-form-model-item>
              </a-col>


              <!-- <a-col :md="6" :sm="8">
                <a-form-model-item label="订单类型" prop="orderType">
                  <a-input placeholder="请输入订单类型" v-model="editShipDet.orderType"></a-input>
                </a-form-model-item>
              </a-col> -->


              <!-- <a-col :md="12" :sm="12">
                <a-form-model-item label="备注" prop="memo">
                  <a-input placeholder="请输入备注" v-model="editShipDet.memo"></a-input>
                </a-form-model-item>
              </a-col> -->
            </a-row>
          </a-form-model>
        </div>
      </a-card>

      <!--  参照订单数据 増行-->
      <a-card :bordered="true" style="margin:10px 0 60px 0">
        <!-- <div class="table-operator">
          <a-button type="primary" @click="referOrderDataOpen" icon="ordered-list" :disabled="btnDisabled">参照订单数据</a-button>
        </div> -->

        <!-- 子表  :model="form" :rules="validatorRules"-->
        <a-spin :spinning="confirmLoading">
          <a-form-model ref="formRef">
            <a-table
              v-if="syShippingDetailsItemList"
              bordered
              rowKey="id"
              :columns="columns"
              :data-source="syShippingDetailsItemList"
              :loading="loading"
              :pagination="false"
              :scroll="{ x: 2800,y:500 }"
              @change="handleTableChange"
            >
              <!-- 款号 输入框 :rules="rules.itemNumber" -->
              <!-- <template slot="itemNumber" slot-scope="text, record, index">
                <a-form-model-item prop="itemNumber">
                  <a-input style="width:100%" type="text" v-model="record.itemNumber" readOnly />
                </a-form-model-item>
              </template> -->
               <!-- 预发货日期 -->
               <template slot="preDeliveryDate" slot-scope="text, record, index">
                <a-form-model-item prop="preDeliveryDate" >
                  <a-date-picker v-model="record.preDeliveryDate" @change="changePreDeliveryDate(record)"/>
                </a-form-model-item>
              </template>
               <!-- 小po -->
               <template slot="smallPo" slot-scope="text, record, index">
                <a-form-model-item prop="smallPo">
                  <a-input style="width:100%" type="text" v-model="record.smallPo" @change="changeSmallPo(record)"/>
                </a-form-model-item>
              </template>
              <!-- 运输方式 -->
              <template slot="typeOfShipping" slot-scope="text, record, index">
                <a-form-model-item prop="typeOfShipping">
                  <a-select v-model="record.typeOfShipping"  @change="changeTypeOfShipping(record)">
                  <a-select-option
                     v-for="(item,index) in shippingTypeOption"
                     :key="index"
                     :value="item.value">
                     {{item.label}}
                  </a-select-option>
                  </a-select>
                  <!-- <a-input style="width:100%" type="text" v-model="record.typeOfShipping" @change="changeSmallPo(record)"/> -->
                </a-form-model-item>
              </template>
              <!-- 成衣工厂 :rules="rules.garmentFactory"-->
              <template slot="garmentFactory" slot-scope="text, record, index">
                <a-form-model-item prop="garmentFactory">
                  <a-input style="width:100%" type="text" v-model="record.garmentFactory"/>
                </a-form-model-item>
              </template>

              <!-- 发货数量 :rules="rules.shipQuantity"-->
              <template slot="shipmentQuantity" slot-scope="text, record, index">
                <a-form-model-item prop="shipmentQuantity">
                  <a-input style="width:100%" type="text" v-model="record.shipmentQuantity"    />
                </a-form-model-item>
              </template>

              <!-- 是否TC功能 :rules="rules.isTC"-->
              <!-- isTc ' 是否 tc 功能 0 否 1 是', -->
              <!-- <template slot="isTC" slot-scope="text, record, index">
                <a-form-model-item prop="isTc">
                  <a-select v-model="record.isTc"  @change='changeTc'>
                    <a-select-option value="">请选择</a-select-option>
                    <a-select-option value="1">是</a-select-option>
                    <a-select-option value="0">否</a-select-option>
                  </a-select>
                </a-form-model-item>
              </template> -->

              <!-- 物料成分 :rules="rules.materialComposition"-->
              <!-- <template slot="materialComposition" slot-scope="text, record, index">
                <a-form-model-item prop="materialComposition">
                  <a-input style="width:100%" type="text" v-model="record.materialComposition"  @change="changeMaterialComposition(record)"/>
                </a-form-model-item>
              </template> -->

              <!-- 采购/委外订单号 :rules="rules.purOrSubOrder"-->
              <template slot="purOrSubOrder" slot-scope="text, record, index">
                <a-form-model-item prop="purOrSubOrder">
                  <a-input style="width:100%" type="text" v-model="record.purOrSubOrder" />
                </a-form-model-item>
              </template>
              <!-- 单价（销售） :rules="rules.salesUnitPrice"-->
              <template slot="salesUnitPrice" slot-scope="text, record, index">
                <a-form-model-item prop="salesUnitPrice">
                  <a-input style="width:100%" type="text" v-model="record.salesUnitPrice"/>
                </a-form-model-item>
              </template>
              <!-- 佣金 :rules="rules.ymoney"-->
              <template slot="ymoney" slot-scope="text, record, index">
                <a-form-model-item prop="ymoney">
                  <a-input style="width:100%" type="text" v-model="record.ymoney" />
                </a-form-model-item>
              </template>

              <!-- 报关单价 :rules="rules.customsDeclarationUnitPrice"-->
              <template slot="customsDeclarationUnitPrice" slot-scope="text, record, index">
                <a-form-model-item prop="customsDeclarationUnitPrice">
                  <a-input style="width:100%" type="text" v-model="record.customsDeclarationUnitPrice" />
                </a-form-model-item>
              </template>
              <!-- 套装件数 :rules="rules.numberOfSets"-->
              <template slot="numberOfSets" slot-scope="text, record, index">
                <a-form-model-item prop="numberOfSets">
                  <a-input style="width:100%" type="text" v-model="record.numberOfSets"  />
                </a-form-model-item>
              </template>

              <!-- 工厂单价 :rules="rules.factoryUnitPrice"-->
              <template slot="factoryUnitPrice" slot-scope="text, record, index">
                <a-form-model-item prop="factoryUnitPrice">
                  <a-input style="width:100%" type="text" v-model="record.factoryUnitPrice"   />
                </a-form-model-item>
              </template>

              <!--处理方式 -->
              <template slot="treatmentMethod" slot-scope="text, record, index">
                <a-form-model-item prop="treatmentMethod">
                  <a-input style="width:100%" type="text" v-model="record.treatmentMethod" />
                </a-form-model-item>
              </template>

              <!--是否手册纱 -->
              <template slot="manualYarnFlag" slot-scope="text, record, index">
                <a-form-model-item prop="manualYarnFlag">
                  <a-select v-model="record.manualYarnFlag" @change='changeManualYarnFlag'>
                    <a-select-option :value="1">是</a-select-option>
                    <a-select-option :value="0">否</a-select-option>
                  </a-select>
                </a-form-model-item>
              </template>

              <!--手册纱单价 -->
              <template slot="manualYarnUnitPrice" slot-scope="text, record, index">
                <a-form-model-item prop="manualYarnUnitPrice">
                  <a-input style="width:100%" type="text" v-model="record.manualYarnUnitPrice" :disabled='manualYarnDisabled' @change="changeManualYarn('Price',record.manualYarnUnitPrice)" />
                </a-form-model-item>
              </template>

              <!--手册纱占比 -->
              <template slot="manualYarnProportion" slot-scope="text, record, index">
                <a-form-model-item prop="manualYarnProportion">
                  <a-input style="width:100%" type="text" v-model="record.manualYarnProportion"  :disabled='manualYarnDisabled' @change="changeManualYarn('Proportion',record.manualYarnProportion)" />
                </a-form-model-item>
              </template>


              <!-- 操作 -->
              <span slot="operationSlot" slot-scope="text, record">
                <a-popconfirm title="确定删除吗?" ok-text="是" cancel-text="否" @confirm="handleDelete(record.id)">
                  <a href="javascript:void(0);" style="color:red;">删除</a>
                </a-popconfirm>
              </span>
            </a-table>
          </a-form-model>
        </a-spin>
      </a-card>
      <!-- 页面底部保存取消 -->
      <div
        :style="{
          position: 'absolute',
          right: 0,
          bottom: 0,
          width: '100%',
          borderTop: '1px solid #e9e9e9',
          padding: '0px 0px',
          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="editSave" :disabled="confirmLoading">
          保存
        </a-button>
      </div>
    </a-drawer>

    <!-- 参照订单数据弹框 -->
    <referOrderData-modal ref="referOrderDataModal" @ok="referOrderDataOk"></referOrderData-modal>
  </div>
</template>

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

import ReferOrderDataModal from '@views/shipment-details/referOrderDataModal.vue'

import { editById,deleteEdit } from '@api/document/shipmentList'
import {Dictionaries} from '@api/document/book.js' //获取数据字典接口

export default {
  name: 'EditShipDetDrawer', // 编辑 发运明细 抽屉
  mixins: [JeecgListMixin], //
  components: { JEllipsis, ReferOrderDataModal, moment }, // 参照订单数据 弹框

  data() {
    // let ellipsis = (v, l = 20) => <j-ellipsis value={v} length={l} />
    return {
      id: '',
      validatorRules:{
          documentDate:[{required: true, message: '请输入单据日期!'}],
          customer:[{required: true, message: '客户为空!', trigger: 'change'}],
         // customer:[{required: true, message: '请选择客户!'}],
         // preDeliveryDate:[{required: true, message: '请选择预发货时间!'}],
         // preCompletionDate:[{required: true, message: '请选择预完工日期!'}],
         // orderType:[{required: true, message: '请输入订单类型!'}],
        },
        btnDisabled:true,//参照数据按钮禁止使用
        readyFabric:'',
      // 表头
      columns: [
       {
          title: '账套',
          dataIndex: 'account',
          width: 80,
          // fixed: 'left',
          className: 'replacecolor',
           ellipsis: true,
        },
        {
          title: '订单号',
          dataIndex: 'orderNumber',
          width: 90,
          // fixed: 'left',
          className: 'replacecolor',
           ellipsis: true,
        },
        {
          title: '款号',
          dataIndex: 'itemNumber',
          // fixed: 'left',
          width: 90,
          className: 'replacecolor',
           ellipsis: true,
        },
        // {
        //   title: '订单日期',
        //   dataIndex: 'orderDate',
        //   width: 120,
        //   className: 'replacecolor',
        //   customRender: text => {
        //     return moment(text).format('YYYY-MM-DD')
        //   },
        //    ellipsis: true,
        // },
        
         {
          title: '预发货日期',
          dataIndex: 'preDeliveryDate',
          width: 150,
          className: 'replacecolor',
          scopedSlots: { customRender: 'preDeliveryDate' },
           ellipsis: true,
        },
        //  {
        //   title: '预完工日期',
        //   dataIndex: 'preCompletionDate',
        //   width: 100,
        //   className: 'replacecolor',
         
        // },
         {
          title: '成衣工厂',
          dataIndex: 'garmentFactory',
          scopedSlots: { customRender: 'garmentFactory' },
          validateRules:[{ required: true, message: '${title}不能为空' }],
          width: 100,
          className: 'replacecolor',
        },
        // {
        //   title: '业务类型',
        //   dataIndex: 'businessTypeText',
        //   width: 120,
        //   className: 'replacecolor',
        //    ellipsis: true,
        // },
        // {
        //   title: '客户订单',
        //   dataIndex: 'customerOrder',
        //   width: 120,

        //   className: 'replacecolor'
        // },
        {
          title: '小po',
          dataIndex: 'smallPo',
          width: 110,
          className: 'replacecolor',
          scopedSlots: { customRender: 'smallPo' },
           ellipsis: true,
        },
        {
          title: '运输方式',
          dataIndex: 'typeOfShipping',
          width: 110,
          className: 'replacecolor',
          scopedSlots: { customRender: 'typeOfShipping' },
           ellipsis: true,
        },
        {
          title: 'Pack Id',
          dataIndex: 'packId',
          width: 110,
          className: 'replacecolor',
           ellipsis: true,
        },
        {
          title: '分销点',
          dataIndex: 'distributionPoint',
          width: 110,
          className: 'replacecolor',
           ellipsis: true,
        },
        {
          title: '存货编码',
          dataIndex: 'inventoryCode',
          width: 110,
          className: 'replacecolor',
           ellipsis: true,
        },
        {
          title: '存货名称',
          dataIndex: 'inventoryName',
          width: 110,
          className: 'replacecolor',
           ellipsis: true,
        },
        {
          title: '颜色',
          dataIndex: 'colour',
          width: 80,
          className: 'replacecolor',
           ellipsis: true,
        },
        {
          title: '尺码',
          dataIndex: 'size',
          width: 80,
          className: 'replacecolor',
           ellipsis: true,
        },
        {
          title: '配码规格',
          dataIndex: 'codingRules',
          width: 110,
          className: 'replacecolor',
           ellipsis: true,
        },
        
        {
          title: '采购/委外订单号',
          dataIndex: 'purOrSubOrder',
          // scopedSlots: { customRender: 'purOrSubOrder' },
          // fixed: 'left',
          width: 130,
          className: 'replacecolor',
        },
        // {
        //   title: '单价(销售)',
        //   // scopedSlots: { customRender: 'salesUnitPrice' },
        //   dataIndex: 'salesUnitPrice',
        //   width: 110,
        //   className: 'replacecolor',
        //    ellipsis: true,
        // },
        //   {
        //   title: '佣金',
        //   // scopedSlots: { customRender: 'ymoney' },
        //   dataIndex: 'ymoney',
        //   width: 80,
        //   className: 'replacecolor',
        //    ellipsis: true,
        // },

        // {
        //   title: ' 报关单价',
        //   dataIndex: 'customsDeclarationUnitPrice',
        //   // scopedSlots: { customRender: 'customsDeclarationUnitPrice' },
        //   // fixed: 'left',
        //   width: 90,
        //   className: 'replacecolor',
        //    ellipsis: true,
        // },
        //  {
        //   title: '工厂单价',
        //   dataIndex: 'factoryUnitPrice',
        //   width: 90,
        //   // scopedSlots: { customRender: 'factoryUnitPrice' },
        //   className: 'replacecolor',
        //    ellipsis: true,
        // },

        {
          title: '订单数量',
          dataIndex: 'orderQuantity',
          width: 90,
          className: 'replacecolor',
           ellipsis: true,
        },
        // {
        //   title: '订单剩余数量',
        //   dataIndex: 'orderRemainingQuantity',
        //   width: 120,
        //   className: 'replacecolor',
        //    ellipsis: true,
        // },

        {
          title: '发货数量',
          dataIndex: 'shipmentQuantity',
          scopedSlots: { customRender: 'shipmentQuantity' },
          width: 90,
        },

        {
          title: '套装件数',
          dataIndex: 'numberOfSets',
          scopedSlots: { customRender: 'numberOfSets' },
          width: 120,
          className: 'replacecolor',
        },
        // {
        //   title: '是否TC功能',
        //   dataIndex: 'isTC',
        //   width: 90,
        //   scopedSlots: { customRender: 'isTC' },
        //   className: 'replacecolor'
        // },
        // {
        //   title: '物料成分',
        //   dataIndex: 'materialComposition',
        //   scopedSlots: { customRender: 'materialComposition' },
        //   width: 140,
        //   className: 'replacecolor'
        // },

        // {
        //   title: '销售类型',
        //   dataIndex: 'salesTypeText',
        //   width: 120,
        //   className: 'replacecolor'
        // },
        // {
        //   title: '客户简称',
        //   dataIndex: 'customerAbbreviation',
        //   width: 120,
        //   align: 'left',
        //   className: 'replacecolor',
        //    ellipsis: true,
        // },
        // {
        //   title: '客户名称',
        //   dataIndex: 'customerName',
        //   width: 300,
        //   align: 'left',
        //   className: 'replacecolor',
        //   //  customRender: t => ellipsis(t),
        //    ellipsis: true,
        // },
        // {
        //   title: '汇率',
        //   dataIndex: 'exchangeRate',
        //   width: 120,
        //   className: 'replacecolor'
        // },

        // {
        //   title: '销售部门',
        //   dataIndex: 'salesDepartment',
        //   width: 100,
        //   className: 'replacecolor',
        //    ellipsis: true,
        // },
        // {
        //   title: '业务员',
        //   dataIndex: 'salesman',
        //   width: 100,
        //   className: 'replacecolor',
        //    ellipsis: true,
        // },
        // {
        //   title: '币种',
        //   dataIndex: 'currencyText',
        //   width: 90,
        //   className: 'replacecolor',
        //    ellipsis: true,
        // },

        // {
        //   title: '品牌方',
        //   dataIndex: 'brandSide',
        //   width: 100,
        //   className: 'replacecolor',
        //    ellipsis: true,
        // },
        // {
        //   title: '第三方',
        //   dataIndex: 'thirdParty',
        //   width: 220,
        //   align: 'left',
        //   className: 'replacecolor',
        //    ellipsis: true,
        // },
        // {
        //   title: '定金比例(%)',
        //   dataIndex: 'depositRatio',
        //   width: 120,
        //   className: 'replacecolor'
        // },
        // {
        //   title: '定金',
        //   dataIndex: 'deposit',
        //   width: 120,
        //   className: 'replacecolor'
        // },
        // {
        //   title: '协同路线',
        //   dataIndex: 'collaborativeRoute',
        //   width: 120,
        //   className: 'replacecolor'
        // },
      
        
       
        // {
        //   title: '付款条件',
        //   dataIndex: 'termOfPayment',
        //   width: 160,
        //   customRender: t => ellipsis(t),
        //   className: 'replacecolor'
        // },
        // {
        //   title: '最终客户',
        //   dataIndex: 'endCustomer',
        //   width: 120,
        //   className: 'replacecolor'
        // },
        // {
        //   title: '订单备注',
        //   dataIndex: 'orderRemarks',
        //   width: 200,
        //   // customRender: t => ellipsis(t),
        //   className: 'replacecolor',
        //    ellipsis: true,
        // },
        // {
        //   title: '价格备注',
        //   dataIndex: 'priceRemarks',
        //   width: 160,
        //   customRender: t => ellipsis(t),
        //   className: 'replacecolor'
        // },
        // {
        //   title: '订单变更说明',
        //   dataIndex: 'orderChangeDescription',
        //   width: 160,
        //   customRender: t => ellipsis(t),
        //   className: 'replacecolor'
        // },

        {
          title: '处理方式',
          dataIndex: 'treatmentMethod',
          width: 160,
          scopedSlots: { customRender: 'treatmentMethod' },
          className: 'replacecolor',
        },
        {
          title: '是否手册纱',
          dataIndex: 'manualYarnFlag',
          width: 140,
          scopedSlots: { customRender: 'manualYarnFlag' },
          className: 'replacecolor', 
        },
        {
          title: '手册纱单价',
          dataIndex: 'manualYarnUnitPrice',
          width: 160,
          scopedSlots: { customRender: 'manualYarnUnitPrice' },
          className: 'replacecolor'
        },
        {
          title: '手册纱占比',
          dataIndex: 'manualYarnProportion',
          width: 120,
          scopedSlots: { customRender: 'manualYarnProportion' },
          className: 'replacecolor'
        },

        {
          title: '操作',
          dataIndex: 'operation',
          scopedSlots: { customRender: 'operationSlot' },
          width: 100,
          fixed: 'right',
          className: 'replacecolor'
        }
      ],
      manualYarnDisabled: false, //手工纱单价和手工纱占比可输入
      msgFormSon: 'test', // 子组件传来数据的变量
      syShippingDetailsItemList: [], // 子表信息
      editShipDet: {}, // 编辑发运明细
      visible: false,
      confirmLoading: false,
      dateFormat: 'YYYY-MM-DD',
      shippingTypeOption:[]  //运输方式下拉框数据
    }
  },
  // 接收父组件查询方法
  props: {
    fatherList: {
      type: Function,
      default: null
    }
  },
  created() {  
    this.getOption()
  },

  methods: {
    // getSon(val) {
    //   var copyValList = JSON.parse(JSON.stringify(val));
    //   for (var i in copyValList) {
    //     copyValList[i]['orderQuantity'] = copyValList[i].quantity
    //     copyValList[i]['orderRemainingQuantity'] = copyValList[i].surplusNum
    //     copyValList[i]['salesUnitPrice'] = copyValList[i].unitPriceIncludingTax
    //     copyValList[i]['customerOrder'] = copyValList[i].customerOrderNumber
    //     copyValList[i]['shipmentQuantity'] = copyValList[i].surplusNum // 订单剩余数量 赋值给发货数量
    //   }
    //   this.syShippingDetailsItemList = this.syShippingDetailsItemList.concat(copyValList);
    //   this.msgFormSon = this.syShippingDetailsItemList;
    // },
    //获取下拉框数据
    getOption(){
      Dictionaries({code:'test0902001'}).then(res => {
         this.shippingTypeOption = res
      })
    },
    // 编辑 保存
    editSave() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(async valid => {
      if (valid) {
        this.editShipDet.syShippingDetailsItemList =this.syShippingDetailsItemList
        // 必须选择子表 --- 参照订单数据
        if (this.editShipDet.syShippingDetailsItemList.length == 0) {
          this.$message.error('请选择参照订单数据')
        } else {
          for (var i=0; i<this.editShipDet.syShippingDetailsItemList.length; i++){
            var rowData = this.editShipDet.syShippingDetailsItemList[i];
            if (rowData.shipmentQuantity > rowData.orderRemainingQuantity){
              this.$message.error('第'+(i+1)+'行超发货数量超过订单剩余数量，无法保存');
              return;
            }
          }
         
         await this.JudgeVluabled()
          if(this.judge == 0){
            this.confirmLoading = true
            editById(this.editShipDet).then(res => {  
            if (res.success) {
              this.$message.success('编辑成功');
              this.addShipDet = {};
              this.addShipDet.syShippingDetailsItemList = [];
                this.confirmLoading = false
              this.close();
              // this.fatherList(); // 调用父组件的查询方法
            }else{
              this.$message.error('res.message')
               this.confirmLoading = false
            }
           })
          }
          
        }
      }else{
        return false;
      }
      });
    },
     JudgeVluabled(){
          this.judge = 0
          for (var i=0; i<this.syShippingDetailsItemList.length;i++){
             var tableRow = this.syShippingDetailsItemList[i];
             for (var j=i+1;j<this.syShippingDetailsItemList.length; j++){
              var nextData = this.syShippingDetailsItemList[j];
              if (tableRow.smallPo == nextData.smallPo && tableRow.orderNumber == nextData.orderNumber  && 
              tableRow.preDeliveryDate == nextData.preDeliveryDate  && tableRow.preCompletionDate == nextData.preCompletionDate && 
              tableRow.itemNumber == nextData.itemNumber && tableRow.inventoryCode == nextData.inventoryCode&& 
              tableRow.colour == nextData.colour&& tableRow.size == nextData.size){
                this.$message.error('第'+(i+1)+'行和第'+(j+1)+'行数据相同，无法保存');
                this.judge += 1
                return;
              }
             } 
           }
           for (var i=0; i<this.syShippingDetailsItemList.length;i++){
             var tableRow = this.syShippingDetailsItemList[i];
            //是否未填
            var required = [
           {key:'garmentFactory',value:'成衣工厂'},
           {key:'purOrSubOrder',value:'采购/委外订单号'},
          //  {key:'customsDeclarationUnitPrice',value:'报关单价'},
           {key:'shipmentQuantity',value:'发货数量'},
           {key:'numberOfSets',value:'套装件数'},
          //  {key:'isTc',value:'是否TC功能'},
          //  {key:'materialComposition',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 number = [
              //  {key:'customsDeclarationUnitPrice',value:'报关单价'},
               {key:'shipmentQuantity',value:'发货数量'},
               {key:'numberOfSets',value:'套装件数'},
              //  {key:'factoryUnitPrice',value:'工厂单价'},
               {key:'manualYarnUnitPrice',value:'手册纱单价'},
             ]
             for(var j=0 ; j<number.length;j++){
                if(isNaN(Number(tableRow[number[j].key],10)) && tableRow[number[j].key]){
                this.$message.error('第'+(i+1)+'行发货数量必须为数字！');
                this.judge += 1
                return
              }
             }
             

             //是否为整
             var integer = [
               {key:'numberOfSets',value:'套装件数'},
               {key:'shipmentQuantity',value:'发货数量'},
             ]
             if(this.readyFabric == '0'){
             integer.splice(1, 1)
            }
             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:'customsDeclarationUnitPrice',value:'报关单价',dig:4},
              //  {key:'factoryUnitPrice',value:'工厂单价',dig:4},
               {key:'manualYarnUnitPrice',value:'手册纱单价',dig:4}
             ]
            for(var s=0 ; s<Several.length;s++){
              if(tableRow.manualYarnFlag !== 0 && tableRow.manualYarnUnitPrice){
                var position =  tableRow[Several[s].key].toString().indexOf('.')  + 1;   //小数点的位置
                var digit = tableRow[Several[s].key].toString().length - position;  //小数的位值
                if(digit > Several[s].dig && position!==0 ){
                 this.$message.error('第'+(i+1)+'行'+Several[s].value+'小数超过两位，无法保存');
                this.judge+=1
                 return 
              }
              }
               
                
             }   
           }
      
    },
    // 修改小po
    changeSmallPo(record){
      this.syShippingDetailsItemList.map(item=>{
        item.smallPo = record.smallPo
      })
    },
    changeTypeOfShipping(record){
      this.syShippingDetailsItemList.map(item=>{
        item.typeOfShipping = record.typeOfShipping
      })
    },
    // 修改预发货日期
    changePreDeliveryDate(record){
      this.syShippingDetailsItemList.map(item=>{
        item.preDeliveryDate = moment(record.preDeliveryDate).format('YYYY-MM-DD')
      })
    },
    // 参照订单数据
    referOrderDataOpen() {
      if(this.syShippingDetailsItemList.length !== 0){
        this.$refs.referOrderDataModal.fatherData.push(this.syShippingDetailsItemList[0]) 
      }
      this.$refs.referOrderDataModal.referOrderDataModVis = true
    },
    // 増行
    handleAddColumn() {
      console.log('増行')
      const addrow = {
        acSetNo: '',
        orderNumber: '',
        itemNumber: '',
        orderDate: '',
        businessType: '',
        customerOrder: '',
        smallPo: '',
        packId: '',
        orderData: '',
        orderRemaQuantity: '',
        shipQuantity: '',
        isTC: '',
        materialComposition: '',
        saleType: '',
        customerShortName: '',
        customerName: '',
        exchangeRate: '',
        wholeSingleCombined: '',
        salesDepartment: '',
        salesman: '',
        currency: '',
        brand: '',
        thirdParty: '',
        depositRate: '',
        deposit: '',
        collaborativeRoute: '',
        paymentClause: '',
        finalCustomer: '',
        orderNote: '',
        priceNote: '',
        orderChangeDesc: '',
        operation: ''
      }

      this.syShippingDetailsItemList.push(addrow)
    },
    // 操作 删除
    handleDelete(index) {
       deleteEdit({id:index}).then(res => {
                if (res.success) {
                  this.syShippingDetailsItemList = this.syShippingDetailsItemList.filter(item =>{
                    return item.id !== index
                  })
                  this.$forceUpdate()
                  this.$message.success('删除成功');
                }else{
                  this.$message.error(res.message)
              }
              })
          // this.$message.error('编辑状态下，不可删除！')
    },
    // 操作 复制
    copy(record) {
       var newRecord = JSON.parse(JSON.stringify(record));
      this.syShippingDetailsItemList.push(newRecord)
    },

      //修改是否为手册纱时触发
    changeManualYarnFlag(val) {
      this.syShippingDetailsItemList.map(item =>{
      item.manualYarnFlag = null
      item.manualYarnFlag = val
      //是手工纱时
      if(val === 0){
        item.manualYarnUnitPrice = null
        item.manualYarnProportion = null
        this.manualYarnDisabled = true
      }else if(val === 1){
        this.manualYarnDisabled = false
      }
      })
      this.$forceUpdate()
   },

  //  changeTc(val){
  //     this.syShippingDetailsItemList.map(item =>{
  //     item.isTc = val
  //     })
  //  },
  //  changeMaterialComposition(val){
  //     this.syShippingDetailsItemList.map(item =>{
  //     item.materialComposition = val.materialComposition
  //     })
  //  },

   //输入手册纱单价或者手册纱占比时触发
   changeManualYarn(data,val){
     console.log(this.syShippingDetailsItemList)
     this.syShippingDetailsItemList.map(item => {
       if(data === 'Price'){item.manualYarnUnitPrice = val}
       else{item.manualYarnProportion = val}
     })
     this.$forceUpdate()
   },

    // --------------------------------------
    // 抽屉 取消
    handleCancel() {
      this.close()
    },

    close() {
      this.$emit('close');
      this.visible = false;
      this.addShipDet = {};
      this.syShippingDetailsItemList = [];
      this.manualYarnDisabled = false
      this.readyFabric =''
      this.$refs.form.resetFields();
    },
    // --------------------------------------
    // 分页、排序、筛选变化时触发
    // handleTableChange(pagination, filters, sorter) {
    //   // console.log('当前页信息>>>>',pagination)
    //   this.queryParam.pageNo = pagination.current
    //   // this.getAnnList()
    // },
    // 参照订单数据弹框 ok-------------------------------------
    referOrderDataOk() {
      console.log('参照订单数据弹框确定')
      this.$refs.referOrderDataModal.referOrderDataModVis = false;
      this.$refs.referOrderDataModal.queryParam.orderNumber="";
      this.$refs.referOrderDataModal.queryParam.account="";
      this.$refs.referOrderDataModal.queryParam.salesman="";
      this.$refs.referOrderDataModal.queryParam.customerName="";
      this.$refs.referOrderDataModal.queryParam.dateRange=[];
      this.$refs.referOrderDataModal.queryParam.preDeliveryDate="";
      this.$refs.referOrderDataModal.queryParam.flourOrGarment="";
    },
  },
  computed: {},
  mounted() {}
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
/deep/ .ant-table-thead > tr > th {
  text-align: center !important;
  // 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: 0px;
}
/deep/.ant-table-row-cell-break-word >.ant-form-item{
  margin-bottom: 0px !important;
}
/deep/.ant-table-tbody .ant-table-row td{
      padding-top: 8px !important;
    padding-bottom: 8px !important;
}
</style>
