Files
du_an_khach_hang/Chico/PC/user.js

172 lines
4.8 KiB
JavaScript
Raw Normal View History

2023-03-31 10:53:25 +07:00
<!-- CUSTOMER -->
// CHECK FORM RESIGTER
function check_field_registor() {
var error = "";
var email = document.getElementById("email").value;
if (ValidateEmail(email)) error += ValidateEmail(email);
var password = document.getElementById("password").value;
if (password.length < 6) error += "- Mật khẩu quá yếu\n";
var full_name = document.getElementById("full_name").value;
if (full_name.length < 2) error += "- Mời bạn nhập đúng tên\n";
var mobile = document.getElementById("tel").value;
if (mobile.length < 9) error += "- Mời bạn nhập đúng số điện thoại\n";
var address = document.getElementById("address").value;
if (address.length < 6) error += "- Mời bạn nhập địa chỉ\n";
var pass = $("#password").val();
var pass1 = $("#password1").val();
if (pass1 != pass) {
error += "- Mật khẩu không trùng khớp. Xin vui lòng nhập lại!";
}
if (error != "") {
alert(error);
return false;
} else {
var registerParams = {
action_type: "register",
info: {
email: email,
name: full_name,
tel: mobile,
mobile: mobile,
birthday: "",
password: password,
address: address,
},
};
Hura.Ajax.post("customer", registerParams).then(function (data) {
//console.log(data);
if (data.status == "error" && data.message == "Email exist") {
alert("Email đã được đăng ký \n Vui lòng nhập lại! ");
} else {
alert("Bạn đã đăng ký thành công! Chuyển tiếp sang Đăng nhập.");
location.href = "/dang-nhap";
}
});
}
}
// CHECK FORM LOGIN
function check_login() {
var error = "";
var email = document.getElementById("email").value;
if (ValidateEmail(email)) error += ValidateEmail(email);
var password = document.getElementById("password").value;
if (password.length == 0)
error += "- Bạn cần nhập mật khẩu để đăng nhập \n";
if (error != "") {
alert(error);
return false;
} else {
Hura.User.login(email, password).then(function (data) {
//console.log(data);
if (data.status == "error") {
alert(data.message);
} else {
alert("Đăng nhập thành công!");
location.href = "/taikhoan";
}
});
}
}
// CHECK VALIDATION EMAIL
function ValidateEmail(emailValue) {
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (emailValue.length < 6) return "- Mời bạn nhập email!\n";
else if (!emailValue.match(mailformat))
return "- Email không chính xác, vui lòng nhập lại\n";
}
// TOGGLE SHOW PASSWORD
function show_hide_pass(password) {
var x = $(password).parents(".item").find(".input-pass").attr("type");
if (x === "password") {
$(password).parents(".item").find(".input-pass").attr("type", "text");
} else {
$(password).parents(".item").find(".input-pass").attr("type", "password");
}
}
// FORGOT PASSWORD
function forgotPassword(){
var email = document.getElementById('email_register').value
Hura.Ajax.customPost("/ajax/reset_password_request.php", {email: email}).then(function(data){
//console.log(data) ;
$("#js-mess").html(data.message)
})
}
var customerOrderTpl = `
<tr align="center">
<td>
<a href="?view=order-detail&id={%= item.orderId %}" style="color: #214186"
>#{%= item.orderId %}
<span class="red-bold" style="display: block">(Xem chi tiết)</span>
</a>
</td>
<td>{%= item.orderDate %}</td>
<td align="left">
{% for (let itemProduct of item.item_list) { %}
<a
href="{%= itemProduct.item_info.productUrl %}"
style="display: block; font-weight: 500; margin-bottom: 4px"
>
- {%= itemProduct.item_info.productName %}
</a>
{% } %}
</td>
<td class="red-bold" style="white-space: nowrap">
{%= parseInt(item.totalValue).toLocaleString() %}
<u>đ</u>
</td>
<td align="center">
{% if (item.status_id === "0") { %}
<span>Đang xử </span>
{% } %}
</td>
</tr>
`;
{% endraw %}
// RENDER CUSTOMER ORDER LIST
function getOrderList() {
Hura.Ajax.post("account", { action_type: "recent-order" }).then(function (
order_list
) {
//console.log(order_list);
if (order_list.length > 0) {
var html = Hura.Template.parse(customerOrderTpl, order_list);
Hura.Template.render("#js-customer-order", html);
} else {
$(".order-page").html(`<p>Bạn chưa có đơn hàng nào!</p>`);
}
});
}