From 00119151c97919800d5ac62a63df6c09d15e1eed Mon Sep 17 00:00:00 2001 From: zhougf Date: Sun, 14 Dec 2025 19:09:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=90=E5=93=81=E6=B7=BB=E5=8A=A0=E5=8D=95?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/SimpleReceiptInController.cs | 81 ++++++++++++++--- .../Views/SimpleReceiptIn/Index.cshtml | 88 ++++++++++++++----- 2 files changed, 134 insertions(+), 35 deletions(-) diff --git a/HHWMS.Web/Areas/Receipt/Controllers/SimpleReceiptInController.cs b/HHWMS.Web/Areas/Receipt/Controllers/SimpleReceiptInController.cs index eacfb11..4f0e6c2 100644 --- a/HHWMS.Web/Areas/Receipt/Controllers/SimpleReceiptInController.cs +++ b/HHWMS.Web/Areas/Receipt/Controllers/SimpleReceiptInController.cs @@ -71,6 +71,7 @@ namespace HHWMS.Web.Controllers MaterialName = x.MaterialType, MaterialSpec = x.MaterialSpec, CompanyCode = x.CompanyCode, + x.SourceCode, Batch = x.Batch, Qty = (int)x.Qty }) @@ -133,39 +134,43 @@ namespace HHWMS.Web.Controllers } [HttpPost] - public ActionResult AddInventory(string containerCode, string materialCode, string company, string sourceCode, decimal qty, string batch) + public ActionResult AddInventory([FromBody] SimpleReceiptInModel model) { try { - if (string.IsNullOrEmpty(containerCode)) + if (string.IsNullOrEmpty(model.ContainerCode)) { return JsonMore(null, 500, "容器编码为空!"); } - if (string.IsNullOrEmpty(materialCode)) + if (string.IsNullOrEmpty(model.MaterialCode)) { return JsonMore(null, 500, "物料编码为空!"); } - if (qty <= 0) + if (model.Qty <= 0) { return JsonMore(null, 500, "数量必须大于0!"); } // 查询容器 - var container = _unitWork.FindSingle(u => u.Code == containerCode); + var container = _unitWork.FindSingle(u => u.Code == model.ContainerCode); if (container == null) { - return JsonMore(null, 500, $"库内没有编码为 {containerCode} 的容器!"); + return JsonMore(null, 500, $"库内没有编码为 {model.ContainerCode} 的容器!"); } // 查询物料信息 - var material = _unitWork.FindSingle(x => x.MaterialCode == materialCode); + var material = _unitWork.FindSingle(x => x.MaterialCode == model.MaterialCode); if (material == null) { - return JsonMore(null, 500, $"未找到物料编码为 {materialCode} 的物料信息!"); + return JsonMore(null, 500, $"未找到物料编码为 {model.MaterialCode} 的物料信息!"); } + var batchCode = _unitWork.Find(x => x.MaterialCode == material.MaterialCode) + .OrderByDescending(x => x.ProcessOrder) + .FirstOrDefault() + ?.ProcessCode; var zone = _unitWork.FindSingle(x => x.ZoneCode == container.Type); // 创建库存记录 var inventory = new Inventory() @@ -177,13 +182,16 @@ namespace HHWMS.Web.Controllers MaterialType = material.MaterialType, MaterialSpec = material.MaterialSpec, MaterialUnit = material.MaterialUnit, - CompanyCode = company, - SourceCode = sourceCode, + CompanyCode = model.CompanyCode, + SourceCode = model.OrderId, + ReceiptDetailId = model.SourceCode, // 优先使用 OrderId SupplierCode = material.SupplierCode, - Batch = batch, - Qty = qty, + Batch = model.Batch, + Qty = model.Qty, + BatchCode = batchCode, TaskStatus = InventoryTaskStatusEnum.Locked, - CreateTime = DateTime.Now + CreateTime = DateTime.Now, + CreateBy = Wtm.LoginUserInfo.ITCode }; _unitWork.Add(inventory); @@ -542,4 +550,51 @@ namespace HHWMS.Web.Controllers } } + + /// + /// 成品入库请求模型 + /// + public class SimpleReceiptInModel + { + /// + /// 托盘编码 + /// + public string ContainerCode { get; set; } + + /// + /// 物料编码 + /// + public string MaterialCode { get; set; } + + /// + /// 物料名称(图号) + /// + public string MaterialName { get; set; } + + /// + /// 物料规格 + /// + public string MaterialSpec { get; set; } + + /// + /// 部件名称(批次) + /// + public string Batch { get; set; } + + /// + /// 订单号(上游单号) + /// + public string SourceCode { get; set; } + public string OrderId { get; set; } + + /// + /// 公司 + /// + public string CompanyCode { get; set; } + + /// + /// 数量 + /// + public decimal Qty { get; set; } + } } diff --git a/HHWMS.Web/Areas/Receipt/Views/SimpleReceiptIn/Index.cshtml b/HHWMS.Web/Areas/Receipt/Views/SimpleReceiptIn/Index.cshtml index 41aa17c..174e4aa 100644 --- a/HHWMS.Web/Areas/Receipt/Views/SimpleReceiptIn/Index.cshtml +++ b/HHWMS.Web/Areas/Receipt/Views/SimpleReceiptIn/Index.cshtml @@ -30,17 +30,18 @@ placeholder="输入部件名称" allow-clear @@keydown.enter="$nextTick(() => { - $refs.sourceCodeInput.focus(); + $refs.sourceCodeSelect.focus(); })"/>/> - + :options="orderOptions" + placeholder="请选择订单号" + allow-search + ref="sourceCodeSelect" + @@change="handleOrderSelect"> + { const json = response.data; if (json.Code == 200) { @@ -321,6 +324,9 @@ this.formData.materialCode = selectedMaterial.MaterialCode; this.formData.materialName = selectedMaterial.MaterialType; this.formData.materialSpec = selectedMaterial.MaterialSpec; + + // 选择物料后加载订单列表 + this.loadOrdersByMaterial(selectedMaterial.MaterialCode); } this.$nextTick(() => { @@ -328,6 +334,47 @@ }); }, + // 根据物料加载订单列表 + loadOrdersByMaterial(materialCode) { + if (!materialCode) { + this.formData.sourceCode = ''; + this.orderOptions = []; + return; + } + + this.orderOptions = []; + const postData = new URLSearchParams(); + postData.append('materialCode', materialCode); + + axios.post('/receipt/ReceiptIn/GetOrdersByMaterial', postData) + .then((response) => { + const json = response.data; + if (json.Code == 200) { + this.orderOptions = json.Data || []; + if (this.orderOptions.length === 0) { + this.$message.warning('该物料暂无关联订单'); + } + } else { + this.$message.error(json.Msg || '获取订单列表失败'); + } + }) + .catch((error) => { + console.error('获取订单列表失败:', error); + this.$message.error('获取订单列表失败: ' + (error.message || '网络错误')); + }); + }, + + // 处理订单选择 + handleOrderSelect(value) { + const selectedOrder = this.orderOptions.find(item => item.value === value); + if (selectedOrder) { + this.formData.orderId = selectedOrder.label; // 设置 OrderId 为订单号 + } + this.$nextTick(() => { + this.$refs.companyCodeInput?.focus(); + }); + }, + handleBind() { // 表单验证 if (!this.formData.containerCode) { @@ -352,34 +399,29 @@ } } - // 添加到绑定列表 - const bindItem = { + // 构建请求数据 + const requestData = { ContainerCode: this.formData.containerCode, MaterialCode: this.formData.materialCode, MaterialName: this.formData.materialName, MaterialSpec: this.formData.materialSpec, Batch: this.formData.batch, SourceCode: this.formData.sourceCode, + OrderId: this.formData.orderId, CompanyCode: this.formData.companyCode, Qty: this.formData.qty }; // 调用后端添加库存 - let postData = new URLSearchParams(); - postData.append('containerCode', this.formData.containerCode); - postData.append('materialCode', this.formData.materialCode); - postData.append('company', this.formData.companyCode); - postData.append('sourceCode', this.formData.sourceCode); - postData.append('qty', this.formData.qty); - postData.append('batch', this.formData.batch); - - axios.post("/receipt/SimpleReceiptIn/AddInventory", postData) + axios.post("/receipt/SimpleReceiptIn/AddInventory", requestData, { + headers: { + 'Content-Type': 'application/json' + } + }) .then((response) => { const json = response.data; if (json.Code == 200) { - // 添加ID到绑定项 - bindItem.Id = json.Data.Id; - this.bindList.unshift(bindItem); + this.$message.success("物料绑定成功"); this.saveToHistory('batch', this.formData.batch); // 清空表单 @@ -405,8 +447,10 @@ this.formData.materialSpec = ''; this.formData.batch = ''; this.formData.sourceCode = ''; + this.formData.orderId = ''; this.formData.companyCode = ''; this.formData.qty = null; + this.orderOptions = []; // 页面加载完成后,将焦点设置到容器编码输入框 this.$nextTick(() => {