add.vm 8.23 KB
<script src="/assets/js/jquery.js"></script>
<script src="/assets/js/riotjs/riotjs.js"></script>
<script src="/assets/products/product.search.categroy.js"></script>
<script src="/assets/products/addProductSearchCate.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="productSearchCate">
	<li><a href="$!{contextPath}/">首页</a><span class="divider">></span>
		<a href="$!{contextPath}/titan/sctop">市场置顶排序</a></li>
</DIV>
<input type="hidden" id="searchCid" value="$!{cid}">
<form class="well form-search" name="productSearchCateForm" action="/titan/sctop" method="POST">

    请选择批发市场:<select name="cid" id="scSelect">
                        <option value="-1">请选择批发市场</option>
        </select>
	<button type="submit" class="btn btn-sm btn-primary"><i class="icon-search icon-white"></i>搜索</button>
	<button type="button"  class="btn btn-sm btn-primary btn-clear">清除</button>
	<a class="btn btn-sm btn-primary act-fancy" href="#fancyalter" style="float:right">添加市场</a>
</form>


<!-- 表格数据 -->
<table class="table table-striped table-bordered table-condensed grid">
	<thead>
		<tr>
			<th #sorting($!{productSearchSort} "id")>编号</th>
			<th #sorting($!{productSearchSort} "categoryName")>市场</th>
			<th #sorting($!{productSearchSort} "ProductSearchSortCount")>推荐商品数量</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody>
#foreach(${item} in ${page.result})
		<tr>
			<td style="width:20%;text-align:center;vertical-align:middle;">$!{item.id}</td>
			<td style="width:35%;text-align:center;vertical-align:middle;">$!{item.name}</td>
			<td style="width:20%;text-align:center;vertical-align:middle;">$!{item.ProductSearchSortCount}</td>
			<td class="textC" style="width:20%;text-align:center;vertical-align:middle;">
				<div class="btn-group">
					   <a  href="/titan/sctop/sortlist?cateId=${item.cid}"><i class="icon-eye-open"></i> 添加排序商品</a>
    				   <a  href="javascript:void(0)" onclick="deleteSearchCate($!{item.cid})"><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">
            <div class="completethis" id="completethisId" style="width:550px">
                <input id="sccid" type="hidden" name="cid" />
                <input id="sc" data-provide="typeahead" class="span align-middle input-medium" type="text" name="pickName" style="width: 200px"  placeholder="市场名称" autocomplete="off" />
            </div>
        </div>
        <div class="completethis">
		    <a href="#" class="addsucc" id="addsc">确定添加</a>
        </div>
  </div>
</div>

<!-- 分页栏 -->
#showPage($!{page})
<script src="/assets/js/underscore.js"></script>
<script>
	$(document).ready(function(){
        $(".btn-clear").click(function(){
//            $("#scSelect").val("-1");
            window.location.href="/titan/sctop";
        })
        //添加市场弹出框中的 搜索市场
        var providers;
        $('#sc').typeahead({
            source: function(query, process) {
                var keyword = $("input[id='sc']").val();

                $.ajax({
                    async : false,
                    type : "post",
                    url  : "/common/searchSc",
                    data : {keyword : keyword},
                    dataType : "json",
                    success : function(data){
                        providers = new Array();
                        if(data && data.length > 0){
                            $.each(data , function(i, n){
                                if(n){
                                    var obj = new Object();
                                    obj.id = n.id;
                                    obj.pickName = n.pickName;
                                    providers[i]=obj;
                                }
                            });
                        };
                    },
                    error : function(){
                        XUI.window.alert("网络错误,请稍后重试");
                    }
                });

                var results = _.map(providers, function(provider) {
                    return provider.id + "";
                });
                process(results);
            },
            matcher: function (item) {
                return true;
            },
            highlighter: function(id) {
                var provider = _.find(providers, function(p) {
                    return p.id == id;
                });
                return provider.pickName ;
            },
            updater: function(id) {
                var provider = _.find(providers, function(p) {
                    return p.id == id;
                });
                $("#sccid").val(id);
                return provider.pickName ;
            }
        });

        //获取当前添加的市场
        $.ajax({
            async : false,
            type : "post",
            url  : "/titan/sctop/getAllSc",
//            data : {keyword : keyword},
            dataType : "json",
            success : function(data){
                if(data && data.length > 0){
                    var searchCid = $("#searchCid").val();
                    $.each(data , function(i, n){
                        if(n){
                            if(searchCid && searchCid== n.id){
                                $("#scSelect").append("<option selected='selected' value='" + n.id + "'>" + n.pickName + "</option>")
                            }else {
                                $("#scSelect").append("<option value='" + n.id + "'>" + n.pickName + "</option>")
                            }
                        }
                    });
                };
            },
            error : function(){
                XUI.window.alert("网络错误,请稍后重试");
            }
        });

        //添加市场
        $("#addsc").live('click', function(){
            var cateStr = $("#sccid").val();
            if(cateStr == null || cateStr==""){
                XUI.window.alert("请选择需要添加的市场!");
                return ;
            }
            $.ajax({
                type : "post",
                dataType : "json",
                url      : "/titan/sctop/save",
                data : {"cid" : cateStr},
                success  : function(data){
                    if(data.code == "success"){
                        window.location.href="/titan/sctop";
                    }else{
                        XUI.window.alert(data.result);
                    }
                },
                error    : function(){
                    XUI.window.alert("网络错误,请稍后重试");
                }
            });

        });
	});

   function deleteSearchCate(cid){
        XUI.window.confirm("确定要删除排序市场吗?", "删除排序市场", function(){
            $.ajax({
                type : "post",
                dataType : "json",
                url      : "/titan/sctop/delete",
                data : {cateId : cid},
                success  : function(data){
                    if(data.code == "success"){
                        //XUI.window.alert(" 排序分类已成功删除,若以后还需要对该分类商品进行排序,请重新添加排序分类!");
                        window.location.href="/titan/sctop";
                    }else{
                        XUI.window.alert(data.result);
                    }
                },
                error    : function(){
                    XUI.window.alert("网络错误,请稍后重试");
                }
            });
        });
    }

 seajs.use(['fancybox'], function(fancybox){
      $(".act-fancy").fancybox({
        scrolling: 'visible',
		afterClose: function(){
            $("#sc").val("");
            $("#sccid").val("");
//            $("#productCategoryId select:first option:first").change();
		}
      });
  });
  
</script>