parent
8b36334de6
commit
94e2170923
5 changed files with 576 additions and 443 deletions
@ -1,328 +1,362 @@ |
|||||||
<template> |
<template> |
||||||
<el-dialog :close-on-click-modal="false" :title="categoryDialogTitle" :visible.sync="categoryVisible" |
<el-dialog |
||||||
:append-to-body="true" width="70%" @close="handleCloseDetail" fullscreen> |
:close-on-click-modal="false" |
||||||
<el-tabs v-model="transactionType" @tab-click="handleTabClick"> |
:title="categoryDialogTitle" |
||||||
<el-tab-pane label="易耗品" name="YH"></el-tab-pane> |
:visible.sync="categoryVisible" |
||||||
<el-tab-pane label="耐用品" name="NY"></el-tab-pane> |
:append-to-body="true" |
||||||
</el-tabs> |
width="70%" |
||||||
<avue-crud :option="option" :table-loading="loading" :data="data" ref="crud" v-model="form" :page.sync="page" |
@close="handleCancel" |
||||||
:permission="permissionList" @row-del="rowDel" @search-change="searchChange" @search-reset="searchReset" |
fullscreen |
||||||
@selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange" |
> |
||||||
@refresh-change="refreshChange" @on-load="onLoad" @row-change="handleRowChange"> |
<el-tabs v-model="transactionType" @tab-click="handleTabClick"> |
||||||
</avue-crud> |
<el-tab-pane label="易耗品" name="YH"></el-tab-pane> |
||||||
<div slot="footer" class="dialog-footer"> |
<el-tab-pane label="耐用品" name="NY"></el-tab-pane> |
||||||
<el-button @click="handleCancel">取消</el-button> |
</el-tabs> |
||||||
<el-button type="primary" @click="handleConfirm">确定</el-button> |
<avue-crud |
||||||
</div> |
:option="option" |
||||||
</el-dialog> |
:table-loading="loading" |
||||||
|
:data="data" |
||||||
|
ref="crud" |
||||||
|
v-model="form" |
||||||
|
:page.sync="page" |
||||||
|
:permission="permissionList" |
||||||
|
@row-del="rowDel" |
||||||
|
@search-change="searchChange" |
||||||
|
@search-reset="searchReset" |
||||||
|
@select="selectionChange" |
||||||
|
@current-change="currentChange" |
||||||
|
@size-change="sizeChange" |
||||||
|
@refresh-change="refreshChange" |
||||||
|
@on-load="onLoad" |
||||||
|
@row-change="handleRowChange" |
||||||
|
row-key="id" |
||||||
|
> |
||||||
|
</avue-crud> |
||||||
|
<div slot="footer" class="dialog-footer"> |
||||||
|
<el-button @click="handleCancel">取消</el-button> |
||||||
|
<el-button type="primary" @click="handleConfirm">确定</el-button> |
||||||
|
</div> |
||||||
|
</el-dialog> |
||||||
</template> |
</template> |
||||||
<script> |
<script> |
||||||
import { getList } from "@/api/secondOrder/list.js"; |
import { getList } from "@/api/secondOrder/list.js"; |
||||||
import { getList as fetchDurableApi } from "@/api/materials/expend"; |
import { getList as fetchDurableApi } from "@/api/materials/expend"; |
||||||
|
|
||||||
export default { |
export default { |
||||||
props: { |
props: { |
||||||
categoryVisible: { |
categoryVisible: { |
||||||
type: Boolean, |
type: Boolean, |
||||||
default: false |
default: false, |
||||||
}, |
|
||||||
categoryDialogTitle: { |
|
||||||
type: String, |
|
||||||
default: '' |
|
||||||
}, |
|
||||||
departmentId: { |
|
||||||
type: [String, Number], |
|
||||||
default: '' |
|
||||||
}, |
|
||||||
selectionData: { |
|
||||||
type: Array, |
|
||||||
default: () => [] |
|
||||||
} |
|
||||||
}, |
}, |
||||||
data() { |
categoryDialogTitle: { |
||||||
return { |
type: String, |
||||||
form: {}, |
default: "", |
||||||
selectionList: [], |
}, |
||||||
newselection: [], |
departmentId: { |
||||||
query: {}, |
type: [String, Number], |
||||||
loading: true, |
default: "", |
||||||
page: { |
}, |
||||||
pageSize: 10, |
selectionData: { |
||||||
currentPage: 1, |
type: Array, |
||||||
total: 0, |
default: () => [], |
||||||
}, |
}, |
||||||
option: { |
}, |
||||||
reserveSelection: true, |
data() { |
||||||
calcHeight: 30, |
return { |
||||||
tip: false, |
form: {}, |
||||||
searchShow: true, |
selectionList: [], |
||||||
searchMenuSpan: 18, |
newselection: [], |
||||||
border: true, |
query: {}, |
||||||
index: true, |
loading: true, |
||||||
selection: true, |
page: { |
||||||
viewBtn: true, |
pageSize: 10, |
||||||
dialogClickModal: false, |
currentPage: 1, |
||||||
menu: false, |
total: 0, |
||||||
addBtn: false, |
}, |
||||||
printBtn: false, |
option: { |
||||||
refreshBtn: false, |
reserveSelection: true, |
||||||
gridBtn: false, |
calcHeight: 30, |
||||||
gridBackgroundImage: false, |
tip: false, |
||||||
gridSpan: false, |
searchShow: true, |
||||||
filterBtn: false, |
searchMenuSpan: 18, |
||||||
columnBtn: false, |
border: true, |
||||||
menuAlign: "left", |
index: true, |
||||||
searchMenuPosition: "right", |
selection: true, |
||||||
menuWidth: 80, |
viewBtn: true, |
||||||
selectable: (row, index) => row.num !== 0, |
dialogClickModal: false, |
||||||
column: [ |
menu: false, |
||||||
{ |
addBtn: false, |
||||||
label: "存货编号", |
printBtn: false, |
||||||
prop: "materialCode", |
refreshBtn: false, |
||||||
headerAlign: "center", |
gridBtn: false, |
||||||
align: "center", |
gridBackgroundImage: false, |
||||||
}, |
gridSpan: false, |
||||||
{ |
filterBtn: false, |
||||||
label: "存货名称", |
columnBtn: false, |
||||||
prop: "materialName", |
menuAlign: "left", |
||||||
search: true, |
searchMenuPosition: "right", |
||||||
headerAlign: "center", |
menuWidth: 80, |
||||||
align: "left", |
selectable: (row, index) => row.num !== 0, |
||||||
}, |
column: [ |
||||||
{ |
{ |
||||||
label: "规格型号", |
label: "存货编号", |
||||||
prop: "model", |
prop: "materialCode", |
||||||
headerAlign: "center", |
headerAlign: "center", |
||||||
align: "left", |
align: "center", |
||||||
}, |
}, |
||||||
{ |
{ |
||||||
label: "类别", |
label: "存货名称", |
||||||
prop: "type", |
prop: "materialName", |
||||||
search: false, |
search: true, |
||||||
type: "select", |
headerAlign: "center", |
||||||
headerAlign: "center", |
align: "left", |
||||||
align: "center", |
}, |
||||||
value: "NY", |
{ |
||||||
disabled: true, |
label: "规格型号", |
||||||
dicData: [ |
prop: "model", |
||||||
{ |
headerAlign: "center", |
||||||
label: "易耗品", |
align: "left", |
||||||
value: "YH", |
}, |
||||||
}, |
{ |
||||||
{ |
label: "类别", |
||||||
label: "耐用品", |
prop: "type", |
||||||
value: "NY", |
search: false, |
||||||
}, |
type: "select", |
||||||
], |
headerAlign: "center", |
||||||
}, |
align: "center", |
||||||
{ |
value: "NY", |
||||||
label: "计量单位", |
disabled: true, |
||||||
prop: "unit", |
dicData: [ |
||||||
headerAlign: "center", |
{ |
||||||
align: "center", |
label: "易耗品", |
||||||
}, |
value: "YH", |
||||||
{ |
}, |
||||||
label: "数量", |
{ |
||||||
prop: "num", |
label: "耐用品", |
||||||
headerAlign: "center", |
value: "NY", |
||||||
align: "center", |
}, |
||||||
}, |
], |
||||||
{ |
}, |
||||||
label: "单价", |
{ |
||||||
prop: "unitPrice", |
label: "计量单位", |
||||||
headerAlign: "center", |
prop: "unit", |
||||||
align: "center", |
headerAlign: "center", |
||||||
formatter: (row, column) => { |
align: "center", |
||||||
const value = row.unitPrice; |
}, |
||||||
if (value === null || value === undefined || value === "") { |
{ |
||||||
return "-"; |
label: "数量", |
||||||
} |
prop: "num", |
||||||
return value; |
headerAlign: "center", |
||||||
} |
align: "center", |
||||||
}, |
}, |
||||||
], |
{ |
||||||
|
label: "单价", |
||||||
|
prop: "unitPrice", |
||||||
|
headerAlign: "center", |
||||||
|
align: "center", |
||||||
|
formatter: (row, column) => { |
||||||
|
const value = row.unitPrice; |
||||||
|
if (value === null || value === undefined || value === "") { |
||||||
|
return "-"; |
||||||
|
} |
||||||
|
return value; |
||||||
}, |
}, |
||||||
data: [], |
}, |
||||||
dialogLogVisible: false, |
], |
||||||
transactionType: "YH", |
}, |
||||||
tableData: [], |
data: [], |
||||||
ckTable: [], |
dialogLogVisible: false, |
||||||
rkTable: [], |
transactionType: "YH", |
||||||
currentRow: null, |
tableData: [], |
||||||
allSelectedList: [], |
ckTable: [], |
||||||
isUpdatingSelection: false, |
rkTable: [], |
||||||
} |
currentRow: null, |
||||||
|
allSelectedList: [], |
||||||
|
isUpdatingSelection: false, |
||||||
|
}; |
||||||
|
}, |
||||||
|
mounted() { |
||||||
|
// 初始化时使用传入的selectionData |
||||||
|
this.allSelectedList = [...this.selectionData]; |
||||||
|
this.onLoad(this.page); |
||||||
|
}, |
||||||
|
methods: { |
||||||
|
//清空搜索 |
||||||
|
searchReset() { |
||||||
|
this.query = {}; |
||||||
|
this.onLoad(this.page); |
||||||
}, |
}, |
||||||
mounted() { |
searchChange(params, done) { |
||||||
// 初始化时使用传入的selectionData |
this.query = params; |
||||||
this.allSelectedList = [...this.selectionData]; |
this.page.currentPage = 1; |
||||||
this.onLoad(this.page); |
this.onLoad(this.page, params); |
||||||
|
done(); |
||||||
}, |
}, |
||||||
methods: { |
|
||||||
//清空搜索 |
|
||||||
searchReset() { |
|
||||||
this.query = {}; |
|
||||||
this.onLoad(this.page); |
|
||||||
}, |
|
||||||
searchChange(params, done) { |
|
||||||
this.query = params; |
|
||||||
this.page.currentPage = 1; |
|
||||||
this.onLoad(this.page, params); |
|
||||||
done(); |
|
||||||
}, |
|
||||||
|
|
||||||
// 更新当前页面的勾选状态 |
// 更新当前页面的勾选状态 |
||||||
updateCurrentPageSelection() { |
updateCurrentPageSelection() { |
||||||
if (!this.$refs.crud || !this.data) return; |
if (!this.$refs.crud || !this.data) return; |
||||||
|
|
||||||
this.isUpdatingSelection = true; |
|
||||||
|
|
||||||
const currentPageData = this.data || []; |
|
||||||
|
|
||||||
// 先清除所有选择 |
|
||||||
this.$refs.crud.toggleSelection(); |
|
||||||
|
|
||||||
// 检查当前页面的数据中有哪些在 allSelectedList 中 |
|
||||||
currentPageData.forEach((item) => { |
|
||||||
const isSelected = this.allSelectedList.some(selectedItem => |
|
||||||
selectedItem.id === item.id |
|
||||||
); |
|
||||||
|
|
||||||
if (isSelected) { |
this.isUpdatingSelection = true; |
||||||
this.$refs.crud.toggleRowSelection(item, true); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
// 延迟 确保选择状态已完全更新 |
|
||||||
this.$nextTick(() => { |
|
||||||
setTimeout(() => { |
|
||||||
this.isUpdatingSelection = false |
|
||||||
}, 100); |
|
||||||
}); |
|
||||||
}, |
|
||||||
|
|
||||||
//勾选选中 |
const currentPageData = this.data || []; |
||||||
selectionChange(selection) { |
|
||||||
if (this.isUpdatingSelection) { |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
console.log('当前选择:', selection) |
|
||||||
console.log('当前页面数据:', this.data) |
|
||||||
console.log('当前全部勾选:', this.allSelectedList) |
|
||||||
|
|
||||||
// 获取当前页面的数据ID |
|
||||||
const currentPageIds = this.data.map(item => item.id); |
|
||||||
|
|
||||||
const otherPageSelected = this.allSelectedList.filter(item => |
|
||||||
!currentPageIds.includes(item.id) |
|
||||||
); |
|
||||||
|
|
||||||
const currentSelected = selection.map(item => ({ |
|
||||||
...item, |
|
||||||
twoInventoryId: item.id |
|
||||||
})); |
|
||||||
|
|
||||||
// 组合所有勾选数据 |
|
||||||
const combinedSelection = [ |
|
||||||
...otherPageSelected, // 其他页面的数据 |
|
||||||
...currentSelected // 当前页面新勾选的数据 |
|
||||||
]; |
|
||||||
|
|
||||||
// 去重并更新 allSelectedList |
|
||||||
this.allSelectedList = this.uniqueById(combinedSelection) |
|
||||||
|
|
||||||
console.log('更新后的allSelectedList:', this.allSelectedList) |
|
||||||
}, |
|
||||||
|
|
||||||
//去重 |
|
||||||
uniqueById(arr) { |
|
||||||
const uniqueObj = {}; |
|
||||||
arr.forEach(item => { |
|
||||||
if (item.id && !uniqueObj[item.id]) { |
|
||||||
uniqueObj[item.id] = item; |
|
||||||
} |
|
||||||
}); |
|
||||||
return Object.values(uniqueObj); |
|
||||||
}, |
|
||||||
|
|
||||||
//点击确定 |
|
||||||
handleConfirm() { |
|
||||||
const uniqueList = this.uniqueById(this.allSelectedList) |
|
||||||
this.$emit("confirm", uniqueList) |
|
||||||
}, |
|
||||||
|
|
||||||
handleCloseDetail() { |
|
||||||
this.$emit('handleCloseDetail') |
|
||||||
}, |
|
||||||
|
|
||||||
selectionClear() { |
|
||||||
this.allSelectedList = [] |
|
||||||
if (this.$refs.crud) { |
|
||||||
this.$refs.crud.toggleSelection() |
|
||||||
} |
|
||||||
}, |
|
||||||
|
|
||||||
currentChange(currentPage) { |
|
||||||
this.page.currentPage = currentPage; |
|
||||||
this.onLoad(this.page, this.query) |
|
||||||
}, |
|
||||||
|
|
||||||
sizeChange(pageSize) { |
// 先清除所有选择 |
||||||
this.page.pageSize = pageSize; |
this.$refs.crud.toggleSelection(); |
||||||
this.onLoad(this.page, this.query) |
|
||||||
}, |
// 检查当前页面的数据中有哪些在 allSelectedList 中 |
||||||
|
currentPageData.forEach((item) => { |
||||||
refreshChange() { |
const isSelected = this.allSelectedList.some( |
||||||
this.onLoad(this.page, this.query) |
(selectedItem) => selectedItem.id === item.id |
||||||
}, |
); |
||||||
|
|
||||||
handleTabClick() { |
if (isSelected) { |
||||||
this.page.currentPage = 1 |
this.$refs.crud.toggleRowSelection(item, true); |
||||||
this.onLoad(this.page) |
|
||||||
}, |
|
||||||
|
|
||||||
onLoad(page, params = {}) { |
|
||||||
this.loading = true |
|
||||||
const requestParams = Object.assign({}, params, this.query, { |
|
||||||
num: 0, |
|
||||||
departmentId: this.departmentId |
|
||||||
}); |
|
||||||
const apiPromise = this.transactionType === "YH" |
|
||||||
? getList(page.currentPage, page.pageSize, requestParams) |
|
||||||
: fetchDurableApi(page.currentPage, page.pageSize, requestParams) |
|
||||||
apiPromise.then((res) => { |
|
||||||
this.data = res.data.result.list |
|
||||||
this.page.total = res.data.result.total |
|
||||||
|
|
||||||
// 数据加载完成后,更新当前页面的勾选状态 |
|
||||||
this.$nextTick(() => { |
|
||||||
this.updateCurrentPageSelection() |
|
||||||
}); |
|
||||||
}).catch(error => { |
|
||||||
this.$message.error('加载数据失败: ' + error.message) |
|
||||||
}).finally(() => { |
|
||||||
this.loading = false; |
|
||||||
}) |
|
||||||
}, |
|
||||||
|
|
||||||
handleCancel() { |
|
||||||
this.categoryVisible = false |
|
||||||
} |
} |
||||||
|
}); |
||||||
|
|
||||||
|
// 延迟 确保选择状态已完全更新 |
||||||
|
this.$nextTick(() => { |
||||||
|
setTimeout(() => { |
||||||
|
this.isUpdatingSelection = false; |
||||||
|
}, 100); |
||||||
|
}); |
||||||
}, |
}, |
||||||
} |
|
||||||
|
//勾选选中 |
||||||
|
selectionChange(selection,row) { |
||||||
|
|
||||||
|
let isSelectedInfo = selection.filter( |
||||||
|
(item) => item.id==row.id |
||||||
|
); |
||||||
|
if (this.isUpdatingSelection) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// 获取当前页面的数据ID |
||||||
|
const currentPageIds = this.data.map((item) => item.id); |
||||||
|
|
||||||
|
const otherPageSelected = this.allSelectedList.filter( |
||||||
|
(item) => !currentPageIds.includes(item.id) |
||||||
|
); |
||||||
|
|
||||||
|
const currentSelected = selection.map((item) => ({ |
||||||
|
...item, |
||||||
|
twoInventoryId: item.id, |
||||||
|
})); |
||||||
|
|
||||||
|
// 组合所有勾选数据 |
||||||
|
const combinedSelection = [ |
||||||
|
...otherPageSelected, // 其他页面的数据 |
||||||
|
...currentSelected, // 当前页面新勾选的数据 |
||||||
|
]; |
||||||
|
|
||||||
|
// 去重并更新 allSelectedList |
||||||
|
this.allSelectedList = this.uniqueById(combinedSelection); |
||||||
|
|
||||||
|
if(isSelectedInfo.length<=0){ |
||||||
|
this.allSelectedList=this.allSelectedList.filter( |
||||||
|
(item) => item.id!==row.id |
||||||
|
); |
||||||
|
} |
||||||
|
console.log('isSelectedInfo', this.allSelectedList); |
||||||
|
this.allSelectedList.forEach(item=>{ |
||||||
|
item.num = 0 |
||||||
|
}) |
||||||
|
// console.log("更新后的allSelectedList:", this.allSelectedList); |
||||||
|
}, |
||||||
|
|
||||||
|
//去重 |
||||||
|
uniqueById(arr) { |
||||||
|
const uniqueObj = {}; |
||||||
|
arr.forEach((item) => { |
||||||
|
if (item.id && !uniqueObj[item.id]) { |
||||||
|
uniqueObj[item.id] = item; |
||||||
|
} |
||||||
|
}); |
||||||
|
return Object.values(uniqueObj); |
||||||
|
}, |
||||||
|
|
||||||
|
//点击确定 |
||||||
|
handleConfirm() { |
||||||
|
const uniqueList = this.uniqueById(this.allSelectedList); |
||||||
|
this.$emit("confirm", uniqueList); |
||||||
|
}, |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
selectionClear() { |
||||||
|
this.allSelectedList = []; |
||||||
|
if (this.$refs.crud) { |
||||||
|
this.$refs.crud.toggleSelection(); |
||||||
|
} |
||||||
|
}, |
||||||
|
|
||||||
|
currentChange(currentPage) { |
||||||
|
this.page.currentPage = currentPage; |
||||||
|
this.onLoad(this.page, this.query); |
||||||
|
}, |
||||||
|
|
||||||
|
sizeChange(pageSize) { |
||||||
|
this.page.pageSize = pageSize; |
||||||
|
this.onLoad(this.page, this.query); |
||||||
|
}, |
||||||
|
|
||||||
|
refreshChange() { |
||||||
|
this.onLoad(this.page, this.query); |
||||||
|
}, |
||||||
|
|
||||||
|
handleTabClick() { |
||||||
|
this.page.currentPage = 1; |
||||||
|
this.onLoad(this.page); |
||||||
|
}, |
||||||
|
|
||||||
|
onLoad(page, params = {}) { |
||||||
|
this.loading = true; |
||||||
|
const requestParams = Object.assign({}, params, this.query, { |
||||||
|
num: 0, |
||||||
|
departmentId: this.departmentId, |
||||||
|
}); |
||||||
|
const apiPromise = |
||||||
|
this.transactionType === "YH" |
||||||
|
? getList(page.currentPage, page.pageSize, requestParams) |
||||||
|
: fetchDurableApi(page.currentPage, page.pageSize, requestParams); |
||||||
|
apiPromise |
||||||
|
.then((res) => { |
||||||
|
this.data = res.data.result.list; |
||||||
|
this.page.total = res.data.result.total; |
||||||
|
|
||||||
|
// 数据加载完成后,更新当前页面的勾选状态 |
||||||
|
this.$nextTick(() => { |
||||||
|
this.updateCurrentPageSelection(); |
||||||
|
}); |
||||||
|
}) |
||||||
|
.catch((error) => { |
||||||
|
this.$message.error("加载数据失败: " + error.message); |
||||||
|
}) |
||||||
|
.finally(() => { |
||||||
|
this.loading = false; |
||||||
|
}); |
||||||
|
}, |
||||||
|
|
||||||
|
handleCancel() { |
||||||
|
this.categoryVisible = false; |
||||||
|
this.$emit("categoryClose"); |
||||||
|
}, |
||||||
|
}, |
||||||
|
}; |
||||||
</script> |
</script> |
||||||
<style lang="scss" scoped> |
<style lang="scss" scoped> |
||||||
::v-deep.el-dialog__footer { |
::v-deep.el-dialog__footer { |
||||||
position: fixed !important; |
position: fixed !important; |
||||||
bottom: 0 !important; |
bottom: 0 !important; |
||||||
right: 0 !important; |
right: 0 !important; |
||||||
} |
} |
||||||
|
|
||||||
::v-deep.dialog-content { |
::v-deep.dialog-content { |
||||||
max-height: calc(100vh - 200px); |
max-height: calc(100vh - 200px); |
||||||
overflow-y: auto; |
overflow-y: auto; |
||||||
padding-right: 10px; |
padding-right: 10px; |
||||||
overflow-x: hidden; |
overflow-x: hidden; |
||||||
} |
} |
||||||
</style> |
</style> |
||||||
|
|||||||
Loading…
Reference in new issue