diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/CategoryController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/CategoryController.java index ed22def1d..9e5614a87 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/CategoryController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/CategoryController.java @@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; import java.util.Collection; +import java.util.Comparator; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -78,8 +79,9 @@ public class CategoryController { @GetMapping("/listByQuery") @ApiOperation("获得商品分类列表") @PreAuthorize("@ss.hasPermission('product:category:query')") - public CommonResult> listByQuery() { - List list = categoryService.listByQuery(); + public CommonResult> listByQuery(@Valid CategoryTreeListReqVO treeListReqVO) { + List list = categoryService.getCategoryTreeList(treeListReqVO); + list.sort(Comparator.comparing(CategoryDO::getSort)); return success(CategoryConvert.INSTANCE.convertList(list)); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryTreeListReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryTreeListReqVO.java new file mode 100644 index 000000000..12256efd3 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryTreeListReqVO.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.product.controller.admin.category.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Data +@ApiModel(value = "管理后台 - 商品分类列表查询 Request VO", description = "参数和 CategoryPageReqVO 是一致的") +public class CategoryTreeListReqVO extends CategoryExportReqVO { + + @ApiModelProperty(value = "分类名称", example = "办公文具") + private String name; + + @ApiModelProperty(value = "开启状态", example = "0") + private Integer status; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "开始创建时间") + private Date beginCreateTime; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "结束创建时间") + private Date endCreateTime; +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryService.java index 89ac934fb..b29b3418f 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryService.java @@ -1,10 +1,7 @@ package cn.iocoder.yudao.module.product.service.category; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryCreateReqVO; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryExportReqVO; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryPageReqVO; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryUpdateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.category.vo.*; import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO; import javax.validation.Valid; @@ -75,7 +72,8 @@ public interface CategoryService { /** * 获得商品分类列表 * + * @param treeListReqVO 查询条件 * @return 商品分类列表 */ - List listByQuery(); + List getCategoryTreeList(CategoryTreeListReqVO treeListReqVO); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImpl.java index 1465892f6..b84ac5b9a 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImpl.java @@ -1,10 +1,7 @@ package cn.iocoder.yudao.module.product.service.category; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryCreateReqVO; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryExportReqVO; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryPageReqVO; -import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryUpdateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.category.vo.*; import cn.iocoder.yudao.module.product.convert.category.CategoryConvert; import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO; import cn.iocoder.yudao.module.product.dal.mysql.category.CategoryMapper; @@ -83,8 +80,8 @@ public class CategoryServiceImpl implements CategoryService { } @Override - public List listByQuery() { - return categoryMapper.selectList(); + public List getCategoryTreeList(CategoryTreeListReqVO treeListReqVO) { + return categoryMapper.selectList(treeListReqVO); } } diff --git a/yudao-ui-admin/src/views/mall/product/category/index.vue b/yudao-ui-admin/src/views/mall/product/category/index.vue index 26cfcdf94..cfef21c0f 100644 --- a/yudao-ui-admin/src/views/mall/product/category/index.vue +++ b/yudao-ui-admin/src/views/mall/product/category/index.vue @@ -12,10 +12,6 @@ :key="dict.value" :label="dict.label" :value="dict.value"/> - - - 搜索 重置 @@ -29,6 +25,9 @@ v-hasPermi="['product:category:create']">新增 + + 展开/折叠 + - + - - @@ -161,7 +158,10 @@ export default { title: "", // 是否显示弹出层 open: false, - dateRangeCreateTime: [], + // 是否展开,默认全部折叠 + isExpandAll: false, + // 重新渲染表格状态 + refreshTable: true, // 查询参数 queryParams: { pageNo: 1, @@ -190,11 +190,9 @@ export default { this.loading = true; // 处理查询参数 let params = {...this.queryParams}; - this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime'); // 执行查询 - getCategoryPage(params).then(response => { - this.list = response.data.list; - this.total = response.data.total; + listCategory(params).then(response => { + this.list = this.handleTree(response.data, "id", "pid"); this.loading = false; }); }, @@ -248,10 +246,17 @@ export default { }, /** 重置按钮操作 */ resetQuery() { - this.dateRangeCreateTime = []; this.resetForm("queryForm"); this.handleQuery(); }, + /** 展开/折叠操作 */ + toggleExpandAll() { + this.refreshTable = false; + this.isExpandAll = !this.isExpandAll; + this.$nextTick(() => { + this.refreshTable = true; + }); + }, /** 新增按钮操作 */ handleAdd() { this.reset(); @@ -310,7 +315,6 @@ export default { let params = {...this.queryParams}; params.pageNo = undefined; params.pageSize = undefined; - this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime'); // 执行导出 this.$modal.confirm('是否确认导出所有商品分类数据项?').then(() => { this.exportLoading = true;