ÿØÿà JFIF ÿÛ „ ( %"1"%)+...383,7(-.-
![]() Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.20 System : Linux st2.domain.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64 User : apache ( 48) PHP Version : 7.4.20 Disable Function : NONE Directory : /proc/self/root/var/www/html/tien-dien/layout/visahp/js/ |
$(document).ready(function() { const inputContainer = $('#inputContainer'); let roomCounter = 1; $('#addRoomButton').on('click', function() { roomCounter++; const newRoomDiv = $('<div>').addClass('form-group mb-3'); const newLabel = $('<label>') .attr('for', 'so_dien_phong_' + roomCounter) .addClass('form-label') .text('Số Ä‘iện Phòng ' + roomCounter + ' (kWh):'); const newInput = $('<input>') .attr('type', 'number') .addClass('form-control') .attr('id', 'so_dien_phong_' + roomCounter) .attr('name', 'so_dien_phong[]') .attr('placeholder', 'Nháºp số kWh') .attr('min', '0'); const costDisplayDiv = $('<div>') .addClass('room-cost mt-1 text-muted') .html('<div>Thà nh tiá»n (chưa VAT): <span class="cost-value-pre-tax fw-bold">0</span> VNÄ</div>' + '<div>Thà nh tiá»n (đã VAT 8%): <span class="cost-value-post-tax fw-bold">0</span> VNÄ</div>' + '<div>Phải đóng: <span class="tien_dong_thuc fw-bold">0</span> VNÄ</div>'); newRoomDiv.append(newLabel).append(newInput).append(costDisplayDiv); inputContainer.append(newRoomDiv); }); $('#calculateButton').on('click', function() { const kwhInputs = $('input[name="so_dien_phong[]"]'); let kwhValues = []; kwhInputs.each(function() { const val = $(this).val(); const kwh = parseFloat(val); kwhValues.push( (val === '' || isNaN(kwh) || kwh < 0) ? 0 : kwh ); }); var tien_dong = 0; if($('#tien_dong').val()){ tien_dong = parseFloat($('#tien_dong').val()); } $.ajax({ url: '?act=tiendien&code=tinh_tiendien', type: 'POST', data: { so_dien_phong: kwhValues,tien_dong:tien_dong }, dataType: 'json', beforeSend: function() { $('#calculateButton').prop('disabled', true).text('Äang tÃnh...'); // Reset previous results $('.cost-value-pre-tax').text('0'); $('.cost-value-post-tax').text('0'); }, success: function(response) { if (response && response.room_costs && response.room_costs.length === kwhInputs.length) { kwhInputs.each(function(index) { const roomData = response.room_costs[index]; const costGroup = $(this).closest('.form-group'); const preTaxSpan = costGroup.find('.cost-value-pre-tax'); const postTaxSpan = costGroup.find('.cost-value-post-tax'); const postTaxSpan2 = costGroup.find('.tien_dong_thuc'); if (roomData) { preTaxSpan.text(Math.round(roomData.pre_tax).toLocaleString('vi-VN')); postTaxSpan.text(Math.round(roomData.post_tax).toLocaleString('vi-VN')); if(tien_dong>0){ const roomData2 = response.result_tien[index]; postTaxSpan2.text(Math.round(roomData2.tien_dong_thuc).toLocaleString('vi-VN')); } } }); $('#total_cost_vat').text(Math.round(response.total_cost_vat).toLocaleString('vi-VN')); } else { alert('Lá»—i khi nháºn dữ liệu tÃnh toán từ server. Vui lòng kiểm tra console.'); console.error("Phản hồi không hợp lệ từ server:", response); } }, error: function(jqXHR, textStatus, errorThrown) { alert('Có lá»—i xảy ra khi tÃnh tiá»n Ä‘iện. Vui lòng thá» lại.'); console.error("Lá»—i AJAX:", textStatus, errorThrown, jqXHR.responseText); }, complete: function() { $('#calculateButton').prop('disabled', false).text('TÃnh tiá»n Ä‘iện'); } }); }); // Star Rating functionality function initStarRating() { const stars = document.querySelectorAll('.star-rating .star'); const selectedRating = document.getElementById('selected-rating'); const messageDiv = document.getElementById('rating-message'); if (!stars.length || !selectedRating || !messageDiv) { return; // Exit if elements don't exist on this page } const productId = selectedRating.getAttribute('data-product-id'); // Add event listeners to stars stars.forEach(star => { star.addEventListener('click', function() { const rating = this.getAttribute('data-rating'); selectedRating.value = rating; // Reset all stars stars.forEach(s => s.classList.remove('active')); // Highlight selected stars (accounting for RTL direction) // With direction:rtl, stars are in reverse order visually but not in the DOM for (let i = 0; i < rating; i++) { // In RTL, we need to highlight stars from the end stars[stars.length - 1 - i].classList.add('active'); } // Submit rating immediately if (rating < 1) { messageDiv.textContent = 'Vui lòng chá»n số sao đánh giá'; messageDiv.className = 'mt-1 error'; return; } // Show loading message messageDiv.textContent = 'Äang gá»i...'; messageDiv.className = 'mt-1'; // Send AJAX request fetch('?act=ajax&code=product_rating', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: `product_id=${productId}&rating=${rating}` }) .then(response => response.json()) .then(data => { if (data.status === 'success') { // Update display messageDiv.textContent = data.message; messageDiv.className = 'mt-1 success'; // Update average rating display document.querySelector('.rating-value').textContent = data.average; document.querySelector('.rating-count').textContent = `(${data.count} đánh giá)`; document.querySelector('.stars-inner').style.width = `${(data.average / 5) * 100}%`; } else { messageDiv.textContent = data.message; messageDiv.className = 'mt-1 error'; } }) .catch(error => { console.error('Error:', error); messageDiv.textContent = 'Có lá»—i xảy ra, vui lòng thá» lại sau'; messageDiv.className = 'mt-1 error'; }); }); }); } // Initialize star rating when DOM is ready initStarRating(); });