daxu0403 7 年 前
コミット
59b494e3d5
1 ファイル変更51 行追加15 行削除
  1. 51 15
      lib/pages/order_taking_page.dart

+ 51 - 15
lib/pages/order_taking_page.dart

@@ -20,7 +20,7 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
   ScrollController _scrollController = ScrollController(); //初始化滚动轴监控对象
   List < OrderList > orderList = []; //订单列表
   bool hasNextPage = true;
-  List lineList = [];
+  List lineList = []; //线路列表
   String stationId;
   List < bool > checkStatusList = [];
   bool showLineStatus = true;
@@ -37,7 +37,7 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
         getOrderList(value, lineIdStr, page).then((resp) {
           if (resp.success && resp.code == 1) {
             setState(() {
-             orderList = resp.data.items;
+              orderList = resp.data.items;
               hasNextPage = resp.data.hasNextPage;
             });
           }
@@ -49,15 +49,16 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
         setState(() {
           showLineStatus = true;
         });
+        switchLine();
       }
       if (_scrollController.position.pixels == _scrollController.position.maxScrollExtent) {
         print('滑动到底部了');
-        if(hasNextPage){
+        if (hasNextPage) {
           setState(() {
-            page=++page;
+            page = ++page;
           });
           getOrderList(stationId, lineIdStr, page).then((resp) {
-          if (resp.success && resp.code == 1) {
+            if (resp.success && resp.code == 1) {
               setState(() {
                 orderList.addAll(resp.data.items);
                 hasNextPage = resp.data.hasNextPage;
@@ -117,6 +118,8 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
                       getLine(value);
                     }
                   });
+                } else {
+                  switchLine();
                 }
               }, )
           ]
@@ -141,7 +144,7 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
                       }
                       if (hasNextPage) {
                         return _getMoreWidget();
-                      }else{
+                      } else {
                         return _noMoreWidegt();
                       }
                     },
@@ -151,6 +154,7 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
                   setState(() {
                     showLineStatus = true;
                   });
+                  switchLine();
                 },
               ),
             ),
@@ -212,7 +216,6 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
         setState(() {
           checkStatusList[index] = !checked;
         });
-
       },
     );
   }
@@ -241,20 +244,20 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
     );
   }
 
-  Widget _noMoreWidegt(){
+  Widget _noMoreWidegt() {
     return Center(
       child: Padding(
         padding: EdgeInsets.all(10.0),
-        child:  Text(
-              '没有更多数据了...',
-              style: TextStyle(fontSize: 16.0),
-            ),
+        child: Text(
+          '没有更多数据了...',
+          style: TextStyle(fontSize: 16.0),
+        ),
       ),
     );
   }
 
   Future < Null > _onRefresh() async {
-   await getKey('stationId').then((value) {
+    await getKey('stationId').then((value) {
       getOrderList(value, lineIdStr, 1).then((resp) {
         setState(() {
           orderList = resp.data.items;
@@ -263,15 +266,48 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
     });
   }
 
-  void deleteOrder(val) {
+  void deleteOrder(val) { //确认接单后的操作
     setState(() {
       orderList.removeAt(val);
       if (orderList.length < 4) {
-
+        if (hasNextPage) {
+          setState(() {
+            page = ++page;
+          });
+          getOrderList(stationId, lineIdStr, page).then((resp) {
+            if (resp.success && resp.code == 1) {
+              setState(() {
+                orderList.addAll(resp.data.items);
+                hasNextPage = resp.data.hasNextPage;
+              });
+            }
+          });
+        }
       }
     });
   }
 
+  void switchLine() { //切换线路
+    setState(() {
+      orderList = [];
+      hasNextPage =true;
+    });
+    lineIdStr = '';
+    for (int i = 0; i < checkStatusList.length; i++) {
+      if (checkStatusList[i]) {
+        lineIdStr += lineList[i].id.toString() + ',';
+      }
+    }
+    lineIdStr = lineIdStr.substring(0, lineIdStr.length - 1);
+    getOrderList(stationId, lineIdStr, page).then((resp) {
+      if (resp.success && resp.code == 1) {
+        setState(() {
+          orderList = resp.data.items;
+          hasNextPage = resp.data.hasNextPage;
+        });
+      }
+    });
+  }
 }