<!DOCTYPE html>
<html>
  <head>
 	 <base href="#springUrl('/assets/adminlte/')"/>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>工作台</title>
 	  <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="plugins/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="plugins/ionicons/css/ionicons.min.css">
    
       <!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">
    
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="plugins/iCheck/flat/blue.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="plugins/morris/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body class="hold-transition skin-blue sidebar-mini">


 <div class="wrapper">
    <div class="content-wrapper"  style="margin-left:0;">
    
     <section class="content-header">
          <h1>
             	公众号管理
            <small>公众号信息</small>
          </h1>
          <ol class="breadcrumb">
          </ol> 
        </section>
    
  
    
        <!-- Main content -->
        <section class="content">
          <div class="row">
            <div class="col-xs-12">
              <div class="box">
                <div class="box-header">
                #if($shiro.hasPermission("mp:account:edit"))
                   <a href="#springUrl('/a/manageaccounts/accountsaddform')" class="btn bg-olive margin">新增</a>
                #end
                </div><!-- /.box-header -->
                <div class="box-body">
                
                
                  <table id="userlilst" class="table table-bordered table-striped">
                    <thead>
                        <tr>
                                        <th hidden="true">id</th>
                                        <th style="width: 10%">微信类型</th>
                                        <th style="width: 15%">微信号名称</th>
                                        <th style="width: 15%">appid</th>
                                        <th style="width: 20%">secret</th>
                                        <th style="width: 10%">encodingaeskey</th>
                                        <th style="width: 10%">创建时间</th>
                                        <th style="width: 20%">操作</th>
                                    </tr>
                    </thead>
                    <tbody id="tablebody">
                   					 </tbody>
				
                  </table>
                  	          <script id="template" type="text/template7">
						{{#each this}}
                      <tr>
						<td hidden="true">{{id}}</td>
					    <td>{{wctype}}</td>
                        <td>{{description}}</td>
                         <td>{{appid}}</td>
						<td>{{secret}}</td>
						<td>{{encodingaeskey}}</td>
						<td class="times">{{createtime.time}}</td>
						<td> 
						<a href="javascript:void(0)" data-id="{{id}}" data-appid = "{{appid}}" data-action="view" onclick="manage(this)" class="btn red">回调地址</a>
						#if($shiro.hasPermission("mp:account:edit"))
						<a href="#springUrl('/a/manageaccounts/getaccountdetail?id={{id}}')" data-id="{{id}}" data-action="view" class="btn green">修改</a>
						{{#js_compare "this.delflag==0"}}
						<a href="javascript:void(0)" data-id="{{id}}" data-action="remove" onclick="removeData(this)" class="btn red">删除</a>
						#end 
						{{else}}
						<a href="javascript:void(0)" data-id="{{id}}" data-action="remove" onclick="startData(this)" class="btn red">启用</a> 
						{{/js_compare}}
                       </td>
                      </tr>
						{{/each}}
                	</script>
                  
                </div><!-- /.box-body -->
              </div><!-- /.box -->
            </div><!-- /.col -->
          </div><!-- /.row -->
        </section><!-- /.content -->
      </div><!-- /.content-wrapper -->  
   	


      <!-- Add the sidebar's background. This div must be placed
           immediately after the control sidebar -->
      <div class="control-sidebar-bg"></div>
    </div><!-- ./wrapper -->

<!-- END CONTAINER -->
<!-- BEGIN FOOTER -->
<!-- END FOOTER -->
    <script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="bootstrap/js/bootstrap.min.js"></script>
    <!-- DataTables -->
    <script src="plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
    <!-- SlimScroll -->
    <script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- FastClick -->
    <script src="plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="dist/js/demo.js"></script>
   <script src="dist/js/template7.js"></script>
 <script>
     var csrfheader = {name:'_csrf_header',value:'${_csrf.headerName}'};
     var csrftoken  = {name:'_csrf',value:'${_csrf.token}'};
 </script>
 <script src="plugins/bootbox/bootbox.min.js"></script>


<!-- END PAGE LEVEL PLUGINS -->
<script>

function manage(node)
{
	  //top.location.href= "#springUrl('/a/showpage?id=')"+$(node).attr("data-id");
    var protocol = location.protocol;//协议 http:
    var domain = document.domain;//域名 localhost
    var currentPath = window.document.location.href;//当前网址 http://localhost:8080/cfwechat/index.html
    var pathName = window.document.location.pathname;//获取主机地址之后的目录，如： /cfwechat/index.html
    var appid =$(node).attr("data-appid");
    var text=protocol+"//"+domain+pathName.substring(0, pathName.substr(1).indexOf('/') + 1)+"/mobile/wechat/get?appid="+appid;
    if($(".slideDown") && $(".slideDown").length>0){
        if($(node).parent().parent().next("tr[class='slideDown']").length==0){//当前节点不存在，添加
            var HTML="";
            HTML+="<tr class='slideDown' style='display: none;background: #F4F4F4;'>";
            HTML+="<td colspan='7' style='text-align: right;'>回调地址为:<span style='margin-left:10px;padding: 10px;border: 1px #ccc solid'>"+text+"</span></td>";
            HTML+="</tr>";
            $(node).parent().parent().after(HTML);
            $(node).parent().parent().next("tr").slideDown("1000");
        }else{//存在了，删除
            $(node).parent().parent().next("tr[class='slideDown']").remove();
        }
        $(".slideDown").not($(node).parent().parent().next("tr[class='slideDown']")).remove();//删除非自己节点的其他节点地址
    }else{
        var HTML="";
        HTML+="<tr class='slideDown' style='display: none;background: #F4F4F4;'>";
        HTML+="<td colspan='7' style='text-align: right;'>回调地址为:<span style='margin-left:10px;padding: 10px;border: 1px #ccc solid'>"+text+"</span></td>";
        HTML+="</tr>";
        $(node).parent().parent().after(HTML);
        $(node).parent().parent().next("tr").slideDown("1000");
    }
}





function removeData(node)
{
	var cn = {
	    OK : '确定',
	    CANCEL : '取消',
	    CONFIRM : '确认'
	};
	bootbox.addLocale("cn",cn);
	bootbox.setLocale("cn");
	bootbox.confirm({
	    size: 'large',
	    message: "是否确定删除？", 
	    callback: function(result){
	   		if(result)
	   		{
	   		   $.post("#springUrl('/a/manageaccounts/deleteaccounts?id=')"+$(node).attr("data-id"),{_csrf_header:csrfheader.value,_csrf:csrftoken.value}, function(returnobj) {
	               if (returnobj.errorCode == '1') {
	            	   bootbox.alert("删除失败，请重试", function() {
	            		});
	               }else
	               {
	            	   bootbox.alert("删除成功", function() {
	            		   window.location.href="#springUrl('/a/manageaccounts/accountslist')";
	            	   });
	               }
	            });
	   		}
	    }
	});
}

function startData(node)
{
	var cn = {
	    OK : '确定',
	    CANCEL : '取消',
	    CONFIRM : '确认'
	};
	bootbox.addLocale("cn",cn);
	bootbox.setLocale("cn");
	bootbox.confirm({
	    size: 'large',
	    message: "是否确定启用账户？", 
	    callback: function(result){
	   		if(result)
	   		{
	   		   $.getJSON("#springUrl('/a/manageaccounts/startaccounts')",{id:$(node).attr("data-id"),delflag:0} ,function(returnobj) {
	               if (returnobj.errorCode == '1') {
	            	   bootbox.alert("账户启用失败，请重试", function() {
	            	   });
	               }else{
	            	   bootbox.alert("账户启用成功", function() {
	            		   window.location.href="#springUrl('/a/manageaccounts/accountslist')";
	            	   });
	               }
	            });
	   		}
	    }
	});
}


    jQuery(document).ready(function() {
     	   var oLanguage={
     		        "oAria": {"sSortAscending": ": 升序排列", "sSortDescending": ": 降序排列"},
     		        "oPaginate": {
     		            "sFirst": "首页",
     		            "sLast": "末页",
     		            "sNext": "下页",
     		            "sPrevious": "上页"
     		        },
     		        "sEmptyTable": "没有相关记录",
     		        "sInfo": "第 _START_ 到 _END_ 条记录，共 _TOTAL_ 条",
     		        "sInfoEmpty": "第 0 到 0 条记录，共 0 条",
     		        "sInfoFiltered": "(从 _MAX_ 条记录中检索)",
     		        "sInfoPostFix": "",
     		        "sDecimal": "",
     		        "sThousands": ",",
     		        "sLengthMenu": "每页显示条数: _MENU_",
     		        "sLoadingRecords": "正在载入...",
     		        "sProcessing": "正在载入...",
     		        "sSearch": "搜索:",
     		        "sSearchPlaceholder": "",
     		        "sUrl": "",
     		        "sZeroRecords": "没有相关记录"};
     	   $.fn.dataTable.defaults.oLanguage=oLanguage;
     	  var sSource = "#springUrl('/a/manageaccounts/accounts/fetchdata')";
     	   var aoData = {
     			   iDisplayStart:1,
     			   iDisplayLength:10
     	   };
     	// Compile templates once on app load/init
     	   var searchTemplate = $('#template').html();
     	   var compiledSearchTemplate = Template7.compile(searchTemplate);
     
     	   
     	   
     	   
     	  function   formatDates(now)   {     
              var   year=now.getFullYear();     
              var   month=now.getMonth()+1;     
              var   date=now.getDate();     
              var   hour=now.getHours();     
              var   minute=now.getMinutes();     
              var   second=now.getSeconds();     
              return   year+"-"+month+"-"+date+"   "+hour+":"+minute+":"+second;     
              }  
     	   
     	   function fnCallback(data)
     	  	{
     	  	    for (var i = 0, j = data.aaData.length; i < j; i++) {
     	  	        var obj = data.aaData[i];

     	  	        if (obj.wctype == '0') {
                        obj.wctype = '服务号';
                    } else {
                        obj.wctype = '企业号';
                    }
                }

     		  $("#tablebody").append(compiledSearchTemplate(data.aaData));
     		  
     		  //执行 时间 计算 
     		    $("#tablebody .times").each(function(e)
     		    {
     		    	var longtimes = $(this).html();
     		    	 $(this).html(formatDates(new Date(parseInt(longtimes))));
     		    	
     		    }		
     		    );
     		      $('#userlilst').DataTable({
     		      "paging": true,
   		          "lengthChange": false, 
   		          "searching": false,
   		          "ordering": false,
   		          "bPaginate" : true, //是否显示（应用）分页器  
   		           "bInfo" : true, //是否显示页脚信息，DataTables插件左下角显示记录数  
   		           "sPaginationType" : "full_numbers"
     		        });
     	  	}
     	     $.ajax({
                  "type": "GET",
                  "contentType": "application/json",
                  "url": sSource,
                  "dataType": "json",
                  "data": aoData, //以json格式传递
                  "success": fnCallback
              });   
    });
</script>
</body>
<!-- END BODY -->
</html>