define(function(require){
	var $ = require('jquery');
	require('grid')($);
    require('uriTemplate')($);
    require('dialog')($);
    require('datepicker')($);
	var IFA = require('util');
	require("../../../../styles/cim/jquery-ui-1.8.14.custom.css");
	require('../../../../styles/cim/cim-grid.css');   
	$(function(){
		search();
		$("#searchBtn").bind("click",search);
		$("#resetBtn").bind("click",reset);
		$("#searchForm :input").bind("keydown",function(e){
			var e = e ? e : window.event;
			if(e.keyCode==13){
			   search();
			}
		});
	});
	//根据条件查询
	function search(){
		var url=$("#queryUrl").val().trim();
		//console.log(IFA.convertQueryStringToJson($("#searchForm").serialize()));
		//console.log($("#searchForm").serialize());
		$("#sendHistoryList").grid({
			url:url,
			root:"smsSendList",
			pageTheme:'Theme1',
			isREST :false,
			method:"POST",
			defaultParams:{smsSendToName:$('#smsSendToName').val(),smsSendUserName:$('#smsSendUserName').val(),startTime:$('#startTime').val(),endTime:$('#endTime').val()},
			fields:[{name:i18n["Entity.grid.seq"],type:'seq',style:{width:"5%"}},
			        {name:i18n["Entity.mailsend.receiver"],style:{width:"25%"},id:"smsSendMobilephone"},
			        {name:i18n["Entity.mailsend.sendtime"],style:{width:"25%"},id:"smsSendDate",type:'time'},
			        {name:i18n["Entity.mailsend.sender"],style:{width:"20%"},id:"smsSendUserName",render:function(data){
			        	var smsSendUserName="";
			        	var dataName=data.smsSendUserName;
			        	if(dataName.lenth>10){
			        		smsSendUserName=dataName.substring(0,10)+"...";
			        	}else{
			        		smsSendUserName=dataName;
			        	}
			        	return smsSendUserName;
			        }},
			        {name:i18n["Entity.Operation"],style:{width:"20%"},operation:[
			                                                  {text:"detail",display:true,action:function(data){
			                                                	  var id = data.smsSendId;
			                                      			      var hiddenUrl = $('#detailUrl').val();
			                                      			      var urlStr = new $.Template(hiddenUrl);
			                                      				  var urlParam = {"id":id};
			                                      				  var url = urlStr.expand(urlParam);	
			                                      			      location.replace(url);	
			                                                  }}
			                                                  ]}
			        ]
			});
	}
	
	$("#startTime").datepicker({ 
		
	});
    $("#endTime").datepicker({
	});
	//重置查询条件
	function reset(){
		$("#smsSendToName").val("");
		$("#smsSendUserName").val("");
		$("#startTime").val("");
		$("#endTime").val("");

	}
});