JeromeSoar 3 ani în urmă
părinte
comite
e4ca2e25f9

+ 4 - 2
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<List<CategoryRespVO>> listByQuery() {
-        List<CategoryDO> list = categoryService.listByQuery();
+    public CommonResult<List<CategoryRespVO>> listByQuery(@Valid CategoryTreeListReqVO treeListReqVO) {
+        List<CategoryDO> list = categoryService.getCategoryTreeList(treeListReqVO);
+        list.sort(Comparator.comparing(CategoryDO::getSort));
         return success(CategoryConvert.INSTANCE.convertList(list));
     }
 

+ 29 - 0
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;
+}

+ 3 - 5
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<CategoryDO> listByQuery();
+    List<CategoryDO> getCategoryTreeList(CategoryTreeListReqVO treeListReqVO);
 }

+ 3 - 6
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<CategoryDO> listByQuery() {
-        return categoryMapper.selectList();
+    public List<CategoryDO> getCategoryTreeList(CategoryTreeListReqVO treeListReqVO) {
+        return categoryMapper.selectList(treeListReqVO);
     }
 
 }

+ 19 - 15
yudao-ui-admin/src/views/mall/product/category/index.vue

@@ -12,10 +12,6 @@
                      :key="dict.value" :label="dict.label" :value="dict.value"/>
         </el-select>
       </el-form-item>
-      <el-form-item label="创建时间">
-        <el-date-picker v-model="dateRangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd"
-                        type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/>
-      </el-form-item>
       <el-form-item>
         <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
         <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
@@ -29,6 +25,9 @@
                    v-hasPermi="['product:category:create']">新增
         </el-button>
       </el-col>
+      <el-col :span="1.5">
+        <el-button type="info" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll">展开/折叠</el-button>
+      </el-col>
       <el-col :span="1.5">
         <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                    :loading="exportLoading"
@@ -39,7 +38,8 @@
     </el-row>
 
     <!-- 列表 -->
-    <el-table v-loading="loading" :data="list">
+    <el-table v-if="refreshTable" v-loading="loading" :data="list"  row-key="id" :default-expand-all="isExpandAll"
+              :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
       <el-table-column label="分类名称" align="center" prop="name"/>
       <el-table-column label="分类图标" align="center" prop="icon">
         <template slot-scope="scope">
@@ -73,9 +73,6 @@
         </template>
       </el-table-column>
     </el-table>
-    <!-- 分页组件 -->
-    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
-                @pagination="getList"/>
 
     <!-- 对话框(添加 / 修改) -->
     <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
@@ -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;