fix_map
This commit is contained in:
parent
932cc7a06a
commit
611c83304a
@ -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');
|
||||
|
||||
@ -111,6 +111,7 @@ async function loadAllTrialPeriods() {
|
||||
|
||||
renderTrialPeriodsTable();
|
||||
updateTrialPagination();
|
||||
renderExpiryWarnings();
|
||||
} catch (error) {
|
||||
console.error('Error loading trial periods:', error);
|
||||
trialPeriodsData = [];
|
||||
|
||||
@ -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{}{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user