完成盘点计划

master
lynn 7 months ago
parent f47bf737ea
commit 600388ff5b

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

Loading…
Cancel
Save