//var interval = 0;
//var code, code1, code2, code3;
var SUCCESS_CODE = 0;
/**
 *@description 简历解析
 */
function resumeAnalysis(that) {
	// 简历解析状态
	var ANALYSIS_TODO = 1;		//待解析 SAVED 1
	var ANALYSIS_SUCCESS = 7;	//解析成功 FINISHED 7
	var ANALYSIS_FAIL = 8;		//解析失败 ERROR 8
	// 简历解析任务状态
	var NOT_START = 1;			//上传简历 SAVED 1
	var SUBMITED = 2; 			//提交解析 SUBMITED 2
	var EXECUTING = 4;			//开始解析 RUNNING 4
	var FINISHED = 7;			//解析完成 FINISHED 7
	var TIMEOUT = 9;			//解析超时 TIMEOUT 9
	// 任务ID
	var taskId = "";
	var targetId = '';
	//上次解析结束任务
	var lastTaskId = "";
	var lastAffirm = false;
	
	var isDialogShow = false;
	
	var analyzeTodoList = [];
	var analyzeSucceedList = [];
	var analyzeFailList = [];

	var analysisProgressTimer;
	var pageUIPK='';

	// 模态框
	var analysisModal = {
		show: false,
		init: function() {
			analyzeTodoList = [];
			analyzeSucceedList = [];
			analyzeFailList = [];	
			analysisModal.analysisTab($('.analysis-success'));
			analysisModal.analysisTab($('.analysis-failure'));
			analysisModal.analysisTab($('.analysis-todo'));	
			
			$('.doneAmount').text(0);
			$('.resumeAmount').text(0);
			$('.failedAmount').text(0);
			$('.successedAmount').text(0);
			$('.todoAmount').text(0);
		},
		hidePanel: function() {
			$('.analysis-panel').hide();
		},
		showAnalysisPanel: function() {
			this.hidePanel();
			$('.some-resume').show();
			$('.some-resume').removeClass('some-resume-hide');
		},
		compileResumeList: function(id, data) {
			var myTemplate = Handlebars.compile($("#handlebars-template").html());
			Handlebars.registerHelper("analyzeSucceed", function (x, options) {
				if (x === ANALYSIS_SUCCESS) {
					return options.fn(this);
				} else {
					return options.inverse(this);
				}
			})
			Handlebars.registerHelper("formatState", function (state, options) {
				if (state === ANALYSIS_TODO) {
					return '待解析';
				} else if (state === ANALYSIS_SUCCESS) {
					return state;
				} else if (state === ANALYSIS_FAIL) {
					return options.data.root.resumes[options.data.index].info;
				} else {
					return '解析失败';
				}
			})
			if(data.resumes.length == 0) {
				switch(id) {
					case 'inputcontainer':
						data = {
							resumes:false,
							des:'你没有待解析的简历哦'
						}
						$('#startAnalyze, #clearResumeList').attr('disabled', 'true').addClass('disabled');
						break;
					case 'resume-list-success':
						data = {
							resumes:false,
							des:'你还没有解析成功的简历哦'
						}
						break;
					case 'resume-list-failure':
						data = {
							resumes:false,
							des:'恭喜，你没有解析失败的简历哦'
						}
				}
			}else{
				$('#_resumeAnalysisDiv,#_resumeAnalysisDiv2,#_resumeAnalysisDiv3,#_resumeAnalysisDiv4,.shrTooltip, #viewLog').show();
			}
			$('#' + id).html(myTemplate(data));
		},
		analysisTab: function(dom) {
			var tabClassName = $(dom).attr('class').replace(' tab-current', '');
			switch (tabClassName) {
				case 'analysis-todo':
					this.compileResumeList('inputcontainer', { resumes: analyzeTodoList });
					break;
				case 'analysis-success':
					this.compileResumeList('resume-list-success', { resumes: analyzeSucceedList });
					break;
				case 'analysis-failure':
					this.compileResumeList('resume-list-failure', { resumes: analyzeFailList });
					break;
				default:
					break;
			}   
			// tab 样式
			$('.analysis-tab button').removeClass('tab-current');
			$(dom).addClass('tab-current');
			// tab-ct 样式
			var tabClassName = $(dom).attr('class').replace(' tab-current', '');
			$('.tab-ct-current').removeClass('tab-ct-current');
			$('.' + tabClassName + '-ct').addClass('tab-ct-current');   
			
			$('#_resumeAnalysisDiv,#_resumeAnalysisDiv2,#_resumeAnalysisDiv3,#_resumeAnalysisDiv4,#_resumeAnalysisDiv5,#_resumeAnalysisDiv6,.shrTooltip, #viewLog').show();

		},
		startAnalyze: function() {
			var param = {taskId: taskId};
			
			var val = $("#recuritmentDemand").shrPromptBox("getValue");
			//判断checkbox类型isKeyTalent是否选中
			var isKeyTalent = $("#isKeyTalent").is(':checked');
			var phoneModifyValue = $("#phoneModify").val();
			var count = $('#inputcontainer .resume-list').length;
			param.isKeyTalent = isKeyTalent;
			param.phoneModify = phoneModifyValue;
			if (pageUIPK == 'com.kingdee.shr.recuritment.resumeScreening' && count > 1 && (phoneModifyValue || isKeyTalent)) {
				let meg = '当选择重点人才或需更新手机号时，只能同时解析单份简历.';
				shr.showWarning({
					message: meg,
					hideAfter: 3
				})
				return false;
			}
			if(val){
				targetId = val.id;
				param.targetId = targetId;
				param.taskId = taskId;
			}else{
				var meg = '';
				if(pageUIPK == 'com.kingdee.shr.recuritment.resumeScreening'||pageUIPK == 'com.kingdee.shr.recuritment.app.RecommendRecord.list'||pageUIPK == 'com.kingdee.shr.recuritment.app.ResumeBaseRec.selfUploadDemand.list'){
					meg = '请选择招聘需求';
				}else if(pageUIPK == 'com.kingdee.shr.recuritment.talentPool'||pageUIPK=='com.kingdee.shr.recuritment.app.ResumeBaseRec.selfUploadEnterPriseArchives.list'){
					meg = '请选择目标简历夹';
				}
				shr.showWarning({
					message: meg,
					hideAfter: 3
				})
				return false;
			}
			//简历来源
			var _resumeSource = $("#resumeSource").shrPromptBox("getValue");
			if(_resumeSource && _resumeSource.id){
			    param.resumeSourceId=_resumeSource.id;
			}

			val = $("#interRecommendation").shrPromptBox("getValue");
			if(!val&&pageUIPK=='com.kingdee.shr.recuritment.app.RecommendRecord.list'){
			    meg = '请选择内部推荐人';
				shr.showWarning({
    				message: meg,
    				hideAfter: 3
    			})
    			return false;
			}
			if(_resumeSource&&_resumeSource.name=="内部推荐"&&!val){
			    meg = '选择内部推荐必须选择内部推荐人';
				shr.showWarning({
    				message: meg,
    				hideAfter: 3
    			})
    			return false;
			}
			if(val && val.id){
			    param.interRecommendationId=val.id;
			}
			val = $("#sourceType").shrSelect('getValue').value;
			if(val){
			    param.sourceType=val;
			}

			$('#restartUpload').parent('.button-wrapper').css('visibility','hidden');
			
			that.remoteCall({
				method: 'resumeAnalysis',
				param: param,
				success: function(response) {
					if(response.code == SUCCESS_CODE) {
						$('.analysis-progress,.modal-header .min').show();
						$('#startAnalyze, #clearResumeList').attr('disabled', 'true').addClass('disabled');
						$('.upload-btn').attr('disabled', 'true').addClass('disabled').css('z-index', '200');
						$("#recuritmentDemand").shrPromptBox("disable");
						$("#interRecommendation").shrPromptBox("disable");
						$("#resumeSource").shrPromptBox("disable");
						$("#sourceType").shrSelect("disable");
						initCntroller.getAnalysisProgress();
					}
					if(response.code != 0) {
						shr.showError({
							message:response.mesg,
							hideAfter:3
						});
						return 	false;
					}
				}
			})


		},
		clearTodo: function() {
			var resumeId = [];
			for(var i = 0; i < analyzeTodoList.length; i++){
				resumeId.push(analyzeTodoList[i].id);
			}
			that.remoteCall({
				method: 'deleteUploadResume',
				param: {
					deleteResumeIds:resumeId.join(',')
				},
				success: function(response) {
					if(response.code == SUCCESS_CODE) {
						$('.todoAmount').text(0);
						analyzeTodoList = []
						analysisModal.analysisTab($('.analysis-todo'));
					}
					if(response.code != 0) {
						shr.showError({
							message:response.mesg,
							hideAfter:3
						});
						return 	false;
					}
				}
			})
		},
		clearFailed: function() {
			var resumeId = [];
			for(var i = 0; i < analyzeFailList.length; i++){
				resumeId.push(analyzeFailList[i].id);
			}
			that.remoteCall({
				method: 'deleteUploadResume',
				param: {
					deleteResumeIds:resumeId.join(',')
				},
				success: function(response) {
					if(response.code == SUCCESS_CODE) {
						analyzeFailList = [];
						analysisModal.analysisTab($('.analysis-failure'));
						$('.failedAmount').text(0);		
						$('#restartUpload').parent('.button-wrapper').css('visibility','hidden');
					}
					if(response.code != 0) {
						shr.showError({
							message:response.mesg,
							hideAfter:3
						});
						return 	false;
					}
				}
			})
			
		},
		deleteResume: function(){
			var resumeId = $(this).find('a').attr('resume-id');
			that.remoteCall({
				method: 'deleteUploadResume',
				param: {
					deleteResumeIds: resumeId
				},
				success: function(response) {
					if(response.code == SUCCESS_CODE) {
						if($('.tab-ct-current').hasClass('analysis-failure-ct')){
							for(var i = 0; i < analyzeFailList.length; i++ ){
								if(analyzeFailList[i].id == resumeId){
									analyzeFailList.splice(i, 1);
									break;
								}
							}
							analysisModal.analysisTab($('.analysis-failure'));
							$('.failedAmount').text(analyzeFailList.length);	
							if(analyzeFailList.length == 0)	{
								$('#restartUpload').parent('.button-wrapper').css('visibility','hidden');
							}
						}else if($('.tab-ct-current').hasClass('analysis-todo-ct')){
							for(var i = 0; i < analyzeTodoList.length; i++ ){
								if(analyzeTodoList[i].id == resumeId){
									analyzeTodoList.splice(i, 1);
									break;
								}
							}
							analysisModal.analysisTab($('.analysis-todo'));
							$('.todoAmount').text(analyzeTodoList.length);
						}
					}
					if(response.code != 0) {
						shr.showError({
							message:response.mesg,
							hideAfter:3
						});
						return 	false;
					}
				}
			})
		},
		restartAnalyze: function() {
			if(analyzeFailList.length === 0) {
				shr.showWarning({
					message: '您没有解析错误的简历哦',
					hideAfter: 5
				})
				return
			}
			$.block.show();
			that.remoteCall({
				method: 'resumeAnalysisAgain',
				param: {
					taskId: lastTaskId
				},
				success: function(res) {
					$.block.hide();
					$('.analysis-progress,.modal-header .min').show();
					initCntroller.getAnalysisProgress(); 
					analysisModal.analysisTab($('.analysis-todo'));
					$('#startAnalyze, #clearResumeList').attr('disabled', 'true').addClass('disabled');
					$('.upload-btn').attr('disabled', 'true').addClass('disabled').css('z-index', '200');
				}
			})
		},
		checkResult: function(dom) {
			var id = $(dom).attr('id');
			$('.some-resume').removeClass('some-resume-result');
			$('.result').hide();
			$('.continueAnalyze').css({
				'visibility':'hidden',
				'z-index': '1'
			});
			// $('#resume_upload').css('left','0px');
			$('.upload-btn').css('visibility','visible');
			if(id === 'check_succeeded') {
				analysisModal.analysisTab($('.analysis-success'));
			} else {
				analysisModal.analysisTab($('.analysis-failure'));	
			}
            if(lastTaskId !=null && lastTaskId !="") {//确认智能导入结果最近导入任务不为空
                analysisModal.lastAffirmChange();
            }
		},
		close: function() {
			$('#resumeInput-modal').modal('hide');
			jQuery("#grid").trigger("reloadGrid");//重新加载表格內的数据
		},
		minimize: function() {
			isDialogShow = false;
			if(lastTaskId){
				$('.minimize-analysis').hide();
			}else{
				$('.minimize-analysis').show();
			}
		},
		setProgressNum: function(data) {
			$('.doneAmount').text(data.doneAmount);
			$('.resumeAmount').text(data.resumeAmount);
			$('.failedAmount').text(data.failedAmount);
			$('.successedAmount').text(data.successedAmount);
			$('.todoAmount').text(data.nonExecuteAmount);
			if(pageUIPK == 'com.kingdee.shr.recuritment.app.ResumeBaseRec.selfUploadDemand.list'){
                $('.result-des-extra').text('解析成功后，将为您通知对应招聘职位的负责HR！');
			}else if(pageUIPK == 'com.kingdee.shr.recuritment.app.ResumeBaseRec.selfUploadEnterPriseArchives.list'){
                $('.result-des-extra').text('简历解析成功进入简历库后，有对应权限的人员可查看并使用该简历！');
    		}
		},
		lastAffirmChange: function(){
			that.remoteCall({
				method: 'affirmSmartImportTaskResult',
				param: {
					taskId: lastTaskId
				},
				success: function(res) {
					console.log(res);
				}
			})
		}
	};
	
	// 最小化进度球
	var minimizeBall = {
		show: false,
		toggleExpansion: function() {
			$('.expansion').toggle();
		},
		maximize: function() {
			$('#resumeInput-modal').modal('show');
			$('.minimize-analysis').hide();
		}
	}

	// 初始化
	var initCntroller = {
		getSmartImportTaskSchedule: function(data) {
			if(data){
				lastTaskId = data.lastTaskId;
				lastAffirm = data.lastAffirm;
				taskId = data.id;
				analyzeTodoList = data.nonExecuteDetails;
				analyzeSucceedList = data.successDetails;
				analyzeFailList = data.failDetails;
			}else{
				$('#_resumeAnalysisDiv,#_resumeAnalysisDiv2,#_resumeAnalysisDiv3,#_resumeAnalysisDiv4,.shrTooltip, #viewLog').show();	//如果没有数据时，F7和查看日志按钮显示
			}
			analysisModal.compileResumeList('inputcontainer', { resumes: analyzeTodoList.reverse() });
			analysisModal.compileResumeList('resume-list-success', { resumes: analyzeSucceedList });
			analysisModal.compileResumeList('resume-list-failure', { resumes: analyzeFailList });
			if(data){
				analysisModal.setProgressNum(data);
			}
			
			if(!data || data.taskState === NOT_START){
				clearInterval(analysisProgressTimer);
				return;
			}
			//待解析大于0
			if(analyzeTodoList.length > 0){
				$('#startAnalyze, #clearResumeList').removeAttr('disabled').removeClass('disabled');
				$('.upload-btn').removeAttr('disabled').removeClass('disabled').css('z-index', '1');
			}
			
			//解析过程中初始化进度
			if(data && data.taskState && (data.taskState.value === SUBMITED || data.taskState.value === EXECUTING)){
				//控制带解析页面按钮不可使用
				$('#startAnalyze, #clearResumeList').attr('disabled', 'true').addClass('disabled');
				$('.upload-btn').attr('disabled', 'true').addClass('disabled').css('z-index', '200');
				//显示进度条
				$('.progress-done').css('width', data.doneAmount / data.resumeAmount * 100 + '%');
				$('.analysis-result').text('解析中...');
				$('.min-todo').show();
				
				//显示进度球
				if(!isDialogShow){
					$('.minimize-analysis').show();	
				}
			}
			//解析完成
			if(data.lastTaskState){  	
				clearInterval(analysisProgressTimer);
				//进度条隐藏
				$('.analysis-progress,.modal-header .min').hide();
				
				//按钮控制
				$('#startAnalyze, #clearResumeList').removeAttr('disabled').removeClass('disabled');
				$('.upload-btn').removeAttr('disabled').removeClass('disabled').css('z-index', '1');

				//显示结果页面
				$('.some-resume').addClass('some-resume-result');
				$('.result').show();
				$('.analysis-result').text('解析完成');
				$('.min-todo').hide();

				analysisModal.analysisTab($('.analysis-todo'));
				if(analyzeSucceedList.length !== 0) {
					$('.analysis-success-ct .button-wrapper').css('visibility', 'visible');
				}
				if(analyzeFailList.length !== 0) {
					$('.analysis-failure-ct .button-wrapper').css('visibility', 'visible');
				}
				if(data.resumeAmount === data.successedAmount) {
					$('.all-success').show();
					$('.some-failed').hide();
					$('.analysis-success-ct .button-wrapper').css('visibility', 'visible');
				} else {
					$('.some-failed').show();
					$('.all-success').hide();
					$('.analysis-failure-ct .button-wrapper').css('visibility', 'visible');
				}
				$('.analysis-progress,.modal-header .min').hide();
				$('#_resumeAnalysisDiv,#_resumeAnalysisDiv2,#_resumeAnalysisDiv3,#_resumeAnalysisDiv4,.upload-resume-wrapper .shrTooltip, #viewLog').hide();
				$('.continueAnalyze').css({
					'visibility':'visible',
					'z-index': '205'
				});
				// $('#resume_upload').css('left','1000px');
				$('.upload-btn').css('visibility','hidden');
				//二开字段隐藏
				$('#_resumeAnalysisDiv5,#_resumeAnalysisDiv6').hide();
				$("#recuritmentDemand").shrPromptBox("enable");
				$("#interRecommendation").shrPromptBox("enable");
				$("#resumeSource").shrPromptBox("enable");
				$("#sourceType").shrSelect("enable");
			}
			if(lastAffirm){
				$('.minimize-analysis').hide();
				$('.some-resume').removeClass('some-resume-result');
				$('.result').hide();
				// $('#resume_upload').css('left','0px');
				$('.upload-btn').css('visibility','visible');
				$('#_resumeAnalysisDiv,#_resumeAnalysisDiv2,#_resumeAnalysisDiv3,#_resumeAnalysisDiv4,.shrTooltip, #viewLog').show();
				$('#_resumeAnalysisDiv5,#_resumeAnalysisDiv6').show();
			}
		},
		getAnalysisProgress: function() {
			that.remoteCall({
				method: 'getSmartImportTaskSchedule',
				param: {
					taskId: taskId
				},
				success: function(res) {
					var data = res.data
					if (res.code !== '0') {
						return false;
					}
					if(data.successDetails.length > 0){
						let  okDetails = data.successDetails;
						let  taskIds = new Array();
						//循环okDetails,并取出id
						for(let i=0;i<okDetails.length;i++){
							taskIds.push(okDetails[i].id);
						}
						that.remoteCall({
						method: 'afterSmartImportTask',
						param: {
							taskIds: taskIds.toString()
						},
						});
					}
					initCntroller.getSmartImportTaskSchedule(data);
				}
			})

			clearInterval(analysisProgressTimer);
			analysisProgressTimer = setInterval(function () {
				that.remoteCall({
					method: 'getSmartImportTaskSchedule',
					param: {
						// taskId: taskId
					},
					success: function(res) {
						var data = res.data
						if (res.code !== '0') {
							return false;
						}
						isEnd = data.isEnd;
						if(!res.data.taskState){
							res.data.taskState = [];
							res.data.taskState.value = NOT_START;
						}
						if(data.successDetails.length > 0){
							let  okDetails = data.successDetails;
							let  taskIds = new Array();
							//循环okDetails,并取出id
							for(let i=0;i<okDetails.length;i++){
								taskIds.push(okDetails[i].id);
							}
							that.remoteCall({
							method: 'afterSmartImportTask',
							param: {
								taskIds: taskIds.toString()
							},
							});
						}
						initCntroller.getSmartImportTaskSchedule(data);
					}
				})
			}, 3000);
		},
		initFileUpload: function() {
			pageUIPK = shr.getUrlRequestParam("uipk");
			var uploadUrl = shr.getContextPath() + "/dynamic.do?uipk=" + pageUIPK + "&method=uploadResume";
			$('#resume_upload').fileupload({
				url:uploadUrl,
				autoUpload:true,
				recalculateProgress:false,
				add: function(e,data) {
					console.log(data)
					var maxNumberOfFiles = 100;
					//DOC,DOCX,TXT,PDF,MSG,WPS,JPG,PNG,GIF,RTF
					var acceptFileTypes = /(\.|\/)(doc|docx|txt|pdf|msg|wps|jpg|png|gif|rtf)$/i;
					var maxSize = 1024 * 20 * 1024
					var todoAmount = parseInt($('.analysis-todo .todoAmount').text());
					var flag = true;
					if(!acceptFileTypes.test(data.files[0].name)) {
						shr.showWarning({
							message:'您上传的文件类型['+data.files[0].name+']不符合安全要求，系统不允许上传，请您上传常用office类、图片等文件',
							hideAfter:5
						});	
						flag = false;
					}
					if(maxNumberOfFiles <= todoAmount) {
						shr.showWarning({
							message:'一次解析数量不能超过' + maxNumberOfFiles + '份',
							hideAfter:3
						});	
						return false;						
					}
					if(maxSize <= data.files[0].size) {
						shr.showWarning({
							message:data.files[0].name + ' 文件超过20M',
							hideAfter:3
						});		
						flag = false;											
					}
					if(data.files[0].size==0){
						shr.showWarning({
							message:'文件内容不能为空 ',
							hideAfter:3
						});	
						return false;
					}
					if(flag){
						$('#startAnalyze, #clearResumeList').removeAttr('disabled').removeClass('disabled');

						$('.todoAmount').text(todoAmount + 1);
						$('.resumeAmount').text(data.files.length);
						var targetIdVal = '';
						if(!$('#_resumeAnalysisDiv').is(':hidden')){
							var val = $("#recuritmentDemand").shrPromptBox("getValue");
							if(val){
								targetIdVal = '&targetId=' + encodeURIComponent(val.id);
							}
						}
						var uploadUrl = shr.getContextPath() + "/dynamic.do?uipk=" + pageUIPK + "&method=uploadResume" + targetIdVal;
						$(this).fileupload('option', 'url', uploadUrl);
						$.block.show( {
							text : '操作中，请稍候...'
						});
						data.submit();
					}
				},
				start: function(e) {
					console.log('start');
				},
				progress: function(e, data) {
					console.log('progress')
				},
				progressall: function(e, data) {
					console.log('progressall')
					console.log(data);
				},
				done: function(e,data) {
					$('.analysis-todo-ct .resume-list').on('mouseover',function () {
						if($('#startAnalyze').hasClass('disabled')) {
							return
						}
						$(this).find('.cancel').show();
						$(this).css('border-color','#55B5EC');
					})
					$('.analysis-todo-ct .resume-list').on('mouseleave',function() {
						$(this).find('.cancel').hide();
						$(this).css('border-color','#E5E5E5');
					})

					var res = data.result;
					if(res.code == '0'){
						var data = res.data;
						taskId = data.id;
						analyzeTodoList.unshift(data.nonExecuteDetails[0]);
						analysisModal.compileResumeList('inputcontainer', { resumes: analyzeTodoList });
					}else{
						shr.showWarning({
							message: res.mesg,
							hideAfter: 3
						})
						$.block.hide();
                        $('.todoAmount').text(parseInt($('.analysis-todo .todoAmount').text()) - 1);
						return;
					}
					if(parseFloat($('.analysis-todo .todoAmount').text()) == analyzeTodoList.length){
						$.block.hide();
					}
				}
			});
		},
		createResumeAnalysisTask: function (cb) {
			var _this = this
			that.remoteCall({
				method: 'createResumeAnalysisTask',
				param: {},
				success: function(res) {
					if (res.code === '0') {
						taskId = res.data.id;
						cb()
					} else {
						cb()
					}
				}
			})
		},
		initPage: function() {
			var _this = this
			_this.initSourceTypeSelect();
			
			$('#resumeInput-modal').draggable();
			// $('#resumeInput-modal').modal({backdrop:"static"});	//单击背景弹框不关闭，但弹框会默认打开，所以要写在弹框打开之前的位置
			_this.getAnalysisProgress();

		},
		initSourceTypeSelect: function(){
			if($('#sourceType').attr('ctrlrole')) return false;
			var opts = [{
				alias: "主动搜索",
				value: "1",
			},{
				alias: "主动投递",
				value: "2",
			},{
				alias: "推荐/竞聘",
				value: "3",
			}]
			$('#sourceType').shrSelect({
				'id': 'sourceType',
                'data':opts,	//选项
                'value': '',	//默认选中项
                'onChange':function(){
					//设置来源类型
					shr.remoteCall({
						method: 'setSmartImportChooseSourceType',
						param: {
							targetId: $("#sourceType").shrSelect('getValue').value
						},
						success: function(res) {
							console.log(res);
						}
					})
				}
			})
			$('#sourceType').bind("keyup.shrSelect", function( event ) {
				if(event.keyCode == 8 || event.keyCode == 46) {
					$('#sourceType').trigger('change');
				}
			})
		},
		addEventListener: function() {
			// 关闭简历解析对话框
			$('#closeAnalyze, #closeAnalyzeDialog').die('click').live('click',analysisModal.close);
			// 最小化
			$('.min').die('click').live('click',analysisModal.minimize);
			// 解析状态切换
			$('.analysis-tab button').die('click').live('click', function() {
				analysisModal.analysisTab(this);
			} ); 				           
			// 清空待解析简历
			$('#clearResumeList').die('click').live('click',analysisModal.clearTodo);
			// 开始解析
			$('#startAnalyze').die('click').live('click',function() {
				analysisModal.startAnalyze();
			});
			// 查看解析结果
			$('.check-result').die('click').live('click',function() {
				analysisModal.checkResult(this);
			});
			// 继续添加，解析简历
			$('.continueAnalyze').die('click').live('click',function() {
				$('.continueAnalyze').css({
					'visibility':'hidden',
					'z-index': '1'
				});
				// $('#resume_upload').css('left','0px');
				$('.upload-btn').css('visibility','visible');
				$('#_resumeAnalysisDiv,#_resumeAnalysisDiv2,#_resumeAnalysisDiv3,#_resumeAnalysisDiv4,,#_resumeAnalysisDiv5,#_resumeAnalysisDiv6,.upload-resume-wrapper .shrTooltip, #viewLog').show();

				$('.result').hide();
				$('.some-resume').removeClass('some-resume-result');
				$('.analysis-progress,.modal-header .min').hide();
                if(lastTaskId !=null && lastTaskId !="") {//确认智能导入结果最近导入任务不为空
                    analysisModal.lastAffirmChange();
                }
				// $('#resume_upload').click();//根据最新需求，继续添加只切换页签，不上传简历
			});
			// 清空失败简历
			$('#clearFailedResume').die('click').live('click',analysisModal.clearFailed);
			// 重新解析
			$('#restartUpload').die('click').live('click',analysisModal.restartAnalyze);
			// 关闭
			// $('#resumeInput-modal').on('hidden.bs.modal', analysisModal.init);
			// 最大化
			$('#resumeInput-modal').die('click').live('show.bs.modal',function(){
				isDialogShow = true;
				$('#resumeInput-modal').removeClass('hide');
				$('.minimize-analysis').hide();
			});
			// 最小化状态下展示进度详情
			$('.progress-ball').die('click').live('click',minimizeBall.toggleExpansion);
			// 最小化时点击最大化按钮
			$('.maximize-icon').on('click',minimizeBall.maximize);
			// 单条删除简历
			$('.cancel').die('click').live('click',analysisModal.deleteResume);
			$('#viewLog').die('click').live('click',function(){
				var uipk = '';
				if(pageUIPK == 'com.kingdee.shr.recuritment.resumeScreening'){
					uipk = 'com.kingdee.shr.recuritment.app.SmartImportTask.resume.list';
				}else if(pageUIPK == 'com.kingdee.shr.recuritment.talentPool'){
					uipk = 'com.kingdee.shr.recuritment.app.SmartImportTask.archives.list';
				}else if(pageUIPK == 'com.kingdee.shr.recuritment.app.RecommendRecord.list'){
				    uipk = 'com.kingdee.shr.recuritment.app.SmartImportTask.recommendResume.list';
				}else if(pageUIPK == 'com.kingdee.shr.recuritment.app.ResumeBaseRec.selfUploadDemand.list'){
                    uipk = 'com.kingdee.shr.recuritment.app.ResumeBaseRec.selfUploadResume.list';
                }else if(pageUIPK == 'com.kingdee.shr.recuritment.app.ResumeBaseRec.selfUploadEnterPriseArchives.list'){
					uipk = 'com.kingdee.shr.recuritment.app.ResumeBaseRec.selfUploadEnterPrise.list';
				}
				var params ={
					uipk: uipk
				};
				var url = shr.getContextPath() + shr.dynamicURL + '?' + $.param(params)+ "&inFrame=true";
				window.open(url,'_blank');
			});
		}
	}
		
	return {
			init: function() {
				initCntroller.initFileUpload();
				initCntroller.initPage();
				initCntroller.addEventListener();
			}
	}
}
