From 355fe96b2a4c7821256d9e8828d2cb9539904878 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 05 五月 2022 19:29:16 +0800
Subject: [PATCH] 功能完善

---
 flutter_module/lib/ui/task.dart |  270 ++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 214 insertions(+), 56 deletions(-)

diff --git a/flutter_module/lib/ui/task.dart b/flutter_module/lib/ui/task.dart
index 4198432..00ed6d6 100644
--- a/flutter_module/lib/ui/task.dart
+++ b/flutter_module/lib/ui/task.dart
@@ -4,11 +4,19 @@
 import 'package:flutter/material.dart';
 import 'package:fluttertoast/fluttertoast.dart';
 import 'package:makemoney/api/gold_corn_api.dart';
+import 'package:makemoney/api/msg_api.dart';
 import 'package:makemoney/model/goldcorn/signin_info_model.dart';
+import 'package:makemoney/model/goldcorn/task_list_model.dart';
+import 'package:makemoney/model/msg/app_notify_msg_model.dart';
+import 'package:makemoney/ui/mine/login.dart';
+import 'package:makemoney/ui/widget/base_ui.dart';
 import 'package:makemoney/ui/widget/button.dart';
+import 'package:makemoney/ui/widget/images_widget.dart';
 import 'package:makemoney/ui/widget/refresh_listview.dart';
+import 'package:makemoney/utils/pageutils.dart';
 import 'package:makemoney/utils/ui_constant.dart';
 import 'package:makemoney/utils/ui_utils.dart';
+import 'package:makemoney/utils/user_util.dart';
 
 import '../../ui/widget/nav.dart';
 
@@ -39,7 +47,13 @@
 
   int selectedIndex = 0;
 
+  bool _notify = true;
+
   FToast? fToast;
+
+  int _page = 1;
+
+  List<TaskListModel> _taskList = [];
 
   @override
   void initState() {
@@ -51,7 +65,7 @@
     //鍒濆鍖�
     _signInfo = SigninInfoModel(
         continueSignInDay: 0,
-        isSignIned: false,
+        isSignIned: true,
         notify: true,
         dayList: [
           DayList(day: "-", goldCorn: 0, state: 2, today: false),
@@ -64,8 +78,11 @@
         ]);
 
     _getSignInfo();
+    _getNotify();
+    _getTaskList(1);
   }
 
+  /***绛惧埌寮�濮�****/
   void _getSignInfo() async {
     Map<String, dynamic>? result = await GoldCornApiUtil.getSignInInfo(context);
     if (result == null) {
@@ -78,10 +95,18 @@
     SigninInfoModel temp = SigninInfoModel.fromJson(result["data"]);
     setState(() {
       _signInfo = temp;
+      _notify = _signInfo!.notify!;
     });
   }
 
   void _signIn() async {
+    bool login = await UserUtil.isLogin();
+    if (!login) {
+      NavigatorUtil.navigateToNextPage(
+          context, LoginPage(title: ""), (data) {});
+      return;
+    }
+
     Map<String, dynamic>? result = await GoldCornApiUtil.signIn(context);
     if (result == null) {
       return;
@@ -93,6 +118,95 @@
     var data = result["data"];
     showSignSuccessToast(data["goldCorn"], data["continueDay"]);
     _getSignInfo();
+  }
+
+  void _setSignInNotify(bool notify) async {
+    Map<String, dynamic>? result =
+        await GoldCornApiUtil.setSignInNotify(context, notify);
+    if (result == null) {
+      return;
+    }
+    if (result["code"] != 0) {
+      ToastUtil.toast(result["msg"], context);
+      return;
+    }
+  }
+
+  /***绛惧埌缁撴潫****/
+
+  AppNotifyMsgModel? _notifyMsg;
+
+  void _getNotify() async {
+    AppNotifyMsgModel? notifyMsgModel =
+        await MsgApiUtil.getNotifyMsg(context, "task");
+    setState(() {
+      _notifyMsg = notifyMsgModel;
+    });
+  }
+
+  //涓嬫媺鍒锋柊
+  void _refresh() {
+    if (_refreshController.dataNormal != null) {
+      _refreshController.dataNormal!();
+    }
+    _refreshController.loadComplete();
+    _getTaskList(1);
+  }
+
+  //鑾峰彇闃熷憳鍒楄〃
+  void _getTaskList(int page) async {
+    setState(() {
+      _page = page;
+    });
+
+    Map<String, dynamic>? result = await GoldCornApiUtil.getTaskList(context);
+
+    _refreshController.refreshCompleted();
+    _refreshController.loadComplete();
+
+    if (result == null && _page == 1&&_taskList.isEmpty) {
+      _refreshController.apiError!();
+    }
+
+    if (result == null || result["code"] != 0) {
+      //椤电爜鍥炴粴
+      if (_page > 1) {
+        setState(() {
+          _page = _page - 1;
+        });
+      }
+      return;
+    }
+    //瑙f瀽鏁版嵁
+    int count = result["data"]["count"];
+    List<dynamic> list = result["data"]["list"];
+    List<TaskListModel> tempList = [];
+    list.forEach((element) {
+      tempList.add(TaskListModel.fromJson(element));
+    });
+
+    if (_page == 1) {
+      setState(() {
+        _taskList = tempList;
+      });
+    } else {
+      setState(() {
+        _taskList.addAll(tempList);
+      });
+    }
+
+    //鍒ゆ柇鏁版嵁
+
+    if (_taskList.isEmpty) {
+      //绌烘暟鎹�
+      _refreshController.dataEmpty!();
+    } else {
+      _refreshController.dataNormal!();
+      if (count <= _taskList.length) {
+        //娌℃湁鏁版嵁浜�
+        _refreshController.loadNoData();
+      }
+    }
   }
 
   @override
@@ -129,10 +243,13 @@
                 ),
 
                 //閫氱煡娑堟伅
-                Container(
-                  height: 30,
-                  color: Colors.red,
-                ),
+                _notifyMsg == null
+                    ? Container(
+                        height: 30,
+                      )
+                    : NotifyWidget(_notifyMsg!.content!,
+                        textColor: Colors.white),
+
                 //绛惧埌
                 _signInfo == null
                     ? Container()
@@ -141,17 +258,23 @@
                         decoration: BoxDecoration(
                             color: Colors.white,
                             borderRadius: BorderRadius.circular(13)),
-                        padding: const EdgeInsets.fromLTRB(10, 10, 10, 10),
+                        padding: const EdgeInsets.fromLTRB(4, 20, 4, 10),
                         child: Column(
                           mainAxisSize: MainAxisSize.min,
                           children: [
                             Row(
                               crossAxisAlignment: CrossAxisAlignment.end,
                               children: [
+                                SizedBox(
+                                  width: 6,
+                                ),
                                 const Text(
                                   "绛惧埌棰嗛噾甯�",
                                   style: TextStyle(
-                                      color: ColorConstant.theme, fontSize: 15),
+                                      color: ColorConstant.theme,
+                                      fontSize: 15,
+                                      fontWeight: FontWeight.bold,
+                                      height: 1),
                                 ),
                                 const SizedBox(
                                   width: 5,
@@ -166,7 +289,8 @@
                                               "${_signInfo!.continueSignInDay}",
                                           style: const TextStyle(
                                               color: ColorConstant.theme,
-                                              fontSize: 12)),
+                                              fontSize: 12,
+                                              fontWeight: FontWeight.bold)),
                                       const TextSpan(text: "澶�")
                                     ])),
                                 Expanded(child: Container()),
@@ -178,12 +302,33 @@
                                 const SizedBox(
                                   width: 5,
                                 ),
-                                Image.asset(
-                                  _signInfo!.notify!
-                                      ? "assets/imgs/task/icon_task_sign_notify_checked.png"
-                                      : "assets/imgs/task/icon_task_sign_notify.png",
-                                  height: 12,
-                                )
+                                InkWell(
+                                    onTap: () {
+                                      UserUtil.isLogin().then((value) {
+                                        if (!value) {
+                                          NavigatorUtil.navigateToNextPage(
+                                              context,
+                                              LoginPage(title: ""),
+                                              (data) {});
+                                          return;
+                                        }
+                                        setState(() {
+                                          _notify = !_notify;
+                                        });
+                                        _setSignInNotify(_notify);
+                                      });
+                                    },
+                                    child: Padding(
+                                        padding: const EdgeInsets.only(top: 10),
+                                        child: Image.asset(
+                                          _notify
+                                              ? "assets/imgs/task/icon_task_sign_notify_checked.png"
+                                              : "assets/imgs/task/icon_task_sign_notify.png",
+                                          width: 22,
+                                        ))),
+                                const SizedBox(
+                                  width: 6,
+                                ),
                               ],
                             ),
                             Row(
@@ -193,21 +338,25 @@
                             const SizedBox(
                               height: 20,
                             ),
-                            MyFillButton(
-                              "绔嬪嵆绛惧埌",
-                              10,
-                              fontSize: 15,
-                              height: 42,
-                              color: _signInfo!.isSignIned!
-                                  ? ColorConstant.theme.withAlpha(128)
-                                  : ColorConstant.theme,
-                              onClick: () {
-                                if (_signInfo!.isSignIned!) {
-                                  return;
-                                }
-                                _signIn();
-                              },
-                            )
+                            Padding(
+                                padding:
+                                    const EdgeInsets.only(left: 6, right: 6),
+                                child: MyFillButton(
+                                  "绔嬪嵆绛惧埌",
+                                  10,
+                                  fontSize: 15,
+                                  height: 42,
+                                  color: _signInfo!.isSignIned!
+                                      ? ColorConstant.theme.withAlpha(128)
+                                      : ColorConstant.theme,
+                                  onClick: () {
+                                    if (_signInfo!.isSignIned!) {
+                                      return;
+                                    }
+
+                                    _signIn();
+                                  },
+                                ))
                           ],
                         ),
                       ),
@@ -225,7 +374,7 @@
                                 fontSize: 10, color: Color(0xFF666666)),
                           ),
                           const SizedBox(
-                            height: 5,
+                            height: 8,
                           ),
                           // Row(
                           //   children: [
@@ -236,18 +385,22 @@
                           Expanded(
                               child: Container(
                             alignment: Alignment.topCenter,
-                            margin: EdgeInsets.only(bottom: 10),
+                            margin: const EdgeInsets.only(bottom: 10),
                             decoration: BoxDecoration(
                                 color: Colors.white,
                                 borderRadius: BorderRadius.circular(13)),
                             child: RefreshListView(
-                              enablePullDown: false,
+                              refresh: () {
+                                _refresh();
+                              },
+                              enablePullUp: false,
                               refreshController: _refreshController,
                               loadTextColor: const Color(0xFFFF8316),
                               content: ListView.builder(
-                                itemCount: 5,
+                                padding: const EdgeInsets.only(top: 12),
+                                itemCount: _taskList.length,
                                 itemBuilder: (BuildContext context, int index) {
-                                  return getItemView(index, () {});
+                                  return getItemView(_taskList[index], () {});
                                 },
                               ),
                             ),
@@ -358,7 +511,7 @@
                 height: 55 * _sizeUnit!,
                 // padding: EdgeInsets.only(left: 10,right: 10),
                 child: Stack(children: [
-                  day.today!
+                  day.today! && !_signInfo!.isSignIned!
                       ? Image.asset(
                           "assets/imgs/task/ic_task_sign_day_item_hb_today.png")
                       : Padding(
@@ -441,12 +594,13 @@
         ));
   }
 
-  Widget getItemView(int index, GestureTapCallback onTap) {
-    return Padding(
-        padding: const EdgeInsets.only(top: 20, left: 16, right: 16, bottom: 5),
+  Widget getItemView(TaskListModel task, GestureTapCallback onTap) {
+    return Container(
+        padding:
+            const EdgeInsets.only(top: 10, left: 16, right: 16, bottom: 10),
         child: Row(
           mainAxisAlignment: MainAxisAlignment.start,
-          crossAxisAlignment: CrossAxisAlignment.start,
+          crossAxisAlignment: CrossAxisAlignment.center,
           children: [
             Container(
               width: 40,
@@ -462,47 +616,51 @@
                   ],
                 ),
               ),
-              child: Container(
-                margin: const EdgeInsets.all(2),
-                decoration: BoxDecoration(
-                  color: const Color(0xFFFFF8AE),
-                  borderRadius: BorderRadius.circular(40),
-                ),
-              ),
+              child: CommonImage(task.icon!),
             ),
-            SizedBox(
+            const SizedBox(
               width: 10,
             ),
             Column(
               crossAxisAlignment: CrossAxisAlignment.start,
               children: [
                 Text(
-                  "娴忚鎺ㄨ崘瑙嗛",
-                  style: TextStyle(color: Color(0xFF454545), fontSize: 12),
+                  task.name!,
+                  style: TextStyle(
+                      color: Color(0xFF454545), fontSize: 12, height: 1.2),
                 ),
                 Text(
-                  "浠婃棩杩涘害锛�1/3锛�",
-                  style: TextStyle(
+                  task.process!,
+                  style: const TextStyle(
                       color: Color(0xFF7F7F7F), fontSize: 9, height: 1.5),
                 ),
                 Text.rich(TextSpan(
-                    style: TextStyle(color: Color(0xFFFF8316), fontSize: 9),
+                    style:
+                        TextStyle(color: const Color(0xFFFF8316), fontSize: 9),
                     children: [
-                      TextSpan(text: "+"),
-                      TextSpan(text: "8888", style: TextStyle(fontSize: 10)),
-                      TextSpan(text: "閲戝竵/浜� (闇�鎵嬪姩棰嗗彇)"),
+                      const TextSpan(text: "+"),
+                      TextSpan(
+                          text: "${task.price}",
+                          style: TextStyle(fontSize: 10)),
+                      TextSpan(text: task.priceUnit),
                     ])),
               ],
             ),
             Expanded(child: Container()),
             MyOutlineButton(
-              "鍘诲畬鎴�",
+              task.actionName!,
               20,
               width: 62,
               height: 25,
               fontSize: 12,
               textColor: ColorConstant.theme,
               color: ColorConstant.theme,
+              onClick: () {
+                if (false == task.active!) {
+                  return;
+                }
+                jumpAppPage(task.jumpType!, null);
+              },
             )
           ],
         ));

--
Gitblit v1.8.0