物料BOM新增批量删除

This commit is contained in:
17630416519 2026-01-16 15:04:55 +08:00
parent bd00fee0de
commit 5a9b9a1e53
2 changed files with 136 additions and 55 deletions

View File

@ -69,13 +69,11 @@ export function getBaseMaterialBom(id) {
})
}
/**
* 删除
* @param {主键} pid
*/
export function delBaseMaterialBom(pid) {
//删除
export function delBaseMaterialBom(ids) {
const idsStr = Array.isArray(ids) ? ids.join(',') : String(ids)
return request({
url: 'MasterDataManagement/Material/MaterialBom/' + pid,
method: 'delete'
url: `MasterDataManagement/Material/MaterialBom/${idsStr}`,
method: 'delete',
})
}
}

View File

@ -21,33 +21,34 @@
</el-button>
<el-button class="tool-box" color="#00aa00" icon="Upload" @click="handleDownload"> 导出 </el-button>
<el-button type="danger" icon="delete" @click="handleBatchDelete"
:disabled="ids.length === 0">批量删除</el-button>
:disabled="mainIds.length === 0 && !hasSelectedChild">批量删除</el-button>
</el-col>
</el-col>
</el-row>
<vxe-table border="inner" ref="tableRef" :column-config="{ resizable: true }" :expand-config="{
<vxe-table border="inner" ref="tableRef" :column-config="{ resizable: true }" :checkbox-config="{trigger: 'row'}" @checkbox-change="handleSelectionChange" @checkbox-all="handleSelectAll" :expand-config="{
lazy: true,
loadMethod: loadContentMethod,
iconOpen: 'vxe-icon-square-minus-fill',
iconClose: 'vxe-icon-square-plus-fill'
}" :data="dataList" @checkbox-change="handleSelectionChange" @checkbox-all="handleSelectAll">
<!-- <vxe-column type="checkbox" width="60" fixed="left"></vxe-column> -->
}" :data="dataList">
<vxe-column type="seq" width="60"></vxe-column>
<vxe-column type="expand" width="80">
<template #content="{ row }">
<vxe-table border size="mini" stripe :data="row.children" @checkbox-change="handleSelectionChange2"
@checkbox-all="handleSelectAll2">
<vxe-table border size="mini" stripe :data="row.children"
:ref="el => setChildTableRef(el, row.id)"
@checkbox-change="(params) => handleSelectionChange2(params, row)"
@checkbox-all="(params) => handleSelectAll2(params, row)">
<vxe-column type="checkbox" width="60" fixed="left"></vxe-column>
<vxe-column type="seq" width="60"></vxe-column>
<vxe-column field="subInvCode" title="子件编码"></vxe-column>
<vxe-column field="subInvName" title="子件名称"></vxe-column>
<vxe-column field="iusequantity" title="使用数量"></vxe-column>
<vxe-column field="bomVersion" title="bom版本"></vxe-column>
<vxe-column field="iusequantity" title="操作">
<template #default="{ row }">
<el-button type="success" size="small" icon="edit" title="编辑" @click="handleSubEdit(row)"></el-button>
<el-button type="danger" @click="handleSubDelete(row)" size="small" icon="delete" title="删除" />
<vxe-column field="operation" title="操作">
<template #default="{ row: subRow }">
<el-button type="success" size="small" icon="edit" title="编辑" @click="handleSubEdit(subRow)"></el-button>
<el-button type="danger" @click="handleSubDelete(subRow)" size="small" icon="delete" title="删除" />
</template>
</vxe-column>
</vxe-table>
@ -56,7 +57,7 @@
<vxe-column field="invCode" title="母件编码"></vxe-column>
<vxe-column field="invName" title="母件名称"></vxe-column>
<vxe-column field="bomVersion" title="bom版本"></vxe-column>
<!-- <vxe-column field="iusequantity" title="操作">
<!-- <vxe-column field="operation" title="操作">
<template #default="{ row }">
<el-button type="success" size="small" icon="edit" title="编辑" @click="handleEdit(row)"></el-button>
<el-button type="danger" size="small" icon="delete" title="删除" @click="handleDelete(row)"></el-button>
@ -137,13 +138,22 @@
</template>
<script setup name="BaseMaterialBOM">
import { listBaseMaterialBom, GetMonterInvList, GetSonInvList, updateBaseMaterialBom,delBaseMaterialBom } from '@/api/baseManagement/basematerialBOM.js'
import { listBaseMaterialBom, GetMonterInvList, GetSonInvList, updateBaseMaterialBom, delBaseMaterialBom } from '@/api/baseManagement/basematerialBOM.js'
import { addBaseMaterialBom, updateBaseMaterialBom as updateMainBom } from '@/api/baseManagement/basematerialBOM.js'
import useUserStore from '@/store/modules/user'
import { ref, reactive, computed } from 'vue' // VueAPI
const userStore = useUserStore()
const userName = userStore.userName
const { proxy } = getCurrentInstance()
const ids = ref([])
// ID
const mainIds = ref([])
// IDkeyIDvalueID
const childIdsMap = ref({})
//
const childTableRefs = ref({})
const loading = ref(false)
const showSearch = ref(true)
@ -247,27 +257,49 @@ function getList() {
})
}
//
function getSelectedRows() {
//
function setChildTableRef(el, parentId) {
if (el) {
childTableRefs.value[parentId] = el
}
}
//
function handleSelectionChange() {
if (tableRef.value) {
const selectedRows = tableRef.value.getCheckboxRecords()
console.log('选中的行数据:', selectedRows)
return selectedRows
mainIds.value = selectedRows.map(row => row.id)
console.log('主件选中项ID:', mainIds.value)
}
return []
}
//
function handleSelectionChange() {
const selectedRows = tableRef.value.getCheckboxRecords()
ids.value = selectedRows.map(row => row.id) // id
console.log('当前选中项ID:', ids.value)
// /
function handleSelectAll() {
if (tableRef.value) {
const selectedRows = tableRef.value.getCheckboxRecords()
mainIds.value = selectedRows.map(row => row.id)
console.log('主件全选后ID:', mainIds.value)
}
}
// /
function handleSelectAll({ records }) {
ids.value = records.map(row => row.id) // id
console.log('全选/取消全选后ID:', ids.value)
//
function handleSelectionChange2(params, parentRow) {
const selectedChildRows = params.$table.getCheckboxRecords()
const childIds = selectedChildRows.map(row => row.id)
//
childIdsMap.value[parentRow.id] = childIds
console.log('所有子件选中状态:', childIdsMap.value)
}
// /
function handleSelectAll2(params, parentRow) {
const selectedChildRows = params.$table.getCheckboxRecords()
const childIds = selectedChildRows.map(row => row.id)
//
childIdsMap.value[parentRow.id] = childIds
console.log('所有子件选中状态:', childIdsMap.value)
}
//
@ -289,6 +321,7 @@ function handleSubEdit(row) {
subDialog.visible = true
subDialog.isEdit = true
}
function formatDateTime(date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
@ -299,6 +332,7 @@ function formatDateTime(date) {
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
//
function submitForm() {
editFormRef.value.validate(valid => {
@ -338,19 +372,15 @@ function submitSubForm() {
subEditFormRef.value.validate(valid => {
if (valid) {
if (subDialog.isEdit) {
//
updateBaseMaterialBom(subFormData.value).then(res => {
if (res.code === 200) {
proxy.$modal.msgSuccess('修改成功')
subDialog.visible = false
resetSubForm()
//
getList()
}
})
} else {
//
// API
addBaseMaterialBom(subFormData.value).then(res => {
if (res.code === 200) {
proxy.$modal.msgSuccess('新增成功')
@ -376,36 +406,93 @@ function cancelSub() {
resetSubForm()
}
//
//
function handleSubDelete(row) {
proxy.$modal.confirm('确认删除该子件数据?')
.then(() => {
//
console.log('删除子件数据:', row.id)
// API
return delBaseMaterialBom(row.id)
})
.then(() => {
proxy.$modal.msgSuccess('删除成功')
getList()
})
.catch((err) => {
console.error('删除子件失败:', err)
proxy.$modal.msgError('删除失败,请稍后重试')
})
}
//
//
function handleDelete(row) {
proxy.$modal.confirm('确认删除该条数据?')
.then(() => {
//
console.log('删除行数据:', row.id)
// API
// return deleteById(row.id)
return delBaseMaterialBom(row.id)
})
.then(() => {
proxy.$modal.msgSuccess('删除成功')
getList()
})
.catch((err) => {
console.error('删除主件失败:', err)
proxy.$modal.msgError('删除失败,请稍后重试')
})
}
//
const hasSelectedChild = computed(() => {
for (const parentId in childIdsMap.value) {
if (childIdsMap.value[parentId] && Array.isArray(childIdsMap.value[parentId]) && childIdsMap.value[parentId].length > 0) {
return true
}
}
return false
})
//
function handleBatchDelete() {
const allSelectedIds = []
if (Array.isArray(mainIds.value) && mainIds.value.length > 0) {
allSelectedIds.push(...mainIds.value)
}
for (const parentId in childIdsMap.value) {
if (childIdsMap.value[parentId] && Array.isArray(childIdsMap.value[parentId]) && childIdsMap.value[parentId].length > 0) {
allSelectedIds.push(...childIdsMap.value[parentId])
}
}
if (allSelectedIds.length === 0) {
proxy.$modal.msgWarning('请选择要删除的数据');
return;
}
proxy.$modal.confirm(`确认删除选中的${allSelectedIds.length}条数据?`)
.then(async () => {
return delBaseMaterialBom(allSelectedIds);
})
.then((res) => {
if (res && res.code === 200) {
proxy.$modal.msgSuccess('删除成功');
mainIds.value = [];
childIdsMap.value = {};
for (const parentId in childTableRefs.value) {
if (childTableRefs.value[parentId] && typeof childTableRefs.value[parentId].clearCheckbox === 'function') {
childTableRefs.value[parentId].clearCheckbox();
}
}
if (tableRef.value && typeof tableRef.value.clearCheckbox === 'function') {
tableRef.value.clearCheckbox();
}
//
getList();
} else {
proxy.$modal.msgError('删除失败,接口返回异常');
}
})
.catch((err) => {
console.error('批量删除失败:', err);
proxy.$modal.msgError('删除失败,请稍后重试');
});
}
//
@ -428,7 +515,7 @@ function getToken() {
const upload = reactive({
open: false,
title: '',
// isUploading: false,
isUploading: false,
updateSupport: 0,
uploadType: 1,
headers: { Authorization: 'Bearer ' + getToken() },
@ -457,14 +544,13 @@ function submitFileForm() {
proxy.$refs['uploadRef'].submit()
}
//
//
function importTemplate() {
proxy.download('/MasterDataManagement/Material/MaterialBom/importTemplate', '物料类别导入模板')
}
/** 文件上传异常处理 */
const handleFileError = (error, file, fileList) => {
// 使
if (error) {
proxy.$message.error('模板导入异常!')
return
@ -481,7 +567,6 @@ const dialogVisibleActualAssembly = ref(false)
/** 文件上传成功处理 */
const handleFileSuccess = (response, file, fileList) => {
const { code, msg, data } = response
if (code === 500) {
proxy.$message.error('模板存在异常!')
@ -530,7 +615,6 @@ function sortChange(column) {
handleQuery()
}
/// ======================= =============================
import { SynchERPBOM } from '@/api/erp/baseInteractERP.js'
const throttle = ref(false)
const syncLoading = ref(false)
@ -551,7 +635,6 @@ function handleSync() {
}
})
}
/// =================================================================
handleQuery()
</script>