mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 06:29:20 +08:00
小修小补
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
<template>
|
||||
<div class="p-6">
|
||||
<VbenCard title="数据分析">
|
||||
<Card title="数据分析" class="mb-6">
|
||||
<div class="text-center py-12">
|
||||
<VbenIcon icon="lucide:bar-chart-3" class="w-16 h-16 mx-auto text-gray-400 mb-4" />
|
||||
<BarChartIcon class="w-16 h-16 mx-auto text-gray-400 mb-4" />
|
||||
<h3 class="text-lg font-medium text-gray-700 mb-2">数据分析功能</h3>
|
||||
<p class="text-gray-500">此功能正在开发中,敬请期待...</p>
|
||||
</div>
|
||||
</VbenCard>
|
||||
</Card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
// 数据分析页面占位
|
||||
import { Card } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
// 创建图标组件
|
||||
const BarChartIcon = createIconifyIcon('lucide:bar-chart-3');
|
||||
|
||||
defineOptions({ name: 'DataAnalysis' });
|
||||
</script>
|
||||
|
||||
+10
-6
@@ -3,7 +3,7 @@
|
||||
<!-- 字段映射说明 -->
|
||||
<div class="bg-blue-50 border border-blue-200 rounded-lg p-4">
|
||||
<div class="flex items-start space-x-2">
|
||||
<VbenIcon icon="lucide:info" class="w-5 h-5 text-blue-500 mt-0.5" />
|
||||
<InfoIcon class="w-5 h-5 text-blue-500 mt-0.5" />
|
||||
<div>
|
||||
<p class="font-medium text-blue-800">字段映射说明</p>
|
||||
<p class="text-sm text-blue-600 mt-1">
|
||||
@@ -40,21 +40,25 @@
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<div class="flex justify-end space-x-3 pt-4 border-t">
|
||||
<VbenButton @click="$emit('cancel')">
|
||||
<Button @click="$emit('cancel')">
|
||||
取消
|
||||
</VbenButton>
|
||||
<VbenButton @click="handleExport" type="primary">
|
||||
</Button>
|
||||
<Button @click="handleExport" type="primary">
|
||||
导出JSON
|
||||
</VbenButton>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, h } from 'vue'
|
||||
import { message, Table } from 'ant-design-vue'
|
||||
import { message, Table, Button } from 'ant-design-vue'
|
||||
import { createIconifyIcon } from '@vben/icons'
|
||||
import { transformDataWithMapping, generateExportData, downloadJSON } from '#/utils/csv-utils'
|
||||
|
||||
// 创建图标组件
|
||||
const InfoIcon = createIconifyIcon('lucide:info')
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
csvHeaders: string[]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="p-6">
|
||||
<VbenCard title="电商数据导入" class="mb-6">
|
||||
<Card title="电商数据导入" class="mb-6">
|
||||
<div class="space-y-6">
|
||||
<!-- 文件拖拽上传区域 -->
|
||||
<div
|
||||
@@ -11,14 +11,14 @@
|
||||
@drop.prevent="handleDrop"
|
||||
>
|
||||
<div class="space-y-4">
|
||||
<VbenIcon icon="lucide:upload" class="w-12 h-12 mx-auto text-gray-400" />
|
||||
<UploadIcon class="w-12 h-12 mx-auto text-gray-400" />
|
||||
<div>
|
||||
<p class="text-lg font-medium text-gray-700">拖拽CSV文件到此处或点击上传</p>
|
||||
<p class="text-sm text-gray-500">支持.csv格式,最大10MB</p>
|
||||
</div>
|
||||
<VbenButton @click="triggerFileInput" type="primary" ghost>
|
||||
<Button @click="triggerFileInput" type="primary" ghost>
|
||||
选择文件
|
||||
</VbenButton>
|
||||
</Button>
|
||||
</div>
|
||||
<input
|
||||
ref="fileInputRef"
|
||||
@@ -33,19 +33,19 @@
|
||||
<div v-if="uploadedFile" class="bg-green-50 border border-green-200 rounded-lg p-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center space-x-2">
|
||||
<VbenIcon icon="lucide:check-circle" class="w-5 h-5 text-green-500" />
|
||||
<CheckCircleIcon class="w-5 h-5 text-green-500" />
|
||||
<span class="font-medium text-green-800">文件上传成功</span>
|
||||
</div>
|
||||
<VbenButton @click="clearData" size="small" type="text" danger>
|
||||
<Button @click="clearData" size="small" type="text" danger>
|
||||
清除数据
|
||||
</VbenButton>
|
||||
</Button>
|
||||
</div>
|
||||
<p class="text-sm text-green-600 mt-1">{{ uploadedFile.name }} ({{ formatFileSize(uploadedFile.size) }})</p>
|
||||
</div>
|
||||
|
||||
<!-- 实体匹配结果 -->
|
||||
<div v-if="matchingResult" class="space-y-4">
|
||||
<VbenCard title="实体匹配结果">
|
||||
<Card title="实体匹配结果">
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-4">
|
||||
<div class="bg-green-50 border border-green-200 rounded-lg p-4">
|
||||
<div class="text-green-800 font-medium">匹配成功</div>
|
||||
@@ -67,24 +67,24 @@
|
||||
</div>
|
||||
|
||||
<div class="flex items-center space-x-2">
|
||||
<VbenButton
|
||||
<Button
|
||||
@click="performImport"
|
||||
type="primary"
|
||||
:loading="importLoading"
|
||||
:disabled="matchingResult.matchedOrders.length === 0"
|
||||
>
|
||||
开始导入 ({{ matchingResult.matchedOrders.length }})
|
||||
</VbenButton>
|
||||
<VbenButton @click="performEntityMatching" size="small">
|
||||
</Button>
|
||||
<Button @click="performEntityMatching" size="small">
|
||||
重新匹配
|
||||
</VbenButton>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<!-- 导入进度 -->
|
||||
<div v-if="importLoading" class="mt-4">
|
||||
<Progress :percent="importProgress" />
|
||||
</div>
|
||||
</VbenCard>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
@@ -97,15 +97,15 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center space-x-2">
|
||||
<VbenButton @click="selectAll" size="small">
|
||||
<Button @click="selectAll" size="small">
|
||||
全选
|
||||
</VbenButton>
|
||||
<VbenButton @click="clearSelection" size="small">
|
||||
</Button>
|
||||
<Button @click="clearSelection" size="small">
|
||||
清空选择
|
||||
</VbenButton>
|
||||
<VbenButton @click="showFieldMapping = true" type="primary" :disabled="selectedRows.length === 0">
|
||||
</Button>
|
||||
<Button @click="showFieldMapping = true" type="primary" :disabled="selectedRows.length === 0">
|
||||
配置字段映射 ({{ selectedRows.length }})
|
||||
</VbenButton>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -115,20 +115,20 @@
|
||||
@checkbox-all="handleCheckboxAll"
|
||||
>
|
||||
<template #action="{ row }">
|
||||
<VbenButton size="small" @click="handleEditRow(row)">
|
||||
<Button size="small" @click="handleEditRow(row)">
|
||||
编辑
|
||||
</VbenButton>
|
||||
<VbenButton size="small" type="primary" @click="handleMatchRow(row)">
|
||||
</Button>
|
||||
<Button size="small" type="primary" @click="handleMatchRow(row)">
|
||||
匹配
|
||||
</VbenButton>
|
||||
</Button>
|
||||
</template>
|
||||
</Grid>
|
||||
</div>
|
||||
</div>
|
||||
</VbenCard>
|
||||
</Card>
|
||||
|
||||
<!-- 字段映射弹窗 -->
|
||||
<VbenModal
|
||||
<Modal
|
||||
v-model:open="showFieldMapping"
|
||||
title="字段映射配置"
|
||||
width="1000px"
|
||||
@@ -140,7 +140,7 @@
|
||||
@confirm="handleFieldMapping"
|
||||
@cancel="showFieldMapping = false"
|
||||
/>
|
||||
</VbenModal>
|
||||
</Modal>
|
||||
|
||||
<!-- 实体创建模态框 -->
|
||||
<EntityCreationModal
|
||||
@@ -155,7 +155,8 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { message, Progress } from 'ant-design-vue'
|
||||
import { message, Progress, Card, Button, Modal } from 'ant-design-vue'
|
||||
import { createIconifyIcon } from '@vben/icons'
|
||||
import FieldMapping from '#/views/ecommerce/data-import/components/FieldMapping.vue'
|
||||
import EntityCreationModal from './components/EntityCreationModal.vue'
|
||||
import { EntityMatchingService, type EntityMatchingResult } from './services/EntityMatchingService'
|
||||
@@ -164,6 +165,10 @@ import { parseOrderCSV, extractShopNameFromFilename, convertToCSVOrderData } fro
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table'
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table'
|
||||
|
||||
// 创建图标组件
|
||||
const UploadIcon = createIconifyIcon('lucide:upload')
|
||||
const CheckCircleIcon = createIconifyIcon('lucide:check-circle')
|
||||
|
||||
// 响应式数据
|
||||
const uploadedFile = ref<File | null>(null)
|
||||
const csvData = ref<any[]>([])
|
||||
|
||||
+3
-3
@@ -8,9 +8,9 @@ import {
|
||||
getProductsByNamesApi,
|
||||
getProductSpecsByProductAndSpecsApi,
|
||||
type ShopVO,
|
||||
type ProductVO,
|
||||
type OrderDTO
|
||||
} from '#/api/ecommerce';
|
||||
type ProductVO
|
||||
} from '#/api/shop';
|
||||
import { type OrderDTO } from '#/api/ecommerce';
|
||||
|
||||
export interface EntityMatchingResult {
|
||||
/** 匹配成功的订单数据 */
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
<script lang="ts" setup>
|
||||
import { Card, Image, Tag, Button, Space, Popconfirm, Tooltip } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import type { ProductVO } from '#/api/ecommerce';
|
||||
import type { ProductVO } from '#/api/shop';
|
||||
|
||||
// 创建图标组件
|
||||
const EditIcon = createIconifyIcon('lucide:edit');
|
||||
|
||||
+1
-1
@@ -152,7 +152,7 @@ import {
|
||||
createProductWithSpecsApi,
|
||||
type ProductVO,
|
||||
type ProductDTO
|
||||
} from '#/api/ecommerce';
|
||||
} from '#/api/shop';
|
||||
import { uploadImageApi } from '#/api/media';
|
||||
|
||||
interface Emits {
|
||||
|
||||
+1
-1
@@ -97,7 +97,7 @@ import {
|
||||
deleteProductSpecApi,
|
||||
type ProductVO,
|
||||
type ProductDTO
|
||||
} from '#/api/ecommerce';
|
||||
} from '#/api/shop';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
interface Emits {
|
||||
|
||||
@@ -168,7 +168,7 @@ import {
|
||||
getProductPageApi,
|
||||
type ProductVO,
|
||||
type ProductDTO
|
||||
} from '#/api/ecommerce';
|
||||
} from '#/api/shop';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import ProductFormModal from './components/ProductFormModal.vue';
|
||||
// @ts-ignore
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ import {
|
||||
updateShopApi,
|
||||
type ShopVO,
|
||||
type ShopDTO
|
||||
} from '#/api/ecommerce';
|
||||
} from '#/api/shop';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
updateShopApi,
|
||||
type ShopVO ,
|
||||
type ShopDTO
|
||||
} from '#/api/ecommerce';
|
||||
} from '#/api/shop';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import ShopFormModal from './components/ShopFormModal.vue';
|
||||
|
||||
|
||||
+299
@@ -0,0 +1,299 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
import { Modal, Form, Input, Select, InputNumber, DatePicker, message } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import {
|
||||
createOrderApi,
|
||||
updateOrderApi,
|
||||
getActiveOrderStatusListApi,
|
||||
type OrderDTO,
|
||||
type OrderVO,
|
||||
type OrderStatusVO
|
||||
} from '#/api/ecommerce';
|
||||
import { getShopPageApi, type ShopVO } from '#/api/shop';
|
||||
|
||||
defineProps<{
|
||||
visible?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
success: [];
|
||||
cancel: [];
|
||||
}>();
|
||||
|
||||
// 响应式数据
|
||||
const visible = ref(false);
|
||||
const loading = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentRecord = ref<OrderVO.OrderInfoVO | null>(null);
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<Partial<OrderDTO.CreateOrderDTO>>({
|
||||
shopId: undefined,
|
||||
platformOrderNo: '',
|
||||
statusId: undefined,
|
||||
receivedAmount: 0,
|
||||
shippingFee: 0,
|
||||
orderDate: dayjs().format('YYYY-MM-DD'),
|
||||
productId: undefined,
|
||||
productSpecId: undefined,
|
||||
quantity: 1,
|
||||
});
|
||||
|
||||
// 下拉选项数据
|
||||
const shopOptions = ref<{ label: string; value: number }[]>([]);
|
||||
const orderStatusOptions = ref<{ label: string; value: number }[]>([]);
|
||||
|
||||
// 表单验证规则
|
||||
const rules = {
|
||||
shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }],
|
||||
receivedAmount: [{ required: true, message: '请输入实收金额', trigger: 'blur' }],
|
||||
orderDate: [{ required: true, message: '请选择下单时间', trigger: 'change' }],
|
||||
productId: [{ required: true, message: '请输入商品ID', trigger: 'blur' }],
|
||||
productSpecId: [{ required: true, message: '请输入商品规格ID', trigger: 'blur' }],
|
||||
quantity: [{ required: true, message: '请输入数量', trigger: 'blur' }],
|
||||
};
|
||||
|
||||
// 表单引用
|
||||
const formRef = ref();
|
||||
|
||||
// 获取店铺选项
|
||||
async function fetchShopOptions() {
|
||||
try {
|
||||
const params: any = {
|
||||
page: 1,
|
||||
pageSize: 1000,
|
||||
filters: {},
|
||||
};
|
||||
const data = await getShopPageApi(params);
|
||||
shopOptions.value = data.records.map((shop: ShopVO.ShopInfoVO) => ({
|
||||
label: shop.name,
|
||||
value: shop.id,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取订单状态选项
|
||||
async function fetchOrderStatusOptions() {
|
||||
try {
|
||||
const data = await getActiveOrderStatusListApi();
|
||||
orderStatusOptions.value = data.map((status: OrderStatusVO.OrderStatusInfoVO) => ({
|
||||
label: status.name,
|
||||
value: status.id,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('获取订单状态列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 打开模态框
|
||||
function open(edit: boolean, record?: OrderVO.OrderInfoVO) {
|
||||
isEdit.value = edit;
|
||||
currentRecord.value = record || null;
|
||||
visible.value = true;
|
||||
|
||||
if (edit && record) {
|
||||
// 编辑模式,填充表单数据
|
||||
formData.value = {
|
||||
shopId: record.shopId,
|
||||
platformOrderNo: record.platformOrderNo || '',
|
||||
statusId: record.statusId,
|
||||
receivedAmount: record.receivedAmount,
|
||||
shippingFee: record.shippingFee || 0,
|
||||
orderDate: record.orderDate ? dayjs(record.orderDate).format('YYYY-MM-DD') : dayjs().format('YYYY-MM-DD'),
|
||||
productId: record.orderItem?.productId,
|
||||
productSpecId: record.orderItem?.productSpecId,
|
||||
quantity: record.orderItem?.quantity || 1,
|
||||
};
|
||||
} else {
|
||||
// 新增模式,重置表单
|
||||
formData.value = {
|
||||
shopId: undefined,
|
||||
platformOrderNo: '',
|
||||
statusId: undefined,
|
||||
receivedAmount: 0,
|
||||
shippingFee: 0,
|
||||
orderDate: dayjs().format('YYYY-MM-DD'),
|
||||
productId: undefined,
|
||||
productSpecId: undefined,
|
||||
quantity: 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭模态框
|
||||
function close() {
|
||||
visible.value = false;
|
||||
formRef.value?.resetFields();
|
||||
emit('cancel');
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
if (isEdit.value && currentRecord.value) {
|
||||
// 更新订单
|
||||
const updateData: OrderDTO.UpdateOrderDTO = {
|
||||
shopId: formData.value.shopId!,
|
||||
platformOrderNo: formData.value.platformOrderNo,
|
||||
statusId: formData.value.statusId,
|
||||
receivedAmount: formData.value.receivedAmount!,
|
||||
shippingFee: formData.value.shippingFee,
|
||||
orderDate: formData.value.orderDate!,
|
||||
};
|
||||
await updateOrderApi(currentRecord.value.id, updateData);
|
||||
message.success('更新订单成功');
|
||||
} else {
|
||||
// 创建订单
|
||||
const createData: OrderDTO.CreateOrderDTO = {
|
||||
shopId: formData.value.shopId!,
|
||||
platformOrderNo: formData.value.platformOrderNo,
|
||||
statusId: formData.value.statusId!,
|
||||
receivedAmount: formData.value.receivedAmount!,
|
||||
shippingFee: formData.value.shippingFee,
|
||||
orderDate: formData.value.orderDate!,
|
||||
productId: formData.value.productId!,
|
||||
productSpecId: formData.value.productSpecId!,
|
||||
quantity: formData.value.quantity!,
|
||||
};
|
||||
await createOrderApi(createData);
|
||||
message.success('创建订单成功');
|
||||
}
|
||||
|
||||
close();
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('提交订单失败:', error);
|
||||
message.error('提交订单失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 监听visible变化
|
||||
watch(visible, (newVal) => {
|
||||
if (newVal) {
|
||||
fetchShopOptions();
|
||||
fetchOrderStatusOptions();
|
||||
}
|
||||
});
|
||||
|
||||
// 暴露方法
|
||||
defineExpose({
|
||||
open,
|
||||
close,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="visible"
|
||||
:title="isEdit ? '编辑订单' : '添加订单'"
|
||||
:confirm-loading="loading"
|
||||
width="600px"
|
||||
@ok="handleSubmit"
|
||||
@cancel="close"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="rules as any"
|
||||
layout="vertical"
|
||||
>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<Form.Item label="店铺" name="shopId">
|
||||
<Select
|
||||
v-model:value="formData.shopId"
|
||||
placeholder="请选择店铺"
|
||||
:options="shopOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="订单状态" name="statusId">
|
||||
<Select
|
||||
v-model:value="formData.statusId"
|
||||
placeholder="请选择订单状态"
|
||||
:options="orderStatusOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<Form.Item label="平台订单号" name="platformOrderNo">
|
||||
<Input
|
||||
v-model:value="formData.platformOrderNo"
|
||||
placeholder="请输入平台订单号(可选)"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="下单时间" name="orderDate">
|
||||
<DatePicker
|
||||
v-model:value="formData.orderDate"
|
||||
placeholder="请选择下单时间"
|
||||
style="width: 100%"
|
||||
format="YYYY-MM-DD"
|
||||
value-format="YYYY-MM-DD"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<Form.Item label="商品ID" name="productId">
|
||||
<InputNumber
|
||||
v-model:value="formData.productId"
|
||||
placeholder="请输入商品ID"
|
||||
style="width: 100%"
|
||||
:min="1"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="商品规格ID" name="productSpecId">
|
||||
<InputNumber
|
||||
v-model:value="formData.productSpecId"
|
||||
placeholder="请输入商品规格ID"
|
||||
style="width: 100%"
|
||||
:min="1"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-3 gap-4">
|
||||
<Form.Item label="数量" name="quantity">
|
||||
<InputNumber
|
||||
v-model:value="formData.quantity"
|
||||
placeholder="请输入数量"
|
||||
style="width: 100%"
|
||||
:min="1"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="实收金额" name="receivedAmount">
|
||||
<InputNumber
|
||||
v-model:value="formData.receivedAmount"
|
||||
placeholder="请输入实收金额"
|
||||
style="width: 100%"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="运费" name="shippingFee">
|
||||
<InputNumber
|
||||
v-model:value="formData.shippingFee"
|
||||
placeholder="请输入运费"
|
||||
style="width: 100%"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,359 @@
|
||||
<script lang="ts" setup>
|
||||
import { h, ref, onMounted } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, Input, Select, Table, message, Form, Space, Tag } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
deleteOrderApi,
|
||||
getOrderPageApi,
|
||||
getActiveOrderStatusListApi,
|
||||
type OrderVO,
|
||||
type OrderDTO,
|
||||
type OrderStatusVO
|
||||
} from '#/api/ecommerce';
|
||||
import { getShopPageApi, type ShopVO } from '#/api/shop';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import OrderFormModal from './components/OrderFormModal.vue';
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const UploadIcon = createIconifyIcon('lucide:upload');
|
||||
|
||||
defineOptions({ name: 'OrderManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const orderList = ref<OrderVO.OrderInfoVO[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(10);
|
||||
const orderFormModalRef = ref();
|
||||
|
||||
// 下拉选项数据
|
||||
const shopOptions = ref<{ label: string; value: number }[]>([]);
|
||||
const orderStatusOptions = ref<{ label: string; value: number }[]>([]);
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
platformOrderNo: '',
|
||||
productName: '',
|
||||
shopId: undefined as number | undefined,
|
||||
statusId: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '平台订单号',
|
||||
dataIndex: 'platformOrderNo',
|
||||
key: 'platformOrderNo',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '店铺名称',
|
||||
dataIndex: 'shopName',
|
||||
key: 'shopName',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
title: '商品信息',
|
||||
key: 'productInfo',
|
||||
width: 200,
|
||||
customRender: ({ record }: { record: OrderVO.OrderInfoVO }) => {
|
||||
if (record.orderItem) {
|
||||
return h('div', [
|
||||
h('div', { style: { fontWeight: 'bold' } }, record.orderItem.productName),
|
||||
h('div', { style: { color: '#666', fontSize: '12px' } }, record.orderItem.specName),
|
||||
]);
|
||||
}
|
||||
return h('span', { style: { color: '#999' } }, '暂无商品信息');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '数量',
|
||||
key: 'quantity',
|
||||
width: 80,
|
||||
customRender: ({ record }: { record: OrderVO.OrderInfoVO }) => {
|
||||
return record.orderItem?.quantity || 0;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '实收金额',
|
||||
dataIndex: 'receivedAmount',
|
||||
key: 'receivedAmount',
|
||||
width: 120,
|
||||
customRender: ({ record }: { record: OrderVO.OrderInfoVO }) => {
|
||||
const amount = record.receivedAmount || 0;
|
||||
return h('span', { style: { color: '#52c41a', fontWeight: 'bold' } }, `¥${amount.toFixed(2)}`);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '运费',
|
||||
dataIndex: 'shippingFee',
|
||||
key: 'shippingFee',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: OrderVO.OrderInfoVO }) => {
|
||||
const fee = record.shippingFee || 0;
|
||||
return h('span', { style: { color: '#666' } }, `¥${fee.toFixed(2)}`);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '订单状态',
|
||||
dataIndex: 'statusId',
|
||||
key: 'statusId',
|
||||
width: 120,
|
||||
customRender: ({ record }: { record: OrderVO.OrderInfoVO }) => {
|
||||
const status = orderStatusOptions.value.find(s => s.value === record.statusId);
|
||||
return h(Tag, { color: 'blue' }, () => status?.label || record.statusName || '未知状态');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '下单时间',
|
||||
dataIndex: 'orderDate',
|
||||
key: 'orderDate',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: OrderVO.OrderInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, { default: () => '编辑' }),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDelete(record),
|
||||
}, { default: () => '删除' }),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 获取订单列表
|
||||
async function fetchOrderList() {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<OrderDTO.OrderFilterDTO> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
orderNumber: searchForm.value.platformOrderNo || undefined,
|
||||
productName: searchForm.value.productName || undefined,
|
||||
shopId: searchForm.value.shopId,
|
||||
orderStatusId: searchForm.value.statusId,
|
||||
},
|
||||
};
|
||||
const data = await getOrderPageApi(params);
|
||||
orderList.value = data.records;
|
||||
total.value = data.total;
|
||||
} catch (error) {
|
||||
console.error('获取订单列表失败:', error);
|
||||
message.error('获取订单列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取店铺选项
|
||||
async function fetchShopOptions() {
|
||||
try {
|
||||
const params: PageQueryDTO<any> = {
|
||||
page: 1,
|
||||
pageSize: 1000, // 获取所有店铺
|
||||
filters: {},
|
||||
};
|
||||
const data = await getShopPageApi(params);
|
||||
shopOptions.value = data.records.map((shop: ShopVO.ShopInfoVO) => ({
|
||||
label: shop.name,
|
||||
value: shop.id,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取订单状态选项
|
||||
async function fetchOrderStatusOptions() {
|
||||
try {
|
||||
const data = await getActiveOrderStatusListApi();
|
||||
orderStatusOptions.value = data.map((status: OrderStatusVO.OrderStatusInfoVO) => ({
|
||||
label: status.name,
|
||||
value: status.id,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('获取订单状态列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
function handleSearch() {
|
||||
current.value = 1;
|
||||
fetchOrderList();
|
||||
}
|
||||
|
||||
// 处理重置
|
||||
function handleReset() {
|
||||
searchForm.value = {
|
||||
platformOrderNo: '',
|
||||
productName: '',
|
||||
shopId: undefined,
|
||||
statusId: undefined,
|
||||
};
|
||||
current.value = 1;
|
||||
fetchOrderList();
|
||||
}
|
||||
|
||||
// 处理分页变化
|
||||
function handleTableChange(pagination: any) {
|
||||
current.value = pagination.current;
|
||||
pageSize.value = pagination.pageSize;
|
||||
fetchOrderList();
|
||||
}
|
||||
|
||||
// 处理添加订单
|
||||
function handleAdd() {
|
||||
orderFormModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑订单
|
||||
function handleEdit(record: OrderVO.OrderInfoVO) {
|
||||
orderFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除订单
|
||||
async function handleDelete(record: OrderVO.OrderInfoVO) {
|
||||
try {
|
||||
await deleteOrderApi(record.id);
|
||||
message.success('删除成功');
|
||||
await fetchOrderList();
|
||||
} catch (error) {
|
||||
console.error('删除订单失败:', error);
|
||||
message.error('删除订单失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理批量导入
|
||||
function handleBatchImport() {
|
||||
// 跳转到数据导入页面
|
||||
window.open('/data-import', '_blank');
|
||||
}
|
||||
|
||||
// 处理模态框成功
|
||||
function handleModalSuccess() {
|
||||
fetchOrderList();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
onMounted(async () => {
|
||||
await Promise.all([
|
||||
fetchOrderList(),
|
||||
fetchShopOptions(),
|
||||
fetchOrderStatusOptions(),
|
||||
]);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="订单管理">
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理电商订单信息,包括订单创建、编辑、删除和状态管理
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Space>
|
||||
<Button @click="handleBatchImport">
|
||||
<UploadIcon class="w-4 h-4 mr-2" />
|
||||
批量导入
|
||||
</Button>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon class="w-4 h-4 mr-2" />
|
||||
添加订单
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 搜索表单 -->
|
||||
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
|
||||
<Form :model="searchForm" layout="inline">
|
||||
<Form.Item label="平台订单号">
|
||||
<Input
|
||||
v-model:value="searchForm.platformOrderNo"
|
||||
placeholder="请输入平台订单号"
|
||||
style="width: 200px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="商品名称">
|
||||
<Input
|
||||
v-model:value="searchForm.productName"
|
||||
placeholder="请输入商品名称"
|
||||
style="width: 200px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="店铺">
|
||||
<Select
|
||||
v-model:value="searchForm.shopId"
|
||||
placeholder="请选择店铺"
|
||||
style="width: 150px;"
|
||||
:options="shopOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="订单状态">
|
||||
<Select
|
||||
v-model:value="searchForm.statusId"
|
||||
placeholder="请选择状态"
|
||||
style="width: 150px;"
|
||||
:options="orderStatusOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="orderList"
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
@change="handleTableChange"
|
||||
/>
|
||||
|
||||
<!-- 订单表单模态框 -->
|
||||
<OrderFormModal
|
||||
ref="orderFormModalRef"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
import { Modal, Form, Input, InputNumber, Switch, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createOrderStatusApi,
|
||||
updateOrderStatusApi,
|
||||
type OrderStatusDTO,
|
||||
type OrderStatusVO
|
||||
} from '#/api/ecommerce';
|
||||
|
||||
defineProps<{
|
||||
visible?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
success: [];
|
||||
cancel: [];
|
||||
}>();
|
||||
|
||||
// 响应式数据
|
||||
const visible = ref(false);
|
||||
const loading = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentRecord = ref<OrderStatusVO.OrderStatusInfoVO | null>(null);
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<Partial<OrderStatusDTO.CreateOrderStatusDTO>>({
|
||||
name: '',
|
||||
description: '',
|
||||
enabled: true,
|
||||
sortOrder: 0,
|
||||
});
|
||||
|
||||
// 表单验证规则
|
||||
const rules = {
|
||||
name: [{ required: true, message: '请输入状态名称', trigger: 'blur' }],
|
||||
sortOrder: [{ required: true, message: '请输入排序', trigger: 'blur' }],
|
||||
};
|
||||
|
||||
// 表单引用
|
||||
const formRef = ref();
|
||||
|
||||
// 打开模态框
|
||||
function open(edit: boolean, record?: OrderStatusVO.OrderStatusInfoVO) {
|
||||
isEdit.value = edit;
|
||||
currentRecord.value = record || null;
|
||||
visible.value = true;
|
||||
|
||||
if (edit && record) {
|
||||
// 编辑模式,填充表单数据
|
||||
formData.value = {
|
||||
name: record.name,
|
||||
description: record.description || '',
|
||||
enabled: record.enabled,
|
||||
sortOrder: record.sortOrder || 0,
|
||||
};
|
||||
} else {
|
||||
// 新增模式,重置表单
|
||||
formData.value = {
|
||||
name: '',
|
||||
description: '',
|
||||
enabled: true,
|
||||
sortOrder: 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭模态框
|
||||
function close() {
|
||||
visible.value = false;
|
||||
formRef.value?.resetFields();
|
||||
emit('cancel');
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
if (isEdit.value && currentRecord.value) {
|
||||
// 更新订单状态
|
||||
const updateData: OrderStatusDTO.UpdateOrderStatusDTO = {
|
||||
id: currentRecord.value.id,
|
||||
name: formData.value.name!,
|
||||
description: formData.value.description,
|
||||
enabled: formData.value.enabled!,
|
||||
sortOrder: formData.value.sortOrder,
|
||||
};
|
||||
await updateOrderStatusApi(updateData);
|
||||
message.success('更新订单状态成功');
|
||||
} else {
|
||||
// 创建订单状态
|
||||
const createData: OrderStatusDTO.CreateOrderStatusDTO = {
|
||||
name: formData.value.name!,
|
||||
description: formData.value.description,
|
||||
enabled: formData.value.enabled!,
|
||||
sortOrder: formData.value.sortOrder,
|
||||
};
|
||||
await createOrderStatusApi(createData);
|
||||
message.success('创建订单状态成功');
|
||||
}
|
||||
|
||||
close();
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('提交订单状态失败:', error);
|
||||
message.error('提交订单状态失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 监听visible变化
|
||||
watch(visible, (newVal) => {
|
||||
if (!newVal) {
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
});
|
||||
|
||||
// 暴露方法
|
||||
defineExpose({
|
||||
open,
|
||||
close,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="visible"
|
||||
:title="isEdit ? '编辑订单状态' : '添加订单状态'"
|
||||
:confirm-loading="loading"
|
||||
width="500px"
|
||||
@ok="handleSubmit"
|
||||
@cancel="close"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="rules as any"
|
||||
layout="vertical"
|
||||
>
|
||||
<Form.Item label="状态名称" name="name">
|
||||
<Input
|
||||
v-model:value="formData.name"
|
||||
placeholder="请输入状态名称"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态描述" name="description">
|
||||
<Input.TextArea
|
||||
v-model:value="formData.description"
|
||||
placeholder="请输入状态描述(可选)"
|
||||
:rows="3"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<Form.Item label="排序" name="sortOrder">
|
||||
<InputNumber
|
||||
v-model:value="formData.sortOrder"
|
||||
placeholder="请输入排序"
|
||||
style="width: 100%"
|
||||
:min="0"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="启用状态" name="enabled">
|
||||
<Switch
|
||||
v-model:checked="formData.enabled"
|
||||
checked-children="启用"
|
||||
un-checked-children="禁用"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,172 @@
|
||||
<script lang="ts" setup>
|
||||
import { h, ref, onMounted } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, Table, message, Tag } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
deleteOrderStatusApi,
|
||||
getAllOrderStatusListApi,
|
||||
type OrderStatusVO
|
||||
} from '#/api/ecommerce';
|
||||
import OrderStatusFormModal from './components/OrderStatusFormModal.vue';
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
defineOptions({ name: 'OrderStatusManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const orderStatusList = ref<OrderStatusVO.OrderStatusInfoVO[]>([]);
|
||||
const orderStatusFormModalRef = ref();
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '状态名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '状态描述',
|
||||
dataIndex: 'description',
|
||||
key: 'description',
|
||||
width: 200,
|
||||
customRender: ({ record }: { record: OrderStatusVO.OrderStatusInfoVO }) => {
|
||||
return record.description || h('span', { style: { color: '#999' } }, '暂无描述');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
dataIndex: 'sortOrder',
|
||||
key: 'sortOrder',
|
||||
width: 80,
|
||||
customRender: ({ record }: { record: OrderStatusVO.OrderStatusInfoVO }) => {
|
||||
return record.sortOrder || 0;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'enabled',
|
||||
key: 'enabled',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: OrderStatusVO.OrderStatusInfoVO }) => {
|
||||
return h(Tag, {
|
||||
color: record.enabled ? 'green' : 'red'
|
||||
}, () => record.enabled ? '启用' : '禁用');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '更新时间',
|
||||
dataIndex: 'updateTime',
|
||||
key: 'updateTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: OrderStatusVO.OrderStatusInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, { default: () => '编辑' }),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDelete(record),
|
||||
}, { default: () => '删除' }),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 获取订单状态列表
|
||||
async function fetchOrderStatusList() {
|
||||
try {
|
||||
loading.value = true;
|
||||
const data = await getAllOrderStatusListApi();
|
||||
orderStatusList.value = data;
|
||||
} catch (error) {
|
||||
console.error('获取订单状态列表失败:', error);
|
||||
message.error('获取订单状态列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理添加订单状态
|
||||
function handleAdd() {
|
||||
orderStatusFormModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑订单状态
|
||||
function handleEdit(record: OrderStatusVO.OrderStatusInfoVO) {
|
||||
orderStatusFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除订单状态
|
||||
async function handleDelete(record: OrderStatusVO.OrderStatusInfoVO) {
|
||||
try {
|
||||
await deleteOrderStatusApi(record.id);
|
||||
message.success('删除成功');
|
||||
await fetchOrderStatusList();
|
||||
} catch (error) {
|
||||
console.error('删除订单状态失败:', error);
|
||||
message.error('删除订单状态失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模态框成功
|
||||
function handleModalSuccess() {
|
||||
fetchOrderStatusList();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
fetchOrderStatusList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="订单状态管理">
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理订单状态信息,包括状态创建、编辑、删除和启用/禁用
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon class="w-4 h-4 mr-2" />
|
||||
添加状态
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="orderStatusList"
|
||||
:loading="loading"
|
||||
:pagination="false"
|
||||
row-key="id"
|
||||
/>
|
||||
|
||||
<!-- 订单状态表单模态框 -->
|
||||
<OrderStatusFormModal
|
||||
ref="orderStatusFormModalRef"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
+187
@@ -0,0 +1,187 @@
|
||||
<script lang="ts" setup>
|
||||
import { Card, Image, Tag, Button, Space, Popconfirm, Tooltip } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import type { ProductVO } from '#/api/shop';
|
||||
|
||||
// 创建图标组件
|
||||
const EditIcon = createIconifyIcon('lucide:edit');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
const SettingsIcon = createIconifyIcon('lucide:settings');
|
||||
const EyeIcon = createIconifyIcon('lucide:eye');
|
||||
|
||||
interface Props {
|
||||
product: ProductVO.ProductInfoVO;
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'edit', product: ProductVO.ProductInfoVO): void;
|
||||
(e: 'delete', product: ProductVO.ProductInfoVO): void;
|
||||
(e: 'manage-specs', product: ProductVO.ProductInfoVO): void;
|
||||
(e: 'view-details', product: ProductVO.ProductInfoVO): void;
|
||||
}
|
||||
|
||||
defineProps<Props>();
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const handleEdit = (product: ProductVO.ProductInfoVO) => {
|
||||
emit('edit', product);
|
||||
};
|
||||
|
||||
const handleDelete = (product: ProductVO.ProductInfoVO) => {
|
||||
emit('delete', product);
|
||||
};
|
||||
|
||||
const handleManageSpecs = (product: ProductVO.ProductInfoVO) => {
|
||||
emit('manage-specs', product);
|
||||
};
|
||||
|
||||
const handleViewDetails = (product: ProductVO.ProductInfoVO) => {
|
||||
emit('view-details', product);
|
||||
};
|
||||
|
||||
const handleImageError = (event: Event | string) => {
|
||||
if (typeof event === 'string') {
|
||||
// 如果是字符串,说明是错误信息,直接隐藏图片
|
||||
const img = document.querySelector(`img[src="${event}"]`) as HTMLImageElement;
|
||||
if (img) {
|
||||
img.style.display = 'none';
|
||||
}
|
||||
} else {
|
||||
// 如果是Event对象,按原来的方式处理
|
||||
const img = event.target as HTMLImageElement;
|
||||
if (img) {
|
||||
img.style.display = 'none';
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Card
|
||||
hoverable
|
||||
:body-style="{ padding: '12px' }"
|
||||
class="product-card"
|
||||
>
|
||||
<div class="relative">
|
||||
<!-- 商品图片 -->
|
||||
<div class="aspect-square bg-gray-100 rounded-lg overflow-hidden">
|
||||
<Image
|
||||
v-if="product.mainImage"
|
||||
:src="product.mainImage"
|
||||
:alt="product.name"
|
||||
class="w-full h-full object-cover"
|
||||
:preview="true"
|
||||
@error="handleImageError"
|
||||
/>
|
||||
<div v-else class="w-full h-full flex items-center justify-center text-gray-400">
|
||||
<div class="text-center">
|
||||
<div class="text-4xl mb-2">📦</div>
|
||||
<div class="text-sm">暂无图片</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 规格数量标签 -->
|
||||
<div v-if="product.specs && product.specs.length > 0" class="absolute top-2 left-2">
|
||||
<Tag color="blue">
|
||||
{{ product.specs.length }} 个规格
|
||||
</Tag>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 商品信息 -->
|
||||
<div class="mt-3">
|
||||
<div class="text-sm font-medium text-gray-900 mb-2 line-clamp-2" :title="product.name">
|
||||
{{ product.name }}
|
||||
</div>
|
||||
|
||||
<!-- 规格信息 -->
|
||||
<div v-if="product.specs && product.specs.length > 0" class="mb-2">
|
||||
<div class="text-xs text-gray-500 mb-1">规格信息:</div>
|
||||
<div class="space-y-1">
|
||||
<div
|
||||
v-for="spec in product.specs.slice(0, 2)"
|
||||
:key="spec.id"
|
||||
class="text-xs bg-gray-50 px-2 py-1 rounded"
|
||||
>
|
||||
<span class="font-medium">{{ spec.name }}</span>
|
||||
<span class="text-red-500 ml-1">¥{{ spec.costPrice.toFixed(2) }}</span>
|
||||
</div>
|
||||
<div v-if="product.specs.length > 2" class="text-xs text-gray-400">
|
||||
还有 {{ product.specs.length - 2 }} 个规格...
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 创建时间 -->
|
||||
<div class="text-xs text-gray-500 mb-3">
|
||||
{{ product.createTime }}
|
||||
</div>
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<div class="flex justify-between items-center">
|
||||
<Space size="small">
|
||||
<Tooltip title="编辑">
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleEdit(product)"
|
||||
>
|
||||
<EditIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Tooltip title="管理规格">
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleManageSpecs(product)"
|
||||
>
|
||||
<SettingsIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Tooltip title="查看详情">
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleViewDetails(product)"
|
||||
>
|
||||
<EyeIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Space>
|
||||
<Popconfirm
|
||||
title="确定要删除这个商品吗?"
|
||||
@confirm="handleDelete(product)"
|
||||
>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
danger
|
||||
>
|
||||
<TrashIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.product-card {
|
||||
transition: all 0.3s ease;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.product-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.line-clamp-2 {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
+419
@@ -0,0 +1,419 @@
|
||||
<template>
|
||||
<Modal
|
||||
:open="visible"
|
||||
:title="modalTitle"
|
||||
width="600px"
|
||||
:confirm-loading="loading"
|
||||
@ok="handleSubmit"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="商品主图" name="mainImageId">
|
||||
<div style="display: flex; align-items: center; gap: 16px;">
|
||||
|
||||
<!-- 主图预览区域 -->
|
||||
<div style="position: relative; display: inline-block;">
|
||||
<!-- 有图片时显示图片 -->
|
||||
<img
|
||||
v-if="currentImageUrl && !imageLoadError"
|
||||
:src="currentImageUrl"
|
||||
alt="商品主图"
|
||||
style="width: 80px; height: 80px; object-fit: cover; border-radius: 8px; border: 1px solid #d9d9d9; background-color: #f5f5f5;"
|
||||
@error="handleImageError"
|
||||
/>
|
||||
<!-- 无图片或加载失败时显示空状态 -->
|
||||
<div
|
||||
v-else
|
||||
style="width: 80px; height: 80px; border: 1px dashed #d9d9d9; border-radius: 8px; background-color: #fafafa; display: flex; align-items: center; justify-content: center; color: #999; font-size: 12px; text-align: center; line-height: 1.2;">
|
||||
<div style="display: flex; flex-direction: column; align-items: center; justify-content: center;">
|
||||
<CameraIcon style="font-size: 16px; margin-bottom: 4px;" />
|
||||
<div>上传主图</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 点击更换遮罩 -->
|
||||
<div
|
||||
style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); border-radius: 8px; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.3s; cursor: pointer;"
|
||||
@mouseenter="($event.target as HTMLElement).style.opacity = '1'"
|
||||
@mouseleave="($event.target as HTMLElement).style.opacity = '0'"
|
||||
@click="selectImageFile">
|
||||
<div style="color: white; text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center;">
|
||||
<CameraIcon style="font-size: 16px; margin-bottom: 4px;" />
|
||||
<div style="font-size: 12px;">{{ currentImageUrl && !imageLoadError ? '更换主图' : '上传主图' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 重置按钮 -->
|
||||
<div v-if="newImageFile">
|
||||
<Button size="small" @click="removeNewImage">重置</Button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="商品名称" name="name" :rules="[{ required: true, message: '请输入商品名称' }]">
|
||||
<Input v-model:value="formData.name" placeholder="请输入商品名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item v-if="isEdit" label="商品编码" name="specCode">
|
||||
<Input v-model:value="formData.specCode" placeholder="请输入商品编码" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item v-if="isEdit" label="商品SKU" name="skuCode">
|
||||
<Input v-model:value="formData.skuCode" placeholder="请输入商品SKU" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item v-if="isEdit" label="成本价" name="costPrice" :rules="[{ required: true, message: '请输入成本价' }]">
|
||||
<InputNumber
|
||||
v-model:value="formData.costPrice"
|
||||
placeholder="请输入成本价"
|
||||
style="width: 100%;"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<!-- 规格管理 -->
|
||||
<Form.Item v-if="!isEdit" label="商品规格">
|
||||
<div class="space-y-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<Button
|
||||
type="dashed"
|
||||
@click="showSpecs = !showSpecs"
|
||||
:icon="showSpecs ? 'up' : 'down'"
|
||||
>
|
||||
{{ showSpecs ? '收起规格' : '添加规格' }}
|
||||
</Button>
|
||||
<span class="text-sm text-gray-500">
|
||||
可以添加多个规格,每个规格包含名称、编码和成本价
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div v-if="showSpecs" class="border border-gray-200 rounded-lg p-4 bg-gray-50">
|
||||
<div class="space-y-3">
|
||||
<div
|
||||
v-for="(spec, index) in specs"
|
||||
:key="index"
|
||||
class="flex items-center gap-2 p-3 bg-white rounded border"
|
||||
>
|
||||
<Input
|
||||
v-model:value="spec.name"
|
||||
placeholder="规格名称"
|
||||
style="flex: 1;"
|
||||
/>
|
||||
<Input
|
||||
v-model:value="spec.specCode"
|
||||
placeholder="规格编码"
|
||||
style="flex: 1;"
|
||||
/>
|
||||
<InputNumber
|
||||
v-model:value="spec.costPrice"
|
||||
placeholder="成本价"
|
||||
style="width: 120px;"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
@click="removeSpec(index)"
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
type="dashed"
|
||||
@click="addSpec"
|
||||
style="width: 100%;"
|
||||
>
|
||||
+ 添加规格
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, onUnmounted } from 'vue';
|
||||
import { Form, Input, Modal, InputNumber, Button, message } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import {
|
||||
createProductApi,
|
||||
updateProductApi,
|
||||
createProductWithSpecsApi,
|
||||
type ProductVO,
|
||||
type ProductDTO
|
||||
} from '#/api/shop';
|
||||
import { uploadImageApi } from '#/api/media';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 创建相机图标组件
|
||||
const CameraIcon = createIconifyIcon('mdi:camera');
|
||||
|
||||
// 内部状态管理
|
||||
const visible = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentProductData = ref<ProductVO.ProductInfoVO | Partial<ProductVO.ProductInfoVO> | null>(null);
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const newImageFile = ref<File | null>(null); // 新选择的图片文件
|
||||
const originalImageUrl = ref(''); // 原始图片 URL
|
||||
const imageLoadError = ref(false); // 图片加载错误状态
|
||||
|
||||
// 表单数据
|
||||
const formData = ref({
|
||||
name: '',
|
||||
specCode: '',
|
||||
skuCode: '',
|
||||
mainImageId: undefined as number | undefined,
|
||||
costPrice: 0,
|
||||
});
|
||||
|
||||
// 规格数据
|
||||
const specs = ref<ProductDTO.ProductSpecDTO[]>([]);
|
||||
const showSpecs = ref(false);
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => isEdit.value ? '编辑商品' : '添加商品');
|
||||
|
||||
// 当前显示的图片 URL(优先显示新选择的)
|
||||
const currentImageUrl = computed(() => {
|
||||
if (newImageFile.value) {
|
||||
return URL.createObjectURL(newImageFile.value);
|
||||
}
|
||||
return originalImageUrl.value;
|
||||
});
|
||||
|
||||
// 初始化表单数据
|
||||
function initFormData() {
|
||||
if (isEdit.value && currentProductData.value) {
|
||||
// 编辑模式
|
||||
formData.value = {
|
||||
name: currentProductData.value.name || '',
|
||||
specCode: '',
|
||||
skuCode: '',
|
||||
mainImageId: undefined,
|
||||
costPrice: 0,
|
||||
};
|
||||
|
||||
// 设置原始图片 URL
|
||||
originalImageUrl.value = currentProductData.value.mainImage || '';
|
||||
} else {
|
||||
// 创建模式 - 如果有传入的productData,则使用它来初始化表单
|
||||
formData.value = {
|
||||
name: currentProductData.value?.name || '',
|
||||
specCode: '',
|
||||
skuCode: '',
|
||||
mainImageId: undefined,
|
||||
costPrice: 0,
|
||||
};
|
||||
originalImageUrl.value = currentProductData.value?.mainImage || '';
|
||||
}
|
||||
|
||||
// 重置新选择的图片和图片加载状态
|
||||
newImageFile.value = null;
|
||||
imageLoadError.value = false;
|
||||
|
||||
// 重置规格数据
|
||||
specs.value = [];
|
||||
showSpecs.value = false;
|
||||
|
||||
// 如果有传入的规格信息,则自动填入
|
||||
if (!isEdit.value && currentProductData.value && 'specs' in currentProductData.value && currentProductData.value.specs) {
|
||||
specs.value = currentProductData.value.specs.map(spec => ({
|
||||
name: (spec as any).specName || spec.specCode || '',
|
||||
specCode: spec.specCode || '',
|
||||
costPrice: spec.costPrice || 0
|
||||
}));
|
||||
showSpecs.value = specs.value.length > 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 重置表单(在open方法中调用)
|
||||
function resetForm() {
|
||||
formRef.value?.resetFields();
|
||||
newImageFile.value = null;
|
||||
originalImageUrl.value = '';
|
||||
imageLoadError.value = false;
|
||||
specs.value = [];
|
||||
showSpecs.value = false;
|
||||
}
|
||||
|
||||
// 处理提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
// 准备提交数据
|
||||
const submitData = { ...formData.value };
|
||||
|
||||
// 如果有新选择的图片,先上传获取ID
|
||||
if (newImageFile.value) {
|
||||
const mainImageId = await uploadImageAndGetId();
|
||||
if (mainImageId) {
|
||||
submitData.mainImageId = mainImageId;
|
||||
}
|
||||
} else if (!isEdit.value) {
|
||||
// 创建模式且没有选择图片,移除mainImageId字段
|
||||
delete submitData.mainImageId;
|
||||
}
|
||||
|
||||
// 调用API
|
||||
if (isEdit.value && currentProductData.value && 'id' in currentProductData.value && currentProductData.value.id) {
|
||||
await updateProductApi(currentProductData.value.id, submitData as ProductDTO.UpdateProductDTO);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
// 创建模式:如果有规格,使用一键创建接口
|
||||
if (specs.value.length > 0) {
|
||||
const createWithSpecsData: ProductDTO.CreateProductWithSpecsDTO = {
|
||||
name: submitData.name,
|
||||
mainImageId: submitData.mainImageId,
|
||||
specs: specs.value,
|
||||
};
|
||||
await createProductWithSpecsApi(createWithSpecsData);
|
||||
message.success('商品和规格创建成功');
|
||||
} else {
|
||||
await createProductApi(submitData as ProductDTO.CreateProductDTO);
|
||||
message.success('创建成功');
|
||||
}
|
||||
}
|
||||
|
||||
visible.value = false;
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('保存商品失败:', error);
|
||||
message.error('保存商品失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理取消
|
||||
function handleCancel() {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(editMode: boolean = false, productData?: ProductVO.ProductInfoVO | Partial<ProductVO.ProductInfoVO> | null) {
|
||||
isEdit.value = editMode;
|
||||
currentProductData.value = productData || null;
|
||||
|
||||
resetForm(); // 先重置表单
|
||||
initFormData(); // 再初始化数据
|
||||
|
||||
visible.value = true;
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
|
||||
// 选择图片文件
|
||||
function selectImageFile() {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.accept = 'image/*';
|
||||
input.style.display = 'none';
|
||||
document.body.appendChild(input);
|
||||
|
||||
input.onchange = (e) => {
|
||||
const file = (e.target as HTMLInputElement).files?.[0];
|
||||
if (file) {
|
||||
// 验证文件
|
||||
const isImage = file.type.startsWith('image/');
|
||||
if (!isImage) {
|
||||
message.error('只能上传图片文件');
|
||||
document.body.removeChild(input);
|
||||
return;
|
||||
}
|
||||
|
||||
const isLt2M = file.size / 1024 / 1024 < 2;
|
||||
if (!isLt2M) {
|
||||
message.error('图片大小不能超过 2MB');
|
||||
document.body.removeChild(input);
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置新选择的文件
|
||||
newImageFile.value = file;
|
||||
imageLoadError.value = false; // 重置图片加载错误状态
|
||||
message.success('图片选择成功');
|
||||
}
|
||||
|
||||
document.body.removeChild(input);
|
||||
};
|
||||
|
||||
input.click();
|
||||
}
|
||||
|
||||
// 重置新选择的图片
|
||||
function removeNewImage() {
|
||||
newImageFile.value = null;
|
||||
imageLoadError.value = false; // 重置图片加载错误状态
|
||||
message.success('已重置图片');
|
||||
}
|
||||
|
||||
// 添加规格
|
||||
function addSpec() {
|
||||
specs.value.push({
|
||||
name: '',
|
||||
specCode: '',
|
||||
costPrice: 0,
|
||||
});
|
||||
}
|
||||
|
||||
// 删除规格
|
||||
function removeSpec(index: number) {
|
||||
specs.value.splice(index, 1);
|
||||
}
|
||||
|
||||
// 上传图片并获取图片ID
|
||||
async function uploadImageAndGetId(): Promise<number | undefined> {
|
||||
if (!newImageFile.value) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await uploadImageApi(newImageFile.value);
|
||||
console.log('图片上传成功:', response);
|
||||
return response.id;
|
||||
} catch (error) {
|
||||
console.error('图片上传失败:', error);
|
||||
message.error('图片上传失败');
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// 图片加载错误处理
|
||||
function handleImageError(event: Event) {
|
||||
console.error('图片加载失败:', event);
|
||||
imageLoadError.value = true;
|
||||
message.error('图片加载失败,请重新选择');
|
||||
}
|
||||
|
||||
// 组件卸载时清理
|
||||
onUnmounted(() => {
|
||||
if (newImageFile.value) {
|
||||
const url = URL.createObjectURL(newImageFile.value);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
+322
@@ -0,0 +1,322 @@
|
||||
<template>
|
||||
<Modal
|
||||
:open="visible"
|
||||
:title="modalTitle"
|
||||
width="800px"
|
||||
:confirm-loading="loading"
|
||||
@ok="handleSubmit"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<div class="space-y-4">
|
||||
<!-- 商品信息 -->
|
||||
<div class="bg-gray-50 p-4 rounded-lg">
|
||||
<h3 class="font-medium text-gray-900 mb-2">商品信息</h3>
|
||||
<div class="grid grid-cols-2 gap-4 text-sm">
|
||||
<div>
|
||||
<span class="text-gray-500">商品名称:</span>
|
||||
<span class="ml-2 font-medium">{{ currentProduct?.name }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-500">商品ID:</span>
|
||||
<span class="ml-2 font-medium">{{ currentProduct?.id }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 规格列表 -->
|
||||
<div>
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<h3 class="font-medium text-gray-900">商品规格</h3>
|
||||
<Button type="primary" @click="handleAddSpec">
|
||||
添加规格
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="specList"
|
||||
:loading="specLoading"
|
||||
:pagination="{
|
||||
current: specCurrent,
|
||||
pageSize: specPageSize,
|
||||
total: specTotal,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
@change="handleSpecTableChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
<!-- 规格表单模态框 -->
|
||||
<Modal
|
||||
:open="specFormVisible"
|
||||
:title="specFormTitle"
|
||||
width="500px"
|
||||
:confirm-loading="specFormLoading"
|
||||
@ok="handleSpecSubmit"
|
||||
@cancel="handleSpecCancel"
|
||||
>
|
||||
<Form
|
||||
ref="specFormRef"
|
||||
:model="specFormData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="规格名称" name="name" :rules="[{ required: true, message: '请输入规格名称' }]">
|
||||
<Input v-model:value="specFormData.name" placeholder="请输入规格名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="规格编码" name="specCode">
|
||||
<Input v-model:value="specFormData.specCode" placeholder="请输入规格编码" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="成本价" name="costPrice" :rules="[{ required: true, message: '请输入成本价' }]">
|
||||
<InputNumber
|
||||
v-model:value="specFormData.costPrice"
|
||||
placeholder="请输入成本价"
|
||||
style="width: 100%;"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, h } from 'vue';
|
||||
import { Form, Input, Modal, InputNumber, Button, Table, message } from 'ant-design-vue';
|
||||
import {
|
||||
getProductSpecPageApi,
|
||||
createProductSpecApi,
|
||||
updateProductSpecApi,
|
||||
deleteProductSpecApi,
|
||||
type ProductVO,
|
||||
type ProductDTO
|
||||
} from '#/api/shop';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 内部状态管理
|
||||
const visible = ref(false);
|
||||
const currentProduct = ref<ProductVO.ProductInfoVO | null>(null);
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const specLoading = ref(false);
|
||||
const specList = ref<ProductVO.ProductSpecInfoVO[]>([]);
|
||||
const specTotal = ref(0);
|
||||
const specCurrent = ref(1);
|
||||
const specPageSize = ref(10);
|
||||
|
||||
// 规格表单相关
|
||||
const specFormVisible = ref(false);
|
||||
const specFormLoading = ref(false);
|
||||
const specFormRef = ref();
|
||||
const isEditSpec = ref(false);
|
||||
const currentSpecId = ref<number | null>(null);
|
||||
|
||||
const specFormData = ref({
|
||||
name: '',
|
||||
specCode: '',
|
||||
costPrice: 0,
|
||||
});
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() =>
|
||||
currentProduct.value ? `管理规格 - ${currentProduct.value.name}` : '管理规格'
|
||||
);
|
||||
|
||||
// 规格表单标题
|
||||
const specFormTitle = computed(() => isEditSpec.value ? '编辑规格' : '添加规格');
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '规格名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '规格编码',
|
||||
dataIndex: 'specCode',
|
||||
key: 'specCode',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '成本价',
|
||||
dataIndex: 'costPrice',
|
||||
key: 'costPrice',
|
||||
width: 120,
|
||||
customRender: ({ record }: { record: ProductVO.ProductSpecInfoVO }) => {
|
||||
return `¥${record.costPrice.toFixed(2)}`;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 150,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: ProductVO.ProductSpecInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleEditSpec(record),
|
||||
}, { default: () => '编辑' }),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDeleteSpec(record),
|
||||
}, { default: () => '删除' }),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 获取规格列表
|
||||
async function fetchSpecList() {
|
||||
if (!currentProduct.value) return;
|
||||
|
||||
try {
|
||||
specLoading.value = true;
|
||||
const params: PageQueryDTO<ProductDTO.ProductSpecFilterDTO> = {
|
||||
page: specCurrent.value,
|
||||
pageSize: specPageSize.value,
|
||||
filters: {
|
||||
productId: currentProduct.value.id,
|
||||
},
|
||||
};
|
||||
const data = await getProductSpecPageApi(params);
|
||||
specList.value = data.records;
|
||||
specTotal.value = data.total;
|
||||
} catch (error) {
|
||||
console.error('获取规格列表失败:', error);
|
||||
message.error('获取规格列表失败');
|
||||
} finally {
|
||||
specLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理规格表格变化
|
||||
function handleSpecTableChange(pagination: any) {
|
||||
specCurrent.value = pagination.current;
|
||||
specPageSize.value = pagination.pageSize;
|
||||
fetchSpecList();
|
||||
}
|
||||
|
||||
// 处理添加规格
|
||||
function handleAddSpec() {
|
||||
isEditSpec.value = false;
|
||||
currentSpecId.value = null;
|
||||
specFormData.value = {
|
||||
name: '',
|
||||
specCode: '',
|
||||
costPrice: 0,
|
||||
};
|
||||
specFormVisible.value = true;
|
||||
}
|
||||
|
||||
// 处理编辑规格
|
||||
function handleEditSpec(record: ProductVO.ProductSpecInfoVO) {
|
||||
isEditSpec.value = true;
|
||||
currentSpecId.value = record.id;
|
||||
specFormData.value = {
|
||||
name: record.name,
|
||||
specCode: record.specCode || '',
|
||||
costPrice: record.costPrice,
|
||||
};
|
||||
specFormVisible.value = true;
|
||||
}
|
||||
|
||||
// 处理删除规格
|
||||
async function handleDeleteSpec(record: ProductVO.ProductSpecInfoVO) {
|
||||
try {
|
||||
await deleteProductSpecApi(record.id);
|
||||
message.success('删除成功');
|
||||
await fetchSpecList();
|
||||
} catch (error) {
|
||||
console.error('删除规格失败:', error);
|
||||
message.error('删除规格失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理规格表单提交
|
||||
async function handleSpecSubmit() {
|
||||
try {
|
||||
await specFormRef.value?.validate();
|
||||
specFormLoading.value = true;
|
||||
|
||||
if (isEditSpec.value && currentSpecId.value) {
|
||||
await updateProductSpecApi(currentSpecId.value, specFormData.value as ProductDTO.UpdateProductSpecDTO);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
if (!currentProduct.value) {
|
||||
message.error('商品信息不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
const createData: ProductDTO.CreateProductSpecDTO = {
|
||||
productId: currentProduct.value.id,
|
||||
...specFormData.value,
|
||||
};
|
||||
await createProductSpecApi(createData);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
specFormVisible.value = false;
|
||||
await fetchSpecList();
|
||||
} catch (error) {
|
||||
console.error('保存规格失败:', error);
|
||||
message.error('保存规格失败');
|
||||
} finally {
|
||||
specFormLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理规格表单取消
|
||||
function handleSpecCancel() {
|
||||
specFormVisible.value = false;
|
||||
}
|
||||
|
||||
// 处理提交
|
||||
function handleSubmit() {
|
||||
// 规格管理模态框不需要提交操作
|
||||
handleCancel();
|
||||
}
|
||||
|
||||
// 处理取消
|
||||
function handleCancel() {
|
||||
visible.value = false;
|
||||
emit('success');
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(product: ProductVO.ProductInfoVO) {
|
||||
currentProduct.value = product;
|
||||
specCurrent.value = 1;
|
||||
specPageSize.value = 10;
|
||||
visible.value = true;
|
||||
fetchSpecList();
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,389 @@
|
||||
<template>
|
||||
<Page>
|
||||
<template #title>商品管理</template>
|
||||
|
||||
<!-- 搜索区域 -->
|
||||
<div class="mb-4 p-4 bg-white rounded-lg shadow-sm">
|
||||
<Form :model="searchForm" layout="inline">
|
||||
<Form.Item label="商品名称">
|
||||
<Input
|
||||
v-model:value="searchForm.name"
|
||||
placeholder="请输入商品名称"
|
||||
style="width: 200px"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="商品编码">
|
||||
<Input
|
||||
v-model:value="searchForm.specCode"
|
||||
placeholder="请输入商品编码"
|
||||
style="width: 150px"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="商品SKU">
|
||||
<Input
|
||||
v-model:value="searchForm.skuCode"
|
||||
placeholder="请输入商品SKU"
|
||||
style="width: 150px"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="成本价范围">
|
||||
<div class="flex items-center gap-2">
|
||||
<InputNumber
|
||||
v-model:value="searchForm.minCostPrice"
|
||||
placeholder="最小值"
|
||||
style="width: 100px"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
<span class="text-gray-500">-</span>
|
||||
<InputNumber
|
||||
v-model:value="searchForm.maxCostPrice"
|
||||
placeholder="最大值"
|
||||
style="width: 100px"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
</div>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
<!-- 操作区域 -->
|
||||
<div class="mb-4 flex justify-between items-center">
|
||||
<div class="flex items-center gap-4">
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon class="w-4 h-4 mr-2" />
|
||||
添加商品
|
||||
</Button>
|
||||
<span class="text-gray-500">支持商品和规格的一键创建</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
<Button
|
||||
:type="viewMode === 'grid' ? 'primary' : 'default'"
|
||||
@click="toggleViewMode"
|
||||
>
|
||||
<GridIcon class="w-4 h-4 mr-2" />
|
||||
网格视图
|
||||
</Button>
|
||||
<Button
|
||||
:type="viewMode === 'table' ? 'primary' : 'default'"
|
||||
@click="toggleViewMode"
|
||||
>
|
||||
<ListIcon class="w-4 h-4 mr-2" />
|
||||
列表视图
|
||||
</Button>
|
||||
<span class="text-gray-500">
|
||||
共 {{ total }} 个商品
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 列表视图 -->
|
||||
<div v-if="viewMode === 'table'" class="bg-white rounded-lg shadow-sm">
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="productList"
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
@change="handleTableChange"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 网格视图 -->
|
||||
<div v-if="viewMode === 'grid'" class="bg-white rounded-lg shadow-sm p-4">
|
||||
<Row :gutter="[16, 16]">
|
||||
<Col
|
||||
v-for="product in productList"
|
||||
:key="product.id"
|
||||
:xs="12"
|
||||
:sm="8"
|
||||
:md="6"
|
||||
:lg="4"
|
||||
:xl="3"
|
||||
>
|
||||
<ProductCard
|
||||
:product="product"
|
||||
@edit="handleEdit"
|
||||
@delete="handleDelete"
|
||||
@manage-specs="handleManageSpecs"
|
||||
@view-details="handleViewDetails"
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="mt-4 flex justify-center">
|
||||
<Pagination
|
||||
v-model:current="current"
|
||||
v-model:page-size="pageSize"
|
||||
:total="total"
|
||||
:show-size-changer="true"
|
||||
:show-quick-jumper="true"
|
||||
:show-total="(total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`"
|
||||
@change="handleTableChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 商品表单模态框 -->
|
||||
<ProductFormModal
|
||||
ref="productFormModalRef"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
|
||||
<!-- 商品规格管理模态框 -->
|
||||
<ProductSpecModal
|
||||
ref="productSpecModalRef"
|
||||
@success="handleSpecModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { h, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, Input, InputNumber, Table, message, Row, Col, Pagination, Form, Space, Tag } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
deleteProductApi,
|
||||
getProductPageApi,
|
||||
type ProductVO,
|
||||
type ProductDTO
|
||||
} from '#/api/shop';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import ProductFormModal from './components/ProductFormModal.vue';
|
||||
// @ts-ignore
|
||||
import ProductSpecModal from './components/ProductSpecModal.vue';
|
||||
import ProductCard from './components/ProductCard.vue';
|
||||
|
||||
// 创建图标组件
|
||||
const GridIcon = createIconifyIcon('lucide:grid-3x3');
|
||||
const ListIcon = createIconifyIcon('lucide:list');
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
defineOptions({ name: 'ProductManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const productList = ref<ProductVO.ProductInfoVO[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(10);
|
||||
const viewMode = ref<'table' | 'grid'>('grid');
|
||||
const productFormModalRef = ref();
|
||||
const productSpecModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
specCode: '',
|
||||
skuCode: '',
|
||||
minCostPrice: undefined as number | undefined,
|
||||
maxCostPrice: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '商品名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '主图',
|
||||
dataIndex: 'mainImage',
|
||||
key: 'mainImage',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: ProductVO.ProductInfoVO }) => {
|
||||
if (record.mainImage) {
|
||||
return h('img', {
|
||||
src: record.mainImage,
|
||||
alt: record.name,
|
||||
style: { width: '40px', height: '40px', objectFit: 'cover', borderRadius: '4px' },
|
||||
});
|
||||
}
|
||||
return h('span', { style: { color: '#999' } }, '暂无图片');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '规格数量',
|
||||
dataIndex: 'specs',
|
||||
key: 'specs',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: ProductVO.ProductInfoVO }) => {
|
||||
const specCount = record.specs?.length || 0;
|
||||
return h(Tag, { color: specCount > 0 ? 'blue' : 'default' }, () => `${specCount} 个规格`);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '更新时间',
|
||||
dataIndex: 'updateTime',
|
||||
key: 'updateTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: ProductVO.ProductInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, { default: () => '编辑' }),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleManageSpecs(record),
|
||||
}, { default: () => '规格' }),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDelete(record),
|
||||
}, { default: () => '删除' }),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 获取商品列表
|
||||
async function fetchProductList() {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<ProductDTO.ProductFiltersDTO> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
specCode: searchForm.value.specCode || undefined,
|
||||
skuCode: searchForm.value.skuCode || undefined,
|
||||
minCostPrice: searchForm.value.minCostPrice,
|
||||
maxCostPrice: searchForm.value.maxCostPrice,
|
||||
},
|
||||
};
|
||||
const data = await getProductPageApi(params);
|
||||
productList.value = data.records;
|
||||
total.value = data.total;
|
||||
} catch (error) {
|
||||
console.error('获取商品列表失败:', error);
|
||||
message.error('获取商品列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
function handleSearch() {
|
||||
current.value = 1;
|
||||
fetchProductList();
|
||||
}
|
||||
|
||||
// 处理重置
|
||||
function handleReset() {
|
||||
searchForm.value = {
|
||||
name: '',
|
||||
specCode: '',
|
||||
skuCode: '',
|
||||
minCostPrice: undefined,
|
||||
maxCostPrice: undefined,
|
||||
};
|
||||
current.value = 1;
|
||||
fetchProductList();
|
||||
}
|
||||
|
||||
// 处理分页变化
|
||||
function handleTableChange(pagination: any) {
|
||||
current.value = pagination.current;
|
||||
pageSize.value = pagination.pageSize;
|
||||
fetchProductList();
|
||||
}
|
||||
|
||||
// 切换视图模式
|
||||
function toggleViewMode() {
|
||||
viewMode.value = viewMode.value === 'table' ? 'grid' : 'table';
|
||||
}
|
||||
|
||||
// 处理添加商品
|
||||
function handleAdd() {
|
||||
productFormModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑商品
|
||||
function handleEdit(record: ProductVO.ProductInfoVO) {
|
||||
productFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除商品
|
||||
async function handleDelete(record: ProductVO.ProductInfoVO) {
|
||||
try {
|
||||
await deleteProductApi(record.id);
|
||||
message.success('删除成功');
|
||||
await fetchProductList();
|
||||
} catch (error) {
|
||||
console.error('删除商品失败:', error);
|
||||
message.error('删除商品失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理管理规格
|
||||
function handleManageSpecs(record: ProductVO.ProductInfoVO) {
|
||||
productSpecModalRef.value?.open(record);
|
||||
}
|
||||
|
||||
// 处理查看详情
|
||||
function handleViewDetails() {
|
||||
// TODO: 实现查看详情功能
|
||||
message.info('查看详情功能待实现');
|
||||
}
|
||||
|
||||
// 处理模态框成功
|
||||
function handleModalSuccess() {
|
||||
fetchProductList();
|
||||
}
|
||||
|
||||
// 处理规格模态框成功
|
||||
function handleSpecModalSuccess() {
|
||||
// 规格管理成功后可能需要刷新商品列表
|
||||
fetchProductList();
|
||||
}
|
||||
|
||||
|
||||
// 初始化
|
||||
fetchProductList();
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.line-clamp-2 {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
+305
@@ -0,0 +1,305 @@
|
||||
<template>
|
||||
<Modal
|
||||
:open="visible"
|
||||
:title="modalTitle"
|
||||
width="600px"
|
||||
:confirm-loading="loading"
|
||||
@ok="handleSubmit"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="店铺Logo" name="logoImageId">
|
||||
<div style="display: flex; align-items: center; gap: 16px;">
|
||||
|
||||
<!-- Logo预览区域 -->
|
||||
<div style="position: relative; display: inline-block;">
|
||||
<!-- 有图片时显示图片 -->
|
||||
<img
|
||||
v-if="currentLogoUrl && !imageLoadError"
|
||||
:src="currentLogoUrl"
|
||||
alt="店铺Logo"
|
||||
style="width: 80px; height: 80px; object-fit: cover; border-radius: 8px; border: 1px solid #d9d9d9; background-color: #f5f5f5;"
|
||||
@error="handleImageError"
|
||||
/>
|
||||
<!-- 无图片或加载失败时显示空状态 -->
|
||||
<div
|
||||
v-else
|
||||
style="width: 80px; height: 80px; border: 1px dashed #d9d9d9; border-radius: 8px; background-color: #fafafa; display: flex; align-items: center; justify-content: center; color: #999; font-size: 12px; text-align: center; line-height: 1.2;">
|
||||
<div style="display: flex; flex-direction: column; align-items: center; justify-content: center;">
|
||||
<CameraIcon style="font-size: 16px; margin-bottom: 4px;" />
|
||||
<div>上传Logo</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 点击更换遮罩 -->
|
||||
<div
|
||||
style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); border-radius: 8px; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.3s; cursor: pointer;"
|
||||
@mouseenter="($event.target as HTMLElement).style.opacity = '1'"
|
||||
@mouseleave="($event.target as HTMLElement).style.opacity = '0'"
|
||||
@click="selectLogoFile">
|
||||
<div style="color: white; text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center;">
|
||||
<CameraIcon style="font-size: 16px; margin-bottom: 4px;" />
|
||||
<div style="font-size: 12px;">{{ currentLogoUrl && !imageLoadError ? '更换Logo' : '上传Logo' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 重置按钮 -->
|
||||
<div v-if="newLogoFile">
|
||||
<Button size="small" @click="removeNewLogo">重置</Button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="店铺名称" name="name" :rules="[{ required: true, message: '请输入店铺名称' }]">
|
||||
<Input v-model:value="formData.name" placeholder="请输入店铺名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="平台" name="platform">
|
||||
<Select
|
||||
v-model:value="formData.platform"
|
||||
placeholder="请选择平台"
|
||||
:options="platformOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, onUnmounted } from 'vue';
|
||||
import { Form, Input, Modal, Select, Button, message } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import {
|
||||
uploadShopLogoApi,
|
||||
createShopApi,
|
||||
updateShopApi,
|
||||
type ShopVO,
|
||||
type ShopDTO
|
||||
} from '#/api/shop';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 创建相机图标组件
|
||||
const CameraIcon = createIconifyIcon('mdi:camera');
|
||||
|
||||
// 内部状态管理
|
||||
const visible = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentShopData = ref<ShopVO.ShopInfoVO | Partial<ShopVO.ShopInfoVO> | null>(null);
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const newLogoFile = ref<File | null>(null); // 新选择的logo文件
|
||||
const originalLogoUrl = ref(''); // 原始logo URL
|
||||
const imageLoadError = ref(false); // 图片加载错误状态
|
||||
|
||||
// 表单数据
|
||||
const formData = ref({
|
||||
name: '',
|
||||
platform: '',
|
||||
logoImageId: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 平台选项
|
||||
const platformOptions = [
|
||||
{ label: '淘宝', value: '淘宝' },
|
||||
{ label: '京东', value: '京东' },
|
||||
{ label: '拼多多', value: '拼多多' },
|
||||
{ label: '天猫', value: '天猫' },
|
||||
];
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => isEdit.value ? '编辑店铺' : '添加店铺');
|
||||
|
||||
// 当前显示的logo URL(优先显示新选择的)
|
||||
const currentLogoUrl = computed(() => {
|
||||
if (newLogoFile.value) {
|
||||
return URL.createObjectURL(newLogoFile.value);
|
||||
}
|
||||
return originalLogoUrl.value;
|
||||
});
|
||||
|
||||
// 初始化表单数据
|
||||
function initFormData() {
|
||||
if (isEdit.value && currentShopData.value) {
|
||||
// 编辑模式
|
||||
formData.value = {
|
||||
name: currentShopData.value.name || '',
|
||||
platform: currentShopData.value.platform || '',
|
||||
logoImageId: undefined,
|
||||
};
|
||||
|
||||
// 设置原始Logo URL
|
||||
originalLogoUrl.value = currentShopData.value.logo || '';
|
||||
} else {
|
||||
// 创建模式 - 如果有传入的shopData,则使用它来初始化表单
|
||||
formData.value = {
|
||||
name: currentShopData.value?.name || '',
|
||||
platform: currentShopData.value?.platform || '',
|
||||
logoImageId: undefined,
|
||||
};
|
||||
originalLogoUrl.value = currentShopData.value?.logo || '';
|
||||
}
|
||||
|
||||
// 重置新选择的logo和图片加载状态
|
||||
newLogoFile.value = null;
|
||||
imageLoadError.value = false;
|
||||
}
|
||||
|
||||
// 重置表单(在open方法中调用)
|
||||
function resetForm() {
|
||||
formRef.value?.resetFields();
|
||||
newLogoFile.value = null;
|
||||
originalLogoUrl.value = '';
|
||||
imageLoadError.value = false;
|
||||
}
|
||||
|
||||
// 处理提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
// 准备提交数据
|
||||
const submitData = { ...formData.value };
|
||||
|
||||
// 如果有新选择的logo,先上传获取ID
|
||||
if (newLogoFile.value) {
|
||||
const logoImageId = await uploadLogoAndGetId();
|
||||
if (logoImageId) {
|
||||
submitData.logoImageId = logoImageId;
|
||||
}
|
||||
} else if (!isEdit.value) {
|
||||
// 创建模式且没有选择Logo,移除logoImageId字段
|
||||
delete submitData.logoImageId;
|
||||
}
|
||||
|
||||
// 调用API
|
||||
if (isEdit.value && currentShopData.value && 'id' in currentShopData.value && currentShopData.value.id) {
|
||||
await updateShopApi(currentShopData.value.id, submitData as ShopDTO.UpdateShopDTO);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createShopApi(submitData as ShopDTO.CreateShopDTO);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
visible.value = false;
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('保存店铺失败:', error);
|
||||
message.error('保存店铺失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理取消
|
||||
function handleCancel() {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(editMode: boolean = false, shopData?: ShopVO.ShopInfoVO | Partial<ShopVO.ShopInfoVO> | null) {
|
||||
isEdit.value = editMode;
|
||||
currentShopData.value = shopData || null;
|
||||
|
||||
resetForm(); // 先重置表单
|
||||
initFormData(); // 再初始化数据
|
||||
|
||||
visible.value = true;
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
|
||||
// 选择logo文件
|
||||
function selectLogoFile() {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.accept = 'image/*';
|
||||
input.style.display = 'none';
|
||||
document.body.appendChild(input);
|
||||
|
||||
input.onchange = (e) => {
|
||||
const file = (e.target as HTMLInputElement).files?.[0];
|
||||
if (file) {
|
||||
// 验证文件
|
||||
const isImage = file.type.startsWith('image/');
|
||||
if (!isImage) {
|
||||
message.error('只能上传图片文件');
|
||||
document.body.removeChild(input);
|
||||
return;
|
||||
}
|
||||
|
||||
const isLt2M = file.size / 1024 / 1024 < 2;
|
||||
if (!isLt2M) {
|
||||
message.error('图片大小不能超过 2MB');
|
||||
document.body.removeChild(input);
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置新选择的文件
|
||||
newLogoFile.value = file;
|
||||
imageLoadError.value = false; // 重置图片加载错误状态
|
||||
message.success('Logo选择成功');
|
||||
}
|
||||
|
||||
document.body.removeChild(input);
|
||||
};
|
||||
|
||||
input.click();
|
||||
}
|
||||
|
||||
// 重置新选择的logo
|
||||
function removeNewLogo() {
|
||||
newLogoFile.value = null;
|
||||
imageLoadError.value = false; // 重置图片加载错误状态
|
||||
message.success('已重置logo');
|
||||
}
|
||||
|
||||
// 上传Logo并获取图片ID
|
||||
async function uploadLogoAndGetId(): Promise<number | undefined> {
|
||||
if (!newLogoFile.value) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await uploadShopLogoApi(newLogoFile.value);
|
||||
console.log('Logo上传成功:', response);
|
||||
return response.id;
|
||||
} catch (error) {
|
||||
console.error('Logo上传失败:', error);
|
||||
message.error('Logo上传失败');
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// 图片加载错误处理
|
||||
function handleImageError(event: Event) {
|
||||
console.error('图片加载失败:', event);
|
||||
imageLoadError.value = true;
|
||||
message.error('图片加载失败,请重新选择');
|
||||
}
|
||||
|
||||
// 组件卸载时清理
|
||||
onUnmounted(() => {
|
||||
if (newLogoFile.value) {
|
||||
const url = URL.createObjectURL(newLogoFile.value);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,248 @@
|
||||
<script lang="ts" setup>
|
||||
import { h, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, Input, Select, Table, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
deleteShopApi,
|
||||
getShopPageApi,
|
||||
type ShopVO ,
|
||||
type ShopDTO
|
||||
} from '#/api/shop';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import ShopFormModal from './components/ShopFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'ShopManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const shopList = ref<ShopVO.ShopInfoVO[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(10);
|
||||
const shopFormModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
platform: undefined as string | undefined,
|
||||
});
|
||||
|
||||
// 表单数据(已移至ShopFormModal组件)
|
||||
|
||||
// 平台选项
|
||||
const platformOptions = [
|
||||
{ label: '淘宝', value: '淘宝' },
|
||||
{ label: '京东', value: '京东' },
|
||||
{ label: '拼多多', value: '拼多多' },
|
||||
{ label: '天猫', value: '天猫' },
|
||||
];
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '店铺名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '平台',
|
||||
dataIndex: 'platform',
|
||||
key: 'platform',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
title: 'Logo',
|
||||
dataIndex: 'logo',
|
||||
key: 'logo',
|
||||
width: 200,
|
||||
customRender: ({ record }: { record: ShopVO.ShopInfoVO }) => {
|
||||
if (record.logo) {
|
||||
return h('img', {
|
||||
src: record.logo,
|
||||
alt: record.name,
|
||||
style: { width: '40px', height: '40px', objectFit: 'cover', borderRadius: '4px' },
|
||||
});
|
||||
}
|
||||
return h('span', { style: { color: '#999' } }, '暂无Logo');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '更新时间',
|
||||
dataIndex: 'updateTime',
|
||||
key: 'updateTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: ShopVO.ShopInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, { default: () => '编辑' }),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDelete(record),
|
||||
}, { default: () => '删除' }),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 获取店铺列表
|
||||
async function fetchShopList() {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<ShopDTO.ShopFiltersDTO> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
platform: searchForm.value.platform,
|
||||
},
|
||||
};
|
||||
const data = await getShopPageApi(params);
|
||||
shopList.value = data.records;
|
||||
total.value = data.total;
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error);
|
||||
message.error('获取店铺列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
function handleSearch() {
|
||||
current.value = 1;
|
||||
fetchShopList();
|
||||
}
|
||||
|
||||
// 处理重置
|
||||
function handleReset() {
|
||||
searchForm.value = {
|
||||
name: '',
|
||||
platform: undefined,
|
||||
};
|
||||
current.value = 1;
|
||||
fetchShopList();
|
||||
}
|
||||
|
||||
// 处理分页变化
|
||||
function handleTableChange(pagination: any) {
|
||||
current.value = pagination.current;
|
||||
pageSize.value = pagination.pageSize;
|
||||
fetchShopList();
|
||||
}
|
||||
|
||||
// 处理添加店铺
|
||||
function handleAdd() {
|
||||
shopFormModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑店铺
|
||||
function handleEdit(record: ShopVO.ShopInfoVO) {
|
||||
shopFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除店铺
|
||||
async function handleDelete(record: ShopVO.ShopInfoVO) {
|
||||
try {
|
||||
await deleteShopApi(record.id);
|
||||
message.success('删除成功');
|
||||
await fetchShopList();
|
||||
} catch (error) {
|
||||
console.error('删除店铺失败:', error);
|
||||
message.error('删除店铺失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模态框成功
|
||||
function handleModalSuccess() {
|
||||
fetchShopList();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
fetchShopList();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="店铺管理">
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理电商店铺信息,包括店铺基本信息、平台信息和Logo设置
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
添加店铺
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<!-- 搜索表单 -->
|
||||
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
|
||||
<div style="display: flex; gap: 16px; align-items: center; flex-wrap: wrap;">
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">店铺名称</label>
|
||||
<Input
|
||||
v-model:value="searchForm.name"
|
||||
placeholder="请输入店铺名称"
|
||||
style="width: 200px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">平台</label>
|
||||
<Select
|
||||
v-model:value="searchForm.platform"
|
||||
placeholder="请选择平台"
|
||||
style="width: 120px;"
|
||||
:options="platformOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: end;">
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="shopList"
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
@change="handleTableChange"
|
||||
/>
|
||||
|
||||
<!-- 店铺表单模态框 -->
|
||||
<ShopFormModal
|
||||
ref="shopFormModalRef"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user