diff --git a/src/api/mes/machineTankDetail/types.ts b/src/api/mes/machineTankDetail/types.ts index 0962bb9..025f117 100644 --- a/src/api/mes/machineTankDetail/types.ts +++ b/src/api/mes/machineTankDetail/types.ts @@ -9,11 +9,21 @@ export interface MachineTankDetailVO { */ machineId: string | number; + /** + * 机台名称(关联查询) + */ + machineName?: string; + /** * 料罐类型 */ tankTypeId: string | number; + /** + * 罐类型(关联查询) + */ + tankType?: string; + /** * 仓位序号 */ @@ -24,6 +34,16 @@ export interface MachineTankDetailVO { */ materialId: string | number; + /** + * 物料编码(关联查询) + */ + materialCode?: string; + + /** + * 物料名称(关联查询) + */ + materialName?: string; + /** * 料仓优先级 */ @@ -102,6 +122,16 @@ export interface MachineTankDetailForm extends BaseEntity { */ materialId?: string | number; + /** + * 物料编码 + */ + materialCode?: string; + + /** + * 物料名称 + */ + materialName?: string; + /** * 料仓优先级 */ diff --git a/src/views/mes/machineTankDetail/index.vue b/src/views/mes/machineTankDetail/index.vue index 41c9a6c..dd4f25c 100644 --- a/src/views/mes/machineTankDetail/index.vue +++ b/src/views/mes/machineTankDetail/index.vue @@ -5,13 +5,34 @@
- - + + + + - - - + + + @@ -53,25 +74,37 @@ - - - - - - - - - - - - + + - - - + + + + + + + + + + + + + + + + + + + + @@ -163,12 +212,37 @@ import { addMachineTankDetail, updateMachineTankDetail } from '@/api/mes/machineTankDetail'; +import { getProdMachineTankTypeList } from '@/api/mes/machineTankType'; +import { getProdBaseMachineInfoList } from '@/api/mes/prodBaseMachineInfo'; import { MachineTankDetailVO, MachineTankDetailQuery, MachineTankDetailForm } from '@/api/mes/machineTankDetail/types'; +import type { MachineTankTypeVO } from '@/api/mes/machineTankType/types'; +import type { ProdBaseMachineInfoVO } from '@/api/mes/prodBaseMachineInfo/types'; +import MaterialSelect from '@/views/mes/recipeInfo/components/MaterialSelect.vue'; const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { sys_show_hide } = toRefs(proxy?.useDict('sys_show_hide')); +const { tank_type } = toRefs(proxy?.useDict('tank_type')); const machineTankDetailList = ref([]); +const tankTypeOptions = ref([]); +const machineOptions = ref([]); +const materialSelectVisible = ref(false); +const materialSelectRef = ref>(); +const materialMap = ref>({}); + +const formMachineDisplay = computed(() => { + const tid = form.value.tankTypeId; + if (tid == null || tid === '') return ''; + const item = tankTypeOptions.value.find((t) => t.tankTypeId === tid || String(t.tankTypeId) === String(tid)); + return item ? (item.machineName || item.machineId || '') : ''; +}); + +const formMaterialDisplay = computed(() => { + const id = form.value.materialId; + if (id == null || id === '') return ''; + const m = materialMap.value[String(id)]; + return m ? `${m.materialName}`.trim() : String(id); +}); const buttonLoading = ref(false); const loading = ref(true); const showSearch = ref(true); @@ -185,30 +259,18 @@ const dialog = reactive({ title: '' }); -// 列显隐信息 +// 列显隐信息(保留兼容 right-toolbar,表格列已固定显示) const columns = ref([ - { key: 0, label: `料罐明细ID`, visible: false }, - { key: 1, label: `租户编号`, visible: true }, - { key: 2, label: `机台名称`, visible: true }, - { key: 3, label: `料罐类型`, visible: true }, - { key: 4, label: `仓位序号`, visible: true }, - { key: 5, label: `物料ID`, visible: true }, - { key: 6, label: `料仓优先级`, visible: true }, - { key: 7, label: `comment`, visible: true }, - { key: 8, label: `comment`, visible: true }, - { key: 9, label: `称重编号`, visible: true }, - { key: 10, label: `最小称重限额`, visible: true }, - { key: 11, label: `最大称重限额`, visible: true }, - { key: 12, label: `状态(0正常1停用)`, visible: true }, - { key: 13, label: `备注`, visible: true }, - { key: 14, label: `创建部门`, visible: true }, - { key: 15, label: `创建者`, visible: true }, - { key: 16, label: `创建时间`, visible: true }, - { key: 17, label: `更新者`, visible: true }, - { key: 18, label: `更新时间`, visible: true }, - { key: 19, label: `仓库ID`, visible: true }, - { key: 20, label: `工位ID`, visible: true }, - { key: 21, label: `删除标志`, visible: true } + { key: 0, label: '机台名称', visible: true }, + { key: 1, label: '料罐类型', visible: true }, + { key: 2, label: '料仓序号', visible: true }, + { key: 3, label: '物料编码', visible: true }, + { key: 4, label: '物料名称', visible: true }, + { key: 5, label: '料仓优先级', visible: true }, + { key: 6, label: '称重编号', visible: false }, + { key: 7, label: '称重限额', visible: false }, + { key: 8, label: '状态', visible: true }, + { key: 9, label: '备注', visible: true } ]); const initFormData: MachineTankDetailForm = { @@ -250,23 +312,76 @@ const data = reactive>({ params: {} }, rules: { - machineId: [ - { required: true, message: '机台名称不能为空', trigger: 'blur' } - ], tankTypeId: [ - { required: true, message: '料罐类型不能为空', trigger: 'blur' } - ], - wareNum: [ - { required: true, message: '仓位序号不能为空', trigger: 'blur' } + { required: true, message: '请选择料罐类型', trigger: 'change' } ], materialId: [ - { required: true, message: '物料ID不能为空', trigger: 'blur' } + { required: true, message: '请选择物料', trigger: 'change' } + ], + wareNum: [ + { required: true, message: '料仓序号不能为空', trigger: 'blur' } ] } }); const { queryParams, form, rules } = toRefs(data); +/** 加载料罐类型下拉列表 */ +const getTankTypeOptions = async () => { + try { + const res = await getProdMachineTankTypeList({}); + tankTypeOptions.value = res.data || res.rows || []; + } catch { + tankTypeOptions.value = []; + } +}; + +/** 加载机台下拉列表 */ +const getMachineOptions = async () => { + try { + const res = await getProdBaseMachineInfoList({}); + machineOptions.value = res.data || []; + } catch { + machineOptions.value = []; + } +}; + +/** 料罐类型下拉选项展示文案 */ +function getTankTypeOptionLabel(item: MachineTankTypeVO): string { + const machineLabel = item.machineName || item.machineId || ''; + const tankLabel = tank_type.value?.find((d: any) => d.value === item.tankType)?.label || item.tankType || ''; + return `${machineLabel} - ${tankLabel}`; +} + +/** 料罐类型选择变化时,回填 machineId */ +function onTankTypeChange(val: string | number) { + if (val == null || val === '') return; + const item = tankTypeOptions.value.find((t) => t.tankTypeId === val || String(t.tankTypeId) === String(val)); + if (item) { + form.value.machineId = item.machineId != null ? String(item.machineId) : undefined; + } +} + + +function openMaterialSelect() { + materialSelectVisible.value = true; +} + +function confirmMaterialSelect() { + const row = materialSelectRef.value?.getSelected(); + if (!row) { + proxy?.$modal.msgWarning('请先选择一条物料'); + return; + } + form.value.materialId = row.materialId; + const id = String(row.materialId); + materialMap.value = { + ...materialMap.value, + [id]: { materialCode: row.materialCode ?? '', materialName: row.materialName ?? '' } + }; + materialSelectVisible.value = false; +} + /** 查询机台料罐明细列表 */ const getList = async () => { loading.value = true; @@ -308,8 +423,9 @@ const handleSelectionChange = (selection: MachineTankDetailVO[]) => { }; /** 新增按钮操作 */ -const handleAdd = () => { +const handleAdd = async () => { reset(); + await getTankTypeOptions(); dialog.visible = true; dialog.title = '添加机台料罐明细'; }; @@ -317,9 +433,17 @@ const handleAdd = () => { /** 修改按钮操作 */ const handleUpdate = async (row?: MachineTankDetailVO) => { reset(); + await getTankTypeOptions(); const _tankDetailId = row?.tankDetailId || ids.value[0]; const res = await getMachineTankDetail(_tankDetailId); Object.assign(form.value, res.data); + const d = res.data as any; + if (d?.materialId != null && (d?.materialCode || d?.materialName)) { + materialMap.value = { + ...materialMap.value, + [String(d.materialId)]: { materialCode: d.materialCode ?? '', materialName: d.materialName ?? '' } + }; + } dialog.visible = true; dialog.title = '修改机台料罐明细'; }; @@ -358,6 +482,8 @@ const handleExport = () => { }; onMounted(() => { + getTankTypeOptions(); + getMachineOptions(); getList(); });