define(function(require){
	var $ = require('jquery');
	require('grid')($);
	require('dialog')($);
	require('uriTemplate')($);
	require('globalization'); 
	require("../../../styles/cim/jquery-ui-1.8.14.custom.css");
	require('../../../styles/cim/cim-grid.css'); 
	var IFA = require('util'); 
	$(function(){
		query();
		$("#query").click(function(){query();}); // 查询
		$("#reset").click(function(){reset();}); // 重置
	});
	
	function query(){
		var queryUrl = $("#queryUrl").val();
		var paymentStatus = $("#paymentStatus").val();
		$("#alipayList").grid({
			url:queryUrl,
			root:"alipayList",
			pageTheme:'Theme1',
			method:"POST",
			isREST:false,
			defaultParams:IFA.convertQueryStringToJson($("#alipayForm").serialize()),
			fields:[
			        {id:"resId",name:i18n["Entity.alipay.resId"],render:function(data){
			        	return $('<a href="#" title='+data.resId+' class="bb"/>').html(data.resId).click(function(){
		 			    	showDetail(data.resId);
		     			});
			        }},
			        {id:"enName",name:i18n["Entity.alipay.enName"],render:function(data){
			        	return data.en1stName+' '+data.enLstName;
			        }},
			        {id:"mobileTelephone",name:i18n["Entity.alipay.mobileTelephone"]},
//			        {id:"paymentAmount",name:i18n["Entity.alipay.paymentAmount"]},			        
			        {id:"paymentAmount",name:i18n["Entity.alipay.paymentAmount"],render:function(data){
			        	return Globalize.format(data.paymentAmount,'n');
			        }},
			        
			        {id:"tradeNo",name:i18n["Entity.alipay.tradeNo"]},
			        {id:"subject",name:i18n["Entity.alipay.subject"]},
			        {id:"tradeDesc",name:i18n["Entity.alipay.tradeDesc"]},
			        {id:"paymentType",name:i18n["Entity.alipay.paymentType"],
			        	 options:{'0':i18n["Entity.alipay.paymentType.immediatePayment"],
			        	          '1':i18n["Entity.alipay.paymentType.securedTransaction"]}
			        },
			        {id:"buyerEmail",name:i18n["Entity.alipay.buyerEmail"]},
			        {id:"paymentDate",name:function(){
			        	var paymentStatus = $("#paymentStatus").val();
			        	return paymentStatus=='TRADE_CLOSED'?i18n['Entity.alipay.refundDate']:i18n['Entity.alipay.paymentDate'];
			        	
			        },type:"time"},
			        {id:"modifierName",name:i18n["Entity.modifier"]},
	  				{id:"modificationDate",name:i18n["Entity.modificationDate"],type:"time"}
			]
		});
	 };
	
	 // 显示订单详细信息
	  function showDetail(resId){
		  var showUrl = new $.Template($("#showUrl").val());
		  var param = {"resId":resId};
	      window.location= showUrl.expand(param);
	  };
	  function reset(){
		  $("#resId").val("");
		  $("#cnName").val("");
		  $("#en1stName").val("");
		  $("#enLstName").val("");
		  $("#paymentAmount").val("");
	  };
});