批量添加按钮:只有当用户通过"查看样品"进入(有receiptId参数)时才显示

批量添加对话框:包含样品型号、硬件版本号和SN号输入框
自动完成功能:型号和版本号都支持自动完成
批量创建:输入多个SN号,每个都会继承相同的型号和版本号
自动刷新:添加成功后自动刷新列表
main
risingLee 2026-01-06 15:05:24 +08:00
parent efd2d003da
commit 5a09430e31
1 changed files with 124 additions and 0 deletions

View File

@ -68,6 +68,16 @@
v-hasPermi="['warehouse:sample:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5" v-if="receiptId">
<el-button
type="success"
plain
icon="el-icon-document-add"
size="mini"
@click="handleBatchAddSample"
v-hasPermi="['warehouse:sample:add']"
>批量添加样品</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
@ -223,6 +233,51 @@
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
<!-- 批量添加样品对话框 -->
<el-dialog title="批量添加样品" :visible.sync="batchSampleOpen" width="600px" append-to-body :close-on-click-modal="false">
<el-form label-width="120px">
<el-form-item label="样品型号">
<el-autocomplete
v-model="batchSampleModel"
:fetch-suggestions="querySampleModel"
placeholder="请输入样品型号"
style="width: 100%"
:trigger-on-focus="false"
/>
<div style="margin-top: 5px; color: #909399; font-size: 12px">
<i class="el-icon-info"></i> 提示该型号将应用于所有批量添加的样品
</div>
</el-form-item>
<el-form-item label="硬件版本号">
<el-autocomplete
v-model="batchHardwareVersion"
:fetch-suggestions="queryHardwareVersion"
placeholder="请输入硬件版本号"
style="width: 100%"
:trigger-on-focus="false"
/>
<div style="margin-top: 5px; color: #909399; font-size: 12px">
<i class="el-icon-info"></i> 提示该版本号将应用于所有批量添加的样品
</div>
</el-form-item>
<el-form-item label="样品SN号">
<el-input
v-model="batchSampleText"
type="textarea"
:rows="10"
placeholder="请输入样品SN号每行一个SN号&#10;例如:&#10;SN001&#10;SN002&#10;SN003"
/>
<div style="margin-top: 10px; color: #909399; font-size: 12px">
<i class="el-icon-info"></i> 提示每行输入一个SN号系统将自动为每个SN号创建一条样品记录
</div>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitBatchSample"> </el-button>
<el-button @click="batchSampleOpen = false"> </el-button>
</div>
</el-dialog>
</div>
</template>
@ -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