define(function(require){
	var $ = require('jquery');
	require('dialog')($);
	require('uriTemplate')($);
	require('../paymethod/generatorForEditting.js');
	require('../../../styles/cim/jquery-ui-1.8.14.custom.css');
	var contextPath = $("#contextPath").val();
		//返回按钮
		$("#returnButton").bind("click",function(){
			location.href=$("#indexUrl").val();
		});
		$("#submitIncomeConfirm").bind("click",submitIncomeConfirm);
	//公司图片显示
	$("#companyImageHandlerShow").bind("click",companyImageFun);
	//resHistory审计历史
	$("#resHistory").bind("click",function(){
		var urlString=new $.Template($("#searchOrderBySegmentIndex").val());
		var urlParams={"segmentNo":$("#segmentNo").val(),
				      "personId":$("#personId").val()};
		var url=urlString.expand(urlParams);
		resHistory(url);
	});
			
	function resHistory(url){
		window.open(url,window);
	}
	//公司价格链接显示图片
	function companyImageFun(){
		$("#imageDrag").removeAttr("style");
		$("#companyImage").dialog({title:i18n["JS.workOrder.companyPricePic"], height:420,width:330, 
			modal: false,closeOnEscape:true,overlay: { opacity: 0.5, background: 'black',overflow:'auto'},
			buttons:{
			'ReDo':function(){$("#imageDrag").removeAttr("style");},	
			'Zoom In':function(){
				$("#imageDrag").css({
				      width: function(index, value) {
				        return parseFloat(value) * 1.2;
				      }, 
				      height: function(index, value) {
				        return parseFloat(value) * 1.2;
				      }});
			},
			'Zoom Out':function(){
				$("#imageDrag").css({
				      width: function(index, value) {
				        return parseFloat(value) / 1.2;
				      }, 
				      height: function(index, value) {
				        return parseFloat(value) / 1.2;
				      }});
			},
			'Close':function(){$(this).dialog('close');}
			}}); 
	}
	//现金确认方法
	function submitIncomeConfirm(){
		var amount=queryCashAmount($("#id").val());
		$('#amountString').text(amount);
		$.msg.confirm(i18n["JS.workOrder.system.tips"],$('#template'),function(result){
			if(result){
				var contractNo = $('#contractNo').val();
				var bankNo = $('#bankNo').val();
				var tips = "<font color='red'>"+i18n["JS.workOrder.submitIncomeTipsAgain"];
				var amountString="<font color='red'>"+i18n["JS.workOrder.cashTotals"]+":"+amount+"RMB</font>"+"</br>&nbsp;&nbsp;"+i18n["Entity.cash.serializNum"]+":"+contractNo+"</br>&nbsp;&nbsp;"+i18n["Page.workOrder.BankCode"]+"："+bankNo;
				$.msg.confirm(i18n["JS.workOrder.system.tips"],tips+"<BR>&nbsp;&nbsp;"+amountString,function(result){
					if(result){
						$.ajax({
							type:"post",
							url:$("#submitIncomeConfirmUrl").val(),
							data:{ids:$("#id").val(),contractNo:contractNo,bankNo:bankNo,paymentAmount:amount},
							success:function(){
								$.msg.alert(i18n["JS.workOrder.submitIncomeSuccess"]);
								location.href=$("#indexUrl").val();
							}
						});
			}
					});
		  }
		});
	}
	//查询现金确认总额
	function queryCashAmount(ids){
		var amounts=0;
		$.ajax({
			type:"post",
			url:$("#cashAmountUrl").val(),
			async:false,
			data:{ids:ids},
			success:function(response,ioArgs){
				amounts=parseFloat(response.amounts).toFixed(2);
			}
		});
		return amounts;
	}
	function hve_display(tId,iId){//显示隐藏程序
		var t_id = tId;//表格ID
		var i_id = iId;//图片ID
		var on_img=contextPath+"/images/btn_arrow_down.gif";//打开时图片
		var off_img=contextPath+"/images/btn_arrow_right.gif";//隐藏时图片
		if (t_id.style.display == "none") {//如果为隐藏状态
			t_id.style.display="";//切换为显示状态
			i_id.src=on_img;//换图
		}
		else{
			t_id.style.display="none";//切换为隐藏状态
			i_id.src=off_img;//换图
		}
		}
	
	$(".tableRes h2").bind("click",function(){
		var tal = $(this).parents(".tableRes").next(".tableRes");
		var img = $(this).children();
		hve_display(tal.get(0),img.get(0));
	});
});