2 changed files with 406 additions and 123 deletions
-
275src/views/modules/warehouse/MultiSelectDialog.vue
-
254src/views/modules/warehouse/countingReport.vue
@ -0,0 +1,275 @@ |
|||
<template> |
|||
<el-dialog |
|||
:title="dialogTitle" |
|||
:visible.sync="visible" |
|||
width="800px" |
|||
:close-on-click-modal="false" |
|||
v-drag |
|||
@close="handleClose"> |
|||
|
|||
<!-- 查询条件 --> |
|||
<el-form :inline="true" label-position="top" :model="searchForm" style="margin-bottom: 5px;"> |
|||
<el-form-item :label="codeLabel"> |
|||
<el-input |
|||
v-model="searchForm.code" |
|||
:placeholder="'请输入' + codeLabel" |
|||
clearable |
|||
style="width: 150px" |
|||
@keyup.enter.native="handleSearch"> |
|||
</el-input> |
|||
</el-form-item> |
|||
<el-form-item :label="nameLabel"> |
|||
<el-input |
|||
v-model="searchForm.name" |
|||
:placeholder="'请输入' + nameLabel" |
|||
clearable |
|||
style="width: 200px" |
|||
@keyup.enter.native="handleSearch"> |
|||
</el-input> |
|||
</el-form-item> |
|||
<el-form-item label=" "> |
|||
<el-button type="primary" icon="el-icon-search" @click="handleSearch">查询</el-button> |
|||
<el-button icon="el-icon-refresh-left" @click="handleReset">重置</el-button> |
|||
</el-form-item> |
|||
</el-form> |
|||
|
|||
<!-- 数据表格 --> |
|||
<el-table |
|||
ref="dataTable" |
|||
:data="dataList" |
|||
border |
|||
height="400" |
|||
v-loading="loading" |
|||
@selection-change="handleSelectionChange" |
|||
style="width: 100%;"> |
|||
<el-table-column |
|||
type="selection" |
|||
width="55" |
|||
align="center"> |
|||
</el-table-column> |
|||
<el-table-column |
|||
:prop="codeField" |
|||
:label="codeLabel" |
|||
width="150" |
|||
align="left"> |
|||
</el-table-column> |
|||
<el-table-column |
|||
:prop="nameField" |
|||
:label="nameLabel" |
|||
align="left"> |
|||
</el-table-column> |
|||
</el-table> |
|||
|
|||
<!-- 分页 --> |
|||
<el-pagination |
|||
@size-change="handleSizeChange" |
|||
@current-change="handleCurrentChange" |
|||
:current-page="pageIndex" |
|||
:page-sizes="[20, 50, 100, 200]" |
|||
:page-size="pageSize" |
|||
:total="totalPage" |
|||
layout="total, sizes, prev, pager, next, jumper" |
|||
style="margin-top: 10px; text-align: right"> |
|||
</el-pagination> |
|||
|
|||
<div slot="footer" class="dialog-footer"> |
|||
<el-button type="primary" @click="handleConfirm">确定</el-button> |
|||
<el-button @click="handleClose">取消</el-button> |
|||
</div> |
|||
</el-dialog> |
|||
</template> |
|||
|
|||
<script> |
|||
export default { |
|||
name: 'MultiSelectDialog', |
|||
data() { |
|||
return { |
|||
visible: false, |
|||
dialogTitle: '', |
|||
codeLabel: '编码', |
|||
nameLabel: '名称', |
|||
codeField: 'code', |
|||
nameField: 'name', |
|||
searchForm: { |
|||
code: '', |
|||
name: '' |
|||
}, |
|||
dataList: [], |
|||
allDataList: [], // 存储所有数据用于前端搜索 |
|||
loading: false, |
|||
pageIndex: 1, |
|||
pageSize: 20, |
|||
totalPage: 0, |
|||
selectedRows: [], |
|||
dataType: '', // 'warehouse', 'location', 'part' |
|||
site: '', |
|||
buNo: '' |
|||
} |
|||
}, |
|||
methods: { |
|||
// 初始化对话框 |
|||
init(type, site, buNo, selectedIds = []) { |
|||
this.dataType = type |
|||
this.site = site |
|||
this.buNo = buNo |
|||
this.visible = true |
|||
this.searchForm = { code: '', name: '' } |
|||
this.selectedRows = [] |
|||
this.pageIndex = 1 |
|||
|
|||
// 根据类型设置标签和字段 |
|||
if (type === 'warehouse') { |
|||
this.dialogTitle = '选择仓库(多选)' |
|||
this.codeLabel = '仓库编码' |
|||
this.nameLabel = '仓库名称' |
|||
this.codeField = 'WareHouseID' |
|||
this.nameField = 'WareHouseName' |
|||
} else if (type === 'location') { |
|||
this.dialogTitle = '选择货位(多选)' |
|||
this.codeLabel = '货位编码' |
|||
this.nameLabel = '货位名称' |
|||
this.codeField = 'LocationID' |
|||
this.nameField = 'LocationName' |
|||
} else if (type === 'part') { |
|||
this.dialogTitle = '选择物料(多选)' |
|||
this.codeLabel = '物料编码' |
|||
this.nameLabel = '物料名称' |
|||
this.codeField = 'PartNo' |
|||
this.nameField = 'PartDescription' |
|||
} |
|||
|
|||
// 加载数据 |
|||
this.loadData(selectedIds) |
|||
}, |
|||
|
|||
// 加载数据 |
|||
loadData(selectedIds = []) { |
|||
this.loading = true |
|||
|
|||
// 根据类型构造SQL |
|||
let sql = '' |
|||
if (this.dataType === 'warehouse') { |
|||
sql = `Select WareHouseID, WareHouseName from WareHouse where active = 'Y' and site = '${this.site}' and bu_no = '${this.buNo}'` |
|||
} else if (this.dataType === 'location') { |
|||
sql = `Select LocationID, LocationName from Location where Active = 'Y' and site = '${this.site}' and bu_no = '${this.buNo}'` |
|||
} else if (this.dataType === 'part') { |
|||
sql = `Select PartNo, PartDescription from Part where active = 'Y' and site = '${this.site}'` |
|||
} |
|||
|
|||
// 调用后端API |
|||
this.$http({ |
|||
url: this.$http.adornUrl('/warehouse/countingReport/querySelectData'), |
|||
method: 'post', |
|||
data: this.$http.adornData({ sql }) |
|||
}).then(({ data }) => { |
|||
if (data && data.code === 0) { |
|||
this.allDataList = data.list || [] |
|||
this.filterData() |
|||
|
|||
// 回显选中项 |
|||
this.$nextTick(() => { |
|||
if (selectedIds && selectedIds.length > 0) { |
|||
this.allDataList.forEach(row => { |
|||
if (selectedIds.includes(row[this.codeField])) { |
|||
this.$refs.dataTable.toggleRowSelection(row, true) |
|||
} |
|||
}) |
|||
} |
|||
}) |
|||
} else { |
|||
this.$message.error(data.msg || '查询失败') |
|||
} |
|||
this.loading = false |
|||
}).catch(() => { |
|||
this.loading = false |
|||
}) |
|||
}, |
|||
|
|||
// 过滤数据(前端搜索) |
|||
filterData() { |
|||
let filtered = this.allDataList |
|||
|
|||
// 按编码过滤 |
|||
if (this.searchForm.code) { |
|||
filtered = filtered.filter(item => |
|||
item[this.codeField] && |
|||
item[this.codeField].toLowerCase().includes(this.searchForm.code.toLowerCase()) |
|||
) |
|||
} |
|||
|
|||
// 按名称过滤 |
|||
if (this.searchForm.name) { |
|||
filtered = filtered.filter(item => |
|||
item[this.nameField] && |
|||
item[this.nameField].toLowerCase().includes(this.searchForm.name.toLowerCase()) |
|||
) |
|||
} |
|||
|
|||
// 分页 |
|||
this.totalPage = filtered.length |
|||
const start = (this.pageIndex - 1) * this.pageSize |
|||
const end = start + this.pageSize |
|||
this.dataList = filtered.slice(start, end) |
|||
}, |
|||
|
|||
// 查询 |
|||
handleSearch() { |
|||
this.pageIndex = 1 |
|||
this.filterData() |
|||
}, |
|||
|
|||
// 重置 |
|||
handleReset() { |
|||
this.searchForm = { code: '', name: '' } |
|||
this.pageIndex = 1 |
|||
this.filterData() |
|||
}, |
|||
|
|||
// 分页 |
|||
handleSizeChange(val) { |
|||
this.pageSize = val |
|||
this.pageIndex = 1 |
|||
this.filterData() |
|||
}, |
|||
|
|||
handleCurrentChange(val) { |
|||
this.pageIndex = val |
|||
this.filterData() |
|||
}, |
|||
|
|||
// 多选变化 |
|||
handleSelectionChange(selection) { |
|||
this.selectedRows = selection |
|||
}, |
|||
|
|||
// 确定 |
|||
handleConfirm() { |
|||
if (this.selectedRows.length === 0) { |
|||
this.$message.warning('请至少选择一项') |
|||
return |
|||
} |
|||
|
|||
// 返回选中的数据 |
|||
const result = { |
|||
type: this.dataType, |
|||
codes: this.selectedRows.map(row => row[this.codeField]), |
|||
names: this.selectedRows.map(row => row[this.nameField]), |
|||
rows: this.selectedRows |
|||
} |
|||
|
|||
this.$emit('confirm', result) |
|||
this.handleClose() |
|||
}, |
|||
|
|||
// 关闭 |
|||
handleClose() { |
|||
this.visible = false |
|||
this.selectedRows = [] |
|||
} |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<style scoped> |
|||
</style> |
|||
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue