update (31/3)
This commit is contained in:
288
Chico/artilce.js
Normal file
288
Chico/artilce.js
Normal file
@@ -0,0 +1,288 @@
|
||||
|
||||
// LAZY LOADING
|
||||
lazy_load_group.push(
|
||||
{
|
||||
id: 'js-article-home',
|
||||
target: '#js-article-home',
|
||||
loadFn: function () {
|
||||
getTopAricleList();
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'js-article-small-top',
|
||||
target: '#js-article-small-top',
|
||||
loadFn: function () {
|
||||
articleTopMainSmall();
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'js-video-featured-',
|
||||
target: '#js-video-featured-',
|
||||
loadFn: function () {
|
||||
getFeaturedVideo();
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'js-new-article',
|
||||
target: '#js-new-article',
|
||||
loadFn: function () {
|
||||
getNewArticleHome();
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'js-product-hot-article',
|
||||
target: '#js-product-hot-article',
|
||||
loadFn: function () {
|
||||
productHot();
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'js-article-small-home',
|
||||
target: '#js-article-small-home',
|
||||
loadFn: function () {
|
||||
getBottomAricleList();
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'js-article-middle-right',
|
||||
target: '#js-article-middle-right',
|
||||
loadFn: function () {
|
||||
articleCatRight();
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
)
|
||||
|
||||
// SWIPER ARTICLE TOP
|
||||
function swiperArticle() {
|
||||
new Swiper(".swiper-article", {
|
||||
slidesPerView: 1,
|
||||
spaceBetween: 10,
|
||||
centeredSlides: true,
|
||||
loop: true,
|
||||
speed: 1000,
|
||||
autoplay: {
|
||||
delay: 2500,
|
||||
disableOnInteraction: false,
|
||||
pauseOnMouseEnter: "true",
|
||||
},
|
||||
pagination: {
|
||||
el: ".swiper-pagination",
|
||||
clickable: true,
|
||||
},
|
||||
navigation: {
|
||||
nextEl: ".swiper-button-next",
|
||||
prevEl: ".swiper-button-prev",
|
||||
},
|
||||
});
|
||||
}
|
||||
swiperArticle();
|
||||
|
||||
// GET ARTICLE TOP NEAR SWIPER
|
||||
function getTopAricleList() {
|
||||
var params = {
|
||||
action_type: 'list',
|
||||
type: 'article',
|
||||
featured: 1,
|
||||
show: 1
|
||||
}
|
||||
var target = "#js-article-home";
|
||||
Hura.Ajax.get("article", params).then(function (data) {
|
||||
var html = Hura.Template.parse(articleMainTop, data.list.splice(0, 3));
|
||||
Hura.Template.render(target, html);
|
||||
});
|
||||
}
|
||||
|
||||
// GET ARTICLE TOP NEAR SWIPER
|
||||
function getBottomAricleList() {
|
||||
var params = {
|
||||
action_type: 'list',
|
||||
type: 'article',
|
||||
featured: 1,
|
||||
show: 8,
|
||||
}
|
||||
var target = "#js-article-small-home";
|
||||
Hura.Ajax.get("article", params).then(function (data) {
|
||||
var html = Hura.Template.parse(articleMainBottom, data.list.splice(0,3));
|
||||
Hura.Template.render(target, html);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// GET ARTICLE COL LEFT
|
||||
function articleTopMainSmall() {
|
||||
var params = {
|
||||
action_type: 'list',
|
||||
type: 'article',
|
||||
featured: 1,
|
||||
show: 18
|
||||
}
|
||||
var target = "#js-article-small-top";
|
||||
Hura.Ajax.get("article", params).then(function (data) {
|
||||
var html = Hura.Template.parse(articleMainSmall, data.list.splice(0, 3));
|
||||
Hura.Template.render(target, html);
|
||||
});
|
||||
}
|
||||
|
||||
// GET FEATURED VIDEO
|
||||
function getFeaturedVideo() {
|
||||
var params = {
|
||||
action_type: "featured",
|
||||
type: "article",
|
||||
show: 10,
|
||||
};
|
||||
var smallTarget = "#js-video-featured-";
|
||||
Hura.Ajax.get("article", params).then(function (data) {
|
||||
var html = Hura.Template.parse(featureVideo, data.splice(0, 3));
|
||||
Hura.Template.render(smallTarget, html);
|
||||
});
|
||||
}
|
||||
|
||||
// TIN MỚI NHẤT
|
||||
function getNewArticleHome() {
|
||||
var params = {
|
||||
action_type: "featured",
|
||||
type: "article",
|
||||
show: 18,
|
||||
};
|
||||
|
||||
var target = "#js-new-article";
|
||||
Hura.Ajax.get("article", params).then(function (data) {
|
||||
var html = Hura.Template.parse(newArticle, data.splice(0, 3));
|
||||
Hura.Template.render(target, html);
|
||||
});
|
||||
}
|
||||
|
||||
// TIN TUYỂN DỤNG
|
||||
function articleCatRight() {
|
||||
var params = {
|
||||
action_type: 'list',
|
||||
type: 'article',
|
||||
catId: 5,
|
||||
};
|
||||
var target = "#js-article-middle-right";
|
||||
Hura.Ajax.get("article", params).then(function (data) {
|
||||
// console.log(data)
|
||||
var html = Hura.Template.parse(articleMiddleRight, data.list);
|
||||
Hura.Template.render(target, html);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// GET PRODUCT NEWEST
|
||||
function productHot() {
|
||||
var params = {
|
||||
action_type: "product-list",
|
||||
hotType: "saleoff",
|
||||
sort: "order",
|
||||
};
|
||||
|
||||
var target = "#js-product-hot-article";
|
||||
Hura.Ajax.get("product", params).then(function (data) {
|
||||
//console.log(data.list);
|
||||
var html = Hura.Template.parse(productHotArticle, data.list.splice(0, 5));
|
||||
Hura.Template.render(target, html);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function run_anchor() {
|
||||
var all = document.getElementById("js-find_toc").getElementsByTagName("*");
|
||||
var nodes = [];
|
||||
for(var i = all.length; i--; nodes.unshift(all[i]));
|
||||
var result = document.createElement("ol");
|
||||
buildRec(nodes, result, 2);
|
||||
|
||||
$("<div class='archor-text-group' id='js-toc_container'><div class='toc_title d-flex align-items-center justify-content-between gap-8'><b class='text-18 font-weight-700 d-flex align-items-center text-fint-toc'><img src='/static/assets/default/images/art-detial.png'><span>Nội dung chính</span></b></div><div id='js-outp'>" + result.outerHTML + "</div></div>").insertAfter('#js-first-paragraph');
|
||||
|
||||
$("#js-outp a").each(function(){
|
||||
if($(this).text().trim()!=''){
|
||||
var anchor_name = convertToSlug($(this).text());
|
||||
$(this).attr("onclick", `scrollRec('${anchor_name}')`);
|
||||
}
|
||||
});
|
||||
|
||||
setTimeout(function(){
|
||||
$("#js-toggle").click(function(){
|
||||
$(this).parents("#js-toc_container").find("#js-outp").toggle();
|
||||
});
|
||||
}, 500)
|
||||
}
|
||||
|
||||
function scrollRec(id) {
|
||||
document.getElementById(id).scrollIntoView({behavior:'smooth'});
|
||||
}
|
||||
|
||||
function buildRec(nodes, elm, lv) {
|
||||
var node;
|
||||
//console.log(elm);
|
||||
// filter
|
||||
do {
|
||||
node = nodes.shift();
|
||||
} while(node && !(/^h[123]$/i.test(node.tagName)));
|
||||
// process the next node
|
||||
if(node) {
|
||||
var ul, li, cnt;
|
||||
var curLv = parseInt(node.tagName.substring(1));
|
||||
//console.log(curLv);
|
||||
var stt = 0;
|
||||
if(curLv == lv) { // same level append an il
|
||||
cnt = 0;
|
||||
} else if(curLv < lv && 1<2) { // walk up then append il
|
||||
cnt = 0;
|
||||
do {
|
||||
elm = elm.parentNode.parentNode;
|
||||
cnt--;
|
||||
} while(cnt > (curLv - lv));
|
||||
} else if(curLv > lv) { // create children then append il
|
||||
cnt = 0;
|
||||
do {
|
||||
li = elm.lastChild;
|
||||
if(li == null)
|
||||
li = elm.appendChild(document.createElement("li"));
|
||||
elm = li.appendChild(document.createElement("ol"));
|
||||
cnt++;
|
||||
} while(cnt < (curLv - lv) && 1<2);
|
||||
}
|
||||
|
||||
li = elm.appendChild(document.createElement("li"));
|
||||
// replace the next line with archor tags or whatever you want
|
||||
li.innerHTML = '<a href="javascript:;">'+ node.innerText +'</a>';
|
||||
// recursive call
|
||||
buildRec(nodes, elm, lv + cnt);
|
||||
}
|
||||
}
|
||||
|
||||
function convertToSlug(Text){
|
||||
let newText = Text;
|
||||
return newText
|
||||
.toLowerCase()
|
||||
.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g, "a")
|
||||
.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, "e")
|
||||
.replace(/ì|í|ị|ỉ|ĩ/g, "i")
|
||||
.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g, "o")
|
||||
.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, "u")
|
||||
.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, "y")
|
||||
.replace(/đ/g, "d")
|
||||
.replace(/\u0300|\u0301|\u0303|\u0309|\u0323/g, "")
|
||||
.replace(/\u02C6|\u0306|\u031B/g, "")
|
||||
.replace(/[^\w ]+/g,'')
|
||||
.replace(/ +/g,'-')
|
||||
;
|
||||
}
|
||||
|
||||
run_anchor();
|
||||
|
||||
$("#js-find_toc h2, #js-find_toc h3").each(function(){
|
||||
if($(this).text().trim()!=''){
|
||||
var anchor_name = convertToSlug($(this).text());
|
||||
$(this).attr("id",anchor_name);
|
||||
$(this).css("scroll-margin-top","80px");
|
||||
}
|
||||
});
|
||||
|
||||
649
Chico/cart.js
Normal file
649
Chico/cart.js
Normal file
@@ -0,0 +1,649 @@
|
||||
|
||||
//Kiểm tra cú pháp Email
|
||||
function validateEmail(Email) {
|
||||
var regaxEmail =
|
||||
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
if (regaxEmail.test(Email)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function check_field(){
|
||||
var number_regex1 = /^[0]\d{9}$/i;
|
||||
var number_regex2 = /^[0]\d{10}$/i;
|
||||
var error = "";
|
||||
|
||||
var check_name = document.getElementById('buyer_name').value;
|
||||
if(check_name.length < 4) error += "- Tên quá ngắn\n";
|
||||
else if(check_name.indexOf('<script') > -1) {
|
||||
error += "- Họ tên chứa các ký tự không hợp lệ, bạn vui lòng kiểm tra lại\n";
|
||||
}
|
||||
|
||||
var check_email = document.getElementById('buyer_email').value;
|
||||
if(check_email.length < 4) {
|
||||
error += "- Bạn chưa nhập email\n";
|
||||
}
|
||||
if(check_email.length > 4){
|
||||
if(validateEmail(check_email)==false) error += "- Email không hợp lệ\n";
|
||||
}
|
||||
|
||||
var check_add = document.getElementById('buyer_address').value;
|
||||
if(check_add.length < 5) error += "- Địa chỉ quá ngắn\n";
|
||||
else if(check_add.indexOf('<script') > -1) {
|
||||
error += "- Địa chỉ chứa các ký tự không hợp lệ, bạn vui lòng kiểm tra lại\n";
|
||||
}
|
||||
|
||||
var check_tel = document.getElementById('buyer_tel').value;
|
||||
if(check_tel.length < 4) error += "- Bạn chưa nhập SĐT\n";
|
||||
else{
|
||||
if(number_regex1.test(check_tel) == false && number_regex2.test(check_tel) == false) error += "- Số điện thoại chưa chính xác\n";
|
||||
}
|
||||
|
||||
var check_note = document.getElementById('buyer_note').value;
|
||||
if(check_note.indexOf('<script') > -1) {
|
||||
error += "- Ghi chú chứa các ký tự không hợp lệ, bạn vui lòng kiểm tra lại\n";
|
||||
}
|
||||
|
||||
var check_province = document.getElementById('buyer_province').value;
|
||||
if(check_province==0) error += "- Bạn chưa chọn Tỉnh/Thành phố\n";
|
||||
else if(check_province.indexOf('<script') > -1) {
|
||||
error += "- Tỉnh/Thành phố chứa các ký tự không hợp lệ, bạn vui lòng kiểm tra lại\n";
|
||||
}
|
||||
|
||||
var check_district = document.getElementById('js-district-holder').value;
|
||||
if(check_district==0) error += "- Bạn chưa chọn Quận/Huyện\n";
|
||||
else if(check_district.indexOf('<script') > -1) {
|
||||
error += "- Quận/Huyện phố chứa các ký tự không hợp lệ, bạn vui lòng kiểm tra lại\n";
|
||||
}
|
||||
|
||||
if(error != "") {
|
||||
alert(error); return false;
|
||||
}
|
||||
if (check_district > 0 && check_add.length > 5) {
|
||||
var district = $('#js-district-holder option:selected').text();
|
||||
$('#buyer_address').val(check_add +', '+ district)
|
||||
}
|
||||
|
||||
$(".js-send-cart").css("pointer-events","none");
|
||||
$(".js-send-cart").html("ĐANG XỬ LÝ...");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// check input validation section
|
||||
function check_valid_input(pattern, target) {
|
||||
// check valid value for input in cart page
|
||||
$(target).on("input", function () {
|
||||
var stringValue = $(target).val();
|
||||
var status = pattern.test(stringValue);
|
||||
if (status == false) {
|
||||
$(this).css("outline-color", "rgb(194 29 29)"); //red
|
||||
var targetName = $(this).prev().html().replace("*", "");
|
||||
this.setCustomValidity(targetName + " quá ngắn/chưa đúng");
|
||||
this.reportValidity();
|
||||
} else {
|
||||
this.setCustomValidity("");
|
||||
this.reportValidity();
|
||||
$(this).css("outline-color", "rgb(45 182 99)"); //green
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
//for mail
|
||||
function check_valid_input_executer() {
|
||||
// add check func for each input here and call this func to check all input
|
||||
//for mail
|
||||
check_valid_input(
|
||||
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
||||
"#buyer_email"
|
||||
);
|
||||
//for name
|
||||
check_valid_input(/^[a-zA-Z ]{4,20}$/, "#buyer_name");
|
||||
//for phone number
|
||||
check_valid_input(/(84|0[3|5|7|8|9])+([0-9]{8})\b/, "#buyer_tel");
|
||||
//for address
|
||||
check_valid_input(/.{10}/, "#buyer_address");
|
||||
}
|
||||
|
||||
// end check input validation section
|
||||
|
||||
//Get province selection ( lay quan huyen )
|
||||
function getProvince(province_id) {
|
||||
var params = {
|
||||
action_type: 'district-list',
|
||||
province: province_id
|
||||
};
|
||||
var target = '#js-district-holder';
|
||||
|
||||
Hura.Ajax.get("province", params).then(function (data) {
|
||||
//console.log(data);
|
||||
// productTpl is in template: javascript/tpl
|
||||
var html = Hura.Template.parse(provinceTpl, data);
|
||||
Hura.Template.render(target, '<select name="user_info[district]" id="ship_to_district"><option value="0">Quận/Huyện</option>' + html +'</select>');
|
||||
})
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$(".js-bank-money").click(function(){
|
||||
$("#show-info-bank").addClass("hide");
|
||||
});
|
||||
|
||||
$(".js-bank-online").click(function(){
|
||||
$("#show-info-bank").removeClass("hide");
|
||||
});
|
||||
})
|
||||
|
||||
var TOTAL_CART_VALUE_NODE = ".js-total-cart-price";
|
||||
|
||||
function formatCurrency(a) {
|
||||
var b = parseFloat(a)
|
||||
.toFixed(2)
|
||||
.replace(/(\d)(?=(\d{3})+\.)/g, "$1.")
|
||||
.toString();
|
||||
var len = b.length;
|
||||
b = b.substring(0, len - 3);
|
||||
return b;
|
||||
}
|
||||
|
||||
function strToNumber(str) {
|
||||
str += "";
|
||||
while (str.indexOf(".") > 0) {
|
||||
str = str.replace(".", "");
|
||||
}
|
||||
var result = parseFloat(str);
|
||||
return isNaN(result) ? 0 : result;
|
||||
}
|
||||
|
||||
function tinhSoLuongSanPham() {
|
||||
var total_item = 0;
|
||||
|
||||
$(".js-buy-quantity").each(function () {
|
||||
total_item += parseInt($(this).val());
|
||||
});
|
||||
$("#js-total-quantity").html(total_item + " sản phẩm");
|
||||
}
|
||||
|
||||
function checkTotalShippingFee(){
|
||||
var province = $("#id-province").val();
|
||||
var district = $("#id-distric").val();
|
||||
|
||||
var cart_total_before_fee_discount = $("#js-total-before-fee-discount").val();
|
||||
|
||||
|
||||
if(province==0 || district == 0){
|
||||
return;
|
||||
}
|
||||
|
||||
var params = {
|
||||
action : "shipping",
|
||||
action_type: "get-shipping-and-cod",
|
||||
order_value : cart_total_before_fee_discount,
|
||||
province : province,
|
||||
district : district
|
||||
}
|
||||
|
||||
Hura.Ajax.post('shipping',params).then(function(data){
|
||||
//console.log(data)
|
||||
$('#js_price_ship').val(data.ship)
|
||||
calculateCartTotalPrice()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
//tinh tong gia don hang
|
||||
function calculateCartTotalPrice() {
|
||||
var dom_target = ".js-total-before-fee-cart-price";
|
||||
var total_cart_price = 0;
|
||||
|
||||
$(".item-cart-price").each(function () {
|
||||
total_cart_price += Hura.Util.strToNumber($(this).html());
|
||||
});
|
||||
|
||||
//log for other reference
|
||||
$("#js-total-before-fee-discount").val(total_cart_price);
|
||||
|
||||
//giam gia khac: voucher, membership, loyalty point conversion
|
||||
var total_discount = 0;
|
||||
total_discount += Number($("#js-discount-voucher").val());
|
||||
total_discount += parseInt($("#js-discount-membership").val());
|
||||
|
||||
var voucher_value = parseInt($("#js-discount-voucher").val());
|
||||
|
||||
//phi khac: shipping, COD...
|
||||
var total_other_fee = 0;
|
||||
total_other_fee += parseInt($("#js-fee-shipping").val());
|
||||
total_other_fee += parseInt($("#js-fee-cod").val());
|
||||
//console.log(total_discount);
|
||||
|
||||
var priceFreeship = parseInt($('#js_price_freeship').val());
|
||||
|
||||
if($('#js_price_ship').val() == "nomal"){
|
||||
$("#js-inner-ship").html(`
|
||||
<div class="cart-customer-total d-flex align-items-center justify-content-between">
|
||||
<div>
|
||||
<span class="text">Phí vận chuyển: </span>
|
||||
</div>
|
||||
<p class="cart-customer-total-price">Chưa tính</p>
|
||||
</div>
|
||||
`);
|
||||
|
||||
$(dom_target).html(formatCurrency(total_cart_price)+' đ');
|
||||
$(TOTAL_CART_VALUE_NODE).html(formatCurrency(total_cart_price - total_discount )+' đ');
|
||||
|
||||
}else{
|
||||
var priceShip = parseInt($('#js_price_ship').val());
|
||||
if(total_cart_price >= priceFreeship || priceShip == 0){
|
||||
//console.log(total_cart_price);
|
||||
//console.log(priceFreeship)
|
||||
$("#js-inner-ship").html(`
|
||||
<div class="cart-customer-total d-flex align-items-center justify-content-between">
|
||||
<div>
|
||||
<span class="text">Phí vận chuyển: </span>
|
||||
</div>
|
||||
<p class="cart-customer-total-price">Freeship</p>
|
||||
</div>
|
||||
`);
|
||||
|
||||
$(dom_target).html(formatCurrency(total_cart_price)+' đ');
|
||||
$(TOTAL_CART_VALUE_NODE).html(formatCurrency(total_cart_price - total_discount )+' đ');
|
||||
|
||||
}else{
|
||||
var minusPriceShip = priceFreeship - total_cart_price;
|
||||
//console.log(total_cart_price);
|
||||
//console.log(priceFreeship)
|
||||
$("#js-inner-ship").html(`
|
||||
<div class="cart-customer-total d-flex align-items-center justify-content-between">
|
||||
<div>
|
||||
<span class="text">Phí vận chuyển: </span>
|
||||
</div>
|
||||
<p class="cart-customer-total-price">${formatCurrency(priceShip) + ' đ'}</p>
|
||||
</div>
|
||||
<div class="text-ship d-flex justify-content-between">
|
||||
<div class="text-ship-left">
|
||||
Mua thêm <span class="text-red-b" style="color:yellow;font-size:14px;">${formatCurrency(minusPriceShip)} đ</span> để được <span class="text-red-b" style="color:yellow;font-size:14px;"> Freeship</span>
|
||||
</div>
|
||||
<div class="text-ship-right">
|
||||
<a href="/">Mua thêm</a>
|
||||
</div>
|
||||
</div>
|
||||
`);
|
||||
//console.log(total_discount)
|
||||
|
||||
|
||||
$(dom_target).html(formatCurrency(total_cart_price)+' đ');
|
||||
$(TOTAL_CART_VALUE_NODE).html(formatCurrency(total_cart_price - total_discount + priceShip )+' đ');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
calculateCartTotalPrice();
|
||||
//thay doi tong gia cua 1 san pham
|
||||
function changeItemTotalPrice() {
|
||||
var $row = $(this).closest(".js-item-row");
|
||||
var item_type = $row.data("item_type");
|
||||
var price = parseInt($row.find(".js-buy-price").val());
|
||||
var quantity = parseInt($row.find(".js-buy-quantity").val());
|
||||
var total_price = price * quantity;
|
||||
|
||||
//loai bo so luong vo ly
|
||||
if (quantity < 1) {
|
||||
$row.find(".js-buy-quantity").val(1);
|
||||
total_price = 0;
|
||||
}
|
||||
|
||||
$row.find(".item-cart-price").html(formatCurrency(total_price)+' đ');
|
||||
|
||||
calculateCartTotalPrice();
|
||||
|
||||
//console.log("updating cart = " + item_type);
|
||||
|
||||
//save to cart
|
||||
switch (item_type) {
|
||||
case "product":
|
||||
Hura.Cart.Product.update($row.data("item_id"), $row.data("variant_id"), {quantity: quantity,});
|
||||
break;
|
||||
|
||||
case "deal":
|
||||
Hura.Cart.Deal.update($row.data("item_id"), { quantity: quantity });
|
||||
break;
|
||||
|
||||
case "combo":
|
||||
Hura.Cart.Combo.update($row.data("item_id"), { quantity: quantity });
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//nghe thay doi so luong sp
|
||||
function listenQuantityChange() {
|
||||
var $track_change = $(".js-quantity-change");
|
||||
|
||||
//thay doi so luong sp mua, neu nhap so luong
|
||||
$track_change.on("change", function (e) {
|
||||
var quantity_stock = $(this).attr("data-stock");
|
||||
var $row = $(this).closest(".js-item-row");
|
||||
var current_quantity = $(this).val();
|
||||
|
||||
if($(this).val() < 1) $(this).val(1);
|
||||
|
||||
if(current_quantity > quantity_stock) {
|
||||
alert("Bạn được mua tối đa "+ quantity_stock + " sản phẩm này");
|
||||
$row.find(".js-buy-quantity").val(quantity_stock);
|
||||
changeItemTotalPrice.call(this);
|
||||
tinhSoLuongSanPham.call(this);
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
changeItemTotalPrice.call(this);
|
||||
tinhSoLuongSanPham.call(this);
|
||||
});
|
||||
|
||||
//thay doi so luong sp theo - hoac +
|
||||
$track_change.on("click", function (e) {
|
||||
if (e.target.nodeName === "INPUT") return;
|
||||
|
||||
var quantity_change = parseInt(this.getAttribute("data-value"));
|
||||
var $row = $(this).closest(".cart-item-info");
|
||||
var current_quantity = parseInt($row.find(".js-buy-quantity").val());
|
||||
var quantity_stock = parseInt($row.find(".js-buy-quantity").attr("data-stock"));
|
||||
|
||||
//loai bo so luong vo ly
|
||||
if (current_quantity + quantity_change < 1) {
|
||||
$row.find(".js-buy-quantity").val(1);
|
||||
return;
|
||||
}
|
||||
|
||||
if(current_quantity + quantity_change > quantity_stock) {
|
||||
alert("Bạn được mua tối đa "+ quantity_stock + " sản phẩm này");
|
||||
$row.find(".js-buy-quantity").val(quantity_stock);
|
||||
changeItemTotalPrice.call(this);
|
||||
tinhSoLuongSanPham.call(this);
|
||||
return ;
|
||||
}
|
||||
|
||||
$row.find(".js-buy-quantity").val(current_quantity + quantity_change);
|
||||
|
||||
//then update
|
||||
changeItemTotalPrice.call(this);
|
||||
tinhSoLuongSanPham.call(this);
|
||||
});
|
||||
}
|
||||
listenQuantityChange();
|
||||
|
||||
|
||||
function deleteCart(){
|
||||
let product_ids = [];
|
||||
$(".js-delete-item").each(function(){
|
||||
var $row = $(this).closest(".js-item-row");
|
||||
var item_id = $row.data("item_id");
|
||||
var variant_id = $row.data("variant_id");
|
||||
product_ids.push({item_id: item_id, variant_id: variant_id})
|
||||
$row.remove();
|
||||
});
|
||||
deleteAllCart(product_ids);
|
||||
}
|
||||
|
||||
async function deleteAllCart(product_ids){
|
||||
for(let i = 0; i < product_ids.length; i++) {
|
||||
let item_id = product_ids[i].item_id;
|
||||
let variant_id = product_ids[i].variant_id;
|
||||
await Hura.Cart.Product.remove(item_id, variant_id);
|
||||
}
|
||||
|
||||
setTimeout(function(){
|
||||
if($(".js-item-row").length==0){ location.reload();}
|
||||
},500);
|
||||
|
||||
}
|
||||
|
||||
function downloadCartImage() {
|
||||
var seconds = new Date().getTime() / 1000;
|
||||
var print_url = "{{ global.domain }}/print/user.php?view=cart&f="+parseInt(seconds)+"&uid="+Hura.User.getUserId();
|
||||
|
||||
window.location = "https://screenshot.hurasoft.com/screenshot.php?url=" + encodeURIComponent(print_url);
|
||||
}
|
||||
|
||||
|
||||
//nghe xoa san pham
|
||||
function listenDeleteCartItem() {
|
||||
$(".item-cart-icon").on("click", function () {
|
||||
var $row = $(this).closest(".cart-item-info");
|
||||
var item_type = $row.data("item_type");
|
||||
var item_id = $row.data("item_id");
|
||||
calculateCartTotalPrice();
|
||||
|
||||
//console.log("deleting item from cart = " + item_type);
|
||||
|
||||
var deleteStatus;
|
||||
//save to cart
|
||||
switch (item_type) {
|
||||
case "product":
|
||||
deleteStatus = Hura.Cart.Product.remove(
|
||||
item_id,
|
||||
$row.data("variant_id")
|
||||
);
|
||||
location.reload();
|
||||
break;
|
||||
case "deal":
|
||||
deleteStatus = Hura.Cart.Deal.remove(item_id);
|
||||
location.reload();
|
||||
break;
|
||||
case "combo":
|
||||
deleteStatus = Hura.Cart.Combo.remove(item_id);
|
||||
location.reload();
|
||||
break;
|
||||
}
|
||||
|
||||
if (deleteStatus) {
|
||||
deleteStatus.then(function () {
|
||||
$row.remove();
|
||||
tinhSoLuongSanPham();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
listenDeleteCartItem();
|
||||
|
||||
|
||||
// Voucher
|
||||
function debounce(func, wait, immediate) {
|
||||
var timeout;
|
||||
return function() {
|
||||
var context = this, args = arguments;
|
||||
var later = function() {
|
||||
timeout = null;
|
||||
if (!immediate) func.apply(context, args);
|
||||
};
|
||||
var callNow = immediate && !timeout;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(later, wait);
|
||||
if (callNow) func.apply(context, args);
|
||||
};
|
||||
};
|
||||
|
||||
function voucher_input_change() {
|
||||
$('#js_voucher_input').change();
|
||||
}
|
||||
|
||||
function listenVoucherCode(dom_node) {
|
||||
var cart_total_before_fee_discount = $("#js-total-before-fee-discount").val();
|
||||
var $message_holder = $("#js-voucher-message");
|
||||
|
||||
var check_deal = 0
|
||||
$(".js-item-row").each(function(){
|
||||
var check = $(this).attr("data-check-deal")
|
||||
if (check == 1) {
|
||||
check_deal = 1;
|
||||
}
|
||||
})
|
||||
|
||||
$(dom_node).change(debounce(function(){
|
||||
if (check_deal == 1) {
|
||||
$message_holder.html('<span class="red">Mã voucher không được áp dụng. Vui lòng xóa sản phẩm DEAL trong giỏ hàng</span>');
|
||||
} else{
|
||||
var voucher_code = this.value.trim();
|
||||
|
||||
//update field to send when submit
|
||||
$("#js_coupon_code").val(voucher_code);
|
||||
$("#js-discount-voucher").val(0);
|
||||
$("#price-discount").html('');
|
||||
$message_holder.html('');
|
||||
|
||||
//xu ly hien thi
|
||||
if(voucher_code.length > 2) {
|
||||
var params = {
|
||||
action_type: 'check',
|
||||
code : voucher_code ,
|
||||
order_value : cart_total_before_fee_discount,
|
||||
product_ids : ''
|
||||
}
|
||||
|
||||
Hura.Ajax.post('coupon', params).then(function (data) {
|
||||
//console.log(data);
|
||||
var voucher_info = data;
|
||||
|
||||
if(voucher_info.status == 'error') {
|
||||
//bao loi
|
||||
$message_holder.html(voucher_info.message);
|
||||
return ;
|
||||
}
|
||||
|
||||
$message_holder.html("Bạn đang sử dụng mã coupon/voucher: <b style='color: #f00;font-size: 16px'>" + voucher_info.coupon_info.code + "</b>");
|
||||
$message_holder.show();
|
||||
|
||||
//xu ly khac
|
||||
switch (voucher_info.coupon_info.type) {
|
||||
case "cash": //giam tru tien
|
||||
$("#js-discount-voucher").val(Hura.Util.strToNumber(voucher_info.coupon_info.cash_discount));
|
||||
$("#price-discount").html(formatCurrency(voucher_info.coupon_info.cash_discount));
|
||||
break;
|
||||
|
||||
case "priceoff"://giam gia %
|
||||
//var total_price_in_cart = $('#js-total-before-fee-discount').val();
|
||||
var total_price_in_cart = {% if global.module.name == 'combo_set' %}0{% else %}{{ page.cart_summary.total_value }}{% endif%};
|
||||
var after_discount = Math.ceil( total_price_in_cart * voucher_info.coupon_info.content / 100);
|
||||
$("#js-discount-voucher").val(Hura.Util.strToNumber(after_discount));
|
||||
$("#price-discount").html(formatCurrency(voucher_info.total_cash_discount));
|
||||
break;
|
||||
|
||||
case "pro":
|
||||
//todo:
|
||||
|
||||
break;
|
||||
|
||||
case "other":
|
||||
//todo:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
calculateCartTotalPrice();
|
||||
})
|
||||
}else{
|
||||
$("#js-discount-voucher").val(0);
|
||||
$message_holder.html('');
|
||||
//recalculate total
|
||||
calculateCartTotalPrice();
|
||||
}
|
||||
}
|
||||
},100));
|
||||
|
||||
}
|
||||
|
||||
function getVoucherList(holder) {
|
||||
var params = {
|
||||
action_type: 'get-active-list',
|
||||
limit: 50
|
||||
}
|
||||
|
||||
Hura.Ajax.post('coupon', params).then(function (response) {
|
||||
//console.log(response);
|
||||
|
||||
buildListVoucher(response, holder);
|
||||
|
||||
$(".js-voucher-active").click(function(){
|
||||
$(".js-voucher-active").removeClass('current-voucher');
|
||||
$(this).addClass('current-voucher');
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
function buildListVoucher(response, holder) {
|
||||
var html = '';
|
||||
var current_time = (new Date()).getTime()/1000;
|
||||
|
||||
if (response.total > 0) {
|
||||
Object.keys(response).forEach(function(key, keyIndex) {
|
||||
var data = response[key];
|
||||
Object.keys(data).forEach(function(item, itemIndex) {
|
||||
var status = data[item].can_use_with_cart.status;
|
||||
var code = data[item].code
|
||||
var title = data[item].title;
|
||||
var id_coupon = data[item].id;
|
||||
var to_time = data[item].to_time;
|
||||
var time_left = to_time - current_time;
|
||||
var check_product = data[item].can_use_with_cart.status;
|
||||
|
||||
if (time_left > 0 && check_product == 'yes') {
|
||||
html+=`<div class="voucher-item active-voucher js-voucher-active" onclick="voucherSelected('`+code+`')">`;
|
||||
} else{
|
||||
html+='<div class="voucher-item">';
|
||||
}
|
||||
html+= '<div class="code"> Nhập <b class="d-block text-18">'+code+'</b> </div>';
|
||||
html+= '<div class="text"> <p>'+ title +'</p><i class="circle"></i></div> </div>';
|
||||
})
|
||||
})
|
||||
} else{
|
||||
html+= `
|
||||
<div class="no-voucher text-center">
|
||||
<i class="no-voucher-img lazy" style="background-image:url(/static/assets/default/images/cart-ticket.png)"></i>
|
||||
|
||||
<p class="text-20 font-600 m-0"> Chưa có mã voucher nào ! </p>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
$(holder).html(html);
|
||||
}
|
||||
|
||||
|
||||
function voucherSelected(voucher_coder) {
|
||||
$("#js_voucher_input_pop").val(voucher_coder);
|
||||
$('#js-voucher-popupmessage').html("");
|
||||
|
||||
}
|
||||
|
||||
function voucherActive() {
|
||||
$("#js_voucher_input").val("");
|
||||
$("#js_voucher_input").change();
|
||||
|
||||
var newCode = $("#js_voucher_input_pop").val();
|
||||
$("#js_voucher_input").val(newCode);
|
||||
$("#js_voucher_input").change();
|
||||
close_voucher();
|
||||
|
||||
}
|
||||
|
||||
function open_voucher() {
|
||||
$("#js-popup-voucher").show();
|
||||
$("body").addClass("overflow-hidden");
|
||||
$(".cart-voucher-popup").addClass("active")
|
||||
}
|
||||
|
||||
function close_voucher() {
|
||||
$("#js-popup-voucher").hide();
|
||||
$("body").removeClass("overflow-hidden");
|
||||
$(".js-voucher-active").removeClass('current-voucher');
|
||||
$("#js_voucher_input_pop").val("");
|
||||
$(".cart-voucher-popup").removeClass("active")
|
||||
}
|
||||
|
||||
|
||||
BIN
Chico/img/card.png
Normal file
BIN
Chico/img/card.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 503 B |
BIN
Chico/img/item-cart.png
Normal file
BIN
Chico/img/item-cart.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
BIN
Chico/img/location-minus.png
Normal file
BIN
Chico/img/location-minus.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 707 B |
BIN
Chico/img/title-artilce1.png
Normal file
BIN
Chico/img/title-artilce1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 538 B |
1478
Chico/index.html
1478
Chico/index.html
File diff suppressed because it is too large
Load Diff
171
Chico/user.js
Normal file
171
Chico/user.js
Normal file
@@ -0,0 +1,171 @@
|
||||
<!-- 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ử lý</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>`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user