|
@@ -0,0 +1,237 @@
|
|
|
+<%@ page import="java.util.Date" %>
|
|
|
+<%@ page contentType="text/html;charset=UTF-8" %>
|
|
|
+<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
|
|
|
+<html>
|
|
|
+<head>
|
|
|
+ <title>相关推荐管理</title>
|
|
|
+ <meta name="decorator" content="default"/>
|
|
|
+ <script type="text/javascript">
|
|
|
+ $(document).ready(function() {
|
|
|
+ //$("#name").focus();
|
|
|
+ $("#inputForm").validate({
|
|
|
+ submitHandler: function(form){
|
|
|
+ loading('正在提交,请稍等...');
|
|
|
+ form.submit();
|
|
|
+ },
|
|
|
+ errorContainer: "#messageBox",
|
|
|
+ errorPlacement: function(error, element) {
|
|
|
+ $("#messageBox").text("输入有误,请先更正。");
|
|
|
+ if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
|
|
|
+ error.appendTo(element.parent().parent());
|
|
|
+ } else {
|
|
|
+ error.insertAfter(element);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ </script>
|
|
|
+</head>
|
|
|
+<body>
|
|
|
+ <ul class="nav nav-tabs">
|
|
|
+ <li><a href="${ctx}/baike/cmBaikeProduct/?commodityType=${cmBaikeProduct.commodityType}">${commodityType}</a></li>
|
|
|
+ <li class="active"><a href="${ctx}/baike/cmBaikeProduct/recommend/form?id=${cmBaikeProduct.id}">相关推荐编辑</a></li>
|
|
|
+ </ul><br/>
|
|
|
+ <table class="table table-striped table-bordered table-condensed">
|
|
|
+ <p><b>${commodityType}名称:</b>${cmBaikeProduct.name}</p>
|
|
|
+ <p><b>推荐列表</b><font color="red">(当前列表推荐数 <span class="recommendCount"></span>, 最多可推荐15条)</font></p>
|
|
|
+ <input class="btn btn-primary" id="showSelectBtn" style="width: 70px;margin-bottom: 10px"
|
|
|
+ onclick="showSelect()" value="添加"/>
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>ID</th>
|
|
|
+ <th>${commodityType}名称</th>
|
|
|
+ <th class="manualData" style="${cmBaikeProduct.recommendType ne 1?'display:none':''}">排序</th>
|
|
|
+ <th class="manualData" style="${cmBaikeProduct.recommendType ne 1?'display:none':''}">操作</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody id="productTbody">
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+ <div class="flex-wrap">
|
|
|
+ <div class="item">
|
|
|
+ <label><font color="red">*</font><b>设置类型:</b></label>
|
|
|
+ <input type="radio" name="recommendType" value="1" onchange="changeRecommendType()" ${cmBaikeProduct.recommendType == 1 ? "checked" : ""} />手动选择<b class="line">|</b>
|
|
|
+ <input type="radio" name="recommendType" value="2" onchange="changeRecommendType()" ${cmBaikeProduct.recommendType == 2 ? "checked" : ""} />自动选择
|
|
|
+ <span style="color:#D0D0D0;">(设置自动选择后,系统将自动推荐相同分类中的排序前15个进行推荐)</span>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="form-actions">
|
|
|
+ <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>
|
|
|
+ <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
|
|
|
+ </div>
|
|
|
+<script>
|
|
|
+
|
|
|
+ var productImageList = [];
|
|
|
+ // 手动列表
|
|
|
+ var manualImageList = [];
|
|
|
+ // 自动列表
|
|
|
+ var autoImageList = [];
|
|
|
+ var productIds = '';
|
|
|
+ var recommendCount = 0;
|
|
|
+ var recommendType = ${cmBaikeProduct.recommendType};
|
|
|
+
|
|
|
+ $(function () {
|
|
|
+ //数据填充
|
|
|
+ if (recommendType == 1) {
|
|
|
+ <c:forEach items="${manualRecommendList}" var="product" varStatus="index">
|
|
|
+ manualImageList.push({
|
|
|
+ recommendProductId: "${product.recommendProductId}",
|
|
|
+ recommendProductName: "${product.recommendProductName}",
|
|
|
+ sort: "${product.sort}"
|
|
|
+ });
|
|
|
+ </c:forEach>
|
|
|
+ }
|
|
|
+ <c:forEach items="${autoRecommendList}" var="product" varStatus="index">
|
|
|
+ autoImageList.push({
|
|
|
+ recommendProductId: "${product.recommendProductId}",
|
|
|
+ recommendProductName: "${product.recommendProductName}",
|
|
|
+ sort: 0,
|
|
|
+ createDate: '<fmt:formatDate value="<%=new Date()%>" pattern="yyyy-MM-dd HH:mm:ss"/>'
|
|
|
+ });
|
|
|
+ </c:forEach>
|
|
|
+ batchSaveSort()
|
|
|
+ })
|
|
|
+
|
|
|
+ //点击添加
|
|
|
+ function showSelect() {
|
|
|
+ if (recommendCount >= 15) {
|
|
|
+ alertx('最多只能推荐15条');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var commodityType = '${cmBaikeProduct.commodityType}';
|
|
|
+ var url = "${ctx}/baike/cmBaikeProduct/recommend/products?productIds=" + productIds + "&commodityType=" + commodityType;
|
|
|
+ title = '添加${commodityType}';
|
|
|
+ width = 700;
|
|
|
+ height = 600;
|
|
|
+ top.$.jBox("iframe:" + url, {
|
|
|
+ iframeScrolling: 'yes',
|
|
|
+ width: width,
|
|
|
+ height: height,
|
|
|
+ persistent: true,
|
|
|
+ title: title,
|
|
|
+ buttons: {"确定": '1', "取消": '-1'},
|
|
|
+ submit: function (v, h, f) {
|
|
|
+ //确定
|
|
|
+ var $jboxFrame = top.$('#jbox-iframe');
|
|
|
+ var $mainFrame = top.$('#mainFrame');
|
|
|
+ if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
|
|
|
+ var items = $jboxFrame[0].contentWindow.getCheckedItems();
|
|
|
+ console.log(items);
|
|
|
+ items.forEach(item =>{
|
|
|
+ items.createDate = '<fmt:formatDate value="<%=new Date()%>" pattern="yyyy-MM-dd HH:mm:ss"/>';
|
|
|
+ manualImageList.push(item);
|
|
|
+ })
|
|
|
+ batchSaveSort();
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 一键排序
|
|
|
+ */
|
|
|
+ function batchSaveSort() {
|
|
|
+ if (recommendType == 1) {
|
|
|
+ productImageList = manualImageList;
|
|
|
+ } else {
|
|
|
+ productImageList = autoImageList;
|
|
|
+ }
|
|
|
+ productImageList.sort(sort);
|
|
|
+ insertHtml();
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据sort值 从小到大排序
|
|
|
+ function sort(a, b) {
|
|
|
+ return ((a.sort - b.sort) == 0 ? (a.createDate > b.createDate ? -1 : 1) : (a.sort - b.sort));
|
|
|
+ }
|
|
|
+
|
|
|
+ function insertHtml() {
|
|
|
+ var html = '';
|
|
|
+ productIds = '';
|
|
|
+ recommendCount = 0;
|
|
|
+ productImageList.forEach(function (item, index) {
|
|
|
+ recommendCount++;
|
|
|
+ html += appendProductHtml(item, index);
|
|
|
+ productIds += item.recommendProductId + ",";
|
|
|
+ });
|
|
|
+ $(".recommendCount").text(recommendCount);
|
|
|
+ $("#productTbody").html(html);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //相关图片列表数据
|
|
|
+ function appendProductHtml(data, index) {
|
|
|
+ var html = '<tr>' +
|
|
|
+ '<td>' +
|
|
|
+ data.recommendProductId +
|
|
|
+ '</td>' +
|
|
|
+ '<td>' + data.recommendProductName + '</td>' +
|
|
|
+ (recommendType == 1?
|
|
|
+ '<td>' +
|
|
|
+ '<input name="sort" style="width:50px;" value="' + data.sort + '" onkeyup="onlynum(this)" onchange="changeSort(' + index + ',this)"></td>' +
|
|
|
+ '</td>' +
|
|
|
+ '<td>' +
|
|
|
+ ' <a href="javascript:;" onclick="delect(' + index + ')">删除</a>' +
|
|
|
+ '</td>':'') +
|
|
|
+ '</tr>';
|
|
|
+ return html;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除操作
|
|
|
+ */
|
|
|
+ function delect(index) {
|
|
|
+ return confirmx("确定删除该数据吗?", function () {
|
|
|
+ var image = getImage(index);
|
|
|
+ if (image.recommendProductId != '') {
|
|
|
+ productIds = productIds.replace(image.recommendProductId, "");
|
|
|
+ }
|
|
|
+ productImageList.splice(index, 1);
|
|
|
+ insertHtml();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function changeSort(index, sortThis) {
|
|
|
+ var sort = sortThis.value;
|
|
|
+ var image = getImage(index);
|
|
|
+ image.sort = sort;
|
|
|
+ }
|
|
|
+
|
|
|
+ function getImage(index) {
|
|
|
+ var image = productImageList[index];
|
|
|
+ return image;
|
|
|
+ }
|
|
|
+
|
|
|
+ $('body').on('click','#btnSubmit',function () {
|
|
|
+ if (recommendCount > 15) {
|
|
|
+ alertx("最多只能添加15条相关商品");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var url = "${ctx}/baike/cmBaikeProduct/recommend/save?id=" + ${cmBaikeProduct.id} + "&recommendType=" + recommendType;
|
|
|
+ if (recommendType == 1) {
|
|
|
+ //只有选择了手动推荐相关商品单选框才修改相关商品数据
|
|
|
+ var recommendJson = JSON.stringify(manualImageList);
|
|
|
+ url += "&recommendJson=" + recommendJson;
|
|
|
+ }
|
|
|
+ //保留搜索条件
|
|
|
+ <%--url += "&searchName=${product.searchName}&searchShopID=${product.searchShopID}&searchShopName=${product.searchShopName}&searchBigTypeID=${product.searchBigTypeID}&searchSmallTypeID=${product.searchSmallTypeID}&searchTinyTypeID=${product.searchTinyTypeID}&searchValidFlag=${product.searchValidFlag}&searchActStatus=${product.searchActStatus}&searchProductType=${product.searchProductType}&searchBrandID=${product.searchBrandID}&searchPreferredFlag=${product.searchPreferredFlag}";--%>
|
|
|
+ window.location.href = url;
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ function changeRecommendType(){
|
|
|
+ recommendType = $("input[name='recommendType']:checked").val();
|
|
|
+ if (recommendType == 1) {
|
|
|
+ $(".manualData").css('display', 'table-cell');
|
|
|
+ productImageList = manualImageList;
|
|
|
+ } else if (recommendType == 2) {
|
|
|
+ $(".manualData").css('display', 'none');
|
|
|
+ productImageList = autoImageList;
|
|
|
+ }
|
|
|
+ batchSaveSort();
|
|
|
+ }
|
|
|
+</script>
|
|
|
+</body>
|
|
|
+</html>
|