define(function(require){
	var $ = require('jquery');
	require('uriTemplate')($);
	require('dialog')($);
	require('datepicker')($);
	require('validation')($);
	require('grid')($);
	var IFA = require('util');
	require('../../../styles/cim/jquery-ui-1.8.14.custom.css');
	require('../../../styles/cim/cim-grid.css');
	$(function(){
		
		$("#import").bind("click",importData);
		$("#APTimport").bind("click",aptimportData);
		$("#CITYimport").bind("click",cityData);
		$("#export").bind("click",cdsdExport);
		$("#cdsdDownLoad").bind("click",cdsdDownload);
		$("#APTexport").bind("click",APTexport);
		$("#aptDownLoad").bind("click",aptTemplate);
		$("#cityDownLoad").bind("click",cityTemplate);
		$("#CITYexport").bind("click",cityExport);
		uploadSuccess();
		cityCheckMessage();
		aptCheckMessage();
		cdsdCheckMessage();
		showrepeatMessage();
		var templateInfo=$("#templateInfo").val();
		if(templateInfo!=null &&templateInfo!=""){
			$.msg.alert(i18ns("RateSheet.productPrice.noTemplate"));
		}
		
	});
	//重复数据
	function showrepeatMessage(){
		var citymes="";
		var cdsdmes="";
		var aptmes="";
		var citylength=cityrepeatMessage.length;
		var cdsdlength=cdsdrepeatMessage.length;
		var aptlength=aptrepeatMessage.length;
		if(citylength==0 && cdsdlength==0 && aptlength==0){
			return false;
		}
		if(citylength!=0){
			for(var i=0;i<citylength;i++){
				if(cityrepeatMessage[i]){
					citymes+=i+",";//city repeat data
				}
			}
			citymes = i18ns('RateSheet.check.excel.message.cityrepeateMessage').patchContent(citymes)+'\n\<br>';
		}
		if(cdsdlength!=0){
			for(var i=0;i<cdsdlength;i++){
				if(cdsdrepeatMessage[i]){
					cdsdmes+=i+",";
				}
			}
			cdsdmes = i18ns('RateSheet.check.excel.message.cdsdrepeateMessage').patchContent(cdsdmes)+'\n\<br>';
		}
		if(aptlength!=0){
			for(var i=0;i<aptlength;i++){
				if(aptrepeatMessage[i]){
					aptmes+=i+",";
				}
			}
			aptmes = i18ns('RateSheet.check.excel.message.aptrepeateMessage').patchContent(aptmes);
		}
			$.msg.alert(citymes+cdsdmes+aptmes);
	}
	//验证cdsd数据信息
	function cdsdCheckMessage(){
		var mes="";
		var length=CDSDerrorMessage.length;
		if(length==0){
			return false;
		}
		for(var i=0;i<CDSDerrorMessage.length;i++){
			if(CDSDerrorMessage[i]){
				mes+=i+2+",";
			}
		}
		$.msg.alert(i18ns('RateSheet.check.excel.cdsdmessage').patchContent(mes));
	}
	//验证apt 数据信息
	function aptCheckMessage(){
		var mes="";
		var length=APTerrorMessage.length;
		if(length==0){
			return false;
		}
		for(var i=0;i<APTerrorMessage.length;i++){
			if(APTerrorMessage[i]){
				mes+=i+2+",";
			}
		}
			$.msg.alert(i18ns('RateSheet.check.excel.aptmessage').patchContent(mes));
	}
	//Intercity 数据验证信息
	function cityCheckMessage(){
		var mes="";
		var city=CITYerrorMessage;
		if(city.length==0){
			return false;
		}
		for(var i=0;i<CITYerrorMessage.length;i++){
			if(CITYerrorMessage[i]){
				mes+=i+3+",";
			}
		}
		$.msg.alert(i18ns('RateSheet.check.excel.cityMessage').patchContent(mes));
		
	};
	/**
	 * 提示导入数据成功
	 */
	function uploadSuccess(){
		var upload = $("#upload").val();
		if(upload=="true"){
			$.msg.alert(i18ns("Page.Dialog.content.upload.success")); 
		}
	}
	/**
	 * city 数据导出
	 */
	function cityExport(){
		var url=$("#cityExportUrl").val().trim();
		 location.href=url;
	}
	/**
	 * city 模版导出
	 */
	function cityTemplate(){
		var url=$("#cityTemplateUrl").val().trim();
		 location.href=url;
	}
	/**
	 * 模板导出APT
	 */
	function aptTemplate(){
		var url=$("#aptTemplateUrl").val().trim();
		 location.href=url;
	}
	
	/**
	 * APT 数据导出
	 */
	function APTexport(){
		var url=$("#aptExportUrl").val().trim();
		 location.href=url;
	}
	
	/**
	 * 模板下载
	 */
	function cdsdDownload(){
		location.href=$("#cdsdTemplate").val().trim();
	}
	
	
	/**
	 * cdsd 导出数据
	 */
	function cdsdExport(){
		 var url = $("#cdsdExport").val().trim();
		 location.href=url;
	}
	
	//导入数据
	function importData(){
		var fileName = $("#cdsd").val().trim();
			if(fileName=="" ||fileName==null){
				$.msg.alert(i18n["RateSheet.productPrice.meage1"]);
				return ;
			}
			var suffix = fileName.split(".");
			var excelSuffix = suffix[suffix.length-1];
			if(excelSuffix!="xlsx" && excelSuffix!="xls"){
				$.msg.alert(i18n["RateSheet.productPrice.meage2"]);
				return ;
			}
		
		$("#importFrom").submit();
	}
	//apt导入数据
	function aptimportData(){
		var fileName = $("#aptfile").val().trim();
		if(fileName=="" ||fileName==null){
			$.msg.alert(i18n["RateSheet.productPrice.meage1"]);
			return ;
		}
		var suffix = fileName.split(".");
		var excelSuffix = suffix[suffix.length-1];
		if(excelSuffix!="xlsx" && excelSuffix!="xls"){
			$.msg.alert(i18n["RateSheet.productPrice.meage2"]);
			return ;
		}
		
		$("#apt").submit();
	}
	//intercity导入数据
	function cityData(filename,formName){
		var fileName = $("#intercity").val().trim();
		if(fileName=="" ||fileName==null){
			$.msg.alert(i18n["RateSheet.productPrice.meage1"]);
			return ;
		}
		var suffix = fileName.split(".");
		var excelSuffix = suffix[suffix.length-1];
		if(excelSuffix!="xlsx" && excelSuffix!="xls"){
			$.msg.alert(i18n["RateSheet.productPrice.meage2"]);
			return ;
		}
		
		$("#intercityImport").submit();
	}

	
	

});