对于半成品的条形码进行更改

This commit is contained in:
dxc
2026-02-03 09:01:03 +08:00
parent 11a4e5f48a
commit 98450d73f1
4 changed files with 238 additions and 109 deletions

View File

@ -97,8 +97,11 @@
</el-table-column>
</template>
<el-table-column label="操作" width="160" fixed="right" align="center">
<el-table-column label="操作" width="220" fixed="right" align="center">
<template #default="{ row }">
<el-button link type="warning" size="default" @click="handlePrint(row)">
<el-icon><Printer /></el-icon> 打印
</el-button>
<el-button link type="primary" size="default" @click="handleUpdate(row)">编辑</el-button>
<el-popconfirm title="确定删除该条记录吗?不可恢复。" @confirm="handleDelete(row)" width="220">
<template #reference>
@ -200,7 +203,11 @@
<div class="card-content">
<el-row :gutter="24">
<el-col :span="6"><el-form-item label="编码/SKU" prop="sku"><el-input v-model="form.sku" placeholder="选填" /></el-form-item></el-col>
<el-col :span="6">
<el-form-item label="编码/SKU" prop="sku">
<el-input v-model="form.sku" placeholder="系统自动生成" disabled />
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="入库日期" prop="in_date">
<el-date-picker v-model="form.in_date" type="date" value-format="YYYY-MM-DD" style="width:100%" disabled />
@ -372,20 +379,51 @@
<div class="dialog-footer">
<el-button @click="visible = false" size="large">取消</el-button>
<el-button type="primary" :loading="submitting" @click="submitForm" size="large" class="confirm-btn">
{{ dialogStatus === 'create' ? '确认入库' : '保存修改' }}
{{ dialogStatus === 'create' ? '确认入库并打印' : '保存修改' }}
</el-button>
</div>
</template>
</el-dialog>
<el-dialog
v-model="printVisible"
title="标签打印预览"
width="400px"
destroy-on-close
append-to-body
>
<div style="text-align: center;">
<div v-loading="printLoading" class="preview-box">
<img v-if="previewUrl" :src="previewUrl" alt="Label Preview" style="width: 100%; border: 1px solid #ccc;"/>
<div v-else class="empty-preview">正在生成预览...</div>
</div>
<div style="margin-top: 20px; font-size: 14px; color: #666;">
<p>打印机 IP: 192.168.9.205</p>
<p>尺寸: 40mm x 30mm</p>
</div>
</div>
<template #footer>
<div class="dialog-footer">
<el-button @click="printVisible = false">取消</el-button>
<el-button type="primary" :loading="printing" @click="confirmPrint">
<el-icon>
<Printer/>
</el-icon>
确认打印
</el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, watch, computed } from 'vue'
import { Plus, Setting, Refresh, Search, Lock, Box, House, InfoFilled, Link } from '@element-plus/icons-vue'
import { Plus, Setting, Refresh, Search, Lock, Box, House, InfoFilled, Link, Printer } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import dayjs from 'dayjs'
// 假设这是半成品入库的API文件
import {
getSemiList,
createSemiInbound,
@ -393,6 +431,7 @@ import {
deleteSemiInbound,
searchMaterialBase
} from '@/api/inbound/semi'
import { getLabelPreview, executePrint } from '@/api/common/print'
// ------------------------------------
// 状态与变量
@ -408,6 +447,13 @@ const formRef = ref()
const queryParams = reactive({ page: 1, pageSize: 15, keyword: '' })
const materialOptions = ref<any[]>([])
// 打印相关变量
const printVisible = ref(false)
const printLoading = ref(false)
const printing = ref(false)
const previewUrl = ref('')
const currentPrintData = ref<any>({})
const entryMode = ref('batch')
const modeLocked = ref(false)
@ -807,6 +853,9 @@ const handleUpdate = (row: any) => {
visible.value = true
}
// ------------------------------------
// 提交逻辑 (新增自动打印逻辑)
// ------------------------------------
const submitForm = async () => {
if (!formRef.value) return
await formRef.value.validate(async (valid: boolean) => {
@ -825,8 +874,24 @@ const submitForm = async () => {
delete payload.production_time_range // 后端不需要数组
if (dialogStatus.value === 'create') {
await createSemiInbound(payload)
// 1. 创建入库
const res: any = await createSemiInbound(payload)
ElMessage.success('入库成功')
// 2. 自动打印 (使用返回的完整数据)
// res.data 包含了 newly created stock item, with generated ID and SKU
const newItem = res.data
if (newItem) {
ElMessage.info('正在发送打印指令...')
try {
await executePrint(newItem)
ElMessage.success('打印指令已发送')
} catch (printErr: any) {
console.error(printErr)
ElMessage.warning('入库成功,但自动打印失败:' + (printErr.msg || '未知错误'))
}
}
} else {
await updateSemiInbound(form.id!, payload)
ElMessage.success('更新成功')
@ -856,6 +921,50 @@ const handleDelete = async (row: any) => {
}
}
// ------------------------------------
// 打印逻辑 (手动 & 预览)
// ------------------------------------
const handlePrint = async (row: any) => {
printVisible.value = true
printLoading.value = true
previewUrl.value = ''
const printData = {
global_print_id: row.global_print_id,
material_name: row.material_name,
spec_model: row.spec_model,
category: row.category,
material_type: row.material_type,
warehouse_loc: row.warehouse_loc,
serial_number: row.serial_number,
batch_number: row.batch_number,
sku: row.sku // 【重要】显式增加 SKU 字段传递给后端
}
currentPrintData.value = printData
try {
const res: any = await getLabelPreview(printData)
previewUrl.value = res.data
} catch (e) {
ElMessage.error('预览生成失败')
} finally {
printLoading.value = false
}
}
const confirmPrint = async () => {
printing.value = true
try {
await executePrint(currentPrintData.value)
ElMessage.success('指令已发送')
printVisible.value = false
} catch (e: any) {
ElMessage.error(e.msg || '打印失败')
} finally {
printing.value = false
}
}
const resetForm = () => {
materialOptions.value = []
Object.assign(form, {
@ -1016,4 +1125,15 @@ onMounted(() => fetchData())
.opt-name { font-weight: bold; }
.opt-spec { color: #8492a6; font-size: 13px; margin-right: 10px; }
.total-price-input :deep(.el-input__inner) { color: #F56C6C; font-weight: bold; }
.preview-box {
min-height: 150px;
display: flex;
justify-content: center;
align-items: center;
background: #f5f7fa;
border-radius: 4px;
}
.empty-preview {
color: #909399;
}
</style>