style:配方配置-新增/编辑添加关联产品分类

main
黄伟杰 3 weeks ago
parent d67ed9f9c9
commit f7ce6117d6

@ -28,8 +28,8 @@ export const ProductApi = {
},
// 查询产品精简列表
getProductSimpleList: async () => {
return await request.get({ url: `/erp/product/simple-list-all` })
getProductSimpleList: async (params?: { categoryId?: string | number }) => {
return await request.get({ url: `/erp/product/simple-list-all`, params })
},
// 查询原料精简列表
getItemSimpleList: async () => {

@ -7,6 +7,7 @@ export interface RecipeConfigVO {
name?: string
recipeType?: string | number
recipeTypeId?: string | number
productCategoryId?: number
productId?: number
productName?: string
machineName?: string
@ -123,6 +124,7 @@ export const RecipeConfigApi = {
name: data.name ?? data.recipeName,
recipeCode: data.recipeCode,
recipeTypeId: (data as any).recipeTypeId ?? data.recipeType,
productCategoryId: (data as any).productCategoryId,
productId: data.productId,
machineId: (data as any).machineId ?? data.deviceId,
recipeDesc: data.recipeDesc ?? data.remark,
@ -138,6 +140,7 @@ export const RecipeConfigApi = {
name: data.name ?? data.recipeName,
recipeCode: data.recipeCode,
recipeTypeId: (data as any).recipeTypeId ?? data.recipeType,
productCategoryId: (data as any).productCategoryId,
productId: data.productId,
machineId: (data as any).machineId ?? data.deviceId,
recipeDesc: data.recipeDesc ?? data.remark,

@ -2542,6 +2542,8 @@ export default {
dialogNamePlaceholder: 'Please enter recipe name',
dialogRecipeTypeLabel: 'Recipe Type',
dialogRecipeTypePlaceholder: 'Please select recipe type',
dialogProductCategoryLabel: 'Product Category',
dialogProductCategoryPlaceholder: 'Please select product category',
dialogProductNameLabel: 'Related Product',
dialogProductNamePlaceholder: 'Please select related product',
dialogMachineNameLabel: 'Related Device',

@ -2125,6 +2125,8 @@ export default {
dialogNamePlaceholder: '请输入配方名称',
dialogRecipeTypeLabel: '配方类型',
dialogRecipeTypePlaceholder: '请选择配方类型',
dialogProductCategoryLabel: '关联产品分类',
dialogProductCategoryPlaceholder: '请选择产品分类',
dialogProductNameLabel: '关联产品',
dialogProductNamePlaceholder: '请选择关联产品',
dialogMachineNameLabel: '关联设备',

@ -168,6 +168,20 @@ ref="detailRef" :visible="detailVisible"
<el-option v-for="item in recipeTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item :label="t('RecipeManagement.RecipeConfig.dialogProductCategoryLabel')" prop="productCategoryId">
<el-select
v-model="dialogForm.productCategoryId"
:placeholder="t('RecipeManagement.RecipeConfig.dialogProductCategoryPlaceholder')"
clearable
filterable
class="!w-full"
:loading="categoryLoading"
@change="handleCategoryChange"
>
<el-option v-for="item in categoryOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item :label="t('RecipeManagement.RecipeConfig.dialogProductNameLabel')" prop="productId">
<el-select
v-model="dialogForm.productId"
@ -176,6 +190,7 @@ ref="detailRef" :visible="detailVisible"
filterable
class="!w-full"
:loading="productLoading"
:disabled="!dialogForm.productCategoryId"
>
<el-option v-for="item in productOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
@ -290,6 +305,7 @@ ref="detailRef" :visible="detailVisible"
<script setup lang="ts">
import download from '@/utils/download'
import { ProductApi } from '@/api/erp/product/product'
import { ProductCategoryApi } from '@/api/erp/product/category'
import { DeviceApi } from '@/api/iot/device'
import { RecipeApi } from '@/api/iot/recipe'
import { RecipeConfigApi, RecipeConfigVO } from '@/api/iot/recipeConfig'
@ -386,6 +402,8 @@ const handleDelete = async (row: RecipeConfigVO) => {
const productLoading = ref(false)
const productOptions = ref<SelectOption<string>[]>([])
const categoryLoading = ref(false)
const categoryOptions = ref<SelectOption<string>[]>([])
const deviceLoading = ref(false)
const deviceOptions = ref<SelectOption<string>[]>([])
const recipeTypeLoading = ref(false)
@ -399,10 +417,24 @@ const getRecipeTypeLabel = (value: unknown) => {
return matched?.label ?? String(value)
}
const getProductOptions = async () => {
const getCategoryOptions = async () => {
categoryLoading.value = true
try {
const data = await ProductCategoryApi.getProductCategorySimpleList()
categoryOptions.value = (data ?? []).map((item: any) => ({ label: item.name, value: item.id }))
} finally {
categoryLoading.value = false
}
}
const getProductOptions = async (categoryId: string | number | undefined) => {
if (categoryId === undefined || categoryId === null || categoryId === '') {
productOptions.value = []
return
}
productLoading.value = true
try {
const data = await ProductApi.getProductSimpleList()
const data = await ProductApi.getProductSimpleList({ categoryId })
productOptions.value = (data ?? []).map((item: any) => ({ label: item.name, value: item.id }))
} finally {
productLoading.value = false
@ -430,7 +462,7 @@ const getRecipeTypeOptions = async () => {
}
const ensureOptionsLoaded = async () => {
if (!productOptions.value.length) await getProductOptions()
if (!categoryOptions.value.length) await getCategoryOptions()
if (!deviceOptions.value.length) await getDeviceOptions()
if (!recipeTypeOptions.value.length) await getRecipeTypeOptions()
}
@ -450,6 +482,7 @@ const dialogForm = reactive({
recipeCode: '',
name: '',
recipeTypeId: '' as string | number | undefined,
productCategoryId: '' as string | number | undefined,
productId: '' as string | number | undefined,
machineId: '' as string | number | undefined,
recipeDesc: ''
@ -485,9 +518,11 @@ const openDialog = async (mode: DialogMode, row?: RecipeConfigVO) => {
dialogForm.recipeCode = ''
dialogForm.name = ''
dialogForm.recipeTypeId = ''
dialogForm.productCategoryId = ''
dialogForm.productId = ''
dialogForm.machineId = ''
dialogForm.recipeDesc = ''
productOptions.value = []
return
}
@ -497,6 +532,7 @@ const openDialog = async (mode: DialogMode, row?: RecipeConfigVO) => {
dialogForm.recipeTypeId =
(row as any)?.recipeTypeId ??
(row?.recipeType === undefined || row?.recipeType === null ? '' : (row as any).recipeType)
dialogForm.productCategoryId = (row as any)?.productCategoryId ?? (row as any)?.categoryId ?? ''
const findProductValueByName = (name: string | undefined) => {
if (!name) return ''
@ -509,11 +545,17 @@ const openDialog = async (mode: DialogMode, row?: RecipeConfigVO) => {
return matched?.value ?? ''
}
await getProductOptions(dialogForm.productCategoryId)
dialogForm.productId = (row as any)?.productId ?? findProductValueByName(row?.productName)
dialogForm.machineId = (row as any)?.machineId ?? (row as any)?.deviceId ?? findDeviceValueByName(row?.machineName ?? row?.deviceName)
dialogForm.recipeDesc = row?.recipeDesc ?? row?.remark ?? ''
}
const handleCategoryChange = async (value: string | number | undefined) => {
dialogForm.productId = ''
await getProductOptions(value)
}
const submitDialog = async () => {
if (!dialogFormRef.value) return
await dialogFormRef.value.validate()
@ -524,6 +566,7 @@ const submitDialog = async () => {
recipeCode: dialogForm.recipeCode,
name: dialogForm.name,
recipeTypeId: dialogForm.recipeTypeId,
productCategoryId: dialogForm.productCategoryId,
productId: dialogForm.productId,
machineId: dialogForm.machineId,
recipeDesc: dialogForm.recipeDesc

Loading…
Cancel
Save