1$(document).ready(function() { 2 console.log("service_logic.js initialized."); 3 4 // --- å å£°æææå¯è½ç¨å°ç jQuery 对象åéï¼åå§å¼ä¸º null --- 5 let $serviceSelectionForm = null; 6 let $homeServiceSelectionForm = null; 7 let $detailsFormSection = null; 8 let $detailsForm = null; 9 let $currentCheckboxes = null; 10 let $currentTotalPriceDisplay = null; 11 let $currentSubmitButton = null; 12 let $currentSelectionError = null; 13 // --- æå¡é¡µç¹å®çå ç´ ï¼å 声æ --- 14 let $detailsFormError = null; 15 let $loadingOverlay = null; 16 let $selectedServicesHidden = null; 17 let $totalAmountHidden = null; 18 let $backButton = null; 19 20 let isOnHomePage = false; 21 let isOnServicePage = false; 22 23 // --- å°è¯è·å页é¢å ç´ æ¥å¤æä¸ä¸æ --- 24 $homeServiceSelectionForm = $('#service_selection_form_home'); // é¦é¡µçæå¡éæ©è¡¨å 25 $serviceSelectionForm = $('#service_selection_form'); // æå¡é¡µçæå¡éæ©è¡¨å 26 $detailsFormSection = $('#details_form_section'); // 详æ 表ååºå 27 $detailsForm = $('#details_form'); // 详æ è¡¨åæ¬èº« 28 29 // --- æ ¹æ®å ç´ å卿 åµç¡®å®ä¸ä¸æå¹¶åå§åéæ©å¨ --- 30 if ($homeServiceSelectionForm.length > 0) { 31 // å½åå¨é¦é¡µ 32 isOnHomePage = true; 33 $currentCheckboxes = $homeServiceSelectionForm.find('input[name="services[]"]'); 34 $currentTotalPriceDisplay = $homeServiceSelectionForm.find('#total_price_display'); // å设 ID å¨è¡¨åå é¨ 35 $currentSubmitButton = $homeServiceSelectionForm.find('#submit_request_button_home'); 36 $currentSelectionError = $homeServiceSelectionForm.find('#selection_error'); 37 console.log("Context: Home Page"); 38 39 } else if ($serviceSelectionForm.length > 0 || ($detailsFormSection.length > 0 && $detailsFormSection.is(':visible'))) { // æå¡é¡µå¤ææ¡ä»¶ä¼å 40 // å½å卿å¡é¡µ (ai_mba_service/index.php) 41 isOnServicePage = true; 42 // åå§åæå¡é¡µéæ©è¡¨åç¸å ³å ç´ (å³ä½¿å®å¯è½å¨é¡µé¢å è½½æ¶éè) 43 if ($serviceSelectionForm.length > 0) { 44 $currentCheckboxes = $serviceSelectionForm.find('input[name="services[]"]'); 45 $currentTotalPriceDisplay = $serviceSelectionForm.find('#total_price_display'); 46 $currentSubmitButton = $serviceSelectionForm.find('#submit_request_button'); // å é¨åæ¢æé® 47 $currentSelectionError = $serviceSelectionForm.find('#selection_error'); 48 } else { 49 // 妿æå¡éæ©è¡¨åä¸åå¨ (ä¾å¦ç´æ¥æ¾ç¤ºè¯¦æ )ï¼å°è¿äºè®¾ä¸º null æç©º jQuery 对象 50 $currentCheckboxes = $(); // 空 jQuery 对象 51 $currentTotalPriceDisplay = $(); 52 $currentSubmitButton = $(); // è¿ä¸ªæé®é叏卿å¡éæ©è¡¨åå 53 $currentSelectionError = $(); 54 console.log("Service selection form not found on service page (maybe showing details directly)."); 55 } 56 // åå§åæå¡é¡µè¯¦æ 表åç¸å ³å ç´ (è¿äºå ç´ åºè¯¥æ»æ¯åå¨äºæå¡é¡µé¢) 57 $detailsFormError = $('#form_error'); 58 $loadingOverlay = $('#loading_overlay'); 59 $selectedServicesHidden = $('#selected_services_json'); 60 $totalAmountHidden = $('#total_amount_hidden'); 61 $backButton = $('#back_to_selection'); 62 console.log("Context: Service Page"); 63 64 } else { 65 console.warn("service_logic.js: Could not determine page context (Home or Service). Script execution stopped."); 66 return; // æªç¥é¡µé¢ï¼éåº 67 } 68 69 // --- è¾åºè°è¯ä¿¡æ¯ --- 70 console.log("Checkboxes found:", ($currentCheckboxes ? $currentCheckboxes.length : 'N/A')); 71 console.log("Total Price Display found:", ($currentTotalPriceDisplay ? $currentTotalPriceDisplay.length : 'N/A')); 72 console.log("Submit Button found:", ($currentSubmitButton ? $currentSubmitButton.length : 'N/A')); 73 console.log("Selection Error found:", ($currentSelectionError ? $currentSelectionError.length : 'N/A')); 74 if(isOnServicePage){ 75 console.log("Details Form Error found:", ($detailsFormError ? $detailsFormError.length : 'N/A')); 76 console.log("Loading Overlay found:", ($loadingOverlay ? $loadingOverlay.length : 'N/A')); 77 console.log("Selected Services Hidden found:", ($selectedServicesHidden ? $selectedServicesHidden.length : 'N/A')); 78 console.log("Total Amount Hidden found:", ($totalAmountHidden ? $totalAmountHidden.length : 'N/A')); 79 console.log("Back Button found:", ($backButton ? $backButton.length : 'N/A')); 80 } 81 82 // --- æ ¸å¿è®¡ä»·ä¸æé®ç¶ææ´æ°å½æ° --- 83 function updatePriceAndButtonState() { 84 // console.log("updatePriceAndButtonState called."); 85 let total = 0; 86 let count = 0; 87 let selectedServices = []; 88 89 // åªæå½å¤éæ¡å卿¶æè®¡ç® 90 if ($currentCheckboxes && $currentCheckboxes.length > 0) { 91 $currentCheckboxes.each(function() { 92 const $checkbox = $(this); 93 if ($checkbox.is(':checked')) { 94 const price = parseFloat($checkbox.data('price')); 95 if (!isNaN(price)) { 96 total += price; 97 count++; 98 // åªå¨æå¡é¡µéè¦æå»ºè¯¦ç»çæå¡å表 99 if (isOnServicePage) { 100 let label = $checkbox.closest('tr').find('label strong').text(); 101 selectedServices.push({ id: $checkbox.val(), name: label, price: price.toFixed(2) }); 102 } 103 } else { console.error("Invalid price data:", $checkbox.data('price'), "on checkbox:", $checkbox.val()); } 104 } 105 }); 106 }
106 else if (isOnServicePage && $('body').hasClass('show-details-on-load')) { 107 // 妿æå¡é¡µç´æ¥æ¾ç¤ºè¯¦æ ï¼ä»éèåæ®µæ¢å¤æ°æ® (ç¡®ä¿éèåæ®µåéå·²èµå¼) 108 if ($totalAmountHidden && $totalAmountHidden.length > 0) { 109 const preTotal = parseFloat($totalAmountHidden.val()); 110 if (!isNaN(preTotal)) { total = preTotal; } 111 } 112 if ($selectedServicesHidden && $selectedServicesHidden.length > 0) { 113 const preSelectedJson = $selectedServicesHidden.val(); 114 try { 115 selectedServices = JSON.parse(preSelectedJson || '[]'); 116 } catch (e) { console.error("Error parsing pre-selected services JSON:", e); selectedServices = []; } 117 count = selectedServices.length; // æ´æ° count 118 } 119 console.log("Using pre-filled data on service page load:", total, selectedServices); 120 } 121 122 // æ´æ°ä»·æ ¼æ¾ç¤º (ç¡®ä¿å ç´ åå¨) 123 if ($currentTotalPriceDisplay && $currentTotalPriceDisplay.length > 0) { 124 $currentTotalPriceDisplay.text(total.toFixed(2)); 125 } 126 127 // æ´æ°æé®ç¶æ (ç¡®ä¿æé®åå¨) 128 if ($currentSubmitButton && $currentSubmitButton.length > 0) { 129 $currentSubmitButton.prop('disabled', count <= 0); 130 // å¤çé误æç¤ºæ¾ç¤º/éè (ç¡®ä¿å ç´ åå¨) 131 if ($currentSelectionError && $currentSelectionError.length > 0) { 132 if (count <= 0 && !isOnHomePage) { // åªå¨æå¡é¡µè®¡ä»·ä¸º0æ¶æ¾ç¤ºé误 133 $currentSelectionError.slideDown(); 134 } else { 135 $currentSelectionError.slideUp(); 136 } 137 } 138 } 139 return { total: total, count: count, selected: selectedServices }; // è¿å count 140 } 141 142 // --- äºä»¶ç»å® --- 143 // 1. 为å¤éæ¡ç»å® change äºä»¶ (妿åå¨) 144 if ($currentCheckboxes && $currentCheckboxes.length > 0) { 145 $currentCheckboxes.on('change', updatePriceAndButtonState); 146 console.log("Checkbox 'change' event handler bound."); 147 } 148 149 // --- 页é¢å è½½æ¶è¿è¡ä¸æ¬¡è®¡ç®åç¶ææ´æ° --- 150 updatePriceAndButtonState(); // ç¡®ä¿åå§ç¶ææ£ç¡® 151 console.log("Initial price and button state updated."); 152 153 154 // =========================================================== 155 // --- ä» å¨æå¡é¡µ (ai_mba_service/index.php) æ§è¡çé»è¾ --- 156 // =========================================================== 157 if (isOnServicePage) { 158 console.log("Setting up Service Page specific logic."); 159 160 // 2. æå¡é¡µå é¨åæ¢ç "ä¸ä¸æ¥" æé®ç¹å»äºä»¶ (ç¡®ä¿æé®åå¨) 161 if ($currentSubmitButton && $currentSubmitButton.attr('id') === 'submit_request_button') { 162 $currentSubmitButton.off('click').on('click', function() { 163 console.log("Service Page internal 'Next' button clicked."); 164 let calculation = updatePriceAndButtonState(); // è·åææ°éæ© 165 // 使ç¨è¿åç count 夿 166 if (calculation.count <= 0) { 167 if ($currentSelectionError && $currentSelectionError.length > 0) $currentSelectionError.slideDown(); 168 return; 169 } 170 // å¡«å éèåæ®µ (ç¡®ä¿åéå·²å®ä¹ä¸å ç´ åå¨) 171 if($selectedServicesHidden && $selectedServicesHidden.length > 0) { 172 $selectedServicesHidden.val(JSON.stringify(calculation.selected)); 173 } 174 if($totalAmountHidden && $totalAmountHidden.length > 0) { 175 $totalAmountHidden.val(calculation.total.toFixed(2)); 176 } 177 // æ§è¡åæ¢ (ç¡®ä¿åéå·²å®ä¹ä¸å ç´ åå¨) 178 const $serviceSection = $('#service_selection_section'); // å¨å½æ°å éæ°è·å 179 if ($serviceSection.length > 0 && $detailsFormSection.length > 0) {
180 $serviceSection.slideUp(400, function() { 181 $detailsFormSection.slideDown(400); 182 $('html, body').animate({ scrollTop: $detailsFormSection.offset().top - 100 }, 500); 183 }); 184 } else { 185 console.error("Cannot toggle sections for 'Next' button, elements not found."); 186 } 187 }); 188 console.log("Service Page internal 'Next' button click handler bound."); 189 } else if ($currentSubmitButton) { 190 console.log("Submit button found, but ID is not 'submit_request_button'."); 191 } else { 192 console.log("Service Page internal 'Next' button not found."); 193 } 194 195 // 3. "è¿åä¿®æ¹æå¡" æé®ç¹å»äºä»¶ (ç¡®ä¿åéå·²å®ä¹ä¸å ç´ åå¨) 196 if ($backButton && $backButton.length > 0) { 197 $backButton.off('click').on('click', function() { 198 console.log("Service Page 'Back' button clicked."); 199 const $serviceSection = $('#service_selection_section'); // éæ°è·å 200 if ($detailsFormSection.length > 0 && $serviceSection.length > 0) { 201 $detailsFormSection.slideUp(400, function() { 202 $serviceSection.slideDown(400); 203 // å¯éæ»å¨ 204 // $('html, body').animate({ scrollTop: $serviceSection.offset().top - 100 }, 500); 205 }); 206 } else { 207 console.error("Cannot toggle sections for 'Back' button, elements not found."); 208 } 209 }); 210 console.log("Service Page 'Back' button click handler bound."); 211 } else { 212 console.log("Service Page 'Back' button not found."); 213 } 214 215 // 4. 详æ 表åæäº¤äºä»¶ (ç¡®ä¿åéå·²å®ä¹ä¸å ç´ åå¨) 216 if ($detailsForm && $detailsForm.length > 0) { 217 $detailsForm.on('submit', function(e) { 218 console.log("Details form submit event triggered."); 219 // --- å端éªè¯ --- 220 let isValid = true; 221 let errorMessages = []; 222 if($detailsFormError && $detailsFormError.length > 0) $detailsFormError.hide().empty(); // ç¡®ä¿é误æç¤ºå ç´ åå¨ 223 224 let title = $('#thesis_title').val().trim(); 225 let requirements = $('#requirements').val().trim(); 226 227 if (!title) { isValid = false; errorMessages.push('请填å论æé¢ç®æç ç©¶æ¹åã'); $('#thesis_title').addClass('is-invalid'); } else { $('#thesis_title').removeClass('is-invalid'); } 228 if (!requirements) { isValid = false; errorMessages.push('请填å详ç»è¦æ±ã'); $('#requirements').addClass('is-invalid'); } else { $('#requirements').removeClass('is-invalid'); } 229 230 // æä»¶å¤§å°éªè¯ 231 let fileInput = $('#attachment')[0]; 232 if (fileInput && fileInput.files.length > 0) { 233 let file = fileInput.files[0]; let maxSize = 10 * 1024 * 1024; 234 if (file.size > maxSize) { isValid = false; errorMessages.push('ä¸ä¼ çæä»¶ä¸è½è¶ è¿ 10MBã'); $('#attachment').addClass('is-invalid'); } else { $('#attachment').removeClass('is-invalid'); } 235 } else { $('#attachment').removeClass('is-invalid'); } 236 237 238 if (!isValid) { 239 e.preventDefault(); // 黿¢æäº¤ 240 let errorHtml = '<ul>'; errorMessages.forEach(msg => { errorHtml += '<li>' + msg + '</li>'; }); errorHtml += '</ul>'; 241 if($detailsFormError && $detailsFormError.length > 0) { 242 $detailsFormError.html(errorHtml).slideDown(); 243 // æ»å¨å°é误ä½ç½® 244 $('html, body').animate({ scrollTop: $detailsFormError.offset().top - 150 }, 300); 245 } else { 246 alert(errorMessages.join("\n")); // åå¤ alert 247 } 248 return false; 249 } 250 251 // éªè¯éè¿ï¼æ¾ç¤ºå è½½å¨ç» (ç¡®ä¿å ç´ åå¨) 252 if ($loadingOverlay && $loadingOverlay.length > 0) $loadingOverlay.fadeIn(); 253 else console.log("Loading overlay not found."); 254 }); 255 256 // è¾å ¥æ¶ç§»é¤éè¯¯æ ·å¼é»è¾ 257 $('#thesis_title, #requirements').on('input', function() { $(this).removeClass('is-invalid'); }); 258 $('#attachment').on('change', function() { $(this).removeClass('is-invalid'); /* 坿·»å æ´è¯¦ç»çæä»¶éªè¯ */ }); 259 console.log("Details form submit handler bound."); 260 } else { 261 console.log("Details form (#details_form) not found."); 262 } 263 264 265 // 5. 页é¢å è½½æ¶æ£æ¥æ¯å¦ç´æ¥æ¾ç¤ºè¯¦æ
266 if ($('body').hasClass('show-details-on-load')) { 267 console.log("Service Page: Detected 'show-details-on-load' class, adjusting view."); 268 const $serviceSection = $('#service_selection_section'); // éæ°è·å 269 if($serviceSection.length > 0) $serviceSection.hide(); 270 if($detailsFormSection.length > 0) { 271 // ç¡®ä¿å¨æ¾ç¤ºåè¿è¡æ»å¨ 272 if ($detailsFormSection.is(':hidden')) { 273 $detailsFormSection.show(); 274 } 275 // å»¶è¿æ»å¨ 276 setTimeout(function() { 277 if ($detailsFormSection.is(':visible')) { // 忬¡ç¡®è®¤å¯è§ 278 $('html, body').animate({ scrollTop: $detailsFormSection.offset().top - 100 }, 500); 279 } 280 }, 100); 281 } 282 } 283 284 } else if (isOnHomePage) { 285 // --- ä» å¨é¦é¡µæ§è¡çé»è¾ --- 286 console.log("Running Home Page specific logic."); 287 // é¦é¡µè¡¨åæäº¤éªè¯ (鲿¢æªéæå¡æ¶æäº¤) 288 if ($homeServiceSelectionForm && $homeServiceSelectionForm.length > 0) { 289 $homeServiceSelectionForm.on('submit', function(e){ 290 let calculation = updatePriceAndButtonState(); // è·åææ°ç¶æ 291 if (calculation.count <= 0) { // ä½¿ç¨ count 夿 292 e.preventDefault(); // 黿¢æäº¤ 293 if ($currentSelectionError && $currentSelectionError.length > 0) { 294 $currentSelectionError.slideDown(); 295 // æ·»å é卿æ (éè¦ animate.css æèªå®ä¹å¨ç») 296 // $currentSelectionError.addClass('animate__animated animate__shakeX'); 297 // setTimeout(() => $currentSelectionError.removeClass('animate__animated animate__shakeX'), 800); 298 } 299 console.log("Home page form submission prevented: No services selected."); 300 return false; 301 } 302 console.log("Home page form submitting..."); 303 // å 许æäº¤å° /ai_mba_service/index.php 304 }); 305 console.log("Home page form submit validation bound."); 306 } else { 307 console.warn("Home page form not found for submit binding."); 308 } 309 310 } 311 312 console.log("service_logic.js setup complete."); 313}); // <-- $(document).ready ç»æ
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.