Browse Source

8.3更新主页轨迹接口

jyj 4 years ago
parent
commit
d984984414

+ 65 - 19
lib/internal/bbs/page/bbs_page.dart

@@ -1,4 +1,4 @@
-import 'dart:async';
+
 
 // import 'package:amap_all_fluttify/amap_all_fluttify.dart';
 import 'package:amap_location_flutter_plugin/amap_location_flutter_plugin.dart';
@@ -37,6 +37,7 @@ import 'package:liftmanager/internal/news/news_router.dart';
 import 'package:uni_links/uni_links.dart';
 import 'package:liftmanager/utils/theme_utils.dart';
 import 'package:fluwx/fluwx.dart' as fluwx;
+import 'dart:async';
 
 class BbsPage extends StatefulWidget {
   @override
@@ -54,7 +55,6 @@ class BbsPageState extends BasePageState<BbsPage, NewsListPresenter>
   StreamSubscription<Map<String, Object>> _locationListener;
   Map<String, Object> _locationResult;
   int _index = 0;
-  Timer _timer;
   String _keyword;
   int _page = 1;
   List<String> menuTitle = ["案例中心", "视频学堂", "在线商城", "招聘专区", "资料库"];
@@ -124,17 +124,12 @@ class BbsPageState extends BasePageState<BbsPage, NewsListPresenter>
         _locationPlugin.stopLocation();
         _locationResult = result;
 //        address latitude longitude
-        _locationResult.forEach((key, value) {
-          if(key == 'city'){
-            cityName = '$value';
-            setState(() {
-
-            });
-          }
-          print(111);
-          print('key:$key :');
-          print('value:$value :');
-        });
+        lat = _locationResult["latitude"];
+        lng = _locationResult["longitude"];
+        cityName = _locationResult["city"];
+        if(FlutterStars.SpUtil.getString(Constant.userId) != "-1") {
+          isDelayAddress();
+        }
       });
     });
 
@@ -173,8 +168,25 @@ class BbsPageState extends BasePageState<BbsPage, NewsListPresenter>
     setState(() {});
   }
 
-  
+  Timer _timer;
+  void startTimer(int intervalTime) {
+    //设置 intervalTime 秒回调一次
+    print(1234);
+    Duration period = Duration(minutes: intervalTime);
+    _timer = Timer.periodic(period, (timer) {
+      print(1236);
+      getStartDelayAddress();
+    });
+  }
 
+  void cancelTimer() {
+    if (_timer != null) {
+      _timer.cancel();
+      _timer = null;
+    }
+  }
+  double lat;
+  double lng;
   Widget bannerLastWidget;
   List<dynamic> bannerList;
   List<dynamic> questionsList;
@@ -183,9 +195,43 @@ class BbsPageState extends BasePageState<BbsPage, NewsListPresenter>
   List<dynamic> shopList;
   List<dynamic> positionList;
   bool isCustom = false;
+  Future isDelayAddress() async {
+    await NewApiService().isDelayAddress(onSuccess: (res) {
+      print("665-------------------////");
+      print(res["id"]);
+      print(jsonEncode(res));
+      print("666-------------------////");
+      if(res["isPush"]!=null && res["isPush"] == 1){
+        getStartDelayAddress();
+        startTimer(res["intervalTime"]);
+      }
+      //intervalTime:时间间隔分钟 ; isPush:1推送 2不推送
+    }, onError: (code, msg) {
+      toasts(msg);
+    });
+  }
+
+  Future getStartDelayAddress() async {
+    String position = lat.toString() +","+ lng.toString();
+    await NewApiService().startDelayAddress(
+      {
+        "mobile":FlutterStars.SpUtil.getString(Constant.phone),
+        "mtCompanyId":FlutterStars.SpUtil.getString(Constant.companyId)!=""?int.parse(FlutterStars.SpUtil.getString(Constant.companyId)):"",
+        "position":position,
+        "userId":int.parse(FlutterStars.SpUtil.getString(Constant.userId))
+      }
+      ,onSuccess: (res) {
+      
+      print("668-------------------////");
+      
+    }, onError: (code, msg) {
+      toasts(msg);
+    });
+  }
+
   Future getBannerList() async {
     await NewApiService().getBanner(1, 10, onSuccess: (BannerModel res) {
-      print(jsonEncode(res));
+      // print(jsonEncode(res));
       // print(JsonEncoder().convert(res.records));
       bannerList = res.records;
       bannerLastWidget = SwipeWidget(banners: bannerList,);
@@ -199,8 +245,8 @@ class BbsPageState extends BasePageState<BbsPage, NewsListPresenter>
   Future getNotificaList() async {
     display = true;
     await NewApiService().myNotificaList(1, 10, onSuccess: (res) {
-      print(jsonEncode(res));
-      print(JsonEncoder().convert(res.records));
+      // print(jsonEncode(res));
+      // print(JsonEncoder().convert(res.records));
       res.records.forEach((item){
         if(item.viewFlag == 0){
           setState(() {
@@ -209,7 +255,6 @@ class BbsPageState extends BasePageState<BbsPage, NewsListPresenter>
           return;
         }
       });
-      print("////////////////////////66666");
       // print(bannerList.length);
       setState(() {});
     }, onError: (code, msg) {
@@ -220,7 +265,7 @@ class BbsPageState extends BasePageState<BbsPage, NewsListPresenter>
   Future getNewsList() async {
     await NewApiService().newsList(1, 3, 1, "", cityName, onSuccess: (res) {
       newsList = res.topNews;
-      print(JsonEncoder().convert(res.topNews));
+      // print(JsonEncoder().convert(res.topNews));
       setState(() {});
     }, onError: (code, msg) {
       toasts(msg);
@@ -294,6 +339,7 @@ class BbsPageState extends BasePageState<BbsPage, NewsListPresenter>
       _locationPlugin.destroy();
     }
     super.dispose();
+    cancelTimer();
   }
 
   static const diagnosisObj = [

+ 1 - 0
lib/internal/bbs/page/tab/position/position_list.dart

@@ -96,6 +96,7 @@ class PositionListState
       return true;
     } else {
       toasts('需要定位权限!');
+      _onRefresh();
       return false;
     }
   }

+ 1 - 0
lib/internal/friends/page/near_list.dart

@@ -74,6 +74,7 @@ class NearListState extends State<NearList> {
     if (permissions[PermissionGroup.location] == PermissionStatus.granted) {
       return true;
     } else {
+      NavigatorUtils.goBack(context);
       toasts('需要定位权限!');
       return false;
     }

+ 22 - 0
lib/net/api_service.dart

@@ -1675,6 +1675,8 @@ class NewApiUrl {
   static const String becomeMasterDetail = "/udream/api/applyExperts/queryByUserId/";
   static const String updataUserLoginInfo = "/udream/api/userInfos/getNewInfo";
   static const String becomeMasterUpdate = "/udream/api/applyExperts/update";
+  static const String isDelayAddressUrl = "/udream/api/otherSettings/query-new";
+  static const String startDelayAddressUrl = "/udream/api/motionTrails/addTrail";
   static const String user_order_update = "/udream/api/userOrderss/update";
   static const String apply_invoice = "/udream/api/applyInvoices/applyInvoice";
   static const String submit_comments = "/udream/api/expertComments/insert";
@@ -3250,4 +3252,24 @@ class NewApiService {
             onSuccess: onSuccess,
             onError: onError);
   }
+
+  //判断是否要定时传当前位置
+  Future isDelayAddress(
+      {Function onSuccess, Function(int code, String msg) onError}) async {
+    await DioUtils().requestNetwork<Map>(
+        Method.get, "${NewApiUrl.isDelayAddressUrl}", 
+        onSuccess: onSuccess,
+        onError: onError);
+  }
+
+  //定时传当前位置
+  Future startDelayAddress(data,
+      {Function onSuccess, Function(int code, String msg) onError}) async {
+    await DioUtils().requestNetwork<String>(
+        Method.post, "${NewApiUrl.startDelayAddressUrl}",
+        params: data,
+        onSuccess: onSuccess,
+        onError: onError);
+  }
+
 }