From f887843d412786a0969cc028c76db18637ac4bd2 Mon Sep 17 00:00:00 2001 From: hwj Date: Mon, 1 Jun 2026 15:14:06 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E4=BA=A7=E5=93=81=E7=89=A9?= =?UTF-8?q?=E6=96=99=E4=BF=A1=E6=81=AF-=E6=B7=BB=E5=8A=A0=E4=BA=A7?= =?UTF-8?q?=E5=93=81/=E7=89=A9=E6=96=99=E7=B1=BB=E5=9E=8B=E5=88=86?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/erp/product/category/index.ts | 4 +- src/locales/en.ts | 1 + src/locales/zh-CN.ts | 2 + src/views/erp/product/product/ProductForm.vue | 34 +++++++++++++++-- src/views/erp/product/product/index.vue | 38 +++++++++---------- 5 files changed, 54 insertions(+), 25 deletions(-) diff --git a/src/api/erp/product/category/index.ts b/src/api/erp/product/category/index.ts index 72cca0c9..69dc93ab 100644 --- a/src/api/erp/product/category/index.ts +++ b/src/api/erp/product/category/index.ts @@ -19,8 +19,8 @@ export const ProductCategoryApi = { }, // 查询产品分类精简列表 - getProductCategorySimpleList: async () => { - return await request.get({ url: `/erp/product-category/simple-list` }) + getProductCategorySimpleList: async (type?: number) => { + return await request.get({ url: `/erp/product-category/simple-list`, params: { type } }) }, // 查询产品分类详情 diff --git a/src/locales/en.ts b/src/locales/en.ts index 928d2cb5..14687bef 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -2055,6 +2055,7 @@ export default { validatorNameRequired: 'Product name can not be empty', validatorBarCodeRequired: 'Product barcode can not be empty', validatorCategoryRequired: 'Product category id can not be empty', + validatorCategoryTypeRequired: 'Type can not be empty', validatorUnitRequired: 'Unit id can not be empty', validatorStatusRequired: 'Product status can not be empty' }, diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index 068dd775..bc78ea6f 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -2894,6 +2894,7 @@ export default { dialogBarCodePlaceholder: '请输入编码', dialogNameLabel: '名称', dialogNamePlaceholder: '请输入名称', + dialogCategoryTypeLabel: '类型', dialogCategoryLabel: '分类', dialogCategoryPlaceholder: '请选择分类', dialogUnitLabel: '单位', @@ -2920,6 +2921,7 @@ export default { validatorNameRequired: '产品名称不能为空', validatorBarCodeRequired: '产品条码不能为空', validatorCategoryRequired: '产品分类编号不能为空', + validatorCategoryTypeRequired: '类型不能为空', validatorUnitRequired: '单位编号不能为空', validatorStatusRequired: '产品状态不能为空' }, diff --git a/src/views/erp/product/product/ProductForm.vue b/src/views/erp/product/product/ProductForm.vue index 545033a5..f397106c 100644 --- a/src/views/erp/product/product/ProductForm.vue +++ b/src/views/erp/product/product/ProductForm.vue @@ -31,6 +31,19 @@ + + + + + {{ dict.label }} + + + + @@ -253,6 +266,7 @@ const formData = ref({ isCode: undefined, qrcodeUrl: undefined, templateJson: undefined, + categoryType: undefined, categoryId: undefined, unitId: undefined, status: undefined, @@ -432,6 +446,7 @@ const validateBarCode = (_rule, value, callback) => { callback() } const formRules = reactive({ + categoryType: [{ required: true, message: t('FactoryModeling.ProductInformation.validatorCategoryTypeRequired'), trigger: 'change' }], name: [{ required: true, message: t('FactoryModeling.ProductInformation.validatorNameRequired'), trigger: 'blur' }], barCode: [{ validator: validateBarCode, trigger: ['blur', 'change'] }], categoryId: [{ required: true, message: t('FactoryModeling.ProductInformation.validatorCategoryRequired'), trigger: 'blur' }], @@ -449,9 +464,12 @@ const open = async (type: string, id?: number) => { dialogTitle.value = t('action.' + type) formType.value = type resetForm() - const categoryData = await ProductCategoryApi.getProductCategorySimpleList() - categoryList.value = handleTree(categoryData, 'id', 'parentId') - unitList.value = await ProductUnitApi.getProductUnitSimpleList() + if (!id) { + const typeOptions = getIntDictOptions(DICT_TYPE.MATERIAL_CLASSIFICATION_TYPE) + if (typeOptions.length > 0) { + formData.value.categoryType = typeOptions[0].value + } + } if (id) { formLoading.value = true try { @@ -485,6 +503,9 @@ const open = async (type: string, id?: number) => { formLoading.value = false } } + const categoryData = await ProductCategoryApi.getProductCategorySimpleList(formData.value.categoryType) + categoryList.value = handleTree(categoryData, 'id', 'parentId') + unitList.value = await ProductUnitApi.getProductUnitSimpleList() } defineExpose({ open }) @@ -507,6 +528,12 @@ const handleCodeAutoChange = (value: boolean) => { formRef.value?.clearValidate('barCode') } +const handleCategoryTypeChange = async () => { + formData.value.categoryId = undefined + const categoryData = await ProductCategoryApi.getProductCategorySimpleList(formData.value.categoryType) + categoryList.value = handleTree(categoryData, 'id', 'parentId') +} + const getQrcodeRefreshUrl = () => { if (!formData.value.id || !formData.value.barCode) return '' return `/erp/product/regenerate-code?id=${formData.value.id}&code=${encodeURIComponent(String(formData.value.barCode))}` @@ -572,6 +599,7 @@ const resetForm = () => { barCode: undefined, isCode: true, qrcodeUrl: undefined, + categoryType: undefined, categoryId: undefined, unitId: undefined, status: CommonStatusEnum.ENABLE, diff --git a/src/views/erp/product/product/index.vue b/src/views/erp/product/product/index.vue index 28214408..aec2349c 100644 --- a/src/views/erp/product/product/index.vue +++ b/src/views/erp/product/product/index.vue @@ -33,8 +33,13 @@ - - + + ([]) -const parentList = ref([]) const formVisible = ref(false) const formType = ref('') @@ -161,21 +163,17 @@ const handleExport = async () => { } onMounted(async () => { - queryParams.categoryId = 2 - await getList() - const categoryData = await ProductCategoryApi.getProductCategorySimpleList() - categoryList.value = handleTree(categoryData, 'id', 'parentId') - for (let i = 0; i < categoryData.length; i++) { - if (categoryData[i].parentId === 0) { - parentList.value.push(categoryData[i]); - } + const typeOptions = getIntDictOptions(DICT_TYPE.MATERIAL_CLASSIFICATION_TYPE) + if (typeOptions.length > 0) { + activeName = String(typeOptions[0].value) + queryParams.categoryType = typeOptions[0].value } - parentList.value.sort((a, b) => a.sort - b.sort); + await getList() }) -let activeName = '2' -const handleTabClick = (tab: TabsPaneContext) => { - queryParams.categoryId = tab.paneName +let activeName = '' +const handleTabChange = (name: string) => { + queryParams.categoryType = name ? Number(name) : undefined handleQuery() }