src/views/inventoryManagement/issueManagement/index.vue
@@ -53,8 +53,15 @@
    </div>
    <el-dialog v-model="dialogFormVisible" :title="'新增出库'" width="40%" @close="closeDia">
      <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef">
        <el-form-item label="出库数量:" prop="salesContractNo">
        <el-form-item label="出库数量:" prop="inboundQuantity">
          <el-input-number :step="0.01" :min="0" style="width: 100%" v-model="form.inboundQuantity" placeholder="请输入" clearable />
        </el-form-item>
        <el-form-item label="出库批次:" prop="batchNo">
          <el-select v-model="form.batchNo" placeholder="请选择出库批次" clearable filterable
            v-loading="batchLoading" style="width: 100%">
            <el-option v-for="item in batchOptions" :key="item.batchNo"
              :label="`${item.batchNo}(可用 ${item.availableQuantity})`" :value="item.batchNo" />
          </el-select>
        </el-form-item>
        <el-form-item label="出库日期:" prop="projectName">
          <el-date-picker style="width: 100%" v-model="form.inboundTime" value-format="YYYY-MM-DD" format="YYYY-MM-DD"
@@ -89,6 +96,7 @@
  getStockManagePage,
    delStockManage,
    stockOut,
    getBatchNoList,
} from "@/api/inventoryManagement/stockManage.js";
const userStore = useUserStore()
@@ -121,6 +129,7 @@
  rules: {
    inboundTime: [{ required: true, message: "请选择", trigger: "change" }],
    inboundQuantity: [{ required: true, message: "请输入", trigger: "blur" }],
    batchNo: [{ required: true, message: "请选择出库批次", trigger: "change" }],
    nickname: [{ required: true, message: "请选择", trigger: "change" }]
  }
})
@@ -179,6 +188,10 @@
const currentRowNum = ref(0)
const salesLedgerProductId = ref(null);
const currentRowProductModelId = ref(null)
// 出库批次可选项(可用量 = 库存量 - 锁定数量)
const batchOptions = ref([])
const batchLoading = ref(false)
// 打开弹框
const openForm = async (row) => {
@@ -186,15 +199,18 @@
  currentRowId.value = row.id
  currentRowNum.value = row.inboundNum0
  salesLedgerProductId.value = row.salesLedgerProductId
  currentRowProductModelId.value = row.productModelId
  form.value = {}
  // 初始化表单数据
  form.value = {
    productrecordId: '',
    inboundQuantity: '', // 出库数量清空
    batchNo: '', // 出库批次清空
    inboundTime: getCurrentDate(), // 默认当前日期
    nickName: '', // 默认当前用户
  }
  console.log('form',form.value)
  loadBatchOptions()
  // 加载用户列表
  try {
    const userLists = await userListNoPageByTenantId()
@@ -204,17 +220,47 @@
  }
}
// 加载规格型号下的可用批次
const loadBatchOptions = async () => {
  batchOptions.value = []
  if (!currentRowProductModelId.value) {
    proxy.$modal.msgWarning('当前记录缺少规格型号,无法查询出库批次')
    return
  }
  batchLoading.value = true
  try {
    const res = await getBatchNoList(currentRowProductModelId.value)
    batchOptions.value = res.data || []
  } catch (error) {
    console.error('查询出库批次失败:', error)
  } finally {
    batchLoading.value = false
  }
}
// 提交表单
const submitForm = () => {
  let num = Number(form.value.inboundQuantity)
  if(num <= 0 || num > currentRowNum.value){
    return proxy.$modal.msgWarning("请填入有效数字")
  }
  // 库存按批次管理、无先进先出,数量不能超过所选批次的可用量
  const selectedBatch = batchOptions.value.find(
    item => item.batchNo === form.value.batchNo
  )
  if (selectedBatch && num > Number(selectedBatch.availableQuantity)) {
    return proxy.$modal.msgWarning(
      `出库数量不能超过批次「${selectedBatch.batchNo}」的可用量 ${selectedBatch.availableQuantity}`
    )
  }
  proxy.$refs["formRef"].validate(valid => {
    if (valid && currentRowId.value) {
      const outData = {
        id: currentRowId.value, // 原始记录ID
        type: 2, // 2=销售出库,出库即自动生成发货台账
        salesLedgerProductId: salesLedgerProductId.value,
        productModelId: currentRowProductModelId.value,
        batchNo: form.value.batchNo, // 出库批次(销售出库必填)
        quantity: form.value.inboundQuantity, // 出库数量
        time: form.value.inboundTime, // 出库时间
        userId: form.value.nickName // 操作人