mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
feat: 商品/规格删除增加影响确认,并优化列表操作列与编辑 SKU 滚动体验
This commit is contained in:
+7
@@ -11,6 +11,7 @@ import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.CreateProductResul
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.ProductFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.UpdateProductDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.UpdateProductResultDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductDeleteImpactVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.service.ProductService;
|
||||
|
||||
@@ -57,6 +58,12 @@ public class ProductController {
|
||||
return ApiResponse.<Void>success("商品删除成功", null);
|
||||
}
|
||||
|
||||
@GetMapping("/delete-impact/{id}")
|
||||
@RequirePermission(value = "ec:product:delete", description = "查看删除商品影响", allowSuper = true)
|
||||
public ApiResponse<ProductDeleteImpactVO> getDeleteImpact(@PathVariable Long id) {
|
||||
return ApiResponse.success("获取删除影响成功", productService.getDeleteImpact(id));
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@RequirePermission(value = "ec:product:read", description = "查询商品列表", allowSuper = true)
|
||||
public ApiResponse<PageResultVO<ProductVO>> getProductPage(
|
||||
|
||||
+7
@@ -13,6 +13,7 @@ import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.CreateProductSkuDT
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.ProductSkuFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.UpdateProductSkuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductSkuDeleteImpactVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductSkuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.service.ProductSkuService;
|
||||
@@ -56,6 +57,12 @@ public class ProductSkuController {
|
||||
return ApiResponse.<Void>success("SKU删除成功", null);
|
||||
}
|
||||
|
||||
@GetMapping("/delete-impact/{id}")
|
||||
@RequirePermission(value = "ec:product:delete", description = "查看删除规格影响", allowSuper = true)
|
||||
public ApiResponse<ProductSkuDeleteImpactVO> getDeleteImpact(@PathVariable Long id) {
|
||||
return ApiResponse.success("获取删除影响成功", productSkuService.getDeleteImpact(id));
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@RequirePermission(value = "ec:product:read", description = "查询商品SKU列表", allowSuper = true)
|
||||
public ApiResponse<PageResultVO<ProductSkuVO>> getProductSkuPage(
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.product.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 删除商品前的影响预览。
|
||||
*/
|
||||
@Data
|
||||
public class ProductDeleteImpactVO {
|
||||
|
||||
private Long productId;
|
||||
private String productName;
|
||||
/** 规格数(将级联删除) */
|
||||
private long skuCount;
|
||||
/** 已绑定该商品规格的订单明细数(删除后解绑,订单本身保留) */
|
||||
private long orderItemCount;
|
||||
/** 商品广告费条数(将级联删除) */
|
||||
private long adFeeCount;
|
||||
/** 刷单费条数(将解绑商品,记录保留) */
|
||||
private long fakeOrdersFeeCount;
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.product.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 删除规格前的影响预览。
|
||||
*/
|
||||
@Data
|
||||
public class ProductSkuDeleteImpactVO {
|
||||
|
||||
private Long skuId;
|
||||
private String skuName;
|
||||
private String skuCode;
|
||||
private Long productId;
|
||||
private String productName;
|
||||
/** 已绑定该规格的订单明细数(删除后解绑,订单本身保留) */
|
||||
private long orderItemCount;
|
||||
/** 成本历史条数(将级联删除) */
|
||||
private long costRecordCount;
|
||||
/** 刷单费条数(将解绑规格,记录保留) */
|
||||
private long fakeOrdersFeeCount;
|
||||
}
|
||||
+6
@@ -10,6 +10,7 @@ import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.UpdateProductDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.UpdateProductResultDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductPO;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductDeleteImpactVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductVO;
|
||||
|
||||
/**
|
||||
@@ -46,6 +47,11 @@ public interface ProductService extends IService<ProductPO> {
|
||||
*/
|
||||
void deleteProduct(Long id);
|
||||
|
||||
/**
|
||||
* 删除前影响预览
|
||||
*/
|
||||
ProductDeleteImpactVO getDeleteImpact(Long id);
|
||||
|
||||
/**
|
||||
* 分页获取商品列表
|
||||
*
|
||||
|
||||
+4
@@ -7,6 +7,7 @@ import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.CreateProductSkuDT
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.ProductSkuFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.UpdateProductSkuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductSkuDeleteImpactVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductSkuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductVO;
|
||||
|
||||
@@ -25,6 +26,9 @@ public interface ProductSkuService extends IService<ProductSkuPO> {
|
||||
|
||||
void deleteProductSku(Long id);
|
||||
|
||||
/** 删除前影响预览 */
|
||||
ProductSkuDeleteImpactVO getDeleteImpact(Long id);
|
||||
|
||||
PageResultVO<ProductSkuVO> getProductSkuPage(PageQueryDTO<ProductSkuFilterDTO> pageQueryDTO);
|
||||
|
||||
ProductSkuVO getProductSkuByProductAndSku(String productName, String skuCode);
|
||||
|
||||
+55
-2
@@ -22,11 +22,18 @@ import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.UpdateProductResul
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.UpdateProductSkuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductDeleteImpactVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductSkuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.mapper.OrderItemMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.model.po.OrderItemPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.service.OrderService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.service.ProductService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.service.ProductSkuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.adfee.mapper.AdFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.adfee.model.po.AdFeePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.fakeordersfee.mapper.FakeOrdersFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.fakeordersfee.model.po.FakeOrdersFeePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.skumigrate.service.SkuMigrateImpactService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.mapper.SysFileMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.po.SysFilePO;
|
||||
@@ -56,17 +63,26 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
||||
private final CategoryService categoryService;
|
||||
private final OrderService orderService;
|
||||
private final SkuMigrateImpactService skuMigrateImpactService;
|
||||
private final OrderItemMapper orderItemMapper;
|
||||
private final AdFeeMapper adFeeMapper;
|
||||
private final FakeOrdersFeeMapper fakeOrdersFeeMapper;
|
||||
|
||||
public ProductServiceImpl(CurrentUserContext currentUserContext, SysFileMapper sysFileMapper,
|
||||
@Lazy ProductSkuService productSkuService, @Lazy CategoryService categoryService,
|
||||
@Lazy OrderService orderService,
|
||||
SkuMigrateImpactService skuMigrateImpactService) {
|
||||
SkuMigrateImpactService skuMigrateImpactService,
|
||||
OrderItemMapper orderItemMapper,
|
||||
AdFeeMapper adFeeMapper,
|
||||
FakeOrdersFeeMapper fakeOrdersFeeMapper) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.sysFileMapper = sysFileMapper;
|
||||
this.productSkuService = productSkuService;
|
||||
this.categoryService = categoryService;
|
||||
this.orderService = orderService;
|
||||
this.skuMigrateImpactService = skuMigrateImpactService;
|
||||
this.orderItemMapper = orderItemMapper;
|
||||
this.adFeeMapper = adFeeMapper;
|
||||
this.fakeOrdersFeeMapper = fakeOrdersFeeMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -467,6 +483,43 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
||||
this.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductDeleteImpactVO getDeleteImpact(Long id) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
ProductPO product = this.getById(id);
|
||||
if (product == null || !product.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("商品不存在");
|
||||
}
|
||||
|
||||
List<ProductSkuPO> skus = productSkuService.list(new LambdaQueryWrapper<ProductSkuPO>()
|
||||
.eq(ProductSkuPO::getProductId, id)
|
||||
.eq(ProductSkuPO::getCompanyId, companyId)
|
||||
.select(ProductSkuPO::getId));
|
||||
List<Long> skuIds = skus.stream().map(ProductSkuPO::getId).filter(java.util.Objects::nonNull).toList();
|
||||
|
||||
ProductDeleteImpactVO vo = new ProductDeleteImpactVO();
|
||||
vo.setProductId(product.getId());
|
||||
vo.setProductName(product.getName());
|
||||
vo.setSkuCount(skuIds.size());
|
||||
if (skuIds.isEmpty()) {
|
||||
vo.setOrderItemCount(0L);
|
||||
} else {
|
||||
Long itemCount = orderItemMapper.selectCount(new LambdaQueryWrapper<OrderItemPO>()
|
||||
.eq(OrderItemPO::getCompanyId, companyId)
|
||||
.in(OrderItemPO::getProductSkuId, skuIds));
|
||||
vo.setOrderItemCount(itemCount == null ? 0L : itemCount);
|
||||
}
|
||||
Long adFeeCount = adFeeMapper.selectCount(new LambdaQueryWrapper<AdFeePO>()
|
||||
.eq(AdFeePO::getCompanyId, companyId)
|
||||
.eq(AdFeePO::getProductId, id));
|
||||
vo.setAdFeeCount(adFeeCount == null ? 0L : adFeeCount);
|
||||
Long fakeCount = fakeOrdersFeeMapper.selectCount(new LambdaQueryWrapper<FakeOrdersFeePO>()
|
||||
.eq(FakeOrdersFeePO::getCompanyId, companyId)
|
||||
.eq(FakeOrdersFeePO::getProductId, id));
|
||||
vo.setFakeOrdersFeeCount(fakeCount == null ? 0L : fakeCount);
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品分页列表
|
||||
* @param pageQueryDTO 分页查询DTO
|
||||
|
||||
+52
@@ -12,7 +12,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.mapper.OrderItemMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.mapper.OrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.model.po.OrderItemPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.mapper.ProductSkuCostMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.mapper.ProductSkuMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.CreateProductSkuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.ProductSkuFilterDTO;
|
||||
@@ -20,11 +23,14 @@ import top.xyquan.ecomdmbbackend.modules.ec.product.model.dto.UpdateProductSkuDT
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductSkuCostPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductSkuDeleteImpactVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductSkuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.service.ProductService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.service.ProductSkuCostService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.service.ProductSkuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.fakeordersfee.mapper.FakeOrdersFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.fakeordersfee.model.po.FakeOrdersFeePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.mapper.SysFileMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.po.SysFilePO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
@@ -49,15 +55,24 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
||||
private final ProductService productService;
|
||||
private final ProductSkuCostService productSkuCostService;
|
||||
private final OrderMapper orderMapper;
|
||||
private final OrderItemMapper orderItemMapper;
|
||||
private final ProductSkuCostMapper productSkuCostMapper;
|
||||
private final FakeOrdersFeeMapper fakeOrdersFeeMapper;
|
||||
private final SysFileMapper sysFileMapper;
|
||||
|
||||
public ProductSkuServiceImpl(CurrentUserContext currentUserContext, ProductService productService,
|
||||
ProductSkuCostService productSkuCostService, OrderMapper orderMapper,
|
||||
OrderItemMapper orderItemMapper,
|
||||
ProductSkuCostMapper productSkuCostMapper,
|
||||
FakeOrdersFeeMapper fakeOrdersFeeMapper,
|
||||
SysFileMapper sysFileMapper) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.productService = productService;
|
||||
this.productSkuCostService = productSkuCostService;
|
||||
this.orderMapper = orderMapper;
|
||||
this.orderItemMapper = orderItemMapper;
|
||||
this.productSkuCostMapper = productSkuCostMapper;
|
||||
this.fakeOrdersFeeMapper = fakeOrdersFeeMapper;
|
||||
this.sysFileMapper = sysFileMapper;
|
||||
}
|
||||
|
||||
@@ -146,6 +161,43 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
||||
this.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductSkuDeleteImpactVO getDeleteImpact(Long id) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
ProductSkuPO sku = this.getById(id);
|
||||
if (sku == null || !sku.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("商品SKU不存在");
|
||||
}
|
||||
|
||||
ProductSkuDeleteImpactVO vo = new ProductSkuDeleteImpactVO();
|
||||
vo.setSkuId(sku.getId());
|
||||
vo.setSkuName(sku.getName());
|
||||
vo.setSkuCode(sku.getSkuCode());
|
||||
vo.setProductId(sku.getProductId());
|
||||
if (sku.getProductId() != null) {
|
||||
ProductPO product = productService.getById(sku.getProductId());
|
||||
if (product != null) {
|
||||
vo.setProductName(product.getName());
|
||||
}
|
||||
}
|
||||
|
||||
Long itemCount = orderItemMapper.selectCount(new LambdaQueryWrapper<OrderItemPO>()
|
||||
.eq(OrderItemPO::getCompanyId, companyId)
|
||||
.eq(OrderItemPO::getProductSkuId, id));
|
||||
vo.setOrderItemCount(itemCount == null ? 0L : itemCount);
|
||||
|
||||
Long costCount = productSkuCostMapper.selectCount(new LambdaQueryWrapper<ProductSkuCostPO>()
|
||||
.eq(ProductSkuCostPO::getCompanyId, companyId)
|
||||
.eq(ProductSkuCostPO::getSkuId, id));
|
||||
vo.setCostRecordCount(costCount == null ? 0L : costCount);
|
||||
|
||||
Long fakeCount = fakeOrdersFeeMapper.selectCount(new LambdaQueryWrapper<FakeOrdersFeePO>()
|
||||
.eq(FakeOrdersFeePO::getCompanyId, companyId)
|
||||
.eq(FakeOrdersFeePO::getProductSkuId, id));
|
||||
vo.setFakeOrdersFeeCount(fakeCount == null ? 0L : fakeCount);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultVO<ProductSkuVO> getProductSkuPage(PageQueryDTO<ProductSkuFilterDTO> pageQueryDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
@@ -44,6 +44,15 @@ export async function deleteProductApi(id: number) {
|
||||
return requestClient.delete(`/ec/product/delete/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品前影响预览
|
||||
*/
|
||||
export async function getProductDeleteImpactApi(id: number) {
|
||||
return requestClient.get<ProductVO.DeleteImpact>(
|
||||
`/ec/product/delete-impact/${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将他品 SKU 迁入当前商品
|
||||
*/
|
||||
|
||||
@@ -35,6 +35,15 @@ export async function deleteProductSkuApi(id: number) {
|
||||
return requestClient.delete(`/ec/product-sku/delete/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除规格前影响预览
|
||||
*/
|
||||
export async function getProductSkuDeleteImpactApi(id: number) {
|
||||
return requestClient.get<ProductSkuVO.DeleteImpact>(
|
||||
`/ec/product-sku/delete-impact/${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取商品 SKU 列表
|
||||
*/
|
||||
|
||||
@@ -40,4 +40,19 @@ export namespace ProductSkuVO {
|
||||
/** 成本是否变更(本次更新中成本字段有变化) */
|
||||
costChanged?: boolean;
|
||||
}
|
||||
|
||||
/** 删除规格前影响预览 */
|
||||
export interface DeleteImpact {
|
||||
skuId: number;
|
||||
skuName: string;
|
||||
skuCode?: string;
|
||||
productId: number;
|
||||
productName: string;
|
||||
/** 已绑定该规格的订单明细数(删除后解绑,订单本身保留) */
|
||||
orderItemCount: number;
|
||||
/** 成本历史条数(将级联删除) */
|
||||
costRecordCount: number;
|
||||
/** 刷单费条数(将解绑规格,记录保留) */
|
||||
fakeOrdersFeeCount: number;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,20 @@ export namespace ProductVO {
|
||||
product: ProductVO.Info;
|
||||
}
|
||||
|
||||
/** 删除商品前影响预览 */
|
||||
export interface DeleteImpact {
|
||||
productId: number;
|
||||
productName: string;
|
||||
/** 规格数(将级联删除) */
|
||||
skuCount: number;
|
||||
/** 已绑定该商品规格的订单明细数(删除后解绑,订单本身保留) */
|
||||
orderItemCount: number;
|
||||
/** 商品广告费条数(将级联删除) */
|
||||
adFeeCount: number;
|
||||
/** 刷单费条数(将解绑商品,记录保留) */
|
||||
fakeOrdersFeeCount: number;
|
||||
}
|
||||
|
||||
/** 商品 SKU 信息 */
|
||||
export interface SkuInfo {
|
||||
/** SKU ID */
|
||||
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ProductVO } from '#/api/ec/product/types';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { Alert, Input, Modal, Spin, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
deleteProductApi,
|
||||
getProductDeleteImpactApi,
|
||||
} from '#/api/ec/product';
|
||||
|
||||
defineOptions({ name: 'ProductDeleteConfirmModal' });
|
||||
|
||||
const CONFIRM_TEXT = '确认删除';
|
||||
|
||||
const open = ref(false);
|
||||
const loadingImpact = ref(false);
|
||||
const deleting = ref(false);
|
||||
const confirmInput = ref('');
|
||||
const productId = ref<number>();
|
||||
const productName = ref('');
|
||||
const impact = ref<null | ProductVO.DeleteImpact>(null);
|
||||
|
||||
const canConfirm = computed(
|
||||
() => confirmInput.value.trim() === CONFIRM_TEXT && !deleting.value,
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
success: [];
|
||||
}>();
|
||||
|
||||
async function openModal(product: { id: number; name: string }) {
|
||||
productId.value = product.id;
|
||||
productName.value = product.name;
|
||||
confirmInput.value = '';
|
||||
impact.value = null;
|
||||
open.value = true;
|
||||
loadingImpact.value = true;
|
||||
try {
|
||||
impact.value = await getProductDeleteImpactApi(product.id);
|
||||
} catch (error) {
|
||||
console.error('获取删除影响失败:', error);
|
||||
message.error('获取删除影响失败');
|
||||
open.value = false;
|
||||
} finally {
|
||||
loadingImpact.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleCancel() {
|
||||
if (deleting.value) return;
|
||||
open.value = false;
|
||||
}
|
||||
|
||||
async function handleOk() {
|
||||
if (!canConfirm.value || productId.value == null) {
|
||||
return Promise.reject(new Error('confirm required'));
|
||||
}
|
||||
deleting.value = true;
|
||||
try {
|
||||
await deleteProductApi(productId.value);
|
||||
message.success('删除成功');
|
||||
open.value = false;
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('删除商品失败:', error);
|
||||
message.error('删除商品失败');
|
||||
return Promise.reject(error);
|
||||
} finally {
|
||||
deleting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ open: openModal });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="open"
|
||||
title="删除商品"
|
||||
ok-text="永久删除"
|
||||
ok-type="danger"
|
||||
:ok-button-props="{ disabled: !canConfirm, loading: deleting }"
|
||||
:cancel-button-props="{ disabled: deleting }"
|
||||
:mask-closable="!deleting"
|
||||
destroy-on-close
|
||||
@ok="handleOk"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<Spin :spinning="loadingImpact">
|
||||
<Alert
|
||||
type="error"
|
||||
show-icon
|
||||
class="mb-4"
|
||||
message="此操作不可恢复"
|
||||
description="将永久删除该商品及其规格、广告费等;已关联订单明细会解绑规格(订单本身保留)。"
|
||||
/>
|
||||
|
||||
<p class="mb-2 text-sm">
|
||||
即将删除商品
|
||||
<strong>{{ productName || impact?.productName }}</strong>
|
||||
(ID: {{ productId }})
|
||||
</p>
|
||||
|
||||
<ul class="mb-4 list-disc space-y-1 pl-5 text-sm text-muted-foreground">
|
||||
<li>规格:{{ impact?.skuCount ?? '—' }} 个(将一并删除)</li>
|
||||
<li>
|
||||
订单明细:{{ impact?.orderItemCount ?? '—' }} 条(解绑规格,不删订单)
|
||||
</li>
|
||||
<li>商品广告费:{{ impact?.adFeeCount ?? '—' }} 条(将删除)</li>
|
||||
<li>
|
||||
刷单费:{{ impact?.fakeOrdersFeeCount ?? '—' }} 条(解绑商品,记录保留)
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p class="mb-2 text-sm">
|
||||
请在下方输入框中输入
|
||||
<span class="font-semibold text-red-500">{{ CONFIRM_TEXT }}</span>
|
||||
以确认删除:
|
||||
</p>
|
||||
<Input
|
||||
v-model:value="confirmInput"
|
||||
:placeholder="`请输入 ${CONFIRM_TEXT}`"
|
||||
:disabled="deleting || loadingImpact"
|
||||
allow-clear
|
||||
@press-enter="handleOk"
|
||||
/>
|
||||
</Spin>
|
||||
</Modal>
|
||||
</template>
|
||||
+21
-3
@@ -8,7 +8,7 @@ import { useRouter } from 'vue-router';
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, Image, Space, Table } from 'ant-design-vue';
|
||||
import { Button, Image, Space, Table, Tooltip } from 'ant-design-vue';
|
||||
|
||||
defineOptions({ name: 'ProductDetailModal' });
|
||||
|
||||
@@ -27,6 +27,22 @@ const emit = defineEmits<{
|
||||
/** 金额展示 */
|
||||
const formatCost = (val?: number) => `¥${(val ?? 0).toFixed(2)}`;
|
||||
|
||||
/** 省略单元格:悬停 Tooltip 展示完整内容 */
|
||||
function renderEllipsisText(text?: null | string) {
|
||||
const display = text?.trim() ? text : '-';
|
||||
if (display === '-') {
|
||||
return display;
|
||||
}
|
||||
return h(
|
||||
Tooltip,
|
||||
{ title: display, placement: 'topLeft' },
|
||||
{
|
||||
default: () =>
|
||||
h('span', { class: 'block max-w-full truncate' }, display),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const skuDataSource = computed(() => product.value?.skus ?? []);
|
||||
|
||||
const skuColumns = [
|
||||
@@ -56,13 +72,15 @@ const skuColumns = [
|
||||
dataIndex: 'skuCode',
|
||||
key: 'skuCode',
|
||||
width: 140,
|
||||
customRender: ({ text }: { text?: string }) => text || '-',
|
||||
ellipsis: true,
|
||||
customRender: ({ text }: { text?: string }) => renderEllipsisText(text),
|
||||
},
|
||||
{
|
||||
title: 'SKU 名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
ellipsis: true,
|
||||
customRender: ({ text }: { text?: string }) => renderEllipsisText(text),
|
||||
},
|
||||
{
|
||||
title: '商品成本',
|
||||
@@ -100,7 +118,7 @@ const skuColumns = [
|
||||
dataIndex: 'remark',
|
||||
key: 'remark',
|
||||
ellipsis: true,
|
||||
customRender: ({ text }: { text?: string }) => text || '-',
|
||||
customRender: ({ text }: { text?: string }) => renderEllipsisText(text),
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
+217
-174
@@ -2,7 +2,7 @@
|
||||
import type { ProductDTO, ProductVO } from '#/api/ec/product/types';
|
||||
|
||||
import type { DropdownRender } from 'ant-design-vue/es/vc-select/BaseSelect';
|
||||
import { computed, h, onUnmounted, ref } from 'vue';
|
||||
import { computed, h, nextTick, onUnmounted, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
@@ -25,6 +25,7 @@ import { uploadFile } from '#/utils/upload-file';
|
||||
import CategoryFormModal from '#/views/ec/product/category/components/CategoryFormModal.vue';
|
||||
import ProductCostSyncToOrdersModal from './ProductCostSyncToOrdersModal.vue';
|
||||
import ProductSkuCostDrawer from './ProductSkuCostDrawer.vue';
|
||||
import ProductSkuDeleteConfirmModal from './ProductSkuDeleteConfirmModal.vue';
|
||||
import ProductSkuMigrateImpactModal from './ProductSkuMigrateImpactModal.vue';
|
||||
import ProductSkuMigrateModal from './ProductSkuMigrateModal.vue';
|
||||
|
||||
@@ -36,17 +37,18 @@ defineOptions({ name: 'ProductFormModal' });
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 创建Vben Modal实例
|
||||
// 创建Vben Modal实例:内容区不滚动,由 SKU 列表占满剩余高度并独立滚动
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
title: '添加商品',
|
||||
class: 'w-[1100px]',
|
||||
draggable: true, // 开启拖拽
|
||||
contentClass: 'px-5 py-4',
|
||||
// max-h 用 vh:百分比相对父级高度常无效,会导致模态框被内容无限撑高、内部无法滚动
|
||||
class: 'w-[1100px] max-h-[80vh]',
|
||||
draggable: true,
|
||||
contentClass:
|
||||
'flex min-h-0 flex-1 flex-col overflow-hidden px-5 py-4',
|
||||
onConfirm: handleSubmit,
|
||||
onCancel: close,
|
||||
onOpenChange: (isOpen: boolean) => {
|
||||
if (isOpen) {
|
||||
// 打开时不做操作
|
||||
return;
|
||||
}
|
||||
resetForm();
|
||||
@@ -72,6 +74,11 @@ const productSkuMigrateModalRef = ref<InstanceType<
|
||||
const productSkuMigrateImpactModalRef = ref<InstanceType<
|
||||
typeof ProductSkuMigrateImpactModal
|
||||
> | null>(null);
|
||||
const productSkuDeleteModalRef = ref<InstanceType<
|
||||
typeof ProductSkuDeleteConfirmModal
|
||||
> | null>(null);
|
||||
/** SKU 列表滚动容器:新增行后滚到底 */
|
||||
const skuListScrollRef = ref<HTMLElement | null>(null);
|
||||
|
||||
async function openSyncModal(skuIds: number[]) {
|
||||
await productCostSyncModalRef.value?.open(skuIds, {
|
||||
@@ -595,18 +602,43 @@ function onMigrateSuccess(product: ProductVO.Info) {
|
||||
emit('success');
|
||||
}
|
||||
|
||||
// 添加 SKU
|
||||
function addSku() {
|
||||
// 添加 SKU:展开列表并滚到最底部,方便继续编辑新行
|
||||
async function addSku() {
|
||||
showSkus.value = true;
|
||||
skus.value.push(defaultSku());
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
const el = skuListScrollRef.value;
|
||||
if (!el) return;
|
||||
el.scrollTo({ top: el.scrollHeight, behavior: 'smooth' });
|
||||
}
|
||||
|
||||
// 删除规格
|
||||
// 删除规格:未落库直接移除;已落库先确认影响,保存商品时再真正删除
|
||||
function removeSku(index: number) {
|
||||
const row = skus.value[index];
|
||||
if (row) {
|
||||
if (!row) return;
|
||||
|
||||
if (!isPersistedSkuId(row.id)) {
|
||||
revokeSkuPreview(row);
|
||||
skus.value.splice(index, 1);
|
||||
return;
|
||||
}
|
||||
skus.value.splice(index, 1);
|
||||
|
||||
productSkuDeleteModalRef.value?.open(
|
||||
{ id: Number(row.id), name: row.name },
|
||||
{
|
||||
deferDelete: true,
|
||||
onConfirmed: () => {
|
||||
const i = skus.value.findIndex((s) => s.id === row.id);
|
||||
if (i < 0) return;
|
||||
const current = skus.value[i];
|
||||
if (current) {
|
||||
revokeSkuPreview(current);
|
||||
}
|
||||
skus.value.splice(i, 1);
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function revokeSkuPreview(row: SkuFormRow) {
|
||||
@@ -854,7 +886,7 @@ const skuColumns = [
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 80,
|
||||
width: 48,
|
||||
align: 'center' as const,
|
||||
customRender: ({ index }: { index: number }) => {
|
||||
return h(
|
||||
@@ -863,10 +895,10 @@ const skuColumns = [
|
||||
type: 'text',
|
||||
danger: true,
|
||||
size: 'small',
|
||||
title: '删除',
|
||||
onClick: () => removeSku(index),
|
||||
},
|
||||
{
|
||||
default: () => '删除',
|
||||
icon: () => h(TrashIcon, { class: 'h-4 w-4' }),
|
||||
},
|
||||
);
|
||||
@@ -926,136 +958,145 @@ onUnmounted(() => {
|
||||
|
||||
<template>
|
||||
<Modal>
|
||||
<Form ref="formRef" :model="formData">
|
||||
<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
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
class="flex min-h-0 flex-1 flex-col overflow-hidden"
|
||||
>
|
||||
<div class="shrink-0">
|
||||
<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;
|
||||
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;
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
line-height: 1.2;
|
||||
"
|
||||
>
|
||||
<CameraIcon style="font-size: 16px; margin-bottom: 4px" />
|
||||
<div style="font-size: 12px">
|
||||
{{
|
||||
currentImageUrl && !imageLoadError ? '更换主图' : '上传主图'
|
||||
}}
|
||||
<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>
|
||||
|
||||
<!-- 重置按钮 -->
|
||||
<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
|
||||
label="商品名称"
|
||||
name="name"
|
||||
:rules="[{ required: true, message: '请输入商品名称' }]"
|
||||
>
|
||||
<Input v-model:value="formData.name" placeholder="请输入商品名称" />
|
||||
</Form.Item>
|
||||
<Form.Item label="商品编码" name="productCode">
|
||||
<Input
|
||||
v-model:value="formData.productCode"
|
||||
placeholder="请输入商品编码"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="商品编码" name="productCode">
|
||||
<Input
|
||||
v-model:value="formData.productCode"
|
||||
placeholder="请输入商品编码"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="商品类目" name="categoryId" class="!mb-3">
|
||||
<TreeSelect
|
||||
v-model:value="formData.categoryId"
|
||||
placeholder="请选择商品类目"
|
||||
:tree-data="categoryOptions"
|
||||
:field-names="{ label: 'name', value: 'id', children: 'children' }"
|
||||
:dropdown-render="categoryTreeDropdownRender"
|
||||
allow-clear
|
||||
tree-default-expand-all
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
<Form.Item label="商品类目" name="categoryId">
|
||||
<TreeSelect
|
||||
v-model:value="formData.categoryId"
|
||||
placeholder="请选择商品类目"
|
||||
:tree-data="categoryOptions"
|
||||
:field-names="{ label: 'name', value: 'id', children: 'children' }"
|
||||
:dropdown-render="categoryTreeDropdownRender"
|
||||
allow-clear
|
||||
tree-default-expand-all
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<!-- 规格管理 -->
|
||||
<Form.Item label="商品 SKU">
|
||||
<div class="space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<!-- 规格管理:不用 Form.Item,避免栅格打断滚动高度链 -->
|
||||
<div class="flex min-h-0 flex-1 flex-col gap-3 overflow-hidden">
|
||||
<div class="flex shrink-0 items-center justify-between gap-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="shrink-0 text-sm text-foreground/80">商品 SKU</span>
|
||||
<Space>
|
||||
<Button type="dashed" @click="showSkus = !showSkus">
|
||||
<template #icon>
|
||||
@@ -1064,7 +1105,7 @@ onUnmounted(() => {
|
||||
class="h-4 w-4"
|
||||
/>
|
||||
</template>
|
||||
{{ showSkus ? '收起 SKU' : '添加 SKU' }}
|
||||
{{ showSkus ? '收起 SKU' : '展开 SKU' }}
|
||||
</Button>
|
||||
<Button
|
||||
v-if="isEdit && currentProductData?.id"
|
||||
@@ -1074,55 +1115,56 @@ onUnmounted(() => {
|
||||
管理成本
|
||||
</Button>
|
||||
</Space>
|
||||
<Space v-if="showSkus">
|
||||
<Button
|
||||
v-if="isEdit && currentProductData?.id"
|
||||
@click="openMigrateModal"
|
||||
>
|
||||
迁入他品 SKU
|
||||
</Button>
|
||||
<Button
|
||||
v-if="isEdit && currentProductData?.id"
|
||||
@click="openMigrateImpactModal"
|
||||
>
|
||||
迁品待重算
|
||||
</Button>
|
||||
<Button type="primary" @click="addSku">
|
||||
<template #icon>
|
||||
<PlusIcon class="h-4 w-4" />
|
||||
</template>
|
||||
添加 SKU
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
<p
|
||||
v-if="isEdit && showSkus"
|
||||
class="text-xs text-slate-400"
|
||||
>
|
||||
已有 SKU 的成本只读;调价请点「管理成本」。新增 SKU 仍可填初始成本。
|
||||
</p>
|
||||
|
||||
<div
|
||||
v-if="showSkus"
|
||||
class="rounded-lg border border-gray-200 bg-white p-4 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_14%)]"
|
||||
>
|
||||
<Table
|
||||
:columns="skuColumns"
|
||||
:data-source="skus"
|
||||
:pagination="false"
|
||||
:row-key="(r: SkuFormRow) => (isPersistedSkuId(r.id) ? String(r.id) : r._clientKey ?? '')"
|
||||
:scroll="{ x: 980 }"
|
||||
size="small"
|
||||
<Space v-if="showSkus">
|
||||
<Button
|
||||
v-if="isEdit && currentProductData?.id"
|
||||
@click="openMigrateModal"
|
||||
>
|
||||
<template #emptyText>
|
||||
<div class="py-4 text-center text-gray-400">
|
||||
暂无 SKU,点击上方"添加 SKU"按钮添加
|
||||
</div>
|
||||
迁入他品 SKU
|
||||
</Button>
|
||||
<Button
|
||||
v-if="isEdit && currentProductData?.id"
|
||||
@click="openMigrateImpactModal"
|
||||
>
|
||||
迁品待重算
|
||||
</Button>
|
||||
<Button type="primary" @click="addSku">
|
||||
<template #icon>
|
||||
<PlusIcon class="h-4 w-4" />
|
||||
</template>
|
||||
</Table>
|
||||
</div>
|
||||
添加 SKU
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
</Form.Item>
|
||||
<p
|
||||
v-if="isEdit && showSkus"
|
||||
class="shrink-0 text-xs text-slate-400"
|
||||
>
|
||||
已有 SKU 的成本只读;调价请点「管理成本」。新增 SKU 仍可填初始成本。
|
||||
</p>
|
||||
|
||||
<div
|
||||
v-if="showSkus"
|
||||
ref="skuListScrollRef"
|
||||
class="min-h-0 flex-1 overflow-y-auto rounded-lg border border-gray-200 bg-white p-4 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_14%)]"
|
||||
>
|
||||
<Table
|
||||
:columns="skuColumns"
|
||||
:data-source="skus"
|
||||
:pagination="false"
|
||||
:row-key="(r: SkuFormRow) => (isPersistedSkuId(r.id) ? String(r.id) : r._clientKey ?? '')"
|
||||
:scroll="{ x: 980 }"
|
||||
size="small"
|
||||
>
|
||||
<template #emptyText>
|
||||
<div class="py-4 text-center text-gray-400">
|
||||
暂无 SKU,点击上方"添加 SKU"按钮添加
|
||||
</div>
|
||||
</template>
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
@@ -1137,5 +1179,6 @@ onUnmounted(() => {
|
||||
@success="onMigrateSuccess"
|
||||
/>
|
||||
<ProductSkuMigrateImpactModal ref="productSkuMigrateImpactModalRef" />
|
||||
<ProductSkuDeleteConfirmModal ref="productSkuDeleteModalRef" />
|
||||
<CategoryFormModal ref="categoryFormModalRef" @success="reloadCategoryTree" />
|
||||
</template>
|
||||
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ProductSkuVO } from '#/api/ec/product/sku/types';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { Alert, Input, Modal, Spin, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
deleteProductSkuApi,
|
||||
getProductSkuDeleteImpactApi,
|
||||
} from '#/api/ec/product/sku';
|
||||
|
||||
defineOptions({ name: 'ProductSkuDeleteConfirmModal' });
|
||||
|
||||
const CONFIRM_TEXT = '确认删除';
|
||||
|
||||
const open = ref(false);
|
||||
const loadingImpact = ref(false);
|
||||
const deleting = ref(false);
|
||||
const confirmInput = ref('');
|
||||
const skuId = ref<number>();
|
||||
const skuName = ref('');
|
||||
/** true:仅从编辑列表移除,保存商品时再真正删除 */
|
||||
const deferDelete = ref(false);
|
||||
const impact = ref<null | ProductSkuVO.DeleteImpact>(null);
|
||||
let onConfirmed: (() => void) | undefined;
|
||||
|
||||
const canConfirm = computed(
|
||||
() => confirmInput.value.trim() === CONFIRM_TEXT && !deleting.value,
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
success: [];
|
||||
}>();
|
||||
|
||||
async function openModal(
|
||||
sku: { id: number; name?: string },
|
||||
options?: { deferDelete?: boolean; onConfirmed?: () => void },
|
||||
) {
|
||||
skuId.value = sku.id;
|
||||
skuName.value = sku.name ?? '';
|
||||
deferDelete.value = Boolean(options?.deferDelete);
|
||||
onConfirmed = options?.onConfirmed;
|
||||
confirmInput.value = '';
|
||||
impact.value = null;
|
||||
open.value = true;
|
||||
loadingImpact.value = true;
|
||||
try {
|
||||
impact.value = await getProductSkuDeleteImpactApi(sku.id);
|
||||
} catch (error) {
|
||||
console.error('获取删除影响失败:', error);
|
||||
message.error('获取删除影响失败');
|
||||
open.value = false;
|
||||
} finally {
|
||||
loadingImpact.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleCancel() {
|
||||
if (deleting.value) return;
|
||||
open.value = false;
|
||||
}
|
||||
|
||||
async function handleOk() {
|
||||
if (!canConfirm.value || skuId.value == null) {
|
||||
return Promise.reject(new Error('confirm required'));
|
||||
}
|
||||
deleting.value = true;
|
||||
try {
|
||||
if (!deferDelete.value) {
|
||||
await deleteProductSkuApi(skuId.value);
|
||||
message.success('删除成功');
|
||||
emit('success');
|
||||
}
|
||||
onConfirmed?.();
|
||||
open.value = false;
|
||||
} catch (error) {
|
||||
console.error('删除规格失败:', error);
|
||||
message.error('删除规格失败');
|
||||
return Promise.reject(error);
|
||||
} finally {
|
||||
deleting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ open: openModal });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="open"
|
||||
title="删除规格"
|
||||
:ok-text="deferDelete ? '确认移除' : '永久删除'"
|
||||
ok-type="danger"
|
||||
:ok-button-props="{ disabled: !canConfirm, loading: deleting }"
|
||||
:cancel-button-props="{ disabled: deleting }"
|
||||
:mask-closable="!deleting"
|
||||
destroy-on-close
|
||||
@ok="handleOk"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<Spin :spinning="loadingImpact">
|
||||
<Alert
|
||||
type="error"
|
||||
show-icon
|
||||
class="mb-4"
|
||||
:message="deferDelete ? '保存商品后才会真正删除' : '此操作不可恢复'"
|
||||
:description="
|
||||
deferDelete
|
||||
? '确认后将从当前编辑列表移除该规格;保存商品时才会真正删除。已关联订单明细会解绑规格(订单本身保留)。'
|
||||
: '将永久删除该规格及其成本历史;已关联订单明细会解绑规格(订单本身保留)。'
|
||||
"
|
||||
/>
|
||||
|
||||
<p class="mb-2 text-sm">
|
||||
即将删除规格
|
||||
<strong>{{ skuName || impact?.skuName }}</strong>
|
||||
<template v-if="impact?.skuCode">(编码:{{ impact.skuCode }})</template>
|
||||
(ID: {{ skuId }})
|
||||
</p>
|
||||
<p v-if="impact?.productName" class="mb-2 text-sm text-muted-foreground">
|
||||
所属商品:{{ impact.productName }}
|
||||
</p>
|
||||
|
||||
<ul class="mb-4 list-disc space-y-1 pl-5 text-sm text-muted-foreground">
|
||||
<li>
|
||||
订单明细:{{ impact?.orderItemCount ?? '—' }} 条(解绑规格,不删订单)
|
||||
</li>
|
||||
<li>成本历史:{{ impact?.costRecordCount ?? '—' }} 条(将删除)</li>
|
||||
<li>
|
||||
刷单费:{{ impact?.fakeOrdersFeeCount ?? '—' }} 条(解绑规格,记录保留)
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p class="mb-2 text-sm">
|
||||
请在下方输入框中输入
|
||||
<span class="font-semibold text-red-500">{{ CONFIRM_TEXT }}</span>
|
||||
以确认删除:
|
||||
</p>
|
||||
<Input
|
||||
v-model:value="confirmInput"
|
||||
:placeholder="`请输入 ${CONFIRM_TEXT}`"
|
||||
:disabled="deleting || loadingImpact"
|
||||
allow-clear
|
||||
@press-enter="handleOk"
|
||||
/>
|
||||
</Spin>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -9,13 +9,25 @@ import { useRouter } from 'vue-router';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { getPopupContainer } from '@vben/utils';
|
||||
|
||||
import { Button, Image, message, Popconfirm, Space, Tag } from 'ant-design-vue';
|
||||
import type { MenuProps } from 'ant-design-vue';
|
||||
import {
|
||||
Button,
|
||||
Dropdown,
|
||||
Image,
|
||||
Menu,
|
||||
Space,
|
||||
Tag,
|
||||
message,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { deleteProductApi, getProductPageApi } from '#/api/ec/product';
|
||||
import { getProductPageApi } from '#/api/ec/product';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
import { usePermission } from '#/composables/use-permission';
|
||||
|
||||
import ProductDeleteConfirmModal from './components/ProductDeleteConfirmModal.vue';
|
||||
import ProductDetailModal from './components/ProductDetailModal.vue';
|
||||
import ProductFormModal from './components/ProductFormModal.vue';
|
||||
import ProductSkuCostDrawer from './components/ProductSkuCostDrawer.vue';
|
||||
@@ -23,10 +35,15 @@ import ProductSkuCostDrawer from './components/ProductSkuCostDrawer.vue';
|
||||
defineOptions({ name: 'ProductManagement' });
|
||||
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const ChartIcon = createIconifyIcon('lucide:line-chart');
|
||||
const EditIcon = createIconifyIcon('lucide:square-pen');
|
||||
const CoinsIcon = createIconifyIcon('lucide:coins');
|
||||
const ImageIcon = createIconifyIcon('lucide:image');
|
||||
const MoreIcon = createIconifyIcon('lucide:ellipsis');
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
|
||||
/** 操作列下拉挂到 body,避免 VXE 固定列 overflow 裁切 */
|
||||
function getActionPopupContainer(node?: HTMLElement) {
|
||||
return document.body || getPopupContainer(node);
|
||||
}
|
||||
|
||||
const router = useRouter();
|
||||
const loading = ref(false);
|
||||
@@ -39,6 +56,9 @@ const productDetailModalRef = ref<InstanceType<typeof ProductDetailModal> | null
|
||||
const productSkuCostDrawerRef = ref<InstanceType<
|
||||
typeof ProductSkuCostDrawer
|
||||
> | null>(null);
|
||||
const productDeleteModalRef = ref<InstanceType<
|
||||
typeof ProductDeleteConfirmModal
|
||||
> | null>(null);
|
||||
|
||||
/** 列表行内最多展示的 SKU 编码标签数 */
|
||||
const MAX_SKU_CODE_TAGS = 4;
|
||||
@@ -113,8 +133,9 @@ const gridOptions: VxeGridProps<ProductVO.Info> = {
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 260,
|
||||
width: 168,
|
||||
fixed: 'right' as const,
|
||||
showOverflow: false,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
@@ -301,14 +322,41 @@ function goToOverview(record: ProductVO.Info) {
|
||||
router.push(`/ec/product/overview/${record.id}`);
|
||||
}
|
||||
|
||||
async function handleDelete(record: ProductVO.Info) {
|
||||
try {
|
||||
await deleteProductApi(record.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('删除商品失败:', error);
|
||||
message.error('删除商品失败');
|
||||
function handleDelete(record: ProductVO.Info) {
|
||||
productDeleteModalRef.value?.open({ id: record.id, name: record.name });
|
||||
}
|
||||
|
||||
/** 操作列「更多」菜单:次要操作收纳,避免窄屏固定列裁切 */
|
||||
function getMoreMenuItems(): MenuProps['items'] {
|
||||
const items: NonNullable<MenuProps['items']> = [];
|
||||
if (hasPermission('ec:product:update')) {
|
||||
items.push({ key: 'cost', label: '成本' });
|
||||
}
|
||||
items.push({ key: 'overview', label: '统计' });
|
||||
if (hasPermission('ec:product:delete')) {
|
||||
items.push({ type: 'divider' });
|
||||
items.push({ key: 'delete', label: '删除', danger: true });
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
function onMoreMenuClick(
|
||||
row: ProductVO.Info,
|
||||
info: { key: string | number },
|
||||
) {
|
||||
switch (String(info.key)) {
|
||||
case 'cost': {
|
||||
handleCost(row);
|
||||
break;
|
||||
}
|
||||
case 'overview': {
|
||||
goToOverview(row);
|
||||
break;
|
||||
}
|
||||
case 'delete': {
|
||||
handleDelete(row);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,39 +445,39 @@ function handleDetailEdit(record: ProductVO.Info) {
|
||||
</template>
|
||||
|
||||
<template #action="{ row }: { row: ProductVO.Info }">
|
||||
<Space :size="4">
|
||||
<Space :size="0" class="flex-nowrap whitespace-nowrap">
|
||||
<Button type="link" size="small" @click="openProductDetail(row)">
|
||||
详情
|
||||
</Button>
|
||||
<PermissionGate code="ec:product:update">
|
||||
<Button type="link" size="small" @click="handleEdit(row)">
|
||||
<EditIcon class="mr-0.5 h-3.5 w-3.5" />
|
||||
编辑
|
||||
</Button>
|
||||
<Button type="link" size="small" @click="handleCost(row)">
|
||||
<CoinsIcon class="mr-0.5 h-3.5 w-3.5" />
|
||||
成本
|
||||
</PermissionGate>
|
||||
<Dropdown
|
||||
:trigger="['click']"
|
||||
:get-popup-container="getActionPopupContainer"
|
||||
>
|
||||
<Button type="link" size="small" @click.prevent>
|
||||
更多
|
||||
<MoreIcon class="ml-0.5 inline h-3.5 w-3.5 align-[-2px]" />
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<Button type="link" size="small" @click="goToOverview(row)">
|
||||
<ChartIcon class="mr-0.5 h-3.5 w-3.5" />
|
||||
统计
|
||||
</Button>
|
||||
<PermissionGate code="ec:product:delete">
|
||||
<Popconfirm
|
||||
title="确定删除该商品吗?删除后不可恢复。"
|
||||
ok-text="确定删除"
|
||||
cancel-text="取消"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button type="link" size="small" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</PermissionGate>
|
||||
<template #overlay>
|
||||
<Menu
|
||||
:items="getMoreMenuItems()"
|
||||
@click="(info) => onMoreMenuClick(row, info)"
|
||||
/>
|
||||
</template>
|
||||
</Dropdown>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<ProductFormModal ref="productFormModalRef" @success="handleModalSuccess" />
|
||||
<ProductDeleteConfirmModal
|
||||
ref="productDeleteModalRef"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
<ProductDetailModal
|
||||
ref="productDetailModalRef"
|
||||
@edit="handleDetailEdit"
|
||||
|
||||
Reference in New Issue
Block a user