$(document).ready(function(){
type2StoreAddressTemp = "";
$("#Main_Form").fromsAuth({type:'NONE'});
$(document).ready(function(){
default_country_id = $("#default_country_id").val();
default_city_id = $("#default_city_id").val();
default_area_id = $("#default_area_id").val();
default_address = $("#default_address").val();
default_full_address = $("#default_full_address").val();
shipType = $("input[name='Ship_Type']:checked");
if(shipType.length > 0) {
let Send_Address = $("#Send_Address")
delType = shipType.attr("data-type");
$("span[id^='ShipType-']").each(function() {
$(this).hide().find("input:text,input:hidden,input:checked,select,textarea").attr("fun","");
});
if(delType == '2'){
Send_Address.attr("disabled",true);
type2StoreAddressTemp = $("#Send_Address").val();
if(!$("#Store_Name").text().trim()) {
Send_Address.val("")
type2StoreAddressTemp = "";
chooseStore(shipType.val())
}else{
chooseStore(shipType.val(), true)
}
} else {
Send_Address.attr("disabled",false);
}
$("#ShipType-"+delType).show().find("input:text,input:hidden,input:checked,select,textarea").attr("fun","checkNull");
}
addressDisplay();
});
//選擇發票類型
$(document).on("change", ".invoice-radio", function(){
let _this = $(this)
radioVal = _this.val()
$(".invoice-box").addClass("hide")
$(".invoice-box[data-invoice=" + radioVal + "]").removeClass("hide")
invoCheck(radioVal)
});
//選擇運送方式
$(document).on("change", ".ship-type", function(){
let _this = $(this)
radioVal = _this.val()
type = _this.attr("data-type")
$("span[id^='ShipType-']").each(function() {
$(this).hide().find("input:text,input:hidden,input:checked,select,textarea").attr("fun","");
$(this).find(".forms_show").attr("error",false);
$(this).find(".forms_show").html("");
});
if(type == '2'){
console.log("selectStore")
$("#Send_Address").attr("disabled",true);
$("#Send_Address").val("");
$("#Ship_Data").val("");
$("#Store_Name").text("");
chooseStore(radioVal);
}else if(type == '1'){
document.getElementById('Address_Country_ID').value=default_country_id;
document.getElementById('Address_City_ID').value=default_city_id;
document.getElementById('Address_Area_ID').value=default_area_id;
$("#Send_Address").val(default_address);
}else if(type == '3'){ //只有地址
$("#Send_Address").val(default_full_address);
}
if(type != '2') $("#Send_Address").attr("disabled",false);
$("#ShipType-"+type).show().find("input:text,input:hidden,input:checked,select,textarea").attr("fun","checkNull");
});
$("#Btn_Sign").on('click', function() {
if($("#Sign_Flag").val() != '1') {
alert("請先登入會員");
window.location.href = Project_Country+$("#Website_Mall_ID").val()+"/member-login/";
} else {
document.getElementById('eventSignup').scrollIntoView();
}
});
//刷新驗證圖片
$("#Change_Pic").click(function(e){
$("#Checkspan").load(Project_Country+'ajax/ajax_get_check_pic.php',{change:1});
});
//發票載具
$("#CarrierType").on('change', function(){
if($(this).val()>1){
$(".invo_code").show().find("input").attr("fun","checkNull");
}else{
$(".invo_code").hide().find("input").attr("fun","");
}
if($(this).val() == '2') {
$("#CarrierId1").attr("placeholder", "請輸入/+7碼英文數字");
$("#CarrierId1").attr("nullstr", "請輸入/+7碼英文數字");
$("#CarrierId1").attr("errorstr", "請輸入/+7碼英文數字");
$("#CarrierId1").attr("fun", "checkInvo");
$("#CarrierId1").val($("#D_CarrierID").val());
$("#CarrierId2").attr("placeholder", "請輸入/+7碼英文數字");
$("#CarrierId2").attr("nullstr", "請輸入/+7碼英文數字");
$("#CarrierId2").attr("fun", "checkInvo");
$("#CarrierId2").attr("errorstr", "請輸入/+7碼英文數字");
$("#CarrierId2").val($("#D_CarrierID").val());
} else {
$("#CarrierId1").attr("placeholder", "確認載具條碼");
$("#CarrierId1").attr("nullstr", "確認載具條碼");
$("#CarrierId1").attr("errorstr", "");
$("#CarrierId1").attr("fun", "");
$("#CarrierId1").val("");
$("#CarrierId2").attr("placeholder", "確認載具條碼");
$("#CarrierId2").attr("nullstr", "確認載具條碼");
$("#CarrierId2").attr("fun", "");
$("#CarrierId2").attr("errorstr", "");
$("#CarrierId1").val("");
}
});
$("#Choose_Store").on("click", function(){
updatePage();
window.location.href = Project_Country+'event/e_returns/emap-p.php?url=event-sign/&type='+$(this).attr("type")+'&coll='+$(this).attr("coll");
});
//國別
$('.select-group-address').each(function(){
let _this = $(this)
addressDisplay()
})
$(document).on('change', '.country-id', function(){
let the_sub = $("#Address_City_ID");
default_country_id = $("#Address_Country_ID").val();
$.ajax({
type: "POST",
url: Project_Country+"ajax/ajax_get_city-p.php",
data: "&Send_ID=" + $(this).val(),
async: false,
dataType: 'json',
error:function(d){
alert('網路連線過慢,網頁請重新整理');
},
success: function(jsonObj){
the_sub.children("option:gt(0)").remove();
for(k in jsonObj){
the_sub.append('');
}
}
});
addressDisplay();
});
$(document).on('change', '.city-id', function(){
let the_sub = $('#Address_Area_ID');
default_city_id =$("#Address_City_ID").val();
$.ajax({
type: "POST",
url: Project_Country+"ajax/ajax_get_area-p.php",
data: "&Send_ID=" + $(this).val(),
async: false,
dataType: 'json',
error:function(d){
alert('網路連線過慢,網頁請重新整理');
},
success: function(jsonObj){
the_sub.children("option:gt(0)").remove();
for(k in jsonObj.area){
the_sub.append('');
}
}
});
addressDisplay();
});
$(document).on('change', '.area-id', function(){
default_area_id = $("#Address_Area_ID").val();
addressDisplay();
});
//手機驗證
$(document).on('change','#Send_Cellphone',function(e){
$.ajax({
type: "POST",
url: Project_Country+"event/ajax/ajax_check_repeat-p.php",
data: "&Cellphone=" + $("#Send_Cellphone").val()+"&Event_Data_ID="+$("#ID").val()+"&Email="+$("#P_Email").val(),
async: false,
dataType: 'json',
error:function(d){
alert('網路連線過慢,網頁請重新整理');
},
success: function(jsonObj){
if(jsonObj.status != 'success') {
alert(jsonObj.message);
$(".forms_show[for='Send_Cellphone']").text(jsonObj.message);
}
}
});
});
$(document).on('change','#P_Email',function(e){
$.ajax({
type: "POST",
url: Project_Country+"event/ajax/ajax_check_repeat-p.php",
data: "&Cellphone=" + $("#Send_Cellphone").val()+"&Event_Data_ID="+$("#ID").val()+"&Email="+$("#P_Email").val(),
async: false,
dataType: 'json',
error:function(d){
alert('網路連線過慢,網頁請重新整理');
},
success: function(jsonObj){
if(jsonObj.status != 'success') {
alert(jsonObj.message);
$(".forms_show[for='P_Email']").text(jsonObj.message);
}
}
});
});
//送出
$("#Main_Form").on('click',"#Form_Submit",function(){
$.ajax({
type: "POST",
url: Project_Country+"event/ajax/ajax_check_repeat-p.php",
data: "&Cellphone=" + $("#Send_Cellphone").val()+"&Event_Data_ID="+$("#ID").val()+"&Email="+$("#P_Email").val(),
async: false,
dataType: 'json',
error:function(d){
alert('網路連線過慢,網頁請重新整理');
},
success: function(jsonObj){
if(jsonObj.status == 'success') {
shipType = $("input[name='Ship_Type']:checked");
if(shipType.length > 0) {
delType = shipType.attr("data-type");
if(delType == 2 || delType == 6) {
if($("#ShipType-"+delType).find("#Ship_Data").val().length == 0) {
alert($("#ShipType-"+delType).find("#Ship_Data").attr("nullstr"));
return false;
}
}
}
$("#Main_Form").submit();
} else {
alert(jsonObj.message);
return false;
}
}
});
});
function addressDisplay(){
shipType = $("input[name='Ship_Type']:checked");
chk = true;
if(shipType.length > 0) {
delType = shipType.attr("data-type");
if(delType != 1) {
chk = false;
}
}
if(chk) {
let country = $('.country-id'),
area = $('.area-id'),
city = $('.city-id'),
address_type = country.find('option:selected').attr('address-type');
if(address_type == 3){
city.hide();
city.attr('fun', '');
area.hide();
area.attr('fun', '');
}
else if(address_type == 2){
city.show();
city.attr('fun', 'checkNull');
area.hide();
area.attr('fun', '');
}
else if(typeof(address_type) != 'undefined') {
city.show();
city.attr('fun', 'checkNull');
area.show();
area.attr('fun', 'checkNull');
}
}
}
})
function invoCheck($no){
for($i=1;$i<=3;$i++){
let invoiceBox = $(".invoice-box[data-invoice="+$i+"]")
if($i != $no){
invoiceBox.find("input,select").attr("fun","");
}else{
if($i == 1 && $("#CarrierType").val() == 1){
invoiceBox.find("select").attr("fun","checkNull");
}else{
invoiceBox.find("input,select").attr("fun","checkNull");
if($i==3) {
invoiceBox.find("#Invo_Email").attr("fun","checkEmail");
}
}
}
}
};
function chooseStore($shipType, scrollFlag = false) {
$.ajax({
url:Project_Country+"event/ajax/ajax_choose_store.php",
type:"POST",
cache:false,
async:false,
data:{ship_type:$shipType},
dataType:"json",
error:function(d){
alert('網路連線過慢,網頁請重新整理');
},
success:function(d){
$("#Choose_Store").attr("type",d.Service);
if(scrollFlag){
$(document).scrollTop($('#Send_Address').offset().top - 500)
}
}
});
};
function updatePage(){
$(".loading").show();
var $member = "";
var $invo = "";
$("#Event_Sign_Data").find("input:text,input:hidden,input:checked,select,textarea").each(function(){
$member += '&'+$(this).attr("name")+'='+$(this).val();
});
if($("#SubmitCheck").val().length > 0) {
$member += '&SubmitCheck='+$("#SubmitCheck").val();
}
$.ajax({
url:Project_Country+"event/ajax/ajax_event_update.php",
type:"POST",
cache:false,
async:false,
data:$member,
error:function(d){
alert('網路連線過慢,網頁請重新整理');
},
success:function(d){
console.log(d);
$(".loading").fadeOut();
}
});
}