HTML部分:
<table id="carouselInfoListTab"
class="table table-bordered text-center table-striped table-hover table-th-nowrap mt20 table-td-m"
xmlns:th="http://www.w3.org/1999/xhtml">
<thead>
<tr class="active">
<th>选择</th>
<th>展示顺序</th>
<th>商品标识</th>
<th>商品名称</th>
<th>商品描述</th>
<th>默认图片链接</th>
<th>开始时间</th>
<th>结束时间</th>
<th>活动标识</th>
<th width="100">操作</th>
</tr>
</thead>
<tbody>
<tr th:if="${#lists.isEmpty(goodsList)}">
<td colspan="15">没有数据</td>
</tr>
<tr th:unless="${#lists.isEmpty(goodsList.result)}" id="proNmSelectList" th:each="map,indexInc:${goodsList.result}">
<td><input type="checkbox" name="proNmCheck" th:value="${indexInc.index}+1"/></td>
<td th:text="${map.showOrder}" th:id="showOrder+(${indexInc.index}+1)" contenteditable="true"></td>
<td th:text="${map.proId}" th:id="proId+(${indexInc.index}+1)"></td>
<td th:text="${map.proNm}" th:id="proNm+(${indexInc.index}+1)"></td>
<td th:text="${map.proExplain}" th:id="proExplain+(${indexInc.index}+1)" contenteditable="true"></td>
<td th:text="${map.picLocation}" th:id="picLocation+(${indexInc.index}+1)" contenteditable="true"></td>
<td th:text="${#dates.format(map.startDate,'yyyy-MM-dd HH:mm:ss')}" class="startDate"
th:id="startDate+(${indexInc.index}+1)" contenteditable="true"></td>
<!--th:onclick="|dateFormate((${indexInc.index}+1))|" th:onclick="|dateFormate((${indexInc.index}+1))|"-->
<td th:text="${#dates.format(map.endDate,'yyyy-MM-dd HH:mm:ss')}" class="endDate"
th:id="endDate+(${indexInc.index}+1)" contenteditable="true"></td>
<td th:text="${map.actId}" th:id="actIdIn+(${indexInc.index}+1)"></td>
<td>
<a th:onclick="|addRecommendGoods((${indexInc.index}+1))|">提交</a> |
<a th:onclick="|deleteRecommendGoods((${indexInc.index}+1))|">删除</a>
</td>
</tr>
<tr>
<td href="javascript:void(0)" th:text="提交" id="batchAddRecommendGoodsBtn"
onclick='batchAddRecommendGoods()' class="btn-primary btn mr10"></td>
</tr>
</tbody>
</table>
js:
function batchAddRecommendGoods() {
//校验
var proNmCheck =$('input[name="proNmCheck"]:checked');
if(null == proNmCheck){
alert("请选择要添加的商品!");
return;
}
var proNmCheckSize = proNmCheck.length;
if(0==proNmCheckSize){
alert("请选择要添加的商品!");
return;
}
var datas = new Array();//取出来的ID拼接后传回后台
for (var i = 0; i<proNmCheckSize;i++) {
datas.push(jointParameters(proNmCheck[i].value));
}
var qryUrl = WEB_ROOT + "/setRecommendGoods/batchAddRecommendGoods";
$.gridUnLoading({message: "正在添加"});
$.ajax({
url: qryUrl,
data: {"data": encodeURIComponent(JSON.stringify(datas))},//前台编码,后台解码,保证所传参数不会被转译
async: true,
dataType: "json",
success: function (data) {
if (data) {
alert("添加推荐商品成功");
}else {
alert("添加推荐商品失败");
}
},
error: function () {
$.gridUnLoading({message: "添加推荐商品失败"});
}
});
}
function jointParameters(numberIndex) {
var data = new Object;
data.showOrder = document.getElementById('showOrder'+numberIndex).innerHTML;
data.proNm = document.getElementById('proNm'+numberIndex).innerHTML;
data.proExplain = document.getElementById('proExplain'+numberIndex).innerHTML;
data.picLocation = document.getElementById('picLocation'+numberIndex).innerHTML;
// data.linkRef = document.getElementById('linkRef'+number).innerHTML;
data.proId = document.getElementById('proId'+numberIndex).innerHTML;
data.startDate = document.getElementById('startDate'+numberIndex).innerHTML;
data.endDate = document.getElementById('endDate'+numberIndex).innerHTML;
data.actId = document.getElementById('actIdIn'+numberIndex).innerHTML;
if (!data.actId || !data.proId || !data.proNm || !data.proExplain || !data.startDate || !data.endDate) {
alert("请填写完整商品ID为“"+data.proId+"”的商品信息再添加");
return;
}
if ("请输入商品描述" == data.proExplain || "null" == data.proExplain) {
alert("请输入商品ID为“"+data.proId+"”的商品描述,再提交!");
return;
}
return data;
}