diff --git a/ruoyi-fastapi-frontend/src/views/warehouse/sample/index.vue b/ruoyi-fastapi-frontend/src/views/warehouse/sample/index.vue index fa876fc..2754277 100644 --- a/ruoyi-fastapi-frontend/src/views/warehouse/sample/index.vue +++ b/ruoyi-fastapi-frontend/src/views/warehouse/sample/index.vue @@ -68,6 +68,16 @@ v-hasPermi="['warehouse:sample:add']" >新增 + + 批量添加样品 + 取 消 + + + + + + +
+ 提示:该型号将应用于所有批量添加的样品 +
+
+ + +
+ 提示:该版本号将应用于所有批量添加的样品 +
+
+ + +
+ 提示:每行输入一个SN号,系统将自动为每个SN号创建一条样品记录 +
+
+
+ +
@@ -251,6 +306,14 @@ export default { title: "", // 是否显示弹出层 open: false, + // 批量添加样品对话框 + batchSampleOpen: false, + // 批量添加样品文本 + batchSampleText: "", + // 批量添加样品型号 + batchSampleModel: "", + // 批量添加硬件版本号 + batchHardwareVersion: "", // 入库单ID(从路由参数获取) receiptId: null, // 入库单号(从路由参数获取) @@ -387,6 +450,67 @@ export default { handleBack() { this.$router.push('/warehouse/receipt'); }, + /** 批量添加样品 */ + handleBatchAddSample() { + if (!this.receiptId) { + this.$modal.msgWarning("请先选择入库单"); + return; + } + this.batchSampleText = ""; + this.batchSampleModel = ""; + this.batchHardwareVersion = ""; + this.batchSampleOpen = true; + }, + /** 提交批量添加样品 */ + async submitBatchSample() { + if (!this.batchSampleText || !this.batchSampleText.trim()) { + this.$modal.msgWarning("请输入样品SN号"); + return; + } + + // 按行分割文本 + const lines = this.batchSampleText.split('\n'); + let addedCount = 0; + let failedCount = 0; + + // 处理每一行 + for (const line of lines) { + const sn = line.trim(); + // 跳过空行 + if (sn) { + try { + // 创建样品对象 + const sampleData = { + receiptId: this.receiptId, + receiptNo: this.receiptNo, + sampleModel: this.batchSampleModel || null, + sampleSn: sn, + hardwareVersion: this.batchHardwareVersion || null, + externalStatus: null, + testItems: null, + testDeadline: null, + status: '0', + remark: null + }; + + // 调用API添加样品 + await addSample(sampleData); + addedCount++; + } catch (error) { + console.error(`添加样品 ${sn} 失败:`, error); + failedCount++; + } + } + } + + if (addedCount > 0) { + this.$modal.msgSuccess(`成功添加 ${addedCount} 条样品记录${failedCount > 0 ? `,失败 ${failedCount} 条` : ''}`); + this.batchSampleOpen = false; + this.getList(); // 刷新列表 + } else { + this.$modal.msgError("添加样品失败,请检查输入"); + } + }, /** 查询样品型号建议 */ querySampleModel(queryString, cb) { // 从 sampleList 中提取不重复的样品型号