<!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]-->
   <style>
table th,td { 
	word-break: break-all
}
</style>
  </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">
            <li><a href="#springUrl('/page/user/showstatics')"><i class="fa fa-dashboard"></i>首页</a></li>
            <li><a class="active">二维码列表</a></li>
          </ol>
        </section>
        <!-- Main content -->
        <section class="content">
          <div class="row">
            <div class="col-xs-12">
              <div class="box">
              <div class="box-header">
              		<form id="seachTableForm"
								action="#springUrl('/a/wx/qrcode/list')" method="get">
	                <div class="col-xs-2">
						<input type="text" class="form-control required"
							placeholder="门店名称" name="storeName" value="$!{qrcode.storeName}" >
					</div>
					<div class="col-xs-2">
						<input type="text" class="form-control required"
							placeholder="门店/导购ID" name="sence" value="$!{qrcode.sence}">
					</div>
					<div class="col-xs-1">
						<button style="width: 100px;" id="seach" type="submit" class="btn btn-primary">搜索</button>
					</div>                 
					<div class="col-xs-2"> 
							  #if($shiro.hasPermission("mp:qrcode:edit"))
	                  			 <a href="#springUrl('/a/wx/qrcode/qrcodeform')"  class="btn bg-olive">新增二维码</a>
	                   		  #end
					</div>
                </div> 
                <!-- /.box-header -->
                <div class="box-body">
                  <table id="qrcodelist" class="table table-bordered table-striped">
                  		<thead>
                  			<th hidden="true">Id</th>
                  			<th>二维码</th>
                  			<th>创建时间</th>
                  			<th>回复类型</th>
                  			<th>回复内容</th>
                  			<th>有效性</th>
                  			<th>失效时间</th>
                  			<th>门店名称</th>
                  			<th>门店/导购ID</th>
                  		</thead>
	                    <tbody id="tablebody">
	                    </tbody>
                  </table>
                </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/extensions/i18n/lanauage_ch.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="plugins/bootbox/bootbox.min.js"></script>
 <script src="common/js/cfapp.js"></script>
<!-- END PAGE LEVEL PLUGINS -->

 <script>
     var csrfheader = {name:'_csrf_header',value:'${_csrf.headerName}'};
     var csrftoken  = {name:'_csrf',value:'${_csrf.token}'};
 </script>
<script>
	var table;
function   formatDates(now)   {
	var now = new Date(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;
}  
   jQuery(document).ready(function() {
         sourceData();    
    }); 
    
   
   function sourceData(){
	   var sSource = "#springUrl('/a/wx/qrcode/fetchData')";
   	 var retrieveData = function (sSource, aoData, fnCallback) {
   		aoData.push({"name":"storeName","value":$("input[name='storeName']").val()},
		{"name":"sence","value":$("input[name='sence']").val()});    
           $.ajax({
               "type": "GET",
               "contentType": "application/json",
               "url": sSource,
               "dataType": "json",
               "data": aoData, //以json格式传递
               "success":fnCallback
           });
       };  
      $('#qrcodelist').DataTable({
            "lengthChange": false,
            "searching": false,
            "ordering": false,
            "bFiltered": false,   
           "bStateSave" : true, //save datatable state(pagination, sort, etc) in cookie.
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": sSource,
            "fnServerData": retrieveData,
            "pagingType": "full_numbers",
           "aoColumns": [
                        {"mData": "id"},
                		{"mData": "shortUrl"},
                        {"mData": "createTime"},
                    	{"mData": "replyType"},
                   		{"mData": "contentSource"},
                  		{"mData": "actionName"},
                	 	{"mData": "esEndtime"},
                	 	{"mData": "storeName"},
                	 	{"mData": "sence"}
                        ],
                    "aoColumnDefs": [ 
                        {  // set default column settings
                            'visible': false,
                            'targets': [0]
                        },{  // set default column settings
                            'targets': [1],
                           	"mData" : "shortUrl",
                           	"mRender" : function(a, b, c, d) {
                           	var viewHTML ='<img style="width: 100px;height: 100px" src="'+a+'">';
                           	return viewHTML;
                           	}
                        },{  // set default column settings
                            'targets': [2],
                           	"mData" : "createTime",
                      		"mRender" : function(a, b, c, d) {
  								return formatDates(c.createTime, "yyyy-MM-dd HH:mm:ss");
                      		}
                        },{  // set default column settings
                            'targets': [3],
                           	"mData" : "replyType",
                           	"mRender" : function(a, b, c, d) {
                           		if(c.replyType=="text"){
                           			return "文本";
                           		}else if(c.replyType=="news"){
                           			return "图文";
                           		}else if(c.replyType=="store"){
                           			return "门店二维码"; 
                           		}else if(c.replyType=="shoping"){
                           			return "导购二维码";
                           		}else if(c.replyType==""){
                           			return "安装工二维码";
                           		}else{
                           			return "";
                           		}
                           	}
                        },{  // set default column settings
                            'targets': [4],
                           	"mData" : "contentSource",
                           	"mRender" : function(a, b, c, d) {
                           		if(c.replyType=="text"){
                           			return c.contentSource;
                           		}else if(c.replyType=="news"){
                           			return "图文";
                           		}else if(c.replyType=="store"){
                           			return "门店";
                           		}else if(c.replyType=="shoping"){
                           			return "导购";
                           		}else{
                           			return "";
                           		}
                           	}
                        },{  // set default column settings
                            'targets': [5],
                           	"mData" : "actionName",
                           	"mRender" : function(a, b, c, d) {
                           		if(c.actionName=="QR_SCENE"){
                           			return "临时";
                           		}else if(c.actionName=="QR_LIMIT_SCENE"){
                           			return "永久";
                           		}else if(c.actionName=="QR_LIMIT_STR_SCENE"){
                           			return "永久";
                           		}
                           	}
                        },{  // set default column settings
                            'targets': [6],
                           	"mData" : "esEndtime",
                           	"mRender" : function(a, b, c, d) {
                           		if(c.actionName == "QR_SCENE"){
	                           		return formatDates(c.esEndtime, "yyyy-MM-dd HH:mm:ss");
                           		}else{
                           			return "无"
                           		}
                           	}
                        } 
//	                        {  // set default column settings
//	                            'targets': [7],
//	                           	"mData" : "id",
//	                           	"mRender" : function(a, b, c, d) {
//	                           		var viewHTML="";
//	                           		var removeHTML="";
//	                           		if(c.replyType!="store" && c.replyType!="shoping"){
//	                           			viewHTML ="#if($shiro.hasPermission('mp:qrcode:edit'))"+"<a href=#springUrl('/a/wx/qrcode/qrcodeform?id="+a+"') >修改</a> "+"#end";
//		     		            		removeHTML="#if($shiro.hasPermission('mp:reply:edit'))"+"<a href='javascript:void(0);' data-id='"+a+" data-action='remove' onclick='removeData("+a+")' class='btn red'>删除</a>"+"#end";
//	                           		} 
//		     		            return viewHTML+removeHTML;
//	                           	}
//	                        }
                        ]
        });
   }
   
   
   
    function removeData(id){ 
		   Cfapp.confirm({
			 message: "确定要删除吗",
			 btnoktext:"确定",
			 btncanceltext:"取消",
			 success:function(){
				 $.ajax({
		              "type": "POST",
		              "url": "#springUrl('/a/wx/qrcode/removeqrcode')",
		              "dataType": "json",
		              "data": {id:id,"_csrf_header":csrfheader.value,"_csrf":csrftoken.value}, //以json格式传递
		              "success": function(data){
		            	  if(data.errorNo==0){
		            		  Cfapp.alert({
		                          message: "删除成功",
		                          btntext: "确定",
		                          success: function () {
		                        	 location.href = "#springUrl('/a/wx/qrcode/list')";
		                          }
		                      })
		            	  }else{
		            		  Cfapp.alert({
		                          message: "删除失败",
		                          btntext: "确定",
		                          success: function () {
		                              location.href = "#springUrl('/a/wx/qrcode/list')";
		                          }
		                      })
		            	  }
		              }
		          }); 
			 },
			cancel:function(){
				$(".modal-backdrop").fadeOut();

			 }
		   })
	   }
</script>
</body>
<!-- END BODY -->
</html>