var cjqt = {
	// 模糊搜索
	search_fuzzy: {
		event_input: function (_this, attrName, liClassName, contextPath, ajaxPath,option) {
			// option = {
			// 	_this: '',           		当前dom节点对象
			// 	type: 1,             		1:项目 2:企业 3:部门
			// 	org_target: '',      		项目对象
			// 	com_target: '',      		企业对象
			// 	dep_target: ''       		部门对象
			// 	org_attrName: 'org__id',    项目属性名称
			// 	com_attrName: 'com__id',    企业属性名称
			// 	dep_attrName: 'dep__id',  	部门属性名称
			// 	org_spanName: 'org__span',  项目span类名
			//	com_spanName: 'com__span',  企业span类名
			//	dep_spanName: 'dep__span',  部门span类名
			// }
			// 
			// 先清空
			_this.attr(attrName, '')
			var obj = {}
			var _option = $.extend(true,{}, option);
			var type = _option.type || '1' 
			if(type == 1){
				obj = {
					orgName: _this.val() || ''
				}
				$(_option.com_target).attr(_option.com_attrName, '').val('')
				$(_option.dep_target).attr(_option.dep_attrName, '').val('')
			}else if(type == 2){
				var orgId = $(_option.org_target).attr(_option.org_attrName)
				if(!orgId){
					layer.msg('项目不允许为空');
					return
				}
				obj = {
					orgId: orgId,
					virName: _this.val() || ''
				}
				$(_option.dep_target).attr(attrName, '').val('')
			}else if(type == 3){
				var orgId = $(_option.org_target).attr(_option.org_attrName)
				var virId = $(_option.com_target).attr(_option.com_attrName)
				if(!orgId){
					layer.msg('项目不允许为空');
					return
				}else if(!virId){
					layer.msg('企业不允许为空');
					return
				}
				obj = {
					orgId: orgId,
					virId: virId,
					deptName: _this.val() || ''
				}
			}
			// 设置定时器检测用户输入时间
			if (typeof (delayClock) != "undefined") {
				clearTimeout(delayClock);
			}
			delayClock = setTimeout(function () {
				$.ajax({
					url: contextPath + ajaxPath,
					type: "POST",
					dataType: "json",
					data: obj,
					success: function (data) {
						if(data.code == 200 && data.data){
							var dataArr = data.data
							var html = ''
							if (dataArr.length) {
								_this.parent().find('.select_wrap').show()
								$.each(dataArr, function (index, el) {
									var meetCode = el.meetCode || ''
									html += '<span class="' + liClassName + '" id="' + el.id + '" meetCode="' + meetCode + '">'
									html += el.name
									html += '</span>'
								});
								_this.parent().find('.select_wrap').empty().append(html)
							} else {
								_this.parent().find('.select_wrap').empty().hide()
							}
						}else{
							layer.msg(data.msg);
						}
						
					}
				});
			}, 300);
			//回调
			var input_callback = _option.input_callback || ''
			if(input_callback && (typeof input_callback == 'function')){
				option.input_callback()
			}
		},
		event_focus: function (_this, attrName, liClassName, contextPath, ajaxPath, option) {
			var obj = {}
			var _option = $.extend(true, {}, option);
			var type = _option.type || '1' 
			if(type == 1){
				obj = {
					orgName: _this.val() || ''
				}
			}else if(type== 2){
				var orgId = $(_option.org_target).attr(_option.org_attrName)
				if(!orgId){
					layer.msg('项目不允许为空');
					return
				}
				obj = {
					orgId: orgId,
					virName: _this.val() || ''
				}
			}else if(type == 3){
				var orgId = $(_option.org_target).attr(_option.org_attrName)
				var virId = $(_option.com_target).attr(_option.com_attrName)
				if(!orgId){
					layer.msg('项目不允许为空');
					return
				}else if(!virId){
					layer.msg('企业不允许为空');
					return
				}
				obj = {
					orgId: orgId,
					virId: virId,
					deptName: _this.val() || ''
				}
			}
			// 清除定时器检
			if (typeof (delayClock) != "undefined") {
				clearTimeout(delayClock);
			}
			closeClock = setTimeout(function () {
				$.ajax({
					url: contextPath + ajaxPath,
					type: "POST",
					dataType: "json",
					data: obj,
					success: function (data) {
						if(data.code == 200 && data.data){
							var dataArr = data.data
							var html = ''
							if (dataArr.length) {
								_this.parent().find('.select_wrap').show()
								$.each(dataArr, function (index, el) {
									var meetCode = el.meetCode || ''
									html += '<span class="' + liClassName + '" id="' + el.id + '" meetCode="' + meetCode + '">'
									html += el.name
									html += '</span>'
								});
								_this.parent().find('.select_wrap').empty().append(html)
							} else {
								_this.parent().find('.select_wrap').empty().hide()
							}
						}else{
							layer.msg(data.msg);
						}
					},
					error: function(err){

					}
				});
			},300)
		},
		event_blur: function (_this, attrName, option) {
			var _option = $.extend(true, {}, option);
			var type = _option.type || '1'
			var blur_callback = _option.blur_callback || ''
			// 清除定时器检
			if (typeof (delayClock) != "undefined") {
				clearTimeout(delayClock);
			}
			// 如果值或者attrName不存在则都清空
			closeClock = setTimeout(function () {
				var name = _this.val()
				var id = _this.attr(attrName)
				if (!(name && id)) {
					_this.val('')
					_this.removeAttr('value')
					_this.attr(attrName, '')
					if(type == 1){
						$(_option.com_target).attr(attrName, '').val('')
						$(_option.dep_target).attr(attrName, '').val('')
					}else if(type == 2){
						$(_option.dep_target).attr(attrName, '').val('')
					}
				}
				$('.select_wrap').empty().hide()
				if(blur_callback && (typeof blur_callback == 'function')){
					option.blur_callback()
				}
			}, 200)
		},
		event_click: function (_this, attrName, target,option,callback,__this) {
			console.log('this:',_this)
			var _option = $.extend(true, {}, option);
			var _Id = _this[0].id
			var _Name = _this[0].innerText
			var _MeetCode= $(_this).attr('meetCode') || ''
			var click_callback = _option.click_callback || ''
			_this.parent('.select_wrap').parent().find(target).val(_Name).attr(attrName,_Id).attr('meetCode',_MeetCode);
			callback && callback(_Id,__this);
			_this.parent('.select_wrap').empty().hide()
			$(target).attr(attrName,_Id)
			if(click_callback && (typeof click_callback == 'function')){
				option.click_callback()
			}
		},
		event_initial: function (_this, attrName, liClassName, contextPath, ajaxPath,option) {
			// 先清空
			_this.attr(attrName, '')
			var obj = {}
			var _option = $.extend(true,{}, option);
			var type = _option.type || '1' 
			if(type == 1){
				obj = {
					orgName: _this.val() || '',
					"conditions[companyId]": localStorage.getItem("companyId")
				}
				$(_option.com_target).attr(_option.com_attrName, '').val('')
				$(_option.dep_target).attr(_option.dep_attrName, '').val('')
			}
			// 设置定时器检测用户输入时间
			if (typeof (delayClock) != "undefined") {
				clearTimeout(delayClock);
			}
			delayClock = setTimeout(function () {
				$.ajax({
					url: contextPath + ajaxPath,
					type: "POST",
					dataType: "json",
					data: obj,
					success: function (data) {
						if(data.code == 200 && data.data){
							var dataArr = data.data
							var html = ''
							if (dataArr.length) {
								// _this.parent().find('.select_wrap').show()
								_this.val(dataArr[0].label).attr('org__id',dataArr[0].value).attr('meetCode',dataArr[0].meetCode);
								$('#conditionform  .search-btn').click();
								$.each(dataArr, function (index, el) {
									var meetCode = el.meetCode || ''
									html += '<span class="' + liClassName + '" id="' + el.value + '" meetCode="' + meetCode + '">'
									html += el.label
									html += '</span>'
								});
								_this.parent().find('.select_wrap').empty().append(html);


							} else {
								_this.parent().find('.select_wrap').empty().hide()
							}
						}else{
							layer.msg(data.msg);
						}
						
					}
				});
			}, 300);
			//回调
			var input_callback = _option.input_callback || ''
			if(input_callback && (typeof input_callback == 'function')){
				option.input_callback()
			}
		},
		event_initial_focus: function (_this, attrName, liClassName, contextPath, ajaxPath, option) {
			var obj = {}
			var _option = $.extend(true, {}, option);
			var type = _option.type || '1' 
			if(type == 1){
				obj = {
					orgName: _this.val() || ''
				}
			}
			// 清除定时器检
			if (typeof (delayClock) != "undefined") {
				clearTimeout(delayClock);
			}
			closeClock = setTimeout(function () {
				$.ajax({
					url: contextPath + ajaxPath,
					type: "POST",
					dataType: "json",
					data: obj,
					success: function (data) {
						if(data.code == 200 && data.data){
							var dataArr = data.data
							var html = ''
							if (dataArr.length) {
								_this.parent().find('.select_wrap').show()
								$.each(dataArr, function (index, el) {
									var meetCode = el.meetCode || ''
									html += '<span class="' + liClassName + '" id="' + el.value + '" meetCode="' + meetCode + '">'
									html += el.label
									html += '</span>'
								});
								_this.parent().find('.select_wrap').empty().append(html)
							} else {
								_this.parent().find('.select_wrap').empty().hide()
							}
						}else{
							layer.msg(data.msg);
						}
					},
					error: function(err){

					}
				});
			},300)
		}
	},
	// 模糊搜索项目、企业、部门
	search_vague: {
		event_input: function (_this, attrName, liClassName, contextPath, ajaxPath,type ,orgId, virId) {
			var param = {};
			if (!orgId) {
				var orgName = _this.val();
				param.orgName = orgName;
			} else if (orgId && !virId) {
				var virName = _this.val();
				param.virName = virName;
				param.orgId = orgId;
			} else {
				var deptName = _this.val();
				param.deptName = deptName;
				param.orgId = orgId;
				param.virId = virId;
			}
			// 把id清空
			_this.attr(attrName, '')
			// 设置定时器检测用户输入时间
			if (typeof (delayClock) != "undefined") {
				clearTimeout(delayClock);
			}
			delayClock = setTimeout(function () {
				$.ajax({
					url: contextPath + ajaxPath,
					type: "POST",
					dataType: "json",
					data: param,
					success: function (data) {
						var dataArr = data.data
						var html = ''
						if (dataArr.length) {
							_this.parent().find('.select_wrap').show()
							$.each(dataArr, function (index, el) {
								var meetCode = el.meetCode || ''
								html += '<span class="' + liClassName + '" id="' + el.id + '" meetCode="' + meetCode + '">'
								html += el.id + '-' + el.name
								html += '</span>'
							});
							_this.parent().find('.select_wrap').empty().append(html)
						} else {
							_this.parent().find('.select_wrap').empty().hide()
						}
					}
				});
			}, 300);
		},
		event_focus: function (_this, attrName, liClassName, contextPath, ajaxPath,type, orgId, virId) {
			var param = {};
			if (!orgId) {
				var orgName = _this.val();
				param.orgName = orgName;
			} else if (orgId && !virId) {
				var virName = _this.val();
				param.virName = virName;
				param.orgId = orgId;
			} else {
				var deptName = _this.val();
				param.deptName = deptName;
				param.orgId = orgId;
				param.virId = virId;
			}
			$.ajax({
				url: contextPath + ajaxPath,
				type: "POST",
				dataType: "json",
				data: param,
				success: function (data) {
					var dataArr = data.data
					var html = ''
					if (dataArr.length) {
						_this.parent().find('.select_wrap').show()
						$.each(dataArr, function (index, el) {
							var meetCode = el.meetCode || ''
							html += '<span class="' + liClassName + '" id="' + el.id + '" meetCode="' + meetCode + '">'
							html += el.name
							html += '</span>'
						});
						_this.parent().find('.select_wrap').empty().append(html)
					} else {
						_this.parent().find('.select_wrap').empty().hide()
					}
				}
			});
		},
		event_blur: function (_this, attrName,type) {
			// 清除定时器检
			if (typeof (delayClock) != "undefined") {
				clearTimeout(delayClock);
			}
			// 如果值或者attrName不存在则都清空
			closeClock = setTimeout(function () {
				var name = _this.val()
				var id = _this.attr(attrName)
				if (!(name && id)) {
					_this.val('')
					_this.removeAttr('value')
					_this.attr(attrName, '')
				}
				$('.select_wrap').hide()
			}, 200)
		},
		event_click: function (_this, attrName, target,type) {
			var $elem; 
			type == 1 ? $elem = $('body #conditionform') : $elem = $('body .dialog-wp');
			var id = _this[0].id
			var name = _this[0].innerText
			_this.parent('.select_wrap').parent().find(target).val(name).attr(attrName, id)
			_this.parent('.select_wrap').empty().hide()
			if(target == "#orgId"){
				$elem.find("#companyId").val('');
				$elem.find("#companyId").attr("company__id", '')
				$elem.find("#apartId").val('');
				$elem.find("#apartId").attr("apart__id", '')
			}else if(target == "#companyId"){
				$elem.find("#apartId").val('');
				$elem.find("#apartId").attr("apart__id", '')
			}
		}
	}
}