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

@ -238,4 +238,9 @@ export interface BaseStructureBomTreeVO {
*/ */
children: []; 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 * BOM

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

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

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

Loading…
Cancel
Save