<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="p" uri="http://www.test.com/jsp/permission" %>
<!doctype html>
<html>
<head>
	<%@ include file="../../common/head.jsp"%>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

	<link href="../res/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet" />
    <script src="../res/js/plugins/bootstrap-table/bootstrap-table.js"></script>
    <script src="../res/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    <script src="../res/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <style type="text/css">
    	#myform {
			overflow:hidden;    	
    	}
    	.prodBtn {
    		float:right;
    		padding:20px 10px 0px;
    	}
    </style>
    <script>
    	
    	function test(value,row,index){
//     		return '<a href="#">' + row['id'] + '</a>';
    		return '<a href="#">编辑 </a>|<a href="#">删除</a>';
    	}
    	
        function format_type(value,row,index){
    	    if(value == 0){
    	        return '平台管理员';
			}else if(value==1){
                return '机场管理员';
            }else if(value==2){
                return '航空公司管理员';
            }
        }
        $(function(){
    		$('#btnSearch').click(function () { 
    			$('#tab_user').bootstrapTable('refresh');
  	        });  
  	        
  	        $('#clearHref').click(function () { 
  	        	$('#myform')[0].reset();
 	       	}); 
    	});
    	 
    	function queryParams(params){
			var page = params.offset / params.limit + 1;
			var dataObj = new Object(); 
			//alert($("#search").val());
			dataObj.name=$("#name").val();
			dataObj.productState=$("#productState").val();
			dataObj.hotline=$("#hotline").val();
			dataObj.isHome=$("#isHome").val();
			dataObj.gcId=$("#gcId").val();
			dataObj.gcParentId=$("#gcParentId").val();
			dataObj.gcThreeId=$("#gcThreeId").val();
			dataObj.gcFourId=$("#gcFourId").val();
			dataObj.xmCode=$("#xmCode").val();
			/* dataObj.xmCode=$("#id1").val();
			dataObj.xmCode=$("#id2").val();
			dataObj.xmCode=$("#id3").val();
			dataObj.xmCode=$("#id4").val(); */
			return  { page:page, 
					  pageSize:params.limit, 
					  search:JSON.stringify(dataObj), 
					  sort:params.sort,
					  order:params.order,
		};  
	} 
    	 function format_type(value,row,index){
     	    if(value==1){
                 return '地产';
             }else if(value==2){
                 return '产品';
             }
         }
    	 function format_state(value,row,index){
      	    if(value==1){
                  return '上架中';
              }else if(value==2){
                  return '已下架';
              }
          }
         function format_home(value,row,index){
     	    if(value==1){
                 return '是';
             }else if(value==0){
                 return '否';
             }
         }
         
         function up(){
     		var data = getSelectedRow("tab_user");
     		if(null == data){
     			layer.msg("未选中行");
     			return;
     		}
     		if(data.productState == '1'){
     			layer.msg("产品已上架");
     			return;
     		}
     		
     		$.confirm("确定上架当前选中的产品吗？ ", function(){
     			$.post('updown.cs?id=' + data.id+'&state=1', 
     					function(result){
     						window.location.reload();
     						}
     			);
     		});
     	}
         
         function down(){
     		var data = getSelectedRow("tab_user");
     		if(null == data){
     			layer.msg("未选中行");
     			return;
     		}
     		if(data.productState == '2'){
     			layer.msg("产品已下架");
     			return;
     		}
     		
     		$.confirm("确定下架当前选中的产品吗？ ", function(){
     			$.post('updown.cs?id=' + data.id+'&state=2', 
     					function(result){
     						window.location.reload();
     						}
     			);
     		});
     	}
         /* 遠程推送 */
         function remote(){
      		var data = getSelectedRow("tab_user");
      		if(null == data){
      			layer.msg("未选中行");
      			return;
      		}
      	
      		$.confirm("确定推送当前选中的产品吗？ ", function(){
      			$.post('remote.cs?id=' + data.id, 
      					function(result){
      						if(result.code==500){
      							layer.msg("当前商品不符合推送需求！");
          						window.location.reload();
      						}else{
      							layer.msg("推送商品成功！");
          						window.location.reload();
      						}
      						}
      			); 
      		});
      	}

         
    </script>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInUp">
<!--           <div class="ibox " style=""> -->
<!--               <div class="ibox-content"> -->
	              <div class="row row-lg">
	              		<div class="col-sm-12">
							<div class="ibox-content m-b-sm border-bottom">
								<div class="ibox-title">
									<h5>查询条件</h5>
								</div>
								<form class="form-inline" id="myform">
								    <table style="border-collapse:separate; border-spacing:0px 10px;" class="col-sm-12">
								    <tr>
								    <td>
									<div class="form-group col-sm-3"><label>&nbsp;产品名称：</label><input id="name" name="name" class="form-control" style="width:48%" type="text" value=""></div>
									<div class="form-group col-sm-3"><label>&nbsp;产品状态：</label>
									<select id="productState" name="productState" class="form-control" style="width:48%">
									<option value="">请选择</option>
									<option value="1">上架中</option>
									<option value="2">已下架</option>
									</select>
									</div>
									<div class="form-group col-sm-3"><label>&nbsp;联系电话：</label><input id="hotline" name="hotline" class="form-control" style="width:48%" type="text" value=""></div>
									<div class="form-group col-sm-3"><label>&nbsp;是否推荐：</label>
									<select id="isHome" name="isHome" class="form-control" style="width:48%">
									<option value="">请选择</option>
									<option value="1">是</option>
									<option value="0">否</option>
									</select>
									</div>
								    </td>
								    </tr>
								    <tr>
								    <td colspan="4">
								    
								    	<!-- <div class="form-group col-sm-3">
									    <label>&nbsp;上级分类：</label><input id="name" name="name" class="form-control"  style="width:48%" type="text" value="">
									    </div>
									    <div class="form-group col-sm-3">
									    <label>&nbsp;二级分类：</label>
									    <input id="name" name="name" class="form-control" type="text" style="width:48%" value="">
									    </div>
									    <div class="form-group col-sm-3">
									    <label>&nbsp;三级分类：</label><input id="name" name="name" class="form-control" type="text" style="width:48%" value="">
									    </div>
									    <div class="form-group col-sm-3">
									    <label>&nbsp;四级分类：</label>
									    <input id="name" name="name" class="form-control" type="text" style="width:48%" value="">
									    </div> -->
									    
                      
                      <div class="form-group col-sm-3">
                          <label >&nbsp;上级分类：</label><select <c:if test="${role.ONE_CATEGORY_Id != null && role.ONE_CATEGORY_Id != '' && role.ONE_CATEGORY_Id!= '0'}">disabled="disabled"</c:if> class="form-control" style="width:48%" id="gcId" name="gcId" onchange="menuChange(this)" validate="{required:true}" validateMessage="{required:'请选择分类'}">
                              		<option value="">请选择</option>
                              		<c:forEach items="${firstCategory }" var="superMenu">
                              			<option value="${superMenu.id }" <c:if test="${role.ONE_CATEGORY_ID == superMenu.id }">selected</c:if>>${superMenu.gcName}</option>
                              		</c:forEach>
                              </select>
                              <c:if test="${role.ONE_CATEGORY_Id != null && role.ONE_CATEGORY_Id != '' && role.ONE_CATEGORY_Id!= '0'}"><input type="hidden" value="${role.ONE_CATEGORY_ID }" name="id1"></c:if>
                      </div>
                     <script type="text/javascript">
                     function menuChange(obj){
                    	 var ss = $(obj).children('option:selected').val();  
                    	 $("#tlb").css("display","none");
                    	 $('#tlb select').find("option:selected").prop('selected',false);
                    	 $("#thlb").css("display","none");
                    	 $('#thlb select').find("option:selected").prop('selected',false);
                    	 $("#folb").css("display","none");
                    	 $('#folb select').find("option:selected").prop('selected',false);
                    	 $('#dcfllb select').find("option:selected").prop('selected',false);
                    	 $('#dcfllb').css("display","none");
                    	 $("#gcParentId").empty();
                    	 $("#gcThreeId").empty();
                    	 $("#gcFourId").empty();
                         $.ajax({
                             type: "get",
                             url: "<%=basePath%>mgmProductCategoryCtl/nextCategory.cs",
                             data: {id:ss},
                             dataType: "json",
                             success: function(data){
                                   	if(data.mlist.length > 0){
                                   	$("#tlb").css("display","block");
                                   	$("#gcParentId").empty();
                                   	$("#gcParentId").append("<option value='0'>请选择</option>");
                                   	data.mlist.forEach(function(val,index,arr){
                                   		  $("#gcParentId").append("<option value='"+val.id+"'>"+ val.gcName+"</option>");            
                                   		});
                                   	}
                                   	if(data.type == "1"){
                                   		$('#dcfllb').css("display","block");
                                   	}
                                 }
                         });
                         
                     }
                     
                     function twoMenuChange(obj){
                    	 var ss = $(obj).children('option:selected').val();  
                    	 $("#thlb").css("display","none");
                    	 $('#thlb select').find("option:selected").prop('selected',false);
                    	 $("#folb").css("display","none");
                    	 $('#folb select').find("option:selected").prop('selected',false);
                    	 $("#gcThreeId").empty();
                    	 $("#gcFourId").empty();
                         $.ajax({
                             type: "get",
                             url: "<%=basePath%>mgmProductCategoryCtl/nextCategory.cs",
                             data: {id:ss},
                             dataType: "json",
                             success: function(data){
                         			if(data.mlist.length > 0){
                         			 $("#thlb").css("display","block");
                         			$("#gcThreeId").empty();
                                   	$("#gcThreeId").append("<option value='0'>请选择</option>");
                                  	data.mlist.forEach(function(val,index,arr){
                                  		  $("#gcThreeId").append("<option value='"+val.id+"'>"+ val.gcName+"</option>");            
                                  		});
                         			}
                                 }
                         });
                         
                     }
                     function threeMenuChange(obj){
                    	 var ss = $(obj).children('option:selected').val();  
                    	 $("#folb").css("display","none");
                    	 $('#folb select').find("option:selected").prop('selected',false);
                    	 $("#gcFourId").empty();
                         $.ajax({
                             type: "get",
                             url: "<%=basePath%>mgmProductCategoryCtl/nextCategory.cs",
                             data: {id:ss},
                             dataType: "json",
                             success: function(data){
                        			 if(data.mlist.length > 0){
                        			 $("#folb").css("display","block");
                        			 $("#gcFourId").empty();
                                    	$("#gcFourId").append("<option value='0'>请选择</option>");
                                 	data.mlist.forEach(function(val,index,arr){
                                 		  $("#gcFourId").append("<option value='"+val.id+"'>"+ val.gcName+"</option>");            
                                 		});
                        			 }
                                 }
                         });
                         
                     }
                     </script>
                     
                     <div id="tlb" class="form-group col-sm-3" <c:if test="${role.TWO_CATEGORY_Id == null }">style="display:none;"</c:if> >
                          <label >&nbsp;二级分类：</label>
                              <select <c:if test="${role.TWO_CATEGORY_Id != null && role.TWO_CATEGORY_Id != '' && role.TWO_CATEGORY_Id!= '0'}">disabled="disabled"</c:if> class="form-control" style="width:48%" id="gcParentId" name="gcParentId" onchange="twoMenuChange(this)" validate="{required:true}" validateMessage="{required:'请选择分类'}">
                              		<option value="">请选择</option>
                              		<c:forEach items="${twoCategory }" var="superMenu">
                              		<option value="${superMenu.id }" <c:if test="${role.TWO_CATEGORY_Id == superMenu.id }">selected</c:if> >${superMenu.gcName}</option>
                              		</c:forEach>
                              </select>
                              <c:if test="${role.TWO_CATEGORY_Id != null && role.TWO_CATEGORY_Id != '' && role.TWO_CATEGORY_Id!= '0'}">
                              <input type="hidden" value="${role.TWO_CATEGORY_Id }" name="id2">
                              </c:if>
                      </div>
                      
                      <div id="thlb" class="form-group col-sm-3"  <c:if test="${role.THREE_CATEGORY_ID == null }">style="display:none;"</c:if>> 
                          <label >&nbsp;三级分类：</label>
                              <select <c:if test="${role.THREE_CATEGORY_Id != null && role.THREE_CATEGORY_Id != '' && role.THREE_CATEGORY_Id!= '0'}">disabled="disabled"</c:if> class="form-control" style="width:48%" id="gcThreeId" name="gcThreeId" onchange="threeMenuChange(this)" validate="{required:true}" validateMessage="{required:'请选择分类'}">
                              		<option value="">请选择</option>
                              		<c:forEach items="${threeCategory }" var="superMenu">
                              		<option value="${superMenu.id }" <c:if test="${role.THREE_CATEGORY_ID == superMenu.id }">selected</c:if> >${superMenu.gcName}</option>
                              		</c:forEach>
                              </select>
                              <c:if test="${role.THREE_CATEGORY_Id != null && role.THREE_CATEGORY_Id != '' && role.THREE_CATEGORY_Id!= '0'}"><input type="hidden" value="${role.THREE_CATEGORY_ID }" name="id3"></c:if>
                      </div>
                      
                      <div id="folb" class="form-group col-sm-3" <c:if test="${role.FOUR_CATEGORY_ID == null }">style="display:none;"</c:if>> 
                          <label >&nbsp;四级分类：</label>
                              <select style="width:48%" <c:if test="${role.FOUR_CATEGORY_Id != null  && role.FOUR_CATEGORY_Id != '' && role.FOUR_CATEGORY_Id!= '0'}">disabled="disabled"</c:if> class="form-control id="gcFourId" name="gcFourId" validate="{required:true}" validateMessage="{required:'请选择分类'}">
                              		<option value="">请选择</option>
                              		<c:forEach items="${fourCategory }" var="superMenu">
                              		<option value="${superMenu.id }" <c:if test="${role.FOUR_CATEGORY_ID == superMenu.id }">selected</c:if> >${superMenu.gcName}</option>
                              		</c:forEach>
                              </select>
                              <c:if test="${role.FOUR_CATEGORY_Id != null  && role.FOUR_CATEGORY_Id != '' && role.FOUR_CATEGORY_Id!= '0'}"><input type="hidden" value="${role.FOUR_CATEGORY_ID }" name="id4"></c:if>
                      </div>
                      
                      <!-- //地产项目分类 -->
                      <div id="dcfllb" class="form-group col-sm-3" style="display:none;"> 
                          <label >&nbsp;项目分类：</label>
                              <select class="form-control" style="width:48%" id="xmCode" name="xmCode" validate="{required:true}" validateMessage="{required:'请输入地产项目分类'}">
                              		<option value="">请选择</option>
                              		<c:forEach items="${diclist }" var="superMenu">
                              			<option value="${superMenu.code }" >${superMenu.name}</option>
                              		</c:forEach>
                              </select>
                      </div>
									    
								    </td>
								    </tr>
								    </table>
										<label class="prodBtn"><a href="#" id="clearHref" class="btn btn-primary"><i class="icon-search"></i> 清除搜索条件</a></label>
										<label class="prodBtn"><a href="#" id="btnSearch" class="btn btn-primary"><i class="icon-search"></i> 搜索</a></label>&nbsp;&nbsp;
										
									
							
								</form>
							</div>
							
	              		 <cs:toolbar title="产品" tableId="tab_user" width="100%" height="100%" menuCode="${menuCode }">
							<p:permission menuCode="${menuCode }" action="16">
	              		 		<button class="btn btn-sm btn-info" type="button" onclick="up()"><i class="fa fa-info"></i>&nbsp;上架</button>
	              		 	</p:permission>
	              		 	<p:permission menuCode="${menuCode }" action="32">
	              		 		<button class="btn btn-sm btn-info" type="button" onclick="down()"><i class="fa fa-info"></i>&nbsp;下架</button>
	              		 	</p:permission>
	              		 	<p:permission menuCode="${menuCode }" action="32">
	              		 		<button class="btn btn-sm btn-success" type="button" onclick="remote()"><i class="fa fa-info"></i>&nbsp;推送</button>
	              		 	</p:permission>
	              		 </cs:toolbar>
		                  <table id="tab_user"  
		                  	   data-toggle="table"
						       data-url="list2.cs"
						       data-method="get"
						       data-click-to-select="true"
						       data-pagination="true"
						       data-data-type="json"
						       data-show-refresh="true"
						       data-show-columns="true"
						       data-show-toggle="true"
						       data-single-select="true"
						       data-search-on-enter-key="true"
						       data-toolbar="#def_toolbar"  
						       data-side-pagination="server"
						       data-query-params="queryParams"
						       data-mobile-responsive="true"
								>
		                      <thead>
		                          <tr>
		                              <th data-checkbox="true"	data-click-to-select="true"></th>
		                              <th data-field="ID" data-visible="false">id</th>
		                              <th data-field="productName">产品名称</th>
		                              <th data-field="gc">项目分类</th>
		                              <th data-field="productRemark">产品标识</th>
		                              <th data-field="productType" data-formatter="format_type">产品类型</th>
		                              <th data-field="commissionRate">佣金比率</th>
		                              <th data-field="hotline">联系电话</th>
		                              <th data-field="productState" data-formatter="format_state">产品状态</th>
		                              <th data-field="productPrice">产品价格</th>
		                              <th data-field="weight">权重</th>
		                              <th data-field="isHome" data-formatter="format_home">是否推荐</th>
		                              <th data-field="unit">单位</th>
		                              <th data-field="createDate" data-formatter="format_time">创建时间</th>
		                          </tr>
		                      </thead>
		                  </table>
	              		
	              		</div>
	              	
	              </div>
				 
<!--               </div> -->
<!--           </div> -->
    </div>
    

</body>

</html>
