<template>
  <a-spin :spinning="loading">
    <JFormContainer :disabled="disabled">
      <template #detail>
        <a-form v-bind="formItemLayout" name="quotationFormForm" ref="formRef">
          <a-row>
            <a-col :span="12">
              <a-form-item
                label="发货通知单号(bill code)"
                v-bind="validateInfos.billCode"
                id="quotationFormForm-billCode"
                name="billCode"
                :labelCol="formItemLayout.labelCol1"
                :wrapperCol="formItemLayout.wrapperCol1"
              >
                <a-input v-model:value="formData.billCode" placeholder="自动生成" disabled />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item
                label="发货日期(delivery date)"
                v-bind="validateInfos.deliveryDate"
                id="quotationFormForm-deliveryDate"
                name="deliveryDate"
              >
                <a-date-picker
                  placeholder="请选择发货日期(delivery date)"
                  v-model:value="formData.deliveryDate"
                  value-format="YYYY-MM-DD"
                  style="width: 100%"
                  allow-clear
                />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="项目(project)" v-bind="validateInfos.projectName" id="quotationFormForm-projectName" name="projectName">
                <a-input-search
                  v-model:value="formData.projectName"
                  placeholder="请输入项目(project)"
                  readonly
                  allow-clear
                  enter-button="Search"
                  :disabled="notAllowEdit"
                  @search="onSearchProject"
                />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item
                label="客户(customer)"
                v-bind="validateInfos.customer"
                id="quotationFormForm-customer"
                name="customer"
                :labelCol="formItemLayout.labelCol1"
                :wrapperCol="formItemLayout.wrapperCol1"
              >
                <JSelectInput v-model:value="formData.customer" placeholder="请选择" :options="customerOption" disabled />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="优先级(priority)" v-bind="validateInfos.priority" id="quotationFormForm-priority" name="priority">
                <JDictSelectTag v-model:value="formData.priority" placeholder="请选择" dictCode="priority" disabled />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item
                label="产品分类(production class)"
                v-bind="validateInfos.productionClass"
                id="quotationFormForm-productionClass"
                name="productionClass"
                :labelCol="formItemLayout.labelCol1"
                :wrapperCol="formItemLayout.wrapperCol1"
              >
                <JSelectInput v-model:value="formData.productionClass" placeholder="请选择" :options="classOption" disabled />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="机型(model)" v-bind="validateInfos.model" id="quotationFormForm-model" name="model">
                <JSelectMultiple v-model:value="formData.model" placeholder="请选择" dictCode="model_typer" disabled />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item
                label="厂家(maker)"
                v-bind="validateInfos.maker"
                id="quotationFormForm-maker"
                name="maker"
                :labelCol="formItemLayout.labelCol1"
                :wrapperCol="formItemLayout.wrapperCol1"
              >
                <a-input v-model:value="formData.maker" placeholder="请输入厂家(maker)" allow-clear disabled />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="币种(currency)" v-bind="validateInfos.currency" id="quotationFormForm-currency" name="currency">
                <JDictSelectTag v-model:value="formData.currency" placeholder="请选择" dictCode="currency" disabled />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item
                label="交货条款(delivery terms)"
                v-bind="validateInfos.deliveryTerms"
                id="quotationFormForm-deliveryTerms"
                name="deliveryTerms"
                :labelCol="formItemLayout.labelCol1"
                :wrapperCol="formItemLayout.wrapperCol1"
              >
                <JDictSelectTag v-model:value="formData.deliveryTerms" placeholder="请选择" dictCode="delivery_terms" disabled />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="发货方式(delivery)" v-bind="validateInfos.delivery" id="SaleOrderForm-delivery" name="delivery">
                <JDictSelectTag v-model:value="formData.delivery" placeholder="请选择" dictCode="delivery_methods" disabled />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item
                label="交货地点(place of delivery)"
                v-bind="validateInfos.deliveryAddress"
                id="quotationFormForm-deliveryAddress"
                name="deliveryAddress"
              >
                <a-input v-model:value="formData.deliveryAddress" placeholder="请输入交货地点(place of delivery)" allow-clear AutoComplete="off" />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item
                label="是否希望出口(isExport)"
                v-bind="validateInfos.isExport"
                id="quotationFormForm-isExport"
                name="isExport"
                :labelCol="formItemLayout.labelCol1"
                :wrapperCol="formItemLayout.wrapperCol1"
              >
                <JDictSelectTag v-model:value="formData.isExport" placeholder="请选择" dictCode="yes_or_no" />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item
                label="质保期(warranty period)"
                v-bind="validateInfos.warrantyPeriod"
                id="SaleOrderForm-warrantyPeriod"
                name="warrantyPeriod"
              >
                <a-input
                  v-model:value="formData.warrantyPeriod"
                  placeholder="请输入"
                  style="width: 85%; margin-right: 1%"
                  AutoComplete="off"
                />月(month)
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item
                label="销售部门(sale department)"
                v-bind="validateInfos.saleDepartment"
                id="SaleInquiryFormForm-saleDepartment"
                name="saleDepartment"
              >
                <a-input v-model:value="formData.saleDepartmentName" placeholder="" allow-clear disabled />
              </a-form-item>
            </a-col>
            <a-col :span="12" v-if="1==0">
              <a-form-item
                label="联系人(linkMan)"
                v-bind="validateInfos.linkMan"
                id="quotationFormForm-linkMan"
                name="linkMan"
                :labelCol="formItemLayout.labelCol1"
                :wrapperCol="formItemLayout.wrapperCol1"
              >
                <a-input v-model:value="formData.linkMan" placeholder="请输入联系人(linkMan)" allow-clear AutoComplete="off" />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item
                label="包装要求(packaging requirement)"
                v-bind="validateInfos.packagingRequirement"
                id="quotationFormForm-packagebRequirement"
                name="packagebRequirement"
                :labelCol="formItemLayout.labelCol1"
                :wrapperCol="formItemLayout.wrapperCol1"
              >
                <a-input
                  v-model:value="formData.packagebRequirement"
                  placeholder="请输入包装要求(packaging requirement)"
                  allow-clear
                  AutoComplete="off"
                />
              </a-form-item>
            </a-col>
            <a-col :span="12"  v-if="1==0">
              <a-form-item label="联系电话(linkMan phone)" v-bind="validateInfos.linkNumber" id="quotationFormForm-linkNumber" name="linkNumber">
                <a-input v-model:value="formData.linkNumber" placeholder="" allow-clear AutoComplete="off" />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="业务员(salesman)" v-bind="validateInfos.salesman" id="quotationFormForm-salesman" name="salesman">
                <a-input v-model:value="formData.salesmanName" placeholder="" allow-clear disabled />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item
                label="F号(F number)"
                v-bind="validateInfos.fnumber"
                id="quotationFormForm-fnumber"
                name="fnumber"
                :labelCol="formItemLayout.labelCol1"
                :wrapperCol="formItemLayout.wrapperCol1"
              >
                <a-input v-model:value="formData.fnumber" placeholder="请选择" AutoComplete="off" />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="提单号(B/L NO)" v-bind="validateInfos.blno" id="quotationFormForm-blno" name="blno">
                <a-input v-model:value="formData.blno" placeholder="请输入" allow-clear AutoComplete="off" />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item
                label="开票抬头(invoice header)"
                v-bind="validateInfos.invoiceHeader"
                id="SaleOrderForm-invoiceHeader"
                name="invoiceHeader"
                :labelCol="formItemLayout.labelCol1"
                :wrapperCol="formItemLayout.wrapperCol1"
              >
                <a-textarea  v-model:value="formData.invoiceHeader" placeholder="" allow-clear AutoComplete="off" :rows="3"/>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item
                label="是否有第三方运费(otherFee)"
                v-bind="validateInfos.otherFee"
                id="SaleOrderForm-otherFee"
                name="otherFee"
                :labelCol="formItemLayout.labelCol1"
                :wrapperCol="formItemLayout.wrapperCol1"
              >
                <a-select v-model:value="formData.otherFee">
                  <a-select-option value="是"> 是 </a-select-option>
                  <a-select-option value="否"> 否 </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item
                label="是否收取客户运费(Customer shipping fee)"
                v-bind="validateInfos.customerFee"
                id="SaleOrderForm-customerFee"
                name="customerFee"
                :labelCol="formItemLayout.labelCol1"
                :wrapperCol="formItemLayout.wrapperCol1"
              >
                <a-select v-model:value="formData.customerFee">
                  <a-select-option value="是"> 是 </a-select-option>
                  <a-select-option value="否"> 否 </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="收货地址(address)" v-bind="validateInfos.address" id="quotationFormForm-address" name="address">
                <a-textarea  v-model:value="formData.address" placeholder="" allow-clear AutoComplete="off" :rows="3"/>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item
                label="包装详情(packingDetails))"
                v-bind="validateInfos.packingDetails"
                id="SaleOrderForm-packingDetails "
                name="packingDetails "
              >
                <a-textarea v-model:value="formData.packingDetails" placeholder="请输入" AutoComplete="off" :rows="3"/>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="备注(notes)" v-bind="validateInfos.notes" id="quotationFormForm-notes" name="notes">
                <a-textarea v-model:value="formData.notes" placeholder="请输入备注(notes)" allow-clear AutoComplete="off"  :rows="3"/>
              </a-form-item>
            </a-col>

          </a-row>
        <a-row>

        </a-row>
        </a-form>
      </template>
    </JFormContainer>

    <!-- 子表单区域 -->
    <a-tabs v-model:activeKey="activeKey" animated style="padding: 24px; padding-top: 0px">
      <a-tab-pane tab="发货通知单 - 发货明细(delivery details)" key="deliveryDetailFormProduct" :forceRender="true">
        <a-button type="primary" @click="selectSaleOrderList" style="margin-right: 1%; margin-bottom: 1%"> 选择销售订单(selete saleOrder)</a-button>
        <a-button type="primary" style="margin-right: 1%; margin-bottom: 1%" @click="selectVirtualProducts">
          选择虚拟产品(select virtual products)</a-button
        >
        <j-vxe-table
          :keep-source="true"
          resizable
          ref="deliveryDetailFormProductTableRef"
          :loading="deliveryDetailFormProductTable.loading"
          :columns="deliveryDetailFormProductTable.columns"
          :dataSource="deliveryDetailFormProductTable.dataSource"
          :maxHeight="340"
          :disabled="disabled"
          :rowNumber="true"
          :rowSelection="true"
          asyncRemove
          @value-change="changeValues"
        >
          <template #action="props">
            <a-popconfirm title="确定删除吗？" @confirm="handleDelete1(props)">
              <a>删除(delete)</a>
            </a-popconfirm>
          </template>
        </j-vxe-table>
      </a-tab-pane>
      <a-tab-pane tab="发货通知单 - 船明细(ship details)" key="deliveryNoticeFormShip" :forceRender="true">
        <j-vxe-table
          :keep-source="true"
          resizable
          ref="deliveryNoticeFormShipTableRef"
          :loading="deliveryNoticeFormShipTable.loading"
          :columns="deliveryNoticeFormShipTable.columns"
          :dataSource="deliveryNoticeFormShipTable.dataSource"
          :maxHeight="340"
          :disabled="disabled"
          :rowNumber="true"
          :rowSelection="true"
        >
          <template #action="props">
            <a @click="viewAccessory(props)">查看配件信息(view accessory information)</a>
          </template>
        </j-vxe-table>
      </a-tab-pane>
    </a-tabs>
    <BaseShipArchiveAccessoriesModal ref="BaseShipArchiveAccessoriesListRef" />
    <SelectProjectModal ref="SelectProjectModalRef" @select-project="addProject" />
    <SelectPrpductModal ref="SelectPrpductModalRef" @select-product="addProduct" />
    <SelectSaleOrderModal ref="SelectSaleOrderModalRef" @select-sale-order="addFormSaleOrder" />
  </a-spin>
</template>

<script lang="ts">
  import { defineComponent, ref, reactive, computed, toRaw, onMounted } from 'vue';
  import { defHttp } from '/@/utils/http/axios';
  import { useValidateAntFormAndTable } from '/@/hooks/system/useJvxeMethods';
  import {
    querydeliveryNoticeFormShipListByMainId,
    querydeliveryNoticeFormProductListByMainId,
    queryDataById,
    saveOrUpdate,
  } from '../delivertNoticeForm.api';
  import { JVxeTable } from '/@/components/jeecg/JVxeTable';
  import { deliveryNoticeShipColumns, deliveryNoticeProductColumns } from '../delivertNoticeForm.data';
  import BaseShipArchiveAccessoriesModal from '../../../publicComponents/BaseShipArchiveAccessoriesModal.vue';
  import SelectPrpductModal from '../../../publicComponents/SelectPrpductModal.vue';
  import SelectProjectModal from '../../../publicComponents/SelectProjectModal.vue';
  import SelectSaleOrderModal from '../../../publicComponents/SelectSaleOrderModal.vue';
  import JFormContainer from '/@/components/Form/src/container/JFormContainer.vue';
  import JUpload from '/@/components/Form/src/jeecg/components/JUpload/JUpload.vue';
  import { JDictSelectTag, JSelectMultiple } from '/@/components/Form';
  import JSelectInput from '/@/components/Form/src/jeecg/components/JSelectInput.vue';
  import { Form, message } from 'ant-design-vue';
  import { useUserStore } from '/@/store/modules/user';
  import moment from 'moment';
  const userStore = useUserStore();
  const useForm = Form.useForm;
  export default defineComponent({
    name: 'DeliveryNoticeForm',
    components: {
      JVxeTable,
      JFormContainer,
      BaseShipArchiveAccessoriesModal,
      SelectPrpductModal,
      JUpload,
      SelectProjectModal,
      JDictSelectTag,
      JSelectInput,
      JSelectMultiple,
      SelectSaleOrderModal,
    },
    props: {
      formDisabled: {
        type: Boolean,
        default: false,
      },
      formData: { type: Object, default: () => {} },
      formBpm: { type: Boolean, default: true },
    },
    emits: ['success'],
    setup(props, { emit }) {
      const loading = ref(false);
      const formRef = ref();
      const SelectSaleOrderModalRef = ref();
      const SelectPrpductModalRef = ref();
      var SelectProjectModalRef = ref();
      const deliveryNoticeFormShipTableRef = ref();
      const deliveryNoticeFormShipTable = reactive<Record<string, any>>({
        loading: false,
        columns: deliveryNoticeShipColumns,
        dataSource: [],
      });
      const deliveryDetailFormProductTableRef = ref();
      const deliveryDetailFormProductTable = reactive<Record<string, any>>({
        loading: false,
        columns: deliveryNoticeProductColumns,
        dataSource: [],
      });
      var SelectShipSModalRef = ref();
      var BaseShipArchiveAccessoriesListRef = ref();
      const activeKey = ref('deliveryDetailFormProduct');
      var notAllowEdit = ref(false);
      var classOption = ref([]);
      var customerOption = ref([]);
      const formData = reactive<Record<string, any>>({
        id: '',
        status: undefined,
        delFlag: undefined,
        sourceCode: '',
        deliveryDate: moment(new Date()).format('YYYY-MM-DD'),
        billCode: '',
        project: '',
        projectName: '',
        customer: '',
        customerName: '',
        priority: '',
        productionClass: '',
        model: '',
        maker: '',
        currency: '',
        deliveryTerms: '',
        delivery: '',
        deliveryAddress: '',
        isExport: '',
        warrantyPeriod: '',
        saleDepartment: '',
        saleDepartmentName: '',
        packagebRequirement: '',
        linkMan: '',
        address: '',
        linkNumber: '',
        salesman: '',
        salesmanName: '',
        fnumber: '',
        blno: '',
        notes: '',
        invoiceHeader: '',
        otherFee: '',
        packingDetails: '',
        customerFee: '',
      });

      //表单验证
      const validatorRules = reactive({
        projectName: [{ required: true, message: '请选择项目(select project)' }],
        customerFee: [{ required: true, message: '请选择是否收取客户运费(Customer shipping fee)' }],
      });
      const { resetFields, validate, validateInfos } = useForm(formData, validatorRules, { immediate: false });
      const dbData = {};
      const formItemLayout = {
        labelCol: { xs: { span: 24 }, sm: { span: 8 } },
        wrapperCol: { xs: { span: 24 }, sm: { span: 13 } },
        labelCol1: { xs: { span: 24 }, sm: { span: 8 } },
        wrapperCol1: { xs: { span: 24 }, sm: { span: 13 } },
      };

      // 表单禁用
      const disabled = computed(() => {
        if (props.formBpm === true) {
          if (props.formData.disabled === false) {
            return false;
          } else {
            return true;
          }
        }
        return props.formDisabled;
      });

      //新增方法
      function add() {
        resetFields();
        deliveryNoticeFormShipTable.dataSource = [];
        deliveryDetailFormProductTable.dataSource = [];
        activeKey.value = 'deliveryDetailFormProduct';
        getOptiom();
        getCustomerOptions();
        formData.salesman = userStore.getUserInfo.username;
        formData.salesmanName = userStore.getUserInfo.realname;
        formData.saleDepartment = userStore.getUserInfo.orgCode;
        formData.saleDepartmentName = userStore.getUserInfo.orgName;
        notAllowEdit.value = false;
      }
      //编辑方法
      async function edit(row) {
        //主表数据
        await queryMainData(row.id);
        //子表数据
        const deliveryNoticeFormShipDataList = await querydeliveryNoticeFormShipListByMainId(row['id']);
        deliveryNoticeFormShipTable.dataSource = [...deliveryNoticeFormShipDataList];
        const deliveryDetailFormProductDataList = await querydeliveryNoticeFormProductListByMainId(row['id']);
        deliveryDetailFormProductTable.dataSource = [...deliveryDetailFormProductDataList];
        getOptiom();
        getCustomerOptions();
        notAllowEdit.value = true;
      }
      //获取主表
      async function queryMainData(id) {
        const row = await queryDataById(id);
        resetFields();
        const tmpData = {};
        Object.keys(formData).forEach((key) => {
          if (row.hasOwnProperty(key)) {
            tmpData[key] = row[key];
          }
        });
        //赋值
        Object.assign(formData, tmpData);
      }

      const { getSubFormAndTableData, transformData } = useValidateAntFormAndTable(activeKey, {
        saleDeliveryShip: deliveryNoticeFormShipTableRef,
        saleDeliveryDetails: deliveryDetailFormProductTableRef,
      });
      //获取表单信息
      async function getFormData() {
        try {
          // 触发表单验证
          await validate();
        } catch ({ errorFields }) {
          if (errorFields) {
            const firstField = errorFields[0];
            if (firstField) {
              formRef.value.scrollToField(firstField.name, { behavior: 'smooth', block: 'center' });
            }
          }
          return Promise.reject(errorFields);
        }
        return transformData(toRaw(formData));
      }
      //保存
      async function submitForm() {
        if (formData.sourceCode == '') {
          message.warning('请添加产品明细');
        } else {
          deliveryDetailFormProductTableRef.value!.validateTable().then(async (errMap) => {
            if (errMap) {
              console.log('表单验证未通过：', { errMap });
            } else {
              const mainData = await getFormData();
              const subData = await getSubFormAndTableData();
              var judge = false;
              if (mainData.customerFee == '是') {
                judge = subData.saleDeliveryDetailsList.every((item) => item.sourceId && item.sourceId !== undefined && item.sourceId !== '');
              } else {
                judge = false;
              }
              if (!judge) {
                const values = Object.assign({}, dbData, mainData, subData);
                console.log('表单提交数据', values);
                const isUpdate = values.id ? true : false;
                await saveOrUpdate(values, isUpdate);
                //关闭弹窗
                emit('success');
              } else {
                message.warning('收取客户运费时，必须选择虚拟产品');
              }
            }
          });
        }
      }

      function setFieldsValue(values) {
        if (values) {
          Object.keys(values).map((k) => {
            formData[k] = values[k];
          });
        }
      }

      /**
       * 值改变事件触发-树控件回调
       * @param key
       * @param value
       */
      function handleFormChange(key, value) {
        formData[key] = value;
      }
      //产品明细-删除行
      async function handleDelete1(prop) {
        var xTable = deliveryDetailFormProductTableRef.value!.getXTable();
        var newArray = [...xTable.data];
        newArray.splice(prop.rowIndex, 1);
        deliveryDetailFormProductTable.dataSource = newArray;
        if (deliveryDetailFormProductTable.dataSource.length !== 0) {
          notAllowEdit.value = true;
        } else {
          formData.sourceCode = '';
          notAllowEdit.value = false;
          add();
        }
      }
      //选择项目
      function addProject(data) {
        if (data.length == 0) {
          formData.project = formData.projectName = '';
        } else {
          formData.project = data[0].id;
          formData.projectName = data[0].code;
          formData.customer = data[0].customerId;
          formData.customerName = data[0].customerId_dictText;
          customerOption.value.map((item) => {
            if (item.value == data[0].customerId) {
              formData.priority = item.priority;
            }
          });
        }
      }
      //获取客户列表
      function getCustomerOptions() {
        let params = { pageSize: '-1', status: 1 };
        defHttp.get({ url: '/cuspCode/cuspCustomerProfile/list', params }, { isTransformResponse: false }).then((res) => {
          if (res) {
            customerOption.value = [];
            res.result.records.forEach((item) => {
              customerOption.value.push({
                label: item.name,
                value: item.id,
                priority: item.priority,
                intermediatorCommission: item.intermediatorCommission,
              });
            });
          }
        });
      }
      //查看配件信息
      function viewAccessory(prop) {
        BaseShipArchiveAccessoriesListRef.value.getTable(prop.row);
      }
      //选择项目
      function onSearchProject() {
        SelectProjectModalRef.value.getTable();
      }
      //获取产品分类下拉框
      function getOptiom() {
        defHttp
          .get({ url: 'baseCode/baseProductClass/list' }, { isTransformResponse: false })
          .then((res) => {
            if (res.success) {
              classOption.value = [];
              res.result.records.forEach((element) => {
                var obj = {
                  label: element.name ? element.name : '无名称请维护',
                  value: element.id ? element.id : '',
                };
                classOption.value.push(obj);
              });
            }
          })
          .finally(() => {
            // loading.value = false;
          });
      }
      // 选择销售订单
      function selectSaleOrderList() {
        var obj = formData;
        obj.sourceCode2 = formData.sourceCode;
        SelectSaleOrderModalRef.value.getTable(obj, 'delivery');
      }
      function addFormSaleOrder(data) {
        data.map((item) => {
          item.model = item.childModel;
          item.sourceId = item.childId;
          item.orderQuantity = item.quantity;
          item.orderMoney = item.discountedAmount;
          item.money = item.discountedAmount;
          item.taxPrice = item.discountedPrice;
        });
        var xTable = deliveryDetailFormProductTableRef.value!.getXTable(); //关键代码 如果不更新 重新加载表格即可
        var arrProduct = xTable.data.concat(data);
        deliveryDetailFormProductTable.dataSource = arrProduct;
        notAllowEdit.value = true;
        formData.sourceCode = data[0].billCode;
        formData.project = data[0].project;
        formData.projectName = data[0].projectName;
        formData.customerName = data[0].customerName;
        formData.customer = data[0].customer;
        formData.priority = data[0].priority;
        formData.productionClass = data[0].productionClass;
        formData.model = data[0].headModel;
        formData.maker = data[0].maker;
        formData.currency = data[0].currency;
        formData.deliveryTerms = data[0].deliveryTerms;
        formData.delivery = data[0].delivery;
        formData.invoiceHeader = data[0].invoiceHeader;
        formData.invoiceAddress = data[0].invoiceAddress;
        formData.deliveryAddress = data[0].deliveryAddress;
        formData.isExport = data[0].isExport;
        formData.packagebRequirement = data[0].packagebRequirement;
        formData.warrantyPeriod = data[0].warrantyPeriod;
        formData.invoiceHeader = data[0].invoiceHeader;
        getShipList(data[0].headId);
      }
      function getShipList(id) {
        let params = { id: id };
        let url = '/saleCode/saleOrder/querySaleOrderShipByMainId';
        defHttp.get({ url: url, params }, { isTransformResponse: false }).then((res) => {
          if (res) {
            deliveryNoticeFormShipTable.dataSource = res.result;
          }
        });
      }
      function changeValues(prop) {
        if (prop.col.key == 'quantity') {
          if (prop.row.quantity) {
            var num = prop.row.quantity * Number(prop.row.taxPrice);
            prop.row.money = isNaN(num) ? '' : num.toFixed(2);
          }
        }
        if (prop.col.key == 'taxPrice') {
          if (prop.row.taxPrice) {
            var num = prop.row.quantity * Number(prop.row.taxPrice);
            prop.row.money = isNaN(num) ? '' : num.toFixed(2);
          }
        }
      }
      function selectVirtualProducts() {
        SelectPrpductModalRef.value.getTableVirtual();
      }
      function addProduct(data) {
        data.map((item) => {
          item.productClass = item.classId_dictText;
          item.productCode = item.code;
          item.productId = item.id;
          item.id = undefined;
        });
        var xTable = deliveryDetailFormProductTableRef.value!.getXTable(); //关键代码 如果不更新 重新加载表格即可
        var arrProduct = xTable.data.concat(data);
        deliveryDetailFormProductTable.dataSource = arrProduct;
      }
      return {
        deliveryNoticeFormShipTableRef,
        deliveryNoticeFormShipTable,
        deliveryDetailFormProductTableRef,
        deliveryDetailFormProductTable,
        validatorRules,
        validateInfos,
        activeKey,
        loading,
        formData,
        setFieldsValue,
        handleFormChange,
        formItemLayout,
        disabled,
        getFormData,
        submitForm,
        SelectShipSModalRef,
        add,
        edit,
        formRef,
        BaseShipArchiveAccessoriesListRef,
        viewAccessory,
        handleDelete1,
        SelectProjectModalRef,
        onSearchProject,
        addProject,
        getOptiom,
        classOption,
        getCustomerOptions,
        customerOption,
        notAllowEdit,
        selectSaleOrderList,
        SelectSaleOrderModalRef,
        addFormSaleOrder,
        changeValues,
        selectVirtualProducts,
        SelectPrpductModalRef,
        addProduct,
      };
    },
  });
</script>
<style lang="less" scoped>
  /** 时间和数字输入框样式 */
  :deep(.ant-input-number) {
    width: 100%;
  }

  :deep(.ant-calendar-picker) {
    width: 100%;
  }
  /deep/.vxe-table--body-wrapper {
    height: 100% !important;
  }
  /deep/.ant-modal-body {
    padding: 24px !important;
  }

  /deep/.ant-form-item {
    margin-bottom: 8px !important;
  }

  /deep/.vxe-cell--valid-error-msg {
    color: white !important;
    background-color: white !important;
  }
</style>
