yaowanxin
2025-12-22 23623551f46642c53c94593b90ab2d1c7e493258
src/views/salesManagement/salesLedger/index.vue
@@ -45,16 +45,22 @@
        <el-table-column align="center" type="selection" width="55" />
        <el-table-column type="expand">
          <template #default="props">
            <el-table :data="props.row.children" border show-summary :summary-method="summarizeChildrenTable">
              <el-table-column align="center" label="序号" type="index" width="60" />
              <el-table-column label="产品大类" prop="productCategory" />
              <el-table-column label="规格型号" prop="specificationModel" />
              <el-table-column label="单位" prop="unit" />
              <el-table-column label="数量" prop="quantity" />
              <el-table-column label="税率(%)" prop="taxRate" />
              <el-table-column label="含税单价(元)" prop="taxInclusiveUnitPrice" :formatter="formattedNumber" />
              <el-table-column label="含税总价(元)" prop="taxInclusiveTotalPrice" :formatter="formattedNumber" />
              <el-table-column label="不含税总价(元)" prop="taxExclusiveTotalPrice" :formatter="formattedNumber" />
            <el-table :data="props.row.children" border show-summary :summary-method="summarizeChildrenTable" style="min-width: 1200px;"
                      scrollbar-always-on>
              <el-table-column align="center" label="序号" type="index" width="70" />
              <el-table-column label="产品大类" prop="productCategory" width="160" />
              <el-table-column label="规格型号" prop="specificationModel" width="220" />
              <el-table-column label="单位" prop="unit" width="100" />
              <el-table-column label="数量" prop="quantity" width="120" />
              <el-table-column label="税率(%)" prop="taxRate" width="120" />
              <el-table-column label="含税单价(元)" prop="taxInclusiveUnitPrice" :formatter="formattedNumber" width="160" />
              <el-table-column label="含税总价(元)" prop="taxInclusiveTotalPrice" :formatter="formattedNumber" width="180" />
              <el-table-column label="不含税总价(元)" prop="taxExclusiveTotalPrice" :formatter="formattedNumber" width="180" />
              <el-table-column fixed="right" label="操作" width="150" align="center">
                <template #default="scope">
                  <el-button link type="primary" size="small" @click="openDeliveryForm(props.row, scope.row)">发货</el-button>
                </template>
              </el-table-column>
            </el-table>
          </template>
        </el-table-column>
@@ -70,12 +76,11 @@
        <el-table-column label="录入人" prop="entryPersonName" width="100" show-overflow-tooltip />
        <el-table-column label="录入日期" prop="entryDate" width="120" show-overflow-tooltip />
        <el-table-column label="签订日期" prop="executionDate" width="120" show-overflow-tooltip />
        <el-table-column fixed="right" label="操作" min-width="200" align="center">
        <el-table-column fixed="right" label="操作" min-width="150" align="center">
          <template #default="scope">
            <el-button link type="primary" size="small" :disabled="scope.row.invoiceTotal>0 || scope.row.entryPersonName !== userStore.nickName" @click="openForm('edit', scope.row)">编辑</el-button>
            <el-button link type="primary" size="small" @click="openForm('edit', scope.row)">编辑</el-button>
<!--            <el-button link type="primary" size="small" @click="openForm('view', scope.row)">详情</el-button>-->
            <el-button link type="primary" size="small" @click="downLoadFile(scope.row)">附件</el-button>
            <el-button link type="primary" size="small" @click="openDeliveryForm(scope.row)">发货</el-button>
          </template>
        </el-table-column>
      </el-table>
@@ -142,7 +147,7 @@
          <el-col :span="12">
            <el-form-item label="录入日期:" prop="entryDate">
              <el-date-picker style="width: 100%" v-model="form.entryDate" value-format="YYYY-MM-DD" format="YYYY-MM-DD"
                type="date" placeholder="请选择" clearable disabled />
                type="date" placeholder="请选择" clearable />
            </el-form-item>
          </el-col>
        </el-row>
@@ -477,6 +482,10 @@
import { modelList, productTreeList } from "@/api/basicData/product.js";
import useFormData from "@/hooks/useFormData.js";
import dayjs from "dayjs";
import {
  getStockInPage
} from "@/api/inventoryManagement/stockIn.js";
const userStore = useUserStore();
const { proxy } = getCurrentInstance();
@@ -588,7 +597,7 @@
// 发货相关
const deliveryFormVisible = ref(false);
const currentDeliveryRow = ref(null);
const currentDeliveryContext = ref(null);
const deliveryFormData = reactive({
  deliveryForm: {
    shippingDate: "",
@@ -1523,13 +1532,48 @@
}
// 打开发货弹框
const openDeliveryForm = (row) => {
  currentDeliveryRow.value = row;
  deliveryForm.value = {
    shippingDate: getCurrentDate(),
    shippingCarNumber: "",
  };
  deliveryFormVisible.value = true;
const openDeliveryForm = async (parentRow, productRow) => {
  // productRow的minStock和quantity
  console.log('22222', productRow)
  // 检查产品库存是否足够
  const requiredQuantity = productRow.quantity || 0;  // 需要发货的数量
  try {
    // 等待获取库存信息
    const res = await getStockInPage({
      current: 1,
      size: 100
    });
    // console.log('res33333', res.data.records)
    // 通过 productRow.id 过滤出对应的库存记录
    const matchingStockRecords = res.data?.records?.filter(record =>
        record.salesLedgerProductId === productRow.id
    ) || [];
    // 计算匹配记录的总库存数量
    const currentStock = matchingStockRecords.reduce((total, record) => {
      return total + (record.inboundNum0 || 0);
    }, 0);
    // 检查库存是否充足
    if (currentStock < requiredQuantity) {
      // 库存不足提示
      proxy.$modal.msgWarning(`产品库存不足`);
      return;
    }
    // 库存充足,继续打开发货弹框
    currentDeliveryContext.value = { parentRow, productRow };
    deliveryForm.value = {
      shippingDate: getCurrentDate(),
      shippingCarNumber: "",
    };
    deliveryFormVisible.value = true;
  } catch (error) {
    console.error('获取库存信息失败:', error);
    proxy.$modal.msgError("获取库存信息失败,请重试");
  }
};
// 提交发货表单
@@ -1537,14 +1581,14 @@
  proxy.$refs["deliveryFormRef"].validate((valid) => {
    if (valid) {
      addShippingInfo({
        salesLedgerId: currentDeliveryRow.value.id,
        salesLedgerId: currentDeliveryContext.value.parentRow.id,
        salesLedgerProductId: currentDeliveryContext.value.productRow.id,
        shippingDate: deliveryForm.value.shippingDate,
        shippingCarNumber: deliveryForm.value.shippingCarNumber,
      })
        .then(() => {
          proxy.$modal.msgSuccess("发货成功");
          closeDeliveryDia();
          getList();
        })
        .catch(() => {
          proxy.$modal.msgError("发货失败,请重试");
@@ -1557,7 +1601,7 @@
const closeDeliveryDia = () => {
  proxy.resetForm("deliveryFormRef");
  deliveryFormVisible.value = false;
  currentDeliveryRow.value = null;
  currentDeliveryContext.value = null;
};
onMounted(() => {