feat: 仓库管理

This commit is contained in:
砂糖
2025-09-17 15:59:03 +08:00
parent 0346e09dd3
commit 2bd09e2cf4
43 changed files with 5473 additions and 33 deletions

View File

@@ -0,0 +1,13 @@
<template>
<StockIoPage ioType="in" />
</template>
<script>
import StockIoPage from './panels/stockIoPage.vue';
export default {
components: {
StockIoPage
}
}
</script>

View File

@@ -0,0 +1,488 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="单号" prop="stockIoCode">
<el-input
v-model="queryParams.stockIoCode"
placeholder="请输入出入库单号"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="类型" prop="ioType">
<el-select v-model="queryParams.ioType" placeholder="请选择类型" clearable>
<el-option
v-for="dict in dict.type.stock_io_type"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="业务类型" prop="bizType">
<el-select v-model="queryParams.bizType" placeholder="请选择业务类型" clearable>
<el-option
v-for="dict in dict.type.stock_biz_type"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="单据状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择单据状态" clearable>
<el-option :key="0" label="草稿" :value="0" />
<el-option :key="1" label="待审核" :value="1" />
<el-option :key="2" label="已完成" :value="2" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="Refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="Plus"
size="mini"
@click="handleAdd"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="Edit"
size="mini"
:disabled="single"
@click="handleUpdate"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="Delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="Download"
size="mini"
@click="handleExport"
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="stockIoList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="出入库单ID" align="center" prop="stockIoId" v-if="true"/>
<el-table-column label="出入库单号" align="center" prop="stockIoCode" />
<el-table-column label="类型" align="center" prop="ioType">
<template #default="scope">
<el-tag :type="getIoTypeTagType(scope.row.ioType)">
{{ getIoTypeLabel(scope.row.ioType) }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="业务类型" align="center" prop="bizType">
<template #default="scope">
<el-tag :type="getBizTypeTagType(scope.row.bizType)">
{{ getBizTypeLabel(scope.row.bizType) }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="单据状态" align="center" prop="status">
<template #default="scope">
<el-tag :type="scope.row.status === 2 ? 'success' : (scope.row.status === 1 ? 'warning' : 'info')">
{{ scope.row.status === 2 ? '已完成' : (scope.row.status === 0 ? '草稿' : '待审核') }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<el-button
size="mini"
type="text"
icon="Edit"
@click="handleUpdate(scope.row)"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="Delete"
@click="handleDelete(scope.row)"
>删除</el-button>
<el-button
size="mini"
type="text"
icon="Document"
@click="showDetail(scope.row)"
>明细</el-button>
<!-- <el-button
size="mini"
type="text"
icon="el-icon-printer"
@click="handleShowBarcodeDrawer(scope.row)"
>打印条码</el-button> -->
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改出入库单主对话框 -->
<el-dialog :title="title" v-model="open" width="600px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-form-item label="出入库单号" prop="stockIoCode">
<el-input v-model="form.stockIoCode" placeholder="请输入出入库单号" />
</el-form-item>
<el-form-item label="类型" prop="ioType">
<el-select v-model="form.ioType" placeholder="请选择类型">
<el-option
v-for="dict in dict.type.stock_io_type"
:key="dict.value"
:label="dict.label"
:value="dict.value"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="业务类型" prop="bizType">
<el-select v-model="form.bizType" placeholder="请选择业务类型">
<el-option
v-for="dict in dict.type.stock_biz_type"
:key="dict.value"
:label="dict.label"
:value="dict.value"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="单据状态" prop="status">
<el-input v-model="form.status" :value="0" readonly disabled />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" placeholder="请输入备注" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button :loading="buttonLoading" type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
<!-- 明细弹窗 -->
<el-dialog
title="出入库单详情"
v-model="detailDialogVisible"
width="1000px"
append-to-body
@close="onDetailClosed"
>
<StockIoDetailPanel
:stockIo="detailStockIo"
@status-changed="onStatusChanged"
/>
</el-dialog>
<!-- 条码打印抽屉 -->
<!-- <el-drawer
title="条码打印"
v-model="drawerBarcodeVisible"
size="100%"
direction="btt"
:with-header="true"
>
<BarcodeGenerator
v-if="drawerBarcodeVisible"
:barcodes="drawerBarcodeData.barcodes"
:perRow="drawerBarcodeData.perRow"
:barcodeWidth="drawerBarcodeData.barcodeWidth"
:barcodeHeight="drawerBarcodeData.barcodeHeight"
/>
</el-drawer> -->
</div>
</template>
<script>
import { listStockIo, getStockIo, delStockIo, addStockIo, updateStockIo } from "@/api/wms/stockIo";
import { listStockIoDetail } from "@/api/wms/stockIoDetail";
import StockIoDetailPanel from './panels/detail.vue';
import BarcodeGenerator from './panels/barcode.vue';
export default {
name: "StockIo",
dicts: ['stock_biz_type', 'stock_io_type', 'stock_status'],
components: { StockIoDetailPanel, BarcodeGenerator },
data() {
return {
// 按钮loading
buttonLoading: false,
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 出入库单主表格数据
stockIoList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 20,
stockIoCode: undefined,
ioType: undefined,
bizType: undefined,
status: undefined,
},
// 表单参数
form: {},
// 表单校验
rules: {
stockIoId: [
{ required: true, message: "出入库单ID不能为空", trigger: "blur" }
],
stockIoCode: [
{ required: true, message: "出入库单号不能为空", trigger: "blur" }
],
ioType: [
{ required: true, message: "类型不能为空", trigger: "change" }
],
bizType: [
{ required: true, message: "业务类型不能为空", trigger: "change" }
],
status: [
{ required: true, message: "单据状态不能为空", trigger: "change" }
],
delFlag: [
{ required: true, message: "删除标志不能为空", trigger: "blur" }
],
createTime: [
{ required: true, message: "创建时间不能为空", trigger: "blur" }
],
updateTime: [
{ required: true, message: "更新时间不能为空", trigger: "blur" }
],
},
detailDialogVisible: false,
detailStockIo: null,
// 条码打印抽屉相关
// drawerBarcodeVisible: false,
// drawerBarcodeData: {
// barcodes: [],
// perRow: 3,
// barcodeWidth: 180,
// barcodeHeight: 60
// },
};
},
created() {
this.getList();
},
methods: {
/** 查询出入库单主列表 */
getList() {
this.loading = true;
listStockIo(this.queryParams).then(response => {
this.stockIoList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
stockIoId: undefined,
stockIoCode: undefined,
ioType: undefined,
bizType: undefined,
status: undefined,
remark: undefined,
delFlag: undefined,
createTime: undefined,
createBy: undefined,
updateTime: undefined,
updateBy: undefined
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.stockIoId)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.form.status = 0; // 新增时默认草稿状态
this.open = true;
this.title = "添加出入库单主";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.loading = true;
this.reset();
const stockIoId = row.stockIoId || this.ids
getStockIo(stockIoId).then(response => {
this.loading = false;
this.form = response.data;
this.open = true;
this.title = "修改出入库单主";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
this.buttonLoading = true;
if (this.form.stockIoId != null) {
updateStockIo(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
}).finally(() => {
this.buttonLoading = false;
});
} else {
addStockIo(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
}).finally(() => {
this.buttonLoading = false;
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const stockIoIds = row.stockIoId || this.ids;
this.$modal.confirm('是否确认删除出入库单主编号为"' + stockIoIds + '"的数据项?').then(() => {
this.loading = true;
return delStockIo(stockIoIds);
}).then(() => {
this.loading = false;
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {
}).finally(() => {
this.loading = false;
});
},
/** 导出按钮操作 */
handleExport() {
this.download('wms/stockIo/export', {
...this.queryParams
}, `stockIo_${new Date().getTime()}.xlsx`)
},
showDetail(row) {
this.detailStockIo = { ...row };
this.detailDialogVisible = true;
},
onDetailClosed() {
this.getList();
},
onStatusChanged(updatedStockIo) {
// 更新主表中的对应记录状态
const index = this.stockIoList.findIndex(item => item.stockIoId === updatedStockIo.stockIoId);
if (index !== -1) {
this.$set(this.stockIoList, index, updatedStockIo);
}
// 刷新列表
this.getList();
},
// async handleShowBarcodeDrawer(row) {
// // 获取明细列表
// const res = await listStockIoDetail({ stockIoId: row.stockIoId });
// const details = res.data || res.rows || [];
// // 拼接条码内容 stockIoId_warehouseId_materialId_quantity
// const barcodes = details.filter(el => el.recordType == 0).map(item => {
// return encodeURIComponent(`${row.stockIoId}_${item.warehouseId || ''}_${item.itemId || ''}_${item.quantity || ''}`);
// });
// // this.drawerBarcodeData = {
// // barcodes,
// // perRow: 3,
// // barcodeWidth: 180,
// // barcodeHeight: 60
// // };
// // this.drawerBarcodeVisible = true;
// },
getIoTypeTagType(type) {
if (type === 'in') return 'success';
if (type === 'out') return 'primary';
if (type === 'transfer') return 'warning';
return '';
},
getIoTypeLabel(type) {
if (type === 'in') return '入库';
if (type === 'out') return '出库';
if (type === 'transfer') return '移库';
return type;
},
getBizTypeTagType(type) {
if (type === 'purchase') return 'success';
if (type === 'sales') return 'primary';
if (type === 'return') return 'warning';
if (type === 'relocation') return 'info';
return 'default';
},
getBizTypeLabel(type) {
const map = {
purchase: '采购',
sales: '销售',
return: '退货',
relocation: '调拨',
other: '其他'
};
return map[type] || type;
}
}
};
</script>

View File

@@ -0,0 +1,13 @@
<template>
<StockIoPage ioType="transfer" />
</template>
<script>
import StockIoPage from './panels/stockIoPage.vue';
export default {
components: {
StockIoPage
}
}
</script>

View File

@@ -0,0 +1,13 @@
<template>
<StockIoPage ioType="out" />
</template>
<script>
import StockIoPage from './panels/stockIoPage.vue';
export default {
components: {
StockIoPage
}
}
</script>

View File

@@ -0,0 +1,424 @@
<template>
<div class="barcode-3col-layout">
<!-- 预览区 -->
<div class="barcode-preview-col">
<div class="iframe-wrapper">
<iframe ref="previewIframe" class="barcode-iframe" frameborder="0" :style="iframeStyle"></iframe>
</div>
</div>
<!-- 右侧控制+设置区 -->
<div class="barcode-right-col">
<!-- 控制区 -->
<div class="barcode-control-bar">
<el-tabs v-model="activeTab" stretch>
<el-tab-pane label="排版设置" name="layout" />
<el-tab-pane label="二维码明细" name="detail" />
</el-tabs>
</div>
<!-- 设置区 -->
<div class="barcode-settings-panel">
<el-form v-if="activeTab==='layout'" label-width="80px" size="small" label-position="top">
<!-- 排版设置内容保持不变 -->
<el-form-item label="每行数量">
<el-input-number :controls=false controls-position="right" v-model="perRow" size="mini" :min="1" :max="10" />
</el-form-item>
<el-form-item label="二维码尺寸">
<el-input-number :controls=false controls-position="right" v-model="barcodeWidth" size="mini" :min="60" :max="600" />
</el-form-item>
<el-form-item label="纸张尺寸">
<el-select v-model="paperSize" placeholder="请选择纸张尺寸" style="width: 160px">
<el-option label="A4 (210mm x 297mm)" value="A4" />
<el-option label="A5 (148mm x 210mm)" value="A5" />
<el-option label="A6 (105mm x 148mm)" value="A6" />
<el-option label="自定义" value="custom" />
</el-select>
</el-form-item>
<el-form-item v-if="paperSize==='custom'" label="自定义宽度(mm)">
<el-input-number :controls=false controls-position="right" v-model="customPaperWidth" size="mini" :min="50" :max="500" />
</el-form-item>
<el-form-item v-if="paperSize==='custom'" label="自定义高度(mm)">
<el-input-number :controls=false controls-position="right" v-model="customPaperHeight" size="mini" :min="50" :max="500" />
</el-form-item>
<el-form-item label="方向">
<el-radio-group v-model="paperOrientation">
<el-radio label="portrait">纵向</el-radio>
<el-radio label="landscape">横向</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="handlePrint">打印</el-button>
</el-form-item>
</el-form>
<el-form v-else label-width="80px" size="small" label-position="top">
<el-form-item label="二维码明细">
<div v-for="(cfg, idx) in barcodeConfigs" :key="idx" style="margin-bottom: 16px; border: 1px solid #eee; border-radius: 4px; padding: 12px 16px; background: #fafbfc;">
<div style="margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center;">
<span style="font-weight: bold; color: #666;">条码 {{ idx + 1 }}</span>
<el-button
type="text"
size="mini"
@click="saveAsImage(cfg.code, cfg.textTpl || cfg.code, idx)"
icon="Download"
>
另存为图片
</el-button>
<el-button
type="text"
size="mini"
@click="handleDelete(cfg, idx)"
icon="Delete"
>
删除
</el-button>
</div>
<el-form-item label="二维码内容" label-width="70px" style="margin-bottom: 8px;">
<el-input disabled type="textarea" v-model="cfg.code" size="mini" :autosize="{ minRows: 1, maxRows: 3 }" placeholder="请输入条码内容" />
</el-form-item>
<el-form-item label="生成数量" label-width="70px" style="margin-bottom: 8px;">
<el-input-number :controls=false controls-position="right" v-model.number="cfg.count" :min="1" :max="100" size="mini" />
</el-form-item>
<el-form-item label="下方文字" label-width="70px" style="margin-bottom: 0;">
<el-input type="textarea" v-model="cfg.textTpl" size="mini" placeholder="如 箱号" />
</el-form-item>
</div>
</el-form-item>
</el-form>
</div>
</div>
</div>
</template>
<script>
import QRCode from 'qrcode';
export default {
name: 'BarcodeGenerator',
props: {
barcodes: {
type: Array,
required: true
}
},
data() {
return {
perRow: 3,
barcodeWidth: 180,
barcodeHeight: 180, // 二维码建议宽高一致
barcodeConfigs: [], // [{code, count, textTpl}]
previewScale: 1, // 预览缩放比例
activeTab: 'layout',
paperSize: 'A4',
paperOrientation: 'portrait',
customPaperWidth: 210,
customPaperHeight: 297
};
},
computed: {
expandedBarcodes() {
let arr = [];
this.barcodeConfigs.forEach(cfg => {
for (let i = 0; i < (cfg.count || 1); i++) {
arr.push(cfg.code);
}
});
return arr;
},
expandedBarcodeTexts() {
let arr = [];
this.barcodeConfigs.forEach(cfg => {
for (let i = 0; i < (cfg.count || 1); i++) {
// 模板替换 {{n}}
let text = cfg.textTpl || cfg.code;
text = text.replace(/\{\{n\}\}/g, i + 1);
arr.push(text);
}
});
return arr;
},
expandedBarcodeTableData() {
return this.expandedBarcodes.map((code, idx) => ({ code, text: this.expandedBarcodeTexts[idx] }));
},
barcodeRows() {
const rows = [];
const arr = this.expandedBarcodes;
for (let i = 0; i < arr.length; i += this.perRow) {
rows.push(arr.slice(i, i + this.perRow));
}
return rows;
},
barcodeTextRows() {
const rows = [];
const arr = this.expandedBarcodeTexts;
for (let i = 0; i < arr.length; i += this.perRow) {
rows.push(arr.slice(i, i + this.perRow));
}
return rows;
},
iframeStyle() {
const { width, height } = this.getPaperPx();
return {
width: width + 'px',
minHeight: height + 'px',
height: height + 'px',
background: '#fff',
border: 'none',
display: 'block',
margin: 0,
padding: 0
};
}
},
watch: {
barcodes: {
handler(newVal) {
// 初始化barcodeConfigs
this.barcodeConfigs = newVal;
this.$nextTick(this.renderPreviewIframe);
},
immediate: true
},
barcodeConfigs: {
handler() { this.$nextTick(this.renderPreviewIframe); },
deep: true
},
perRow() { this.$nextTick(this.renderPreviewIframe); },
barcodeWidth() { this.$nextTick(this.renderPreviewIframe); },
barcodeHeight() { this.$nextTick(this.renderPreviewIframe); },
previewScale() { this.$nextTick(this.renderPreviewIframe); },
paperSize() { this.$nextTick(this.renderPreviewIframe); },
paperOrientation() { this.$nextTick(this.renderPreviewIframe); },
customPaperWidth() { this.$nextTick(this.renderPreviewIframe); },
customPaperHeight() { this.$nextTick(this.renderPreviewIframe); }
},
methods: {
getBarcodeId(row, col) {
return `barcode-canvas-${row}-${col}`;
},
getBarcodeText(row, col, code) {
if (
this.barcodeTextRows[row] &&
typeof this.barcodeTextRows[row][col] !== 'undefined' &&
this.barcodeTextRows[row][col] !== null &&
this.barcodeTextRows[row][col] !== ''
) {
return this.barcodeTextRows[row][col];
}
return code;
},
handleDelete(cfg, idx) {
// this.barcodeConfigs.splice(idx, 1);
this.$emit('delete', cfg, idx);
},
getPaperPx() {
// mm to px, 1mm ≈ 3.78px
let width, height;
if (this.paperSize === 'A4') {
width = 210 * 3.78;
height = 297 * 3.78;
} else if (this.paperSize === 'A5') {
width = 148 * 3.78;
height = 210 * 3.78;
} else if (this.paperSize === 'A6') {
width = 105 * 3.78;
height = 148 * 3.78;
} else {
width = this.customPaperWidth * 3.78;
height = this.customPaperHeight * 3.78;
}
if (this.paperOrientation === 'landscape') {
return { width: height, height: width };
}
return { width, height };
},
getPrintHtml() {
const { width, height } = this.getPaperPx();
let html = `
<html>
<head>
<title>打印二维码</title>
<style>
body { margin: 0; padding: 0; background: #fff; }
.barcode-list { width: ${width}px; min-height: ${height}px; margin: 0 auto; background: #fff; }
.barcode-row { display: flex; margin-bottom: 24px; }
.barcode-item { flex: 1; text-align: center; }
.barcode-text { margin-top: 8px; font-size: 14px; }
html, body { overflow-x: hidden; }
</style>
</head>
<body>
<div class="barcode-list">
`;
this.barcodeRows.forEach((row, rowIndex) => {
html += '<div class="barcode-row">';
row.forEach((code, colIndex) => {
const id = this.getBarcodeId(rowIndex, colIndex);
const text = this.getBarcodeText(rowIndex, colIndex, code);
html += `<div class="barcode-item">
<canvas id="${id}" width="${this.barcodeWidth}" height="${this.barcodeHeight}"></canvas>
<div class="barcode-text">${text}</div>
</div>`;
});
html += '</div>';
});
html += '</div></body></html>';
return html;
},
async renderPreviewIframe() {
const iframe = this.$refs.previewIframe;
if (!iframe) return;
const doc = iframe.contentDocument || iframe.contentWindow.document;
doc.open();
doc.write(this.getPrintHtml());
doc.close();
// 渲染二维码
setTimeout(async () => {
for (let rowIndex = 0; rowIndex < this.barcodeRows.length; rowIndex++) {
const row = this.barcodeRows[rowIndex];
for (let colIndex = 0; colIndex < row.length; colIndex++) {
const code = row[colIndex];
const id = this.getBarcodeId(rowIndex, colIndex);
const el = doc.getElementById(id);
if (el) {
await QRCode.toCanvas(el, code, {
width: this.barcodeWidth,
height: this.barcodeHeight,
margin: 0
});
}
}
}
}, 50);
},
handlePrint() {
const iframe = this.$refs.previewIframe;
if (!iframe) return;
iframe.contentWindow.focus();
iframe.contentWindow.print();
},
/**
* 保存二维码为图片
* @param {string} code 二维码内容
* @param {string} text 下方文字
* @param {number} index 索引,用于生成文件名
*/
async saveAsImage(code, text, index) {
try {
// 创建临时canvas用于绘制二维码和文字
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
// 计算总高度(二维码高度 + 文字区域高度)
const textHeight = 30; // 文字区域高度
canvas.width = this.barcodeWidth;
canvas.height = this.barcodeHeight + textHeight;
// 绘制二维码
const qrCanvas = document.createElement('canvas');
qrCanvas.width = this.barcodeWidth;
qrCanvas.height = this.barcodeHeight;
await QRCode.toCanvas(qrCanvas, code, {
width: this.barcodeWidth,
height: this.barcodeHeight,
margin: 0
});
// 将二维码绘制到主canvas
ctx.drawImage(qrCanvas, 0, 0);
// 绘制文字
ctx.fillStyle = '#000';
ctx.font = '14px Arial';
ctx.textAlign = 'center';
ctx.textBaseline = 'top';
ctx.fillText(text, this.barcodeWidth / 2, this.barcodeHeight + 5);
// 创建图片链接并下载
canvas.toBlob(blob => {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
// 生成文件名(使用索引和内容摘要)
const fileName = `二维码_${index + 1}_${code.substring(0, 10)}.png`;
a.download = fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
});
this.$message.success('图片保存成功');
} catch (error) {
console.error('保存图片失败:', error);
this.$message.error('保存图片失败,请重试');
}
}
},
mounted() {
this.barcodeConfigs = this.barcodes?.map(b => ({ code: b, count: 1, textTpl: b })) || [];
this.renderPreviewIframe();
}
};
</script>
<style scoped>
/* 样式保持不变 */
.barcode-3col-layout {
display: flex;
flex-direction: row;
width: 100%;
min-height: 400px;
}
.barcode-preview-col {
flex: 1 1 0;
min-width: 0;
background: #fff;
border-right: 1px solid #eee;
padding: 24px 0 24px 24px;
display: flex;
flex-direction: column;
height: 90vh;
overflow: auto;
}
.barcode-right-col {
width: 420px;
min-width: 320px;
padding: 16px;
display: flex;
flex-direction: column;
background: #fafbfc;
height: 90vh;
}
.barcode-control-bar {
border-bottom: 1px solid #eee;
background: #fafbfc;
padding: 0 16px;
}
.barcode-settings-panel {
flex: 1;
overflow: auto;
min-height: 0;
max-height: calc(90vh - 48px); /* 48px 约为tabs高度可根据实际调整 */
}
.preview-toolbar {
margin-bottom: 12px;
display: flex;
align-items: center;
}
.iframe-wrapper {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: flex-start;
background: #f8f8f8;
overflow: auto;
}
.barcode-iframe {
/* width、height 由:style绑定动态控制 */
min-width: 0;
min-height: 0;
border: none;
background: #fff;
border-radius: 4px;
display: block;
}
</style>

View File

@@ -0,0 +1,609 @@
<template>
<div class="app-container">
<template v-if="stockIo && stockIo.stockIoId">
<!-- 主表信息 -->
<el-descriptions :title="'单号:' + (stockIo.stockIoCode || '-')" :column="2" border>
<el-descriptions-item label="类型">
<dict-tag :options="stock_io_type" :value="stockIo.ioType"></dict-tag>
</el-descriptions-item>
<el-descriptions-item label="业务类型">
<dict-tag :options="stock_biz_type" :value="stockIo.bizType"></dict-tag>
</el-descriptions-item>
<el-descriptions-item label="状态">
<el-tag :type="stockIo.status === 2 ? 'success' : (stockIo.status === 1 ? 'warning' : 'info')">
{{ stockIo.status === 2 ? '已完成' : (stockIo.status === 0 ? '草稿' : '待审核') }}
</el-tag>
</el-descriptions-item>
<el-descriptions-item label="备注">{{ stockIo.remark }}</el-descriptions-item>
</el-descriptions>
<br />
<!-- 明细表格 -->
<!-- <el-tabs v-model="activeTab" style="margin-bottom: 10px;"> -->
<!-- <el-tab-pane label="扫码枪" name="scanner">
<el-table :data="scannerList" :show-header="true" :border="true" style="width: 100%;" :default-sort="{}" :highlight-current-row="true">
<el-table-column type="index" width="55" align="center" label="#" />
<el-table-column label="库区/库位" align="center" prop="warehouseName" />
<el-table-column v-if="stockIo.ioType === 'transfer'" label="源库区/库位" align="center" prop="fromWarehouseName" />
<el-table-column label="物品类型" align="center" prop="itemType">
<template #default="scope">
<dict-tag :options="stock_item_type" :value="scope.row.itemType" />
</template>
</el-table-column>
<el-table-column label="物品信息" align="center" prop="itemId">
<template #default="scope">
<product-info v-if="scope.row.itemType === ITEM_TYPE.PRODUCT" :product-id="scope.row.itemId" />
<span v-else>{{ scope.row.itemId }}</span>
</template>
</el-table-column>
<el-table-column label="数量" align="center" prop="quantity" />
<el-table-column label="单位" align="center" prop="unit" />
<el-table-column label="批次号" align="center" prop="batchNo" />
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<el-button
size="mini"
type="text"
icon="Edit"
@click="handleUpdate(scope.row)"
:disabled="stockIo.status >= 2"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="Delete"
@click="handleDelete(scope.row)"
:disabled="stockIo.status >= 2"
>删除</el-button>
</template>
</el-table-column>
</el-table>
</el-tab-pane> -->
<!-- <el-tab-pane label="手动录入" name="manual"> -->
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="Plus"
size="mini"
@click="handleAdd"
:disabled="stockIo.status >= 2"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="Edit"
size="mini"
:disabled="single || stockIo.status >= 2"
@click="handleUpdate"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="Delete"
size="mini"
:disabled="multiple || stockIo.status >= 2"
@click="handleDelete"
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="Download"
size="mini"
@click="handleExport"
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="manualList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="库区/库位" align="center" prop="warehouseName" />
<el-table-column
v-if="stockIo.ioType === 'transfer'"
label="源库区/库位"
align="center"
prop="fromWarehouseName"
/>
<el-table-column label="物品类型" align="center" prop="itemType">
<template #default="scope">
<dict-tag :options="stock_item_type" :value="scope.row.itemType" />
</template>
</el-table-column>
<el-table-column label="物品信息" align="center" prop="itemId">
<template #default="scope">
<product-info v-if="scope.row.itemType === ITEM_TYPE.PRODUCT" :product-id="scope.row.itemId" />
<span v-else>{{ scope.row.itemId }}</span>
</template>
</el-table-column>
<el-table-column label="BOM" align="center">
<template #default="scope">
<BomInfoMini :item-type="scope.row.itemType" :item-id="scope.row.itemId" />
</template>
</el-table-column>
<el-table-column label="数量" align="center" prop="quantity" />
<el-table-column label="单位" align="center" prop="unit" />
<el-table-column label="批次号" align="center" prop="batchNo" />
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<el-button
size="mini"
type="text"
icon="Edit"
@click="handleUpdate(scope.row)"
:disabled="stockIo.status >= 2"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="Delete"
@click="handleDelete(scope.row)"
:disabled="stockIo.status >= 2"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- </el-tab-pane> -->
<!-- </el-tabs> -->
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 操作按钮 -->
<div style="margin-top: 20px; text-align: right;">
<!-- 状态修改按钮 -->
<el-button
v-if="stockIo.status === 0"
type="warning"
:loading="statusLoading"
@click="handleUpdateStatus"
>{{ getStatusButtonText() }}</el-button>
<!-- 审核按钮 -->
<el-button
v-if="stockIo.status === 1"
type="primary"
:loading="auditLoading"
@click="handleAudit"
>{{ getAuditButtonText() }}</el-button>
<!-- 撤回按钮 -->
<el-button
v-if="stockIo.status === 2 && stockIo.ioType !== 'withdraw'"
type="warning"
:loading="cancelLoading"
@click="handleCancel"
>撤回</el-button>
</div>
<!-- 明细编辑弹窗 -->
<el-dialog :title="title" v-model="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-form-item label="出入库单ID" prop="stockIoId">
<el-input v-model="form.stockIoId" placeholder="请输入出入库单ID" :disabled="true" />
</el-form-item>
<el-form-item label="库区/库位" prop="warehouseId">
<warehouse-select v-model="form.warehouseId" placeholder="请选择库区/库位" />
</el-form-item>
<el-form-item
v-if="stockIo.ioType === 'transfer'"
label="源库区/库位"
prop="fromWarehouseId"
>
<warehouse-select v-model="form.fromWarehouseId" placeholder="请选择源库区/库位" />
</el-form-item>
<el-form-item label="产品信息" prop="itemId">
<product-select v-model="form.itemId" placeholder="请选择产品" />
</el-form-item>
<!-- <MaterialSelect :itemType.sync="form.itemType" :itemId.sync="form.itemId" @change="onItemChange" /> -->
<el-form-item label="数量" prop="quantity">
<el-input v-model="form.quantity" placeholder="请输入数量" />
</el-form-item>
<!-- <el-form-item label="单位" prop="unit">
<el-input v-model="form.unit" placeholder="请输入单位" :disabled="unitDisabled" />
</el-form-item> -->
<el-form-item label="批次号" prop="batchNo">
<el-input v-model="form.batchNo" placeholder="请输入批次号" />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" placeholder="请输入备注" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button :loading="buttonLoading" type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</template>
<template v-else>
<div style="height:200px;text-align:center;line-height:200px;">未获取到主表数据</div>
</template>
</div>
</template>
<script>
import { listStockIoDetail, getStockIoDetail, delStockIoDetail, addStockIoDetail, updateStockIoDetail } from "@/api/wms/stockIoDetail";
import { auditStockIo, updateStockIoStatus, cancelStockIo, getStockIo, returnStock } from "@/api/wms/stockIo";
import WarehouseSelect from '@/components/WarehouseSelect';
import ProductSelect from '@/components/ProductSelect';
import { ITEM_TYPE } from '@/utils/enums';
import ProductInfo from "@/components/Renderer/ProductInfo.vue";
import BomInfoMini from '@/components/Renderer/BomInfoMini.vue';
export default {
name: "StockIoDetailPanel",
components: {
WarehouseSelect,
ProductSelect,
ProductInfo,
BomInfoMini,
},
setup() {
const { proxy } = getCurrentInstance();
const { stock_item_type, stock_biz_type, stock_io_type } = proxy.useDict('stock_item_type', 'stock_biz_type', 'stock_io_type');
return {
stock_item_type,
stock_biz_type,
stock_io_type,
};
},
props: {
stockIo: {
type: Object,
required: true
}
},
data() {
return {
ITEM_TYPE,
loading: true,
stockIoDetailList: [],
total: 0,
queryParams: {
pageNum: 1,
pageSize: 20,
stockIoId: undefined
},
auditLoading: false,
open: false,
title: '',
form: {},
buttonLoading: false,
rules: {
warehouseId: [
{ required: true, message: "库区/库位不能为空", trigger: "blur" }
],
itemType: [
{ required: true, message: "物品类型不能为空", trigger: "blur" }
],
itemId: [
{ required: true, message: "物品ID不能为空", trigger: "blur" }
],
quantity: [
{ required: true, message: "数量不能为空", trigger: "blur" }
],
// unit: [
// { required: true, message: "单位不能为空", trigger: "blur" }
// ]
},
ids: [],
single: true,
multiple: true,
statusLoading: false, // 新增状态修改按钮加载状态
cancelLoading: false, // 撤回按钮加载状态
unitDisabled: false, // 新增:单位输入框是否禁用
activeTab: 'scanner' // 新增:当前激活的标签页
};
},
watch: {
'stockIo.stockIoId': {
handler(val) {
if (val) {
this.queryParams.stockIoId = val;
this.getList();
}
},
immediate: true
}
},
computed: {
// 手动录入的列表,使用recordType区分为0
manualList() {
return this.stockIoDetailList.filter(item => item.recordType === 0);
},
// 来自扫码枪的列表为1
scannerList() {
return this.stockIoDetailList.filter(item => item.recordType === 1);
}
},
mounted() {
if (this.stockIo && this.stockIo.stockIoId) {
this.queryParams.stockIoId = this.stockIo.stockIoId;
this.getList();
}
},
methods: {
getList() {
if (!this.queryParams.stockIoId) return;
this.loading = true;
listStockIoDetail(this.queryParams).then(response => {
this.stockIoDetailList = response.rows;
this.total = response.total;
}).finally(() => {
this.loading = false;
});
},
handleAudit() {
// 检查是否有明细数据
if (!this.stockIoDetailList || this.stockIoDetailList.length === 0) {
this.$modal.msgError('请先添加明细数据');
return;
}
// 确认审核
this.$modal.confirm('确认要审核此出入库单吗?审核后将影响库存数据。').then(() => {
this.auditLoading = true;
// 如果是退库单,则需要先审核出库单
if (this.stockIo.ioType === 'withdraw') {
returnStock(this.stockIo).then(response => {
this.$modal.msgSuccess('审核成功');
this.stockIo.status = 2;
// 刷新明细列表
this.getList();
// 通知父组件状态已更新
this.$emit('status-changed', this.stockIo);
}).finally(() => {
this.auditLoading = false;
})
return;
}
auditStockIo(this.stockIo.stockIoId).then(response => {
this.$modal.msgSuccess('审核成功');
// 更新主表状态
this.stockIo.status = 2;
// 刷新明细列表
this.getList();
// 通知父组件状态已更新
this.$emit('status-changed', this.stockIo);
}).catch(error => {
console.error('审核失败:', error);
this.$modal.msgError('审核失败:' + (error.message || '未知错误'));
}).finally(() => {
this.auditLoading = false;
});
}).catch(() => {
// 用户取消审核
});
},
handleSelectionChange(selection) {
this.ids = selection.map(item => item.detailId)
this.single = selection.length!==1
this.multiple = !selection.length
},
handleAdd() {
this.reset();
this.form.stockIoId = this.stockIo.stockIoId;
this.form.recordType = 0; // 新增时设为手动录入
this.open = true;
this.title = "添加出入库单明细";
},
handleUpdate(row) {
this.loading = true;
this.reset();
const detailId = row.detailId || this.ids
getStockIoDetail(detailId).then(response => {
this.loading = false;
this.form = response.data;
this.form.recordType = 0; // 修改时强制设为手动录入
this.open = true;
this.title = "修改出入库单明细";
});
},
submitForm() {
// 动态添加源库位验证规则
// if (this.stockIo.ioType === 'transfer') {
// this.$set(this.rules, 'fromWarehouseId', [
// { required: true, message: "源库区/库位不能为空", trigger: "blur" }
// ]);
// }
this.$refs["form"].validate(valid => {
if (valid) {
this.buttonLoading = true;
if (this.form.detailId != null) {
updateStockIoDetail(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
}).finally(() => {
this.buttonLoading = false;
});
} else {
addStockIoDetail(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
this.stockIo.status = 1;
// 新增明细后刷新主表状态
this.refreshStockIoStatus();
}).finally(() => {
this.buttonLoading = false;
});
}
}
});
},
handleDelete(row) {
const detailIds = row.detailId || this.ids;
this.$modal.confirm('是否确认删除出入库单明细编号为"' + detailIds + '"的数据项?').then(() => {
this.loading = true;
return delStockIoDetail(detailIds);
}).then(() => {
this.loading = false;
this.getList();
this.$modal.msgSuccess("删除成功");
// 删除明细后刷新主表状态
this.refreshStockIoStatus();
}).catch(() => {
}).finally(() => {
this.loading = false;
});
},
reset() {
this.form = {
detailId: undefined,
stockIoId: undefined,
warehouseId: undefined,
fromWarehouseId: undefined,
itemType: 'product',
itemId: undefined,
quantity: undefined,
// unit: undefined,
batchNo: '',
remark: undefined
};
this.unitDisabled = false; // 新增:重置单位输入框为可编辑
this.resetForm("form");
},
cancel() {
this.open = false;
this.reset();
},
handleExport() {
this.download('wms/stockIoDetail/export', {
...this.queryParams
}, `stockIoDetail_${new Date().getTime()}.xlsx`)
},
getAuditButtonText() {
if (this.stockIo.ioType === 'in') {
return '审核入库';
} else if (this.stockIo.ioType === 'out') {
return '审核出库';
} else if (this.stockIo.ioType === 'transfer') {
return '审核移库';
} else {
return '审核';
}
},
getStatusButtonText() {
if (this.stockIo.ioType === 'in') {
return '提交入库';
} else if (this.stockIo.ioType === 'out') {
return '提交出库';
} else if (this.stockIo.ioType === 'transfer') {
return '提交移库';
} else {
return '提交';
}
},
handleUpdateStatus() {
// 检查是否有明细数据
if (!this.stockIoDetailList || this.stockIoDetailList.length === 0) {
this.$modal.msgError('请先添加明细数据');
return;
}
this.$modal.confirm('确认要提交此出入库单吗?提交后将无法修改明细。').then(() => {
this.statusLoading = true;
updateStockIoStatus(this.stockIo.stockIoId, 1).then(response => {
this.$modal.msgSuccess('状态更新成功');
// 更新主表状态
this.stockIo.status = 1;
// 通知父组件状态已更新
this.$emit('status-changed', this.stockIo);
}).catch(error => {
console.error('状态更新失败:', error);
this.$modal.msgError('状态更新失败:' + (error.message || '未知错误'));
}).finally(() => {
this.statusLoading = false;
});
}).catch(() => {
// 用户取消状态更新
});
},
handleCancel() {
this.$modal.confirm('确认要撤回此出入库单吗?撤回后将回滚库存数据。').then(() => {
this.cancelLoading = true;
cancelStockIo(this.stockIo.stockIoId).then(response => {
this.$modal.msgSuccess('撤回成功');
// 更新主表状态
this.stockIo.status = 1;
// 刷新明细列表
this.getList();
// 通知父组件状态已更新
this.$emit('status-changed', this.stockIo);
}).catch(error => {
console.error('撤回失败:', error);
this.$modal.msgError('撤回失败:' + (error.message || '未知错误'));
}).finally(() => {
this.cancelLoading = false;
});
}).catch(() => {
// 用户取消撤回
});
},
refreshStockIoStatus() {
// 刷新主表状态
if (this.stockIo && this.stockIo.stockIoId) {
getStockIo(this.stockIo.stockIoId).then(response => {
const updatedStockIo = response.data;
// 更新主表状态
this.stockIo.status = updatedStockIo.status;
// 通知父组件状态已更新
this.$emit('status-changed', this.stockIo);
}).catch(error => {
console.error('刷新主表状态失败:', error);
});
}
},
getIoTypeTagType(type) {
if (type === 'in') return 'success';
if (type === 'out') return 'primary';
if (type === 'transfer') return 'warning';
return '';
},
getIoTypeLabel(type) {
if (type === 'in') return '入库';
if (type === 'out') return '出库';
if (type === 'transfer') return '移库';
return type;
},
getBizTypeLabel(type) {
const map = {
purchase: '采购',
sales: '销售',
return: '退货',
relocation: '调拨',
other: '其他'
};
return map[type] || type;
},
getBizTypeTagType(type) {
if (type === 'purchase') return 'success';
if (type === 'sales') return 'primary';
if (type === 'return') return 'warning';
if (type === 'relocation') return 'info';
return 'default';
},
// onItemChange(e) {
// if (e && e.unit) {
// this.form.unit = e.unit;
// this.unitDisabled = true;
// }
// }
}
}
</script>

View File

@@ -0,0 +1,435 @@
<template>
<div class="app-container">
<template v-if="stockIo && stockIo.stockIoId">
<el-row>
<el-form :model="returnForm" :rules="rules" inline label-width="120px">
<el-form-item label="出库单单号">
<el-input :value="stockIo.stockIoCode" disabled placeholder="请输入父单号" />
</el-form-item>
<el-form-item label="出库单ID" prop="parentId">
<el-input v-model="returnForm.parentId" disabled placeholder="请输入父单号" />
</el-form-item>
<el-form-item label="退库单号" prop="stockIoCode">
<el-input v-model="returnForm.stockIoCode" placeholder="请输入出入库单号" />
</el-form-item>
<el-form-item label="业务类型" prop="bizType">
<el-select v-model="returnForm.bizType" placeholder="请选择业务类型">
<el-option v-for="dict in stock_biz_type" :key="dict.value" :label="dict.label"
:value="dict.value"></el-option>
</el-select>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input type="textarea" v-model="returnForm.remark" placeholder="请输入备注" />
</el-form-item>
</el-form>
</el-row>
<el-table v-loading="loading" :data="manualList">
<el-table-column label="库区/库位" align="center" prop="warehouseName" />
<el-table-column v-if="stockIo.ioType === 'transfer'" label="源库区/库位" align="center" prop="fromWarehouseName" />
<el-table-column label="物品类型" align="center" prop="itemType">
<template #default="scope">
<dict-tag :options="stock_item_type" :value="scope.row.itemType" />
</template>
</el-table-column>
<el-table-column label="物品信息" align="center" prop="itemId">
<template #default="scope">
<product-info v-if="scope.row.itemType === ITEM_TYPE.PRODUCT" :product-id="scope.row.itemId" />
<span v-else>{{ scope.row.itemId }}</span>
</template>
</el-table-column>
<el-table-column label="BOM" align="center">
<template #default="scope">
<BomInfoMini :item-type="scope.row.itemType" :item-id="scope.row.itemId" />
</template>
</el-table-column>
<el-table-column label="单位" align="center" prop="unit" />
<el-table-column label="批次号" align="center" prop="batchNo" />
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column width="55" label="开关">
<template #default="scope">
<el-switch v-model="scope.row.switchInput" />
</template>
</el-table-column>
<el-table-column label="数量" width="180" align="center" prop="quantity">
<template #default="scope">
<el-input-number :controls=false controls-position="right" style="width: 160px;" v-model="scope.row.count" :max="scope.row.quantity"
placeholder="请输入数量" @input="handleQuantityInput(scope.row)" />
</template>
</el-table-column>
</el-table>
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
@pagination="getList" />
<!-- 操作按钮 -->
<div style="margin-top: 20px; text-align: right;">
<el-button type="primary" @click="submitForm">提交</el-button>
</div>
</template>
<template v-else>
<div style="height:200px;text-align:center;line-height:200px;">未获取到主表数据</div>
</template>
</div>
</template>
<script>
import { listStockIoDetail, getStockIoDetail, delStockIoDetail, addStockIoDetail, updateStockIoDetail } from "@/api/wms/stockIoDetail";
import { auditStockIo, updateStockIoStatus, cancelStockIo, getStockIo, addStockIoWithDetail } from "@/api/wms/stockIo";
import WarehouseSelect from '@/components/WarehouseSelect';
import ProductSelect from '@/components/ProductSelect';
import { ITEM_TYPE } from '@/utils/enums';
import ProductInfo from "@/components/Renderer/ProductInfo.vue";
import BomInfoMini from '@/components/Renderer/BomInfoMini.vue';
export default {
name: "returnCreatePanel",
components: {
WarehouseSelect,
ProductSelect,
ProductInfo,
BomInfoMini,
},
setup() {
const { proxy } = getCurrentInstance();
const { stock_item_type, stock_biz_type } = proxy.useDict('stock_item_type', 'stock_biz_type');
return {
stock_item_type,
stock_biz_type,
};
},
props: {
stockIo: {
type: Object,
required: true
}
},
data() {
return {
ITEM_TYPE,
loading: true,
stockIoDetailList: [],
total: 0,
queryParams: {
pageNum: 1,
pageSize: 20,
stockIoId: undefined
},
returnForm: {
},
auditLoading: false,
open: false,
title: '',
form: {},
buttonLoading: false,
rules: {
warehouseId: [
{ required: true, message: "库区/库位不能为空", trigger: "blur" }
],
itemType: [
{ required: true, message: "物品类型不能为空", trigger: "blur" }
],
itemId: [
{ required: true, message: "物品ID不能为空", trigger: "blur" }
],
quantity: [
{ required: true, message: "数量不能为空", trigger: "blur" }
],
unit: [
{ required: true, message: "单位不能为空", trigger: "blur" }
]
},
};
},
watch: {
'stockIo.stockIoId': {
handler(val) {
if (val) {
this.queryParams.stockIoId = val;
this.returnForm.parentId = val;
this.getList();
}
},
immediate: true
}
},
computed: {
manualList() {
return this.stockIoDetailList.filter(item => item.recordType === 0);
}
},
mounted() {
if (this.stockIo && this.stockIo.stockIoId) {
this.queryParams.stockIoId = this.stockIo.stockIoId;
this.getList();
}
},
methods: {
getList() {
if (!this.queryParams.stockIoId) return;
this.loading = true;
listStockIoDetail(this.queryParams).then(response => {
this.stockIoDetailList = response.rows.map(item => {
return {
...item,
count: item.quantity,
switchInput: true
}
});
this.total = response.total;
}).finally(() => {
this.loading = false;
});
},
handleAudit() {
// 检查是否有明细数据
if (!this.stockIoDetailList || this.stockIoDetailList.length === 0) {
this.$modal.msgError('请先添加明细数据');
return;
}
// 确认审核
this.$modal.confirm('确认要审核此出入库单吗?审核后将影响库存数据。').then(() => {
this.auditLoading = true;
auditStockIo(this.stockIo.stockIoId).then(response => {
this.$modal.msgSuccess('审核成功');
// 更新主表状态
this.$set(this.stockIo, 'status', 2);
// 刷新明细列表
this.getList();
// 通知父组件状态已更新
this.$emit('status-changed', this.stockIo);
}).catch(error => {
console.error('审核失败:', error);
this.$modal.msgError('审核失败:' + (error.message || '未知错误'));
}).finally(() => {
this.auditLoading = false;
});
}).catch(() => {
// 用户取消审核
});
},
handleSelectionChange(selection) {
this.ids = selection.map(item => item.detailId)
this.single = selection.length !== 1
this.multiple = !selection.length
},
handleQuantityInput(row) {
row.count = Math.min(row.count, row.quantity);
},
handleAdd() {
this.reset();
this.form.stockIoId = this.stockIo.stockIoId;
this.form.recordType = 0; // 新增时设为手动录入
this.open = true;
this.title = "添加出入库单明细";
},
handleUpdate(row) {
this.loading = true;
this.reset();
const detailId = row.detailId || this.ids
getStockIoDetail(detailId).then(response => {
this.loading = false;
this.form = response.data;
this.form.recordType = 0; // 修改时强制设为手动录入
this.open = true;
this.title = "修改出入库单明细";
});
},
submitForm() {
// 手动校验
if (!this.returnForm.stockIoCode) {
this.$modal.msgError("请输入退库单号");
return;
}
if (!this.returnForm.bizType) {
this.$modal.msgError("请选择业务类型");
return;
}
if (!this.manualList.filter(el => el.switchInput).length) {
this.$modal.msgError("请至少选择一个明细");
return;
}
const payload = {
stockIoCode: this.returnForm.stockIoCode,
bizType: this.returnForm.bizType,
remark: this.returnForm.remark,
ioType: 'withdraw',
parentId: this.returnForm.parentId,
details: this.manualList.filter(el => el.switchInput).map(el => {
const { detailId, stockIoId, switchInput, ...rest } = el;
return {
...rest,
quantity: el.count,
recordType: 0
}
})
};
addStockIoWithDetail(payload).then(response => {
this.$modal.msgSuccess("提交成功");
this.$emit('finish', this.stockIo);
}).catch(error => {
this.$modal.msgError("提交失败:" + (error.message || "未知错误"));
});
},
handleDelete(row) {
const detailIds = row.detailId || this.ids;
this.$modal.confirm('是否确认删除出入库单明细编号为"' + detailIds + '"的数据项?').then(() => {
this.loading = true;
return delStockIoDetail(detailIds);
}).then(() => {
this.loading = false;
this.getList();
this.$modal.msgSuccess("删除成功");
// 删除明细后刷新主表状态
this.refreshStockIoStatus();
}).catch(() => {
}).finally(() => {
this.loading = false;
});
},
reset() {
this.form = {
detailId: undefined,
stockIoId: undefined,
warehouseId: undefined,
fromWarehouseId: undefined,
itemType: undefined,
itemId: undefined,
quantity: undefined,
unit: undefined,
batchNo: undefined,
remark: undefined
};
this.unitDisabled = false; // 新增:重置单位输入框为可编辑
this.resetForm("form");
},
cancel() {
this.open = false;
this.reset();
},
handleExport() {
this.download('wms/stockIoDetail/export', {
...this.queryParams
}, `stockIoDetail_${new Date().getTime()}.xlsx`)
},
getAuditButtonText() {
if (this.stockIo.ioType === 'in') {
return '审核入库';
} else if (this.stockIo.ioType === 'out') {
return '审核出库';
} else if (this.stockIo.ioType === 'transfer') {
return '审核移库';
} else {
return '审核';
}
},
getStatusButtonText() {
if (this.stockIo.ioType === 'in') {
return '提交入库';
} else if (this.stockIo.ioType === 'out') {
return '提交出库';
} else if (this.stockIo.ioType === 'transfer') {
return '提交移库';
} else {
return '提交';
}
},
handleUpdateStatus() {
// 检查是否有明细数据
if (!this.stockIoDetailList || this.stockIoDetailList.length === 0) {
this.$modal.msgError('请先添加明细数据');
return;
}
this.$modal.confirm('确认要提交此出入库单吗?提交后将无法修改明细。').then(() => {
this.statusLoading = true;
updateStockIoStatus(this.stockIo.stockIoId, 1).then(response => {
this.$modal.msgSuccess('状态更新成功');
// 更新主表状态
this.$set(this.stockIo, 'status', 1);
// 通知父组件状态已更新
this.$emit('status-changed', this.stockIo);
}).catch(error => {
console.error('状态更新失败:', error);
this.$modal.msgError('状态更新失败:' + (error.message || '未知错误'));
}).finally(() => {
this.statusLoading = false;
});
}).catch(() => {
// 用户取消状态更新
});
},
handleCancel() {
this.$modal.confirm('确认要撤回此出入库单吗?撤回后将回滚库存数据。').then(() => {
this.cancelLoading = true;
cancelStockIo(this.stockIo.stockIoId).then(response => {
this.$modal.msgSuccess('撤回成功');
// 更新主表状态
this.$set(this.stockIo, 'status', 1);
// 刷新明细列表
this.getList();
// 通知父组件状态已更新
this.$emit('status-changed', this.stockIo);
}).catch(error => {
console.error('撤回失败:', error);
this.$modal.msgError('撤回失败:' + (error.message || '未知错误'));
}).finally(() => {
this.cancelLoading = false;
});
}).catch(() => {
// 用户取消撤回
});
},
refreshStockIoStatus() {
// 刷新主表状态
if (this.stockIo && this.stockIo.stockIoId) {
getStockIo(this.stockIo.stockIoId).then(response => {
const updatedStockIo = response.data;
// 更新主表状态
this.$set(this.stockIo, 'status', updatedStockIo.status);
// 通知父组件状态已更新
this.$emit('status-changed', this.stockIo);
}).catch(error => {
console.error('刷新主表状态失败:', error);
});
}
},
getIoTypeTagType(type) {
if (type === 'in') return 'success';
if (type === 'out') return 'primary';
if (type === 'transfer') return 'warning';
return '';
},
getIoTypeLabel(type) {
if (type === 'in') return '入库';
if (type === 'out') return '出库';
if (type === 'transfer') return '移库';
return type;
},
getBizTypeLabel(type) {
const map = {
purchase: '采购',
sales: '销售',
return: '退货',
relocation: '调拨',
other: '其他'
};
return map[type] || type;
},
getBizTypeTagType(type) {
if (type === 'purchase') return 'success';
if (type === 'sales') return 'primary';
if (type === 'return') return 'warning';
if (type === 'relocation') return 'info';
return 'default';
},
onItemChange(e) {
if (e && e.unit) {
this.form.unit = e.unit;
this.unitDisabled = true;
}
}
}
}
</script>

View File

@@ -0,0 +1,373 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="单号" prop="stockIoCode">
<el-input v-model="queryParams.stockIoCode" placeholder="请输入出入库单号" clearable
@keyup.enter.native="handleQuery" />
</el-form-item>
<el-form-item label="业务类型" prop="bizType">
<el-select style="width: 100px;" v-model="queryParams.bizType" placeholder="请选择业务类型" clearable>
<el-option v-for="dict in stock_biz_type" :key="dict.value" :label="dict.label"
:value="dict.value" />
</el-select>
</el-form-item>
<el-form-item label="单据状态" prop="status">
<el-select style="width: 100px;" v-model="queryParams.status" placeholder="请选择单据状态" clearable>
<el-option :key="0" label="草稿" :value="0" />
<el-option :key="1" label="待审核" :value="1" />
<el-option :key="2" label="已完成" :value="2" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="Refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="Plus" size="mini" @click="handleAdd">新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="success" plain icon="Edit" size="mini" :disabled="single"
@click="handleUpdate">修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="danger" plain icon="Delete" size="mini" :disabled="multiple"
@click="handleDelete">删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="warning" plain icon="Download" size="mini" @click="handleExport">导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="stockIoList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="出入库单ID" align="center" prop="stockIoId" v-if="false" />
<el-table-column label="出入库单号" align="center" prop="stockIoCode" />
<el-table-column label="类型" align="center" prop="ioType">
<template #default="scope">
<dict-tag :options="stock_io_type" :value="scope.row.ioType"></dict-tag>
</template>
</el-table-column>
<el-table-column label="业务类型" align="center" prop="bizType">
<template #default="scope">
<!-- <el-tag :type="getBizTypeTagType(scope.row.bizType)">
{{ getBizTypeLabel(scope.row.bizType) }}
</el-tag> -->
<dict-tag :options="stock_biz_type" :value="scope.row.bizType"></dict-tag>
</template>
</el-table-column>
<el-table-column label="单据状态" align="center" prop="status">
<template #default="scope">
<el-tag :type="scope.row.status === 2 ? 'success' : (scope.row.status === 1 ? 'warning' : 'info')">
{{ scope.row.status === 2 ? '已完成' : (scope.row.status === 0 ? '草稿' : '待审核') }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="创建时间" align="center" prop="createTime" />
<el-table-column label="创建人" align="center" prop="createBy" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<el-button size="mini" type="text" icon="Edit" @click="handleUpdate(scope.row)">修改</el-button>
<el-button size="mini" type="text" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
<el-button size="mini" type="text" icon="Document" @click="showDetail(scope.row)">明细</el-button>
<el-button size="mini" type="text" icon="Document"
v-if="scope.row.ioType === 'out' && scope.row.status === 2"
@click="showReturnCreate(scope.row)">退库</el-button>
</template>
</el-table-column>
</el-table>
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
@pagination="getList" />
<!-- 添加或修改出入库单主对话框 -->
<el-dialog :title="title" v-model="open" width="600px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-form-item label="出入库单号" prop="stockIoCode">
<el-input v-model="form.stockIoCode" placeholder="请输入出入库单号" />
</el-form-item>
<el-form-item label="业务类型" prop="bizType">
<el-select v-model="form.bizType" placeholder="请选择业务类型">
<el-option v-for="dict in stock_biz_type" :key="dict.value" :label="dict.label"
:value="dict.value"></el-option>
</el-select>
</el-form-item>
<el-form-item label="单据状态" prop="status">
<el-input v-model="form.status" :value="0" readonly disabled />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" placeholder="请输入备注" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button :loading="buttonLoading" type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
<!-- 明细弹窗 -->
<el-dialog title="单据明细" v-model="detailDialogVisible" width="1000px" append-to-body @close="onDetailClosed">
<StockIoDetailPanel :stockIo="detailStockIo" @status-changed="onStatusChanged" />
</el-dialog>
<el-dialog title="退库单" v-model="returnCreateDialogVisible" width="1000px" append-to-body>
<ReturnCreatePanel :stockIo="form" @finish="returnCreateDialogVisible = false" />
</el-dialog>
</div>
</template>
<script>
import { listStockIo, getStockIo, delStockIo, addStockIo, updateStockIo } from "@/api/wms/stockIo";
import StockIoDetailPanel from './detail.vue';
import ReturnCreatePanel from './returnCreate.vue';
export default {
name: "StockIo",
setup() {
const { proxy } = getCurrentInstance();
const { stock_biz_type, stock_status, stock_io_type } = proxy.useDict('stock_biz_type', 'stock_status', 'stock_io_type');
return {
stock_biz_type,
stock_status,
stock_io_type,
};
},
components: { StockIoDetailPanel, ReturnCreatePanel },
props: {
ioType: {
require: true
}
},
data() {
return {
// 按钮loading
buttonLoading: false,
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 出入库单主表格数据
stockIoList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 20,
stockIoCode: undefined,
ioType: this.ioType,
bizType: undefined,
status: undefined,
},
// 表单参数
form: {},
// 表单校验
rules: {
stockIoId: [
{ required: true, message: "出入库单ID不能为空", trigger: "blur" }
],
stockIoCode: [
{ required: true, message: "出入库单号不能为空", trigger: "blur" }
],
bizType: [
{ required: true, message: "业务类型不能为空", trigger: "change" }
],
status: [
{ required: true, message: "单据状态不能为空", trigger: "change" }
],
delFlag: [
{ required: true, message: "删除标志不能为空", trigger: "blur" }
],
createTime: [
{ required: true, message: "创建时间不能为空", trigger: "blur" }
],
updateTime: [
{ required: true, message: "更新时间不能为空", trigger: "blur" }
],
},
detailDialogVisible: false,
detailStockIo: null,
returnCreateDialogVisible: false,
};
},
created() {
this.getList();
},
methods: {
/** 查询出入库单主列表 */
getList() {
this.loading = true;
listStockIo(this.queryParams).then(response => {
this.stockIoList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
stockIoId: undefined,
stockIoCode: undefined,
ioType: this.ioType,
bizType: undefined,
status: undefined,
remark: undefined,
delFlag: undefined,
createTime: undefined,
createBy: undefined,
updateTime: undefined,
updateBy: undefined
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.stockIoId)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.form.status = 0; // 新增时默认草稿状态
this.open = true;
this.title = "添加单据";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.loading = true;
this.reset();
const stockIoId = row.stockIoId || this.ids
getStockIo(stockIoId).then(response => {
this.loading = false;
this.form = response.data;
this.open = true;
this.title = "修改单据";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
this.buttonLoading = true;
if (this.form.stockIoId != null) {
updateStockIo(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
}).finally(() => {
this.buttonLoading = false;
});
} else {
addStockIo(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
}).finally(() => {
this.buttonLoading = false;
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const stockIoIds = row.stockIoId || this.ids;
this.$modal.confirm('是否确认删除出入库单主编号为"' + stockIoIds + '"的数据项?').then(() => {
this.loading = true;
return delStockIo(stockIoIds);
}).then(() => {
this.loading = false;
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {
}).finally(() => {
this.loading = false;
});
},
/** 导出按钮操作 */
handleExport() {
this.download('wms/stockIo/export', {
...this.queryParams
}, `stockIo_${new Date().getTime()}.xlsx`)
},
showDetail(row) {
this.detailStockIo = { ...row };
this.detailDialogVisible = true;
},
onDetailClosed() {
this.getList();
},
onStatusChanged(updatedStockIo) {
// 更新主表中的对应记录状态
const index = this.stockIoList.findIndex(item => item.stockIoId === updatedStockIo.stockIoId);
if (index !== -1) {
this.$set(this.stockIoList, index, updatedStockIo);
}
// 刷新列表
this.getList();
},
getIoTypeTagType(type) {
if (type === 'in') return 'success';
if (type === 'out') return 'primary';
if (type === 'transfer') return 'warning';
return '';
},
getIoTypeLabel(type) {
if (type === 'in') return '入库';
if (type === 'out') return '出库';
if (type === 'transfer') return '移库';
return type;
},
getBizTypeTagType(type) {
if (type === 'purchase') return 'success';
if (type === 'sales') return 'primary';
if (type === 'return') return 'warning';
if (type === 'relocation') return 'info';
return 'default';
},
getBizTypeLabel(type) {
const map = {
purchase: '采购',
sales: '销售',
return: '退货',
relocation: '调拨',
other: '其他'
};
return map[type] || type;
},
showReturnCreate(row) {
this.returnCreateDialogVisible = true;
this.form = { ...row };
}
}
}
</script>

View File

@@ -0,0 +1,13 @@
<template>
<StockIoPage ioType="withdraw" />
</template>
<script>
import StockIoPage from './panels/stockIoPage.vue';
export default {
components: {
StockIoPage
}
}
</script>