var getNode = function(id){
	return document.getElementById(id)
}
var yuyue = getNode("yuyue")
var share = getNode("share")
var modal = getNode("zy-h5-modal")
var modalZz = getNode("zy-h5-fix-z")
var submitModal = getNode("submitModal")
var canselModal = getNode("canselModal")
var userPhone = getNode("userPhone")
// test,  测试     local:本地     pre ：预发布      pro：生产
if(baseType == 'test'){
	var reqUrl = 'http://192.168.16.100:9110/saas/clz/'
}else if(baseType == 'local'){
	var reqUrl = 'http://127.0.0.1:9110/saas/clz/'
}else if(baseType == 'pre'){
	var reqUrl = 'http://md.test.zyucgj.com/saas/clz/'
}else if(baseType == 'pro'){
	var reqUrl = 'http://md.chelingzhu.com/saas/clz/'
}
// 隐藏预约弹框
var closeYy = function (){
	userPhone.value = ''
	modal.style.display = 'none'
	modalZz.style.display = 'none'
}
window.onload = function(){
	
	getActivityData()
	//  获取活动信息
	function getActivityData(){
		//  获取活动信息 （海报和门店二维码）
		$.ajax({
			url: reqUrl + 'active/findActiveAttach/' + acitveId,
			type: 'get',
			header: {
				contentType: 'application/json;charset=UTF-8',
			},
			// 设置的是请求参数
			data: {},
			dataType: 'json',
			success: function (res) {
				if(res.status == 200){
					const data = res.data
					if(staticHtmlPath){  //  发布
						const joinerNum = parseInt(data.initBuyNum) + parseInt(data.joinerNum)
						document.getElementById('joinerNum').innerHTML = joinerNum
					}
				}
			},
		})
	}
	// 打开预约弹框
	yuyue.onclick = function(){
		modal.style.display = 'block'
		modalZz.style.display = 'block'
	}
	// 关闭预约弹框
	canselModal.onclick = function(){
		closeYy()
	}
	// 提交预约
	submitModal.onclick = function(){
		// 提交代码到后台
		var mobile = userPhone.value
		if(mobile==''){
			alert("请输入手机号码");
			return false; 
		}
		if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(mobile))){ 
			alert("手机号码错误，请重填");  
			return false; 
		}
		
		const obj = JSON.stringify({
			"joinerMobile": mobile,
			"activeId": acitveId,
		})
		//  立即参与
		$.ajax({
			url: reqUrl + 'active/signUp',
			type: 'post',
			contentType: 'application/json;charset=UTF-8',
			// 设置的是请求参数
			data: obj,
			dataType: 'json',
			success: function (res) {
				console.log(res)
				if(res.status == 200){
					closeYy()
				}
				alert(res.message)
			}
		})
	}
	// 分享
	share.onclick = function(){
		window.location.href = 'http://static.chelingzhu.com/active/poster.html?id=' + acitveId + '&reqUrl=' + reqUrl
	}
}