diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/index.vue index 22c74c0a..06d6f590 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/index.vue @@ -9,18 +9,9 @@ import 'vue-waterfall-plugin-next/dist/style.css'; import { Page } from '@vben/common-ui'; import { createIconifyIcon } from '@vben/icons'; -import { - Button, - Card, - Empty, - Flex, - Form, - Input, - message, - Space, - Spin, -} from 'ant-design-vue'; +import { Button, Card, Empty, message, Spin } from 'ant-design-vue'; +import { useVbenForm } from '#/adapter/form'; import { deleteProductApi, getProductPageApi } from '#/api/ecommerce/product'; import ProductCard from './components/ProductCard.vue'; @@ -39,6 +30,98 @@ const searchForm = ref({ specName: '', }); +const searchFormSubmitRef = ref Promise)>(null); + +const [SearchForm, formApi] = useVbenForm({ + commonConfig: { + componentProps: { + class: 'w-full', + }, + }, + handleReset: handleSearchFormReset, + handleSubmit: handleSearchFormSubmit, + layout: 'horizontal', + schema: [ + { + component: 'Input', + componentProps: { + placeholder: '请输入商品名称(回车搜索)', + allowClear: true, + onPressEnter: () => void searchFormSubmitRef.value?.(), + }, + defaultValue: '', + fieldName: 'name', + label: '商品名称', + }, + { + component: 'Input', + componentProps: { + placeholder: '请输入商品编码(回车搜索)', + allowClear: true, + onPressEnter: () => void searchFormSubmitRef.value?.(), + }, + defaultValue: '', + fieldName: 'productCode', + label: '商品编码', + }, + { + component: 'Input', + componentProps: { + placeholder: '请输入规格编码(回车搜索)', + allowClear: true, + onPressEnter: () => void searchFormSubmitRef.value?.(), + }, + defaultValue: '', + fieldName: 'specCode', + label: '规格编码', + }, + { + component: 'Input', + componentProps: { + placeholder: '请输入规格名称(回车搜索)', + allowClear: true, + onPressEnter: () => void searchFormSubmitRef.value?.(), + }, + defaultValue: '', + fieldName: 'specName', + label: '规格名称', + }, + ], + showCollapseButton: false, + showDefaultActions: true, + submitButtonOptions: { + content: '搜索', + }, + resetButtonOptions: { + content: '重置', + }, + submitOnEnter: true, + wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3', +}); + +searchFormSubmitRef.value = () => formApi.validateAndSubmitForm(); + +async function handleSearchFormSubmit(values: Record) { + searchForm.value = { + name: String(values.name ?? '').trim(), + productCode: String(values.productCode ?? '').trim(), + specCode: String(values.specCode ?? '').trim(), + specName: String(values.specName ?? '').trim(), + }; + runSearch(); +} + +async function handleSearchFormReset() { + await formApi.resetForm(); + searchForm.value = { + name: '', + productCode: '', + specCode: '', + specName: '', + }; + runSearch(); +} + const loading = ref(false); const productList = ref([]); const total = ref(0); @@ -87,22 +170,12 @@ const loadProductList = async (reset = false) => { } }; -const handleSearch = () => { +function runSearch() { current.value = 1; productList.value = []; hasMore.value = true; loadProductList(true); -}; - -const handleReset = () => { - searchForm.value = { - name: '', - productCode: '', - specCode: '', - specName: '', - }; - handleSearch(); -}; +} const handleScroll = () => { const container = scrollContainerRef.value; @@ -170,130 +243,98 @@ onUnmounted(() => {