Commit 364b35fa authored by Junling Bu's avatar Junling Bu
Browse files

feat[litemall-admin]: 行政区域页面数据表采用树形结构显示

parent e10bf6b9
package org.linlinjava.litemall.admin.vo;
import java.util.List;
public class RegionVO {
private Integer id;
private String name;
private Byte type;
private Integer code;
private List<RegionVO> children;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public List<RegionVO> getChildren() {
return children;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Byte getType() {
return type;
}
public void setType(Byte type) {
this.type = type;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public void setChildren(List<RegionVO> children) {
this.children = children;
}
}
...@@ -3,6 +3,7 @@ package org.linlinjava.litemall.admin.web; ...@@ -3,6 +3,7 @@ package org.linlinjava.litemall.admin.web;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.admin.vo.RegionVO;
import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.validator.Order; import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort; import org.linlinjava.litemall.core.validator.Sort;
...@@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -36,17 +38,44 @@ public class AdminRegionController { ...@@ -36,17 +38,44 @@ public class AdminRegionController {
} }
@GetMapping("/list") @GetMapping("/list")
public Object list(String name, Integer code, public Object list() {
@RequestParam(defaultValue = "1") Integer page, List<RegionVO> regionVOList = new ArrayList<>();
@RequestParam(defaultValue = "10") Integer limit,
@Sort(accepts = {"id"}) @RequestParam(defaultValue = "id") String sort, List<LitemallRegion> provinceList = regionService.queryByPid(0);
@Order @RequestParam(defaultValue = "desc") String order) { for(LitemallRegion province : provinceList){
List<LitemallRegion> regionList = regionService.querySelective(name, code, page, limit, sort, order); RegionVO provinceVO = new RegionVO();
long total = PageInfo.of(regionList).getTotal(); provinceVO.setId(province.getId());
Map<String, Object> data = new HashMap<>(); provinceVO.setName(province.getName());
data.put("total", total); provinceVO.setCode(province.getCode());
data.put("items", regionList); provinceVO.setType(province.getType());
return ResponseUtil.ok(data); List<LitemallRegion> cityList = regionService.queryByPid(province.getId());
List<RegionVO> cityVOList = new ArrayList<>();
for(LitemallRegion city : cityList){
RegionVO cityVO = new RegionVO();
cityVO.setId(city.getId());
cityVO.setName(city.getName());
cityVO.setCode(city.getCode());
cityVO.setType(city.getType());
List<LitemallRegion> areaList = regionService.queryByPid(city.getId());
List<RegionVO> areaVOList = new ArrayList<>();
for(LitemallRegion area : areaList){
RegionVO areaVO = new RegionVO();
areaVO.setId(area.getId());
areaVO.setName(area.getName());
areaVO.setCode(area.getCode());
areaVO.setType(area.getType());
areaVOList.add(areaVO);
}
cityVO.setChildren(areaVOList);
cityVOList.add(cityVO);
}
provinceVO.setChildren(cityVOList);
regionVOList.add(provinceVO);
}
return ResponseUtil.ok(regionVOList);
} }
} }
import request from '@/utils/request' import request from '@/utils/request'
export function listRegion(query) { export function listRegion() {
return request({ return request({
url: '/region/list', url: '/region/list',
method: 'get', method: 'get'
params: query
}) })
} }
......
<template> <template>
<div class="app-container"> <div class="app-container">
<!-- 查询和其他操作 --> <el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" row-key="id" style="width: 100%;margin-bottom: 20px;" border="">
<div class="filter-container">
<el-input v-model="listQuery.name" clearable class="filter-item" style="width: 200px;" placeholder="请输入行政区域名称"/>
<el-input v-model="listQuery.code" clearable class="filter-item" style="width: 200px;" placeholder="请输入行政区域编码"/>
<el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">查找</el-button>
<el-button :loading="downloadLoading" class="filter-item" type="primary" icon="el-icon-download" @click="handleDownload">导出</el-button>
</div>
<!-- 查询结果 --> <el-table-column label="区域名称" prop="name"/>
<el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row>
<el-table-column align="center" width="100px" label="区域ID" prop="id" sortable/> <el-table-column label="区域类型" prop="type">
<el-table-column align="center" min-width="100px" label="区域父ID" prop="pid"/>
<el-table-column align="center" min-width="200px" label="区域名称" prop="name"/>
<el-table-column align="center" min-width="100px" label="区域类型" prop="type">
<template slot-scope="scope"> <template slot-scope="scope">
{{ scope.row.type | typeFilter }} {{ scope.row.type | typeFilter }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" min-width="100px" label="区域编码" prop="code"/> <el-table-column label="区域编码" prop="code"/>
</el-table> </el-table>
<pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
</div> </div>
</template> </template>
<script> <script>
import { listRegion } from '@/api/region' import { listRegion } from '@/api/region'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
export default { export default {
name: 'Region', name: 'Region',
components: { Pagination },
filters: { filters: {
typeFilter(status) { typeFilter(status) {
const typeMap = { const typeMap = {
...@@ -53,14 +36,7 @@ export default { ...@@ -53,14 +36,7 @@ export default {
data() { data() {
return { return {
list: undefined, list: undefined,
total: 0,
listLoading: true, listLoading: true,
listQuery: {
page: 1,
limit: 20,
name: undefined,
code: undefined
},
downloadLoading: false downloadLoading: false
} }
}, },
...@@ -70,28 +46,13 @@ export default { ...@@ -70,28 +46,13 @@ export default {
methods: { methods: {
getList() { getList() {
this.listLoading = true this.listLoading = true
listRegion(this.listQuery).then(response => { listRegion().then(response => {
this.list = response.data.data.items this.list = response.data.data
this.total = response.data.data.total
this.listLoading = false this.listLoading = false
}).catch(() => { }).catch(() => {
this.list = [] this.list = []
this.total = 0
this.listLoading = false this.listLoading = false
}) })
},
handleFilter() {
this.listQuery.page = 1
this.getList()
},
handleDownload() {
this.downloadLoading = true
import('@/vendor/Export2Excel').then(excel => {
const tHeader = ['区域ID', '区域父ID', '区域名称', '区域类型', '区域编码']
const filterVal = ['id', 'pid', 'name', 'type', 'code']
excel.export_json_to_excel2(tHeader, this.list, filterVal, '行政区域信息')
this.downloadLoading = false
})
} }
} }
} }
......
...@@ -51,4 +51,11 @@ public class LitemallRegionService { ...@@ -51,4 +51,11 @@ public class LitemallRegionService {
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
return regionMapper.selectByExample(example); return regionMapper.selectByExample(example);
} }
public List<LitemallRegion> queryChildren(Integer id) {
LitemallRegionExample example = new LitemallRegionExample();
example.or().andPidEqualTo(id);
return regionMapper.selectByExample(example);
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment