add:仓储管理出入库单据增加导出明细到excel

This commit is contained in:
zhaoyf
2026-10-31 15:53:39 +08:00
parent 46d922d7e3
commit 127cb06847
3 changed files with 205 additions and 16 deletions

View File

@@ -0,0 +1,47 @@
import XLSX from 'xlsx'
/**
* 生成文件名中的时间戳,如 20261031_152919
*/
export function formatExportTime(date) {
const pad = value => String(value).padStart(2, '0')
return date.getFullYear() + pad(date.getMonth() + 1) + pad(date.getDate()) + '_' +
pad(date.getHours()) + pad(date.getMinutes()) + pad(date.getSeconds())
}
/**
* 将数据按列定义导出为 excel 文件
*
* @param {Object} options
* @param {Array} options.columns 列定义 [{ label, prop, width, value }],value 为可选的自定义取值函数
* @param {Array} options.rows 数据行
* @param {String} options.sheetName sheet 名称
* @param {String} options.fileName 文件名(不含时间戳和后缀)
*/
export function exportRowsToExcel({ columns, rows, sheetName = '明细', fileName = '明细' }) {
if (!columns || !columns.length) {
throw new Error('未定义导出列')
}
const header = columns.map(col => col.label)
const body = rows.map(row => columns.map(col => {
const value = typeof col.value === 'function' ? col.value(row) : row[col.prop]
if (value === null || value === undefined) {
return ''
}
return value
}))
const sheet = XLSX.utils.aoa_to_sheet([header].concat(body))
sheet['!cols'] = columns.map(col => ({ wch: col.width || 14 }))
if (body.length) {
sheet['!autofilter'] = {
ref: XLSX.utils.encode_range({
s: { r: 0, c: 0 },
e: { r: body.length, c: header.length - 1 }
})
}
}
const workbook = XLSX.utils.book_new()
XLSX.utils.book_append_sheet(workbook, sheet, sheetName)
XLSX.writeFile(workbook, fileName + '_' + formatExportTime(new Date()) + '.xlsx')
return body.length
}

View File

@@ -130,6 +130,18 @@
>
强制确认
</el-button>
<el-button
slot="right"
class="filter-item"
type="primary"
plain
icon="el-icon-download"
size="mini"
:loading="exporting"
@click="exportDetail"
>
导出明细
</el-button>
</crudOperation>
<!--表格渲染-->
<el-table
@@ -212,6 +224,7 @@ import ViewDialog from '@/views/wms/st/inbill/ViewDialog'
// import TaskDialog from '@/views/wms/st/inbill/TaskDialog'
import { mapGetters } from 'vuex'
import crudBsrealstorattr from '@/views/wms/basedata/bsrealstorattr/bsrealstorattr'
import { exportRowsToExcel } from '@/utils/export-excel'
export default {
name: 'Rawassist',
@@ -240,6 +253,7 @@ export default {
audit_flag: true,
dis_flag: true,
task_flag: true,
exporting: false,
disShow: false,
viewShow: false,
mstrow: {},
@@ -308,18 +322,20 @@ export default {
return row.bill_status !== '10'
},
handleSelectionChange(val, row) {
if (val.length > 1) {
this.$refs.table.clearSelection()
this.$refs.table.toggleRowSelection(val.pop())
this.buttonChange(row)
} else if (val.length === 1) {
this.buttonChange(row)
} else {
if (val.length === 0) {
this.handleCurrentChange(null)
return
}
// 记录最后勾选的行,供分配、强制确认等单条操作使用
this.buttonChange(row)
if (val.length > 1) {
// 多选只用于批量导出明细,单条操作按钮置为不可用,避免误操作
this.dis_flag = true
this.task_flag = true
}
},
onSelectAll() {
this.$refs.table.clearSelection()
// 允许全选,便于一次性导出当前页全部单据的明细
this.handleCurrentChange(null)
},
buttonChange(currentRow) {
@@ -375,7 +391,62 @@ export default {
this.divShow = true
})
},
exportDetail() {
const selections = this.crud.selections || []
if (!selections.length) {
this.crud.notify('请先勾选要导出的单据', CRUD.NOTIFICATION_TYPE.INFO)
return
}
this.exporting = true
const promises = selections.map(bill => {
return crudRawAssist.getIODtl({ 'iostorinv_id': bill.iostorinv_id }).then(res => {
const dtlList = res.data || []
return dtlList.map(dtl => ({ ...dtl, stor_name: dtl.stor_name || bill.stor_name }))
})
})
Promise.all(promises).then(results => {
const allDtls = results.reduce((acc, cur) => acc.concat(cur), [])
if (allDtls.length === 0) {
this.crud.notify('未查询到明细数据', CRUD.NOTIFICATION_TYPE.INFO)
return
}
const total = exportRowsToExcel({
columns: this.detailColumns(),
rows: allDtls,
sheetName: '入库明细',
fileName: '入库明细'
})
this.crud.notify('导出成功,共 ' + total + ' 条明细', CRUD.NOTIFICATION_TYPE.SUCCESS)
}).catch(() => {
this.crud.notify('导出失败,请重试', CRUD.NOTIFICATION_TYPE.ERROR)
}).finally(() => {
this.exporting = false
})
},
detailColumns() {
return [
{ label: '单据号', prop: 'bill_code', width: 20 },
{ label: '仓库', prop: 'stor_name', width: 18 },
{ label: '行号', prop: 'seq_no', width: 8 },
{ label: '物料编码', prop: 'material_code', width: 20 },
{ label: '物料名称', prop: 'material_name', width: 28 },
{ label: '批次号', prop: 'pcsn', width: 18 },
{ label: '明细状态', prop: 'bill_status', width: 12, value: row => this.dict.label.io_bill_status[row.bill_status] || row.bill_status },
{ label: '计划数量', prop: 'plan_qty', width: 12 },
{ label: '已分配数量', prop: 'assign_qty', width: 12 },
{ label: '未分配数量', prop: 'unassign_qty', width: 12 },
{ label: '实际数量', prop: 'real_qty', width: 12 },
{ label: '单位', prop: 'qty_unit_name', width: 8 },
{ label: '载具类型', prop: 'vehicle_type', width: 14 },
{ label: '载具编号', prop: 'storagevehicle_code', width: 18 },
{ label: '来源单号', prop: 'source_bill_code', width: 20 },
{ label: '备注', prop: 'remark', width: 24 }
]
},
querytable() {
if (this.$refs.table) {
this.$refs.table.clearSelection()
}
this.onSelectAll()
this.crud.toQuery()
}

View File

@@ -159,6 +159,17 @@
@click="printBill"
>出库标签打印
</el-button>
<el-button
slot="right"
class="filter-item"
type="primary"
plain
icon="el-icon-download"
size="mini"
:loading="exporting"
@click="exportDetail"
>导出明细
</el-button>
</crudOperation>
<!--表格渲染-->
<el-table
@@ -250,6 +261,7 @@ import DivDialog from '@/views/wms/st/outbill/DivDialog'
import ViewDialog from '@/views/wms/st/outbill/ViewDialog'
import crudBsrealstorattr from '@/views/wms/basedata/bsrealstorattr/bsrealstorattr'
import QRCode from 'qrcode'
import { exportRowsToExcel } from '@/utils/export-excel'
export default {
name: 'Checkoutbill',
@@ -279,6 +291,7 @@ export default {
confirm: ['admin', 'checkoutbill:confirm']
},
loadingConfirm: false,
exporting: false,
divShow: false,
printPreviewVisible: false,
dis_flag: true,
@@ -359,18 +372,20 @@ export default {
this.handleCurrentChange(null)
},
handleSelectionChange(val, row) {
if (val.length > 1) {
this.$refs.table.clearSelection()
this.$refs.table.toggleRowSelection(val.pop())
this.buttonChange(row)
} else if (val.length === 1) {
this.buttonChange(row)
} else {
if (val.length === 0) {
this.handleCurrentChange(null)
return
}
// 记录最后勾选的行,供分配、强制确认等单条操作使用
this.buttonChange(row)
if (val.length > 1) {
// 多选只用于批量导出明细,单条操作按钮置为不可用,避免误操作
this.dis_flag = true
this.confirm_flag = true
}
},
onSelectAll() {
this.$refs.table.clearSelection()
// 允许全选,便于一次性导出当前页全部单据的明细
this.handleCurrentChange(null)
},
doPrint() {
@@ -394,6 +409,59 @@ export default {
this.fetchDetailsAndPrint(selections)
}).catch(() => {})
},
exportDetail() {
const selections = this.crud.selections || []
if (!selections.length) {
this.crud.notify('请先勾选要导出的单据', CRUD.NOTIFICATION_TYPE.INFO)
return
}
this.exporting = true
const promises = selections.map(bill => {
return checkoutbill.getOutBillDtl({ 'iostorinv_id': bill.iostorinv_id }).then(res => {
const dtlList = res.data || []
return dtlList.map(dtl => ({ ...dtl, stor_name: dtl.stor_name || bill.stor_name }))
})
})
Promise.all(promises).then(results => {
const allDtls = results.reduce((acc, cur) => acc.concat(cur), [])
if (allDtls.length === 0) {
this.crud.notify('未查询到明细数据', CRUD.NOTIFICATION_TYPE.INFO)
return
}
const total = exportRowsToExcel({
columns: this.detailColumns(),
rows: allDtls,
sheetName: '出库明细',
fileName: '出库明细'
})
this.crud.notify('导出成功,共 ' + total + ' 条明细', CRUD.NOTIFICATION_TYPE.SUCCESS)
}).catch(() => {
this.crud.notify('导出失败,请重试', CRUD.NOTIFICATION_TYPE.ERROR)
}).finally(() => {
this.exporting = false
})
},
detailColumns() {
return [
{ label: '单据号', prop: 'bill_code', width: 20 },
{ label: '仓库', prop: 'stor_name', width: 18 },
{ label: '行号', prop: 'seq_no', width: 8 },
{ label: '物料编码', prop: 'material_code', width: 20 },
{ label: '物料名称', prop: 'material_name', width: 28 },
{ label: '批次号', prop: 'pcsn', width: 18 },
{ label: '明细状态', prop: 'bill_status', width: 12, value: row => this.dict.label.io_bill_status[row.bill_status] || row.bill_status },
{ label: '计划数量', prop: 'plan_qty', width: 12 },
{ label: '已分配数量', prop: 'assign_qty', width: 12 },
{ label: '未分配数量', prop: 'unassign_qty', width: 12 },
{ label: '实际数量', prop: 'real_qty', width: 12 },
{ label: '单位', prop: 'qty_unit_name', width: 8 },
{ label: '载具类型', prop: 'vehicle_type', width: 14 },
{ label: '载具编号', prop: 'storagevehicle_code', width: 18 },
{ label: '用料位置', prop: 'source_load_port', width: 16 },
{ label: '来源单号', prop: 'source_bill_code', width: 20 },
{ label: '备注', prop: 'remark', width: 24 }
]
},
fetchDetailsAndPrint(selections) {
const promises = selections.map(bill => {
return checkoutbill.getOutBillDtl({ 'iostorinv_id': bill.iostorinv_id }).then(res => {
@@ -546,6 +614,9 @@ export default {
})
},
querytable() {
if (this.$refs.table) {
this.$refs.table.clearSelection()
}
this.onSelectAll()
this.crud.toQuery()
this.handleCurrentChange(null)