批量添加按钮:只有当用户通过"查看样品"进入(有receiptId参数)时才显示
批量添加对话框:包含样品型号、硬件版本号和SN号输入框 自动完成功能:型号和版本号都支持自动完成 批量创建:输入多个SN号,每个都会继承相同的型号和版本号 自动刷新:添加成功后自动刷新列表main
parent
efd2d003da
commit
5a09430e31
|
|
@ -68,6 +68,16 @@
|
||||||
v-hasPermi="['warehouse:sample:add']"
|
v-hasPermi="['warehouse:sample:add']"
|
||||||
>新增</el-button>
|
>新增</el-button>
|
||||||
</el-col>
|
</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-col :span="1.5">
|
||||||
<el-button
|
<el-button
|
||||||
type="danger"
|
type="danger"
|
||||||
|
|
@ -223,6 +233,51 @@
|
||||||
<el-button @click="cancel">取 消</el-button>
|
<el-button @click="cancel">取 消</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-dialog>
|
</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号 例如: SN001 SN002 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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
@ -251,6 +306,14 @@ export default {
|
||||||
title: "",
|
title: "",
|
||||||
// 是否显示弹出层
|
// 是否显示弹出层
|
||||||
open: false,
|
open: false,
|
||||||
|
// 批量添加样品对话框
|
||||||
|
batchSampleOpen: false,
|
||||||
|
// 批量添加样品文本
|
||||||
|
batchSampleText: "",
|
||||||
|
// 批量添加样品型号
|
||||||
|
batchSampleModel: "",
|
||||||
|
// 批量添加硬件版本号
|
||||||
|
batchHardwareVersion: "",
|
||||||
// 入库单ID(从路由参数获取)
|
// 入库单ID(从路由参数获取)
|
||||||
receiptId: null,
|
receiptId: null,
|
||||||
// 入库单号(从路由参数获取)
|
// 入库单号(从路由参数获取)
|
||||||
|
|
@ -387,6 +450,67 @@ export default {
|
||||||
handleBack() {
|
handleBack() {
|
||||||
this.$router.push('/warehouse/receipt');
|
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) {
|
querySampleModel(queryString, cb) {
|
||||||
// 从 sampleList 中提取不重复的样品型号
|
// 从 sampleList 中提取不重复的样品型号
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue