${product?.storeName}
-
+
`; cartTableBody.insertAdjacentHTML('beforeend', newRow); }); let productRows = document.querySelectorAll('.uni-sample-table tbody tr'); productRows.forEach(row => { let productCountInput = row.querySelector('.cart-plus-minus-box'); let decButton = row.querySelector('.dec.qtybutton'); let incButton = row.querySelector('.inc.qtybutton'); let productUuidInput = row.querySelector('#productUuid').value; let closeButton = row.querySelector('.pro-remove a'); decButton.addEventListener('click', () => { let currentCount = parseInt(productCountInput.value); if (currentCount > 0) { currentCount--; productCountInput.value = currentCount; updateProductList(currentCount,cookieValue,productUuidInput); } }); incButton.addEventListener('click', () => { let currentCount = parseInt(productCountInput.value); currentCount++; productCountInput.value = currentCount; updateProductList( currentCount,cookieValue,productUuidInput); }); closeButton.addEventListener('click', function (e) { e.preventDefault(); removeProductByUUID(productUuidInput, cookieValue) constructTable(getSampleList()); }); }); } //提交申請(qǐng) function sampleApply() { $("#sampleForm").prop("disabled", true); let formObject = {}; $.each($("#sampleForm").serializeArray(), function(i, field) { formObject[field.name] = field.value; }); let myCookie = getCookie("l"); let productList = getSampleList(); if(productList.length > 0){ let productListJson = JSON.stringify(productList); let sendData = { ...formObject, productList: productListJson }; let jsonData = JSON.stringify(sendData); let online=myCookie=="zh_CN"?"申請(qǐng)成功":"Application is successful"; $.ajax({ url: BaseUrl+"/sample/apply", type: "POST", data: jsonData, dataType: "json", contentType: 'application/json', async: true, headers: { 'Authorization': token }, success: function(response) { deleteCookie(getCookie("l")+"_sampleList","/") alert(online); location.href = "/sample/list.html"; }, error: function(xhr, status, error) { console.error("請(qǐng)求失敗:", error); } }); }else{ let online=myCookie=="zh_CN"?"產(chǎn)品信息為空,請(qǐng)先選擇需要申請(qǐng)的樣品!":"Product information is blank, please select the sample to apply for first!"; alert(online); } return false; } function personalInfo(token){ if (!token) { window.location.href = '/news/toLogin.html'; return; } $.ajax({ url: BaseUrl+'/news/customer/info', type: 'GET', dataType: 'json', headers: { 'Authorization': token }, success: function(data) { // 獲取表單元素 const $form = $('#loginForm'); if (!$form.length) return; var res = data.data // 遍歷表單字段并賦值(根據(jù)name屬性匹配) $form.find('input, textarea, select').each(function() { const fieldName = $(this).attr('name'); // 如果數(shù)據(jù)中存在對(duì)應(yīng)字段,則填充值 if (res[fieldName] !== undefined && res[fieldName] !== null) { $(this).val(res[fieldName]); } }); }, error: function(xhr, status, error) { console.error('獲取數(shù)據(jù)失敗:', error); } }); let isValid = formValid(); return isValid; } /**/ function sampleDownloadList(token){ if (!token) { window.location.href = '/news/toLogin.html'; return; } $.ajax({ url: BaseUrl+'/news/customer/download', // 替換為實(shí)際接口URL type: 'GET', dataType: 'json', headers: { 'Authorization': token }, success: function(data) { // 獲取列表 var res = data.data if(!res){ return; } const tbodyElement = document.getElementById("sampleDownload") // 清空現(xiàn)有內(nèi)容 tbodyElement.innerHTML = ''; // 遍歷數(shù)據(jù)生成 HTML res.forEach(file => { // 格式化日期(對(duì)應(yīng) Thymeleaf 的#dates.format) let formattedStart = ''; let formattedEnd = ''; // 當(dāng) status 不為 0 時(shí)才顯示有效期 if (file.status !== 0) { // 處理 startTime:yyyy-MM-dd 日 const startTime = new Date(file.startTime); formattedStart = `${startTime.getFullYear()}-${ (startTime.getMonth() + 1).toString().padStart(2, '0') }-${ startTime.getDate().toString().padStart(2, '0') }日`; // 處理 endTime:yyyy 年 MM 月 dd 日 const endTime = new Date(file.endTime); formattedEnd = `${endTime.getFullYear()}年${ (endTime.getMonth() + 1).toString().padStart(2, '0') }月${ endTime.getDate().toString().padStart(2, '0') }日`; } // 處理狀態(tài)文本(對(duì)應(yīng) Thymeleaf 的 th:if 判斷) let statusText = ''; if (file.status === 0) { statusText = downOnCheck; } else if (file.status === -1) { statusText = downCheckNo; } else if (file.status === 1) { statusText = downCheckYes; } // 處理下載鏈接(status 為 0 時(shí)置空) const linkDisplay = file.status === 0 ? '' : `${file.documentUrl}`; // 創(chuàng)建行 HTML const row = ` ${file.productName}/${file.documentName} ${linkDisplay} ${formattedStart} -- ${formattedEnd} ${statusText} `; // 插入到 tbody 中 tbodyElement.innerHTML += row; }); }, error: function(xhr, status, error) { console.error('獲取數(shù)據(jù)失敗:', error); } }) } function sampleProductList(token){ if (!token) { window.location.href = '/news/toLogin.html'; return; } $.ajax({ url: BaseUrl+'/news/sample/productList', // 替換為實(shí)際接口URL type: 'GET', dataType: 'json', headers: { 'Authorization': token }, success: function(data) { // 獲取列表 var res = data.data if(!res){ return; } const tbodyElement = document.getElementById("sampleProductList") // 清空現(xiàn)有內(nèi)容 tbodyElement.innerHTML = ''; // 遍歷數(shù)據(jù)生成HTML res.forEach(product => { let statusText = ''; switch(product.status) { case -1: statusText = sampleStatusNo; break; case 0: statusText = sampleOnCheck; break; case 1: statusText = sampleStatusWait; break; case 2: case 3: statusText = sampleStatusSuc; break; default: statusText = '未知狀態(tài)'; // 兜底處理,避免空文本 } const productRow = ` Product ${product.barCode || ''} ${product.storeName || ''} ${product.productCount || 0} ${statusText} `; tbodyElement.innerHTML += productRow; }); }, error: function(xhr, status, error) { console.error('獲取數(shù)據(jù)失敗:', error); } }) } function formValid() { const form = document.getElementById('loginForm'); const requiredFields = form.querySelectorAll('input[required]'); requiredFields.forEach(field => { const value = field.value.trim(); if (value === '') { return false; } }); return true; }