addtop.vm 12 KB
<script src="/assets/js/jquery.js"></script>
<script src="/assets/js/riotjs/riotjs.js"></script>
<script type="text/javascript" src="http://static.1n4j.com/static/newStatic/common/js/base/sea.js"></script>
<script type="text/javascript" src="http://static.1n4j.com/static/newStatic/pnr/js/javascript/common/config.js"></script>
<link rel="stylesheet" type="text/css" href="http://static.1n4j.com/static/newStatic/pnr/backstage/css/fancy.css">
<DIV id="navBar" title="productSearchSort">
	<li><a href="$!{contextPath}/">首页</a><span class="divider">></span>
		<a href="$!{contextPath}/titan/sctop">市场置顶排序</a>></span>
		<a href="$!{contextPath}/titan/sctop/sortlist?cateId=$!{cateId}">市场排序商品</a></li>
</DIV>
<form  name="productSearchCateForm" action="/titan/productSearchCate" method="POST">
	<a  id="contentID" class="act-fancy" href="#fancyalter" onclick="openProductPopData($!{cateId},1)"></a>
	<a  class="btn btn-sm btn-primary" style="float:right" onclick="clickadd($!{cateId},1)">添加排序商品</a>
</form>
<style>
	.fancysearch a:focus {color:#fff}
	.fancybox-close {right:40px}
</style>
<!-- 表格数据 -->
<table class="table table-striped table-bordered table-condensed grid">
	<thead>
		<tr>
			<th #sorting($!{productSearchSort} "pName")>商品名称</th>
			<th #sorting($!{productSearchSort} "cate")>商品分类</th>
			<th #sorting($!{productSearchSort} "ctime")>添加时间</th>
			<th #sorting($!{productSearchSort} "SearchSort")>排序</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody>
        #foreach(${item} in ${page.result})
        		<tr>
        			<td style="width:25%;text-align:center;vertical-align:middle;"><a href="javascript:void(0)" onclick="window.open('http://www.1n4j.com/product/$!{item.pid}.html')">$!{item.pName}</td>
					<td style="width:25%;text-align:center;vertical-align:middle;">$!{item.categoryName}</td>
					<td style="width:15%;text-align:center;vertical-align:middle;">$!{dateFormatUtils.format($!{item.ctime},'yyyy-MM-dd HH:mm')}</td>
        			<td style="width:15%;text-align:center;vertical-align:middle;"><input type="text" class="ipt numInput" value="$!{item.SearchSort}" id="searchSortId${item.id}" onblur="changeSearchSort($!{cateId},$!{item.id},$!{item.searchSort})" style="width:60px;text-align: center;"/></td>
        			<td class="textC" style="width:20%;text-align:center;vertical-align:middle;">
        				<div class="btn-group">
            				   <a   href="javascript:void(0)" onclick="deleteSearchSort($!{item.id},$!{item.cateId})"><i class="icon-pencil"></i> 删除</a>
        				</div>
        			</td>
        		</tr>
        #end
	</tbody>
</table>

<div class="fancyalter" id="fancyalter">
  <h2 class="alterhd">添加排序商品</h2>
  <div class="alterbd">
    <div class="fancysearch">
      <span>
        商品编号:
        <input type="text" class="ipt numInput" name="pid" maxlength="15" style="width: 100px;"/>
      </span>
      <span  style="margin-left:10px">
        商品标题:
        <input type="text" class="ipt" name="name" maxlength="50" style="width: 100px;"/>
      </span>
			<span  style="margin-left:10px">
        店铺名称:
        <input type="text" class="ipt" name="shopName" maxlength="50" style="width: 100px;"/>
      </span>
     <span  style="margin-left:10px">
		<input type="hidden" id="isSearch" value="0"/>
        <a href="javascript:void(0)" class="searchlink" onClick="searchPop($!{cateId},1)">搜索</a>
      </span>
    </div>
    <table cellpadding="0" cellspacing="0" class="fancytab">
      <thead>
        <tr>
          <td>商品编号</td>
          <td>商品标题</td>
          <td>单价</td>
          <td>卖家</td>
          <td>操作</td>
        </tr>
      </thead>
      <tbody id="productPopTableDateId">

      </tbody>
    </table>
    <div class="paging" id="pageId">

    </div>
    <div class="completethis">
      <a href="javascript:void(0)" class="addsucc" onclick="saveProductSearch($!{cateId})">添加已完成</a>
    </div>
  </div>
</div>


<!-- 分页栏 -->
###showPage($!{page})
<script>
     var pids = new Array();
	 function clickadd(cateId,pageId){
		var pid,name;
		$.ajax({
			type : "post",
			dataType : "json",
			url      : "/titan/sctop/queryProductPopData",
			data : {cateId : cateId, pageId : pageId, pid : pid, name : name},
			success  : function(data){
				if(data.success){
					$("#productPopTableDateId").html("");
					$("#pageId").html("");
					var result = data.allResult.page.result;
					if(result == null || result == '' || result.length ==0){
						XUI.window.alert("没有可添加的商品!");
					}else{
						$("#contentID").click();
					}
				}
			}
		});
	 }
	 function queryProductPopData(cateId,pageId){
		var pid = "";
		var name = "";
         var shopName = "";
         if($("#isSearch").val() == 1){
             pid = $("input[name='pid']").val();
             name = $("input[name='name']").val();
             shopName = $("input[name='shopName']").val();
         }
		if(pid != ""){
			var regex=/^[0-9]+$/;
			if (!regex.test(pid) || pid.length > 15) {
				XUI.window.alert("请输入合法的商品ID!");
				return false;
			}
		}
		if(name !=""){
			var regex=/^[0-9a-zA-Z\u4e00-\u9fa5/()()&《》【】\+=\]\[]+$/g;
			var message="请输入合法的商品名称(中文汉字、英文字母(含大小写)、数字、“/,(),&,《》,【】,[],=,+”)";
			if (!regex.test(name)) {
				XUI.window.alert(message);
				return false;
			}
		}
         if(shopName !=""){
             var regex=/^[0-9a-zA-Z\u4e00-\u9fa5/()()&《》【】\+=\]\[]+$/g;
             var message="请输入合法的店铺名称(中文汉字、英文字母(含大小写)、数字、“/,(),&,《》,【】,[],=,+”)";
             if (!regex.test(shopName)) {
                 XUI.window.alert(message);
                 return false;
             }
         }
		$.ajax({
			type : "post",
			dataType : "json",
			url      : "/titan/sctop/queryProductPopData",
			data : {cateId : cateId, pageId : pageId, pid : pid, name : name,shopName:shopName},
			success  : function(data){
				if(data.success){
					$("#productPopTableDateId").html("");
					$("#pageId").html("");
					var result = data.allResult.page.result;
					if(result != null && result != '' && result.length >0){
						for(var i = 0;i<result.length;i++){
							var tr = "<tr><td>"+result[i].pid+"</td><td><a href='javascript:void(0)' onclick=\"window.open('http://www.1n4j.com/product/"+result[i].pid+".html')\" class='goodtitle'>"+result[i].name+"</a></td>";
							if(result[i].minPrice == result[i].maxPrice){
								tr = tr+"<td>"+(result[i].minPrice/100).toFixed(2)+"元</td><td><span class='goodtitle'>"+result[i].shopName+"</span></td><td>";
							}else{
								tr = tr+"<td>"+(result[i].minPrice/100).toFixed(2)+"-"+(result[i].maxPrice/100).toFixed(2)+"元</td><td><span class='goodtitle'>"+result[i].shopName+"</span></td><td>";
							}
							var sign = 0;
							for(var j=0;j<pids.length;j++){
								if(result[i].pid == pids[j]){
                                    tr = tr + "<input type='checkbox' class='addpid' id='"+result[i].pid+"' checked='true' /></td></tr>";
                                    sign = 1;
									break;
								}
							}
							if(sign == 0){
                                tr = tr + "<input class='addpid' type='checkbox'  id='"+result[i].pid+"'  /></td></tr>";
                            }
							$("#productPopTableDateId").append(tr);
						}
					}
					var current = data.allResult.page.currentPage;
					var up = 1;
					var down = 1;
					if(current == 1){
						up = 1;
					}else{
						up = current - 1;
					}
					if(current < data.allResult.page.pageCount){
						down = current + 1;
					}else{
						down = current;
					}
					var pageHtml = "<a href='javascript:void(0)' onclick='queryProductPopData("+cateId+",1)'>首页</a>"+
							"<a href='javascript:void(0)' style='margin-left: 10px;' onclick='queryProductPopData("+cateId+","+up+")'>上一页</a>"+
							"<a href='javascript:void(0)' style='margin-left: 10px;' onclick='queryProductPopData("+cateId+","+down+")'>下一页</a>"+
							"<a href='javascript:void(0)' style='margin-left: 10px;' onclick='queryProductPopData("+cateId+","+data.allResult.page.pageCount+")'>尾 页</a>";
					$("#pageId").html(pageHtml);
					$.fancybox.update();
                    $(".addpid").bind("change",function(){
                        var pid = $(this).attr("id");
                        if($(this).is(':checked')){
                            pids.push(pid);
                        }else{
                            if(pids.length>0){
                                for(var i = 0 ;i<pids.length;i++){
                                    if(pids[i]==pid){
                                        pids.splice(i,1);
                                    }
                                }
                            }
                        }
                    });
				}else{
					XUI.window.alert(data.result);
				}
			},
			error    : function(){
				XUI.window.alert("网络错误,请稍后重试");
			}
		});
	}
	 function searchPop(cateId,pageId){
		$("#isSearch").val(1);
		pids = new Array();
		this.queryProductPopData(cateId,pageId);
	}
	 function openProductPopData(cateId,pageId){
		$("#isSearch").val(0);
		$("input[name='pid']").val("");
		$("input[name='name']").val("");
         $("input[name='shopName']").val("");
		pids = new Array();
		this.queryProductPopData(cateId,pageId);
	 }
	 function saveProductSearch(cateId){
		if(pids.length == 0){
			window.location.href="/titan/sctop/sortlist?cateId="+cateId;
			return;
		}
		$.ajax({
			type : "post",
			dataType : "json",
			url      : "/titan/sctop/savesort",
			data : {cateId:cateId, pids:JSON.stringify(pids)},
			success  : function(data){
				if(data.code != "success"){
					XUI.window.alert(data.result);
				}else{
					pids = new Array();
					window.location.href="/titan/sctop/sortlist?cateId="+cateId;
				}
			},
			error    : function(){
				XUI.window.alert("网络错误,请稍后重试");
                window.location.href="/titan/cdtop/sortlist?cateId="+cateId;
			}
		});
	}
	 function changeSearchSort(cateId,id,oldSearchSort){
		var newSearchSort = $("#searchSortId"+id).val();
		if(newSearchSort <= 0 || newSearchSort >= 99999 ){
			XUI.window.alert("排序的数据只能取0-99999之间!");
			$("#searchSortId"+id).val(oldSearchSort);
			return;
		}
		var ss = /\D|^0/g;
		if(ss.test(newSearchSort)){
			XUI.window.alert("排序的数据只能取0-99999之间!");
			$("#searchSortId"+id).val(oldSearchSort);
			return;
		}
		if(oldSearchSort == newSearchSort){
			return;
		}
		$.ajax({
			type : "post",
			dataType : "json",
			url      : "/titan/sctop/changesort",
			data : {id:id, cateId : cateId, searchSort:newSearchSort},
			success  : function(data){
				if(data.code != "success"){
					XUI.window.alert("数据操作失败!");
					$("#searchSortId"+id).val(oldSearchSort);
				}else{
					window.location.href="/titan/sctop/sortlist?cateId="+cateId;
				}
			},
			error    : function(){
				XUI.window.alert("网络错误,请稍后重试");
			}
		});
	}
	 function deleteSearchSort(id,cid){
		XUI.window.confirm("确定要删除该排序商品吗?", "删除排序商品", function(){
			$.ajax({
				type : "post",
				dataType : "json",
				url      : "/titan/sctop/deletesort",
				data : {id : id , cateId : cid},
				success  : function(data){
					if(data.code == "success"){
						//XUI.window.alert(" 排序分类已成功删除,若以后还需要对该分类商品进行排序,请重新添加排序分类!");
						window.location.href="/titan/sctop/sortlist?cateId="+cid;
					}else{
						XUI.window.alert(data.result);
					}
				},
				error    : function(){
					XUI.window.alert("网络错误,请稍后重试");
				}
			});
		});
	}

     seajs.use(['fancybox'], function(fancybox){
         $(".act-fancy").fancybox({
             scrolling: 'visible',
			 autoSize:false,
			 width:680,
             afterClose: function(){
                 pids=new Array();
//            $("#productCategoryId select:first option:first").change();
             }
         });
     });
</script>