Selaa lähdekoodia

接单列表重新更新路线逻辑

daxu0403 7 vuotta sitten
vanhempi
commit
f06aafc1dd
2 muutettua tiedostoa jossa 77 lisäystä ja 62 poistoa
  1. 74 56
      lib/pages/order_taking_page.dart
  2. 3 6
      lib/util/api.dart

+ 74 - 56
lib/pages/order_taking_page.dart

@@ -32,19 +32,14 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
   @override
   void initState() {
     super.initState();
-    getKey('stationId').then((value) {
-      setState(() {
-        stationId = value;
-      });
-      getLine(value).then((childValue) {
-        getOrderList(value, lineIdStr, page).then((resp) {
-          if (isNotError(context, resp)) {
-            setState(() {
-              orderList = OrderListObj.fromJson(resp.data).data.items;
-              hasNextPage = OrderListObj.fromJson(resp.data).data.hasNextPage;
-            });
-          }
-        });
+    getLine().then((childValue) {
+      getOrderList(lineIdStr, page).then((resp) {
+        if (isNotError(context, resp)) {
+          setState(() {
+            orderList = OrderListObj.fromJson(resp.data).data.items;
+            hasNextPage = OrderListObj.fromJson(resp.data).data.hasNextPage;
+          });
+        }
       });
     });
     _scrollController.addListener(() {
@@ -58,15 +53,15 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
         if (hasNextPage && loadMoreOrder) {
           loadMoreOrder = false;
           page = ++page;
-          getOrderList(stationId, lineIdStr, page).then((resp) {
+          getOrderList(lineIdStr, page).then((resp) {
             if (isNotError(context, resp)) {
-              OrderListObj tempObj =OrderListObj.fromJson(resp.data);
+              OrderListObj tempObj = OrderListObj.fromJson(resp.data);
               setState(() {
                 orderList.addAll(tempObj.data.items);
                 hasNextPage = tempObj.data.hasNextPage;
               });
               loadMoreOrder = true;
-            }else{
+            } else {
               loadMoreOrder = true;
             }
           });
@@ -76,21 +71,39 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
   }
 
 
-  Future getLine(String value) async {
-    await getLineFromStation(value).then((resp) {
+  Future getLine() async {
+    await getAllLine().then((resp) {
       if (isNotError(context, resp)) {
         setState(() {
           checkStatusList = [];
           lineList = StationLine.fromJson(resp.data).data;
-          for (int i = 0; i < lineList.length; i++) {
-            checkStatusList.add(true);
-            if (i < lineList.length - 1) {
-              lineIdStr += lineList[i].id.toString() + ',';
+          getKey('lineIdStr').then((value) {
+            if (value != null) {
+              for (int i = 0; i < lineList.length; i++) {
+                if (value.indexOf(lineList[i].id.toString()) != -1) {
+                  checkStatusList.add(true);
+                } else {
+                  checkStatusList.add(false);
+                }
+                if (i < lineList.length - 1) {
+                  lineIdStr += lineList[i].id.toString() + ',';
+                } else {
+                  lineIdStr += lineList[i].id.toString();
+                }
+              }
+              print(checkStatusList);
             } else {
-              lineIdStr += lineList[i].id.toString();
+              for (int i = 0; i < lineList.length; i++) {
+                checkStatusList.add(true);
+                if (i < lineList.length - 1) {
+                  lineIdStr += lineList[i].id.toString() + ',';
+                } else {
+                  lineIdStr += lineList[i].id.toString();
+                }
+              }
             }
-          }
-          stationId = value;
+          });
+
         });
         return lineIdStr;
       }
@@ -117,11 +130,7 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
                   showLineStatus = !showLineStatus;
                 });
                 if (!showLineStatus) {
-                  getKey('stationId').then((value) {
-                    if (stationId != value) {
-                      getLine(value);
-                    }
-                  });
+                  getLine();
                 } else {
                   switchLine(context);
                 }
@@ -199,13 +208,13 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
       child: Container(
         height: ScreenUtil.getInstance().setHeight(80),
         decoration: BoxDecoration(
-          border: BorderDirectional(bottom: BorderSide(color: Colors.white,width: 0.5))
+          border: BorderDirectional(bottom: BorderSide(color: Colors.white, width: 0.5))
         ),
         child: Row(
           children: < Widget > [
             Padding(
               padding: EdgeInsets.only(right: 10),
-              child: checked ? Icon(Icons.check, color: Colors.white, ) : Icon(Icons.check, color: Color.fromRGBO(0, 0, 0, 0.0)),
+              child: checked ? Icon(Icons.check, color: Colors.white, ) : Icon(Icons.check,color: Color.fromRGBO(0, 0, 0, 0.0,)),
             ),
             Expanded(
               flex: 1,
@@ -260,19 +269,18 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
     );
   }
 
-  Future  _onRefresh() async{
-    var stationId;
+  Future _onRefresh() async {
     await getKey('stationId').then((value) {
       stationId = value;
       page = 1;
     });
-    await getOrderList(stationId, lineIdStr, page).then((resp) {
-        if(isNotError(context, resp)){
-          setState(() {
-            orderList = OrderListObj.fromJson(resp.data).data.items;
-          });
-        }
-      });
+    await getOrderList(lineIdStr, page).then((resp) {
+      if (isNotError(context, resp)) {
+        setState(() {
+          orderList = OrderListObj.fromJson(resp.data).data.items;
+        });
+      }
+    });
   }
 
   void deleteOrder(val) { //确认接单后的操作
@@ -283,7 +291,7 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
           setState(() {
             page = ++page;
           });
-          getOrderList(stationId, lineIdStr, page).then((resp) {
+          getOrderList(lineIdStr, page).then((resp) {
             if (resp.success && resp.code == 1) {
               setState(() {
                 orderList.addAll(resp.data.items);
@@ -303,20 +311,30 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
         lineIdStr += lineList[i].id.toString() + ',';
       }
     }
+    if (lineIdStr == '') {
+      setState(() {
+        orderList = [];
+        hasNextPage = false;
+      });
+       setKey('lineIdStr', lineIdStr);
+      return;
+    }
     lineIdStr = lineIdStr.substring(0, lineIdStr.length - 1);
-    if(oldLineIdStr==lineIdStr) return;
+
+    if (oldLineIdStr == lineIdStr) return;
     setState(() {
       orderList = [];
-      hasNextPage =true;
+      hasNextPage = true;
     });
-    getOrderList(stationId, lineIdStr, page).then((resp) {
-      if(isNotError(context, resp)){
-          OrderListObj tempObj =OrderListObj.fromJson(resp.data);
-          setState(() {
-            orderList = tempObj.data.items;
-            hasNextPage = tempObj.data.hasNextPage;
-          });
-          oldLineIdStr =lineIdStr;
+    getOrderList(lineIdStr, page).then((resp) {
+      if (isNotError(context, resp)) {
+        OrderListObj tempObj = OrderListObj.fromJson(resp.data);
+        setState(() {
+          orderList = tempObj.data.items;
+          hasNextPage = tempObj.data.hasNextPage;
+        });
+        oldLineIdStr = lineIdStr;
+        setKey('lineIdStr', lineIdStr);
       }
     });
   }
@@ -379,7 +397,7 @@ class _OrderCardContainerState extends State < OrderCardContainer > with SingleT
             orderItem('货物名称', widget.order.goods, 15),
             orderItem('货物件数', '${widget.order.goodsQuantity}件', 30),
             orderCutLine(),
-            orderBtn(context, animationStatus, controller, str,widget.order.orderNo),
+            orderBtn(context, animationStatus, controller, str, widget.order.orderNo),
             AnimatedOpen(animation: animation, openInfo: widget.order, )
           ],
         ),
@@ -392,7 +410,7 @@ class _OrderCardContainerState extends State < OrderCardContainer > with SingleT
     super.dispose();
   }
 
-  Widget orderBtn(BuildContext context, bool animationStatus, AnimationController controller, String str,String orderNo) {
+  Widget orderBtn(BuildContext context, bool animationStatus, AnimationController controller, String str, String orderNo) {
     return Container(
       margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
       child: Row(
@@ -437,8 +455,8 @@ class _OrderCardContainerState extends State < OrderCardContainer > with SingleT
                   return new LoadingDialog( //调用对话框
                     text: '是否确认接单', childCallback: (val) {
                       if (val) {
-                        orderReception(orderNo).then((resp){
-                          if(isNotError(context, resp)){
+                        orderReception(orderNo).then((resp) {
+                          if (isNotError(context, resp)) {
                             widget.callback(widget.index);
                           }
                         });

+ 3 - 6
lib/util/api.dart

@@ -17,9 +17,8 @@ Future checkToken(String token) async{
 }
 
 //获取接单列表
-Future getOrderList(String stationId, String lineId, int page) async {
+Future getOrderList(String lineId, int page) async {
   var response = await Http().post('app/order/wait_order_list_pages', data: {
-    'stationId': stationId,
     'lineId': lineId,
     'limit': limit,
     'page': page
@@ -35,10 +34,8 @@ Future getStationList() async {
 }
 
 //根据站点获取线路
-Future getLineFromStation(String stationId) async {
-  var response = await Http().get('app/station/station_line_all_list', data: {
-    'stationId': stationId
-  });
+Future getAllLine() async {
+  var response = await Http().get('app/line/line_all');
   return response;
 }