结构bom和物料bom前端完善
master
xs 3 months ago
parent 582f96e7b8
commit 751a6c80da

@ -238,4 +238,9 @@ export interface BaseStructureBomTreeVO {
*/
children: [];
/**
*
*/
treeKey: string | number;
}

@ -64,6 +64,18 @@ export const delMaterialBom = (materialBomId: string | number | Array<string | n
});
};
/**
* BOM
* @param data
*/
export const deleteMaterialBoms = (data) => {
return request({
url: '/mes/materialBom/deleteMaterialBoms',
method: 'post',
data: data
});
};
/**
* BOM

@ -495,7 +495,6 @@ const handleRowClick = (row) =>{
};
defineExpose({tableRef})
onMounted(() => {
alert(materialTypeId.value)
if(materialTypeId.value){
queryParams.value.materialTypeId = materialTypeId.value;
}

@ -20,15 +20,22 @@
</el-card>
</el-col>
<el-col :lg="20" :xs="24" v-loading="loading">
<el-divider content-position="left">物料类型</el-divider>
<el-form ref="parentStructureBomFormRef" label-width="120px">
<el-divider content-position="left">物料类型</el-divider>
<el-form ref="parentStructureBomFormRef" label-width="120px" :model="parentForm">
<el-row>
<el-form-item label="父级物料类型">
{{ parentParentMaterialTypeName }}
</el-form-item>
<el-form-item label="物料类型">
{{ parentMaterialTypeName }}
<el-form-item label='父物料类型' prop='parentId' :model="parentForm">
<el-select v-model="parentForm.parentId" placeholder="请选择" style="width:260px"
:disabled="parentMaterialTypeDisabled" >
<el-option
v-for="item in materialTypeOptions"
:key="item.matrialTypeId"
:label="item.matrialTypeName"
:value="item.matrialTypeId"
:disabled="item.activeFlag == '0' || item.matrialTypeId === form.parentId"
></el-option>
</el-select>
</el-form-item>
</el-row>
@ -36,27 +43,27 @@
<el-divider content-position="left">子级物料类型</el-divider>
<transition :enter-active-class="proxy?.animate.searchAnimate.enter"
:leave-active-class="proxy?.animate.searchAnimate.leave">
<div v-show="showSearch" class="mb-[10px]">
<el-card shadow="hover">
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
<el-form-item label="物料类型编号" prop="materialTypeCode" label-width="120px">
<el-input v-model="queryParams.materialTypeCode" placeholder="请输入物料类型编号" clearable
@keyup.enter="handleQuery"/>
</el-form-item>
<el-form-item label="物料类型名称" prop="materialTypeName" label-width="120px">
<el-input v-model="queryParams.materialTypeName" placeholder="请输入物料类型名称" clearable
@keyup.enter="handleQuery"/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery"></el-button>
<el-button icon="Refresh" @click="resetQuery"></el-button>
</el-form-item>
</el-form>
</el-card>
</div>
</transition>
<!-- <transition :enter-active-class="proxy?.animate.searchAnimate.enter"-->
<!-- :leave-active-class="proxy?.animate.searchAnimate.leave">-->
<!-- <div v-show="showSearch" class="mb-[10px]">-->
<!-- <el-card shadow="hover">-->
<!-- <el-form ref="queryFormRef" :model="queryParams" :inline="true">-->
<!-- <el-form-item label="物料类型编号" prop="materialTypeCode" label-width="120px">-->
<!-- <el-input v-model="queryParams.materialTypeCode" placeholder="请输入物料类型编号" clearable-->
<!-- @keyup.enter="handleQuery"/>-->
<!-- </el-form-item>-->
<!-- <el-form-item label="物料类型名称" prop="materialTypeName" label-width="120px">-->
<!-- <el-input v-model="queryParams.materialTypeName" placeholder="请输入物料类型名称" clearable-->
<!-- @keyup.enter="handleQuery"/>-->
<!-- </el-form-item>-->
<!-- <el-form-item>-->
<!-- <el-button type="primary" icon="Search" @click="handleQuery"></el-button>-->
<!-- <el-button icon="Refresh" @click="resetQuery"></el-button>-->
<!-- </el-form-item>-->
<!-- </el-form>-->
<!-- </el-card>-->
<!-- </div>-->
<!-- </transition>-->
<el-card shadow="hover">
<template #header>
@ -66,24 +73,24 @@
@click="handleAdd()">新增
</el-button>
</el-col>
<el-col :span="1.5">
<el-button v-has-permi="['mes:baseStructureBom:edit']" type="success" plain :disabled="single"
icon="Edit" @click="handleUpdate()">
修改
</el-button>
</el-col>
<!-- <el-col :span="1.5">-->
<!-- <el-button v-has-permi="['mes:baseStructureBom:edit']" type="success" plain :disabled="single"-->
<!-- icon="Edit" @click="handleUpdate()">-->
<!-- 修改-->
<!-- </el-button>-->
<!-- </el-col>-->
<el-col :span="1.5">
<el-button v-has-permi="['mes:baseStructureBom:remove']" type="danger" plain :disabled="multiple"
icon="Delete" @click="handleDelete()">
删除
</el-button>
</el-col>
<right-toolbar v-model:showSearch="showSearch" :columns="columns" :search="true"
@query-table="getList"></right-toolbar>
<!-- <right-toolbar v-model:showSearch="showSearch" :columns="columns" :search="true"-->
<!-- @query-table="getList"></right-toolbar>-->
</el-row>
</template>
<el-table :data="structureBomList" @selection-change="handleSelectionChange">
<el-table :data="structureBomList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="50" align="center"/>
<el-table-column v-if="columns[0].visible" key="structureBomId" label="BOM结构编号" align="center"
prop="structureBomId"/>
@ -104,12 +111,12 @@
<el-table-column label="操作" fixed="right" width="180" class-name="small-padding fixed-width">
<template #default="scope">
<el-tooltip content="修改" placement="top">
<el-button v-hasPermi="['mes:baseStructureBom:edit']" link type="primary" icon="Edit"
@click="handleUpdate(scope.row)"></el-button>
</el-tooltip>
<!-- <el-tooltip content="修改" placement="top">-->
<!-- <el-button v-hasPermi="['mes:baseStructureBom:edit']" link type="primary" icon="Edit"-->
<!-- @click="handleUpdate(scope.row)"></el-button>-->
<!-- </el-tooltip>-->
<el-tooltip content="删除" placement="top">
<el-button v-hasPermi="['mes:baseStructureBom:remove']" link type="primary" icon="Delete"
<el-button v-hasPermi="['mes:baseStructureBom:remove']" link type="danger" icon="Delete"
@click="handleDelete(scope.row)"></el-button>
</el-tooltip>
</template>
@ -168,10 +175,16 @@ import {
addBaseStructureBom,
updateBaseStructureBom, getMaterialTypeList
} from "@/api/mes/baseStructureBom";
import {BaseStructureBomVO, BaseStructureBomTreeVO,BaseStructureBomQuery, BaseStructureBomForm} from '@/api/mes/baseStructureBom/types';
import {
BaseStructureBomVO,
BaseStructureBomTreeVO,
BaseStructureBomQuery,
BaseStructureBomForm
} from '@/api/mes/baseStructureBom/types';
import {BaseMaterialTypeVO} from '@/api/mes/baseMaterialType/types';
import {to} from 'await-to-js';
import {nextTick} from "vue";
import {MaterialBomVO} from "@/api/mes/materialBom/types";
const router = useRouter();
const {proxy} = getCurrentInstance() as ComponentInternalInstance;
@ -191,6 +204,9 @@ const structureBomOptions = ref<BaseStructureBomTreeVO[]>([]);
const materialTypeOptions = ref<BaseMaterialTypeVO[]>([]);
const parentMaterialTypeName = ref('');
const parentParentMaterialTypeName = ref('');
const focusKeyNode = ref<BaseStructureBomVO>;
const parentMaterialTypeDisabled = ref(true);
//
const columns = ref<FieldOption[]>([
{key: 0, label: `BOM结构编号`, visible: true, children: []},
@ -200,6 +216,8 @@ const columns = ref<FieldOption[]>([
{key: 4, label: `更新时间`, visible: true, children: []}
]);
const parentStructureBomFormRef = ref<ElTreeInstance>();
const structureBomTreeRef = ref<ElTreeInstance>();
const queryFormRef = ref<ElFormInstance>();
const structureBomFormRef = ref<ElFormInstance>();
@ -224,8 +242,24 @@ const initFormData: BaseStructureBomForm = {
remark: undefined,
}
const initParentFormData: BaseStructureBomForm = {
structureBomId: undefined,
parentId: undefined,
materialTypeId: undefined,
materialTypeName: undefined,
structureBomDesc: undefined,
structureBomVersion: undefined,
ancestors: undefined,
level: undefined,
topFlag: undefined,
activeFlag: '1',
remark: undefined,
}
const data = reactive<PageData<BaseStructureBomForm, BaseStructureBomQuery>>({
form: {...initFormData},
parentForm: {...initParentFormData},
queryParams: {
structureBomId: undefined,
parentId: undefined,
@ -247,7 +281,7 @@ const data = reactive<PageData<BaseStructureBomForm, BaseStructureBomQuery>>({
}
});
const {queryParams, form, rules} = toRefs(data);
const {queryParams, form, rules, parentForm} = toRefs(data);
/** 通过条件过滤节点 */
@ -269,32 +303,47 @@ watchEffect(
const getTreeSelect = async () => {
treeLoading.value = true;
loading.value = true;
const res = await structureBomTreeSelect();
// structureBomOptions.value = res.data;
structureBomOptions.value = [];
const virtualTopNodeId = -1;
const initialTree: BaseStructureBomTreeVO = {
id: 1,
id: virtualTopNodeId,
parentId: -1,
materialTypeId: 0,
label: "制造BOM结构",
children: res.data
};
structureBomOptions.value.push(initialTree);
console.log(structureBomOptions);
if (queryParams.value.parentId === null || queryParams.value.parentId === undefined) {
const topStructureBom = structureBomOptions.value.find(item => item.parentId === -1);
if (topStructureBom != null){
parentMaterialTypeName.value = topStructureBom.label;
// if (queryParams.value.parentId === null || queryParams.value.parentId === undefined) {
// const topStructureBom = structureBomOptions.value.find(item => item.parentId === -1);
// if (topStructureBom != null){
// parentMaterialTypeName.value = topStructureBom.label;
// }
// queryParams.value.parentId = 1;
// parentParentMaterialTypeName.value = "";
// }
// alert(JSON.stringify(focusKeyNode.value))
if (!focusKeyNode.value) {//focus
focusKeyNode.value = {id: virtualTopNodeId};
} else {
const allIds = structureBomOptions.value.flatMap(item => getAllIds(item));
if (!allIds || allIds.length <= 0) {
focusKeyNode.value = {id: virtualTopNodeId};
}
queryParams.value.parentId = 1;
parentParentMaterialTypeName.value = "顶级";
// console.log(JSON.stringify(materialBomOptions.value))
}
nextTick(function () {
structureBomTreeRef.value?.setCurrentKey(queryParams.value.parentId, true);
handleQuery();
structureBomTreeRef.value?.setCurrentKey(focusKeyNode.value.id, true);
})
treeLoading.value = false;
loading.value = false;
handleNodeClick(focusKeyNode.value);
// const dd = {"id":"1","parentId":-1,"label":"dd"};
// alert(materialTypeOptions.value[0])
// materialTypeOptions.value[0].children.push(dd);
@ -313,20 +362,47 @@ const getList = async () => {
/** 节点单击事件 */
const handleNodeClick = (data: BaseStructureBomTreeVO) => {
queryParams.value.parentId = data.id;
parentMaterialTypeName.value = data.label;
if (data.parentId === -1) {
parentParentMaterialTypeName.value = "顶级";
} else if (data.parentId === 1) {
parentParentMaterialTypeName.value = "制造BOM结构";
} else {
const findMaterialType = materialTypeOptions.value.find(item => item.matrialTypeId === data.parentId);
parentParentMaterialTypeName.value = findMaterialType.matrialTypeName;
structureBomList.value = [];
parentMaterialTypeDisabled.value = true;
resetParentForm();
resetQueryParams();
focusKeyNode.value = data;
// alert(JSON.stringify(focusKeyNode.value))
if (data.id && data.id != 0 && data.id != -1) {
parentForm.value.parentId = data.id;//materialTypeId
queryParams.value.parentId = data.id;
handleQuery();
}
parentMaterialTypeDisabled.value = focusKeyNode.value.id != -1;
handleQuery();
// if (data.parentId === -1) {
// parentParentMaterialTypeName.value = "";
// } else if (data.parentId === 1) {
// parentParentMaterialTypeName.value = "BOM";
// } else {
// const findMaterialType = materialTypeOptions.value.find(item => item.matrialTypeId === data.parentId);
// if(findMaterialType){
// parentParentMaterialTypeName.value = findMaterialType.matrialTypeName;
// }else{
// parentParentMaterialTypeName.value = undefined;
// }
// }
};
/**
* 重置父级表单
*/
const resetParentForm = () => {
parentStructureBomFormRef.value?.resetFields();
parentStructureBomFormRef.value?.clearValidate();
};
const resetQueryParams = () => {
queryParams.value.parentId = undefined;//materialtypeid
}
/** 搜索按钮操作 */
const handleQuery = () => {
// queryParams.value.pageNum = 1;
@ -348,12 +424,12 @@ const handleDelete = async (row?: BaseStructureBomVO) => {
const [err] = await to(proxy?.$modal.confirm('是否确认删除BOM结构编号为"' + structureBomIds + '"的数据项?') as any);
if (!err) {
await delBaseStructureBom(structureBomIds)
await getTreeSelect();
handleQuery();
proxy?.$modal.msgSuccess('删除成功');
await getTreeSelect();
}
};
/** 选择条数 */
const handleSelectionChange = (selection: BaseStructureBomVO[]) => {
ids.value = selection.map((item) => item.structureBomId);
@ -387,12 +463,19 @@ const cancel = () => {
/** 新增按钮操作 */
const handleAdd = async () => {
if (!parentForm.value.parentId) {
proxy?.$modal.msgWarning('请先选择父物料类型');
return;
}
reset();
await initMaterialTypeData();
const findMaterialType = materialTypeOptions.value.find(item => item.matrialTypeId === parentForm.value.parentId);
parentMaterialTypeName.value = findMaterialType.matrialTypeName;
form.value.parentId = parentForm.value.parentId;
// alert(JSON.stringify(data))
dialog.visible = true;
dialog.title = '新增';
await initMaterialTypeData();
form.value.parentId = queryParams.value.parentId;
};
/** 修改按钮操作 */
@ -422,7 +505,6 @@ const submitForm = () => {
form.value.structureBomId ? await updateBaseStructureBom(form.value) : await addBaseStructureBom(form.value);
proxy?.$modal.msgSuccess('操作成功');
await getTreeSelect();
handleQuery();
dialog.visible = false;
submitLoading.value = false;
} catch {
@ -459,6 +541,26 @@ onMounted(() => {
initMaterialTypeData();
});
const getAllIds = (obj) => {
let ids = [];
// id,focusid
// console.log(JSON.stringify(obj))
if (obj.id !== undefined && obj.id === focusKeyNode.value.id) {
ids.push(obj.id);
}
// children
if (obj.children && Array.isArray(obj.children)) {
obj.children.forEach(child => {
ids = ids.concat(getAllIds(child)); // id
});
}
return ids;
}
// async function handleDeptChange(value: number | string) {
// const response = await optionselect(value);
// materialTypeOptions.value = response.data;

@ -16,35 +16,44 @@
highlight-current
default-expand-all
@node-click="handleNodeClick"
/>
>
<template #default="{ node, data }">
<el-tooltip :content="`${data.label}`">
<div class="custom-tree-node">
<span>{{ node.label }}</span>
</div>
</el-tooltip>
</template>
</el-tree>
</el-card>
</el-col>
<el-col :lg="18" :xs="24" v-loading="loading">
<div>
<el-divider content-position="left">父级物料</el-divider>
<el-form ref="parentMaterialBomFormRef" label-width="120px" :model="parentForm">
<el-form ref="parentMaterialBomFormRef" label-width="120px" :model="parentForm" :rules="parentRules">
<el-row>
<el-form-item label='父物料ID' prop='parentId'>
<el-form-item label='父物料ID' prop='parentId' v-if="false">
<el-input v-model='parentForm.parentId' placeholder='' style="width:360px"/>
</el-form-item>
<el-form-item label='父物料类型ID' prop='parentMaterialTypeId'>
<el-form-item label='父物料类型ID' prop='parentMaterialTypeId' v-if="false">
<el-input v-model='parentForm.parentMaterialTypeId' placeholder='' style="width:360px"/>
</el-form-item>
<el-form-item label='父物料名称' prop='parentMaterialName'>
<el-input v-model='parentForm.parentMaterialName' placeholder='请点击检索物料'
@click='handleMaterialSelect(parentForm,SELECT_MATERIAL_MODEL.PARENT_SELECT)'
style="width:360px" @change="getList" suffix-icon="Search"/>
style="width:260px" @change="getList" suffix-icon="Search" readonly
:disabled="parentMaterialDisabled"/>
</el-form-item>
<el-form-item label="父物料类型名称" prop='parentMaterialTypeName'>
<el-input v-model='parentForm.parentMaterialTypeName' placeholder='' style="width:360px" dsiabeld/>
<el-input v-model='parentForm.parentMaterialTypeName' placeholder='' style="width:260px" readonly/>
</el-form-item>
<el-form-item label="BOM版本" prop='materialBomVersion' :model="parentForm">
<el-select v-model="parentForm.materialBomVersion"
placeholder="请选择" style="width:360px">
placeholder="请选择" style="width:200px">
<el-option
v-for="item in materialBomVersionOptions"
:key="item.materialBomVersion"
@ -55,13 +64,13 @@
</el-form-item>
<el-form-item label='父物料数量' prop='parentStandardAmount'>
<el-input-number v-model='parentForm.parentStandardAmount' :precision="2" :step="0.1"
<el-input-number v-model='parentForm.parentStandardAmount' :precision="2" :step="1"
placeholder='请输入父物料数量'
style="width:360px"/>
style="width:200px"/>
</el-form-item>
<el-form-item label='单位' prop='parentUnitId'>
<el-select v-model="parentForm.parentUnitId" placeholder="请选择" style="width:360px">
<el-select v-model="parentForm.parentUnitId" placeholder="请选择" style="width:200px">
<el-option
v-for="item in unitInfoOptions"
:key="item.unitId"
@ -110,15 +119,15 @@
prop="materialName" :show-overflow-tooltip="true">
<template #default='scope'>
<el-input v-model='scope.row.materialName' placeholder='请点击检索物料'
@click='handleMaterialSelect(scope.row,SELECT_MATERIAL_MODEL.CHILD_SELECT)' readonly/>
@click='handleMaterialSelect(scope.row,SELECT_MATERIAL_MODEL.CHILD_SELECT)'
suffix-icon="Search" readonly/>
</template>
</el-table-column>
<el-table-column v-if="columns[6].visible" key="standardAmount" label="子物料数量" align="center"
prop="standardAmount" :show-overflow-tooltip="true" width="200px">
prop="standardAmount" :show-overflow-tooltip="true" width="220px">
<template #default='scope'>
<el-input-number v-model='scope.row.standardAmount' :precision="2" :step="0.1"
placeholder='请输入数量'
style="width:180px"/>
<el-input-number v-model='scope.row.standardAmount' :precision="2" :step="1"
placeholder='请输入数量' style="width:180px"/>
</template>
</el-table-column>
@ -191,12 +200,12 @@
</el-form-item>
<el-form-item label='子物料数量' prop='standardAmount'>
<el-input-number v-model='form.standardAmount' :precision="2" :step="0.1" placeholder='请输入子物料数量'
<el-input-number v-model='form.standardAmount' :precision="2" :step="1" placeholder='请输入子物料数量'
style="width:360px"/>
</el-form-item>
<el-form-item label='子物料单位' prop='unitId'>
<el-select v-model="form.unitId" placeholder="请选择单位">
<el-select v-model="form.unitId" placeholder="请选择单位" style="width:360px">
<el-option
v-for="item in unitInfoOptions"
:key="item.unitId"
@ -233,8 +242,8 @@
import {
materialBomTreeSelect,
listMaterialBomJoinStructure,
addBatchMaterialBom, updateMaterialBom, addMaterialBom, delMaterialBom,
getUnitInfoList, getMaterialBomVersionList, getParentMaterialBom
addBatchMaterialBom,
getUnitInfoList, getMaterialBomVersionList, getParentMaterialBom, deleteMaterialBoms
} from "@/api/mes/materialBom";
import {MaterialBomVO, MaterialBomForm, MaterialBomQuery} from '@/api/mes/materialBom/types';
@ -262,6 +271,7 @@ const submitLoading = ref(false);
const btnLoading = ref(false);
const showSearch = ref(true);
const selectedMaterialBoms = ref<MaterialBomVO[]>([]);
const toDeleteMaterialBoms = ref<MaterialBomVO[]>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
@ -276,6 +286,8 @@ const unitInfoOptions = ref<BaseMeasurementUnitInfoVO[]>([]);
const focusKeyNode = ref<MaterialBomVO>;
const parentMaterialDisabled = ref(true);
const globalSelectMode = ref('');
const SELECT_MATERIAL_MODEL = ref({
PARENT_SELECT: '1',//
@ -309,7 +321,7 @@ const dialog = reactive<DialogOption>({
const initParentFormData: MaterialBomForm = {
materialBomId: undefined,
parentId: undefined,
parentStandardAmount: undefined,
parentStandardAmount: 1,
unitId: undefined,
parentUnitId: undefined,
materialId: undefined,
@ -381,7 +393,23 @@ const data = reactive<PageData<MaterialBomForm, MaterialBomQuery>>({
standardAmount: [
{required: true, message: "子物料数量不能为空", trigger: "blur"}
]
},
parentRules: {
parentMaterialName: [
{required: true, message: "父物料名称不能为空", trigger: "blur"}
],
materialBomVersion: [
{required: true, message: "BOM版本不能为空", trigger: "blur"}
],
parentStandardAmount: [
{required: true, message: "父物料数量不能为空", trigger: "blur"}
],
parentUnitId: [
{required: true, message: "父物料单位不能为空", trigger: "blur"}
]
}
});
@ -395,7 +423,7 @@ const parentQueryParams = ref({
params: {}
})
const {queryParams, form, rules, parentForm} = toRefs(data);
const {queryParams, form, rules, parentForm, parentRules} = toRefs(data);
/** 通过条件过滤节点 */
const filterNode = (value: string, data: any) => {
@ -415,6 +443,7 @@ watchEffect(
/** 查询物料类型bom结构树下拉树结构 */
const getTreeSelect = async () => {
treeLoading.value = true;
loading.value = true;
const res = await materialBomTreeSelect();
materialBomOptions.value = [];
const virtualTopNodeId = -1;
@ -430,21 +459,38 @@ const getTreeSelect = async () => {
console.log(materialBomOptions);
// materialBomOptions.value = res.data;
if (!focusKeyNode.value) {//focus
focusKeyNode.value = {treeKey: virtualTopNodeId};
} else {
alert(23)
alert(focusKeyNode.value.treeKey)
console.log(JSON.stringify(materialBomOptions.value))
const clickNode = findObjectByTreeKey(materialBomOptions.value, focusKeyNode.value.treeKey)
if (!clickNode) {
focusKeyNode.value = undefined;
focusKeyNode.value = {treeKey: virtualTopNodeId};
}
// if (!allTreeKeys || allTreeKeys.length <= 0) {
// focusKeyNode.value = {
// treeKey: virtualTopNodeId,
// id: virtualTopNodeId
// };
// }
// const focusKeyNodeIndex = JSON.stringify(materialBomOptions.value).indexOf(focusKeyNode.value.treeKey);
// if (focusKeyNodeIndex < 0) {
// focusKeyNode.value = {treeKey: virtualTopNodeId};
// }
// const focusKeyNodeIndex = materialBomOptions.value.findIndex((optionItem) => focusKeyNode.value.treeKey === optionItem.treeKey);//children
}
nextTick(function () {
materialBomTreeRef.value?.setCurrentKey(focusKeyNode.value.treeKey, true);
})
handleNodeClick(focusKeyNode.value);
loading.value = false;
treeLoading.value = false;
handleNodeClick(focusKeyNode.value);
// const dd = {"id":"1","parentId":-1,"label":"dd"};
// materialTypeOptions.value[0].children.push(dd);
};
@ -471,6 +517,7 @@ const resetQueryParams = () => {
/** 节点单击事件 */
const handleNodeClick = (data: MaterialBomVO) => {
materialBomList.value = [];
parentMaterialDisabled.value = true;
resetParentForm();
resetQueryParams();
resetParentQueryParams();
@ -489,6 +536,7 @@ const handleNodeClick = (data: MaterialBomVO) => {
queryParams.value.materialBomVersion = materialBomVersionOptions.value[0].materialBomVersion;
}
}
parentMaterialDisabled.value = focusKeyNode.value.treeKey != -1;
};
@ -520,20 +568,30 @@ const resetQuery = () => {
/** 删除按钮操作 */
const handleDelete = async (row?: MaterialBomVO) => {
btnLoading.value = true;
const materialBomIds = [];
const toDeleteIndexes = [];
selectedMaterialBoms.value.forEach(item => {
if (item.materialBomId && item.materialBomId !== '') {
materialBomIds.push(item.materialBomId);
} else {
deleteReset(item);
}
// const index = materialBomList.value.findIndex((optionItem) => item.materialBomId === optionItem.materialBomId);
const index = materialBomList.value.indexOf(item);
toDeleteIndexes.push(parseInt(index + 1));
});
if (materialBomIds.length > 0) {
if (toDeleteIndexes.length > 0) {
try {
const [err] = await to(proxy?.$modal.confirm('是否确认删除生产BOM编号为"' + materialBomIds + '"的数据项?') as any);
const [err] = await to(proxy?.$modal.confirm('是否确认删除序号为"' + toDeleteIndexes + '"的数据项?') as any);
if (!err) {
await delMaterialBom(materialBomIds)
await getTreeSelect();
selectedMaterialBoms.value.forEach(item => {
if (item.materialBomId && item.materialBomId !== '') {
toDeleteMaterialBoms.value.push(item);
} else {
deleteReset(item);
}
});
// alert(JSON.stringify(toDeleteMaterialBoms.value))
if (toDeleteMaterialBoms.value.length > 0) {
await deleteMaterialBoms(toDeleteMaterialBoms.value)
await getTreeSelect();
}
proxy?.$modal.msgSuccess('删除成功');
}
} catch {
@ -548,6 +606,7 @@ const deleteReset = (item) => {
item.materialName = undefined;
item.materialBomVersion = undefined;
item.standardAmount = undefined;
item.unitId = undefined;
};
/** 选择条数 */
@ -706,55 +765,58 @@ const submitMaterialForm = () => {
const submitBatchSaveMaterialBoms = async () => {
try {
btnLoading.value = true;
saveMaterialBomList.value = [];
for (let i = 0; i < materialBomList.value.length; i++) {
let item = materialBomList.value[i];
if (item.materialId) {
parentMaterialBomFormRef.value?.validate(async (valid: boolean) => {
if (valid) {
try {
btnLoading.value = true;
saveMaterialBomList.value = [];
for (let i = 0; i < materialBomList.value.length; i++) {
let item = materialBomList.value[i];
if (item.materialId) {
if (!item.standardAmount) {
proxy?.$modal.msgWarning('序号为[' + i + 1 + '],请填写子物料数量');
btnLoading.value = false;
return;
}
if (!item.unitId) {
proxy?.$modal.msgWarning('序号为[' + i + 1 + '],请选择单位');
if (!item.standardAmount) {
proxy?.$modal.msgWarning('序号为[' + (parseInt(i) + 1) + '],请填写子物料数量');
btnLoading.value = false;
return;
}
if (!item.unitId) {
proxy?.$modal.msgWarning('序号为[' + (parseInt(i) + 1) + '],请选择单位');
btnLoading.value = false;
return;
}
item.parentId = parentForm.value.parentId;
item.parentUnitId = parentForm.value.parentUnitId;
item.materialBomVersion = parentForm.value.materialBomVersion;
item.parentStandardAmount = parentForm.value.parentStandardAmount;
item.parentMaterialTypeId = parentForm.value.parentMaterialTypeId;
saveMaterialBomList.value.push(item);
}
}
if (saveMaterialBomList.value.length <= 0) {
proxy?.$modal.msgWarning('无可保存子级物料');
btnLoading.value = false;
return;
}
await addBatchMaterialBom(saveMaterialBomList.value);
proxy?.$modal.msgSuccess('操作成功');
item.parentId = parentForm.value.parentId;
item.parentUnitId = parentForm.value.parentUnitId;
item.materialBomVersion = parentForm.value.materialBomVersion;
item.parentStandardAmount = parentForm.value.parentStandardAmount;
item.parentMaterialTypeId = parentForm.value.parentMaterialTypeId;
saveMaterialBomList.value.push(item);
focusKeyNode.value.treeKey = parentForm.value.parentId + "-" + parentForm.value.materialBomVersion;
focusKeyNode.value.materialBomVersion = parentForm.value.materialBomVersion;
focusKeyNode.value.parentUnitId = parentForm.value.parentUnitId;
focusKeyNode.value.parentStandardAmount = parentForm.value.parentStandardAmount;
resetParentQueryParams();
resetQueryParams();
resetParentForm();
await getTreeSelect();
btnLoading.value = false;
} catch (e) {
proxy?.$modal.msgWarning(e);
btnLoading.value = false;
}
}
if (saveMaterialBomList.value.length <= 0) {
proxy?.$modal.msgWarning('无可保存子级物料');
btnLoading.value = false;
return;
}
await addBatchMaterialBom(saveMaterialBomList.value);
proxy?.$modal.msgSuccess('操作成功');
focusKeyNode.value.treeKey = parentForm.value.parentId + "-" + parentForm.value.materialBomVersion;
focusKeyNode.value.materialBomVersion = parentForm.value.materialBomVersion;
focusKeyNode.value.parentUnitId = parentForm.value.parentUnitId;
focusKeyNode.value.parentStandardAmount = parentForm.value.parentStandardAmount;
await getTreeSelect();
resetParentQueryParams();
resetQueryParams();
resetParentForm();
btnLoading.value = false;
} catch (e) {
proxy?.$modal.msgWarning(e);
btnLoading.value = false;
}
});
}
@ -790,6 +852,34 @@ const getParentMaterialBomInfo = async () => {
};
const findObjectByTreeKey = (list, targetTreeKey) => {
for (const item of list) {
if (item.treeKey === targetTreeKey) return item;
if (item.children) {
const found = findObjectByTreeKey(item.children, targetTreeKey);
if (found) return found;
}
}
return null;
}
// const getClickNode = (obj) => {
// // id,focusid
// // console.log(JSON.stringify(obj))
// if (obj.treeKey !== undefined && obj.treeKey === focusKeyNode.value.treeKey) {
// return obj;
// }
//
// // children
// if (obj.children && Array.isArray(obj.children)) {
// obj.children.forEach(child => {
// getClickNode(child); //
// });
// }
//
// }
</script>
<style lang="scss" scoped></style>

Loading…
Cancel
Save