李志伟 hace 3 años
padre
commit
23834cd249
Se han modificado 2 ficheros con 218 adiciones y 80 borrados
  1. 182
    45
      lib/pages/home/index.dart
  2. 36
    35
      lib/pages/jobDetail/index.dart

+ 182
- 45
lib/pages/home/index.dart Ver fichero

@@ -1,7 +1,10 @@
1
+import 'package:flutter_easyloading/flutter_easyloading.dart';
2
+import 'package:fluttertoast/fluttertoast.dart';
1 3
 import 'package:get/get.dart';
2 4
 import 'package:carousel_slider/carousel_slider.dart';
3 5
 import 'package:flutter/material.dart';
4 6
 import 'package:flutter_screenutil/flutter_screenutil.dart';
7
+import 'package:worker_client/models/app.dart';
5 8
 import 'package:worker_client/models/entities/Banner.dart';
6 9
 import 'package:worker_client/models/entities/Job.dart';
7 10
 import 'package:worker_client/pages/home/widgets/headers.dart';
@@ -10,6 +13,7 @@ import 'package:worker_client/services/job.dart';
10 13
 import 'package:worker_client/widgets/MyCard/index.dart';
11 14
 import 'package:worker_client/widgets/RefreshMoreList.dart';
12 15
 import 'package:worker_client/widgets/layout/BasicPage.dart';
16
+import '/widgets/MyDialog.dart' as modal;
13 17
 
14 18
 class Home extends BasicPage {
15 19
   Home({Key? key}) : super(key: key) {
@@ -20,7 +24,9 @@ class Home extends BasicPage {
20 24
   final bannerList = Rx<List<BannerModel>>([]);
21 25
   final jobList = Rx<List<Job>>([]);
22 26
   final job = Rx<Job>(Job());
27
+  final area = Rx<String>('');
23 28
   final params = Rx<Map<String, dynamic>>({'pageSize': 10});
29
+  Function? Refresh;
24 30
 
25 31
   void beforeShow() {
26 32
     super.beforeShow();
@@ -39,12 +45,143 @@ class Home extends BasicPage {
39 45
     if (value != null) value.forEach((item) => {list.add(Job.fromJson(item))});
40 46
     return list;
41 47
   }
42
-  void changeJob(Job item) {}
48
+
43 49
   void goDetail(Job item) {
44 50
     Get.toNamed('/jobDetail', arguments: {'id': item.jobId});
45 51
   }
46 52
 
47
-  Function? Refresh;
53
+  void changeList(Job item) {
54
+    List<Job> list = [];
55
+    for (var e in jobList.value) {
56
+      if (e.jobId == item.jobId) {
57
+        if (item.status == 0) {
58
+          e.status = 1;
59
+        } else if (item.status == 1) {
60
+          e.status = 3;
61
+        }
62
+      }
63
+      list.add(e);
64
+    }
65
+    jobList(list);
66
+  }
67
+
68
+  Widget startContent() {
69
+    return Column(
70
+      children: [
71
+        Image.asset(
72
+          'images/index/positionImg.png',
73
+          width: 40.w,
74
+        ),
75
+        Container(
76
+          alignment: Alignment.centerLeft,
77
+          margin: EdgeInsets.fromLTRB(65.w, 26.h, 65.w, 0),
78
+          child: Text(
79
+            '当前位置在',
80
+            style: TextStyle(
81
+              fontSize: 17.sp,
82
+              fontWeight: FontWeight.w800,
83
+              color: const Color(0xff323232),
84
+            ),
85
+          ),
86
+        ),
87
+        Container(
88
+          margin: EdgeInsets.fromLTRB(65.w, 0, 65.w, 50.h),
89
+          child: Text(
90
+            AppController.t.location.value!['address'].toString(),
91
+            style: TextStyle(
92
+              fontSize: 17.sp,
93
+              fontWeight: FontWeight.w800,
94
+              color: const Color(0xff323232),
95
+            ),
96
+          ),
97
+        ),
98
+      ],
99
+    );
100
+  }
101
+
102
+  Widget endContent() {
103
+    return Container(
104
+      margin: EdgeInsets.fromLTRB(15.w, 0, 15.w, 25.h),
105
+      padding: EdgeInsets.symmetric(vertical: 18.h, horizontal: 15.w),
106
+      decoration: BoxDecoration(
107
+          border: Border.all(
108
+              width: 1.w,
109
+              style: BorderStyle.solid,
110
+              color: const Color(0xFFF2F2F2)),
111
+          borderRadius: BorderRadius.all(Radius.circular(20.w))),
112
+      child: Row(
113
+        children: [
114
+          Text(
115
+            '作业面积:',
116
+            style: TextStyle(
117
+              fontSize: 17.sp,
118
+              fontWeight: FontWeight.w500,
119
+              color: const Color(0xff333333),
120
+            ),
121
+          ),
122
+          Expanded(
123
+            child: TextField(
124
+              keyboardType: TextInputType.number,
125
+              style: TextStyle(fontSize: 16.sp),
126
+              decoration: const InputDecoration(
127
+                isCollapsed: true,
128
+                hintText: '请输入本次作业的面积',
129
+                border: InputBorder.none,
130
+                counterText: '', //去掉计数
131
+                floatingLabelBehavior: FloatingLabelBehavior.never,
132
+              ),
133
+              onChanged: (e) {
134
+                area(e);
135
+              },
136
+            ),
137
+          )
138
+        ],
139
+      ),
140
+    );
141
+  }
142
+
143
+  void changeJob(Job item) {
144
+    if (item.status == 0) {
145
+      modal.showDialog(
146
+          content: startContent(),
147
+          onConfirm: () {
148
+            EasyLoading.show(status: '请稍后');
149
+            startJob(item.jobId.toString(), {'mode': true}).then((value) {
150
+              //关闭弹窗需要改变列表
151
+              changeList(item);
152
+              EasyLoading.dismiss();
153
+            }).catchError((error) {
154
+              Fluttertoast.showToast(msg: error.error['message']);
155
+              EasyLoading.dismiss();
156
+            });
157
+          });
158
+    } else {
159
+      modal.showDialog(
160
+        content: endContent(),
161
+        onConfirm: () {
162
+          if (area.value == '') {
163
+            Fluttertoast.showToast(msg: '请输入正确的面积整数或最多两位小数');
164
+            return false;
165
+          } else {
166
+            EasyLoading.show(status: '请稍后');
167
+            overJob(item.jobId.toString(), {
168
+              ...item.toJson(),
169
+              'area': area.value.toString()
170
+            }).then((value) {
171
+              //关闭弹窗需要改变列表
172
+              changeList(item);
173
+              EasyLoading.dismiss();
174
+              Fluttertoast.showToast(msg: '恭喜完成作业');
175
+            }).catchError((error) {
176
+              Fluttertoast.showToast(msg: error.error['message']);
177
+              EasyLoading.dismiss();
178
+            });
179
+          }
180
+        },
181
+      );
182
+    }
183
+  }
184
+
48 185
   @override
49 186
   Widget builder(BuildContext context) {
50 187
     return Container(
@@ -52,49 +189,49 @@ class Home extends BasicPage {
52 189
       padding: EdgeInsets.all(15.w),
53 190
       child: Column(
54 191
         children: [
55
-          const headers(),
56
-          //banner
57
-          Container(
58
-            margin: EdgeInsets.fromLTRB(0, 15.h, 0, 15.h),
59
-            child: Obx(() => CarouselSlider(
60
-                  items: bannerList.value
61
-                      .map((item) => Center(
62
-                          child: Image.network(item.thumb.toString(),
63
-                              fit: BoxFit.cover, width: 345.w)))
64
-                      .toList(),
65
-                  options: CarouselOptions(
66
-                    autoPlay: true,
67
-                    enlargeCenterPage: false,
68
-                    //图片中心放大
69
-                    viewportFraction: 1,
70
-                    //每个页面应占据的视口部分。默认为 0.8,这意味着每个页面填充 80% 的轮播。
71
-                    // aspectRatio: 1.6,//纵横比
72
-                    height: 214.w,
73
-                    initialPage: 1, //初始页
74
-                  ),
75
-                )),
76
-          ),
77
-          Container(
78
-            margin: EdgeInsets.fromLTRB(0, 15.h, 0, 20.h),
79
-            child: Row(
80
-              children: [
81
-                Padding(
82
-                  padding: EdgeInsets.fromLTRB(0, 0, 10.w, 0),
83
-                  child: Image.asset(
84
-                    'images/index/orderList.png',
85
-                    width: 20.w,
86
-                  ),
87
-                ),
88
-                Text(
89
-                  '作业列表',
90
-                  style: TextStyle(
91
-                      color: Color(0xff222222),
92
-                      fontSize: 20.sp,
93
-                      fontWeight: FontWeight.w800),
94
-                )
95
-              ],
96
-            ),
97
-          ),
192
+          // const headers(),
193
+          // //banner
194
+          // Container(
195
+          //   margin: EdgeInsets.fromLTRB(0, 15.h, 0, 15.h),
196
+          //   child: Obx(() => CarouselSlider(
197
+          //         items: bannerList.value
198
+          //             .map((item) => Center(
199
+          //                 child: Image.network(item.thumb.toString(),
200
+          //                     fit: BoxFit.cover, width: 345.w)))
201
+          //             .toList(),
202
+          //         options: CarouselOptions(
203
+          //           autoPlay: true,
204
+          //           enlargeCenterPage: false,
205
+          //           //图片中心放大
206
+          //           viewportFraction: 1,
207
+          //           //每个页面应占据的视口部分。默认为 0.8,这意味着每个页面填充 80% 的轮播。
208
+          //           // aspectRatio: 1.6,//纵横比
209
+          //           height: 214.w,
210
+          //           initialPage: 1, //初始页
211
+          //         ),
212
+          //       )),
213
+          // ),
214
+          // Container(
215
+          //   margin: EdgeInsets.fromLTRB(0, 15.h, 0, 20.h),
216
+          //   child: Row(
217
+          //     children: [
218
+          //       Padding(
219
+          //         padding: EdgeInsets.fromLTRB(0, 0, 10.w, 0),
220
+          //         child: Image.asset(
221
+          //           'images/index/orderList.png',
222
+          //           width: 20.w,
223
+          //         ),
224
+          //       ),
225
+          //       Text(
226
+          //         '作业列表',
227
+          //         style: TextStyle(
228
+          //             color: Color(0xff222222),
229
+          //             fontSize: 20.sp,
230
+          //             fontWeight: FontWeight.w800),
231
+          //       )
232
+          //     ],
233
+          //   ),
234
+          // ),
98 235
           Expanded(
99 236
             flex: 1,
100 237
             child: RefreshMoreList(

+ 36
- 35
lib/pages/jobDetail/index.dart Ver fichero

@@ -57,49 +57,50 @@ class JobDetail extends BasicPage {
57 57
               color: const Color(0xff323232),
58 58
             ),
59 59
           ),
60
-        )
60
+        ),
61 61
       ],
62 62
     );
63 63
   }
64 64
 
65 65
   Widget endContent() {
66 66
     return Container(
67
-        margin: EdgeInsets.fromLTRB(15.w, 0, 15.w, 25.h),
68
-        padding: EdgeInsets.symmetric(vertical: 18.h, horizontal: 15.w),
69
-        decoration: BoxDecoration(
70
-            border: Border.all(
71
-                width: 1.w,
72
-                style: BorderStyle.solid,
73
-                color: const Color(0xFFF2F2F2)),
74
-            borderRadius: BorderRadius.all(Radius.circular(20.w))),
75
-        child: Row(
76
-          children: [
77
-            Text(
78
-              '作业面积:',
79
-              style: TextStyle(
80
-                fontSize: 17.sp,
81
-                fontWeight: FontWeight.w500,
82
-                color: const Color(0xff333333),
83
-              ),
67
+      margin: EdgeInsets.fromLTRB(15.w, 0, 15.w, 25.h),
68
+      padding: EdgeInsets.symmetric(vertical: 18.h, horizontal: 15.w),
69
+      decoration: BoxDecoration(
70
+          border: Border.all(
71
+              width: 1.w,
72
+              style: BorderStyle.solid,
73
+              color: const Color(0xFFF2F2F2)),
74
+          borderRadius: BorderRadius.all(Radius.circular(20.w))),
75
+      child: Row(
76
+        children: [
77
+          Text(
78
+            '作业面积:',
79
+            style: TextStyle(
80
+              fontSize: 17.sp,
81
+              fontWeight: FontWeight.w500,
82
+              color: const Color(0xff333333),
84 83
             ),
85
-            Expanded(
86
-              child: TextField(
87
-                keyboardType: TextInputType.number,
88
-                style: TextStyle(fontSize: 16.sp),
89
-                decoration: const InputDecoration(
90
-                  isCollapsed: true,
91
-                  hintText: '请输入本次作业的面积',
92
-                  border: InputBorder.none,
93
-                  counterText: '', //去掉计数
94
-                  floatingLabelBehavior: FloatingLabelBehavior.never,
95
-                ),
96
-                onChanged: (e) {
97
-                  area(e);
98
-                },
84
+          ),
85
+          Expanded(
86
+            child: TextField(
87
+              keyboardType: TextInputType.number,
88
+              style: TextStyle(fontSize: 16.sp),
89
+              decoration: const InputDecoration(
90
+                isCollapsed: true,
91
+                hintText: '请输入本次作业的面积',
92
+                border: InputBorder.none,
93
+                counterText: '', //去掉计数
94
+                floatingLabelBehavior: FloatingLabelBehavior.never,
99 95
               ),
100
-            )
101
-          ],
102
-        ));
96
+              onChanged: (e) {
97
+                area(e);
98
+              },
99
+            ),
100
+          )
101
+        ],
102
+      ),
103
+    );
103 104
   }
104 105
 
105 106
   void changeJob(Job item) {