完成盘点计划

master
lynn 7 months ago
parent f47bf737ea
commit 600388ff5b

@ -171,29 +171,54 @@
<Button type="primary" style="margin-left: 10px" @click="searchMaterials"></Button>
<Button style="margin-left: 10px" @click="resetMaterialSearch"></Button>
</div>
<Table
<el-table
ref="materialTable"
:columns="materialColumns"
:data="materialList"
:loading="materialModal.loading"
@on-select="handleSelect"
@on-select-all="handleSelectAll"
@on-selection-change="handleSelectionChange"
v-loading="materialModal.loading"
@select="handleSelect"
@select-all="handleSelectAll"
row-key="id"
>
<template slot-scope="{ row, index }" slot="action">
<el-table-column
type="selection"
width="55">
</el-table-column>
<el-table-column
prop="zichanmingcheng"
label="物资名称">
</el-table-column>
<el-table-column
prop="guigexinghao"
label="规格型号">
</el-table-column>
<el-table-column
prop="jiliangdanwei"
label="单位">
</el-table-column>
<el-table-column
prop="inventorys_total"
label="当前库存">
<template slot-scope="scope">
{{ scope.row.inventorys_total === null ? '0' : scope.row.inventorys_total }}
</template>
</el-table-column>
<el-table-column
label="操作"
width="100">
<template slot-scope="scope">
<div style="display: flex; gap: 8px; justify-content: center;">
<Button
:type="isSelected(row) ? 'warning' : 'success'"
<el-button
:type="isSelected(scope.row) ? 'warning' : 'success'"
size="small"
style="border-radius: 6px;"
@click="toggleMaterialSelection(row, index)"
@click="toggleMaterialSelection(scope.row, scope.$index)"
>
{{ isSelected(row) ? '移出计划' : '加入计划' }}
</Button>
{{ isSelected(scope.row) ? '移出计划' : '加入计划' }}
</el-button>
</div>
</template>
</Table>
</el-table-column>
</el-table>
<div class="pagination-container">
<el-pagination
@size-change="handleMaterialPageSizeChange"
@ -426,7 +451,9 @@ export default {
currentPlanId: '',
pageIndex: 1,
pageSize: 10,
total: 0
total: 0,
selectedMaterialIds: new Set(),
isInitialLoad: true
},
materialList: [],
materialColumns: [
@ -481,8 +508,7 @@ export default {
key: 'status',
width: 100
}
],
linkedMaterialIds: []
]
}
},
mounted() {
@ -801,79 +827,115 @@ export default {
}
},
async showInventorySelectModal(planId) {
showInventorySelectModal(planId) {
this.materialModal.currentPlanId = planId
this.materialModal.visible = true
this.materialModal.pageIndex = 1
this.linkedMaterialIds = [] // ID
this.selectedRows = [] //
// ID
try {
const res = await getStocktakingPlanLinkList({ material_infos_plan_id: planId })
if (res && res.list && res.list.data) {
this.linkedMaterialIds = res.list.data.map(item => item.material_info_id)
}
} catch (error) {
console.error('获取已关联物资失败:', error)
}
//
await this.$nextTick()
this.searchMaterials()
},
isSelected(row) {
return this.linkedMaterialIds.includes(row.id)
},
handleSelectionChange(selection) {
this.selectedRows = selection
isSelected(item) {
// console.log('isSelected called', item.id)
// console.log('materialModal.selectedMaterialIds', this.materialModal.selectedMaterialIds)
// console.log('this.materialModal.selectedMaterialIds.has(item.id)', this.materialModal.selectedMaterialIds.has(item.id))
return this.materialModal.selectedMaterialIds.has(item.id);
},
handleSelect(selection, row) {
console.log('handleSelect called', selection, row) //
this.selectedRows = selection
// planMaterials
const planId = this.materialModal.currentPlanId
if (!this.planMaterials[planId]) {
this.planMaterials[planId] = []
handleSelect(selection, item) {
console.log('handleSelect called', selection, item);
//
const planId = this.materialModal.currentPlanId;
if (planId) {
if (selection.includes(item)) {
this.materialModal.selectedMaterialIds.add(item.id);
} else {
this.materialModal.selectedMaterialIds.delete(item.id);
}
if (selection.includes(row)) {
if (!this.planMaterials[planId].includes(row.id)) {
this.planMaterials[planId].push(row.id)
//
this.$nextTick(() => {
if (this.$refs.materialTable) {
this.materialList.forEach(row => {
this.$refs.materialTable.toggleRowSelection(row, this.materialModal.selectedMaterialIds.has(row.id));
});
}
} else {
this.planMaterials[planId] = this.planMaterials[planId].filter(id => id !== row.id)
});
}
},
// console.log('handleSelectionChange called', selection);
// //
// if (this.materialModal.isInitialLoad) {
// this.materialModal.isInitialLoad = false;
// return;
// }
// //
// const planId = this.materialModal.currentPlanId;
// if (planId) {
// //
// this.$nextTick(() => {
// if (this.$refs.materialTable) {
// this.materialList.forEach(row => {
// this.$refs.materialTable.toggleRowSelection(row, this.materialModal.selectedMaterialIds.has(row.id));
// });
// }
// });
// }
// },
handleSelectAll(selection) {
console.log('handleSelectAll called', selection) //
this.selectedRows = selection
const planId = this.materialModal.currentPlanId
if (!this.planMaterials[planId]) {
this.planMaterials[planId] = []
console.log('handleSelectAll called', selection);
const planId = this.materialModal.currentPlanId;
if (planId) {
//
if (selection.length > 0) {
//
this.materialList.forEach(item => {
this.materialModal.selectedMaterialIds.add(item.id);
});
} else {
//
this.materialList.forEach(item => {
this.materialModal.selectedMaterialIds.delete(item.id);
});
}
// planMaterials
this.planMaterials[planId] = selection.map(item => item.id)
//
this.$nextTick(() => {
if (this.$refs.materialTable) {
//
this.materialList.forEach(row => {
this.$refs.materialTable.toggleRowSelection(row, this.materialModal.selectedMaterialIds.has(row.id));
});
}
});
}
},
toggleMaterialSelection(row, index) {
//
if (!this.$refs.materialTable) return
if (this.isSelected(row)) {
// ""
this.$refs.materialTable.toggleSelect(index)
this.selectedRows = this.selectedRows.filter(item => item.id !== row.id)
this.linkedMaterialIds = this.linkedMaterialIds.filter(id => id !== row.id)
toggleMaterialSelection(item, index) {
console.log('toggleMaterialSelection called', item, index);
//
if (!this.isSelected(item)) {
console.log('Adding to plan');
this.materialModal.selectedMaterialIds.add(item.id);
} else {
// ""
this.$refs.materialTable.toggleSelect(index)
this.selectedRows.push(row)
this.linkedMaterialIds.push(row.id)
console.log('Removing from plan');
this.materialModal.selectedMaterialIds.delete(item.id);
}
//
this.$nextTick(() => {
if (this.$refs.materialTable) {
this.materialList.forEach(row => {
this.$refs.materialTable.toggleRowSelection(row, this.materialModal.selectedMaterialIds.has(row.id));
});
}
});
},
async searchMaterials() {
this.materialModal.loading = true
this.materialModal.loading = true;
this.materialModal.isInitialLoad = true; //
try {
const data = {
page_size: this.materialModal.pageSize,
@ -887,7 +949,7 @@ export default {
'filter[1][key]': 'wuzileixing',
'filter[1][op]': 'eq',
'filter[1][value]': '一物一码'
}
};
const res = await request({
url: '/api/admin/material-infos/index',
method: 'post',
@ -895,25 +957,31 @@ export default {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
});
if (res && res.data) {
this.materialList = res.data
this.selectedRows = [] //
this.materialModal.total = res.total || 0
this.materialList = res.data;
this.materialModal.total = res.total || 0;
//
await this.$nextTick()
if (this.$refs.materialTable) {
this.materialList.forEach((item, index) => {
if (this.linkedMaterialIds.includes(item.id)) {
this.$refs.materialTable.toggleSelect(index, true)
this.selectedRows.push(item)
//
const planId = this.materialModal.currentPlanId;
if (planId) {
//
if (this.materialModal.selectedMaterialIds.size === 0) {
this.materialList.forEach(item => {
if (item.material_infos_plan &&
item.material_infos_plan.length > 0 &&
item.material_infos_plan[0].material_infos_plan_id === planId) {
console.log('item.id', item.id)
this.materialModal.selectedMaterialIds.add(item.id);
}
})
});
}
console.log('this.materialModal.selectedMaterialIds', this.materialModal.selectedMaterialIds)
}
}
} finally {
this.materialModal.loading = false
this.materialModal.loading = false;
}
},
async batchAddMaterials() {
@ -1037,18 +1105,21 @@ export default {
},
async handleMaterialSubmit() {
const planId = this.materialModal.currentPlanId;
//
const selectedMaterialIds = this.selectedRows.map(row => row.id);
if (!planId) {
this.$Message.error('未找到计划ID');
return;
}
// formdata
// ID
const selectedMaterialIds = Array.from(this.materialModal.selectedMaterialIds);
// formdata
const formData = new FormData();
formData.append('id', planId);
selectedMaterialIds.forEach((materialId, index) => {
formData.append(`material_infos_plan_links[${index}][material_info_id]`, materialId);
});
try {
await saveStocktakingPlan(formData);
this.$Message.success('物资关联成功');
@ -1073,6 +1144,25 @@ export default {
this.detailModal.pageIndex = 1;
this.viewInventoryDetail(this.detailModal.data.id);
}
},
watch: {
'materialModal.loading': {
handler(newVal, oldVal) {
// loadingtruefalse
if (oldVal === true && newVal === false) {
this.$nextTick(() => {
if (this.$refs.materialTable) {
this.materialList.forEach((item, index) => {
if (this.materialModal.selectedMaterialIds.has(item.id)) {
this.$refs.materialTable.toggleRowSelection(item, true);
console.log('item.id1111111111111111111111', item.id)
}
});
}
});
}
}
}
}
}
</script>

Loading…
Cancel
Save