Ver Fonte

修复船公司查询逻辑和实现滚动加载功能

后端修改:
- 修复船公司查询逻辑,直接关联Bus_CustomerCompany和Bus_Customer_CustomerType表
- 添加findByRecordStatus分页方法支持
- 移除不必要的Bus_CustomerCompanyBusiness表关联

前端修改:
- 实现船公司下拉框的滚动加载功能
- 添加分页参数和加载状态管理
- 添加滚动事件监听和自动加载更多数据
- 添加下拉框最大高度和滚动样式
heyiwen há 2 semanas atrás
pai
commit
abbc00e17f

+ 5 - 0
JavaBackend/src/main/java/com/lianda/backend/repository/BusCustomerCompanyRepository.java

@@ -30,6 +30,11 @@ public interface BusCustomerCompanyRepository extends JpaRepository<BusCustomerC
      */
     List<BusCustomerCompany> findByRecordStatus(Integer recordStatus);
     
+    /**
+     * 根据记录状态查找客户公司(分页)
+     */
+    Page<BusCustomerCompany> findByRecordStatus(Integer recordStatus, Pageable pageable);
+    
     /**
      * 根据名称和记录状态查找客户公司
      */

+ 9 - 33
JavaBackend/src/main/java/com/lianda/backend/service/CommonDataService.java

@@ -109,29 +109,18 @@ public class CommonDataService {
                 .map(BusCustomerCustomerType::getCustomerId)
                 .collect(Collectors.toSet());
 
-        // 查询所有有效的船公司业务记录(RecordStatus=1)
-        List<BusCustomerCompanyBusiness> validBusinessRecords = busCustomerCompanyBusinessRepository.findAll().stream()
-                .filter(business -> business.getRecordStatus() != null && business.getRecordStatus() == 1)
-                .filter(business -> shippingCompanyCustomerIds.contains(business.getCustomerCompanyId()))
-                .collect(Collectors.toList());
-
-        // 获取这些业务记录对应的客户公司ID
-        Set<String> customerCompanyIds = validBusinessRecords.stream()
-                .map(BusCustomerCompanyBusiness::getCustomerCompanyId)
-                .collect(Collectors.toSet());
-
-        // 查询对应的客户公司信息(支持模糊搜索)
-        List<BusCustomerCompany> allCompanies;
+        // 查询对应的客户公司信息(支持模糊搜索和分页)
+        Page<BusCustomerCompany> companyPage;
         if (companyName != null && !companyName.isEmpty()) {
-            allCompanies = busCustomerCompanyRepository.findByNameContainingAndRecordStatus(
-                    companyName, 1, Pageable.unpaged()).getContent();
+            companyPage = busCustomerCompanyRepository.findByNameContainingAndRecordStatus(
+                    companyName, 1, pageable);
         } else {
-            allCompanies = busCustomerCompanyRepository.findAll();
+            companyPage = busCustomerCompanyRepository.findByRecordStatus(1, pageable);
         }
 
         // 过滤出船公司类型的数据并转换为DTO
-        List<ShippingCompanyDTO> filteredCompanies = allCompanies.stream()
-                .filter(company -> customerCompanyIds.contains(company.getCustomerCompanyId()))
+        List<ShippingCompanyDTO> filteredCompanies = companyPage.getContent().stream()
+                .filter(company -> shippingCompanyCustomerIds.contains(company.getCustomerCompanyId()))
                 .map(company -> new ShippingCompanyDTO(
                         company.getCustomerCompanyId(),
                         company.getName(),
@@ -140,24 +129,11 @@ public class CommonDataService {
                         company.getMobile()))
                 .collect(Collectors.toList());
 
-        // 手动分页
-        int pageSize = pageable.getPageSize();
-        int currentPage = pageable.getPageNumber();
-        int start = currentPage * pageSize;
-        int end = Math.min(start + pageSize, filteredCompanies.size());
-
-        List<ShippingCompanyDTO> pageContent;
-        if (filteredCompanies.isEmpty() || start >= filteredCompanies.size()) {
-            pageContent = new ArrayList<>();
-        } else {
-            pageContent = filteredCompanies.subList(start, end);
-        }
-
         // 创建新的Page对象
         return new org.springframework.data.domain.PageImpl<>(
-                pageContent,
+                filteredCompanies,
                 pageable,
-                filteredCompanies.size()
+                companyPage.getTotalElements()
         );
     }
 }

+ 62 - 3
vue-frontend/src/components/PilotPlan.vue

@@ -86,6 +86,7 @@
               filterable
               :loading="shipCompanyLoading"
               @visible-change="handleShipCompanyVisibleChange"
+              popper-class="ship-company-select-dropdown"
             >
               <el-option
                 v-for="company in shipCompanyList"
@@ -300,6 +301,10 @@ export default {
       portList: [],
       shipCompanyList: [],
       shipCompanyLoading: false,
+      shipCompanyPage: 1,
+      shipCompanyPageSize: 10,
+      shipCompanyTotal: 0,
+      shipCompanyHasMore: true,
       currentPage: 1,
       pageSize: 20,
       total: 0,
@@ -370,10 +375,12 @@ export default {
     this.$nextTick(() => {
       this.calculateTableHeight();
       window.addEventListener('resize', this.calculateTableHeight);
+      this.addShipCompanyScrollListener();
     });
   },
   beforeUnmount() {
     window.removeEventListener('resize', this.calculateTableHeight);
+    this.removeShipCompanyScrollListener();
   },
   methods: {
     calculateTableHeight() {
@@ -402,11 +409,23 @@ export default {
           console.error('获取港口列表失败:', error);
         });
     },
-    getShipCompanyList() {
+    getShipCompanyList(isLoadMore = false) {
       this.shipCompanyLoading = true;
-      this.$axios.get('/api/ship-company/list')
+      this.$axios.get('/api/ship-company/list', {
+        params: {
+          page: this.shipCompanyPage,
+          pageSize: this.shipCompanyPageSize
+        }
+      })
         .then(response => {
-          this.shipCompanyList = response.data.content || [];
+          const newCompanies = response.data.content || [];
+          if (isLoadMore) {
+            this.shipCompanyList = [...this.shipCompanyList, ...newCompanies];
+          } else {
+            this.shipCompanyList = newCompanies;
+          }
+          this.shipCompanyTotal = response.data.totalElements || 0;
+          this.shipCompanyHasMore = this.shipCompanyList.length < this.shipCompanyTotal;
         })
         .catch(error => {
           console.error('获取船公司列表失败:', error);
@@ -418,9 +437,39 @@ export default {
     },
     handleShipCompanyVisibleChange(visible) {
       if (visible && this.shipCompanyList.length === 0) {
+        this.shipCompanyPage = 1;
         this.getShipCompanyList();
       }
     },
+    handleShipCompanyScroll(event) {
+      const { target } = event;
+      const scrollBottom = target.scrollHeight - target.scrollTop - target.clientHeight;
+      
+      if (scrollBottom < 10 && this.shipCompanyHasMore && !this.shipCompanyLoading) {
+        this.shipCompanyPage++;
+        this.getShipCompanyList(true);
+      }
+    },
+    addShipCompanyScrollListener() {
+      this.$nextTick(() => {
+        const dropdown = document.querySelector('.ship-company-select-dropdown');
+        if (dropdown) {
+          const dropdownWrap = dropdown.querySelector('.el-select-dropdown__wrap');
+          if (dropdownWrap) {
+            dropdownWrap.addEventListener('scroll', this.handleShipCompanyScroll);
+          }
+        }
+      });
+    },
+    removeShipCompanyScrollListener() {
+      const dropdown = document.querySelector('.ship-company-select-dropdown');
+      if (dropdown) {
+        const dropdownWrap = dropdown.querySelector('.el-select-dropdown__wrap');
+        if (dropdownWrap) {
+          dropdownWrap.removeEventListener('scroll', this.handleShipCompanyScroll);
+        }
+      }
+    },
     getPilotPlans() {
       if (this.loading) return;
       
@@ -720,6 +769,16 @@ h3 {
   font-size: 15px;
 }
 
+.ship-company-select-dropdown {
+  max-height: 300px;
+  overflow-y: auto;
+}
+
+.ship-company-select-dropdown .el-select-dropdown__wrap {
+  max-height: 300px;
+  overflow-y: auto;
+}
+</style>
 .preview-dialog {
   --el-dialog-margin-top: 5vh;
 }