diff --git a/src/api/feed/FormulaManagement.js b/src/api/feed/FormulaManagement.js index d78d1a1..558673b 100644 --- a/src/api/feed/FormulaManagement.js +++ b/src/api/feed/FormulaManagement.js @@ -36,9 +36,9 @@ export function updateFormulaManagement(data) { } // 删除配方管理 -export function delFormulaManagement(formulaId) { +export function delFormulaManagement(formulaIdAndBatchId) { return request({ - url: '/feed/FormulaManagement/' + formulaId, + url: '/feed/FormulaManagement/' + formulaIdAndBatchId, method: 'delete' }) } diff --git a/src/views/feed/FormulaManagement/index.vue b/src/views/feed/FormulaManagement/index.vue index d37000e..a4f41e4 100644 --- a/src/views/feed/FormulaManagement/index.vue +++ b/src/views/feed/FormulaManagement/index.vue @@ -15,16 +15,16 @@ - 新增 修改 + v-hasPermi="['feed:FormulaManagement:edit']" v-show="false">修改 删除 + v-hasPermi="['feed:FormulaManagement:remove']" v-show="false">删除 - - + + - @@ -80,11 +78,11 @@ @@ -152,7 +150,7 @@ - + @@ -164,9 +162,16 @@
+ + + + + - + @@ -176,15 +181,15 @@ - + - + @@ -211,13 +216,15 @@ - + @@ -284,7 +291,8 @@ const isView = ref(false) */ const operationType = ref("") // 操作类型:add 或 update // 控制批号是否可编辑 -const BatchIdEditable = ref(false) +const BatchIdEditable = ref(false) +const FormulaIdEditable = ref(false) // 原料下拉列表 const materials = ref([]) // 原料类型 @@ -313,8 +321,8 @@ const data = reactive({ feedStage: [ { required: true, message: "饲养阶段不能为空", trigger: "blur" } ], - ratio:[ - {required: true, message: "比例不能为空", trigger: "blur"}, + ratio: [ + { required: true, message: "比例不能为空", trigger: "blur" }, ] } }) @@ -341,11 +349,19 @@ function getList() { } // 处理展开行的变化 -function handleExpandChange(row, expanded) { - if (expanded) { - expandedRows.value.push(row.formulaId) // 添加展开的行 - } else { - expandedRows.value = expandedRows.value.filter(id => id !== row.formulaId) // 移除收起的行 +function handleExpandChange(row, expandedRows) { + // 收起其他行 + expandedRows.forEach(r => { + if (r !== row) { + mainTable.value.toggleRowExpansion(r, false) + } + }) + + // 如果是展开状态,刷新子表数据 + const isExpanded = expandedRows.includes(row) + if (isExpanded) { + loading.value = true + getList(); } } @@ -391,20 +407,59 @@ function handleSelectionChange(selection) { } /** 新增按钮操作 */ -function handleAdd() { +function handleAddFormulatemplate() { + formulaFormReset() reset() - open.value = true - title.value = "添加配方管理" + operationType.value = "add" + // 模板禁用批号编辑 + BatchIdEditable.value = false + // 添加模板时配方编号可编辑 + FormulaIdEditable.value = true + isView.value = false + // 初始化表单 + showFormulaManagementList.value = { + formulaId: null, + // 模板批号为 0 + batchId: "0", + feedStage: null, + useStartDate: null, + useEndDate: null, + useState: '1', // 默认启用 + remark: null, + sgFormulaList: [{ + materialId: null, + materialName: null, + ratio: null, + isGranular: "0", + isSupplement: "0" + }] + } + formulaListOpen.value = true + title.value = "添加配方管理模板" } /** 修改按钮操作 */ -function handleUpdate(row) { +function handleFormulaTemplateUpdate(row) { reset() - const _formulaId = row.formulaId || ids.value - getFormulaManagement(_formulaId).then(response => { - form.value = response.data - open.value = true - title.value = "修改配方管理" + operationType.value = "update" + const _id = row.formulaId || ids.value + BatchIdEditable.value = false // 修改时批号不可编辑 + FormulaIdEditable.value = false // 修改时配方编号不可编辑 + const batchId = row.batchId + const queryParams = { + formulaId: _id, + batchId: batchId, + queryType: "query" + } + listFormulaManagement(queryParams).then(response => { + if (response.rows && response.rows.length > 0) { + showFormulaManagementList.value = response.rows[0] // 取第一条记录 + } else { + showFormulaManagementList.value = {} + } + formulaListOpen.value = true + title.value = "修改处方" + isView.value = false }) } @@ -441,12 +496,14 @@ function handleDelete(row) { } /** ================= 配方列表操作 ================= */ -function handleAddSgFormulaList(row){ +function handleAddSgFormulaList(row) { formulaFormReset() reset() operationType.value = "add" BatchIdEditable.value = true + FormulaIdEditable.value = false isView.value = false + console.log(row.sgFormulaList) // 初始化表单 showFormulaManagementList.value = { formulaId: row.formulaId || null, @@ -456,7 +513,7 @@ function handleAddSgFormulaList(row){ useEndDate: null, useState: '1', // 默认启用 remark: null, - sgFormulaList: [{ + sgFormulaList: row.sgFormulaList || [{ materialId: null, materialName: null, ratio: null, @@ -481,15 +538,16 @@ function handleFormulaUpdate(row) { } console.log("formulaForm: ", formulaForm.value) formulaListOpen.value = true + FormulaIdEditable.value = false title.value = "修改配方列表" }) } /** 删除按钮操作 */ -function handleFormulaDelete_Old(row) { - const _codes = row.code || ids.value +function handleFormulaDelete(row) { + const _codes = row.formulaId + "/" + row.batchId proxy.$modal.confirm('是否确认删除配方列表编号为"' + _codes + '"的数据项?').then(function () { - return delFormulaList(_codes) + return delFormulaManagement(_codes) }).then(() => { getList() proxy.$modal.msgSuccess("删除成功") @@ -518,13 +576,13 @@ function submitFormulaListForm() { } // 原料下拉选择变化时,更新对应的原料名称 - function handleMaterialChange(row, selectedValue) { - const selectedItem = this.materials.find(item => item.value === selectedValue); - if (selectedItem) { - // materialName 也在 row 中 - row.materialName = selectedItem.label; - } +function handleMaterialChange(row, selectedValue) { + const selectedItem = this.materials.find(item => item.value === selectedValue); + if (selectedItem) { + // materialName 也在 row 中 + row.materialName = selectedItem.label; } +} /** * 查看详情