chengjie 3 months ago
parent
commit
8f1afc0f81
2 changed files with 104 additions and 3 deletions
  1. 102 1
      pages/main/mainlist.js
  2. 2 2
      pages/main/mainlist.wxml

+ 102 - 1
pages/main/mainlist.js

@@ -1372,8 +1372,109 @@ Page({
1372 1372
       }
1373 1373
     }
1374 1374
   },
1375
-  selectThisFunc:function(){
1375
+  selectThisFunc:function(e){
1376 1376
 
1377
+    let upOrDown=e.currentTarget.dataset.selecttype;
1378
+    
1379
+    var that = this;
1380
+
1381
+    var list = that.data.List;
1382
+    var firstSelectedIndex = -1;
1383
+    var lastSelectedIndex = -1;
1384
+    
1385
+    // 找出第一个和最后一个已选中的项目索引
1386
+    for(var i = 0; i < list.length; i++) {
1387
+      if(list[i].Selected) {
1388
+        if(firstSelectedIndex === -1) firstSelectedIndex = i;
1389
+        lastSelectedIndex = i;
1390
+      }
1391
+    }
1392
+    
1393
+    if(firstSelectedIndex === -1) return; // 没有选中项,不执行操作
1394
+    
1395
+    // 创建选择器查询
1396
+    var query = wx.createSelectorQuery();
1397
+    
1398
+    // 获取所有列表项的位置信息
1399
+    for(var i = 0; i < list.length; i++) {
1400
+      query.select('#scroll-' + i).boundingClientRect();
1401
+    }
1402
+    
1403
+    // 获取视口信息
1404
+    query.selectViewport().boundingClientRect();
1405
+    
1406
+    query.exec(function(res) {
1407
+      if(!res || res.length <= list.length) return;
1408
+      
1409
+      var screenHeight = res[res.length - 1].height;
1410
+      var visibleItems = [];
1411
+      
1412
+      // 找出当前在视口中可见的项
1413
+      for(var i = 0; i < list.length; i++) {
1414
+        var item = res[i];
1415
+        if(item && item.top < screenHeight && item.bottom > 0) {
1416
+          visibleItems.push({
1417
+            index: i,
1418
+            top: item.top,
1419
+            bottom: item.bottom
1420
+          });
1421
+        }
1422
+      }
1423
+      
1424
+      if(visibleItems.length === 0) return;
1425
+      
1426
+      // 根据按钮类型决定选择范围
1427
+      if(that.data.IsShowSelectThisUp) {
1428
+        // 上按钮 - 选择从视口中最上面的项到第一个已选项之间的所有项
1429
+        var topVisibleIndex = visibleItems[0].index;
1430
+        
1431
+        // 如果顶部可见项在第一个已选项之前,选择这个范围内的所有项
1432
+        if(topVisibleIndex < firstSelectedIndex) {
1433
+          for(var i = topVisibleIndex; i <= firstSelectedIndex; i++) {
1434
+            list[i].Selected = true;
1435
+          }
1436
+        } 
1437
+        // 否则选择从第一个已选项到顶部可见项之间的所有项
1438
+        else {
1439
+          for(var i = firstSelectedIndex; i <= topVisibleIndex; i++) {
1440
+            list[i].Selected = true;
1441
+          }
1442
+        }
1443
+      } else if(that.data.IsShowSelectThisDown) {
1444
+        // 下按钮 - 选择从最后一个已选项到视口中最下面的项之间的所有项
1445
+        var bottomVisibleIndex = visibleItems[visibleItems.length - 1].index;
1446
+        
1447
+        // 如果底部可见项在最后一个已选项之后,选择这个范围内的所有项
1448
+        if(bottomVisibleIndex > lastSelectedIndex) {
1449
+          for(var i = lastSelectedIndex; i <= bottomVisibleIndex; i++) {
1450
+            list[i].Selected = true;
1451
+          }
1452
+        } 
1453
+        // 否则选择从底部可见项到最后一个已选项之间的所有项
1454
+        else {
1455
+          for(var i = bottomVisibleIndex; i <= lastSelectedIndex; i++) {
1456
+            list[i].Selected = true;
1457
+          }
1458
+        }
1459
+      }
1460
+      
1461
+      // 计算选中的总数
1462
+      var selectedCount = 0;
1463
+      for(var i = 0; i < list.length; i++) {
1464
+        if(list[i].Selected) {
1465
+          selectedCount++;
1466
+        }
1467
+      }
1468
+      
1469
+      // 更新数据
1470
+      that.setData({
1471
+        List: list,
1472
+        SelectedCount: selectedCount
1473
+      });
1474
+      
1475
+      // 更新按钮显示状态
1476
+      that.checkSelectedItemsPosition(firstSelectedIndex, lastSelectedIndex);
1477
+    });
1377 1478
   },
1378 1479
   //保存多选数据
1379 1480
   saveMultipleData:function(mData,list){

+ 2 - 2
pages/main/mainlist.wxml

@@ -148,10 +148,10 @@
148 148
   
149 149
     <view class="panelMore" wx:if="{{HasPageDelete && CardType==-2}}" bindtap='gotoNextPageDelete' data-id="{{List[List.length-1].MiaoguoCardID}}">更多</view>
150 150
     <view class="panelEnd" wx:if="{{!HasPageDelete && List.length>0 && CardType==-2}}">到底了</view>
151
-    <view class="SelectThisUpCss FlexRow" wx:if="{{IsShowSelectThisUp}}" catch:tap="selectThisFunc">
151
+    <view class="SelectThisUpCss FlexRow" wx:if="{{IsShowSelectThisUp}}" catch:tap="selectThisFunc" data-selecttype="up">
152 152
       <image src="../images/ArrowUp1.png" class="ArrowUp1"></image>选择到这里
153 153
     </view>
154
-    <view class="SelectThisUpCss SelectThisDownCss FlexRow" wx:if="{{IsShowSelectThisDown}}" catch:tap="selectThisFunc">
154
+    <view class="SelectThisUpCss SelectThisDownCss FlexRow" wx:if="{{IsShowSelectThisDown}}" catch:tap="selectThisFunc" data-selecttype="down">
155 155
       <image src="../images/ArrowDown1.png" class="ArrowUp1"></image>选择到这里
156 156
     </view>
157 157
   </view>