src/views/financialManagement/receivable/receipt.vue
@@ -171,10 +171,10 @@
                          prop="amount">
              <el-input-number v-model="form.amount"
                               :min="0"
                               :max="collectionAmountInputMax"
                               :precision="2"
                               style="width: 100%;"
                               :disabled="isView"
                               placeholder="根据关联单据自动汇总,可修改" />
                               :disabled="isView" />
            </el-form-item>
          </el-col>
        </el-row>
@@ -196,7 +196,7 @@
          <el-col :span="12">
            <el-form-item label="创建时间"
                          prop="createTime">
              <el-date-picker v-model="form.createTime"
              <el-date-picker v-model="formCreateTimeDate"
                              type="date"
                              placeholder="选择日期"
                              value-format="YYYY-MM-DD"
@@ -274,6 +274,12 @@
                         align="right">
          <template #default="{ row }">¥{{ formatMoney(row.outboundAmount) }}</template>
        </el-table-column>
        <el-table-column prop="amountReceived"
                         label="已收款金额"
                         width="110"
                         align="right">
          <template #default="{ row }">¥{{ formatMoney(row.amountReceived) }}</template>
        </el-table-column>
        <el-table-column prop="taxRate"
                         label="税率"
                         width="80"
@@ -299,6 +305,7 @@
    nextTick,
    getCurrentInstance,
  } from "vue";
  import dayjs from "dayjs";
  import { ElMessage, ElMessageBox } from "element-plus";
  import FormDialog from "@/components/Dialog/FormDialog.vue";
  import { listCustomer } from "@/api/basicData/customer.js";
@@ -361,6 +368,7 @@
  const isEdit = ref(false);
  const isView = ref(false);
  const currentId = ref(null);
  const originalReceiptAmount = ref(0);
  const submitLoading = ref(false);
  const customerList = ref([]);
@@ -392,6 +400,52 @@
    remark: "",
    createTime: "",
  });
  const formCreateTimeDate = computed({
    get: () => (form.createTime ? String(form.createTime).split(" ")[0] : ""),
    set: (value) => {
      form.createTime = value ? `${value} ${dayjs().format("HH:mm:ss")}` : "";
    },
  });
  const maxCollectionAmount = computed(() => {
    const selected = form.stockOutRecordIds || [];
    const editAmount = isEdit.value ? Number(originalReceiptAmount.value) || 0 : 0;
    if (!selected.length) return isEdit.value ? editAmount : undefined;
    const selectedValueSet = new Set(selected.map(id => String(id)));
    const selectedOptions = outboundBatchOptions.value.filter(
      opt => opt.amountLimitAvailable && selectedValueSet.has(String(opt.value))
    );
    if (selectedOptions.length !== selectedValueSet.size) {
      return isEdit.value ? Number(editAmount.toFixed(2)) : undefined;
    }
    const sum = selectedOptions.reduce(
      (acc, opt) => acc + (Number(opt.outboundAmount) || 0),
      0
    );
    return Number((sum + editAmount).toFixed(2));
  });
  const collectionAmountInputMax = computed(
    () => maxCollectionAmount.value ?? Number.MAX_SAFE_INTEGER
  );
  const validateCollectionAmount = (rule, value, callback) => {
    if (value === undefined || value === null || value === "") {
      callback();
      return;
    }
    const amount = Number(value);
    if (Number.isNaN(amount)) {
      callback(new Error("请输入收款金额"));
      return;
    }
    const max = maxCollectionAmount.value;
    if (max !== undefined && amount - max > 0.000001) {
      callback(new Error(`收款金额不能超过${max.toFixed(2)}`));
      return;
    }
    callback();
  };
  const rules = {
    customerId: [{ required: true, message: "请选择客户", trigger: "change" }],
@@ -407,7 +461,10 @@
    receiptDate: [
      { required: true, message: "请选择收款日期", trigger: "change" },
    ],
    amount: [{ required: true, message: "请输入收款金额", trigger: "blur" }],
    amount: [
      { required: true, message: "请输入收款金额", trigger: "blur" },
      { validator: validateCollectionAmount, trigger: ["blur", "change"] },
    ],
    receiptMethod: [
      { required: true, message: "请选择收款方式", trigger: "change" },
    ],
@@ -467,7 +524,12 @@
    return list.map((item, index) => {
      if (typeof item === "string" || typeof item === "number") {
        const text = String(item);
        return { label: text, value: text, outboundAmount: 0 };
        return {
          label: text,
          value: text,
          outboundAmount: 0,
          amountLimitAvailable: false,
        };
      }
      const label =
        item.outboundBatches ??
@@ -477,10 +539,15 @@
        item.label ??
        `出库单${index + 1}`;
      const value = item.id ?? item.stockOutRecordId ?? label;
      const outboundAmount = Number(item.outboundAmount) || 0;
      const amountReceived = Number(item.amountReceived) || 0;
      const availableAmount = outboundAmount - amountReceived;
      return {
        label: String(label),
        value,
        outboundAmount: Number(item.outboundAmount) || 0,
        outboundAmount:
          availableAmount > 0 ? Number(availableAmount.toFixed(2)) : 0,
        amountLimitAvailable: true,
      };
    });
  };
@@ -528,6 +595,7 @@
        label: String(id),
        value: id,
        outboundAmount: 0,
        amountLimitAvailable: false,
      });
    });
  };
@@ -630,6 +698,7 @@
    outboundSelectVisible.value = false;
    syncCollectionAmount();
    formRef.value?.validateField("stockOutRecordIds");
    formRef.value?.validateField("amount");
  };
  const handleOutboundDialogClosed = () => {
@@ -691,6 +760,7 @@
      stockOutRecordIds,
      outboundBatches: formatOutboundBatches(row.outboundBatches),
      remark: row.remark ?? "",
      createTime: row.createTime ?? "",
    });
  };
@@ -699,6 +769,7 @@
    outboundSelectVisible.value = false;
    isView.value = false;
    isEdit.value = false;
    originalReceiptAmount.value = 0;
  };
  const handleExport = () => {
@@ -758,6 +829,7 @@
    isEdit.value = false;
    isView.value = false;
    dialogTitle.value = "新增收款";
    originalReceiptAmount.value = 0;
    Object.assign(form, {
      receiptCode: "",
      customerId: "",
@@ -767,7 +839,7 @@
      stockOutRecordIds: [],
      outboundBatches: "",
      remark: "",
      createTime: new Date().toISOString().split("T")[0],
      createTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
    });
    outboundBatchList.value = [];
    outboundBatchOptions.value = [];
@@ -780,13 +852,16 @@
    currentId.value = row.id;
    dialogTitle.value = "编辑收款";
    fillFormFromRow(row);
    originalReceiptAmount.value = Number(form.amount || 0);
    dialogVisible.value = true;
    loadOutboundBatches(form.customerId, true);
  };
  const view = row => {
    isView.value = true;
    isEdit.value = false;
    dialogTitle.value = "查看收款";
    originalReceiptAmount.value = 0;
    fillFormFromRow(row);
    dialogVisible.value = true;
  };