Skip to content

Instantly share code, notes, and snippets.

@peter279k
Created July 24, 2020 03:55
Show Gist options
  • Save peter279k/150e9de08ba28f63a6304303004a8311 to your computer and use it in GitHub Desktop.
Save peter279k/150e9de08ba28f63a6304303004a8311 to your computer and use it in GitHub Desktop.
$( document ).ready(function() {
console.log( "ready!" );
let line_userid = "";
$('input[name="idtype"]')[0].checked = true; // 預設為身份證字號
liff.init({
liffId: "1552207375-1xDKJLe5"
})
.then(() => {
// Start to use liff's api
liff.getProfile()
.then(profile => {
line_userid = profile.userId;
})
.catch((err) => {
//alert('getProfile error', err);
});
})
.catch((LiffError) => {
// Error happens during initialization
//alert(err.code, err.message);
});
$("#twzipcode").twzipcode( {
zipcodeIntoDistrict: false
});
$("#btn_save").click(function(){
$("#btn_save").prop('disabled', true);
var uname = $("#uname").val();
var uidentity_card = $("#uidentity_card").val();
var uphone = $("#uphone").val();
var uagree = "n";
var idtype = $("input[name='idtype']:checked").val();
var recaptcha = "";
if ($("#uagree").is(":checked")) {
uagree = "y";
}
// if (line_userid == "") {
// swal({
// text: "非由 Line@入口進入,無法執行此功能。",
// type: "warning"
// }).then(function() {
// $("#btn_save").prop('disabled', false);
// $("#waitBox").html("");
// });
// return;
// }
if ($("#uname").val() == "") {
swal({
text: "請輸入姓名。",
type: "warning"
}).then(function() {
$("#uname").focus();
$("#btn_save").prop('disabled', false);
$("#waitBox").html("");
});
return;
}
/*
if (isPureChinese($("#uname").val()) == false) {
swal({
text: "姓名請輸入中文。",
type: "warning"
}).then(function() {
$("#uname").focus();
$("#btn_save").prop('disabled', false);
$("#waitBox").html("");
});
return;
}
*/
if ($("#uidentity_card").val() == "") {
if (idtype == "1") {
swal({
text: "請輸入身份證號碼。",
type: "warning"
}).then(function() {
$("#uidentity_card").focus();
$("#btn_save").prop('disabled', false);
$("#waitBox").html("");
});
return;
} else if (idtype == "2") {
swal({
text: "請輸入居留證號碼。 ",
type: "warning"
}).then(function() {
$("#uidentity_card").focus();
$("#btn_save").prop('disabled', false);
$("#waitBox").html("");
});
return;
}
}
if ($("#uphone").val() == "") {
swal({
text: "請輸入行動電話。",
type: "warning"
}).then(function() {
$("#uphone").focus();
$("#btn_save").prop('disabled', false);
$("#waitBox").html("");
});
return;
}
var county = $("#twzipcode").twzipcode('get', 'county');
var district = $("#twzipcode").twzipcode('get', 'district');
if (county == "") {
swal({
text: "請選取縣市。",
type: "warning"
}).then(function() {
$("#btn_save").prop('disabled', false);
$("#waitBox").html("");
});
return;
}
if (district == "") {
swal({
text: "請選取區/鄉鎮。",
type: "warning"
}).then(function() {
$("#btn_save").prop('disabled', false);
$("#waitBox").html("");
});
return;
}
if (uagree == "n") {
swal({
text: "請同意免責聲明",
type: "warning"
}).then(function() {
$("#btn_save").prop('disabled', false);
$("#waitBox").html("");
});
return;
}
swal({
title: "請確認以下資訊",
html: "敬請留意您所留的手機號碼,以免影響權益<br>是否確定送出?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "是",
cancelButtonText: "否"
})
.catch (swal.noop)
.then((willDelete) => {
if (willDelete) {
$("#waitBox").html("<h4>資料送出中請稍候... <img id='wgif' src='"+contextPath+"images/ajax-loader.gif' /></h4>");
// var formdata = new FormData();
// formdata.append("city", county);
// formdata.append("dist", district);
// formdata.append("name", uname);
// formdata.append("phone", uphone);
// formdata.append("idtype", idtype);
// formdata.append("identity_card", uidentity_card);
// formdata.append("line_userid", line_userid);
// formdata.append("recaptcha", recaptcha);
var formdata = {
"city": county,
"dist": district,
"name": uname,
"phone": uphone,
"idtype": idtype,
"identity_card": uidentity_card,
"line_userid": line_userid,
"recaptcha": recaptcha
}
$.ajax({
url: "https://369.pdis.tw/useregister",
type: 'POST',
// url: "./useregister",
// type: 'GET',
dataType: "json",
contentType: "application/json;charset=utf-8",
data: JSON.stringify(formdata),
processData:false,
success: function(rdata, status, xhr){
if (rdata == "200") {
$("#btn_save").hide();
$("#waitBox").html("");
swal({
html: "登錄成功<br>本活動於7月29日下5時前抽籤並公布得獎名單,抽籤結果將另行發送,敬請留意您所留的手機號碼,便於聯繫。<br>&nbsp;<br>注意:客委會保留隨時可修改、終止或變更本活動之權利,若有其他未盡事宜,悉依本會相關規定或解釋為準。",
type: "success"
}).then(function() {
liff.closeWindow();
$("#twzipcode").twzipcode('reset');
$("#uname").val('');
$("#uidentity_card").val('');
$("#uphone").val('');
$('input[name="idtype"]')[0].checked = true; // 預設為身份證字號
$('#uagree').prop('checked', false);
$("#btn_save").prop('disabled', false);
});
} else if (rdata == "501") {
$("#waitBox").html("");
swal({
text: "手機檢核失敗。",
type: "error"
}).then(function() {
$("#btn_save").prop('disabled', false);
});
} else if (rdata == "502") {
$("#waitBox").html("");
if (idtype == "1") {
swal({
text: "身份證號碼檢核失敗。",
type: "error"
}).then(function() {
$("#btn_save").prop('disabled', false);
});
} else if (idtype == "2") {
swal({
text: "居留證號碼檢核失敗。",
type: "error"
}).then(function() {
$("#btn_save").prop('disabled', false);
});
}
} else if (rdata == "503") {
$("#waitBox").html("");
if (idtype == "1") {
swal({
text: "身份證號碼或手機號碼或此Line帳號已有註冊資料。",
type: "error"
}).then(function() {
$("#btn_save").prop('disabled', false);
});
} else if (idtype == "2") {
swal({
text: "居留證號碼或手機號碼或此Line帳號已有註冊資料。",
type: "error"
}).then(function() {
$("#btn_save").prop('disabled', false);
});
}
}
},
error: function(){
console.log("ajax fail");
$("#waitBox").html("");
swal({
html: "登錄成功<br>本活動於7月29日下5時前抽籤並公布得獎名單,抽籤結果將另行發送,敬請留意您所留的手機號碼,便於聯繫。<br>&nbsp;<br>注意:客委會保留隨時可修改、終止或變更本活動之權利,若有其他未盡事宜,悉依本會相關規定或解釋為準。",
type: "success"
}).then(function() {
$("#twzipcode").twzipcode('reset');
$("#uname").val('');
$("#uidentity_card").val('');
$("#uphone").val('');
$('input[name="idtype"]')[0].checked = true; // 預設為身份證字號
$('#uagree').prop('checked', false);
$("#btn_save").prop('disabled', false);
});
},
complete: function(XMLHttpRequest, textStatus) {
$("#btn_save").prop('disabled', false);
$("#waitBox").html("");
}
});
} else {
//alert("no");
$("#btn_save").prop('disabled', false);
}
});
})
function isPureChinese(input) {
var reg = /^[\u4E00-\u9FA5]+$/
if (reg.test(input)) {
return true
} else {
return false
}
}
$("#aaaaa").click(function() {
$("#waitBox").html("<h4>資料送出中請稍候... <img id='wgif' src='"+contextPath+"images/ajax-loader.gif' /></h4>");
})
$("#btest").click(function() {
swal({
title: "請確認以下資訊",
text: "敬請留意您所留的手機號碼,以免影響權益",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "是",
cancelButtonText: "否"
})
.catch (swal.noop)
.then((willDelete) => {
if (willDelete) {
//location.href = contextPath + "mgr/logout";
} else {
//alert("no");
$("#btn_save").prop('disabled', false);
}
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment