李志伟 3 vuotta sitten
vanhempi
commit
c6fc3c4553

+ 6
- 2
lib/models/entities/Machinery.dart Näytä tiedosto

@@ -18,6 +18,8 @@ class Machinery {
18 18
   int? laborCost;
19 19
 //  当前位置
20 20
   String? location;
21
+  //当前农机地址
22
+  String? address;
21 23
 //  农机Id
22 24
   String? machineryId;
23 25
 //  名称
@@ -61,6 +63,7 @@ class Machinery {
61 63
         price = json["price"],
62 64
         thumb = json["thumb"],
63 65
         location = json["location"],
66
+        address = json["address"],
64 67
         // distance=json["distance"],调度??
65 68
         orgId = json["orgId"],
66 69
         orgName = json["orgName"],
@@ -77,6 +80,7 @@ class Machinery {
77 80
         'price': price,
78 81
         'thumb': thumb,
79 82
         'location': location,
83
+        'address': address,
80 84
         // 'distance':distance,
81 85
         'orgId': orgId,
82 86
         'orgName': orgName,
@@ -89,7 +93,7 @@ class Machinery {
89 93
 
90 94
 List<ExtendContent> jsonToContentList(list) {
91 95
   List<ExtendContent> contList = [];
92
-  if (list!=null) {
96
+  if (list != null) {
93 97
     list.forEach((item) {
94 98
       contList.add(ExtendContent.fromJson(item));
95 99
     });
@@ -99,7 +103,7 @@ List<ExtendContent> jsonToContentList(list) {
99 103
 
100 104
 List<MachineryImage> jsonToImagesList(list) {
101 105
   List<MachineryImage> contList = [];
102
-  if (list!=null) {
106
+  if (list != null) {
103 107
     list.forEach((item) {
104 108
       contList.add(MachineryImage.fromJson(item));
105 109
     });

+ 1
- 0
lib/pages/home/index.dart Näytä tiedosto

@@ -132,6 +132,7 @@ class Home extends BasicPage {
132 132
                               itemBuilder:
133 133
                                   (BuildContext context, int position) {
134 134
                                 if (jobList.value.isNotEmpty &&
135
+                                    GetList(data.records).isNotEmpty &&
135 136
                                     jobList.value[0].jobId !=
136 137
                                         GetList(data.records)[0].jobId) {
137 138
                                   jobList([

+ 158
- 73
lib/pages/machineryMap/index.dart Näytä tiedosto

@@ -1,25 +1,73 @@
1
+import 'dart:convert';
1 2
 import 'package:flutter/material.dart';
2 3
 import 'package:flutter_screenutil/flutter_screenutil.dart';
3 4
 import 'package:get/get.dart';
5
+import 'package:worker_client/models/app.dart';
4 6
 import 'package:worker_client/models/entities/Machinery.dart';
7
+import 'package:worker_client/services/amap.dart';
5 8
 import 'package:worker_client/services/machinery.dart';
6 9
 import 'package:worker_client/widgets/amap/amap.dart';
7 10
 import 'package:worker_client/widgets/layout/BasicPage.dart';
8
-import 'package:amap_flutter_base/amap_flutter_base.dart';
9 11
 
10 12
 class MachineryMap extends BasicPage {
11 13
   MachineryMap({Key? key}) : super(key: key);
14
+  String? location = AppController.t.locationStr;
12 15
   final machineryList = Rx<List<Machinery>>([]);
16
+  //用来放地图中心的
13 17
   final machinery = Rx<Machinery>(Machinery());
18
+  //切换农机时用的当前农机变量
19
+  final current = Rx<Machinery>(Machinery());
20
+  final visible = Rx<bool>(true);
14 21
 
22
+  dynamic locList = [
23
+    '32.685927, 112.106514',
24
+    '32.673406, 112.100406',
25
+    '32.670488, 112.06397',
26
+    '32.685684, 112.05434',
27
+    '32.701302, 112.058724',
28
+    '32.665504, 112.015102',
29
+    '32.685502, 112.010503',
30
+    '32.651764, 112.097747',
31
+    '32.664957, 112.149705',
32
+    '32.701241, 112.16185',
33
+  ];
15 34
   @override
16 35
   void beforeShow() {
17 36
     super.beforeShow();
18 37
     if (Get.arguments != null) {
19 38
       getMachineryDetail(Get.arguments['id'], {
20 39
         'attached': true,
40
+        //查询农机详情时需要把当前定位传到服务端
21 41
         'location': '118.84002,31.95266'
22
-      }).then((res) => {machinery(Machinery.fromJson(res))});
42
+      }).then((res) => {
43
+            getMachineryList({'pageSize': 500, 'location': location})
44
+                .then((value) {
45
+              dynamic list = <Machinery>[];
46
+              int index;
47
+              Machinery data = Machinery.fromJson(res);
48
+              List area = [];
49
+              value['records'].forEach((item) {
50
+                index = value['records'].indexOf(item);
51
+                item['location'] = locList[index % 10];
52
+                list.add(Machinery.fromJson(item));
53
+                if (data.machineryId == item['machineryId']) {
54
+                  data.location = item['location'];
55
+                  area = item['location'].toString().split(',');
56
+                  setAmap({
57
+                    'params': 'location=${area[1]},${area[0]}',
58
+                    'path': '/v3/geocode/regeo'
59
+                  }).then((value) {
60
+                    //json字符串转Map对象
61
+                    data.address =
62
+                        jsonDecode(value)['regeocode']['formatted_address'];
63
+                    machinery(data);
64
+                    current(data);
65
+                  });
66
+                }
67
+              });
68
+              machineryList(list);
69
+            }),
70
+          });
23 71
     }
24 72
   }
25 73
 
@@ -29,97 +77,134 @@ class MachineryMap extends BasicPage {
29 77
 
30 78
   void goDetail() {
31 79
     Get.toNamed('/machineryDetail',
32
-        arguments: {'id': machinery.value.machineryId});
80
+        arguments: {'id': current.value.machineryId});
81
+  }
82
+
83
+  void onClick(e) {
84
+    List area = e.location.toString().split(',');
85
+    if (e.address == null) {
86
+      setAmap({
87
+        //定位有问题
88
+        'params': 'location=${area[1]},${area[0]}',
89
+        'path': '/v3/geocode/regeo'
90
+      }).then((value) {
91
+        //json字符串转Map对象
92
+        e.address = jsonDecode(value)['regeocode']['formatted_address'];
93
+        current(e);
94
+        visible(true);
95
+      });
96
+    } else {
97
+      current(e);
98
+      visible(true);
99
+    }
100
+  }
101
+
102
+  void onCancel() {
103
+    if (!visible.value) {
104
+      visible(false);
105
+    }
33 106
   }
34 107
 
35
-  final LatLng position = const LatLng(32.690712, 112.091892);
36 108
   @override
37 109
   Widget builder(BuildContext context) {
38 110
     naviTitle = '我的农机';
111
+
39 112
     return Stack(
40 113
       children: [
41 114
         SizedBox(
42 115
           width: 375.w,
43
-          child: AMap(position: position),
116
+          child: Obx(
117
+            () => AMap(
118
+              machineryList: machineryList.value,
119
+              machinery: machinery.value,
120
+              onCancel: onCancel,
121
+              onClick: onClick,
122
+            ),
123
+          ),
44 124
         ),
45
-        Positioned(
46
-          bottom: 0,
47
-          child: Container(
48
-            width: 375.w,
49
-            padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 30.h),
50
-            decoration: BoxDecoration(
51
-                borderRadius: BorderRadius.only(
52
-                    topLeft: Radius.circular(20.w),
53
-                    topRight: Radius.circular(20.w)),
54
-                color: Colors.white),
55
-            child: Column(
56
-              crossAxisAlignment: CrossAxisAlignment.start,
57
-              children: [
58
-                GestureDetector(
59
-                  onTap: () {
60
-                    goBack();
61
-                  },
62
-                  child: Text(
63
-                    '<<农机列表',
64
-                    style: TextStyle(
65
-                        color: const Color(0xff666666),
66
-                        fontSize: 15.sp,
67
-                        fontWeight: FontWeight.bold),
68
-                  ),
69
-                ),
70
-                Container(
71
-                  margin: EdgeInsets.only(top: 30.h, bottom: 20.h),
72
-                  child: Row(
73
-                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
74
-                    children: [
75
-                      Text(
76
-                        '第一台收割机',
125
+        Obx(
126
+          () => Visibility(
127
+            visible: visible.value,
128
+            child: Positioned(
129
+              bottom: 0,
130
+              child: Container(
131
+                width: 375.w,
132
+                padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 30.h),
133
+                decoration: BoxDecoration(
134
+                    borderRadius: BorderRadius.only(
135
+                        topLeft: Radius.circular(20.w),
136
+                        topRight: Radius.circular(20.w)),
137
+                    color: Colors.white),
138
+                child: Column(
139
+                  crossAxisAlignment: CrossAxisAlignment.start,
140
+                  children: [
141
+                    GestureDetector(
142
+                      onTap: () {
143
+                        goBack();
144
+                      },
145
+                      child: Text(
146
+                        '<<农机列表',
77 147
                         style: TextStyle(
78
-                            color: const Color(0xff222222),
79
-                            fontSize: 18.sp,
148
+                            color: const Color(0xff666666),
149
+                            fontSize: 15.sp,
80 150
                             fontWeight: FontWeight.bold),
81 151
                       ),
82
-                      GestureDetector(
83
-                        onTap: () {
84
-                          goDetail();
85
-                        },
86
-                        child: Text(
87
-                          '详情>>',
88
-                          style: TextStyle(
89
-                              color: const Color(0xff666666),
90
-                              fontSize: 15.sp,
91
-                              fontWeight: FontWeight.bold),
92
-                        ),
93
-                      )
94
-                    ],
95
-                  ),
96
-                ),
97
-                Row(
98
-                  children: [
152
+                    ),
99 153
                     Container(
100
-                      margin: EdgeInsets.only(right: 8.w),
101
-                      child: Image.asset(
102
-                        'images/index/position.png',
103
-                        width: 17.w,
154
+                      margin: EdgeInsets.only(top: 30.h, bottom: 20.h),
155
+                      child: Row(
156
+                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
157
+                        children: [
158
+                          Text(
159
+                            current.value.name.toString(),
160
+                            style: TextStyle(
161
+                                color: const Color(0xff222222),
162
+                                fontSize: 18.sp,
163
+                                fontWeight: FontWeight.bold),
164
+                          ),
165
+                          GestureDetector(
166
+                            onTap: () {
167
+                              goDetail();
168
+                            },
169
+                            child: Text(
170
+                              '详情>>',
171
+                              style: TextStyle(
172
+                                  color: const Color(0xff666666),
173
+                                  fontSize: 15.sp,
174
+                                  fontWeight: FontWeight.bold),
175
+                            ),
176
+                          )
177
+                        ],
104 178
                       ),
105 179
                     ),
106
-                    Expanded(
107
-                      flex: 1,
108
-                      child: Text(
109
-                        '当前位置:  江苏省南京市南京南站城际空间站D2栋212南京云致科技服务有限公司',
110
-                        style: TextStyle(
111
-                          fontWeight: FontWeight.bold,
112
-                          fontSize: 15.sp,
113
-                          color: const Color(0xff222222),
180
+                    Row(
181
+                      children: [
182
+                        Container(
183
+                          margin: EdgeInsets.only(right: 8.w),
184
+                          child: Image.asset(
185
+                            'images/index/position.png',
186
+                            width: 17.w,
187
+                          ),
114 188
                         ),
115
-                      ),
116
-                    )
189
+                        Expanded(
190
+                          flex: 1,
191
+                          child: Text(
192
+                            '当前位置:${current.value.address ?? ''.toString()}',
193
+                            style: TextStyle(
194
+                              fontWeight: FontWeight.bold,
195
+                              fontSize: 15.sp,
196
+                              color: const Color(0xff222222),
197
+                            ),
198
+                          ),
199
+                        ),
200
+                      ],
201
+                    ),
117 202
                   ],
118
-                )
119
-              ],
203
+                ),
204
+              ),
120 205
             ),
121 206
           ),
122
-        )
207
+        ),
123 208
       ],
124 209
     );
125 210
   }

+ 60
- 15
lib/widgets/amap/amap.dart Näytä tiedosto

@@ -1,27 +1,60 @@
1 1
 import 'package:amap_flutter_map/amap_flutter_map.dart';
2 2
 import 'package:amap_flutter_base/amap_flutter_base.dart';
3 3
 import 'package:flutter/widgets.dart';
4
+import 'package:get/get.dart';
5
+import 'package:worker_client/models/entities/Machinery.dart';
4 6
 
5 7
 import '/utils/amap/const_config.dart';
6 8
 
7 9
 // https://developer.amap.com/api/flutter/guide/map-flutter-plug-in/map-flutter-info
8 10
 class AMap extends StatelessWidget {
9 11
   late AMapController _mapController;
10
-  final LatLng? position;
12
+  final List<Machinery> machineryList;
13
+  final Machinery machinery;
14
+  dynamic centerLocationArea = [];
11 15
   final Map<String, Marker> _markers = Map<String, Marker>();
16
+  final Function onClick;
17
+  final Function onCancel;
12 18
 
13
-  AMap({Key? key, this.position}) : super(key: key);
19
+  AMap({
20
+    Key? key,
21
+    required this.machineryList,
22
+    required this.machinery,
23
+    required this.onClick,
24
+    required this.onCancel,
25
+  }) : super(key: key);
14 26
 
15 27
   void onMapCreated(AMapController controller) {
16 28
     _mapController = controller;
17 29
   }
18 30
 
31
+  BitmapDescriptor m1 =
32
+      BitmapDescriptor.fromIconPath("images/machinery/greenMachinery.png");
33
+  BitmapDescriptor m2 =
34
+      BitmapDescriptor.fromIconPath("images/machinery/orangeMachinery.png");
35
+  BitmapDescriptor m3 =
36
+      BitmapDescriptor.fromIconPath("images/machinery/repairMachinery.png");
19 37
   void _initMarkers() {
20
-    if (null != position) {
21
-      Marker marker = Marker(
22
-          position: position!,
23
-          icon: BitmapDescriptor.fromIconPath("images/locationImage.png"));
24
-      _markers[marker.id] = marker;
38
+    if (machineryList.isNotEmpty && machinery.location != null) {
39
+      centerLocationArea = machinery.location!.split(',');
40
+
41
+      dynamic locationArea = [];
42
+      for (var item in machineryList) {
43
+        locationArea = item.location!.split(',');
44
+        Marker marker = Marker(
45
+            onTap: (e) {
46
+              onClick(item);
47
+            },
48
+            clickable: true,
49
+            position: LatLng(
50
+                double.parse(locationArea[0]), double.parse(locationArea[1])),
51
+            icon: item.status == 0
52
+                ? m3
53
+                : (item.jobStatus == null || item.jobStatus == 3)
54
+                    ? m2
55
+                    : m1);
56
+        _markers[item.machineryId.toString()] = marker;
57
+      }
25 58
     }
26 59
   }
27 60
 
@@ -29,13 +62,25 @@ class AMap extends StatelessWidget {
29 62
   Widget build(BuildContext context) {
30 63
     _initMarkers();
31 64
 
32
-    return AMapWidget(
33
-      privacyStatement: ConstConfig.amapPrivacyStatement,
34
-      apiKey: ConstConfig.amapApiKeys,
35
-      markers: Set<Marker>.of(_markers.values),
36
-      // 默认是邓州市中心
37
-      initialCameraPosition:
38
-          const CameraPosition(target: LatLng(32.687732, 112.08745)),
39
-    );
65
+    return centerLocationArea.length != 0
66
+        ? AMapWidget(
67
+            privacyStatement: ConstConfig.amapPrivacyStatement,
68
+            apiKey: ConstConfig.amapApiKeys,
69
+            markers: Set<Marker>.of(_markers.values),
70
+            onPoiTouched: (e) {},
71
+            onCameraMove: (e) {
72
+              // 移动地图
73
+              onCancel();
74
+            },
75
+            // 默认是邓州市中心
76
+            initialCameraPosition: CameraPosition(
77
+                target: LatLng(double.parse(centerLocationArea[0].toString()),
78
+                    double.parse(centerLocationArea[1].toString())),
79
+                zoom: 13),
80
+          )
81
+        : const SizedBox(
82
+            width: 1,
83
+            height: 1,
84
+          );
40 85
   }
41 86
 }