From 611c83304a748a6f0624da9b88751f64ab64ce09 Mon Sep 17 00:00:00 2001 From: "hangyu.tao" Date: Wed, 14 Jan 2026 20:31:08 +0800 Subject: [PATCH] fix_map --- frontend/js/main.js | 21 ++++++++------------- frontend/js/trial-periods-page.js | 1 + internal/handlers/followup_handler.go | 26 +++++++++----------------- 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/frontend/js/main.js b/frontend/js/main.js index d45408b..17545d7 100644 --- a/frontend/js/main.js +++ b/frontend/js/main.js @@ -397,20 +397,15 @@ document.addEventListener('DOMContentLoaded', function () { pageTitle.textContent = '客户试用时间'; currentSection = 'trialPeriods'; - console.log('loadCustomersForDropdown exists?', typeof loadCustomersForDropdown); - if (typeof loadCustomersForDropdown === 'function') { - console.log('Calling loadCustomersForDropdown'); - loadCustomersForDropdown(); + // Load customers first, then trial periods + if (typeof loadCustomersForDropdown === 'function' && typeof loadAllTrialPeriods === 'function') { + console.log('Loading customers first, then trial periods'); + loadCustomersForDropdown().then(() => { + console.log('Customers loaded, now loading trial periods'); + loadAllTrialPeriods(); + }); } else { - console.error('loadCustomersForDropdown is not a function!'); - } - - console.log('loadAllTrialPeriods exists?', typeof loadAllTrialPeriods); - if (typeof loadAllTrialPeriods === 'function') { - console.log('Calling loadAllTrialPeriods'); - loadAllTrialPeriods(); - } else { - console.error('loadAllTrialPeriods is not a function!'); + console.error('Required functions not available!'); } } else if (section === 'dashboard') { dashboardSection.classList.add('active'); diff --git a/frontend/js/trial-periods-page.js b/frontend/js/trial-periods-page.js index a436ee6..5e7e7a8 100644 --- a/frontend/js/trial-periods-page.js +++ b/frontend/js/trial-periods-page.js @@ -111,6 +111,7 @@ async function loadAllTrialPeriods() { renderTrialPeriodsTable(); updateTrialPagination(); + renderExpiryWarnings(); } catch (error) { console.error('Error loading trial periods:', error); trialPeriodsData = []; diff --git a/internal/handlers/followup_handler.go b/internal/handlers/followup_handler.go index 11c6023..86f5c89 100644 --- a/internal/handlers/followup_handler.go +++ b/internal/handlers/followup_handler.go @@ -277,28 +277,20 @@ func (h *FollowUpHandler) GetCustomerList(w http.ResponseWriter, r *http.Request CustomerName string `json:"customerName"` } - // Use a map to deduplicate customers by name - customerMap := make(map[string]CustomerInfo) + // Return all customers (including duplicates with same name but different IDs) + // This is needed so that trial periods can map all customer IDs to names + var customerList []CustomerInfo for _, customer := range customers { if customer.CustomerName != "" { - // Only keep the first occurrence of each customer name - if _, exists := customerMap[customer.CustomerName]; !exists { - customerMap[customer.CustomerName] = CustomerInfo{ - ID: customer.ID, - CustomerName: customer.CustomerName, - } - fmt.Printf("DEBUG: Added customer: ID=%s, Name=%s\n", customer.ID, customer.CustomerName) - } + customerList = append(customerList, CustomerInfo{ + ID: customer.ID, + CustomerName: customer.CustomerName, + }) + fmt.Printf("DEBUG: Added customer: ID=%s, Name=%s\n", customer.ID, customer.CustomerName) } } - // Convert map to slice - var customerList []CustomerInfo - for _, customer := range customerMap { - customerList = append(customerList, customer) - } - - fmt.Printf("DEBUG: Total unique customer list items: %d\n", len(customerList)) + fmt.Printf("DEBUG: Total customer list items: %d\n", len(customerList)) w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(map[string]interface{}{