mui.init({
	beforeback: function() { //获得父页面的webview
		var list = plus.webview.currentWebview().opener(); //触发父页面的自定义事件(refresh),从而进行刷新
		mui.fire(list, 'reload');
		//返回true,继续页面关闭逻辑
		return true;
	}
});
mui.plusReady(function() {
	var self = plus.webview.currentWebview();
	var hhrrzid = self.id ? self.id : 0;
	//console.log(hhrrzid);
	if (hhrrzid > 0) {
		$('.header .title').html("编辑合伙人认证信息")
		$('#home_zhezhao').hide();

		JZL.ajax(qlgUrl('app/auth/getAuthFamilyPersonalInfo'), {
			id: hhrrzid
		}, function(data) {
			// //console.log(data);
			if (data.status == 1) {
				var data = data.data
				$('#userName').val(data.familyName);
				$('#cardId').val(data.familyIdCard);
				$('#familyRelations').val(data.familyRelations);
				// var html='<img data-src="' +data.familyRelationsImg + '" src="' + hyhImgUrl(data.familyRelationsImg)+ '" />';
				$("#familyRelationsImg").val(data.familyRelationsImg)
				$("#idCardFrontImg").val(data.idCardFrontImg)
				$("#idCardBackImg").val(data.idCardBackImg)

				$("#familyRelationsimg").attr("src", hyhImgUrl(data.familyRelationsImg))
				$("#idCardBack").attr("src", hyhImgUrl(data.idCardBackImg))

				$("#idCardFront").attr("src", hyhImgUrl(data.idCardFrontImg))
			}else{
				mui.alert(data.msg)
			}
		})
	} else {
		$('.header .title').html("添加合伙人认证信息")
	}

	$('.lxy_home_zz ul').on('tap', function(e) {
		e.preventDefault();
		e.stopPropagation()
	})
	var wait = 120;

	function time() {
		if (wait == 0) {
			$('.HQYZM').removeAttr("disabled");
			$('.HQYZM').val("重新发送");
			wait = 120;
		} else {
			$('.HQYZM').attr("disabled", true);
			$('.HQYZM').val("重新发送(" + wait + ")");
			wait--;
			setTimeout(function() {
					time()
				},
				1000)
		}
	}
	mui('.lxy_home_zz ul').on('tap', '.HQYZM', function() {
		var pargams = {}
		pargams.userPhone = $('#indiv-tel').val();
		if ('' == pargams.userPhone) {
			mui.alert('手机号不能为空！');
			return;
		}
		if (!(
				/^134[0-8]\d{7}$|^13[^4]\d{8}$|^14[5-9]\d{8}$|^15[^4]\d{8}$|^16[6]\d{8}$|^17[0-8]\d{8}$|^18[\d]{9}$|^19[8,9]\d{8}$/
				.test(pargams.userPhone))) {
			mui.alert("手机号码有误，请重填!");
			return;
		}

		JZL.ajax(qlgUrl('app/auth/getPartnerPhoneCode'), pargams, function(data) {
			data = toJson(data);
			//console.log(data)
			if (data.status == 1) {
				telephoneNo = pargams.userPhone;
				time();
			} else {
				mui.alert(data.msg);
			}
		});
	})
	var click = 0;

	mui('.lxy_home_zz ul').on('tap', '.lxy_zz_btn', function() {
		if (1 == click) return
		click = 1
		var pargams = {}
		pargams.userPhone = $('#indiv-tel').val();
		pargams.mobileCode = $('.YZM').val();
		if ('' == pargams.mobileCode) {
			mui.alert('请输入验证码！');
			return;
		}
		JZL.ajax(qlgUrl('app/auth/getAuthInfoByMobile'), {
			mobileCode: pargams.mobileCode
		}, function(data) {
			//console.log(data);
			if (data.status == 1) {
				var data = data.data;
				$('#home_zhezhao').hide();

				$('#familyName').val(data.uName);
				$('#familyIdCard').val(data.idCard);
			}else{
				mui.alert (data.msg)
			}
		})
	
	})
	$(".photos_con").on("tap", '.business', function() {
		UP.init("businessImg", "test", "business")
		openCamera();
	})
	$(".photos_con").on("tap", '.idCardFront', function() {
		UP.init("idCardFrontImg", "test", "idCardFront")
		openCamera();
	})
	$(".photos_con").on("tap", '.idCardBack', function() {
		UP.init("idCardBackImg", "test", "idCardBack")
		openCamera();
	})


var bcclick = 0
	$(".bc_btn").on('tap',function() {
		if (bcclick == 1) return;
		bcclick = 1;
		var pargams = JZL.getParams('.inp');
		pargams.id = hhrrzid

		if (pargams.positionName == '') {
			mui.alert('职位名不能为空！');
			return;
		}
		if (pargams.stake == '') {
			mui.alert('持股比例不能为空！');
			return;
		}
		if (pargams.businessImg == '') {
			mui.alert('请上传手持营业执照照！');
			return;
		}
		if (pargams.idCardFrontImg == '') {
			mui.alert('请上传身份证正面照！');
			return;
		}
		if (pargams.idCardBackImg == '') {
			mui.alert('请上传身份证反面照！');
			return;
		}
	
	
		JZL.ajax(qlgUrl('app/auth/setAuthPartner'), pargams, function(data) {
			//服务器返回响应，根据响应结果，分析是否登录成功;
			//console.log(data);
			var data = toJson(data);
			if (data.status == 1) {
				mui.back();
			} else {
				mui.alert('发生错误请刷新后重试！');
				//							location.reload();
			}
		})


	})
})
