diff --git a/src/views/product/components/EditDialog.vue b/src/views/product/components/EditDialog.vue index fc443e9..58e292d 100644 --- a/src/views/product/components/EditDialog.vue +++ b/src/views/product/components/EditDialog.vue @@ -137,7 +137,8 @@ const okText = ref(t('button.confirm')) const rolesValue = ref([]) const roles = ref([]) const imgUrl = ref('') -const areaList = ref([]) +const categoryList = ref([]) +const targetList = ref([]) const images = ref([]) const mainImage = ref([]) const contentImage = ref([]) @@ -161,51 +162,25 @@ formRules.value = { } const areaFormRules = { categoryIDName: [{ required: true, message: '请输入产品类别' }], - // targetName: [{ required: true, message: '请输入产品适用对象' }], + targetName: [{ required: true, message: '请输入产品适用对象' }], status: [{ required: true, message: '请选择状态', trigger: 'change' }], } -const initDataBatch = async (configs) => { +const initData = async () => { try { - showSpining() - const responses = await Promise.all( - configs.map(({ apiFunc }) => apiFunc({ pageSize: 999, page: 1 })) - ) - configs.forEach(({ nameKey, resultKey }, index) => { - const { success, data } = responses[index] - - if (config('http.code.success') === success) { - const mapped = data.map(item => { - return { - value: item.value, - children: item.children, - [resultKey]: item.label,// e.g. item['label'] - } - }) - - areaList.value = [...areaList.value, ...mapped] - console.log(areaList.value) - console.log('after merge:', areaList.value) - } - }) + showSpining(); + const { success: prodSuccess, data: prodData } = await apis.products.getProductObj({ pageSize: 999, page: 1 }); + if (config('http.code.success') === prodSuccess) { + targetList.value = prodData + .filter(item => item.status === 'enabled') + .map(item => ({ code: item.id, name: item.name })); + } } catch (error) { - message.error({ content: error.message }) + message.error({ content: error.message }); } finally { - hideSpining() + hideSpining(); } } -initDataBatch([ - { - apiFunc: apis.products.getProductCategory, - nameKey: 'name', - resultKey: 'categoryIDName' - }, - // { - // apiFunc: apis.products.getProductObj, - // nameKey: 'name', - // resultKey: 'targetName' - // } -]) /** * 新建 @@ -253,11 +228,11 @@ function handleCreate() { const childHandleOk = async () => { areaFormRef.value.validateFields().then(async (values) => { try { - const params = { ...formArea.value } + const params = { ...categoryForm.value } const { success } = await apis.products.createProductCategory(params) if (success) message.success('新增成功') childOpen.value = false - formArea.value = { categoryIDName: '', status: 'enabled' } + categoryForm.value = { categoryIDName: '', status: 'enabled' } initData() } catch (error) { message.error(error.message) @@ -268,11 +243,11 @@ const childHandleOk = async () => { const childHandleObjOk = async () => { areaFormRef.value.validateFields().then(async (values) => { try { - const params = { ...formArea.value } + const params = { ...targetForm.value } const { success } = await apis.products.createProductObj(params) if (success) message.success('新增成功') childOpen.value = false - formArea.value = { targetName: '', status: 'enabled' } + targetForm.value = { targetName: '', status: 'enabled' } initData() } catch (error) { message.error(error.message) diff --git a/src/views/product/index.vue b/src/views/product/index.vue index 44b1f38..618f23c 100644 --- a/src/views/product/index.vue +++ b/src/views/product/index.vue @@ -60,17 +60,21 @@
{{ record.categoryID }}
- - + + @@ -121,9 +125,10 @@ const { t } = useI18n() // 解构出t方法 const columns = [ { title: '产品名称', dataIndex: 'code', width: 120 }, { title: '产品类别名称', dataIndex: 'title', width: 120 }, - { title: '产品类别', dataIndex: 'categoryID', key: 'categoryID', width: 120 }, - { title: '原料组成', dataIndex: 'compose', key: 'compose', width: 120 }, + { title: '产品类别ID', dataIndex: 'categoryID', key: 'categoryID', width: 120 }, { title: '适用对象', dataIndex: 'target', width: 120 }, + { title: '产品适用类别ID', dataIndex: 'CategoryRootID', key: 'CategoryRootID', width: 120 }, + { title: '原料组成', dataIndex: 'compose', key: 'compose', width: 120 }, { title: '功能特点', dataIndex: 'feature',