This commit is contained in:
kuang.yifei@iwhalecloud.com 2022-06-10 16:44:26 +08:00
commit 297e441c75
2 changed files with 49 additions and 14 deletions

View File

@ -18,7 +18,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
@Controller
@RequestMapping("/goods/goods")
@ -46,7 +45,7 @@ public class GoodsController extends BaseController {
// @RequiresPermissions("goods:goods:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(@RequestBody Goods goods) {
public TableDataInfo list(Goods goods) {
startPage();
List<Goods> list = goodsService.selectGoodsList(goods);
list.forEach(one -> {
@ -222,4 +221,25 @@ public class GoodsController extends BaseController {
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));
}
}
}

View File

@ -111,6 +111,12 @@
align: 'left',
formatter: function (value, row, index) {
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-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodsId + '\')"><i class="fa fa-trash"></i>删除</a>');
return actions.join('');
@ -119,6 +125,15 @@
};
$.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>
</body>
</html>