gongchunyi
2 天以前 0a251e40e30e7c8a96d71b3b9b6c459d4dfa4b22
src/views/salesManagement/salesLedger/index.vue
@@ -123,9 +123,11 @@
              </el-table-column>
              <el-table-column label="快递公司"
                               prop="expressCompany"
                               v-if="false"
                               show-overflow-tooltip />
              <el-table-column label="快递单号"
                               prop="expressNumber"
                               v-if="false"
                               show-overflow-tooltip />
              <el-table-column label="发货车牌"
                               minWidth="100px"
@@ -566,7 +568,7 @@
                         width="160"
                         align="right">
          <template #default="scope">
            {{ Number(scope.row.totalAmount ?? 0).toFixed(2) }}
            {{ formatDecimal(scope.row.totalAmount) }}
          </template>
        </el-table-column>
        <el-table-column fixed="right"
@@ -664,11 +666,11 @@
          <el-col :span="12">
            <el-form-item label="含税单价(元):"
                          prop="taxInclusiveUnitPrice">
              <el-input-number :step="0.01"
              <el-input-number :step="0.000001"
                               :min="0"
                               v-model="productForm.taxInclusiveUnitPrice"
                               style="width: 100%"
                               :precision="2"
                               :precision="6"
                               placeholder="请输入"
                               clearable
                               @change="calculateFromUnitPrice" />
@@ -722,17 +724,38 @@
              </el-select>
            </el-form-item>
          </el-col>
<!--          <el-col :span="12">
          <el-col :span="12">
            <el-form-item label="是否生产:"
                          prop="isProduction">
              <el-radio-group v-model="productForm.isProduction">
                <el-radio label="是"
                          :value="true" />
                <el-radio label="否"
                          :value="false" />
              </el-radio-group>
              <div style="display: flex; align-items: center; width: 100%;">
                <el-radio-group v-model="productForm.isProduction">
                  <el-radio label="是"
                            :value="true" />
                  <el-radio label="否"
                            :value="false" />
                </el-radio-group>
                <div
                  v-if="currentStock !== null"
                  :style="{
                    marginLeft: '20px',
                    padding: '0 12px',
                    height: '28px',
                    lineHeight: '28px',
                    borderRadius: '4px',
                    fontSize: '13px',
                    fontWeight: '500',
                    display: 'inline-block',
                    whiteSpace: 'nowrap',
                    backgroundColor: (productForm.quantity || 0) > currentStock ? '#fff0f0' : '#f0f9eb',
                    border: (productForm.quantity || 0) > currentStock ? '1px solid #ffcccc' : '1px solid #e1f3d8',
                    color: (productForm.quantity || 0) > currentStock ? '#f56c6c' : '#67c23a'
                  }"
                >
                  <span>当前库存:{{ currentStock }} {{ productForm.unit || '' }}</span>
                </div>
              </div>
            </el-form-item>
          </el-col>-->
          </el-col>
        </el-row>
      </el-form>
    </FormDialog>
@@ -917,6 +940,7 @@
                <el-option label="货车"
                           value="货车" />
                <el-option label="快递"
                           v-if="false"
                           value="快递" />
              </el-select>
            </el-form-item>
@@ -939,7 +963,7 @@
            </el-form-item>
          </el-col>
          <el-col :span="24"
                  v-else>
                  v-else-if="false">
            <el-form-item label="快递公司:"
                          prop="expressCompany">
              <el-input v-model="deliveryForm.expressCompany"
@@ -949,7 +973,7 @@
          </el-col>
        </el-row>
        <el-row :gutter="30"
                v-if="deliveryForm.type === '快递'">
                v-if="false">
          <el-col :span="24">
            <el-form-item label="快递单号:"
                          prop="expressNumber">
@@ -1017,6 +1041,7 @@
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary"
                     :loading="deliveryLoading"
                     @click="submitDelivery">确认发货
          </el-button>
          <el-button @click="closeDeliveryDia">取消</el-button>
@@ -1053,6 +1078,11 @@
  import useFormData from "@/hooks/useFormData.js";
  import dayjs from "dayjs";
  import FileUpload from "@/components/AttachmentUpload/file/index.vue";
  import {
    tableAmountFormatter,
    formatDecimal,
    buildAmountSummaryFormat,
  } from "@/utils/numberFormat";
  import ImageUpload from "@/components/AttachmentUpload/image/index.vue";
  import { getCurrentDate } from "@/utils/index.js";
  import { listCustomer } from "@/api/basicData/customer.js";
@@ -1182,6 +1212,7 @@
  // 发货相关
  const deliveryFormVisible = ref(false);
  const deliveryLoading = ref(false);
  const currentDeliveryRow = ref(null);
  const getDeliveryBatchQuantity = item => {
    const quantity =
@@ -1192,6 +1223,27 @@
      item?.qualifiedQuantity ??
      item?.stockQuantity;
    return quantity ?? 0;
  };
  const currentStock = ref(null);
  const fetchCurrentStock = async (productModelId) => {
    if (!productModelId) {
      currentStock.value = null;
      return;
    }
    try {
      const res = await getStockInventoryByModelId(productModelId);
      const rawList = Array.isArray(res?.data)
        ? res.data
        : res?.data?.records || res?.data?.rows || [];
      let total = 0;
      rawList.forEach(item => {
        total += Number(getDeliveryBatchQuantity(item) || 0);
      });
      currentStock.value = total;
    } catch (e) {
      console.error(e);
      currentStock.value = 0;
    }
  };
  const getCurrentDeliveryRowQuantity = () => {
    return Number(currentDeliveryRow.value?.noQuantity || 0);
@@ -1396,12 +1448,7 @@
      return productOptions.value;
    });
  };
  const formattedNumber = (row, column, cellValue) => {
    if (cellValue === undefined || cellValue === null || cellValue === "") {
      return "0.00";
    }
    return parseFloat(cellValue).toFixed(2);
  };
  const formattedNumber = tableAmountFormatter;
  const findLedgerRecordByRow = row => {
    if (!row) return null;
    if (
@@ -1458,6 +1505,7 @@
  // 获取tree子数据
  const getModels = value => {
    productForm.value.productCategory = findNodeById(productOptions.value, value);
    currentStock.value = null;
    modelList({ id: value }).then(res => {
      modelOptions.value = res;
    });
@@ -1467,9 +1515,11 @@
    if (index !== -1) {
      productForm.value.specificationModel = modelOptions.value[index].model;
      productForm.value.unit = modelOptions.value[index].unit;
      fetchCurrentStock(value);
    } else {
      productForm.value.specificationModel = null;
      productForm.value.unit = null;
      currentStock.value = null;
    }
  };
  const findNodeById = (nodes, productId) => {
@@ -1564,11 +1614,15 @@
  };
  // 主表合计方法
  const summarizeMainTable = param => {
    return proxy.summarizeTable(param, [
      "contractAmount",
      "taxInclusiveTotalPrice",
      "taxExclusiveTotalPrice",
    ]);
    return proxy.summarizeTable(
      param,
      ["contractAmount", "taxInclusiveTotalPrice", "taxExclusiveTotalPrice"],
      buildAmountSummaryFormat([
        "contractAmount",
        "taxInclusiveTotalPrice",
        "taxExclusiveTotalPrice",
      ])
    );
  };
  // 子表合计方法
  const summarizeChildrenTable = (param, parentRow) => {
@@ -1590,11 +1644,19 @@
        return "";
      });
    }
    return proxy.summarizeTable(param, [
      "taxInclusiveUnitPrice",
      "taxInclusiveTotalPrice",
      "taxExclusiveTotalPrice",
    ]);
    return proxy.summarizeTable(
      param,
      [
        "taxInclusiveUnitPrice",
        "taxInclusiveTotalPrice",
        "taxExclusiveTotalPrice",
      ],
      buildAmountSummaryFormat([
        "taxInclusiveUnitPrice",
        "taxInclusiveTotalPrice",
        "taxExclusiveTotalPrice",
      ])
    );
  };
  // 打开弹框
  const openForm = async (type, row) => {
@@ -1722,7 +1784,7 @@
      const quantity = Number(p.quantity ?? 0) || 0;
      const unitPrice = Number(p.unitPrice ?? 0) || 0;
      const taxRate = "13"; // 默认 13%,便于直接提交(如需可在产品中自行修改)
      const taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(2);
      const taxInclusiveTotalPrice = formatDecimal(unitPrice * quantity);
      const taxExclusiveTotalPrice = proxy.calculateTaxExclusiveTotalPrice(
        taxInclusiveTotalPrice,
        taxRate
@@ -1734,7 +1796,7 @@
        unit: p.unit || "",
        quantity: quantity,
        taxRate: taxRate,
        taxInclusiveUnitPrice: unitPrice.toFixed(2),
        taxInclusiveUnitPrice: formatDecimal(unitPrice),
        taxInclusiveTotalPrice: taxInclusiveTotalPrice,
        taxExclusiveTotalPrice: taxExclusiveTotalPrice,
        invoiceType: "增普票",
@@ -1793,6 +1855,7 @@
    productOperationType.value = type;
    productForm.value = {};
    currentStock.value = null;
    if (type === "add") {
      productForm.value.isProduction = true;
    }
@@ -1819,6 +1882,7 @@
          );
          if (currentModel) {
            productForm.value.productModelId = currentModel.id;
            fetchCurrentStock(currentModel.id);
          }
        }
      } catch (e) {
@@ -2408,7 +2472,7 @@
    const total = products.reduce((sum, product) => {
      return sum + (parseFloat(product.taxInclusiveTotalPrice) || 0);
    }, 0);
    return total.toFixed(2);
    return formatDecimal(total);
  };
  // 用于打印的计算函数
@@ -2425,7 +2489,7 @@
    const total = products.reduce((sum, product) => {
      return sum + (parseFloat(product.taxInclusiveTotalPrice) || 0);
    }, 0);
    return total.toFixed(2);
    return formatDecimal(total);
  };
  const mathNum = () => {
@@ -2466,7 +2530,7 @@
    isCalculating.value = true;
    // 计算含税单价 = 含税总价 / 数量
    productForm.value.taxInclusiveUnitPrice = (totalPrice / quantity).toFixed(2);
    productForm.value.taxInclusiveUnitPrice = formatDecimal(totalPrice / quantity);
    // 如果有税率,计算不含税总价
    if (productForm.value.taxRate) {
@@ -2503,12 +2567,12 @@
    // 先计算含税总价 = 不含税总价 / (1 - 税率/100)
    const taxRateDecimal = taxRate / 100;
    const inclusiveTotalPrice = exclusiveTotalPrice / (1 - taxRateDecimal);
    productForm.value.taxInclusiveTotalPrice = inclusiveTotalPrice.toFixed(2);
    productForm.value.taxInclusiveTotalPrice = formatDecimal(inclusiveTotalPrice);
    // 计算含税单价 = 含税总价 / 数量
    productForm.value.taxInclusiveUnitPrice = (
    productForm.value.taxInclusiveUnitPrice = formatDecimal(
      inclusiveTotalPrice / quantity
    ).toFixed(2);
    );
    isCalculating.value = false;
  };
@@ -2531,7 +2595,7 @@
    isCalculating.value = true;
    // 计算含税总价
    productForm.value.taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(2);
    productForm.value.taxInclusiveTotalPrice = formatDecimal(unitPrice * quantity);
    // 如果有税率,计算不含税总价
    if (productForm.value.taxRate) {
@@ -2563,7 +2627,7 @@
    isCalculating.value = true;
    // 计算含税总价
    productForm.value.taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(2);
    productForm.value.taxInclusiveTotalPrice = formatDecimal(unitPrice * quantity);
    // 如果有税率,计算不含税总价
    if (productForm.value.taxRate) {
@@ -2760,6 +2824,7 @@
        const productModelId =
          currentDeliveryRow.value.productModelId ||
          currentDeliveryRow.value.modelId;
        deliveryLoading.value = true;
        addShippingInfo({
          salesLedgerId: salesLedgerId,
          salesLedgerProductId: currentDeliveryRow.value.id,
@@ -2810,6 +2875,8 @@
              });
            }
          });
        }).finally(() => {
            deliveryLoading.value = false;
        });
      }
    });