From 63cf4da6102fa8d2106b0fef50da341cbee766dd Mon Sep 17 00:00:00 2001 From: taozi <1362265981@qq.com> Date: Wed, 7 Jan 2026 16:28:05 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BA=8C=E7=BA=A7=E5=BA=93=E5=87=BA?= =?UTF-8?q?=E5=BA=93=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/secondOrder/list.js | 1 + .../components/consumableDialog.vue | 4 +- src/views/materials/expend.vue | 7 + .../secondOrder/components/categoryDialog.vue | 255 ++++++++++++++++++ .../secondOrder/components/outDialog.vue | 254 ++++++++--------- 5 files changed, 378 insertions(+), 143 deletions(-) create mode 100644 src/views/secondOrder/components/categoryDialog.vue diff --git a/src/api/secondOrder/list.js b/src/api/secondOrder/list.js index bf17413..3c01272 100644 --- a/src/api/secondOrder/list.js +++ b/src/api/secondOrder/list.js @@ -1,6 +1,7 @@ import request from '@/router/axios'; export const getList = (current, size, params) => { + console.log(params, 'apiparams') return request({ url: '/smartpark/consumerForm/list', method: 'get', diff --git a/src/views/firstOrder/components/consumableDialog.vue b/src/views/firstOrder/components/consumableDialog.vue index 5ac547a..d354c13 100644 --- a/src/views/firstOrder/components/consumableDialog.vue +++ b/src/views/firstOrder/components/consumableDialog.vue @@ -359,8 +359,8 @@ export default { }, handleCancel() { - // this.$emit('handleCloseDetail'); - this.consumableVisible + this.$emit('handleCloseDetail'); + } }, } diff --git a/src/views/materials/expend.vue b/src/views/materials/expend.vue index ff78957..3e8e298 100644 --- a/src/views/materials/expend.vue +++ b/src/views/materials/expend.vue @@ -110,6 +110,12 @@ export default { searchMenuPosition: "right", menuWidth: 140, column: [ + { + label: "部门", + prop: "department", + headerAlign: "center", + align: "center", + }, { label: "编号", prop: "materialCode", @@ -165,6 +171,7 @@ export default { headerAlign: "center", align: "center", }, + // { // label: "金额", // prop: "amount", diff --git a/src/views/secondOrder/components/categoryDialog.vue b/src/views/secondOrder/components/categoryDialog.vue new file mode 100644 index 0000000..c3d5c03 --- /dev/null +++ b/src/views/secondOrder/components/categoryDialog.vue @@ -0,0 +1,255 @@ + + + \ No newline at end of file diff --git a/src/views/secondOrder/components/outDialog.vue b/src/views/secondOrder/components/outDialog.vue index d2a73ab..5ed1ba2 100644 --- a/src/views/secondOrder/components/outDialog.vue +++ b/src/views/secondOrder/components/outDialog.vue @@ -1,56 +1,30 @@ + \ No newline at end of file diff --git a/src/views/secondOrder/components/categoryDialog.vue b/src/views/secondOrder/components/categoryDialog.vue index c3d5c03..7857dae 100644 --- a/src/views/secondOrder/components/categoryDialog.vue +++ b/src/views/secondOrder/components/categoryDialog.vue @@ -33,12 +33,17 @@ export default { departmentId: { type: [String, Number], default: '' + }, + selectionData: { + type: Array, + default: () => [] } }, data() { return { form: {}, selectionList: [], + newselection: [], query: {}, loading: true, page: { @@ -139,17 +144,18 @@ export default { }, data: [], dialogLogVisible: false, - transactionType: "YH", // 初始值改为YH(易耗品),匹配标签页name + transactionType: "YH", tableData: [], ckTable: [], rkTable: [], currentRow: null, - allSelectedList: [], //存储所有勾选的数据 - isUpdatingSelection: false, // 修正:将此属性移到 data 中 + allSelectedList: [], + isUpdatingSelection: false, } }, mounted() { - // 页面初始化时调用易耗品接口 + // 初始化时使用传入的selectionData + this.allSelectedList = [...this.selectionData]; this.onLoad(this.page); }, methods: { @@ -165,74 +171,141 @@ export default { done(); }, + // 更新当前页面的勾选状态 + updateCurrentPageSelection() { + 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.$refs.crud.toggleRowSelection(item, true); + } + }); + + // 延迟 确保选择状态已完全更新 + this.$nextTick(() => { + setTimeout(() => { + this.isUpdatingSelection = false + }, 100); + }); + }, + //勾选选中 selectionChange(selection) { - console.log("勾选选中", 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); - this.allSelectedList = this.allSelectedList.filter(item => + + const otherPageSelected = this.allSelectedList.filter(item => !currentPageIds.includes(item.id) ); - const selectionWithTwoInventoryId = selection.map(item => ({ + + const currentSelected = selection.map(item => ({ ...item, - twoInventoryId: item.twoInventoryId || item.id + twoInventoryId: item.id })); - this.allSelectedList.push(...selectionWithTwoInventoryId); + + // 组合所有勾选数据 + 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() { - this.$emit("confirm", this.allSelectedList); + const uniqueList = this.uniqueById(this.allSelectedList) + this.$emit("confirm", uniqueList) }, + handleCloseDetail() { this.$emit('handleCloseDetail') }, + selectionClear() { - this.allSelectedList = []; // 清空所有选中的数据 + this.allSelectedList = [] if (this.$refs.crud) { - this.$refs.crud.toggleSelection(); // 清空表格选择 + this.$refs.crud.toggleSelection() } }, + currentChange(currentPage) { this.page.currentPage = currentPage; - this.onLoad(this.page, this.query); + this.onLoad(this.page, this.query) }, sizeChange(pageSize) { this.page.pageSize = pageSize; - this.onLoad(this.page, this.query); + this.onLoad(this.page, this.query) }, - + refreshChange() { - this.onLoad(this.page, this.query); + this.onLoad(this.page, this.query) }, - - // 切换标签页时触发 + handleTabClick() { - // 切换标签后重置页码为第1页,重新加载对应类型数据 - this.page.currentPage = 1; - this.onLoad(this.page); - // 清空当前页的勾选状态(可选,根据业务需求) - this.selectionClear(); + this.page.currentPage = 1 + this.onLoad(this.page) }, - - + onLoad(page, params = {}) { - this.loading = true; + 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); + : fetchDurableApi(page.currentPage, page.pageSize, requestParams) apiPromise.then((res) => { - this.data = res.data.result.list; - this.page.total = res.data.result.total; + this.data = res.data.result.list + this.page.total = res.data.result.total + + // 数据加载完成后,更新当前页面的勾选状态 + this.$nextTick(() => { + this.updateCurrentPageSelection() + }); }).catch(error => { - this.$message.error('加载数据失败: ' + error.message); + this.$message.error('加载数据失败: ' + error.message) }).finally(() => { this.loading = false; - }); + }) }, + handleCancel() { this.categoryVisible = false } diff --git a/src/views/secondOrder/components/outDialog.vue b/src/views/secondOrder/components/outDialog.vue index 5ed1ba2..bdd1459 100644 --- a/src/views/secondOrder/components/outDialog.vue +++ b/src/views/secondOrder/components/outDialog.vue @@ -79,7 +79,7 @@ {{ scope.row.materialName }} - --> + --> @@ -135,7 +135,7 @@ 确 定 - @@ -201,6 +201,8 @@ export default { outDialogVisible: false, categoryVisible: false, categoryDialogTitle: '出库', + allSelectedList:[], + selectionData:[], sizeForm: { ldTwoOutStorage: { outDate: "", @@ -280,17 +282,32 @@ export default { this.categoryVisible = true }, confirm(allSelectedList) { + console.log('allSelectedList-------',allSelectedList) + // this.selectionData = allSelectedList + allSelectedList.map(item =>{ + this.selectionData.push(item) + }) this.categoryVisible = false; - const formattedList = allSelectedList.map(item => ({ - ...item, - // oldNum: item.num , - // newNum: item.num , - num: item.type === "NY" ? 1 : item.num // 耐用品默认1,易耗品可选 - })); - this.sizeForm.ldTwoOutStorageDetailList = formattedList; - this.sizeForm.inAccountsTableData = JSON.parse(JSON.stringify(formattedList)); + // 去重:过滤已存在的物资 + const newItems = allSelectedList.filter(newItem => + !this.sizeForm.ldTwoOutStorageDetailList.some( + oldItem => oldItem.id === newItem.id + ) + ); + // 追加数据 + this.sizeForm.ldTwoOutStorageDetailList = [ + ...this.sizeForm.ldTwoOutStorageDetailList, + ...newItems + ]; + console.log('ldTwoOutStorageDetailList--------',this.sizeForm.ldTwoOutStorageDetailList) + // 同步库存汇总表 + this.summaryTableData(); }, - // 删除表格行数据 + categoryHandle() { + this.categoryVisible = true; + + }, + // 删除表格行数据 handleDelete(index, row) { this.sizeForm.ldTwoOutStorageDetailList.splice(index, 1) }, @@ -309,7 +326,7 @@ export default { // this.$set(this.sizeForm.inAccountsTableData, index, currentRow) // this.sizeForm.inAccountsTableData[index] = currentRow // }, - handleQuantityChange(newValue, index) { + handleQuantityChange(newValue, index) { const currentRow = this.sizeForm.ldTwoOutStorageDetailList[index]; if (!currentRow) return; if (currentRow.type === "NY") { @@ -324,7 +341,7 @@ export default { currentRow.newNum = stockNum - newValue // 出库后库存 this.$set(this.sizeForm.ldTwoOutStorageDetailList, index, currentRow) this.$set(this.sizeForm.inAccountsTableData, index, { ...currentRow }) - }, + }, // 更新全局总计 updateGlobalTotal() {