Browse Source

orderHomePages

[baozhangchao] 3 years ago
parent
commit
86e88cbb36

+ 4
- 9
lib/models/app.dart View File

@@ -15,15 +15,10 @@ class AppController extends GetxController {
15 15
   final location = Rxn<LocationData>();
16 16
   final testInt = 1.obs;
17 17
 
18
-  // get locationStr {
19
-  //   if(location.value!.longitude==null){
20
-  //     return null;
21
-  //
22
-  //   }else{
23
-  //   return location.value!.longitude.toString() + "," + location.value!.latitude.toString();
24
-  //
25
-  //   }
26
-  // }
18
+  get locationStr {
19
+    if (null == location.value) return null;
20
+    return location.value!.longitude.toString() + "," + location.value!.latitude.toString();
21
+  }
27 22
 
28 23
   @override
29 24
   void onInit() {

lib/models/entities/banner.dart → lib/models/entities/Banners.dart View File

@@ -1,4 +1,4 @@
1
-class banner {
1
+class Banners {
2 2
   String? bannerId;
3 3
   String? title;
4 4
   String? thumb;
@@ -6,9 +6,9 @@ class banner {
6 6
   num? sortNo;
7 7
   num? status;
8 8
   String? createDat;
9
-  banner();
9
+  Banners();
10 10
 
11
-  banner.fromJson(Map<String, dynamic> json)
11
+  Banners.fromJson(Map<String, dynamic> json)
12 12
       : bannerId = json["bannerId"],
13 13
         title = json["title"],
14 14
         thumb = json["thumb"],

+ 2
- 2
lib/models/entities/CardInfo.dart View File

@@ -33,10 +33,10 @@ class CardInfo {
33 33
   int? status;
34 34
 
35 35
   // @ApiModelProperty(value = "内容详情")
36
-  late List<dynamic> contentList;
36
+  late List<dynamic>? contentList;
37 37
 
38 38
   // @ApiModelProperty(value = "图片列表")
39
-  late List<dynamic> imagesList;
39
+  late List<dynamic>? imagesList;
40 40
 
41 41
   CardInfo();
42 42
 

+ 1
- 4
lib/pages/MoreCars/index.dart View File

@@ -80,10 +80,7 @@ class _MoreCarsState extends State<MoreCars> with TickerProviderStateMixin {
80 80
                 Container(
81 81
                   child: Column(
82 82
                     children: [
83
-                      CarsCard(),
84
-                      CarsCard(),
85
-                      CarsCard(),
86
-                      CarsCard(),
83
+
87 84
                     ],
88 85
                   )
89 86
                   ,

+ 29
- 16
lib/pages/TabBar/widgets/home/index.dart View File

@@ -5,45 +5,56 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
5 5
 import 'package:get/get.dart';
6 6
 import 'package:get/get_core/src/get_main.dart';
7 7
 import '../../../../models/app.dart';
8
-import '../../../../models/entities/banner.dart';
8
+import '../../../../models/entities/CardInfo.dart';
9 9
 import '../../../../services/homeAPI.dart';
10 10
 import '../../../../widgets/CarsCard.dart';
11
-import 'package:farmer_client/models/app.dart';
11
+import 'package:farmer_client/models/entities/Banners.dart';
12 12
 import '../../../MoreCars/index.dart';
13 13
 
14 14
 class HomePage extends StatefulWidget {
15
-  const HomePage({Key? key}) : super(key: key);
15
+  const HomePage({Key? key, }) : super(key: key);
16
+
16 17
 
17 18
   @override
18
-  State<HomePage> createState() => _HomePageState();
19
+  _HomePageState createState() => _HomePageState();
19 20
 }
20 21
 
21 22
 
22 23
 class _HomePageState extends State<HomePage> {
23 24
   final CarouselController _controller = CarouselController();
24
-  List<banner> BannerList = [];
25
+  List<Banners> bannerList = [];
26
+
27
+  List<CardInfo> machineryLists = [];
28
+
29
+
30
+
25 31
 
26 32
   @override
27 33
   void initState() {
28 34
     super.initState();
29
-    final location = AppController.t.location;
30
-    print('location+$location');
35
+    // final location = AppController.t.location;
36
+    // print('location+$location');
31 37
 
32 38
     getHomeBanner('banner').then((value) {
33 39
       setState(() {
34 40
         value.forEach((item) {
35
-          BannerList.add(banner.fromJson(item));
41
+          bannerList.add(Banners.fromJson(item));
36 42
         });
37 43
       });
38 44
     });
39 45
 
40
-    // getMachinery(location.value!.longitude.toString()).then((value) {
41
-    //   print('$value');
42
-    // });
46
+    getMachinery('112.087433,32.687692').then((value) {
47
+      setState(() {
48
+        value['records'].forEach((item) {
49
+          machineryLists.add(CardInfo.fromJson(item));
50
+        });
51
+      });
52
+    });
43 53
   }
44 54
 
45 55
   @override
46 56
   Widget build(BuildContext context) {
57
+
47 58
     return Container(
48 59
       alignment: Alignment.center,
49 60
       padding: EdgeInsets.fromLTRB(15.w, 0, 15.w, 0),
@@ -58,9 +69,8 @@ class _HomePageState extends State<HomePage> {
58 69
           Container(
59 70
             margin: EdgeInsets.fromLTRB(0, 15, 0, 0),
60 71
             child:
61
-                // Text('asdasdas')
62 72
                 CarouselSlider(
63
-              items: BannerList.map((item) => Container(
73
+              items: bannerList.map((item) => Container(
64 74
                     child: Center(
65 75
                         child: Image.network(item.thumb.toString(),
66 76
                             fit: BoxFit.cover, width: 350.w)),
@@ -115,9 +125,12 @@ class _HomePageState extends State<HomePage> {
115 125
                       )
116 126
                     ],
117 127
                   ),
118
-                  CarsCard(),
119
-                  CarsCard(),
120
-                  CarsCard(),
128
+            Column(
129
+              children: machineryLists.map((item) =>CarsCard(item:item)).toList(),
130
+            )
131
+
132
+
133
+
121 134
                 ],
122 135
               )),
123 136
         ],

+ 0
- 4
lib/pages/search/index.jsx.dart View File

@@ -74,10 +74,6 @@ class _SearchPage extends State<SearchPage> {
74 74
               child: Column(
75 75
                 children: [
76 76
                   // NullCard(text: '暂无农机信息'),
77
-                  CarsCard(),
78
-                  CarsCard(),
79
-                  CarsCard(),
80
-                  CarsCard(),
81 77
                 ],
82 78
               ),
83 79
             )

+ 21
- 0
lib/services/orderAPI.dart View File

@@ -0,0 +1,21 @@
1
+
2
+
3
+import 'package:dio/dio.dart';
4
+import 'package:farmer_client/utils/Request.dart';
5
+import 'package:fluttertoast/fluttertoast.dart';
6
+
7
+
8
+/**
9
+ * 订单列表
10
+ * @param {*} data
11
+ * @returns
12
+ */
13
+Future getOrderList(bool mine)async{
14
+  return request('/order',options: Options(method: 'GET'),data: { 'mine': mine}).catchError((error) =>
15
+  { Fluttertoast.showToast(
16
+      msg: error.error['message']
17
+  ),});
18
+
19
+}
20
+
21
+

+ 40
- 40
lib/widgets/CarsCard.dart View File

@@ -4,25 +4,25 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
4 4
 import 'package:get/get.dart';
5 5
 import 'package:get/get_core/src/get_main.dart';
6 6
 
7
+import '../models/entities/CardInfo.dart';
7 8
 import '../pages/OrderConfirmation/index.dart';
8 9
 import '../pages/machinery/detail/index.dart';
9 10
 import '../pages/machinery/map/index.dart';
10 11
 import 'LinearGradientText.dart';
11 12
 
12
-// class CarItem {
13
-//   late String name;
14
-//   late num? price;
15
-//   late num? distance;
16
-//   CarItem({required this.name, this.price, this.distance});
17
-// }
13
+class CarsCard extends StatefulWidget {
14
+  final CardInfo item;
18 15
 
19
-class CarsCard extends StatelessWidget {
20
-  // final CarItem item;
16
+  const CarsCard({Key? key, required this.item}) : super(key: key);
17
+
18
+  @override
19
+  _CarsCardPage createState() => _CarsCardPage(item);
20
+}
21
+
22
+class _CarsCardPage extends State<CarsCard> {
23
+  final CardInfo item;
24
+  _CarsCardPage(this.item);
21 25
 
22
-  // const CarsCard({
23
-  //   Key? key,
24
-  //   required this.item,
25
-  // }) : super(key: key);
26 26
 
27 27
   @override
28 28
   Widget build(BuildContext context) {
@@ -36,11 +36,11 @@ class CarsCard extends StatelessWidget {
36 36
       child: Column(
37 37
         children: [
38 38
           GestureDetector(
39
-            onTap: (){
39
+            onTap: () {
40 40
               Get.to(MachineryDetailPage());
41 41
             },
42
-            child:Image.network(
43
-              "http://yz-shigongli.oss-accelerate.aliyuncs.com/2022-03/1648094119154-7b280bbf63105a8e90299e2d79c8c6ee.jpeg",
42
+            child: Image.network(
43
+              item.thumb.toString(),
44 44
               width: 345.w,
45 45
               height: 230.h,
46 46
               fit: BoxFit.cover,
@@ -55,7 +55,7 @@ class CarsCard extends StatelessWidget {
55 55
               children: <Widget>[
56 56
                 Container(
57 57
                   child: Text(
58
-                    '联合收割机GB01235-0B',
58
+                    item.name.toString(),
59 59
                     style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
60 60
                   ),
61 61
                 ),
@@ -76,28 +76,26 @@ class CarsCard extends StatelessWidget {
76 76
                       Color(0xFFB61515),
77 77
                     ],
78 78
                     child: RichText(
79
-                      text: TextSpan(
80
-                          children: <InlineSpan>[
81
-                            TextSpan(
82
-                                text: "4508",
83
-                                style: TextStyle(
84
-                                  fontSize: 22,
85
-                                  fontWeight: FontWeight.bold,
86
-                                )),
87
-                            TextSpan(
88
-                                text: "元/",
89
-                                style: TextStyle(
90
-                                  fontSize: 22,
91
-                                  fontWeight: FontWeight.bold,
92
-                                )),
93
-                            TextSpan(
94
-                                text: "公顷",
95
-                                style: TextStyle(
96
-                                  fontSize: 12,
97
-                                  fontWeight: FontWeight.bold,
98
-                                )),
99
-                          ]
100
-                      ),
79
+                      text: TextSpan(children: <InlineSpan>[
80
+                        TextSpan(
81
+                            text: (item.price! / 100).toString(),
82
+                            style: TextStyle(
83
+                              fontSize: 22,
84
+                              fontWeight: FontWeight.bold,
85
+                            )),
86
+                        TextSpan(
87
+                            text: "元/",
88
+                            style: TextStyle(
89
+                              fontSize: 22,
90
+                              fontWeight: FontWeight.bold,
91
+                            )),
92
+                        TextSpan(
93
+                            text: "公顷",
94
+                            style: TextStyle(
95
+                              fontSize: 12,
96
+                              fontWeight: FontWeight.bold,
97
+                            )),
98
+                      ]),
101 99
                     ),
102 100
                   ),
103 101
                 ),
@@ -111,7 +109,8 @@ class CarsCard extends StatelessWidget {
111 109
                     height: 44.h, //+10
112 110
                     child: ElevatedButton(
113 111
                       onPressed: () {
114
-                        Get.to(OrderConfirmation());
112
+                        Get.toNamed('/orderConfirmation',
113
+                            arguments: {'machineryId': item.machineryId});
115 114
                       },
116 115
                       child: const Text(
117 116
                         "预约",
@@ -165,7 +164,8 @@ class CarsCard extends StatelessWidget {
165 164
                             ),
166 165
                             onTap: () {
167 166
                               print('进入地图');
168
-                              Get.to(MachineryMapPage());
167
+                              Get.toNamed('/machineryMap',
168
+                                  arguments: {'machineryId': item.machineryId});
169 169
                             },
170 170
                           )
171 171
                         ],