mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 11:09:20 +08:00
forgot it
This commit is contained in:
@@ -23,6 +23,8 @@ export namespace ProductDTO {
|
||||
productCode?: string;
|
||||
/** 主图图片ID */
|
||||
mainImageId?: number;
|
||||
/** 商品规格列表(如果提供,则更新这些规格) */
|
||||
specs?: UpdateSpec[];
|
||||
}
|
||||
|
||||
/** 商品规格DTO */
|
||||
@@ -49,6 +51,8 @@ export namespace ProductDTO {
|
||||
|
||||
/** 更新商品规格参数 */
|
||||
export interface UpdateSpec {
|
||||
/** 规格ID(必填,用于确定更新哪个规格) */
|
||||
id: number;
|
||||
/** 规格名称 */
|
||||
name: string;
|
||||
/** 规格编码 */
|
||||
@@ -59,12 +63,14 @@ export namespace ProductDTO {
|
||||
|
||||
/** 商品过滤条件 */
|
||||
export interface Filters {
|
||||
/** 商品ID */
|
||||
id?: number;
|
||||
/** 商品名称(模糊查询) */
|
||||
name?: string;
|
||||
/** 商品编码(模糊查询) */
|
||||
/** 商品编码(精准查询) */
|
||||
productCode?: string;
|
||||
/** 规格编码(精准查询) */
|
||||
specCode?: string;
|
||||
/** 规格名称(模糊查询) */
|
||||
specName?: string;
|
||||
}
|
||||
|
||||
/** 商品规格过滤条件 */
|
||||
|
||||
@@ -178,7 +178,7 @@ onUnmounted(() => {
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- 错误信息 -->
|
||||
<!-- 任务详情信息(失败任务) -->
|
||||
<div
|
||||
v-if="item.status === 'failed' && item.message"
|
||||
class="flex items-center gap-2 rounded bg-red-50 p-2 dark:bg-red-950"
|
||||
@@ -198,6 +198,26 @@ onUnmounted(() => {
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<!-- 任务详情信息(成功任务) -->
|
||||
<div
|
||||
v-if="item.status === 'success' && item.message"
|
||||
class="flex items-center gap-2 rounded bg-green-50 p-2 dark:bg-green-950"
|
||||
>
|
||||
<div
|
||||
class="flex-1 overflow-hidden text-ellipsis whitespace-nowrap text-xs text-green-600 dark:text-green-400"
|
||||
>
|
||||
{{ item.message }}
|
||||
</div>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
class="h-auto p-0 text-xs"
|
||||
@click="openMessageModal(item.message)"
|
||||
>
|
||||
查看
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<!-- 任务类型 -->
|
||||
<div class="text-xs text-gray-400">
|
||||
类型: {{ item.type === 'order' ? '订单导入' : '商品导入' }}
|
||||
|
||||
@@ -22,7 +22,6 @@ import OrderFormModal from './components/OrderFormModal.vue';
|
||||
defineOptions({ name: 'OrderManagement' });
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const UploadIcon = createIconifyIcon('lucide:upload');
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
@@ -271,12 +270,6 @@ async function handleDelete(record: OrderVO.Info) {
|
||||
}
|
||||
}
|
||||
|
||||
// 处理批量导入
|
||||
function handleBatchImport() {
|
||||
// 跳转到数据导入页面
|
||||
window.open('/data-import', '_blank');
|
||||
}
|
||||
|
||||
// 处理模态框成功
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
@@ -295,10 +288,6 @@ onMounted(async () => {
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button @click="handleBatchImport">
|
||||
<UploadIcon />
|
||||
批量导入
|
||||
</Button>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加订单
|
||||
|
||||
+50
-80
@@ -3,14 +3,13 @@ import type { ProductVO } from '#/api/ecommerce/product/types';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, Card, Image, Popconfirm, Space, Tag } from 'ant-design-vue';
|
||||
import { Button, Card, Image, Popconfirm, Popover, Tag } from 'ant-design-vue';
|
||||
|
||||
defineProps<Props>();
|
||||
const emit = defineEmits<Emits>();
|
||||
// 创建图标组件
|
||||
const EditIcon = createIconifyIcon('lucide:edit');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
const SettingsIcon = createIconifyIcon('lucide:settings');
|
||||
|
||||
interface Props {
|
||||
product: ProductVO.Info;
|
||||
@@ -19,7 +18,6 @@ interface Props {
|
||||
interface Emits {
|
||||
(e: 'edit', product: ProductVO.Info): void;
|
||||
(e: 'delete', product: ProductVO.Info): void;
|
||||
(e: 'manageSpecs', product: ProductVO.Info): void;
|
||||
}
|
||||
|
||||
const handleEdit = (product: ProductVO.Info) => {
|
||||
@@ -29,10 +27,6 @@ const handleEdit = (product: ProductVO.Info) => {
|
||||
const handleDelete = (product: ProductVO.Info) => {
|
||||
emit('delete', product);
|
||||
};
|
||||
|
||||
const handleManageSpecs = (product: ProductVO.Info) => {
|
||||
emit('manageSpecs', product);
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -61,22 +55,6 @@ const handleManageSpecs = (product: ProductVO.Info) => {
|
||||
<div class="text-sm">暂无图片</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 规格数量标签 -->
|
||||
<div
|
||||
v-if="product.specs && product.specs.length > 0"
|
||||
class="absolute left-2 top-2"
|
||||
>
|
||||
<Tag color="blue" size="small"> {{ product.specs.length }} 个规格 </Tag>
|
||||
</div>
|
||||
|
||||
<!-- 如果有多个规格,显示更多标识 -->
|
||||
<div
|
||||
v-if="product.specs && product.specs.length > 3"
|
||||
class="absolute right-2 top-2"
|
||||
>
|
||||
<Tag color="orange" size="small"> +{{ product.specs.length - 3 }} </Tag>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 信息区域 -->
|
||||
@@ -97,29 +75,42 @@ const handleManageSpecs = (product: ProductVO.Info) => {
|
||||
编码: {{ product.productCode }}
|
||||
</div>
|
||||
|
||||
<!-- 规格信息预览 -->
|
||||
<div
|
||||
v-if="product.specs && product.specs.length > 0"
|
||||
class="mb-3 space-y-1"
|
||||
>
|
||||
<div
|
||||
v-for="spec in product.specs.slice(0, 2)"
|
||||
:key="spec.id"
|
||||
class="flex items-center justify-between rounded-md bg-gray-50 px-2 py-1 text-xs dark:bg-neutral-800"
|
||||
>
|
||||
<span class="font-medium text-gray-700 dark:text-gray-300">{{
|
||||
spec.name
|
||||
}}</span>
|
||||
<span class="ml-2 font-semibold text-red-500 dark:text-red-400">
|
||||
¥{{ spec.costPrice.toFixed(2) }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="product.specs.length > 2"
|
||||
class="text-xs text-gray-400 dark:text-gray-500"
|
||||
>
|
||||
还有 {{ product.specs.length - 2 }} 个规格...
|
||||
</div>
|
||||
<!-- 规格数量标签(支持悬停显示详情) -->
|
||||
<div v-if="product.specs && product.specs.length > 0" class="mb-3">
|
||||
<Popover placement="right" trigger="hover">
|
||||
<template #content>
|
||||
<div class="max-w-xs space-y-2">
|
||||
<div
|
||||
class="mb-2 text-sm font-medium text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
规格详情
|
||||
</div>
|
||||
<div
|
||||
v-for="spec in product.specs"
|
||||
:key="spec.id"
|
||||
class="flex items-center justify-between rounded-md bg-gray-50 px-3 py-2 text-xs dark:bg-neutral-800"
|
||||
>
|
||||
<div class="flex flex-col gap-1">
|
||||
<span class="font-medium text-gray-700 dark:text-gray-300">
|
||||
{{ spec.name }}
|
||||
</span>
|
||||
<span
|
||||
v-if="spec.specCode"
|
||||
class="text-gray-500 dark:text-gray-400"
|
||||
>
|
||||
编码: {{ spec.specCode }}
|
||||
</span>
|
||||
</div>
|
||||
<span class="ml-4 font-semibold text-red-500 dark:text-red-400">
|
||||
¥{{ spec.costPrice.toFixed(2) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<Tag color="blue" class="cursor-pointer">
|
||||
{{ product.specs.length }} 个规格
|
||||
</Tag>
|
||||
</Popover>
|
||||
</div>
|
||||
|
||||
<!-- 创建时间 -->
|
||||
@@ -128,44 +119,23 @@ const handleManageSpecs = (product: ProductVO.Info) => {
|
||||
</div>
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<div class="flex w-full items-center justify-between gap-1">
|
||||
<Space size="small">
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleEdit(product)"
|
||||
title="编辑"
|
||||
class="min-w-0 flex-1"
|
||||
>
|
||||
<template #icon>
|
||||
<EditIcon class="h-4 w-4" />
|
||||
</template>
|
||||
<span class="hidden sm:inline">编辑</span>
|
||||
</Button>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleManageSpecs(product)"
|
||||
title="管理规格"
|
||||
class="min-w-0 flex-1"
|
||||
>
|
||||
<template #icon>
|
||||
<SettingsIcon class="h-4 w-4" />
|
||||
</template>
|
||||
<span class="hidden sm:inline">规格</span>
|
||||
</Button>
|
||||
</Space>
|
||||
<div class="flex w-full items-center gap-2">
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleEdit(product)"
|
||||
title="编辑"
|
||||
>
|
||||
<template #icon>
|
||||
<EditIcon class="h-4 w-4" />
|
||||
</template>
|
||||
<span class="hidden sm:inline">编辑</span>
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这个商品吗?"
|
||||
@confirm="handleDelete(product)"
|
||||
>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
danger
|
||||
title="删除"
|
||||
class="flex-shrink-0"
|
||||
>
|
||||
<Button type="text" size="small" danger title="删除">
|
||||
<template #icon>
|
||||
<TrashIcon class="h-4 w-4" />
|
||||
</template>
|
||||
|
||||
+71
-22
@@ -1,12 +1,20 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ProductDTO, ProductVO } from '#/api/ecommerce/product/types';
|
||||
|
||||
import { computed, h, onUnmounted, ref, resolveComponent } from 'vue';
|
||||
import { computed, h, onUnmounted, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, Form, Input, message, Space, Table } from 'ant-design-vue';
|
||||
import {
|
||||
Button,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
message,
|
||||
Space,
|
||||
Table,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { createProductApi, updateProductApi } from '#/api/ecommerce/product';
|
||||
import { uploadImageApi } from '#/api/media/image';
|
||||
@@ -65,8 +73,8 @@ const formData = ref({
|
||||
costPrice: 0,
|
||||
});
|
||||
|
||||
// 规格数据
|
||||
const specs = ref<ProductDTO.Spec[]>([]);
|
||||
// 规格数据 - 支持创建和更新
|
||||
const specs = ref<Array<ProductDTO.Spec | ProductDTO.UpdateSpec>>([]);
|
||||
const showSpecs = ref(false);
|
||||
|
||||
// 当前显示的图片 URL(优先显示新选择的)
|
||||
@@ -118,16 +126,29 @@ function initFormData() {
|
||||
|
||||
// 如果有传入的规格信息,则自动填入
|
||||
if (
|
||||
!isEdit.value &&
|
||||
currentProductData.value &&
|
||||
'specs' in currentProductData.value &&
|
||||
currentProductData.value.specs
|
||||
) {
|
||||
specs.value = currentProductData.value.specs.map((spec) => ({
|
||||
name: (spec as ProductVO.SpecInfo).name || spec.specCode || '',
|
||||
specCode: spec.specCode || '',
|
||||
costPrice: spec.costPrice || 0,
|
||||
}));
|
||||
if (isEdit.value) {
|
||||
// 编辑模式:使用 UpdateSpec 格式,包含 id
|
||||
specs.value = currentProductData.value.specs.map(
|
||||
(spec) =>
|
||||
({
|
||||
id: (spec as ProductVO.SpecInfo).id,
|
||||
name: (spec as ProductVO.SpecInfo).name || spec.specCode || '',
|
||||
specCode: spec.specCode || '',
|
||||
costPrice: spec.costPrice || 0,
|
||||
}) as ProductDTO.UpdateSpec,
|
||||
);
|
||||
} else {
|
||||
// 创建模式:使用 Spec 格式
|
||||
specs.value = currentProductData.value.specs.map((spec) => ({
|
||||
name: (spec as ProductVO.SpecInfo).name || spec.specCode || '',
|
||||
specCode: spec.specCode || '',
|
||||
costPrice: spec.costPrice || 0,
|
||||
}));
|
||||
}
|
||||
showSpecs.value = specs.value.length > 0;
|
||||
}
|
||||
}
|
||||
@@ -173,9 +194,16 @@ async function handleSubmit() {
|
||||
name: submitData.name,
|
||||
productCode: submitData.productCode || undefined,
|
||||
mainImageId: submitData.mainImageId,
|
||||
...(specs.value.length > 0 && {
|
||||
specs: specs.value as ProductDTO.UpdateSpec[],
|
||||
}),
|
||||
};
|
||||
await updateProductApi(currentProductData.value.id, updateData);
|
||||
message.success('更新成功');
|
||||
if (specs.value.length > 0) {
|
||||
message.success('商品和规格更新成功');
|
||||
} else {
|
||||
message.success('更新成功');
|
||||
}
|
||||
} else {
|
||||
// 创建模式:统一使用创建接口,规格信息作为可选字段
|
||||
const createData: ProductDTO.Create = {
|
||||
@@ -279,11 +307,21 @@ function removeNewImage() {
|
||||
|
||||
// 添加规格
|
||||
function addSpec() {
|
||||
specs.value.push({
|
||||
name: '',
|
||||
specCode: '',
|
||||
costPrice: 0,
|
||||
});
|
||||
if (isEdit.value) {
|
||||
// 编辑模式:新增的规格暂时不包含id,服务器端会识别并创建新规格
|
||||
specs.value.push({
|
||||
name: '',
|
||||
specCode: '',
|
||||
costPrice: 0,
|
||||
} as ProductDTO.Spec);
|
||||
} else {
|
||||
// 创建模式
|
||||
specs.value.push({
|
||||
name: '',
|
||||
specCode: '',
|
||||
costPrice: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 删除规格
|
||||
@@ -298,7 +336,11 @@ const specColumns = [
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: '30%',
|
||||
customRender: ({ record }: { record: ProductDTO.Spec }) => {
|
||||
customRender: ({
|
||||
record,
|
||||
}: {
|
||||
record: ProductDTO.Spec | ProductDTO.UpdateSpec;
|
||||
}) => {
|
||||
return h(Input, {
|
||||
value: record.name,
|
||||
placeholder: '请输入规格名称',
|
||||
@@ -313,7 +355,11 @@ const specColumns = [
|
||||
dataIndex: 'specCode',
|
||||
key: 'specCode',
|
||||
width: '30%',
|
||||
customRender: ({ record }: { record: ProductDTO.Spec }) => {
|
||||
customRender: ({
|
||||
record,
|
||||
}: {
|
||||
record: ProductDTO.Spec | ProductDTO.UpdateSpec;
|
||||
}) => {
|
||||
return h(Input, {
|
||||
value: record.specCode,
|
||||
placeholder: '请输入规格编码',
|
||||
@@ -328,9 +374,12 @@ const specColumns = [
|
||||
dataIndex: 'costPrice',
|
||||
key: 'costPrice',
|
||||
width: '25%',
|
||||
customRender: ({ record }: { record: ProductDTO.Spec }) => {
|
||||
const InputNumberComponent = resolveComponent('InputNumber');
|
||||
return h(InputNumberComponent, {
|
||||
customRender: ({
|
||||
record,
|
||||
}: {
|
||||
record: ProductDTO.Spec | ProductDTO.UpdateSpec;
|
||||
}) => {
|
||||
return h(InputNumber, {
|
||||
value: record.costPrice,
|
||||
placeholder: '请输入成本价',
|
||||
min: 0,
|
||||
@@ -518,7 +567,7 @@ onUnmounted(() => {
|
||||
</Form.Item>
|
||||
|
||||
<!-- 规格管理 -->
|
||||
<Form.Item v-if="!isEdit" label="商品规格">
|
||||
<Form.Item label="商品规格">
|
||||
<div class="space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<Space>
|
||||
|
||||
@@ -11,7 +11,6 @@ import { Button, Divider, Flex, Space } from 'ant-design-vue';
|
||||
import { deleteProductApi } from '#/api/ecommerce/product';
|
||||
|
||||
import ProductFormModal from './components/ProductFormModal.vue';
|
||||
import ProductSpecModal from './components/ProductSpecModal.vue';
|
||||
import ProductGridView from './views/ProductGridView/index.vue';
|
||||
import ProductListView from './views/ProductListView/index.vue';
|
||||
|
||||
@@ -24,15 +23,15 @@ const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
// 响应式数据
|
||||
const viewMode = ref<'grid' | 'table'>('grid');
|
||||
const productFormModalRef = ref();
|
||||
const productSpecModalRef = ref();
|
||||
const productListViewRef = ref<null | { refreshTable: () => void }>(null);
|
||||
const productGridViewRef = ref<null | { refreshTable: () => void }>(null);
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
id: undefined as number | undefined,
|
||||
name: '',
|
||||
productCode: '',
|
||||
specCode: '',
|
||||
specName: '',
|
||||
});
|
||||
|
||||
// 刷新表格数据
|
||||
@@ -69,11 +68,6 @@ const handleListViewDelete = (product: ProductVO.Info) => {
|
||||
handleDelete(product);
|
||||
};
|
||||
|
||||
// 处理管理规格
|
||||
function handleManageSpecs(record: ProductVO.Info) {
|
||||
productSpecModalRef.value?.open(record);
|
||||
}
|
||||
|
||||
// 切换视图模式
|
||||
function toggleViewMode() {
|
||||
viewMode.value = viewMode.value === 'grid' ? 'table' : 'grid';
|
||||
@@ -83,12 +77,6 @@ function toggleViewMode() {
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// 处理规格模态框成功
|
||||
function handleSpecModalSuccess() {
|
||||
// 规格管理成功后可能需要刷新商品列表
|
||||
refreshTable();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -131,7 +119,6 @@ function handleSpecModalSuccess() {
|
||||
v-model:search-form="searchForm"
|
||||
@edit="handleEdit"
|
||||
@delete="handleListViewDelete"
|
||||
@manage-specs="handleManageSpecs"
|
||||
/>
|
||||
|
||||
<!-- 网格视图 -->
|
||||
@@ -141,17 +128,10 @@ function handleSpecModalSuccess() {
|
||||
v-model:search-form="searchForm"
|
||||
@edit="handleEdit"
|
||||
@delete="handleDelete"
|
||||
@manage-specs="handleManageSpecs"
|
||||
/>
|
||||
|
||||
<!-- 商品表单模态框 -->
|
||||
<ProductFormModal ref="productFormModalRef" @success="handleModalSuccess" />
|
||||
|
||||
<!-- 商品规格管理模态框 -->
|
||||
<ProductSpecModal
|
||||
ref="productSpecModalRef"
|
||||
@success="handleSpecModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
|
||||
+29
-20
@@ -13,7 +13,6 @@ import {
|
||||
Flex,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
message,
|
||||
Space,
|
||||
Spin,
|
||||
@@ -27,16 +26,16 @@ defineOptions({ name: 'ProductGridView' });
|
||||
|
||||
const props = defineProps<{
|
||||
searchForm: {
|
||||
id?: number;
|
||||
name: string;
|
||||
productCode: string;
|
||||
specCode: string;
|
||||
specName: string;
|
||||
};
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'edit', product: ProductVO.Info): void;
|
||||
(e: 'delete', product: ProductVO.Info): void;
|
||||
(e: 'manageSpecs', product: ProductVO.Info): void;
|
||||
(e: 'update:searchForm', value: typeof props.searchForm): void;
|
||||
}>();
|
||||
|
||||
@@ -51,9 +50,10 @@ const scrollContainerRef = ref<HTMLElement | null>(null);
|
||||
|
||||
// 本地搜索表单副本(用于 v-model)
|
||||
const localSearchForm = ref({
|
||||
id: props.searchForm.id,
|
||||
name: props.searchForm.name,
|
||||
productCode: props.searchForm.productCode,
|
||||
specCode: props.searchForm.specCode,
|
||||
specName: props.searchForm.specName,
|
||||
});
|
||||
|
||||
// 监听 props 变化,同步到本地
|
||||
@@ -61,13 +61,15 @@ watch(
|
||||
() => props.searchForm,
|
||||
(newForm) => {
|
||||
if (
|
||||
localSearchForm.value.id !== newForm.id ||
|
||||
localSearchForm.value.name !== newForm.name ||
|
||||
localSearchForm.value.productCode !== newForm.productCode
|
||||
localSearchForm.value.productCode !== newForm.productCode ||
|
||||
localSearchForm.value.specCode !== newForm.specCode ||
|
||||
localSearchForm.value.specName !== newForm.specName
|
||||
) {
|
||||
localSearchForm.value.id = newForm.id;
|
||||
localSearchForm.value.name = newForm.name;
|
||||
localSearchForm.value.productCode = newForm.productCode;
|
||||
localSearchForm.value.specCode = newForm.specCode;
|
||||
localSearchForm.value.specName = newForm.specName;
|
||||
// 重置分页和列表
|
||||
current.value = 1;
|
||||
productList.value = [];
|
||||
@@ -83,9 +85,10 @@ watch(
|
||||
localSearchForm,
|
||||
(newForm) => {
|
||||
if (
|
||||
props.searchForm.id !== newForm.id ||
|
||||
props.searchForm.name !== newForm.name ||
|
||||
props.searchForm.productCode !== newForm.productCode
|
||||
props.searchForm.productCode !== newForm.productCode ||
|
||||
props.searchForm.specCode !== newForm.specCode ||
|
||||
props.searchForm.specName !== newForm.specName
|
||||
) {
|
||||
emit('update:searchForm', { ...newForm });
|
||||
}
|
||||
@@ -103,9 +106,10 @@ const loadProductList = async (reset = false) => {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
id: localSearchForm.value.id,
|
||||
name: localSearchForm.value.name || undefined,
|
||||
productCode: localSearchForm.value.productCode || undefined,
|
||||
specCode: localSearchForm.value.specCode || undefined,
|
||||
specName: localSearchForm.value.specName || undefined,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -146,7 +150,8 @@ const handleReset = () => {
|
||||
localSearchForm.value = {
|
||||
name: '',
|
||||
productCode: '',
|
||||
id: undefined,
|
||||
specCode: '',
|
||||
specName: '',
|
||||
};
|
||||
handleSearch();
|
||||
};
|
||||
@@ -172,10 +177,6 @@ const handleDelete = (product: ProductVO.Info) => {
|
||||
emit('delete', product);
|
||||
};
|
||||
|
||||
const handleManageSpecs = (product: ProductVO.Info) => {
|
||||
emit('manageSpecs', product);
|
||||
};
|
||||
|
||||
// 刷新列表
|
||||
function refreshTable() {
|
||||
handleSearch();
|
||||
@@ -228,10 +229,19 @@ onUnmounted(() => {
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="商品ID" class="mb-0">
|
||||
<InputNumber
|
||||
v-model:value="localSearchForm.id"
|
||||
placeholder="请输入商品ID"
|
||||
<Form.Item label="规格编码" class="mb-0">
|
||||
<Input
|
||||
v-model:value="localSearchForm.specCode"
|
||||
placeholder="请输入规格编码"
|
||||
style="width: 150px"
|
||||
allow-clear
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="规格名称" class="mb-0">
|
||||
<Input
|
||||
v-model:value="localSearchForm.specName"
|
||||
placeholder="请输入规格名称"
|
||||
style="width: 150px"
|
||||
allow-clear
|
||||
@press-enter="handleSearch"
|
||||
@@ -291,7 +301,6 @@ onUnmounted(() => {
|
||||
:product="item"
|
||||
@edit="handleEdit"
|
||||
@delete="handleDelete"
|
||||
@manage-specs="handleManageSpecs"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
+94
-23
@@ -5,7 +5,15 @@ import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
import { Button, Image, message, Popconfirm, Space, Tag } from 'ant-design-vue';
|
||||
import {
|
||||
Button,
|
||||
Image,
|
||||
message,
|
||||
Popconfirm,
|
||||
Popover,
|
||||
Space,
|
||||
Tag,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getProductPageApi } from '#/api/ecommerce/product';
|
||||
@@ -14,16 +22,16 @@ defineOptions({ name: 'ProductListView' });
|
||||
|
||||
const props = defineProps<{
|
||||
searchForm: {
|
||||
id?: number;
|
||||
name: string;
|
||||
productCode: string;
|
||||
specCode: string;
|
||||
specName: string;
|
||||
};
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'edit', product: ProductVO.Info): void;
|
||||
(e: 'delete', product: ProductVO.Info): void;
|
||||
(e: 'manageSpecs', product: ProductVO.Info): void;
|
||||
(e: 'update:searchForm', value: typeof props.searchForm): void;
|
||||
}>();
|
||||
|
||||
@@ -32,9 +40,10 @@ const loading = ref(false);
|
||||
|
||||
// 本地搜索表单副本(用于 v-model)
|
||||
const localSearchForm = ref({
|
||||
id: props.searchForm.id,
|
||||
name: props.searchForm.name,
|
||||
productCode: props.searchForm.productCode,
|
||||
specCode: props.searchForm.specCode,
|
||||
specName: props.searchForm.specName,
|
||||
});
|
||||
|
||||
// 监听 props 变化,同步到本地
|
||||
@@ -42,13 +51,15 @@ watch(
|
||||
() => props.searchForm,
|
||||
(newForm) => {
|
||||
if (
|
||||
localSearchForm.value.id !== newForm.id ||
|
||||
localSearchForm.value.name !== newForm.name ||
|
||||
localSearchForm.value.productCode !== newForm.productCode
|
||||
localSearchForm.value.productCode !== newForm.productCode ||
|
||||
localSearchForm.value.specCode !== newForm.specCode ||
|
||||
localSearchForm.value.specName !== newForm.specName
|
||||
) {
|
||||
localSearchForm.value.id = newForm.id;
|
||||
localSearchForm.value.name = newForm.name;
|
||||
localSearchForm.value.productCode = newForm.productCode;
|
||||
localSearchForm.value.specCode = newForm.specCode;
|
||||
localSearchForm.value.specName = newForm.specName;
|
||||
refreshTable();
|
||||
}
|
||||
},
|
||||
@@ -60,9 +71,10 @@ watch(
|
||||
localSearchForm,
|
||||
(newForm) => {
|
||||
if (
|
||||
props.searchForm.id !== newForm.id ||
|
||||
props.searchForm.name !== newForm.name ||
|
||||
props.searchForm.productCode !== newForm.productCode
|
||||
props.searchForm.productCode !== newForm.productCode ||
|
||||
props.searchForm.specCode !== newForm.specCode ||
|
||||
props.searchForm.specName !== newForm.specName
|
||||
) {
|
||||
emit('update:searchForm', { ...newForm });
|
||||
}
|
||||
@@ -162,9 +174,10 @@ const gridOptions: VxeGridProps<any> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
id: localSearchForm.value.id,
|
||||
name: localSearchForm.value.name || undefined,
|
||||
productCode: localSearchForm.value.productCode || undefined,
|
||||
specCode: localSearchForm.value.specCode || undefined,
|
||||
specName: localSearchForm.value.specName || undefined,
|
||||
},
|
||||
};
|
||||
const data = await getProductPageApi(params);
|
||||
@@ -207,13 +220,20 @@ const formOptions = computed(() => ({
|
||||
label: '商品编码',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入商品ID',
|
||||
style: { width: '100%' },
|
||||
placeholder: '请输入规格编码',
|
||||
},
|
||||
fieldName: 'id',
|
||||
label: '商品ID',
|
||||
fieldName: 'specCode',
|
||||
label: '规格编码',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入规格名称',
|
||||
},
|
||||
fieldName: 'specName',
|
||||
label: '规格名称',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
@@ -245,10 +265,6 @@ const handleDelete = (product: ProductVO.Info) => {
|
||||
emit('delete', product);
|
||||
};
|
||||
|
||||
const handleManageSpecs = (product: ProductVO.Info) => {
|
||||
emit('manageSpecs', product);
|
||||
};
|
||||
|
||||
// 暴露刷新方法
|
||||
defineExpose({
|
||||
refreshTable,
|
||||
@@ -271,16 +287,71 @@ defineExpose({
|
||||
|
||||
<!-- 规格数量列 -->
|
||||
<template #specs="{ row }: { row: any }">
|
||||
<Tag :color="(row.specs?.length || 0) > 0 ? 'blue' : 'default'">
|
||||
{{ row.specs?.length || 0 }} 个规格
|
||||
</Tag>
|
||||
<!-- 有规格时显示悬停弹窗 -->
|
||||
<Popover
|
||||
v-if="row.specs && row.specs.length > 0"
|
||||
placement="right"
|
||||
trigger="hover"
|
||||
>
|
||||
<template #content>
|
||||
<div style="max-width: 300px">
|
||||
<div
|
||||
style="
|
||||
margin-bottom: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #374151;
|
||||
"
|
||||
>
|
||||
规格详情
|
||||
</div>
|
||||
<div
|
||||
v-for="spec in row.specs"
|
||||
:key="spec.id"
|
||||
style="
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 8px;
|
||||
padding: 8px 12px;
|
||||
background-color: #f9fafb;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
"
|
||||
>
|
||||
<div style="display: flex; flex-direction: column; gap: 4px">
|
||||
<span style="font-weight: 500; color: #374151">
|
||||
{{ spec.name }}
|
||||
</span>
|
||||
<span v-if="spec.specCode" style="color: #6b7280">
|
||||
编码: {{ spec.specCode }}
|
||||
</span>
|
||||
</div>
|
||||
<span
|
||||
style="
|
||||
margin-left: 16px;
|
||||
font-weight: 600;
|
||||
color: #ef4444;
|
||||
white-space: nowrap;
|
||||
"
|
||||
>
|
||||
¥{{ spec.costPrice.toFixed(2) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<Tag color="blue" style="cursor: pointer">
|
||||
{{ row.specs.length }} 个规格
|
||||
</Tag>
|
||||
</Popover>
|
||||
<!-- 无规格时显示普通标签 -->
|
||||
<Tag v-else color="default"> 0 个规格 </Tag>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
||||
<Button size="small" @click="handleManageSpecs(row)"> 规格 </Button>
|
||||
<Popconfirm title="确定要删除这个商品吗?" @confirm="handleDelete(row)">
|
||||
<Button size="small" danger> 删除 </Button>
|
||||
</Popconfirm>
|
||||
|
||||
Reference in New Issue
Block a user