#set($layout = "layout/null.vm") <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="myModalLabel"> #if($conSellerGoods)商家商品更新 #else 商家商品新增 #end </h4> </div> <form id="conSellerGoodsEdit_form" method="post" class="form-horizontal bv-form" novalidate="novalidate"> <input type="hidden" id="id" name="id" value="$!{conSellerGoods.id}"/> <button type="submit" class="bv-hidden-submit" style="display: none; width: 0px; height: 0px;"></button> <div class="modal-body"> <div class="row"> <div class="col-sm-6"> <div class="form-group has-feedback"> <label class="col-sm-4 control-label" style="padding-left: 0px;">商品编码</label> <div class="col-sm-8" style="padding-left: 0px;"> <input readonly class="form-control" id="goodsNo" name="goodsNo" value="$!{conSellerGoods.goodsNo}"/> </div> </div> </div> <div class="col-sm-6"> <div class="form-group has-feedback"> <label class="col-sm-4 control-label" style="padding-left: 0px;">商品名称</label> <div class="col-sm-8" style="padding-left: 0px;"> <input readonly class="form-control" id="goodsName" name="goodsName" value="$!{conSellerGoods.goodsName}"/> </div> </div> </div> </div> <div class="row"> <div class="col-sm-6"> <div class="form-group has-feedback"> <label class="col-sm-4 control-label" style="padding-left: 0px;">统一售价(元)</label> <input type="text" id="saleUnitRealPrice" value="$!{conSellerGoods.saleUnitRealPrice}"> <input type="button" value="修改售价" id="updateTotalPrice"> </div> </div> </div> <div class="row" style="display: none;"> <div class="col-sm-6"> <div class="form-group has-feedback"> <label class="col-sm-4 control-label" style="padding-left: 0px;">项目编号</label> <div class="col-sm-8" style="padding-left: 0px;"> <input class="form-control" id="projectNo" name="projectNo" value="$!{conSellerGoods.projectNo}"/> </div> </div> </div> <div class="col-sm-6"> <div class="form-group has-feedback"> <label class="col-sm-4 control-label" style="padding-left: 0px;">项目名称</label> <div class="col-sm-8" style="padding-left: 0px;"> <input class="form-control" id="projectName" name="projectName" value="$!{conSellerGoods.projectName}"/> <input readonly style="display: none;" class="form-control" id="sellerNo" name="sellerNo" value="$!{conSellerGoods.sellerNo}"/> <input readonly style="display: none;" class="form-control" id="goodsNo" name="goodsNo" value="$!{conSellerGoods.goodsNo}"/> </div> </div> </div> </div> <div class="row"> <table class="ui-jqgrid-htable ui-common-table table table-bordered" style="margin-bottom: 0px"> <thead> <tr class="ui-jqgrid-labels" role="row"> <th style="width: 10%;text-align: center;">序号</th> <th style="width: 25%;text-align: center;">门店名称</th> <th style="width: 25%;text-align: center;">设备名称</th> <th style="width: 25%;text-align: center;">单独售价</th> </tr> </thead> </table> <table id="boxGoods" class="ui-jqgrid-htable ui-common-table table table-bordered table-hover table-striped"> <tbody> #foreach( $item in $boxGoodsList) <tr class="ui-jqgrid-labels" role="row"> <td style="width: 10%;text-align: center;">$velocityCount</td> <td style="width: 25%;text-align: center;">$!{item.storeName}</td> <td style="width: 25%;text-align: center;">$!{item.boxName}</td> <td style="width: 25%;text-align: center;"> <input type="text" style="width: 120px;text-align: center;" value="$!{item.realtimePrice}"> </td> <td style="display: none">$!{item.id}</td> <td style="display: none">$!{item.sellerNo}</td> <td style="display: none">$!{item.goodsNo}</td> </tr> #end </tbody> </table> </div> <div class="modal-footer"> <button id="conSellerGoods_sumbit3" type="button" class="btn btn-primary" onclick="updateListBoxGoodsPrice()">保存 </button> <a href="#" class="btn btn-info" id="closeModal" data-dismiss="modal">关闭</a> </div> </form> </div> </div> <script src="${assetModule}/static/script/conSellerGoods/conSellerGoodsEdit.js"></script> <script type="text/javascript"> // 更新统一商品价格 function updateListBoxGoodsPrice() { var arrayColumn = new Array(); //遍历table $('#boxGoods tr').each(function (i) { // 遍历 tr var rowGoods = new Object(); //定义一个对象 $(this).children('td').each(function (j) { // 遍历 tr 的各个 td //alert("第" + (i + 1) + "行,第" + (j + 1) + "个td的值:" + $(this).text() + "。"); if (j == 3) { console.log($($(this).children('input')[0]).val()); rowGoods.realtimePrice = $($(this).children('input')[0]).val(); } if (j == 4) { console.log($(this).text()); rowGoods.id = $(this).text(); } if (j == 5) { rowGoods.sellerNo = $(this).text(); } if (j == 6) { rowGoods.goodsNo = $(this).text(); } }); arrayColumn.push(rowGoods); }); jQuery.ajax({ type: "post", url: "conBoxGoods/updateListBoxGoodsPrice.do", data: JSON.stringify(arrayColumn), dataType: "json", contentType: "application/json", // 指定这个协议很重要 success: function (data) { console.log(data); if (data.resultCode == 1) { alert("修改成功") //$("#closeModal").click(); } else { alert("修改失败") } //alert(data.msg); return true; } }); } </script>
后台:
/** * 编辑设备货柜商品数据 * * @return */ @RequestMapping(value = "/updateListBoxGoodsPrice.do", method = {RequestMethod.POST}) public @ResponseBody Object updateListBoxGoodsPrice(HttpServletRequest request, @RequestBody ConBoxGoods[] conBoxGoodsList) { Result result = new Result(); if (conBoxGoodsList.length > 0) { String userCode = String.valueOf(request.getAttribute(CommonConfig.USER_CODE)); List<ConBoxGoods> lsitBoxGoods = Arrays.asList(conBoxGoodsList); lsitBoxGoods.forEach(item -> { item.setUpdateTime(new Date()); item.setUpdateUser(userCode); }); result = conBoxGoodsBusiness.updateListBoxGoodsPrice(lsitBoxGoods); } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RETURN_MESSAGE_DEFAULT_KEY, StkConstants.SERVICE_RESULT_FAIL_MESSAGE); } return result; }