'); } }); $('.zoom').slick({ dots: false, slidesToShow: 1, slidesToScroll: 1, autoplay: true, autoplaySpeed: 2000 }); } $(".thumb-slide ul li img").click(function () { $(".thumb-slide ul li").removeClass("active"), $(this).parent().addClass("active"); $('.zoom').slick('unslick'); $('.zoom').html(""); var colorID = $(this).parent().attr("data-color"); var src = $(this).attr("src"); changeImageCombo(src); $('.slide-item img').each(function () { var imgID = $(this).attr("data-id"); var alt = $(this).attr("alt"); if (imgID == colorID) { $(this).parent().show(); $('.zoom').append('
'); } else { $(this).parent().hide(); } }); $(".color-list a").removeClass("active"); $('.color-list a').each(function () { var data_color = $(this).attr("data-color"); if (data_color == colorID) { $(this).addClass("active") } }); $('.zoom').slick({ dots: false, slidesToShow: 1, slidesToScroll: 1, autoplay: true, autoplaySpeed: 2000 }); checkSizeAvaiable(); $('.zoom').slick({ refresh: true }); }); } if (IsMobile == "false") { var $window = $(window); function zoomProduct() { var window_width = $window.width(); var inner_height = $window.innerHeight(); if (window_width > 768) { $("#zoom").click(function (e) { e.preventDefault(); var src_zoom = $(this).attr("data-zoom-image"); var alt = $(this).attr("alt"); $(".popup-zoom-image").show(); $('body').css('overflow-y', 'hidden'); $(".popup-zoom-image").height(inner_height); $('.popup-zoom-image').find('.zoom-container').html(""); $(".popup-zoom-image").find('.zoom-container').append(''); $(".popup-zoom-image").find('.zoom-container').height(inner_height); $('.popup-zoom-image .zoom-container').zoom(); $('.popup-zoom-image').find('.list_miniature').find('ul').html(""); var index = 0; $('.slide-item ul li:visible').each(function () { var src = $(this).find('img').attr("src"); var alt = $(this).find('img').attr("alt"); if (src_zoom == src.replace("_small", "")) { $('.popup-zoom-image').find('.list_miniature').find('ul').append(''); } else { $('.popup-zoom-image').find('.list_miniature').find('ul').append(''); } index++; }); $(".list_miniature ul li img").hover(function () { $(".list_miniature ul li").removeClass('active'); $(this).parent().addClass('active'); var src = $(this).attr("src"); var alt = $(this).attr("alt"); $('.popup-zoom-image').find('.zoom-container').html(""); $(".popup-zoom-image").find('.zoom-container').append(''); $('.popup-zoom-image .zoom-container').zoom(); }); }); $(document).on("click", ".popup-zoom-image .close-cube span.close, .popup-zoom-image .zoom-container", function () { $('.popup-zoom-image').hide(); $('body').css('overflow-y', 'unset') }); } } zoomProduct(); $(window).resize(zoomProduct); $('#zoom').hover(function () { var title = $(this).attr('title'); $(this).data('tipText', title).removeAttr('title'); $('').css({ display: "none", position: "absolute", border: "1px solid #333", "background-color": "#161616", padding: "5px 10px", color: "#fff", "font-size": "12px", "z-index": "9999" }).text(title).appendTo('body').fadeIn('slow').delay(1000).fadeOut(); }, function () { $(this).attr('title', $(this).data('tipText')); $('.zoom-tooltip').remove(); }).mousemove(function (e) { var mousex = e.pageX + 20; var mousey = e.pageY + 10; $('.zoom-tooltip').css({ top: mousey, left: mousex }) }); } var width = $(window).width(); if (width > 768) { var height_left = $(".product-gallery").height(); var height_right = $(".product-infor").height(); if (height_left > height_right) { $(".product-infor").height(height_left); } else if (height_left < height_right) { $(".product-gallery").height(height_right); } } $('#ProvinceID').change(function () { var value = $(this).val(); $('#ProvinceID option[value="' + value + '"]').attr("selected", "selected"); $('#ProvinceID option[value!="' + value + '"]').removeAttr("selected"); $('#DistrictID option').remove(); if (value != 0) { $(this).removeClass("error-msg"); $.ajax({ type: "post", url: "/Home/GetDistrict", data: { province: parseInt(value) }, dataType: "json", success: function (data) { var html = ""; html += ""; if (data.length) { for (var i = 0; i < data.length; i++) { html += ""; } } $('#DistrictID').append(html); }, error: function (xhr, textStatus, errorThrown) { }, }); } else { $('#DistrictID').append(""); } }); $('#DistrictID').change(function () { var value = $(this).val(); $('#DistrictID option[value="' + value + '"]').attr("selected", "selected"); $('#DistrictID option[value!="' + value + '"]').removeAttr("selected"); if (value != 0) { $(this).removeClass("error-msg"); $.ajax({ type: "post", url: "/Home/GetShipping", data: { district: parseInt(value) }, dataType: "json", success: function (data) { var price = $("#price").val(); var html = ""; html += "Phí giao hàng: " + commaSeparateNumber(data.districtInfor.ShippingFee) + "đ."; html += "Giao trong " + data.districtInfor.TimeOfDelivery + " (không tính ngày lễ và chủ nhật)"; $("#shipInfor").html(""); $("#shipInfor").append(html); $("#shipInfor").removeClass("hidden"); }, error: function (xhr, textStatus, errorThrown) { }, }); } }); $("body").on("click", ".btn-comment", function () { var dataPost = {}; const minLenght = 30; var type = parseInt($(this).data("type")); if (type == 1) { $("#NameReview").removeClass("error-msg"); $("#PhoneReview").removeClass("error-msg"); $("#DescriptionReview").removeClass("error-msg"); var point = parseInt($("input[name=rating]:checked").val()); if (isNaN(point)) { alert("Vui lòng chọn điểm đánh giá!"); return false; } if ($("#NameReview").val().length == 0 || !validPhoneNumber($("#PhoneReview").val()) || $("#DescriptionReview").val().length < minLenght) { if ($("#NameReview").val().length == 0) { alert("Vui lòng nhập Họ và tên!"); $("#NameReview").addClass("error-msg"); } else if (!validPhoneNumber($("#PhoneReview").val())) { alert("Vui lòng nhập đúng Số điện thoại!"); $("#PhoneReview").addClass("error-msg"); } else if ($("#DescriptionReview").val().length < minLenght) { alert("Bình luận tối thiểu " + minLenght.toString() + " ký tự!"); $("#DescriptionReview").addClass("error-msg"); } return false; } dataPost = { Name: $("#NameReview").val(), Description: $("#DescriptionReview").val(), Phone: $("#PhoneReview").val(), ProductID: $("#ProductID").val(), Type: type, Point: point, }; } else if (type == 2) { $("#NameCmt").removeClass("error-msg"); $("#DescriptionCmt").removeClass("error-msg"); $("#PhoneCmt").removeClass("error-msg"); if ($("#NameCmt").val().length == 0 || !validPhoneNumber($("#PhoneCmt").val()) || $("#DescriptionCmt").val().length < minLenght) { if ($("#NameCmt").val().length == 0) { alert("Vui lòng nhập Họ và tên!"); $("#NameCmt").addClass("error-msg"); } else if (!validPhoneNumber($("#PhoneCmt").val())) { alert("Vui lòng nhập đúng Số điện thoại!"); $("#PhoneCmt").addClass("error-msg"); } else if ($("#DescriptionCmt").val().length < minLenght) { alert("Bình luận tối thiểu " + minLenght.toString() + " ký tự!"); $("#DescriptionCmt").addClass("error-msg"); } return false; } dataPost = { Name: $("#NameCmt").val(), Description: $("#DescriptionCmt").val(), Phone: $("#PhoneCmt").val(), ProductID: $("#ProductID").val(), Type: type, }; } $.ajax({ url: '/commentProduct', type: 'POST', data: dataPost, success: function (data) { if (data.success) { if (type == 1) { if (data.isEmployee) { $("#listreviews").load("/listreviewproduct", { page: 1, productID: $("#ProductID").val().toString() }, function () { $('html, body').animate({ scrollTop: ($(".list-review-wrap").offset().top) - 180 }, 200); }); $("#assessmentReviews").load("/assessmentreviewproduct", { productID: $("#ProductID").val().toString() }, function () { }); } else { alert(data.message); $("#NameReview").val(""); } $("#DescriptionReview").val(""); $("#PhoneReview").val(""); } else if (type == 2) { if (data.isEmployee) { $("#listcomments").load("/listcommentproduct", { page: 1, productID: $("#ProductID").val().toString() }, function () { $('html, body').animate({ scrollTop: ($(".list-comment-wrap").offset().top) - 180 }, 200); }); } else { alert(data.message); $("#NameCmt").val(""); } $("#DescriptionCmt").val(""); $("#PhoneCmt").val(""); } } }, error: function (err) { } }) }); $("body").on("click", ".change-page-comments, .prevposts-link-comments, .nextposts-link-comments", function () { var page = $(this).data("page"); var productID = $(this).data("productid"); $("#listcomments").load("/listcommentproduct", { page: parseInt(page), productID: productID.toString() }, function () { $('html, body').animate({ scrollTop: ($(".list-comment-wrap").offset().top) - 180 }, 200); }); }); $("body").on("click", ".change-page-reviews, .prevposts-link-reviews, .nextposts-link-reviews", function () { var page = $(this).data("page"); var productID = $(this).data("productid"); $("#listreviews").load("/listreviewproduct", { page: parseInt(page), productID: productID.toString() }, function () { $('html, body').animate({ scrollTop: ($(".list-review-wrap").offset().top) - 180 }, 200); }); }); $("body").on('click', '.repcomments', function (e) { e.preventDefault(); var IDcomment = $(this).data("idcomments"); $(".checkrepcomment").addClass("d-none"); $(".name-reply").val(""); $(".name-reply").removeClass("error-msg"); $(".description-reply").val(""); $(".description-reply").removeClass("error-msg"); $("#rep-comments-" + IDcomment).removeClass("d-none"); $("#Description-" + IDcomment).focus(); }); $("body").on('click', '.replycomments', function () { var parentID = $(this).data("parentid"); var type = $(this).data("type"); var $name = $("#Name-" + parentID); var $description = $("#Description-" + parentID); const minLenght = 30; if ($name.val().length == 0 || $description.val().length < minLenght) { if ($name.val().length == 0) { alert("Vui lòng nhập Họ và tên!"); $name.addClass("error-msg"); } else if ($description.val().length < minLenght) { alert("Vui lòng nhập tối thiểu " + minLenght.toString() + " ký tự!"); $description.addClass("error-msg"); } return false; } var page = 1; if (type == 1) { page = $(".current-page-review").data("page"); } else if (type == 2) { page = $(".current-page-comment").data("page"); } var dataPost = { ParentID: parentID.toString(), Name: $("#Name-" + parentID).val(), Description: $("#Description-" + parentID).val(), ProductID: $("#ProductID").val() }; $.ajax({ url: '/commentProduct', type: 'POST', data: dataPost, success: function (data) { if (data.success) { $(".checkrepcomment").addClass("d-none"); if (data.isEmployee) { if (data.type == 1) { $("#listreviews").load("/listreviewproduct", { page: parseInt(page), productID: $("#ProductID").val().toString() }, function () { $('html, body').animate({ scrollTop: ($(".comment-" + parentID).offset().top) }, 200); }); } else if (data.type == 2) { $("#listcomments").load("/listcommentproduct", { page: parseInt(page), productID: $("#ProductID").val().toString() }, function () { $('html, body').animate({ scrollTop: ($(".comment-" + parentID).offset().top) }, 200); }); } } else { alert(data.message); $("#Name-" + parentID).val(""); $("#Name-" + parentID).removeClass("error-msg"); } $("#Description-" + parentID).val(""); $("#Description-" + parentID).removeClass("error-msg"); } else { alert("Có lỗi xảy ra khi bình luận."); } }, error: function (err) { alert("Có lỗi xảy ra khi bình luận."); } }) }); $("body").on('click', "#reviewProduct", function () { $("#DescriptionReview").focus(); }); $('.short-video').magnificPopup({ type: 'iframe' }); }); function validPhoneNumber(phoneNumber) { var check = false; if (phoneNumber.length > 0) { phoneNumber = phoneNumber.replace(/ /g, ''); var pattern = "[0][8|9|3|5|7][0-9]{8}"; check = phoneNumber.match(pattern) ? true : false; } return check; } function commaSeparateNumber(val) { while (/(\d+)(\d{3})/.test(val.toString())) { val = val.toString().replace(/(\d+)(\d{3})/, '$1' + ',' + '$2'); } return val; }