gaoluyang
2026-06-12 ac00bb7b8eae1bf6aabb7f1ae67c2e5aa5b8ae90
src/views/salesManagement/salesLedger/index.vue
@@ -158,6 +158,10 @@
              </el-table-column>
              <el-table-column label="数量"
                               prop="quantity" />
              <el-table-column label="每件数量"
                               prop="singleQuantity" />
              <el-table-column label="总数"
                               prop="totalQuantity" />
              <el-table-column label="待发货数量"
                               prop="noQuantity" />
              <el-table-column label="税率(%)"
@@ -243,7 +247,7 @@
            <el-button link
                       type="primary"
                       @click="openForm('edit', scope.row)"
                       :disabled="!scope.row.isEdit || scope.row.hasProductionRecord || !canEditLedger(scope.row)">编辑
                       :disabled="!canEditLedger(scope.row)">编辑
            </el-button>
            <el-button link
                       type="primary"
@@ -287,10 +291,15 @@
          <el-col :span="12">
            <el-form-item label="销售合同号:"
                          prop="salesContractNo">
              <el-input v-model="form.salesContractNo"
                        placeholder="自动生成"
                        clearable
                        disabled />
              <div style="display: flex; align-items: center; gap: 12px;width: 100%;">
                <el-checkbox v-model="form.autoGenerateContractNo" v-if="operationType === 'add'">自动生成
                </el-checkbox>
                <el-input v-model="form.salesContractNo"
                          :placeholder="form.autoGenerateContractNo ? '自动生成' : '请输入'"
                          clearable
                          :disabled="form.autoGenerateContractNo" />
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
@@ -443,6 +452,10 @@
                           prop="unit" />
          <el-table-column label="数量"
                           prop="quantity" />
          <el-table-column label="每件数量"
                           prop="singleQuantity" />
          <el-table-column label="总数"
                           prop="totalQuantity" />
          <el-table-column label="税率(%)"
                           prop="taxRate" />
          <el-table-column label="含税单价(元)"
@@ -679,6 +692,30 @@
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="每件数量:"
                          prop="singleQuantity">
              <el-input-number :step="1"
                               :min="1"
                               v-model="productForm.singleQuantity"
                               placeholder="请输入"
                               clearable
                               :precision="0"
                               @change="calculateFromSingleQuantity"
                               style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总数:"
                          prop="totalQuantity">
              <el-input v-model="productForm.totalQuantity"
                        placeholder="自动计算"
                        disabled
                        style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="含税总价(元):"
                          prop="taxInclusiveTotalPrice">
              <el-input v-model="productForm.taxInclusiveTotalPrice"
@@ -888,7 +925,7 @@
    <!-- 发货弹框 -->
    <el-dialog v-model="deliveryFormVisible"
               title="发货信息"
               width="40%"
               width="70%"
               @close="closeDeliveryDia">
      <el-form :model="deliveryForm"
               label-width="120px"
@@ -954,7 +991,7 @@
        </el-row>
        <el-row :gutter="30">
          <el-col :span="24">
            <el-form-item label="批号:"
            <el-form-item label="库存:"
                          prop="batchNo">
              <el-table :data="deliveryForm.batchNoList"
                        border
@@ -964,6 +1001,15 @@
                <el-table-column label="批号"
                                 prop="batchNo"
                                 min-width="180" />
                <el-table-column label="产品大类"
                                 prop="productName"
                                 min-width="100" />
                <el-table-column label="规格型号"
                                 prop="model"
                                 min-width="100" />
                <el-table-column label="单位"
                                 prop="unit"
                                 min-width="100" />
                <el-table-column label="库存数量"
                                 min-width="120"
                                 align="center">
@@ -1072,6 +1118,7 @@
    },
    form: {
      salesContractNo: "",
      autoGenerateContractNo: true,
      salesman: "",
      customerId: "",
      entryPerson: "",
@@ -1080,7 +1127,6 @@
      maintenanceTime: "",
      productData: [],
      executionDate: "",
      hasProductionRecord: false,
    },
    rules: {
      salesman: [{ required: true, message: "请选择", trigger: "change" }],
@@ -1103,6 +1149,8 @@
      specificationModel: "",
      unit: "",
      quantity: "",
      singleQuantity: 1,
      totalQuantity: "",
      taxInclusiveUnitPrice: "",
      taxRate: "",
      taxInclusiveTotalPrice: "",
@@ -1590,6 +1638,8 @@
      form.value.entryDate = getCurrentDate();
      // 签订日期默认为当天
      form.value.executionDate = getCurrentDate();
      // 默认自动生成销售合同号
      form.value.autoGenerateContractNo = true;
    } else {
      currentId.value = row.id;
      getSalesLedgerWithProducts({ id: row.id, type: 1 }).then(res => {
@@ -1597,6 +1647,8 @@
        form.value.entryPerson = Number(res.entryPerson);
        productData.value = form.value.productData;
        fileList.value = form.value.storageBlobVOs;
        // 编辑时设置自动生成为false,允许手动修改
        form.value.autoGenerateContractNo = false;
      });
    }
    // let userAll = await userStore.getInfo()
@@ -1690,6 +1742,7 @@
    productData.value = products.map(p => {
      const quantity = Number(p.quantity ?? 0) || 0;
      const unitPrice = Number(p.unitPrice ?? 0) || 0;
      const singleQuantity = 1;
      const taxRate = "13"; // 默认 13%,便于直接提交(如需可在产品中自行修改)
      const taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(2);
      const taxExclusiveTotalPrice = proxy.calculateTaxExclusiveTotalPrice(
@@ -1702,12 +1755,16 @@
        specificationModel: p.specification || "",
        unit: p.unit || "",
        quantity: quantity,
        singleQuantity: singleQuantity,
        totalQuantity: String(quantity * singleQuantity),
        taxRate: taxRate,
        taxInclusiveUnitPrice: unitPrice.toFixed(2),
        taxInclusiveTotalPrice: taxInclusiveTotalPrice,
        taxExclusiveTotalPrice: taxExclusiveTotalPrice,
        invoiceType: "增普票",
        isProduction: true,
        productId: p.productId,
        productModelId: p.productModelId
      };
    });
@@ -1731,6 +1788,9 @@
        }
        form.value.storageBlobDTOs = fileList;
        form.value.type = 1;
        if (form.value.autoGenerateContractNo) {
          form.value.salesContractNo = '';
        }
        addOrUpdateSalesLedger(form.value).then(res => {
          proxy.$modal.msgSuccess("提交成功");
          closeDia();
@@ -1764,6 +1824,12 @@
    if (type === "edit") {
      productForm.value = { ...row };
      productIndex.value = index;
      // 如果没有 totalQuantity,自动计算:总数 = 每件数量 * 数量
      if (!productForm.value.totalQuantity && productForm.value.quantity) {
        const singleQuantity = parseInt(productForm.value.singleQuantity) || 1;
        const quantity = parseFloat(productForm.value.quantity);
        productForm.value.totalQuantity = (quantity * singleQuantity).toFixed(0);
      }
      // 编辑时根据产品大类名称反查 tree 节点 id,并加载规格型号列表
      try {
        const options =
@@ -2445,6 +2511,10 @@
        );
    }
    // 计算总数 = 每件数量 * 数量
    const singleQuantity = parseInt(productForm.value.singleQuantity) || 1;
    productForm.value.totalQuantity = (quantity * singleQuantity).toFixed(0);
    isCalculating.value = false;
  };
@@ -2478,6 +2548,10 @@
      inclusiveTotalPrice / quantity
    ).toFixed(2);
    // 计算总数 = 每件数量 * 数量
    const singleQuantity = parseInt(productForm.value.singleQuantity) || 1;
    productForm.value.totalQuantity = (quantity * singleQuantity).toFixed(0);
    isCalculating.value = false;
  };
@@ -2498,7 +2572,7 @@
    isCalculating.value = true;
    // 计算含税总价
    // 计算含税总价 = 单价 * 数量
    productForm.value.taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(2);
    // 如果有税率,计算不含税总价
@@ -2509,6 +2583,10 @@
          productForm.value.taxRate
        );
    }
    // 计算总数 = 每件数量 * 数量
    const singleQuantity = parseInt(productForm.value.singleQuantity) || 1;
    productForm.value.totalQuantity = (quantity * singleQuantity).toFixed(0);
    isCalculating.value = false;
  };
@@ -2530,7 +2608,7 @@
    isCalculating.value = true;
    // 计算含税总价
    // 计算含税总价 = 单价 * 数量
    productForm.value.taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(2);
    // 如果有税率,计算不含税总价
@@ -2541,6 +2619,25 @@
          productForm.value.taxRate
        );
    }
    isCalculating.value = false;
  };
  // 根据每件数量变化计算总数
  const calculateFromSingleQuantity = () => {
    if (isCalculating.value) return;
    const quantity = parseFloat(productForm.value.quantity);
    if (!quantity || quantity <= 0) {
      return;
    }
    isCalculating.value = true;
    // 计算总数 = 每件数量 * 数量
    const singleQuantity = parseInt(productForm.value.singleQuantity) || 1;
    productForm.value.totalQuantity = (quantity * singleQuantity).toFixed(0);
    isCalculating.value = false;
  };
@@ -2715,6 +2812,22 @@
    const batchNoList = await getDeliveryBatchNoList(
      row.productModelId || row.modelId
    );
    // 自动分配发货数量:按照待发货数量,从上到下依次分配
    const noQuantity = Number(row?.noQuantity || 0);
    let remainingQuantity = noQuantity;
    batchNoList.forEach(item => {
      if (remainingQuantity <= 0) {
        item.deliveryQuantity = 0;
        return;
      }
      const batchStockQuantity = getDeliveryBatchQuantity(item);
      // 当前批次可分配的数量:取剩余待发货数量和库存数量的较小值
      const assignQuantity = Math.min(remainingQuantity, batchStockQuantity);
      item.deliveryQuantity = assignQuantity;
      remainingQuantity -= assignQuantity;
    });
    deliveryForm.value = {
      shippingCarNumber: "",
      expressCompany: "",
@@ -3041,4 +3154,4 @@
      page-break-after: avoid;
    }
  }
</style>
</style>