mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 21:49:18 +08:00
feat: 发货物流增加发货仓商品页支持按仓查看与批量分配 SKU
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
-- 发货物流:发货仓商品(仓×SKU 默认分配)
|
||||||
|
|
||||||
|
-- 侧栏顺序:发货仓库 → 发货仓商品 → 快递报价
|
||||||
|
UPDATE `sys_menu` SET `order` = 1 WHERE `id` = 14020 OR `route_name` = 'WarehouseManagement';
|
||||||
|
UPDATE `sys_menu` SET `order` = 3 WHERE `id` = 14021 OR `route_name` = 'ExpressQuoteManagement';
|
||||||
|
|
||||||
|
INSERT INTO `sys_menu` (
|
||||||
|
`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`,
|
||||||
|
`redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
14023,
|
||||||
|
(SELECT id FROM `sys_menu` WHERE `id` = 14019 OR `route_name` = 'FreightCatalog' LIMIT 1),
|
||||||
|
0,
|
||||||
|
'WarehouseSkuManagement',
|
||||||
|
'发货仓商品',
|
||||||
|
'/ec/warehouse/sku',
|
||||||
|
'/ec/warehouse/sku/index',
|
||||||
|
'',
|
||||||
|
'lucide:boxes',
|
||||||
|
'menu',
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
FROM DUAL
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1 FROM `sys_menu` WHERE `id` = 14023 OR `route_name` = 'WarehouseSkuManagement'
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 复用发货仓库读写权限
|
||||||
|
INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`)
|
||||||
|
SELECT m.id, p.id
|
||||||
|
FROM `sys_menu` m
|
||||||
|
JOIN `sys_permission` p ON p.code IN ('ec:warehouse:read', 'ec:warehouse:update')
|
||||||
|
WHERE m.route_name = 'WarehouseSkuManagement' OR m.id = 14023;
|
||||||
|
|
||||||
|
-- 已开通发货物流或发货仓库的公司同步开通
|
||||||
|
INSERT IGNORE INTO `org_company_menu` (`company_id`, `menu_id`, `status`)
|
||||||
|
SELECT DISTINCT cm.`company_id`, 14023, 1
|
||||||
|
FROM `org_company_menu` cm
|
||||||
|
WHERE cm.`menu_id` IN (14019, 14020);
|
||||||
|
|
||||||
|
INSERT IGNORE INTO `org_position_menu` (`position_id`, `menu_id`)
|
||||||
|
SELECT DISTINCT pm.`position_id`, 14023
|
||||||
|
FROM `org_position_menu` pm
|
||||||
|
WHERE pm.`menu_id` IN (14019, 14020);
|
||||||
+6
@@ -21,4 +21,10 @@ public class ProductSkuFilterDTO {
|
|||||||
|
|
||||||
/** 模糊匹配:SKU 名称、SKU 编码、所属商品名称、商品编码 */
|
/** 模糊匹配:SKU 名称、SKU 编码、所属商品名称、商品编码 */
|
||||||
private String keywords;
|
private String keywords;
|
||||||
|
|
||||||
|
/** 默认发货仓;与 unassignedOnly 互斥(未分配优先) */
|
||||||
|
private Long warehouseId;
|
||||||
|
|
||||||
|
/** true = 仅未分配发货仓(warehouse_id IS NULL) */
|
||||||
|
private Boolean unassignedOnly;
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -239,6 +239,11 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
|||||||
if (filter.getExcludeProductId() != null) {
|
if (filter.getExcludeProductId() != null) {
|
||||||
wrapper.ne(ProductSkuPO::getProductId, filter.getExcludeProductId());
|
wrapper.ne(ProductSkuPO::getProductId, filter.getExcludeProductId());
|
||||||
}
|
}
|
||||||
|
if (Boolean.TRUE.equals(filter.getUnassignedOnly())) {
|
||||||
|
wrapper.isNull(ProductSkuPO::getWarehouseId);
|
||||||
|
} else if (filter.getWarehouseId() != null) {
|
||||||
|
wrapper.eq(ProductSkuPO::getWarehouseId, filter.getWarehouseId());
|
||||||
|
}
|
||||||
if (filter.getKeywords() != null && !filter.getKeywords().trim().isEmpty()) {
|
if (filter.getKeywords() != null && !filter.getKeywords().trim().isEmpty()) {
|
||||||
String keywords = filter.getKeywords().trim();
|
String keywords = filter.getKeywords().trim();
|
||||||
LambdaQueryWrapper<ProductPO> productKw = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<ProductPO> productKw = new LambdaQueryWrapper<>();
|
||||||
|
|||||||
+24
-1
@@ -6,14 +6,16 @@ import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
|||||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.vo.ProductSkuVO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.WarehouseDtos;
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.WarehouseDtos;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseExpressBindVO;
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseExpressBindVO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseVO;
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseVO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.WarehouseService;
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.WarehouseService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/** 发货仓库与报价绑定。 */
|
/** 发货仓库、报价绑定与仓商品。 */
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/ec/warehouse")
|
@RequestMapping("/api/ec/warehouse")
|
||||||
public class WarehouseController {
|
public class WarehouseController {
|
||||||
@@ -86,4 +88,25 @@ public class WarehouseController {
|
|||||||
warehouseService.removeBind(bindId);
|
warehouseService.removeBind(bindId);
|
||||||
return ApiResponse.success("已解绑");
|
return ApiResponse.success("已解绑");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/skus/list")
|
||||||
|
@RequirePermission(value = "ec:warehouse:read", description = "发货仓商品列表", allowSuper = true)
|
||||||
|
public ApiResponse<PageResultVO<ProductSkuVO>> skuList(
|
||||||
|
@Valid @RequestBody PageQueryDTO<WarehouseDtos.SkuFilter> query) {
|
||||||
|
return ApiResponse.success("获取成功", warehouseService.pageSkus(query));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/skus/unassigned-count")
|
||||||
|
@RequirePermission(value = "ec:warehouse:read", description = "未分配 SKU 数", allowSuper = true)
|
||||||
|
public ApiResponse<Map<String, Long>> unassignedSkuCount() {
|
||||||
|
return ApiResponse.success("获取成功", Map.of("count", warehouseService.countUnassignedSkus()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/skus/batch-assign")
|
||||||
|
@RequirePermission(value = "ec:warehouse:update", description = "批量分配发货仓", allowSuper = true)
|
||||||
|
public ApiResponse<Map<String, Integer>> batchAssignSkus(
|
||||||
|
@Valid @RequestBody WarehouseDtos.SkuBatchAssign dto) {
|
||||||
|
int updated = warehouseService.batchAssignSkus(dto);
|
||||||
|
return ApiResponse.success("分配成功", Map.of("updated", updated));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+21
@@ -1,9 +1,12 @@
|
|||||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto;
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/** 仓库相关 DTO。 */
|
/** 仓库相关 DTO。 */
|
||||||
public final class WarehouseDtos {
|
public final class WarehouseDtos {
|
||||||
|
|
||||||
@@ -55,4 +58,22 @@ public final class WarehouseDtos {
|
|||||||
private Integer priority;
|
private Integer priority;
|
||||||
private Integer status;
|
private Integer status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 发货仓商品列表筛选(走仓权限,内部复用 SKU 查询) */
|
||||||
|
@Data
|
||||||
|
public static class SkuFilter {
|
||||||
|
private String keywords;
|
||||||
|
private Long warehouseId;
|
||||||
|
/** true = 仅未分配 */
|
||||||
|
private Boolean unassignedOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量设置 SKU 默认发货仓;warehouseId 空=取消分配 */
|
||||||
|
@Data
|
||||||
|
public static class SkuBatchAssign {
|
||||||
|
@NotEmpty(message = "请选择 SKU")
|
||||||
|
private List<Long> skuIds;
|
||||||
|
/** null = 取消分配 */
|
||||||
|
private Long warehouseId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -22,5 +22,7 @@ public class WarehouseVO {
|
|||||||
private LocalDateTime updateTime;
|
private LocalDateTime updateTime;
|
||||||
/** 已绑定报价数 */
|
/** 已绑定报价数 */
|
||||||
private Integer bindCount;
|
private Integer bindCount;
|
||||||
|
/** 默认发此仓的 SKU 数 */
|
||||||
|
private Integer skuCount;
|
||||||
private List<WarehouseExpressBindVO> binds;
|
private List<WarehouseExpressBindVO> binds;
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-1
@@ -2,6 +2,7 @@ package top.xyquan.ecomdmbbackend.modules.ec.warehouse.service;
|
|||||||
|
|
||||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.vo.ProductSkuVO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.WarehouseDtos;
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.WarehouseDtos;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehousePO;
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehousePO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseExpressBindVO;
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseExpressBindVO;
|
||||||
@@ -9,7 +10,7 @@ import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseVO;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/** 发货仓库与报价绑定。 */
|
/** 发货仓库、报价绑定与仓商品分配。 */
|
||||||
public interface WarehouseService {
|
public interface WarehouseService {
|
||||||
|
|
||||||
WarehouseVO create(WarehouseDtos.Create dto);
|
WarehouseVO create(WarehouseDtos.Create dto);
|
||||||
@@ -33,4 +34,13 @@ public interface WarehouseService {
|
|||||||
void removeBind(Long bindId);
|
void removeBind(Long bindId);
|
||||||
|
|
||||||
List<WarehouseExpressBindVO> listBinds(Long warehouseId);
|
List<WarehouseExpressBindVO> listBinds(Long warehouseId);
|
||||||
|
|
||||||
|
/** 按仓/未分配筛选 SKU(仓权限) */
|
||||||
|
PageResultVO<ProductSkuVO> pageSkus(PageQueryDTO<WarehouseDtos.SkuFilter> query);
|
||||||
|
|
||||||
|
/** 未分配默认仓的 SKU 数量 */
|
||||||
|
long countUnassignedSkus();
|
||||||
|
|
||||||
|
/** 批量设置/清空 SKU 默认发货仓 */
|
||||||
|
int batchAssignSkus(WarehouseDtos.SkuBatchAssign dto);
|
||||||
}
|
}
|
||||||
|
|||||||
+99
-6
@@ -1,6 +1,7 @@
|
|||||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.impl;
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -12,7 +13,10 @@ import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
|||||||
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.service.BiOrderStatDirtyDayService;
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.service.BiOrderStatDirtyDayService;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.mapper.ProductSkuMapper;
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.mapper.ProductSkuMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.dto.ProductSkuFilterDTO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.po.ProductSkuPO;
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.po.ProductSkuPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.vo.ProductSkuVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.service.ProductSkuService;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight.ExpressCarrierCodes;
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight.ExpressCarrierCodes;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteMapper;
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteMapper;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.WarehouseExpressBindMapper;
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.WarehouseExpressBindMapper;
|
||||||
@@ -41,17 +45,20 @@ public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse
|
|||||||
private final WarehouseExpressBindMapper bindMapper;
|
private final WarehouseExpressBindMapper bindMapper;
|
||||||
private final ExpressQuoteMapper quoteMapper;
|
private final ExpressQuoteMapper quoteMapper;
|
||||||
private final ProductSkuMapper productSkuMapper;
|
private final ProductSkuMapper productSkuMapper;
|
||||||
|
private final ProductSkuService productSkuService;
|
||||||
private final BiOrderStatDirtyDayService dirtyDayService;
|
private final BiOrderStatDirtyDayService dirtyDayService;
|
||||||
|
|
||||||
public WarehouseServiceImpl(CurrentUserContext currentUserContext,
|
public WarehouseServiceImpl(CurrentUserContext currentUserContext,
|
||||||
WarehouseExpressBindMapper bindMapper,
|
WarehouseExpressBindMapper bindMapper,
|
||||||
ExpressQuoteMapper quoteMapper,
|
ExpressQuoteMapper quoteMapper,
|
||||||
ProductSkuMapper productSkuMapper,
|
ProductSkuMapper productSkuMapper,
|
||||||
|
ProductSkuService productSkuService,
|
||||||
BiOrderStatDirtyDayService dirtyDayService) {
|
BiOrderStatDirtyDayService dirtyDayService) {
|
||||||
this.currentUserContext = currentUserContext;
|
this.currentUserContext = currentUserContext;
|
||||||
this.bindMapper = bindMapper;
|
this.bindMapper = bindMapper;
|
||||||
this.quoteMapper = quoteMapper;
|
this.quoteMapper = quoteMapper;
|
||||||
this.productSkuMapper = productSkuMapper;
|
this.productSkuMapper = productSkuMapper;
|
||||||
|
this.productSkuService = productSkuService;
|
||||||
this.dirtyDayService = dirtyDayService;
|
this.dirtyDayService = dirtyDayService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +76,7 @@ public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse
|
|||||||
}
|
}
|
||||||
po.setCreateBy(currentUserContext.getCurrentUserId());
|
po.setCreateBy(currentUserContext.getCurrentUserId());
|
||||||
save(po);
|
save(po);
|
||||||
return toVo(po, false);
|
return toVo(po, false, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -86,7 +93,8 @@ public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse
|
|||||||
}
|
}
|
||||||
po.setUpdateBy(currentUserContext.getCurrentUserId());
|
po.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||||
updateById(po);
|
updateById(po);
|
||||||
return toVo(po, true);
|
Map<Long, Integer> skuCounts = loadSkuCounts(po.getCompanyId());
|
||||||
|
return toVo(po, true, skuCounts.getOrDefault(po.getId(), 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -120,24 +128,92 @@ public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse
|
|||||||
}
|
}
|
||||||
w.orderByDesc(WarehousePO::getId);
|
w.orderByDesc(WarehousePO::getId);
|
||||||
Page<WarehousePO> page = page(new Page<>(query.getPage(), query.getPageSize()), w);
|
Page<WarehousePO> page = page(new Page<>(query.getPage(), query.getPageSize()), w);
|
||||||
List<WarehouseVO> records = page.getRecords().stream().map(p -> toVo(p, false)).toList();
|
Map<Long, Integer> skuCounts = loadSkuCounts(companyId);
|
||||||
|
List<WarehouseVO> records = page.getRecords().stream()
|
||||||
|
.map(p -> toVo(p, false, skuCounts.getOrDefault(p.getId(), 0)))
|
||||||
|
.toList();
|
||||||
return PageResultVO.create(records, page.getTotal(), query.getPage(), query.getPageSize());
|
return PageResultVO.create(records, page.getTotal(), query.getPage(), query.getPageSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WarehouseVO> listEnabled() {
|
public List<WarehouseVO> listEnabled() {
|
||||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
Map<Long, Integer> skuCounts = loadSkuCounts(companyId);
|
||||||
return list(new LambdaQueryWrapper<WarehousePO>()
|
return list(new LambdaQueryWrapper<WarehousePO>()
|
||||||
.eq(WarehousePO::getCompanyId, companyId)
|
.eq(WarehousePO::getCompanyId, companyId)
|
||||||
.eq(WarehousePO::getStatus, 1)
|
.eq(WarehousePO::getStatus, 1)
|
||||||
.orderByAsc(WarehousePO::getCode)).stream()
|
.orderByAsc(WarehousePO::getCode)).stream()
|
||||||
.map(p -> toVo(p, false))
|
.map(p -> toVo(p, false, skuCounts.getOrDefault(p.getId(), 0)))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WarehouseVO detail(Long id) {
|
public WarehouseVO detail(Long id) {
|
||||||
return toVo(requireCompanyWarehouse(id), true);
|
WarehousePO po = requireCompanyWarehouse(id);
|
||||||
|
Map<Long, Integer> skuCounts = loadSkuCounts(po.getCompanyId());
|
||||||
|
return toVo(po, true, skuCounts.getOrDefault(po.getId(), 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResultVO<ProductSkuVO> pageSkus(PageQueryDTO<WarehouseDtos.SkuFilter> query) {
|
||||||
|
ProductSkuFilterDTO skuFilter = new ProductSkuFilterDTO();
|
||||||
|
WarehouseDtos.SkuFilter f = query.getFilters();
|
||||||
|
if (f != null) {
|
||||||
|
skuFilter.setKeywords(f.getKeywords());
|
||||||
|
skuFilter.setWarehouseId(f.getWarehouseId());
|
||||||
|
skuFilter.setUnassignedOnly(f.getUnassignedOnly());
|
||||||
|
}
|
||||||
|
PageQueryDTO<ProductSkuFilterDTO> pageQuery = new PageQueryDTO<>();
|
||||||
|
pageQuery.setPage(query.getPage());
|
||||||
|
pageQuery.setPageSize(query.getPageSize());
|
||||||
|
pageQuery.setFilters(skuFilter);
|
||||||
|
return productSkuService.getProductSkuPage(pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long countUnassignedSkus() {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
Long count = productSkuMapper.selectCount(new LambdaQueryWrapper<ProductSkuPO>()
|
||||||
|
.eq(ProductSkuPO::getCompanyId, companyId)
|
||||||
|
.isNull(ProductSkuPO::getWarehouseId));
|
||||||
|
return count == null ? 0L : count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public int batchAssignSkus(WarehouseDtos.SkuBatchAssign dto) {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
Long userId = currentUserContext.getCurrentUserId();
|
||||||
|
Long targetWarehouseId = dto.getWarehouseId();
|
||||||
|
if (targetWarehouseId != null) {
|
||||||
|
requireCompanyWarehouse(targetWarehouseId);
|
||||||
|
}
|
||||||
|
List<Long> skuIds = dto.getSkuIds().stream().filter(Objects::nonNull).distinct().toList();
|
||||||
|
if (skuIds.isEmpty()) {
|
||||||
|
throw new BusinessException("请选择 SKU");
|
||||||
|
}
|
||||||
|
List<ProductSkuPO> skus = productSkuMapper.selectList(new LambdaQueryWrapper<ProductSkuPO>()
|
||||||
|
.eq(ProductSkuPO::getCompanyId, companyId)
|
||||||
|
.in(ProductSkuPO::getId, skuIds));
|
||||||
|
if (skus.size() != skuIds.size()) {
|
||||||
|
throw new BusinessException("部分 SKU 不存在或不属于本公司");
|
||||||
|
}
|
||||||
|
LocalDate from = LocalDate.now().minusYears(1);
|
||||||
|
int updated = 0;
|
||||||
|
for (ProductSkuPO sku : skus) {
|
||||||
|
if (Objects.equals(sku.getWarehouseId(), targetWarehouseId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 允许 warehouseId 置空(取消分配)
|
||||||
|
productSkuMapper.update(null, new LambdaUpdateWrapper<ProductSkuPO>()
|
||||||
|
.eq(ProductSkuPO::getId, sku.getId())
|
||||||
|
.eq(ProductSkuPO::getCompanyId, companyId)
|
||||||
|
.set(ProductSkuPO::getWarehouseId, targetWarehouseId)
|
||||||
|
.set(ProductSkuPO::getUpdateBy, userId));
|
||||||
|
dirtyDayService.markAfterFreightQuoteChange(companyId, sku.getId(), from, userId);
|
||||||
|
updated++;
|
||||||
|
}
|
||||||
|
return updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -244,12 +320,29 @@ public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private WarehouseVO toVo(WarehousePO po, boolean withBinds) {
|
/** 按仓汇总默认 SKU 数 */
|
||||||
|
private Map<Long, Integer> loadSkuCounts(Long companyId) {
|
||||||
|
List<ProductSkuPO> rows = productSkuMapper.selectList(new LambdaQueryWrapper<ProductSkuPO>()
|
||||||
|
.eq(ProductSkuPO::getCompanyId, companyId)
|
||||||
|
.isNotNull(ProductSkuPO::getWarehouseId)
|
||||||
|
.select(ProductSkuPO::getWarehouseId));
|
||||||
|
Map<Long, Integer> counts = new HashMap<>();
|
||||||
|
for (ProductSkuPO row : rows) {
|
||||||
|
if (row.getWarehouseId() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
counts.merge(row.getWarehouseId(), 1, Integer::sum);
|
||||||
|
}
|
||||||
|
return counts;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WarehouseVO toVo(WarehousePO po, boolean withBinds, int skuCount) {
|
||||||
WarehouseVO vo = new WarehouseVO();
|
WarehouseVO vo = new WarehouseVO();
|
||||||
BeanCopyUtils.copyProperties(po, vo);
|
BeanCopyUtils.copyProperties(po, vo);
|
||||||
List<WarehouseExpressBindPO> binds = bindMapper.selectList(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
List<WarehouseExpressBindPO> binds = bindMapper.selectList(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||||
.eq(WarehouseExpressBindPO::getWarehouseId, po.getId()));
|
.eq(WarehouseExpressBindPO::getWarehouseId, po.getId()));
|
||||||
vo.setBindCount(binds.size());
|
vo.setBindCount(binds.size());
|
||||||
|
vo.setSkuCount(skuCount);
|
||||||
if (withBinds) {
|
if (withBinds) {
|
||||||
vo.setBinds(toBindVos(binds));
|
vo.setBinds(toBindVos(binds));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -802,6 +802,11 @@ INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path
|
|||||||
SELECT 43, (SELECT id FROM `sys_menu` WHERE `id` = 6 OR `title` = '电商页面' LIMIT 1), 0, 'ProductOverview', '商品概览', '/ec/product/overview/:id', '/ec/product/overview/index', '', 'lets-icons:chart', 'embedded', 0, 1, 1, 2
|
SELECT 43, (SELECT id FROM `sys_menu` WHERE `id` = 6 OR `title` = '电商页面' LIMIT 1), 0, 'ProductOverview', '商品概览', '/ec/product/overview/:id', '/ec/product/overview/index', '', 'lets-icons:chart', 'embedded', 0, 1, 1, 2
|
||||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 43 OR `route_name` = 'ProductOverview');
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 43 OR `route_name` = 'ProductOverview');
|
||||||
|
|
||||||
|
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||||
|
SELECT 14023, (SELECT id FROM `sys_menu` WHERE `id` = 14019 OR `title` = '发货物流' OR `route_name` = 'FreightCatalog' LIMIT 1), 0,
|
||||||
|
'WarehouseSkuManagement', '发货仓商品', '/ec/warehouse/sku', '/ec/warehouse/sku/index', '', 'lucide:boxes', 'menu', 1, 1, 1, 2
|
||||||
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 14023 OR `route_name` = 'WarehouseSkuManagement');
|
||||||
|
|
||||||
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||||
SELECT 14022, (SELECT id FROM `sys_menu` WHERE `id` = 14019 OR `title` = '发货物流' OR `route_name` = 'FreightCatalog' LIMIT 1), 0,
|
SELECT 14022, (SELECT id FROM `sys_menu` WHERE `id` = 14019 OR `title` = '发货物流' OR `route_name` = 'FreightCatalog' LIMIT 1), 0,
|
||||||
'ExpressQuoteEdit', '快递报价单编辑', '/ec/warehouse/express-quote/edit/:id?', '/ec/warehouse/express-quote/edit/index', '', 'lucide:file-pen-line', 'embedded', 0, 1, 0, 8
|
'ExpressQuoteEdit', '快递报价单编辑', '/ec/warehouse/express-quote/edit/:id?', '/ec/warehouse/express-quote/edit/index', '', 'lucide:file-pen-line', 'embedded', 0, 1, 0, 8
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ export namespace ProductSkuDTO {
|
|||||||
skuCode?: string;
|
skuCode?: string;
|
||||||
/** 关键字(模糊查询 SKU 名称、SKU 编码) */
|
/** 关键字(模糊查询 SKU 名称、SKU 编码) */
|
||||||
keywords?: string;
|
keywords?: string;
|
||||||
|
warehouseId?: number;
|
||||||
|
unassignedOnly?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 商品 SKU 查询 DTO(用于批量查询) */
|
/** 商品 SKU 查询 DTO(用于批量查询) */
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { WarehouseDTO, WarehouseVO } from './types';
|
import type { WarehouseDTO, WarehouseVO } from './types';
|
||||||
|
|
||||||
|
import type { ProductSkuVO } from '#/api/ec/product/sku';
|
||||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||||
|
|
||||||
import { requestClient } from '#/api/request';
|
import { requestClient } from '#/api/request';
|
||||||
@@ -59,3 +60,28 @@ export async function updateWarehouseBindApi(
|
|||||||
export async function removeWarehouseBindApi(bindId: number) {
|
export async function removeWarehouseBindApi(bindId: number) {
|
||||||
return requestClient.delete(`/ec/warehouse/bind/${bindId}`);
|
return requestClient.delete(`/ec/warehouse/bind/${bindId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 发货仓商品分页(仓权限) */
|
||||||
|
export async function getWarehouseSkuPageApi(
|
||||||
|
params: PageQueryDTO<WarehouseDTO.SkuFilters>,
|
||||||
|
) {
|
||||||
|
return requestClient.post<PageResultVO<ProductSkuVO.Info>>(
|
||||||
|
'/ec/warehouse/skus/list',
|
||||||
|
params,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getUnassignedWarehouseSkuCountApi() {
|
||||||
|
return requestClient.get<{ count: number }>(
|
||||||
|
'/ec/warehouse/skus/unassigned-count',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function batchAssignWarehouseSkusApi(
|
||||||
|
data: WarehouseDTO.SkuBatchAssign,
|
||||||
|
) {
|
||||||
|
return requestClient.post<{ updated: number }>(
|
||||||
|
'/ec/warehouse/skus/batch-assign',
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,4 +34,17 @@ export namespace WarehouseDTO {
|
|||||||
priority?: number;
|
priority?: number;
|
||||||
status?: number;
|
status?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 发货仓商品筛选 */
|
||||||
|
export interface SkuFilters {
|
||||||
|
keywords?: string;
|
||||||
|
warehouseId?: number;
|
||||||
|
unassignedOnly?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量分配默认发货仓;warehouseId 空=取消分配 */
|
||||||
|
export interface SkuBatchAssign {
|
||||||
|
skuIds: number[];
|
||||||
|
warehouseId?: number | null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ export namespace WarehouseVO {
|
|||||||
createTime?: string;
|
createTime?: string;
|
||||||
updateTime?: string;
|
updateTime?: string;
|
||||||
bindCount?: number;
|
bindCount?: number;
|
||||||
|
/** 默认发此仓的 SKU 数 */
|
||||||
|
skuCount?: number;
|
||||||
binds?: Bind[];
|
binds?: Bind[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { defineStore } from 'pinia';
|
|||||||
export type ColSidebarKind =
|
export type ColSidebarKind =
|
||||||
| 'company'
|
| 'company'
|
||||||
| 'ec-shop'
|
| 'ec-shop'
|
||||||
|
| 'ec-warehouse'
|
||||||
| 'pdd-shop'
|
| 'pdd-shop'
|
||||||
| 'pdd-publish-agent';
|
| 'pdd-publish-agent';
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ const AGENT_DEFAULT_LAYOUT: ColSidebarLayout = {
|
|||||||
function createDefaultLayouts(): Record<ColSidebarKind, ColSidebarLayout> {
|
function createDefaultLayouts(): Record<ColSidebarKind, ColSidebarLayout> {
|
||||||
return {
|
return {
|
||||||
'ec-shop': { ...DEFAULT_LAYOUT },
|
'ec-shop': { ...DEFAULT_LAYOUT },
|
||||||
|
'ec-warehouse': { ...DEFAULT_LAYOUT },
|
||||||
'pdd-shop': { ...DEFAULT_LAYOUT },
|
'pdd-shop': { ...DEFAULT_LAYOUT },
|
||||||
company: { ...DEFAULT_LAYOUT },
|
company: { ...DEFAULT_LAYOUT },
|
||||||
'pdd-publish-agent': { ...AGENT_DEFAULT_LAYOUT },
|
'pdd-publish-agent': { ...AGENT_DEFAULT_LAYOUT },
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
/**
|
||||||
|
* 发货仓双栏页:左栏 WarehouseSidebarList,宽度/收起走全局持久化。
|
||||||
|
*/
|
||||||
|
import type { WarehouseVO } from '#/api/ec/warehouse';
|
||||||
|
import type { WarehouseSidebarScope } from '#/views/ec/components/WarehouseSidebarList.vue';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
import { ColPage } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { useColSidebarLayout } from '#/store/col-sidebar-layout';
|
||||||
|
import WarehouseSidebarList from '#/views/ec/components/WarehouseSidebarList.vue';
|
||||||
|
|
||||||
|
defineOptions({ name: 'EcWarehouseColPage' });
|
||||||
|
|
||||||
|
withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
scope?: WarehouseSidebarScope;
|
||||||
|
selectedWarehouseId?: number;
|
||||||
|
autoContentHeight?: boolean;
|
||||||
|
leftMinWidth?: number;
|
||||||
|
leftMaxWidth?: number;
|
||||||
|
leftCollapsedWidth?: number;
|
||||||
|
leftCollapsible?: boolean;
|
||||||
|
resizable?: boolean;
|
||||||
|
splitHandle?: boolean;
|
||||||
|
splitLine?: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
scope: 'all',
|
||||||
|
selectedWarehouseId: undefined,
|
||||||
|
autoContentHeight: true,
|
||||||
|
leftMinWidth: 16,
|
||||||
|
leftMaxWidth: 36,
|
||||||
|
leftCollapsedWidth: 3,
|
||||||
|
leftCollapsible: true,
|
||||||
|
resizable: true,
|
||||||
|
splitHandle: false,
|
||||||
|
splitLine: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:scope': [scope: WarehouseSidebarScope];
|
||||||
|
'update:selectedWarehouseId': [id: number | undefined];
|
||||||
|
select: [
|
||||||
|
payload: {
|
||||||
|
scope: WarehouseSidebarScope;
|
||||||
|
warehouse: WarehouseVO.Info | null;
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const { width: leftWidth, collapsed: leftCollapsed } =
|
||||||
|
useColSidebarLayout('ec-warehouse');
|
||||||
|
|
||||||
|
const listRef = ref<InstanceType<typeof WarehouseSidebarList> | null>(null);
|
||||||
|
|
||||||
|
function refreshSidebar() {
|
||||||
|
void listRef.value?.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ refreshSidebar });
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="ec-warehouse-col-page h-full min-h-0">
|
||||||
|
<ColPage
|
||||||
|
v-model:left-width="leftWidth"
|
||||||
|
v-model:left-collapsed="leftCollapsed"
|
||||||
|
:auto-content-height="autoContentHeight"
|
||||||
|
:left-min-width="leftMinWidth"
|
||||||
|
:left-max-width="leftMaxWidth"
|
||||||
|
:left-collapsed-width="leftCollapsedWidth"
|
||||||
|
:left-collapsible="leftCollapsible"
|
||||||
|
:right-width="100 - leftWidth"
|
||||||
|
:resizable="resizable"
|
||||||
|
:split-handle="splitHandle"
|
||||||
|
:split-line="splitLine"
|
||||||
|
content-class="!p-2 sm:!p-3"
|
||||||
|
>
|
||||||
|
<template #left="{ isCollapsed, expand, collapse }">
|
||||||
|
<div
|
||||||
|
class="flex h-full min-h-0 flex-col"
|
||||||
|
:class="
|
||||||
|
isCollapsed
|
||||||
|
? 'warehouse-sidebar-collapsed-mark min-w-[56px] overflow-visible'
|
||||||
|
: 'min-w-0 overflow-hidden'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<WarehouseSidebarList
|
||||||
|
ref="listRef"
|
||||||
|
fluid
|
||||||
|
:collapsed="!!isCollapsed"
|
||||||
|
show-collapse-action
|
||||||
|
:scope="scope"
|
||||||
|
:selected-warehouse-id="selectedWarehouseId"
|
||||||
|
@collapse="collapse"
|
||||||
|
@expand="expand"
|
||||||
|
@update:scope="emit('update:scope', $event)"
|
||||||
|
@update:selected-warehouse-id="
|
||||||
|
emit('update:selectedWarehouseId', $event)
|
||||||
|
"
|
||||||
|
@select="emit('select', $event)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<slot />
|
||||||
|
</ColPage>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.ec-warehouse-col-page :deep([data-panel]:has(.warehouse-sidebar-collapsed-mark)),
|
||||||
|
.ec-warehouse-col-page
|
||||||
|
:deep(
|
||||||
|
[data-panel-group-direction]
|
||||||
|
> *:first-child:has(.warehouse-sidebar-collapsed-mark)
|
||||||
|
) {
|
||||||
|
flex: 0 0 56px !important;
|
||||||
|
width: 56px !important;
|
||||||
|
min-width: 56px !important;
|
||||||
|
max-width: 56px !important;
|
||||||
|
overflow: visible;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,455 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
/**
|
||||||
|
* 发货仓侧栏:全部 / 未分配 / 指定仓;交互对齐 ShopSidebarList。
|
||||||
|
*/
|
||||||
|
import type { WarehouseVO } from '#/api/ec/warehouse';
|
||||||
|
|
||||||
|
import { computed, onMounted, ref } from 'vue';
|
||||||
|
|
||||||
|
import { createIconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
Empty,
|
||||||
|
Input,
|
||||||
|
message,
|
||||||
|
Spin,
|
||||||
|
Tag,
|
||||||
|
Tooltip,
|
||||||
|
} from 'ant-design-vue';
|
||||||
|
|
||||||
|
import {
|
||||||
|
getUnassignedWarehouseSkuCountApi,
|
||||||
|
getWarehousePageApi,
|
||||||
|
} from '#/api/ec/warehouse';
|
||||||
|
|
||||||
|
defineOptions({ name: 'WarehouseSidebarList' });
|
||||||
|
|
||||||
|
export type WarehouseSidebarScope = 'all' | 'unassigned' | 'warehouse';
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
scope?: WarehouseSidebarScope;
|
||||||
|
/** scope=warehouse 时选中的仓 id */
|
||||||
|
selectedWarehouseId?: number;
|
||||||
|
fluid?: boolean;
|
||||||
|
showCollapseAction?: boolean;
|
||||||
|
collapsed?: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
scope: 'all',
|
||||||
|
selectedWarehouseId: undefined,
|
||||||
|
fluid: false,
|
||||||
|
showCollapseAction: false,
|
||||||
|
collapsed: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:scope': [scope: WarehouseSidebarScope];
|
||||||
|
'update:selectedWarehouseId': [id: number | undefined];
|
||||||
|
select: [
|
||||||
|
payload: {
|
||||||
|
scope: WarehouseSidebarScope;
|
||||||
|
warehouse: WarehouseVO.Info | null;
|
||||||
|
},
|
||||||
|
];
|
||||||
|
collapse: [];
|
||||||
|
expand: [];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const WarehouseIcon = createIconifyIcon('lucide:warehouse');
|
||||||
|
const BoxesIcon = createIconifyIcon('lucide:boxes');
|
||||||
|
const InboxIcon = createIconifyIcon('lucide:inbox');
|
||||||
|
const PanelCloseIcon = createIconifyIcon('lucide:panel-left-close');
|
||||||
|
const PanelOpenIcon = createIconifyIcon('lucide:panel-left-open');
|
||||||
|
const ChevronUpIcon = createIconifyIcon('lucide:chevron-up');
|
||||||
|
const ChevronDownIcon = createIconifyIcon('lucide:chevron-down');
|
||||||
|
|
||||||
|
const keyword = ref('');
|
||||||
|
const warehouses = ref<WarehouseVO.Info[]>([]);
|
||||||
|
const loading = ref(false);
|
||||||
|
const unassignedCount = ref(0);
|
||||||
|
const pagination = ref({ current: 1, pageSize: 20, total: 0 });
|
||||||
|
|
||||||
|
const totalPages = computed(() => {
|
||||||
|
const { total, pageSize } = pagination.value;
|
||||||
|
return Math.max(1, Math.ceil(total / pageSize) || 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
const allSelected = computed(() => props.scope === 'all');
|
||||||
|
const unassignedSelected = computed(() => props.scope === 'unassigned');
|
||||||
|
|
||||||
|
async function loadUnassignedCount() {
|
||||||
|
try {
|
||||||
|
const res = await getUnassignedWarehouseSkuCountApi();
|
||||||
|
unassignedCount.value = Number(res?.count ?? 0);
|
||||||
|
} catch {
|
||||||
|
unassignedCount.value = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function searchWarehouses(resetPage = false) {
|
||||||
|
if (resetPage) {
|
||||||
|
pagination.value.current = 1;
|
||||||
|
}
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const result = await getWarehousePageApi({
|
||||||
|
page: pagination.value.current,
|
||||||
|
pageSize: pagination.value.pageSize,
|
||||||
|
filters: {
|
||||||
|
keywords: keyword.value || undefined,
|
||||||
|
status: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
warehouses.value = result.records ?? [];
|
||||||
|
pagination.value.total = result.total ?? 0;
|
||||||
|
} catch (error: any) {
|
||||||
|
message.error(error?.message || '获取仓库列表失败');
|
||||||
|
warehouses.value = [];
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetSearch() {
|
||||||
|
keyword.value = '';
|
||||||
|
void searchWarehouses(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function goPage(page: number) {
|
||||||
|
const next = Math.min(totalPages.value, Math.max(1, page));
|
||||||
|
if (next === pagination.value.current) return;
|
||||||
|
pagination.value.current = next;
|
||||||
|
void searchWarehouses();
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectAll() {
|
||||||
|
emit('update:scope', 'all');
|
||||||
|
emit('update:selectedWarehouseId', undefined);
|
||||||
|
emit('select', { scope: 'all', warehouse: null });
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectUnassigned() {
|
||||||
|
emit('update:scope', 'unassigned');
|
||||||
|
emit('update:selectedWarehouseId', undefined);
|
||||||
|
emit('select', { scope: 'unassigned', warehouse: null });
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectWarehouse(wh: WarehouseVO.Info) {
|
||||||
|
emit('update:scope', 'warehouse');
|
||||||
|
emit('update:selectedWarehouseId', wh.id);
|
||||||
|
emit('select', { scope: 'warehouse', warehouse: wh });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refresh() {
|
||||||
|
await Promise.all([loadUnassignedCount(), searchWarehouses()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ refresh });
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
void refresh();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
v-if="collapsed"
|
||||||
|
class="flex h-full min-h-0 w-full flex-col items-center gap-1 pb-2 pt-3"
|
||||||
|
>
|
||||||
|
<Tooltip title="展开仓库列表">
|
||||||
|
<Button type="text" size="small" class="!px-1" @click="emit('expand')">
|
||||||
|
<PanelOpenIcon class="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="flex min-h-0 w-full flex-1 flex-col items-center gap-1.5 overflow-y-auto px-1.5 pb-1 pt-2"
|
||||||
|
>
|
||||||
|
<Tooltip title="全部 SKU">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="inline-flex shrink-0 rounded-md p-0.5 transition-colors hover:bg-accent"
|
||||||
|
:class="
|
||||||
|
allSelected
|
||||||
|
? 'ring-2 ring-primary ring-offset-1 ring-offset-background'
|
||||||
|
: undefined
|
||||||
|
"
|
||||||
|
@click="selectAll"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="flex h-9 w-9 items-center justify-center rounded-md border border-dashed border-border bg-muted/50"
|
||||||
|
>
|
||||||
|
<BoxesIcon class="h-4 w-4 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip title="未分配">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="inline-flex shrink-0 rounded-md p-0.5 transition-colors hover:bg-accent"
|
||||||
|
:class="
|
||||||
|
unassignedSelected
|
||||||
|
? 'ring-2 ring-primary ring-offset-1 ring-offset-background'
|
||||||
|
: undefined
|
||||||
|
"
|
||||||
|
@click="selectUnassigned"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="flex h-9 w-9 items-center justify-center rounded-md border border-dashed border-border bg-muted/50"
|
||||||
|
>
|
||||||
|
<InboxIcon class="h-4 w-4 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
|
<Spin
|
||||||
|
:spinning="loading"
|
||||||
|
size="small"
|
||||||
|
wrapper-class-name="warehouse-sidebar-collapsed-spin"
|
||||||
|
>
|
||||||
|
<div class="flex w-full flex-col items-center gap-1.5">
|
||||||
|
<Tooltip
|
||||||
|
v-for="wh in warehouses"
|
||||||
|
:key="wh.id"
|
||||||
|
:title="`${wh.name}(${wh.skuCount ?? 0})`"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="inline-flex shrink-0 rounded-md p-0.5 transition-colors hover:bg-accent"
|
||||||
|
:class="
|
||||||
|
scope === 'warehouse' && selectedWarehouseId === wh.id
|
||||||
|
? 'ring-2 ring-primary ring-offset-1 ring-offset-background'
|
||||||
|
: undefined
|
||||||
|
"
|
||||||
|
@click="selectWarehouse(wh)"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="flex h-9 w-9 items-center justify-center rounded-md border border-border bg-card text-xs font-medium"
|
||||||
|
>
|
||||||
|
{{ (wh.name || wh.code || '?').slice(0, 1) }}
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
</Spin>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="totalPages > 1"
|
||||||
|
class="flex shrink-0 flex-col items-center gap-0.5"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
size="small"
|
||||||
|
class="!h-6 !px-1"
|
||||||
|
:disabled="pagination.current <= 1 || loading"
|
||||||
|
@click="goPage(pagination.current - 1)"
|
||||||
|
>
|
||||||
|
<ChevronUpIcon class="h-3.5 w-3.5" />
|
||||||
|
</Button>
|
||||||
|
<span class="text-[10px] leading-none text-muted-foreground">
|
||||||
|
{{ pagination.current }}/{{ totalPages }}
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
size="small"
|
||||||
|
class="!h-6 !px-1"
|
||||||
|
:disabled="pagination.current >= totalPages || loading"
|
||||||
|
@click="goPage(pagination.current + 1)"
|
||||||
|
>
|
||||||
|
<ChevronDownIcon class="h-3.5 w-3.5" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Card
|
||||||
|
v-else
|
||||||
|
class="flex h-full flex-col overflow-hidden"
|
||||||
|
:class="fluid ? 'w-full min-w-0' : 'w-[320px] shrink-0'"
|
||||||
|
:body-style="{
|
||||||
|
height: '100%',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '8px',
|
||||||
|
minHeight: 0,
|
||||||
|
minWidth: 0,
|
||||||
|
overflow: 'hidden',
|
||||||
|
padding: '12px',
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<template #title>
|
||||||
|
<span class="flex items-center gap-2 text-base font-semibold">
|
||||||
|
<WarehouseIcon class="h-4 w-4" />
|
||||||
|
发货仓
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-if="showCollapseAction" #extra>
|
||||||
|
<Tooltip title="收起仓库列表">
|
||||||
|
<Button type="text" size="small" class="!px-1" @click="emit('collapse')">
|
||||||
|
<PanelCloseIcon class="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div class="flex min-w-0 shrink-0 items-center gap-2">
|
||||||
|
<Input
|
||||||
|
v-model:value="keyword"
|
||||||
|
placeholder="名称/编码"
|
||||||
|
allow-clear
|
||||||
|
class="min-w-0 flex-1"
|
||||||
|
@press-enter="searchWarehouses(true)"
|
||||||
|
/>
|
||||||
|
<Button type="primary" class="shrink-0" @click="searchWarehouses(true)">
|
||||||
|
搜索
|
||||||
|
</Button>
|
||||||
|
<Button class="shrink-0" @click="resetSearch">重置</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
|
||||||
|
<div class="flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto">
|
||||||
|
<Card
|
||||||
|
size="small"
|
||||||
|
:body-style="{ padding: '10px 12px' }"
|
||||||
|
class="cursor-pointer !shadow-none hover:border-primary"
|
||||||
|
:class="allSelected ? 'border-primary bg-primary/5' : undefined"
|
||||||
|
@click="selectAll"
|
||||||
|
>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<div
|
||||||
|
class="flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-dashed border-border bg-muted/50"
|
||||||
|
>
|
||||||
|
<BoxesIcon class="h-4 w-4 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<div class="flex items-center justify-between gap-2">
|
||||||
|
<span class="min-w-0 truncate text-sm font-medium">全部</span>
|
||||||
|
<span class="shrink-0 text-xs text-muted-foreground">全部 SKU</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card
|
||||||
|
size="small"
|
||||||
|
:body-style="{ padding: '10px 12px' }"
|
||||||
|
class="cursor-pointer !shadow-none hover:border-primary"
|
||||||
|
:class="unassignedSelected ? 'border-primary bg-primary/5' : undefined"
|
||||||
|
@click="selectUnassigned"
|
||||||
|
>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<div
|
||||||
|
class="flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-dashed border-border bg-muted/50"
|
||||||
|
>
|
||||||
|
<InboxIcon class="h-4 w-4 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<div class="flex items-center justify-between gap-2">
|
||||||
|
<span class="min-w-0 truncate text-sm font-medium">未分配</span>
|
||||||
|
<Tag class="m-0 shrink-0">{{ unassignedCount }}</Tag>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Spin
|
||||||
|
:spinning="loading"
|
||||||
|
wrapper-class-name="warehouse-sidebar-list-spin"
|
||||||
|
>
|
||||||
|
<Empty
|
||||||
|
v-if="!loading && warehouses.length === 0"
|
||||||
|
class="py-8"
|
||||||
|
description="暂无启用仓库"
|
||||||
|
/>
|
||||||
|
<div v-else class="flex flex-col gap-2">
|
||||||
|
<Card
|
||||||
|
v-for="wh in warehouses"
|
||||||
|
:key="wh.id"
|
||||||
|
size="small"
|
||||||
|
:body-style="{ padding: '10px 12px' }"
|
||||||
|
class="cursor-pointer !shadow-none hover:border-primary"
|
||||||
|
:class="
|
||||||
|
scope === 'warehouse' && selectedWarehouseId === wh.id
|
||||||
|
? 'border-primary bg-primary/5'
|
||||||
|
: undefined
|
||||||
|
"
|
||||||
|
@click="selectWarehouse(wh)"
|
||||||
|
>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<div
|
||||||
|
class="flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-border bg-card"
|
||||||
|
>
|
||||||
|
<WarehouseIcon class="h-4 w-4 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<div class="flex items-center justify-between gap-2">
|
||||||
|
<span class="min-w-0 truncate text-sm font-medium">
|
||||||
|
{{ wh.name }}
|
||||||
|
</span>
|
||||||
|
<Tag class="m-0 shrink-0">{{ wh.skuCount ?? 0 }}</Tag>
|
||||||
|
</div>
|
||||||
|
<div class="truncate text-xs text-muted-foreground">
|
||||||
|
{{ wh.code }}
|
||||||
|
<template v-if="wh.province || wh.city">
|
||||||
|
· {{ [wh.province, wh.city].filter(Boolean).join(' ') }}
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</Spin>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="mt-2 flex w-full min-w-0 shrink-0 items-center justify-between gap-2"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
class="shrink-0"
|
||||||
|
:disabled="pagination.current <= 1 || loading"
|
||||||
|
@click="goPage(pagination.current - 1)"
|
||||||
|
>
|
||||||
|
上一页
|
||||||
|
</Button>
|
||||||
|
<span
|
||||||
|
class="min-w-0 flex-1 truncate text-center text-xs text-muted-foreground"
|
||||||
|
>
|
||||||
|
{{ pagination.current }} / {{ totalPages }}
|
||||||
|
<span class="ml-1 opacity-70">({{ pagination.total }})</span>
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
class="shrink-0"
|
||||||
|
:disabled="pagination.current >= totalPages || loading"
|
||||||
|
@click="goPage(pagination.current + 1)"
|
||||||
|
>
|
||||||
|
下一页
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
:deep(.warehouse-sidebar-collapsed-spin),
|
||||||
|
:deep(.warehouse-sidebar-collapsed-spin .ant-spin-container) {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
overflow: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.warehouse-sidebar-list-spin),
|
||||||
|
:deep(.warehouse-sidebar-list-spin .ant-spin-container) {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,334 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
/**
|
||||||
|
* 发货仓商品:左栏仓筛选,右栏 SKU 列表与批量分配默认仓。
|
||||||
|
*/
|
||||||
|
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||||
|
import type { WarehouseVO } from '#/api/ec/warehouse';
|
||||||
|
import type { ProductSkuVO } from '#/api/ec/product/sku';
|
||||||
|
import type { WarehouseSidebarScope } from '#/views/ec/components/WarehouseSidebarList.vue';
|
||||||
|
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
|
import { createIconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
message,
|
||||||
|
Modal,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
} from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import {
|
||||||
|
batchAssignWarehouseSkusApi,
|
||||||
|
getEnabledWarehousesApi,
|
||||||
|
getWarehouseSkuPageApi,
|
||||||
|
} from '#/api/ec/warehouse';
|
||||||
|
import { PermissionGate } from '#/components/permission';
|
||||||
|
import {
|
||||||
|
syncVxeGridColumns,
|
||||||
|
useActionColumnVisible,
|
||||||
|
} from '#/composables/use-vxe-action-column';
|
||||||
|
import EcWarehouseColPage from '#/views/ec/components/EcWarehouseColPage.vue';
|
||||||
|
|
||||||
|
defineOptions({ name: 'WarehouseSkuManagement' });
|
||||||
|
|
||||||
|
const AssignIcon = createIconifyIcon('lucide:package-plus');
|
||||||
|
const ClearIcon = createIconifyIcon('lucide:unlink');
|
||||||
|
|
||||||
|
const scope = ref<WarehouseSidebarScope>('all');
|
||||||
|
const selectedWarehouseId = ref<number | undefined>(undefined);
|
||||||
|
const selectedWarehouseName = ref<string | undefined>(undefined);
|
||||||
|
const colPageRef = ref<InstanceType<typeof EcWarehouseColPage> | null>(null);
|
||||||
|
|
||||||
|
const loading = ref(false);
|
||||||
|
const hasSelected = ref(false);
|
||||||
|
const keywords = ref('');
|
||||||
|
const gridReloadRef = ref<(() => void) | null>(null);
|
||||||
|
|
||||||
|
const assignOpen = ref(false);
|
||||||
|
const assignLoading = ref(false);
|
||||||
|
const assignTargetId = ref<number | undefined>(undefined);
|
||||||
|
const assignWarehouseOptions = ref<{ label: string; value: number }[]>([]);
|
||||||
|
|
||||||
|
const showCheckboxColumn = useActionColumnVisible(['ec:warehouse:update']);
|
||||||
|
|
||||||
|
const titleText = computed(() => {
|
||||||
|
if (scope.value === 'unassigned') return '未分配 SKU';
|
||||||
|
if (scope.value === 'warehouse') {
|
||||||
|
return selectedWarehouseName.value
|
||||||
|
? `发货仓「${selectedWarehouseName.value}」的 SKU`
|
||||||
|
: '发货仓 SKU';
|
||||||
|
}
|
||||||
|
return '全部 SKU';
|
||||||
|
});
|
||||||
|
|
||||||
|
const tableBaseColumns: VxeGridProps<ProductSkuVO.Info>['columns'] = [
|
||||||
|
{ type: 'seq' as const, minWidth: 'auto', title: '序号' },
|
||||||
|
{ field: 'productName', title: '商品', minWidth: 140 },
|
||||||
|
{ field: 'name', title: 'SKU', minWidth: 120 },
|
||||||
|
{ field: 'skuCode', title: '编码', minWidth: 120 },
|
||||||
|
{ field: 'warehouseName', title: '发货仓', minWidth: 120 },
|
||||||
|
{
|
||||||
|
field: 'weightG',
|
||||||
|
title: '实重(g)',
|
||||||
|
minWidth: 90,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const checkboxColumn: NonNullable<
|
||||||
|
VxeGridProps<ProductSkuVO.Info>['columns']
|
||||||
|
>[number] = {
|
||||||
|
type: 'checkbox' as const,
|
||||||
|
width: 48,
|
||||||
|
};
|
||||||
|
|
||||||
|
const tableColumns = computed(() =>
|
||||||
|
showCheckboxColumn.value
|
||||||
|
? [checkboxColumn, ...(tableBaseColumns ?? [])]
|
||||||
|
: (tableBaseColumns ?? []),
|
||||||
|
);
|
||||||
|
|
||||||
|
const formOptions = computed(() => ({
|
||||||
|
schema: [
|
||||||
|
{
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '商品/SKU/编码',
|
||||||
|
allowClear: true,
|
||||||
|
onChange: (e: Event) => {
|
||||||
|
keywords.value = (e.target as HTMLInputElement).value;
|
||||||
|
},
|
||||||
|
onPressEnter: () => gridReloadRef.value?.(),
|
||||||
|
},
|
||||||
|
fieldName: 'keywords',
|
||||||
|
label: '关键字',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
showDefaultActions: true,
|
||||||
|
collapsed: true,
|
||||||
|
handleSubmit: async () => gridReloadRef.value?.(),
|
||||||
|
handleReset: async () => {
|
||||||
|
keywords.value = '';
|
||||||
|
gridReloadRef.value?.();
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
function buildFilters() {
|
||||||
|
return {
|
||||||
|
keywords: keywords.value || undefined,
|
||||||
|
warehouseId:
|
||||||
|
scope.value === 'warehouse' ? selectedWarehouseId.value : undefined,
|
||||||
|
unassignedOnly: scope.value === 'unassigned' ? true : undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const gridOptions: VxeGridProps<ProductSkuVO.Info> = {
|
||||||
|
columns: tableColumns.value,
|
||||||
|
height: 'auto',
|
||||||
|
border: true,
|
||||||
|
stripe: true,
|
||||||
|
rowConfig: { keyField: 'id' },
|
||||||
|
checkboxConfig: { highlight: true },
|
||||||
|
pagerConfig: { enabled: true, pageSizes: [10, 20, 50, 100] },
|
||||||
|
proxyConfig: {
|
||||||
|
ajax: {
|
||||||
|
query: async ({ page }) => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const data = await getWarehouseSkuPageApi({
|
||||||
|
page: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
filters: buildFilters(),
|
||||||
|
});
|
||||||
|
return { items: data.records, total: data.total };
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
gridOptions,
|
||||||
|
formOptions: formOptions.value,
|
||||||
|
showSearchForm: true,
|
||||||
|
tableTitle: '发货仓商品',
|
||||||
|
gridEvents: {
|
||||||
|
checkboxAll: () => syncSelection(),
|
||||||
|
checkboxChange: () => syncSelection(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
gridReloadRef.value = () => gridApi.reload();
|
||||||
|
syncVxeGridColumns(gridApi, tableColumns);
|
||||||
|
|
||||||
|
function syncSelection() {
|
||||||
|
const vxeTable = gridApi.grid;
|
||||||
|
const rows = vxeTable?.getCheckboxRecords?.() ?? [];
|
||||||
|
hasSelected.value = rows.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSidebarSelect(payload: {
|
||||||
|
scope: WarehouseSidebarScope;
|
||||||
|
warehouse: WarehouseVO.Info | null;
|
||||||
|
}) {
|
||||||
|
scope.value = payload.scope;
|
||||||
|
selectedWarehouseId.value = payload.warehouse?.id;
|
||||||
|
selectedWarehouseName.value = payload.warehouse?.name;
|
||||||
|
hasSelected.value = false;
|
||||||
|
gridApi.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadAssignOptions() {
|
||||||
|
const list = await getEnabledWarehousesApi();
|
||||||
|
assignWarehouseOptions.value = (list ?? []).map((w) => ({
|
||||||
|
label: `${w.name}(${w.code})`,
|
||||||
|
value: w.id,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSelectedSkuIds(): number[] {
|
||||||
|
const rows: ProductSkuVO.Info[] =
|
||||||
|
gridApi.grid?.getCheckboxRecords?.() ?? [];
|
||||||
|
return rows.map((r) => r.id).filter((id) => id != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openAssignSelected() {
|
||||||
|
const ids = getSelectedSkuIds();
|
||||||
|
if (!ids.length) {
|
||||||
|
message.warning('请先勾选 SKU');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assignTargetId.value =
|
||||||
|
scope.value === 'warehouse' ? selectedWarehouseId.value : undefined;
|
||||||
|
await loadAssignOptions();
|
||||||
|
assignOpen.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function confirmAssign() {
|
||||||
|
const ids = getSelectedSkuIds();
|
||||||
|
if (!ids.length) {
|
||||||
|
message.warning('请先勾选 SKU');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (assignTargetId.value == null) {
|
||||||
|
message.warning('请选择目标发货仓');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assignLoading.value = true;
|
||||||
|
try {
|
||||||
|
const res = await batchAssignWarehouseSkusApi({
|
||||||
|
skuIds: ids,
|
||||||
|
warehouseId: assignTargetId.value,
|
||||||
|
});
|
||||||
|
message.success(`已更新 ${res?.updated ?? ids.length} 个 SKU`);
|
||||||
|
assignOpen.value = false;
|
||||||
|
hasSelected.value = false;
|
||||||
|
gridApi.reload();
|
||||||
|
colPageRef.value?.refreshSidebar();
|
||||||
|
} finally {
|
||||||
|
assignLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function clearAssign() {
|
||||||
|
const ids = getSelectedSkuIds();
|
||||||
|
if (!ids.length) {
|
||||||
|
message.warning('请先勾选 SKU');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Modal.confirm({
|
||||||
|
title: '取消发货仓分配',
|
||||||
|
content: `确定将选中的 ${ids.length} 个 SKU 设为未分配?`,
|
||||||
|
okText: '确定',
|
||||||
|
cancelText: '取消',
|
||||||
|
async onOk() {
|
||||||
|
const res = await batchAssignWarehouseSkusApi({
|
||||||
|
skuIds: ids,
|
||||||
|
warehouseId: null,
|
||||||
|
});
|
||||||
|
message.success(`已取消 ${res?.updated ?? ids.length} 个分配`);
|
||||||
|
hasSelected.value = false;
|
||||||
|
gridApi.reload();
|
||||||
|
colPageRef.value?.refreshSidebar();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<EcWarehouseColPage
|
||||||
|
ref="colPageRef"
|
||||||
|
:scope="scope"
|
||||||
|
:selected-warehouse-id="selectedWarehouseId"
|
||||||
|
@select="onSidebarSelect"
|
||||||
|
>
|
||||||
|
<Card
|
||||||
|
class="flex h-full min-h-0 min-w-0 flex-1 flex-col"
|
||||||
|
:body-style="{
|
||||||
|
height: '100%',
|
||||||
|
minHeight: 0,
|
||||||
|
padding: 0,
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<template #title>
|
||||||
|
<span class="text-base font-semibold">{{ titleText }}</span>
|
||||||
|
</template>
|
||||||
|
<template #extra>
|
||||||
|
<Space wrap size="small">
|
||||||
|
<PermissionGate code="ec:warehouse:update">
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
:disabled="!hasSelected"
|
||||||
|
@click="openAssignSelected"
|
||||||
|
>
|
||||||
|
<AssignIcon class="mr-1 h-4 w-4" />
|
||||||
|
批量分配到仓
|
||||||
|
</Button>
|
||||||
|
</PermissionGate>
|
||||||
|
<PermissionGate code="ec:warehouse:update">
|
||||||
|
<Button danger :disabled="!hasSelected" @click="clearAssign">
|
||||||
|
<ClearIcon class="mr-1 h-4 w-4" />
|
||||||
|
取消分配
|
||||||
|
</Button>
|
||||||
|
</PermissionGate>
|
||||||
|
</Space>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div class="min-h-0 flex-1 overflow-hidden">
|
||||||
|
<Grid :loading="loading" />
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
v-model:open="assignOpen"
|
||||||
|
title="批量分配发货仓"
|
||||||
|
:confirm-loading="assignLoading"
|
||||||
|
ok-text="确定分配"
|
||||||
|
destroy-on-close
|
||||||
|
@ok="confirmAssign"
|
||||||
|
>
|
||||||
|
<div class="space-y-3 py-2">
|
||||||
|
<div class="text-sm text-muted-foreground">
|
||||||
|
已选 {{ getSelectedSkuIds().length }} 个 SKU,将设置其默认发货仓。
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div class="mb-1 text-sm">目标发货仓</div>
|
||||||
|
<Select
|
||||||
|
v-model:value="assignTargetId"
|
||||||
|
class="w-full"
|
||||||
|
show-search
|
||||||
|
option-filter-prop="label"
|
||||||
|
placeholder="选择发货仓"
|
||||||
|
:options="assignWarehouseOptions"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
</EcWarehouseColPage>
|
||||||
|
</template>
|
||||||
Reference in New Issue
Block a user