 var mySwiper = new Swiper ('.swiper-container', {
//					    direction: 'vertical',
//					    loop: true,
					    // 如果需要分页器
					    pagination: {
					      el: '.swiper-pagination',
					       clickable: true,
					    },
					  })        
			var token = $.cookie("token");
        	var table = $('#table1');
        	 $('#depID').val(0);
        	$(document).ready(function(){
//      		$('#firstOne').trigger("click");
				//右侧搜索事件
				bindtree();
	        	initTable($('#depID').val());
	        	$('#rightSearch').click(function(){
	        			initTable($('#depID').val());
	        	})
				function initTable(ids) {
		            //先销毁表格
		            table.bootstrapTable('destroy');
		            //初始化表格,动态从服务器加载数据
		            table.bootstrapTable({
		                method: "get", //使用get请求到服务器获取数据
		                url: huayi.config.callcenter_url + "Repository/GetList", //获取数据的Servlet地址
		                contentType: "application/x-www-form-urlencoded", striped: true,
		                striped: true, //表格显示条纹
		                pagination: true, //启动分页
		                pageSize: 10, //每页显示的记录数
		                pageNumber: 1, //当前第几页
		                pageList: [10, 15, 25], //记录数可选列表
		                search: false, //是否启用查询
		                showColumns: false, //显示下拉框勾选要显示的列
		                showRefresh: false, //显示刷新按钮
		                sidePagination: "server", //表示服务端请求
		                //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
		                //设置为limit可以获取limit, offset, search, sort, order
		                queryParamsType: "undefined",
		                queryParams: function queryParams(params) { //设置查询参数
		                    var param = {
		                        page: params.pageNumber,
		                        pagesize: params.pageSize,
		                        token: token,
		                        deptid:ids,
		                        type:1,
		                        key:$('.rightSearchKey').val(),
//								starttime:	否	string	开始时间 （2017-01-09）
//								endtime:
		                    };
		                    return param;
		                },
		                onLoadSuccess: function () { //加载成功时执行
		                    //layer.msg("加载成功");
		                },
		                onLoadError: function () { //加载失败时执行
		                    //layer.msg("加载数据失败", { time: 1500, icon: 2 });
		                }
	            });
	        }
        		function bindtree() {
			    $.getJSON(huayi.config.callcenter_url + "Department/GetDeptList", { "token": $.cookie("token") }, function (result) {
			        if (result.state.toLowerCase() == "success") {
			            tree = $.fn.zTree.init($("#treeDemo"), setting1, result.data);
			        }
			    })
			}
			//获取所属部门
			var setting1 = {
					data: {
						key: {
							name: "F_DeptName"
						},
						simpleData: {
							enable: true,
							idKey: "F_DeptId",
							pIdKey: "F_PartentId",
							rootPId: 0
						}
					},
					callback: {
						onClick: zTreeOnClick
					}
				};
			function zTreeOnClick(event, treeId, treeNode) {
				$('#urgent').css('color','red');
				$('#policies').css('color','red');
				$('.polices').css('display','none');
        		$('.addTo').css('display','block');
				$('#depID').val('');
			    if (treeNode.level >= 2) {
			    	$('.mechanism').css('visibility','visible');
			    	var depId=treeNode.F_DeptId;
					$('#depID').val(depId);
					$.getJSON(huayi.config.callcenter_url + "Department/GetDept", { id:depId,"token": $.cookie("token") }, function (result) {
				        if (result.state.toLowerCase() == "success") {
				            $('#mechanism').val(result.data.F_Remark);
				        }
				   })
			        initTable(depId);
			    }
			    
			};
//      		if($('.allAdd').hasClass('active')){
//      			$('.addTo').hide();
//      		}else{
//      			$('.addTo').show();
//      		}
        		
        		$('.unitList li').click(function(){
        			$('.unitList li').removeClass('active')
        			$(this).addClass('active');
    				if($('.allAdd').hasClass('active')){
	        			$('.addTo').hide();
	        		}else{
	        			$('.addTo').show();
	        		}
        			var depId=$(this).attr('data-id');
        			var keyWord=$(this).find('div').html();
        			$('.rightTabKey').html(keyWord);
        			$('#depID').val(depId);
        			initTable(depId);
        		})
        		
        		//左侧单位鼠标移入效果
        		$('.unitList li').hover(function(){
        			$(this).addClass('acs');
        			
        		},function(){
        			$(this).removeClass('acs');
        		})
        		//右侧关键字鼠标移入效果
        		$('.keyList li').hover(function(){
        			$('.keyList li').removeClass('active')
        			$(this).addClass('active');
        			
        		},function(){
        			$(this).removeClass('active');
        		})
        		$('.addTo').click(function(){
        			var depid=$('#depID').val();
        			if(!depid||depid==0){
        				layer.msg('请选择一个承办单位');
        				return;
        			}
        			goAdd(depid)
        			
        		})
        		//紧急事件添加
        		$('#urgent').click(function(){
        			$('#depID').val('99999');
        			$('.mechanism').css('visibility','hidden');
        			$('.polices').css('display','none');
        			$('.addTo').css('display','block');
        			$('#policies').css('color','red');
        			$('#urgent').css('color','#048aad');
        			$('#mechanism').val('');
        			initTable($('#depID').val());
        		})
        		//政策法规添加
        		$('#policies').click(function(){
        			$('#depID').val('100000');
        			$('.mechanism').css('visibility','hidden');
        			$('.polices').css('display','block');
        			$('.addTo').css('display','none');
        			$('#urgent').css('color','red');
        			$('#policies').css('color','#048aad');
        			$('#mechanism').val('');
        			initTable($('#depID').val());
        		})
        		$('.polices').click(function(){
        			var depid=$('#depID').val();
        			policesAdd(depid)
        			
        		})
        		//机构职能保存
        		$('.btn_save').click(function(){
        			if($('#depID').val()==0||$('#depID').val()==99999||$('#depID').val()==100000){
        				layer.msg('请选择一个承办单位');
        				return;
        			}
        			$.ajax({
						type: "post",
						url: huayi.config.callcenter_url + "Department/UpdateDeptRemark",
						async: true,
						dataType: 'json',
						data: {
						    token: $.cookie("token"),
							id: $('#depID').val(),
							remark:$('#mechanism').val(),
						},
						success: function(data) {
							if(data.state.toLowerCase() == 'success') {
								layer.msg("保存成功！");
//								location=location
							}
						}
					});
        		})
        		function policesAdd(ids){
					//iframe窗
				    layer.open({
				      	type: 2,
				      	title: '新增知识库',
				      	area: ['70%', '60%'],
				      	content: 'policesAdd.html?depId='+ ids +''
				    });
				}
        		function goAdd(ids){
					//iframe窗
				    layer.open({
				      	type: 2,
				      	title: '新增知识库',
				      	area: ['70%', '60%'],
				      	content: 'newRepositoryAdd.html?depId='+ ids +''
				    });
				}
        	})
        	//操作
			function CZ(val,row){
				var Rows = row.Buttons;
	            var html = '';
	            for (var i = 0; i < Rows.length; i++) {
	
	                var html1 = huayi.config.kapArr[Rows[i].key * 1 - 1];
	                if (html1) {
	                    html1 = html1.replace("data", row.F_Id);
	                     html1 = html1.replace("data_id", row.F_DeptId);
	                }
	                html += html1;
	            }
	            return html;
	      }
			//详情
			function goDetail(ids,DeptId){
				if(DeptId==100000){
					layer.open({
				      	type: 2,
				      	title: '查看知识库详情',
				      	area: ['70%', '60%'],
				      	maxmin:true,
				      	content: 'policiesDetails.html?ids='+ ids
				    });
				}else{
				    layer.open({
				      	type: 2,
				      	title: '查看知识库详情',
				      	area: ['70%', '60%'],
				      	maxmin:true,
				      	content: 'newRepositoryDetail.html?ids='+ ids+'&&DeptId='+DeptId
				    });
				}
					
			}
			//解决
			function solve(id) {
				var laye = layer.confirm('确定解决？', {
					btn: ['确定', '取消'] //可以无限个按钮
				}, function() {
					//按钮【按钮一】的回调
					$.ajax({
						type: "post",
						url: huayi.config.callcenter_url + "Repository/DelRepository",
						async: true,
						dataType: 'json',
						data: {
						    token: $.cookie("token"),
							type: id
						},
						success: function(data) {
							if(data.state.toLowerCase() == 'success') {
								layer.msg("提交成功！");
								layer.close(laye);
								table.bootstrapTable('refresh');
							}
						}
					});
				}, function(index) {
					//按钮【按钮二】的回调
					layer.close(laye)
				});
			}
			//解决
			function solve(id) {
				var laye = layer.confirm('确定解决？', {
					btn: ['确定', '取消'] //可以无限个按钮
				}, function() {
					//按钮【按钮一】的回调
					$.ajax({
						type: "post",
						url: huayi.config.callcenter_url + "Repository/OptRep",
						async: true,
						dataType: 'json',
						data: {
						    token: $.cookie("token"),
							repid: id,
							type:1
						},
						success: function(data) {
							if(data.state.toLowerCase() == 'success') {
								layer.msg("提交成功！");
								layer.close(laye);
								table.bootstrapTable('refresh');
							}
						}
					});
				}, function(index) {
					//按钮【按钮二】的回调
					layer.close(laye)
				});
			}
			function noSolve(id){
				var laye=layer.open({
			          type: 1,
			          shade: false,
			          area: ['430px', '260px'],
			          title: '请输入未解决原因', //不显示标题
			          content:
			          '<div style="padding-top:10px;padding-left:20px;">\n' +
			                '</span><textarea id="result" type="text" placeholder="请输入未解决原因"></textarea>' +
			            '</div>',
			          cancel: function(){
			            layer.close();
			          },
			          btn: ['确定','取消'],//按钮
			          yes: function(){ 
			          		if(!$('#result').val()){
									layer.msg('请填写未解决原因!');
									return false;
							}else{
								$.ajax({
									type: "post",
									url: huayi.config.callcenter_url + "Repository/OptRep",
									async: true,
									dataType: 'json',
									data: {
									    token: $.cookie("token"),
										repid: id,
										reason:$('#result').val(),
										type:2
									},
									success: function(data) {
										if(data.state.toLowerCase() == 'success') {
											layer.msg("提交成功！");
											layer.close(laye);
											table.bootstrapTable('refresh');
										}
									}
								});
							}
			          }
			        });
			}
//			//未解决
//			function noSolve(id) {
//				var laye = layer.confirm('确定未解决？', {
//					area: ['500px', '300px'],
//					content:
//			            '<div>\n' +
//			                '<span class="result_str">未解决原因:</span><textarea id="result" type="text"></textarea>' +
//			            '</div>',
//					btn: ['确定', '取消'] //可以无限个按钮
//				}, function() {
//					//按钮【按钮一】的回调
//					if(!$('#result').val()){
//							layer.msg('请填写未解决原因!');
//							return false;
//					}else{
//						$.ajax({
//							type: "post",
//							url: huayi.config.callcenter_url + "Repository/OptRep",
//							async: true,
//							dataType: 'json',
//							data: {
//							    token: $.cookie("token"),
//								repid: id,
//								reason:$('#result').val(),
//								type:2
//							},
//							success: function(data) {
//								if(data.state.toLowerCase() == 'success') {
//									layer.msg("提交成功！");
//									layer.close(laye);
//									table.bootstrapTable('refresh');
//								}
//							}
//						});
//					}
//				}, function(index) {
//					//按钮【按钮二】的回调
//					layer.close(laye)
//				});
//			}
			//编辑
			function goEdit(ids,DeptId){
				if(DeptId==100000){
					 //iframe窗
				    layer.open({
				      	type: 2,
				      	title: '编辑知识库',
				      	area: ['70%', '60%'],
				      	maxmin:true,
				      	content: 'policesAdd.html?ids='+ ids +'&depId='+$('#depID').val() 
				    });
				}else{
					//iframe窗
				    layer.open({
				      	type: 2,
				      	title: '编辑知识库',
				      	area: ['70%', '60%'],
				      	maxmin:true,
//				      	content: 'newRepositoryAdd.html?ids='+ ids +'&depId='+$('#depID').val()
				      	content: 'newRepositoryAdd.html?ids='+ ids +'&depId='+DeptId
				    });
				}
						
			}
			//删除
			function goDel(id) {
				var arr=[];
				arr.push(id);
				var laye = layer.confirm('您确定要删除吗？', {
					btn: ['确定', '取消'] //可以无限个按钮
				}, function() {
					//按钮【按钮一】的回调
					$.ajax({
						type: "post",
						url: huayi.config.callcenter_url + "Repository/DelRepository",
						async: true,
						dataType: 'json',
						data: {
						    token: $.cookie("token"),
							ids: arr
						},
						success: function(data) {
							if(data.state.toLowerCase() == 'success') {
								layer.msg("删除成功！");
								layer.close(laye);
								table.bootstrapTable('refresh');
							}
						}
					});
				}, function(index) {
					//按钮【按钮二】的回调
					layer.close(laye)
				});
			}

