diff --git a/apps/web-ele/src/views/mall/product/comment/data.ts b/apps/web-ele/src/views/mall/product/comment/data.ts index 7a3641ef2..e3f895801 100644 --- a/apps/web-ele/src/views/mall/product/comment/data.ts +++ b/apps/web-ele/src/views/mall/product/comment/data.ts @@ -3,7 +3,6 @@ import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { MallCommentApi } from '#/api/mall/product/comment'; import { z } from '#/adapter/form'; -import { getSpuSimpleList } from '#/api/mall/product/spu'; import { getRangePickerDefaultProps } from '#/utils'; /** 新增/修改的表单 */ @@ -17,19 +16,28 @@ export function useFormSchema(): VbenFormSchema[] { show: () => false, }, }, - // TODO @puhui999:商品的选择 { fieldName: 'spuId', label: '商品', - component: 'ApiSelect', + component: 'Input', componentProps: { - api: getSpuSimpleList, - labelField: 'name', - valueField: 'id', placeholder: '请选择商品', }, rules: 'required', }, + { + fieldName: 'skuId', + label: '商品规格', + component: 'Input', + componentProps: { + placeholder: '请选择商品规格', + }, + dependencies: { + triggerFields: ['spuId'], + show: (values) => !!values.spuId, + }, + rules: 'required', + }, { fieldName: 'userAvatar', label: '用户头像', @@ -88,7 +96,7 @@ export function useGridFormSchema(): VbenFormSchema[] { { fieldName: 'replyStatus', label: '回复状态', - component: 'Select', + component: 'RadioGroup', componentProps: { options: [ { label: '已回复', value: true }, diff --git a/apps/web-ele/src/views/mall/product/comment/index.vue b/apps/web-ele/src/views/mall/product/comment/index.vue index 373dbe7c0..3c39a767c 100644 --- a/apps/web-ele/src/views/mall/product/comment/index.vue +++ b/apps/web-ele/src/views/mall/product/comment/index.vue @@ -2,8 +2,6 @@ import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { MallCommentApi } from '#/api/mall/product/comment'; -import { h } from 'vue'; - import { confirm, DocAlert, Page, prompt, useVbenModal } from '@vben/common-ui'; import { ElInput, ElMessage, ElRate } from 'element-plus'; @@ -37,17 +35,17 @@ function handleCreate() { /** 回复评价 */ function handleReply(row: MallCommentApi.Comment) { prompt({ - component: () => { - return h(ElInput, { - type: 'textarea', - placeholder: '请输入回复内容', - }); + component: ElInput, + componentProps: { + type: 'textarea', + placeholder: '请输入回复内容', + rows: 4, }, content: row.content ? `用户评论:${row.content}\n请输入回复内容:` : '请输入回复内容:', title: '回复评论', - modelPropName: 'value', + modelPropName: 'modelValue', }).then(async (val) => { if (val) { await replyComment({ @@ -127,10 +125,10 @@ const [Grid, gridApi] = useVbenVxeGrid({ - + - + import type { MallCommentApi } from '#/api/mall/product/comment'; +import type { MallSpuApi } from '#/api/mall/product/spu'; import { computed, ref } from 'vue'; import { useVbenModal } from '@vben/common-ui'; -import { ElMessage } from 'element-plus'; +import { ElButton, ElMessage } from 'element-plus'; import { useVbenForm } from '#/adapter/form'; import { createComment, getComment } from '#/api/mall/product/comment'; +import { getSpu } from '#/api/mall/product/spu'; import { $t } from '#/locales'; +import { + SkuTableSelect, + SpuShowcase, +} from '#/views/mall/product/spu/components'; import { useFormSchema } from '../data'; const emit = defineEmits(['success']); -// TODO @puhui999:这里和 yudao-ui-admin-vben-v5/apps/web-antd/src/views/mall/product/comment/modules/form.vue 存在差异,是不是还没迁移到呀。 -const formData = ref(); +const formData = ref>({ + descriptionScores: 5, + benefitScores: 5, +}); const getTitle = computed(() => { return formData.value?.id ? $t('ui.actionTitle.edit', ['虚拟评论']) @@ -36,6 +44,40 @@ const [Form, formApi] = useVbenForm({ showDefaultActions: false, }); +const skuTableSelectRef = ref>(); +const selectedSku = ref(); + +/** 处理商品的选择变化 */ +async function handleSpuChange(spu?: MallSpuApi.Spu | null) { + // 处理商品选择:如果 spu 为 null 或 id 为 0,表示清空选择 + const spuId = spu?.id && spu.id ? spu.id : undefined; + formData.value.spuId = spuId; + await formApi.setFieldValue('spuId', spuId); + // 清空已选规格 + selectedSku.value = undefined; + formData.value.skuId = undefined; + await formApi.setFieldValue('skuId', undefined); +} + +/** 打开商品规格的选择弹框 */ +async function openSkuSelect() { + const currentValues = + (await formApi.getValues()) as Partial; + const currentSpuId = currentValues.spuId ?? formData.value?.spuId; + if (!currentSpuId) { + ElMessage.warning('请先选择商品'); + return; + } + skuTableSelectRef.value?.open({ spuId: currentSpuId }); +} + +/** 处理商品规格的选择 */ +async function handleSkuSelected(sku: MallSpuApi.Sku) { + selectedSku.value = sku; + formData.value.skuId = sku.id; + await formApi.setFieldValue('skuId', sku.id); +} + const [Modal, modalApi] = useVbenModal({ async onConfirm() { const { valid } = await formApi.validate(); @@ -57,7 +99,9 @@ const [Modal, modalApi] = useVbenModal({ }, async onOpenChange(isOpen: boolean) { if (!isOpen) { - formData.value = undefined; + // 关闭时重置表单状态 + selectedSku.value = undefined; + await formApi.setValues({ spuId: undefined, skuId: undefined }); return; } // 加载数据 @@ -65,11 +109,22 @@ const [Modal, modalApi] = useVbenModal({ if (!data || !data.id) { return; } + // 编辑模式:加载数据 modalApi.lock(); try { formData.value = await getComment(data.id); // 设置到 values await formApi.setValues(formData.value); + // 回显已选的商品规格 + if (formData.value?.spuId && formData.value?.skuId) { + const spu = await getSpu(formData.value.spuId); + const sku = spu.skus?.find((item) => item.id === formData.value!.skuId); + if (sku) { + selectedSku.value = sku; + } + } else { + selectedSku.value = undefined; + } } finally { modalApi.unlock(); } @@ -79,6 +134,37 @@ const [Modal, modalApi] = useVbenModal({ - + + + + + + + + 选择规格 + + + 已选: + {{ selectedSku.properties.map((p: any) => p.valueName).join('/') }} + + 已选:{{ selectedSku.id }} + + + +