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

main
黄伟杰 3 weeks ago
parent d67ed9f9c9
commit f7ce6117d6

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

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

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

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

Loading…
Cancel
Save