/**
 * 修改增加客户信息
 * */
var indexNum = 0;
$(function() {

	laydate.render({
		elem: '#customer_handoverDate',
		theme: '#1ab394',
		calendar: true
	});
	
	laydate.render({
		elem: '#customer_feeExpires',
		theme: '#1ab394',
		calendar: true
	});

	//获取所属部门 
	getDepts('customerTreeView', 'customer_bedept')
		.then(function() {
			var edit_id = helper.request.queryString("edit_id");
			if (edit_id) {
				getCustomer(edit_id);
			}
			//绑定验证(所有 input.form-control)
			$('#tab_user_contents').find("input[class='form-control']").on('blur keyup', valideInput);
		});

});

//获取客户详情
function getCustomer(ids) {
	$.getJSON(huayi.config.callcenter_url + "CustomerNew/GetCustomer", {
		cusid: ids, //客户id
		token: $.cookie("token")
	}, function(data) {
		if (data.state.toLowerCase() == "success") {
			$('#contactLists').hide();
			var cusBase = data.data.CustomerBase;
			$('#customer_bedept').val(data.data && data.data.BeDeptName); // int 客户归属部门
			if (cusBase) {
				// $('#customer_key').val(cusBase.F_KeyWords); //string 关键词	
				$('#customer_code').val(cusBase.F_CustomerCode); //string 客户编号
				$('#customer_companyname').val(cusBase.F_CompanyName); //string 公司名称
				$('#customer_comaddress').val(cusBase.F_CompanyAddress); //string 公司地址
				$('#customer_legalName').val(cusBase.F_LegalName); //string 法人姓名
				$('#customer_lehalTel').val(cusBase.F_LegalTel); //string 法人电话
				$('#customer_subtrade').val(cusBase.F_SubTrade); // int 所属行业
				$('#customer_taxCategory').val(cusBase.F_TaxCategory); // int 税务类别
				$('#customer_taxPointDes').val(cusBase.F_TaxPointDes); //string 税点描述
				$('#customer_invoiceRange').val(cusBase.F_InvoiceRange); //string 开票范围
				$('#customer_layer').val(cusBase.F_Layer); // int 客户信誉等级
				$('#customer_bedept').attr('data-id', cusBase.F_BeDept); // int 客户归属部门
				$('#customer_berelatedAcc').val(cusBase.F_BeRelatedAcc); //string 客户归属涉税会计
				$('#customer_beauditAcc').val(cusBase.F_BeAuditAcc); //string 客户归属审核会计
				$('#customer_bemakeAcc').val(cusBase.F_BeMakeAcc); //string 客户归属做账会计

				$('#customer_RegisteredAddress').val(cusBase.F_RegisteredAddress); // string 注册地址
				$('#customer_LegalIDCards').val(cusBase.F_LegalIDCards); // string 法人身份证
				$('#customer_Qualification').val(cusBase.F_Qualification); // string 企业资质荣誉
				$('#customer_FinancialManager').val(cusBase.F_FinancialManager); // string 客户公司财务负责人
				$('#customer_BusinessOwner').val(cusBase.F_BusinessOwner); // string 客户归属业务负责人
				$('#customer_Remark1').val(cusBase.F_Remark1); // string 备注1（输入框即可）
				$('#customer_Remark2').val(cusBase.F_Remark2); // string 备注2（输入框即可）
				$('#customer_Remark3').val(cusBase.F_Remark3); // string 备注3（输入框即可）

				$('#customer_service').val(cusBase.F_CusService); // string 客服
				$('#customer_handoverDate').val(cusBase.F_HandoverDate); // string 交接日期
				$('#customer_isbankSlips').find('input[type="radio"][value="' + cusBase.F_ISBankSlips + '"]').prop('checked',
					true); // string 是否需要去银行拿回单（一般纳税人）
				$('#customer_address').val(cusBase.F_Address); // string 联系地址
				$('#customer_address1').val(cusBase.F_Address); // string 联系地址1
				$('#customer_address2').val(cusBase.F_Address1); // string 联系地址2
				$('#customer_address3').val(cusBase.F_Address2); // string 联系地址3
				$('#customer_address4').val(cusBase.F_Address3); // string 联系地址4
				$('#customer_feeExpires').val(cusBase.F_FeeExpires && cusBase.F_FeeExpires.split(' ')[0]); // datetime	代理费到期日期


				$('#customer_code').trigger('blur');
			}
			/* var cusLists = data.data.ContactList;
			if (cusLists && cusLists.length > 0) {
				for (var i = 0; i < cusLists.length; i++) {
					var tplstr = '';
					tplstr = '<div class="contactList_item col-md-offset-2 clearfix">' +
						'<div class="form-group col-md-5 col-sm-5">' +
						'<div class="input-group">' +
						'<span class="input-group-addon">联系人姓名</span>' +
						'<input id="F_Name_' + i + '" type="text" class="form-control" value="' + cusLists[i].F_Name +
						'" placeholder="请输入联系人姓名" aria-describedby="联系人姓名">' +
						'</div>' +
						'</div>' +
						'<div class="form-group col-md-5 col-sm-5">' +
						'<div class="input-group">' +
						'<span class="input-group-addon">联系人电话</span>' +
						'<input id="F_Telephone_' + i + '" value="' + cusLists[i].F_Telephone +
						'" type="text" class="form-control" placeholder="请输入联系人电话" aria-describedby="联系人电话">' +
						'</div>' +
						'</div>' +
						'<div class="form-group col-md-5 col-sm-5">' +
						'<div class="input-group">' +
						'<span class="input-group-addon">联系人邮箱</span>' +
						'<input id="F_Email_' + i + '" value="' + cusLists[i].F_Email +
						'" type="text" class="form-control" placeholder="请输入联系人邮箱" aria-describedby="联系人邮箱">' +
						'</div>' +
						'</div>' +
						'<div class="form-group col-md-5 col-sm-5">' +
						'<div class="input-group">' +
						'<span class="input-group-addon">联系人职务</span>' +
						'<input id="F_Duties_' + i + '" value="' + cusLists[i].F_Duties +
						'" type="text" class="form-control" placeholder="请输入联系人职务" aria-describedby="联系人职务">' +
						'</div>' +
						'</div>' +
						'<div class="form-group col-md-5 col-sm-5">' +
						'<div class="input-group">' +
						'<span class="input-group-addon">联系人QQ</span>' +
						'<input id="F_QQ_' + i + '" value="' + cusLists[i].F_QQ +
						'" type="text" class="form-control" placeholder="请输入联系人QQ" aria-describedby="联系人QQ">' +
						'</div>' +
						'</div>' +
						'<div class="form-group col-md-5 col-sm-5">' +
						'<div class="input-group">' +
						'<span class="input-group-addon">联系人MSN</span>' +
						'<input id="F_MSN_' + i + '" value="' + cusLists[i].F_MSN +
						'" type="text" class="form-control" placeholder="请输入联系人MSN" aria-describedby="联系人MSN">' +
						'</div>' +
						'</div>' +
						'<div class="form-group col-md-10 col-sm-10">' +
						'<div class="input-group">' +
						'<span class="input-group-addon">联系人备注</span>' +
						'<input id="F_Remark_' + i + '" value="' + cusLists[i].F_Remark +
						'" type="text" class="form-control" placeholder="请输入联系人备注" aria-describedby="联系人备注">' +
						'</div>' +
						'</div>' +
						'<div class="form-group col-md-5 col-sm-5">' +
						'<div class="input-group">' +
						'<span class="input-group-addon">是否主要联系人</span>' +
						'<div class="isMain" id="F_IsMain_' + i + '">' +
						'<label class="radio-inline">' +
						'<input type="radio" name="inlineOptions_' + i + '" value="true"> 是' +
						'</label>' +
						'<label class="radio-inline">' +
						'<input type="radio" name="inlineOptions_' + i + '" value="false"> 否' +
						'</label>' +
						'</div>' +
						'</div>' +
						'</div>' +
						'<button class="form-control btn btn-default" style="width:60px;margin-left:15px" onclick="btn_delete($(this))">删除</button>' +
						'</div>';
					$('#contactList').prepend(tplstr);
					$('#F_IsMain_' + i).find('input[type="radio"][value="' + cusLists[i].F_IsMain +'"]').prop('checked', true);
					
				}
				indexNum = cusLists.length;
			} */
		}
	});
}

//保存
function saveCustomer() {
	
	var contactList = $('#contactList').find('.contactList_item');
	for (var i = 0; i < contactList.length; i++) {
		var F_Name = $(contactList[i]).find('input[id*="F_Name_"]').val();
		var F_Telephone = $(contactList[i]).find('input[id*="F_Telephone_"]').val();
		var F_Email = $(contactList[i]).find('input[id*="F_Email_"]').val();
		var F_Duties = $(contactList[i]).find('input[id*="F_Duties_"]').val();
		var F_QQ = $(contactList[i]).find('input[id*="F_QQ_"]').val();
		var F_MSN = $(contactList[i]).find('input[id*="F_MSN_"]').val();
		if (!regexs.chOrenOrnum.test($.trim(F_Name))) {
			layer.confirm('您添加的联系人姓名格式不正确（只能输入中文、英文、数字）！', {
				icon: 2,
				btn: ['确定']
			});
			return;
		}
		if (!regexs.phone.test($.trim(F_Telephone))) {
			layer.confirm('您添加的联系人电话号码格式不正确！', {
				icon: 2,
				btn: ['确定']
			});
			return;
		}
		if (F_Email && !regexs.email.test($.trim(F_Email))) {
			layer.confirm('您添加的联系人邮箱格式不正确！', {
				icon: 2,
				btn: ['确定']
			});
			return;
		}
		if (F_Duties && !regexs.chOrenOrnum.test($.trim(F_Duties))) {
			layer.confirm('您添加的联系人职务格式不正确！', {
				icon: 2,
				btn: ['确定']
			});
			return;
		}
		if (F_QQ && !regexs.QQreg.test($.trim(F_QQ))) {
			layer.confirm('您添加的联系人QQ格式不正确！', {
				icon: 2,
				btn: ['确定']
			});
			return;
		}
		if (F_MSN && !regexs.chOrenOrnum.test($.trim(F_MSN))) {
			layer.confirm('您添加的联系人MSN格式不正确！', {
				icon: 2,
				btn: ['确定']
			});
			return;
		}
	}
	var wURL, loadIndex, contactLists;
	var edit_id = helper.request.queryString("edit_id");
	if (edit_id) {
		wURL = "CustomerNew/Update";
		contactLists = null;
	} else {
		wURL = "CustomerNew/Add";
		contactLists = getFields();
	}
	$.ajax({
		type: 'post',
		url: huayi.config.callcenter_url + wURL,
		dataType: 'json',
		async: true,
		beforeSend: function() { //触发ajax请求开始时执行
			$('#save_btns').attr("disabled", true);
			$('#save_btns').text('保存中...');
			loadIndex = layer.load();
		},
		data: {
			F_CustomerId: edit_id, //	否	string	id
			// F_KeyWords: $('#customer_key').val(), //string 关键词	
			F_CustomerCode: $('#customer_code').val(), //string 客户编号
			F_CompanyName: $('#customer_companyname').val(), //string 名称
			F_CompanyAddress: $('#customer_address').val(), //string 地址
			F_LegalName: $('#customer_legalName').val(), //string 姓名
			F_LegalTel: $('#customer_lehalTel').val(), //string 电话
		
			
				
			token: $.cookie("token")
		},
		success: function(data) {
			layer.close(loadIndex);
			if (data.state === "success") {
				var index = parent.layer.getFrameIndex(window.name);
				parent.layer.close(index);
				parent.$('#cusList').bootstrapTable('refresh');
				parent.layer.msg("保存成功");
			} else {
				$('#save_btns').attr("disabled", false);
				$('#save_btns').text('保存');
			}
		},
		error: function(textStatus) {
			layer.close(loadIndex);
			layer.confirm('网络繁忙，请稍后再试...', {
				icon: 7,
				closeBtn: 0,
				btn: ['确定'] //按钮
			});
			$('#save_btns').attr("disabled", false);
			$('#save_btns').text('保存');
		},
		complete: function(XMLHttpRequest, textStatus) {
			layer.close(loadIndex);
			if (textStatus == 'timeout') {
				var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
				xmlhttp.abort();
				layer.confirm('网络超时，请稍后再试...', {
					icon: 7,
					closeBtn: 0,
					btn: ['确定'] //按钮
				});
			}
			$('#save_btns').attr("disabled", false);
			$('#save_btns').text('保存');
		},
	});
}

//添加联系人
function btn_add() {
	var tplstr = '';
	tplstr = '<div class="contactList_item col-md-offset-2 clearfix">' +
		'<div class="form-group col-md-5 col-sm-5">' +
		'<div class="input-group">' +
		'<span class="input-group-addon">联系人姓名</span>' +
		'<input id="F_Name_' + indexNum +
		'" type="text" class="form-control" placeholder="请输入联系人姓名" aria-describedby="联系人姓名">' +
		'</div>' +
		'</div>' +
		'<div class="form-group col-md-5 col-sm-5">' +
		'<div class="input-group">' +
		'<span class="input-group-addon">联系人电话</span>' +
		'<input id="F_Telephone_' + indexNum +
		'" type="text" class="form-control" placeholder="请输入联系人电话" aria-describedby="联系人电话">' +
		'</div>' +
		'</div>' +
		'<div class="form-group col-md-5 col-sm-5">' +
		'<div class="input-group">' +
		'<span class="input-group-addon">联系人邮箱</span>' +
		'<input id="F_Email_' + indexNum +
		'" type="text" class="form-control" placeholder="请输入联系人邮箱" aria-describedby="联系人邮箱">' +
		'</div>' +
		'</div>' +
		'<div class="form-group col-md-5 col-sm-5">' +
		'<div class="input-group">' +
		'<span class="input-group-addon">联系人职务</span>' +
		'<input id="F_Duties_' + indexNum +
		'" type="text" class="form-control" placeholder="请输入联系人职务" aria-describedby="联系人职务">' +
		'</div>' +
		'</div>' +
		'<div class="form-group col-md-5 col-sm-5">' +
		'<div class="input-group">' +
		'<span class="input-group-addon">联系人QQ</span>' +
		'<input id="F_QQ_' + indexNum + '" type="text" class="form-control" placeholder="请输入联系人QQ" aria-describedby="联系人QQ">' +
		'</div>' +
		'</div>' +
		'<div class="form-group col-md-5 col-sm-5">' +
		'<div class="input-group">' +
		'<span class="input-group-addon">联系人MSN</span>' +
		'<input id="F_MSN_' + indexNum +
		'" type="text" class="form-control" placeholder="请输入联系人MSN" aria-describedby="联系人MSN">' +
		'</div>' +
		'</div>' +
		'<div class="form-group col-md-10 col-sm-10">' +
		'<div class="input-group">' +
		'<span class="input-group-addon">联系人备注</span>' +
		'<input id="F_Remark_' + indexNum +
		'" type="text" class="form-control" placeholder="请输入联系人备注" aria-describedby="联系人备注">' +
		'</div>' +
		'</div>' +
		'<div class="form-group col-md-5 col-sm-5">' +
		'<div class="input-group">' +
		'<span class="input-group-addon">是否主要联系人</span>' +
		'<div class="isMain" id="F_IsMain_' + indexNum + '">' +
		'<label class="radio-inline">' +
		'<input type="radio" name="inlineOptions_' + indexNum + '" value="true"> 是' +
		'</label>' +
		'<label class="radio-inline">' +
		'<input type="radio" name="inlineOptions_' + indexNum + '" value="false" checked="checked"> 否' +
		'</label>' +
		'</div>' +
		'</div>' +
		'</div>' +
		'<button class="form-control btn btn-default" style="width:60px;margin-left:15px" onclick="btn_delete($(this))">删除</button>' +
		'</div>';
	$('#contactList').prepend(tplstr);
	indexNum++;
}

//删除联系人
function btn_delete(el) {
	el.parent().remove();
}

//获取联系人信息
function getFields() {
	var goodslists = [];
	var goodsLists_items = $('#contactList').find('.contactList_item');
	$.each(goodsLists_items, function(i, v) {
		goodslists.push({
			"F_Name": $(v).find('input[id*="F_Name_"]').val(),
			"F_Telephone": $(v).find('input[id*="F_Telephone_"]').val(),
			"F_Email": $(v).find('input[id*="F_Email_"]').val(),
			"F_Duties": $(v).find('input[id*="F_Duties_"]').val(),
			"F_QQ": $(v).find('input[id*="F_QQ_"]').val(),
			"F_MSN": $(v).find('input[id*="F_MSN_"]').val(),
			"F_Remark": $(v).find('input[id*="F_Remark_"]').val(),
			"F_IsMain": $(v).find('div[id*="F_IsMain_"]').find('input[type="radio"]:checked').val(),
		});
	});
	//去重
	// helper.methods.uniqueObjArray(goodslists, 'F_Name');
	return goodslists;
}


/**
 * 获取客户归属部门
 * el1, 树形结构元素id名 customerTreeView
 * el2, 搜索框元素id名 customer_bedept
 * */
function getDepts(el1, el2) {
	var dtd = $.Deferred(); //在函数内部，新建一个Deferred对象
	//初始化 样式
	$('#' + el2).on('focus click', function() {
		$('#' + el1).removeClass('hidden').addClass('show');
	});
	$('#' + el2).on('keyup', function() {
		if ($(this).val() == '') {
			$('#' + el1).treeview('uncheckAll', {
				silent: true
			});
			$(this).attr('data-id', '0');
		}
	});
	$('#' + el2 + ' .caret').on('click', function() {
		$('#' + el1).removeClass('hidden').addClass('show');
	});
	$('#' + el1).mouseleave(function() {
		$(this).removeClass('show').addClass('hidden');
	});

	$.getJSON(huayi.config.callcenter_url + 'Department/GetDeptList', {
		token: $.cookie("token")
	}, function(result) {
		if (result.state.toLowerCase() == "success") {
			var defaultDatas = helper.methods.buildTree(result.data);
			var sortChildrenArr = helper.methods.objToArray(defaultDatas[0].children);
			sortChildrenArr.sort(helper.methods.compare('sort'));
			var sortChildrenObj = helper.methods.arrayToObj(sortChildrenArr);
			defaultDatas[0].children = sortChildrenObj;
			if (defaultDatas) {
				var $sTree = $('#' + el1).treeview({
					color: "#1ab394",
					selectedBackColor: '#1ab394',
					expandIcon: 'glyphicon glyphicon-chevron-right',
					collapseIcon: 'glyphicon glyphicon-chevron-down',
					nodeIcon: 'fa fa-folder-o',
					//selectedIcon: "glyphicon glyphicon-stop",
					//icon: "glyphicon glyphicon-stop",
					//emptyIcon: 'glyphicon',
					//showCheckbox: true,
					selectable: true,
					state: {
						selected: true
					},
					data: defaultDatas,
					onNodeSelected: function(event, node) {
						$sTree.treeview('clearSearch');
						$('#' + el2).val(node.text);
						$('#' + el2).attr('data-id', node.id);
						$('#' + el1).removeClass('show').addClass('hidden');
					},
					onNodeUnselected: function(event, node) {
						$('#' + el2).attr('data-id', 0);
						$('#' + el2).attr('placeholder', '请选择客户归属部门');
					}
				});
				//				$('#' + el1).treeview('collapseAll', {
				//					silent: true
				//				});
				$('#' + el1).treeview('expandAll', {
					levels: 2,
					silent: true
				});
				var findSNodes = function() {
					return $sTree.treeview('search', [$('#' + el2).val(), {
						ignoreCase: false,
						exactMatch: false
					}]);
				};
				$('#' + el2).on('keyup focus', function(e) {
					var selectableNodes = findSNodes();
					//var m = $('#' + el1).treeview('getParent', selectableNodes);
					//$('#' + el1).treeview('selectNode', [ m, { silent: true } ]);
				});
			}
			dtd.resolve(); // 改变Deferred对象的执行状态
		}
	})
	return dtd.promise(); // 返回promise对象
}


//验证(所有 input.form-control)的方法
function valideInput() {
	var _that = $(this);
	//console.log($(this).attr('id'));
	switch ($(this).attr('id')) {
		case 'customer_code': //验证客户编号
			valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', false);
			break;
		case 'customer_companyname': //验证公司名称
			valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', false);
			break;
		case 'customer_legalName': //验证法人姓名
			valideMethods(_that, regexs.userNameReg, '格式不正确(只能输入2-20位汉字可以包含·•)！', true);
			break;
		case 'customer_lehalTel': //验证法人电话
			valideMethods(_that, regexs.phone, '您输入的电话号码格式不正确！', true);
			break;
		case 'customer_subtrade': //验证所属行业
			valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
			break;
		case 'customer_taxCategory': //验证 税务类别
			valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
			break;
		// case 'customer_invoiceRange': //验证 开票范围
		// 	valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
		// 	break;
		case 'customer_layer': //验证 客户信誉等级
			valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
			break;
		case 'customer_berelatedAcc': //客户归属涉税会计
			valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
			break;
		case 'customer_beauditAcc': //客户归属审核会计
			valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
			break;
		case 'customer_bemakeAcc': //客户归属做账会计
			valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
			break;
		// case 'customer_RegisteredAddress': //注册地址
		// 	valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
		// 	break;
		case 'customer_LegalIDCards': //法人身份证
			valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
			break;
		case 'customer_Qualification': //企业资质荣誉
			valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
			break;
		case 'customer_FinancialManager': //客户公司财务负责人
			valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
			break;
		case 'customer_BusinessOwner': //客户归属业务负责人
			valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
			break;
		// case 'customer_Remark1': //备注1
		// 	valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
		// 	break;
		// case 'customer_Remark2': //备注2
		// 	valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
		// 	break;
		// case 'customer_Remark3': //备注3
		// 	valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
		// 	break;
		case 'customer_service': //客服
			valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
			break;
		// case 'customer_address': //地址
		// 	valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
		// 	break;
		// case 'customer_address1': //地址1
		// 	valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
		// 	break;
		// case 'customer_address2': //地址2
		// 	valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
		// 	break;
		// case 'customer_address3': //地址3
		// 	valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
		// 	break;
		// case 'customer_address4': //地址4
		// 	valideMethods(_that, regexs.chOrenOrnum, '格式不正确（只能输入中文、英文、数字）！', true);
		// 	break;
	}
	if ($('#tab_user_contents').find('.has-error').length > 0) {
		$('.project_save').attr('disabled', true);
		$('#save_btns').off('click', saveCustomer);
	} else {
		$('.project_save').attr('disabled', false);
		$('#save_btns').off('click', saveCustomer);
		$('#save_btns').on('click', saveCustomer);
	}
}
/**
 * 验证方法
 * _this :传递的this
 * regRlues: 验证的规则
 * msg: 提示信息
 * isRes:boolean 是否允许验证的内容为空，true:允许为空，false:不允许为空
 * */
function valideMethods(_this, regRlues, msg, isRes) {
	var txtTpips = _this.parent().parent().find('.text-tips');
	if (txtTpips) {
		txtTpips.parent().remove();
	}
	if (!isRes) {
		//不为空
		if (!regRlues.test($.trim(_this.val()))) {
			_this.parent().parent().removeClass('has-success has-feedback').addClass('has-error has-feedback');
			_this.parent().find('.glyphicon').remove();
			$('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>').appendTo(_this.parent());
			$('<div class="col-md-10 col-md-offset-2"><span class="text-tips">' + msg + '</span></div>').appendTo(_this.parent()
				.parent());
			$('.project_save').attr('disabled', true);
		} else {
			_this.parent().parent().removeClass('has-error has-feedback').addClass('has-success has-feedback');
			_this.parent().find('.glyphicon').remove();
			$('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>').appendTo(_this.parent());
		}
	} else {
		//为空不验证；但是有内容就验证；
		if ($.trim(_this.val())) {
			if (!regRlues.test($.trim(_this.val()))) {
				_this.parent().parent().removeClass('has-success has-feedback').addClass('has-error has-feedback');
				_this.parent().find('.glyphicon').remove();
				$('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>').appendTo(_this.parent());
				$('<div class="col-md-10 col-md-offset-2"><span class="text-tips">' + msg + '</span></div>').appendTo(_this.parent()
					.parent());
				$('.project_save').attr('disabled', true);
			} else {
				_this.parent().parent().removeClass('has-error has-feedback').addClass('has-success has-feedback');
				_this.parent().find('.glyphicon').remove();
				$('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>').appendTo(_this.parent());
			}
		} else {
			_this.parent().find('.glyphicon').remove();
			_this.parent().parent().removeClass('has-error has-success has-feedback');
		}
	}
}
