zhangwencui
2 天以前 dea83e911b593d564bb326492869fdfb1ba51a76
src/views/inventoryManagement/receiptManagement/index.vue
@@ -23,7 +23,9 @@
      </div>
      <div>
        <el-button type="primary"
                   @click="openForm('add')">新增入库</el-button>
                   @click="openFormadd('add')">订单入库</el-button>
        <el-button type="primary"
                   @click="openDirectForm('add')">新增入库</el-button>
        <el-button @click="handleOut">导出</el-button>
        <el-button type="danger"
                   plain
@@ -231,6 +233,72 @@
        </div>
      </template>
    </el-dialog>
    <!-- 直接新增入库对话框 -->
    <el-dialog v-model="directDialogVisible"
               title="新增入库"
               width="70%"
               @close="closeDirectDia">
      <el-form :model="directForm"
               label-width="140px"
               label-position="top"
               :rules="directRules"
               ref="directFormRef">
        <el-form :model="directQuery"
                 class="mb-2">
          <el-form-item label="产品大类">
            <el-select v-model="directQuery.productCategory"
                       placeholder="请选择产品大类"
                       clearable
                       filterable
                       @change="handleProductCategoryChange">
              <el-option v-for="item in productList"
                         :key="item.id"
                         :label="item.productName"
                         :value="item.productName" />
            </el-select>
          </el-form-item>
          <el-form-item label="规格型号">
            <el-select v-model="directQuery.productModelId"
                       placeholder="请先选择产品大类"
                       clearable
                       filterable
                       :disabled="!directQuery.productCategory">
              <el-option v-for="item in productModelList"
                         :key="item.id"
                         :label="item.model"
                         :value="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="入库数量">
            <el-input v-model="directQuery.inboundQuantity"
                      placeholder="输入入库数量"
                      clearable />
          </el-form-item>
          <el-form-item label="预警数量">
            <el-input v-model="directQuery.warnNum"
                      placeholder="输入预警数量"
                      clearable />
          </el-form-item>
          <el-form-item label="缺货数量">
            <el-input v-model="directQuery.outStockQuantity"
                      placeholder="输入缺货数量"
                      clearable />
          </el-form-item>
          <el-form-item label="缺货情况">
            <el-input v-model="directQuery.shortageDescription"
                      placeholder="输入缺货情况"
                      clearable />
          </el-form-item>
        </el-form>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary"
                     @click="submitDirectForm">确认</el-button>
          <el-button @click="closeDirectDia">取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
@@ -245,8 +313,10 @@
    addSutockIn,
    delStockIn,
    selectProductRecordListByPuechaserId,
    addProduct,
  } from "@/api/inventoryManagement/stockIn.js";
  import { purchaseListPage } from "@/api/procurementManagement/procurementLedger.js";
  import { productTreeList, modelList } from "@/api/basicData/product.js";
  const userStore = useUserStore();
  const { proxy } = getCurrentInstance();
@@ -304,8 +374,56 @@
        { required: true, message: "请输入入库批次", trigger: "blur" },
      ],
    },
    // 直接新增入库相关
    directDialogVisible: false,
    directForm: {
      id: null,
      productId: null,
      productModel: "",
      inboundQuantity: 0,
      warnNum: 0,
      outStockQuantity: 0,
      shortageDescription: "",
    },
    directRules: {
      supplierId: [
        { required: true, message: "请选择供应商", trigger: "change" },
      ],
      inboundTime: [
        { required: true, message: "请选择入库时间", trigger: "change" },
      ],
      inboundBatch: [
        { required: true, message: "请输入入库批次", trigger: "blur" },
      ],
    },
    directQuery: {
      productId: null,
      productModelId: null,
      inboundQuantity: 0,
      warnNum: 0,
      outStockQuantity: 0,
      shortageDescription: "",
    },
    directProductList: [],
    directLoading: false,
    directSelectedRows: [],
    // 产品相关
    productList: [],
    productModelList: [],
  });
  const { searchForm, form, rules } = toRefs(data);
  const {
    searchForm,
    form,
    rules,
    directDialogVisible,
    directForm,
    directRules,
    directQuery,
    directProductList,
    directLoading,
    directSelectedRows,
    productModelList,
  } = toRefs(data);
  const formatPurchaseOption = (item = {}) => {
    const contract = item.purchaseContractNumber || "--";
@@ -441,9 +559,7 @@
      loadingProducts.value = false;
    }
  };
  // 打开弹框
  const openForm = async (type, row) => {
  const openFormadd = async (type, row) => {
    operationType.value = type;
    dialogFormVisible.value = true;
    selectedRows.value = [];
@@ -491,6 +607,215 @@
        loadingProducts.value = false;
      }
    }
  };
  // 打开订单入库弹框
  const openForm = async (type, row) => {
    if (row.salesLedgerProductId) {
      operationType.value = type;
      dialogFormVisible.value = true;
      selectedRows.value = [];
      await loadPurchaseOptions();
      if (type === "add") {
        // 新增时初始化表单
        form.value = {
          id: null,
          purchaseContractNumber: "",
          supplierId: null,
          supplierName: "",
          inboundTime: "",
          inboundBatch: "",
          recorderId: userStore.userId,
          recorderName: userStore.name,
          entryDate: getCurrentDate(),
          remark: "",
        };
        productList.value = []; // 清空产品列表
      } else {
        form.value = JSON.parse(JSON.stringify(row));
        try {
          loadingProducts.value = true;
          // 根据合同号加载对应的产品列表(假设 getProductByContract 是可用接口)
          const res = await selectProductRecordListByPuechaserId({
            purchaseContractNumber: form.value.purchaseContractNumber,
            id: row.id,
          });
          productList.value = res.data.map(item => ({
            ...item,
            quantityStock: Number(
              item.quantityStock ?? item.inboundQuantity ?? row.inboundNum ?? 0
            ),
            originalQuantityStock: Number(
              item.quantityStock ?? item.inboundQuantity ?? row.inboundNum ?? 0
            ),
          }));
          selectedRows.value = productList.value;
        } catch (error) {
          console.error("加载产品失败:", error);
          proxy.$modal.msgError("加载产品失败");
          productList.value = [];
        } finally {
          loadingProducts.value = false;
        }
      }
    } else {
      // 直接新增入库
      openDirectForm(type, row);
    }
  };
  // 打开直接新增入库弹框
  const openDirectForm = (type, row) => {
    directDialogVisible.value = true;
    directSelectedRows.value = [];
    directQuery.value = {
      productId: null,
      productModelId: null,
      inboundQuantity: 0,
      warnNum: 0,
      outStockQuantity: 0,
      shortageDescription: "",
    };
    directProductList.value = [];
    directForm.value = {
      id: null,
      supplierId: null,
      supplierName: "",
      inboundTime: "",
      inboundBatch: "",
      recorderId: userStore.userId,
      recorderName: userStore.name,
      entryDate: getCurrentDate(),
      remark: "",
    };
    if (type === "edit" && row) {
      // 编辑模式,回显数据
      directForm.value = { ...row };
      // 回显产品大类
      const selectedProduct = productList.value.find(
        item => item.productName === row.productCategory
      );
      if (selectedProduct) {
        directQuery.value.productId = selectedProduct.id;
        // 根据产品大类加载规格型号列表并回显
        loadProductModelList(selectedProduct.id).then(() => {
          // 回显规格型号
          directQuery.value.productCategory = row.productCategory || "";
          directQuery.value.productModelId = row.productModelId;
          // 回显其他字段
          directQuery.value.inboundQuantity =
            row.inboundNum || row.inboundQuantity;
          directQuery.value.warnNum = row.warnNum || 0;
          directQuery.value.outStockQuantity = row.outStockQuantity || 0;
          directQuery.value.shortageDescription = row.shortageDescription || "";
        });
      }
    }
  };
  // 加载产品大类列表
  const loadProductList = async () => {
    try {
      const res = await productTreeList();
      productList.value = res;
    } catch (error) {
      console.error("加载产品大类失败:", error);
      proxy.$modal.msgError("加载产品大类失败");
    }
  };
  // 处理产品大类变化
  const handleProductCategoryChange = value => {
    directQuery.value.specificationModel = "";
    productModelList.value = [];
    if (value) {
      // 根据产品大类加载规格型号列表
      const selectedProduct = productList.value.find(
        item => item.productName === value
      );
      if (selectedProduct) {
        loadProductModelList(selectedProduct.id);
      }
    }
  };
  // 加载产品型号列表
  const loadProductModelList = async productId => {
    try {
      const res = await modelList({ id: productId });
      productModelList.value = res;
    } catch (error) {
      console.error("加载规格型号失败:", error);
      proxy.$modal.msgError("加载规格型号失败");
    }
  };
  // 直接新增入库搜索产品
  const onDirectSearch = async () => {
    try {
      directLoading.value = true;
      // 这里需要调用产品搜索API,暂时模拟数据
      // 实际项目中应该调用真实的产品查询接口
      directProductList.value = [
        {
          id: 1,
          productCategory: "电子产品",
          specificationModel: "A-100",
          unit: "个",
          quantityStock: 0,
          outStockQuantity: 0,
          shortageDescription: "",
          taxRate: 13,
          taxInclusiveUnitPrice: 100,
        },
        {
          id: 2,
          productCategory: "电子产品",
          specificationModel: "A-200",
          unit: "个",
          quantityStock: 0,
          outStockQuantity: 0,
          shortageDescription: "",
          taxRate: 13,
          taxInclusiveUnitPrice: 200,
        },
        {
          id: 3,
          productCategory: "办公用品",
          specificationModel: "B-100",
          unit: "套",
          quantityStock: 0,
          outStockQuantity: 0,
          shortageDescription: "",
          taxRate: 13,
          taxInclusiveUnitPrice: 50,
        },
      ];
    } catch (error) {
      console.error("搜索产品失败:", error);
      proxy.$modal.msgError("搜索产品失败");
      directProductList.value = [];
    } finally {
      directLoading.value = false;
    }
  };
  // 直接新增入库重置搜索
  const onDirectReset = () => {
    directQuery.value = {
      productId: null,
      productModelId: null,
      inboundQuantity: 0,
      warnNum: 0,
      outStockQuantity: 0,
      shortageDescription: "",
    };
    directProductList.value = [];
  };
  // 处理直接新增入库产品选择
  const handleDirectSelectionChange = selection => {
    directSelectedRows.value = selection.filter(item => item.id);
  };
  const updatePro = async () => {
@@ -583,10 +908,50 @@
    }
  };
  // 关闭弹框
  // 关闭订单入库弹框
  const closeDia = () => {
    proxy.$refs.formRef.resetFields();
    dialogFormVisible.value = false;
  };
  // 关闭直接新增入库弹框
  const closeDirectDia = () => {
    if (proxy.$refs.directFormRef) {
      proxy.$refs.directFormRef.resetFields();
    }
    directDialogVisible.value = false;
  };
  // 提交直接新增入库表单
  const submitDirectForm = async () => {
    // 验证至少选择了一个产品
    console.log(directQuery.value, "directQuery.value");
    if (!directQuery.value.productModelId) {
      proxy.$modal.msgWarning("请先选择产品及规格型号");
      return;
    }
    await proxy.$refs.directFormRef.validate();
    if (directQuery.value.inboundQuantity <= 0) {
      proxy.$modal.msgError("本次入库数量需大于0");
      return;
    }
    // 准备提交数据
    const submitData = {
      ...directQuery.value,
      // 如果是编辑模式,添加id
      ...(directForm.value.id && { id: directForm.value.id }),
    };
    addProduct(submitData).then(res => {
      if (res.code === 200) {
        proxy.$modal.msgSuccess("操作成功");
        closeDirectDia();
        getList(); // 刷新列表
      } else {
        proxy.$modal.msgError(res.msg || "操作失败");
      }
    });
  };
  // 表格选择数据
  const handleSelectionChange = selection => {
@@ -679,6 +1044,7 @@
  onMounted(() => {
    getList();
    loadProductList();
  });
</script>