商品列表增加上架/下架按钮
This commit is contained in:
parent
4bd975d7c4
commit
8cd6050dfe
|
|
@ -18,7 +18,6 @@ import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/goods/goods")
|
@RequestMapping("/goods/goods")
|
||||||
|
|
@ -43,13 +42,13 @@ public class GoodsController extends BaseController {
|
||||||
return PREFIX + "/goods";
|
return PREFIX + "/goods";
|
||||||
}
|
}
|
||||||
|
|
||||||
// @RequiresPermissions("goods:goods:list")
|
// @RequiresPermissions("goods:goods:list")
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public TableDataInfo list(@RequestBody Goods goods) {
|
public TableDataInfo list(Goods goods) {
|
||||||
startPage();
|
startPage();
|
||||||
List<Goods> list = goodsService.selectGoodsList(goods);
|
List<Goods> list = goodsService.selectGoodsList(goods);
|
||||||
list.forEach(one->{
|
list.forEach(one -> {
|
||||||
// 补全商品
|
// 补全商品
|
||||||
List<GoodsArea> goodsAreas = goodsAreaService.selectByGoodsId(one.getGoodsId());
|
List<GoodsArea> goodsAreas = goodsAreaService.selectByGoodsId(one.getGoodsId());
|
||||||
one.setGoodsAreaList(goodsAreas);
|
one.setGoodsAreaList(goodsAreas);
|
||||||
|
|
@ -70,13 +69,13 @@ public class GoodsController extends BaseController {
|
||||||
deptGoodsCategory.setLevel(2);
|
deptGoodsCategory.setLevel(2);
|
||||||
List<DeptGoodsCategory> categoryList = deptGoodsCategoryService.list(deptGoodsCategory);
|
List<DeptGoodsCategory> categoryList = deptGoodsCategoryService.list(deptGoodsCategory);
|
||||||
Collection<Long> ids = new ArrayList<>();
|
Collection<Long> ids = new ArrayList<>();
|
||||||
categoryList.forEach(category->{
|
categoryList.forEach(category -> {
|
||||||
ids.add(category.getGoodsCategoryId());
|
ids.add(category.getGoodsCategoryId());
|
||||||
});
|
});
|
||||||
|
|
||||||
startPage();
|
startPage();
|
||||||
List<Goods> list = goodsService.selectByCategoryIds(ids);
|
List<Goods> list = goodsService.selectByCategoryIds(ids);
|
||||||
list.forEach(one->{
|
list.forEach(one -> {
|
||||||
// 补全商品
|
// 补全商品
|
||||||
List<GoodsArea> goodsAreas = goodsAreaService.selectByGoodsId(one.getGoodsId());
|
List<GoodsArea> goodsAreas = goodsAreaService.selectByGoodsId(one.getGoodsId());
|
||||||
one.setGoodsAreaList(goodsAreas);
|
one.setGoodsAreaList(goodsAreas);
|
||||||
|
|
@ -90,11 +89,11 @@ public class GoodsController extends BaseController {
|
||||||
|
|
||||||
@PostMapping("/addGoods")
|
@PostMapping("/addGoods")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult addGoods(@RequestBody Goods goods){
|
public AjaxResult addGoods(@RequestBody Goods goods) {
|
||||||
try {
|
try {
|
||||||
goodsService.addGoods(goods);
|
goodsService.addGoods(goods);
|
||||||
return AjaxResult.success("新增成功");
|
return AjaxResult.success("新增成功");
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return AjaxResult.error(ExceptionUtil.getExceptionMessage(e));
|
return AjaxResult.error(ExceptionUtil.getExceptionMessage(e));
|
||||||
|
|
@ -103,7 +102,7 @@ public class GoodsController extends BaseController {
|
||||||
|
|
||||||
@PostMapping("/getDetail")
|
@PostMapping("/getDetail")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult getDetail(@RequestBody Goods goods){
|
public AjaxResult getDetail(@RequestBody Goods goods) {
|
||||||
try {
|
try {
|
||||||
Goods result = goodsService.selectById(goods.getGoodsId());
|
Goods result = goodsService.selectById(goods.getGoodsId());
|
||||||
|
|
||||||
|
|
@ -124,7 +123,7 @@ public class GoodsController extends BaseController {
|
||||||
result.setGoodsStandardList(goodsStandards);
|
result.setGoodsStandardList(goodsStandards);
|
||||||
|
|
||||||
return AjaxResult.success(result);
|
return AjaxResult.success(result);
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return AjaxResult.error(ExceptionUtil.getExceptionMessage(e));
|
return AjaxResult.error(ExceptionUtil.getExceptionMessage(e));
|
||||||
|
|
@ -222,4 +221,25 @@ public class GoodsController extends BaseController {
|
||||||
return goodsService.checkGoodsCodeUnique(goods);
|
return goodsService.checkGoodsCodeUnique(goods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改商品状态
|
||||||
|
*
|
||||||
|
* @param goodsId 商品ID
|
||||||
|
* @param status 0=上架,1=下架,2删除
|
||||||
|
*/
|
||||||
|
@PostMapping("/status")
|
||||||
|
@ResponseBody
|
||||||
|
public AjaxResult status(Long goodsId, Integer status) {
|
||||||
|
try {
|
||||||
|
Goods goods = new Goods();
|
||||||
|
goods.setGoodsId(goodsId);
|
||||||
|
goods.setStatus(status);
|
||||||
|
goodsService.updateGoods(goods);
|
||||||
|
return AjaxResult.success("操作成功");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
return AjaxResult.error(ExceptionUtil.getExceptionMessage(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
<li>
|
<li>
|
||||||
类目状态:<select name="status" th:with="type=${@dict.getType('goods_status')}">
|
类目状态:<select name="status" th:with="type=${@dict.getType('goods_status')}">
|
||||||
<option value="">所有</option>
|
<option value="">所有</option>
|
||||||
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" />
|
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"/>
|
||||||
</select>
|
</select>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
|
@ -34,9 +34,9 @@
|
||||||
<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="goods:goods:add">
|
<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="goods:goods:add">
|
||||||
<i class="fa fa-plus"></i> 新增
|
<i class="fa fa-plus"></i> 新增
|
||||||
</a>
|
</a>
|
||||||
<!-- <a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="goods:goods:edit">-->
|
<!-- <a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="goods:goods:edit">-->
|
||||||
<!-- <i class="fa fa-edit"></i> 修改-->
|
<!-- <i class="fa fa-edit"></i> 修改-->
|
||||||
<!-- </a>-->
|
<!-- </a>-->
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 select-table table-striped">
|
<div class="col-sm-12 select-table table-striped">
|
||||||
<table id="bootstrap-table"></table>
|
<table id="bootstrap-table"></table>
|
||||||
|
|
@ -111,6 +111,12 @@
|
||||||
align: 'left',
|
align: 'left',
|
||||||
formatter: function (value, row, index) {
|
formatter: function (value, row, index) {
|
||||||
var actions = [];
|
var actions = [];
|
||||||
|
if (row.status === 1) {
|
||||||
|
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="enable(\'' + row.goodsId + '\')"><i class="fa fa-arrow-up"></i>上架</a> ');
|
||||||
|
}
|
||||||
|
if (row.status === 0) {
|
||||||
|
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="disable(\'' + row.goodsId + '\')"><i class="fa fa-arrow-down"></i>下架</a> ');
|
||||||
|
}
|
||||||
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.goodsId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
|
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.goodsId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
|
||||||
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodsId + '\')"><i class="fa fa-trash"></i>删除</a>');
|
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodsId + '\')"><i class="fa fa-trash"></i>删除</a>');
|
||||||
return actions.join('');
|
return actions.join('');
|
||||||
|
|
@ -119,6 +125,15 @@
|
||||||
};
|
};
|
||||||
$.table.init(options);
|
$.table.init(options);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function enable(goodsId) {
|
||||||
|
$.operate.post(prefix + "/status?goodsId=" + goodsId + "&status=" + 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function disable(goodsId) {
|
||||||
|
$.operate.post(prefix + "/status?goodsId=" + goodsId + "&status=" + 1);
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Loading…
Reference in New Issue