From f325cce223071c69ccc32deba6dd535dea216e2e Mon Sep 17 00:00:00 2001 From: louis <869322496@qq.com> Date: Thu, 21 Mar 2024 16:22:00 +0800 Subject: [PATCH] feat: inventory home page --- lib/config.dart | 1 + lib/constants/enum.dart | 8 + lib/models/index.dart | 1 + lib/models/inventory_inout.model.dart | 98 ++++++++++ .../components/inventory_inout_card.dart | 177 ++++++++++++++++++ .../inventory_inout_card_content.dart | 72 +++++++ .../components/task_detail_col.dart | 68 ------- .../components/task_detail_container.dart | 153 --------------- .../inventory_inout/components/task_list.dart | 5 +- .../components/task_page_View.dart | 33 +--- .../components/today_button.dart | 4 +- .../components/upper_body.dart | 2 +- .../inventory_inout_controller.dart | 66 ++++--- .../new_inventory_inout_controller.dart | 52 ++--- lib/services/dio.service.dart | 2 +- 15 files changed, 437 insertions(+), 305 deletions(-) create mode 100644 lib/models/inventory_inout.model.dart create mode 100644 lib/screens/inventory_inout/components/inventory_inout_card.dart create mode 100644 lib/screens/inventory_inout/components/inventory_inout_card_content.dart delete mode 100644 lib/screens/inventory_inout/components/task_detail_col.dart delete mode 100644 lib/screens/inventory_inout/components/task_detail_container.dart diff --git a/lib/config.dart b/lib/config.dart index bb2c5d5..c7d7ca1 100644 --- a/lib/config.dart +++ b/lib/config.dart @@ -2,6 +2,7 @@ class GloablConfig { // static const BASE_URL = "http://10.0.2.2:7001/api/"; static const BASE_URL = "http://192.168.60.220:7001/api/"; + static const OSS_URL = "http://192.168.60.220:7001"; static const DOMAIN_NAME = "山矿通"; static const DEBUG = true; static const PRIVACY_POLICY = 'http://h5.heeru.xyz/privacyPolicy.html'; diff --git a/lib/constants/enum.dart b/lib/constants/enum.dart index 358a6e1..f21a38e 100644 --- a/lib/constants/enum.dart +++ b/lib/constants/enum.dart @@ -3,3 +3,11 @@ enum BackActionEnum { } enum LoginEnum { apple, fastLogin } + +enum InventoryInOrOutEnum { In, Out } + +// 创建一个映射,将 InventoryInOrOutEnum 值与整数关联起来 +const Map InventoryInOrOutEnumValues = { + InventoryInOrOutEnum.In: 1, + InventoryInOrOutEnum.Out: 2, +}; diff --git a/lib/models/index.dart b/lib/models/index.dart index 19c575e..318b65c 100644 --- a/lib/models/index.dart +++ b/lib/models/index.dart @@ -4,3 +4,4 @@ export './project.model.dart'; export './product.model.dart'; export './dict_item.model.dart'; export './company.model.dart'; +export './inventory_inout.model.dart'; diff --git a/lib/models/inventory_inout.model.dart b/lib/models/inventory_inout.model.dart new file mode 100644 index 0000000..c4d29a2 --- /dev/null +++ b/lib/models/inventory_inout.model.dart @@ -0,0 +1,98 @@ +import 'package:sk_base_mobile/constants/enum.dart'; +import 'package:sk_base_mobile/models/file.model.dart'; +import 'package:sk_base_mobile/models/index.dart'; +import 'package:sk_base_mobile/models/product.model.dart'; +import 'package:sk_base_mobile/models/project.model.dart'; + +class InventoryInOutModel { + InventoryInOutModel({ + required this.id, + required this.createdAt, + required this.updatedAt, + required this.inventoryNumber, + required this.productId, + required this.inOrOut, + required this.time, + required this.quantity, + required this.unitPrice, + required this.amount, + required this.agent, + required this.issuanceNumber, + required this.remark, + required this.projectId, + required this.isDelete, + required this.files, + required this.project, + required this.product, + }); + + final int? id; + final DateTime? createdAt; + final DateTime? updatedAt; + final String? inventoryNumber; + final int? productId; + final int? inOrOut; + final DateTime? time; + final int? quantity; + final String? unitPrice; + final String? amount; + final String? agent; + final dynamic issuanceNumber; + final String? remark; + final int? projectId; + final int? isDelete; + final List files; + final ProjectModel? project; + final ProductModel? product; + + factory InventoryInOutModel.fromJson(Map json) { + return InventoryInOutModel( + id: json["id"], + createdAt: DateTime.tryParse(json["createdAt"] ?? ""), + updatedAt: DateTime.tryParse(json["updatedAt"] ?? ""), + inventoryNumber: json["inventoryNumber"], + productId: json["productId"], + inOrOut: json["inOrOut"], + time: DateTime.tryParse(json["time"] ?? ""), + quantity: json["quantity"], + unitPrice: json["unitPrice"], + amount: json["amount"], + agent: json["agent"], + issuanceNumber: json["issuanceNumber"], + remark: json["remark"], + projectId: json["projectId"], + isDelete: json["isDelete"], + files: json["files"] == null + ? [] + : List.from( + json["files"]!.map((x) => FileModel.fromJson(x))), + project: json["project"] == null + ? null + : ProjectModel.fromJson(json["project"]), + product: json["product"] == null + ? null + : ProductModel.fromJson(json["product"]), + ); + } + + Map toJson() => { + "id": id, + "createdAt": createdAt?.toIso8601String(), + "updatedAt": updatedAt?.toIso8601String(), + "inventoryNumber": inventoryNumber, + "productId": productId, + "inOrOut": inOrOut, + "time": time, + "quantity": quantity, + "unitPrice": unitPrice, + "amount": amount, + "agent": agent, + "issuanceNumber": issuanceNumber, + "remark": remark, + "projectId": projectId, + "isDelete": isDelete, + "files": files.map((x) => x).toList(), + "project": project?.toJson(), + "product": product?.toJson(), + }; +} diff --git a/lib/screens/inventory_inout/components/inventory_inout_card.dart b/lib/screens/inventory_inout/components/inventory_inout_card.dart new file mode 100644 index 0000000..2ff2c72 --- /dev/null +++ b/lib/screens/inventory_inout/components/inventory_inout_card.dart @@ -0,0 +1,177 @@ +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:sk_base_mobile/config.dart'; +import 'package:sk_base_mobile/constants/bg_color.dart'; +import 'package:sk_base_mobile/constants/data.dart'; +import 'package:sk_base_mobile/constants/enum.dart'; +import 'package:sk_base_mobile/screens/inventory_inout/components/inventory_inout_card_content.dart'; +import 'package:sk_base_mobile/screens/inventory_inout/inventory_inout_controller.dart'; +import 'package:sk_base_mobile/util/util.dart'; +import 'package:sk_base_mobile/widgets/fade_in_cache_image.dart'; + +class InventoryInoutCard extends StatelessWidget { + InventoryInoutCard({required this.index, required this.ind}); + final int index; + final int ind; + final controller = Get.find(); + @override + Widget build(BuildContext context) { + return Dismissible( + key: UniqueKey(), + confirmDismiss: (direction) async { + // return await ModalUtil.showWarningDialog( + // 'Remove Task', 'Are you sure to remove this task', 'Confirm', () { + // controller.db.delete(controller.list[ind][index].key, 'Tasks'); + // controller.list[ind].remove(controller.list[ind][index]); + // }); + }, + child: Container( + margin: EdgeInsets.symmetric( + vertical: ScreenAdaper.height(15), + horizontal: ScreenAdaper.width(15)), + padding: EdgeInsets.symmetric( + horizontal: ScreenAdaper.width(defaultPadding)), + decoration: BoxDecoration( + boxShadow: [ + BoxShadow( + color: lightAccentBlue.withOpacity(.5), + offset: Offset(0, ScreenAdaper.height(5)), + blurRadius: ScreenAdaper.sp(10)), + ], + color: Colors.white, + borderRadius: BorderRadius.circular(ScreenAdaper.sp(30))), + child: Row( + children: [ + // Image.asset( + // Data().images[controller.list[ind][index].image], + // height: 100, + // width: 100, + // ), + if (controller.list[ind][index].files.isNotEmpty) + ClipRRect( + borderRadius: BorderRadius.circular(ScreenAdaper.sp(15)), + child: FadeInCacheImage( + width: ScreenAdaper.width(100), + height: ScreenAdaper.width(100), + url: + '${GloablConfig.OSS_URL}${controller.list[ind][index].files[0]?.path}'), + ), + SizedBox( + width: ScreenAdaper.width(defaultPadding) / 2, + ), + InventoryInoutCardContent(index: index, ind: ind), + // const Spacer( + // flex: 2, + // ), + // controller.list[ind][index].inOrOut == + // InventoryInOrOutEnumValues[InventoryInOrOutEnum.In] + // ? Container( + // height: ScreenAdaper.height(40), + // width: ScreenAdaper.width(40), + // decoration: BoxDecoration( + // shape: BoxShape.circle, + // gradient: const LinearGradient( + // begin: Alignment.topCenter, + // end: Alignment.bottomCenter, + // colors: [ + // lightOrange, + // darkOrange, + // ]), + // boxShadow: [ + // BoxShadow( + // color: lightOrange, + // offset: Offset(0, ScreenAdaper.height(10)), + // blurRadius: ScreenAdaper.sp(10)) + // ]), + // child: const Icon( + // Icons.done, + // color: Colors.white, + // ), + // ) + // : Align( + // alignment: Alignment.topRight, + // child: Padding( + // padding: EdgeInsets.only(top: ScreenAdaper.height(20)), + // child: PopupMenuButton( + // onSelected: (value) => { + // // controller.onTaskComplete(value, index, ind, + // // controller.list[ind][index].key, context) + // }, + // surfaceTintColor: Colors.white, + // padding: EdgeInsets.zero, + // icon: Icon( + // Icons.more_vert_rounded, + // color: Colors.grey, + // size: ScreenAdaper.sp(24), + // ), + // shape: OutlineInputBorder( + // borderRadius: + // BorderRadius.circular(ScreenAdaper.sp(20)), + // borderSide: BorderSide.none, + // ), + // itemBuilder: (context) { + // return [ + // PopupMenuItem( + // height: ScreenAdaper.height(20), + // value: 1, + // child: Row( + // children: [ + // Icon( + // Icons.edit_note, + // color: Colors.orange, + // size: ScreenAdaper.sp(14), + // ), + // SizedBox( + // width: + // ScreenAdaper.width(defaultPadding) / + // 2, + // ), + // const Text('Edit') + // ], + // )), + // PopupMenuItem( + // height: ScreenAdaper.height(25), + // value: 2, + // child: Row( + // children: [ + // Icon( + // Icons.delete_outline, + // color: Colors.orange, + // size: ScreenAdaper.sp(14), + // ), + // SizedBox( + // width: + // ScreenAdaper.width(defaultPadding) / + // 2, + // ), + // Text('Delete') + // ], + // )), + // PopupMenuItem( + // height: ScreenAdaper.height(25), + // value: 3, + // child: Row( + // children: [ + // Icon( + // Icons.done_all_outlined, + // color: Colors.orange, + // size: ScreenAdaper.sp(14), + // ), + // SizedBox( + // width: + // ScreenAdaper.width(defaultPadding) / + // 2, + // ), + // Text('Complete') + // ], + // )), + // ]; + // }, + // )), + // ), + ], + ), + ), + ); + } +} diff --git a/lib/screens/inventory_inout/components/inventory_inout_card_content.dart b/lib/screens/inventory_inout/components/inventory_inout_card_content.dart new file mode 100644 index 0000000..4eb13d6 --- /dev/null +++ b/lib/screens/inventory_inout/components/inventory_inout_card_content.dart @@ -0,0 +1,72 @@ +import 'dart:math'; + +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:sk_base_mobile/constants/bg_color.dart'; +import 'package:sk_base_mobile/constants/data.dart'; +import 'package:sk_base_mobile/screens/inventory_inout/inventory_inout_controller.dart'; +import 'package:sk_base_mobile/util/screen_adaper_util.dart'; + +class InventoryInoutCardContent extends StatelessWidget { + InventoryInoutCardContent( + {super.key, required this.index, required this.ind}); + final int index; + final int ind; + final int randomColor1 = Random().nextInt(9); + final int randomColor2 = Random().nextInt(9); + final controller = Get.find(); + @override + Widget build(BuildContext context) { + return Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + controller.list[ind][index].product?.name ?? 'Product Name', + style: TextStyle( + color: Colors.black, + fontWeight: FontWeight.bold, + fontSize: ScreenAdaper.sp(25)), + ), + // Text( + // '${controller.list[ind][index].time} - ${controller.list[ind][index].time}', + // style: const TextStyle( + // color: Colors.grey, fontWeight: FontWeight.w300, fontSize: 12), + // ), + SizedBox( + height: ScreenAdaper.width(defaultPadding) / 2, + ), + // Row( + // children: [ + // Container( + // alignment: Alignment.center, + // padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 10), + // decoration: BoxDecoration( + // color: Data().colors[randomColor1].withOpacity(.5), + // borderRadius: BorderRadius.circular(10), + // ), + // child: Text( + // Data().tags[Random().nextInt(13)], + // style: TextStyle(color: Data().colors[randomColor1]), + // ), + // ), + // const SizedBox( + // width: defaultPadding / 2, + // ), + // Container( + // alignment: Alignment.center, + // padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 10), + // decoration: BoxDecoration( + // color: Data().colors[randomColor2].withOpacity(.5), + // borderRadius: BorderRadius.circular(10)), + // child: Text( + // Data().tags[Random().nextInt(13)], + // style: TextStyle(color: Data().colors[randomColor2]), + // ), + // ) + // ], + // ), + ], + ); + } +} diff --git a/lib/screens/inventory_inout/components/task_detail_col.dart b/lib/screens/inventory_inout/components/task_detail_col.dart deleted file mode 100644 index 7b4c49b..0000000 --- a/lib/screens/inventory_inout/components/task_detail_col.dart +++ /dev/null @@ -1,68 +0,0 @@ -import 'dart:math'; - -import 'package:flutter/material.dart'; -import 'package:get/get.dart'; -import 'package:sk_base_mobile/constants/bg_color.dart'; -import 'package:sk_base_mobile/constants/data.dart'; -import 'package:sk_base_mobile/screens/inventory_inout/inventory_inout_controller.dart'; - -class TaskTitle extends StatelessWidget { - TaskTitle({super.key, required this.index, required this.ind}); - final int index; - final int ind; - final int randomColor1 = Random().nextInt(9); - final int randomColor2 = Random().nextInt(9); - final controller = Get.put(InventoryInoutController()); - @override - Widget build(BuildContext context) { - return Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - controller.list[ind][index].title, - style: const TextStyle( - color: Colors.black, fontWeight: FontWeight.bold, fontSize: 20), - ), - Text( - '${controller.list[ind][index].startTime} - ${controller.list[ind][index].endTime}', - style: const TextStyle( - color: Colors.grey, fontWeight: FontWeight.w300, fontSize: 12), - ), - const SizedBox( - height: defaultPadding / 2, - ), - Row( - children: [ - Container( - alignment: Alignment.center, - padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 10), - decoration: BoxDecoration( - color: Data().colors[randomColor1].withOpacity(.5), - borderRadius: BorderRadius.circular(10), - ), - child: Text( - Data().tags[Random().nextInt(13)], - style: TextStyle(color: Data().colors[randomColor1]), - ), - ), - const SizedBox( - width: defaultPadding / 2, - ), - Container( - alignment: Alignment.center, - padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 10), - decoration: BoxDecoration( - color: Data().colors[randomColor2].withOpacity(.5), - borderRadius: BorderRadius.circular(10)), - child: Text( - Data().tags[Random().nextInt(13)], - style: TextStyle(color: Data().colors[randomColor2]), - ), - ) - ], - ), - ], - ); - } -} diff --git a/lib/screens/inventory_inout/components/task_detail_container.dart b/lib/screens/inventory_inout/components/task_detail_container.dart deleted file mode 100644 index c5861e7..0000000 --- a/lib/screens/inventory_inout/components/task_detail_container.dart +++ /dev/null @@ -1,153 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:get/get.dart'; -import 'package:sk_base_mobile/constants/bg_color.dart'; -import 'package:sk_base_mobile/constants/data.dart'; -import 'package:sk_base_mobile/screens/inventory_inout/components/task_detail_col.dart'; -import 'package:sk_base_mobile/screens/inventory_inout/inventory_inout_controller.dart'; -import 'package:sk_base_mobile/util/util.dart'; - -class TaskDetailContainer extends StatelessWidget { - TaskDetailContainer({super.key, required this.index, required this.ind}); - final int index; - final int ind; - final controller = Get.put(InventoryInoutController()); - @override - Widget build(BuildContext context) { - return Dismissible( - key: UniqueKey(), - confirmDismiss: (direction) async { - return await ModalUtil.showWarningDialog( - 'Remove Task', 'Are you sure to remove this task', 'Confirm', () { - controller.db.delete(controller.list[ind][index].key, 'Tasks'); - controller.list[ind].remove(controller.list[ind][index]); - }); - }, - child: Container( - margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 20), - padding: const EdgeInsets.symmetric(horizontal: 10), - decoration: BoxDecoration(boxShadow: [ - BoxShadow( - color: lightAccentBlue.withOpacity(.5), - offset: Offset(0, 5), - blurRadius: 10), - ], color: Colors.white, borderRadius: BorderRadius.circular(30)), - child: Row( - children: [ - Image.asset( - Data().images[controller.list[ind][index].image], - height: 100, - width: 100, - ), - const Spacer( - flex: 1, - ), - TaskTitle(index: index, ind: ind), - const Spacer( - flex: 2, - ), - controller.list[ind][index].status == 'complete' - ? Container( - height: 40, - width: 40, - decoration: const BoxDecoration( - shape: BoxShape.circle, - gradient: LinearGradient( - begin: Alignment.topCenter, - end: Alignment.bottomCenter, - colors: [ - lightOrange, - darkOrange, - ]), - boxShadow: [ - BoxShadow( - color: lightOrange, - offset: Offset(0, 10), - blurRadius: 10) - ]), - child: const Icon( - Icons.done, - color: Colors.white, - ), - ) - : Align( - alignment: Alignment.topRight, - child: Padding( - padding: const EdgeInsets.only(top: 20), - child: PopupMenuButton( - onSelected: (value) => controller.onTaskComplete( - value, - index, - ind, - controller.list[ind][index].key, - context), - surfaceTintColor: Colors.white, - padding: EdgeInsets.zero, - icon: const Icon( - Icons.more_vert_rounded, - color: Colors.grey, - size: 24, - ), - shape: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: BorderSide.none, - ), - itemBuilder: (context) { - return [ - const PopupMenuItem( - height: 25, - value: 1, - child: Row( - children: [ - Icon( - Icons.edit_note, - color: Colors.orange, - size: 14, - ), - SizedBox( - width: defaultPadding / 2, - ), - Text('Edit') - ], - )), - const PopupMenuItem( - height: 25, - value: 2, - child: Row( - children: [ - Icon( - Icons.delete_outline, - color: Colors.orange, - size: 14, - ), - SizedBox( - width: defaultPadding / 2, - ), - Text('Delete') - ], - )), - const PopupMenuItem( - height: 25, - value: 3, - child: Row( - children: [ - Icon( - Icons.done_all_outlined, - color: Colors.orange, - size: 14, - ), - SizedBox( - width: defaultPadding / 2, - ), - Text('Complete') - ], - )), - ]; - }, - )), - ), - ], - ), - ), - ); - } -} diff --git a/lib/screens/inventory_inout/components/task_list.dart b/lib/screens/inventory_inout/components/task_list.dart index e3a495d..957bf13 100644 --- a/lib/screens/inventory_inout/components/task_list.dart +++ b/lib/screens/inventory_inout/components/task_list.dart @@ -3,7 +3,7 @@ import 'package:get/get.dart'; import 'package:sk_base_mobile/app_theme.dart'; import 'package:sk_base_mobile/constants/constants.dart'; import 'package:sk_base_mobile/screens/inventory_inout/components/responsive.dart'; -import 'package:sk_base_mobile/screens/inventory_inout/components/task_detail_container.dart'; +import 'package:sk_base_mobile/screens/inventory_inout/components/inventory_inout_card.dart'; import 'package:sk_base_mobile/screens/inventory_inout/inventory_inout_controller.dart'; import 'package:sk_base_mobile/util/util.dart'; @@ -56,12 +56,11 @@ class Grid extends StatelessWidget { ) : GridView.builder( padding: const EdgeInsets.only(top: 40), - reverse: true, itemCount: controller.list[ind].length, gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: crossAsis, childAspectRatio: ratio), itemBuilder: (context, index) { - return TaskDetailContainer( + return InventoryInoutCard( index: index, ind: ind, ); diff --git a/lib/screens/inventory_inout/components/task_page_View.dart b/lib/screens/inventory_inout/components/task_page_View.dart index 1f90c65..7376786 100644 --- a/lib/screens/inventory_inout/components/task_page_View.dart +++ b/lib/screens/inventory_inout/components/task_page_View.dart @@ -9,31 +9,12 @@ class TaskPageView extends StatelessWidget { @override Widget build(BuildContext context) { return PageView( - physics: const NeverScrollableScrollPhysics(), - controller: controller.pageController, - children: const [ - TaskList( - index: 0, - ), - TaskList( - index: 1, - ), - TaskList( - index: 2, - ), - TaskList( - index: 3, - ), - TaskList( - index: 4, - ), - TaskList( - index: 5, - ), - TaskList( - index: 6, - ), - ], - ); + physics: const NeverScrollableScrollPhysics(), + controller: controller.pageController, + children: List.generate( + controller.daysNum, + (index) => TaskList( + index: index, + ))); } } diff --git a/lib/screens/inventory_inout/components/today_button.dart b/lib/screens/inventory_inout/components/today_button.dart index 637d98e..43356ee 100644 --- a/lib/screens/inventory_inout/components/today_button.dart +++ b/lib/screens/inventory_inout/components/today_button.dart @@ -24,8 +24,8 @@ class TodayButton extends StatelessWidget { boxShadow: [ BoxShadow( color: AppTheme.primaryColorLight, - offset: Offset(0, ScreenAdaper.height(10)), - blurRadius: ScreenAdaper.sp(25)) + offset: Offset(0, ScreenAdaper.height(5)), + blurRadius: ScreenAdaper.sp(20)) ], gradient: const LinearGradient( begin: Alignment.topLeft, diff --git a/lib/screens/inventory_inout/components/upper_body.dart b/lib/screens/inventory_inout/components/upper_body.dart index 65afb6d..022c1cb 100644 --- a/lib/screens/inventory_inout/components/upper_body.dart +++ b/lib/screens/inventory_inout/components/upper_body.dart @@ -23,7 +23,7 @@ class UperBody extends StatelessWidget { controller: controller.scrollController, shrinkWrap: true, reverse: true, - itemCount: 20, + itemCount: controller.daysNum, scrollDirection: Axis.horizontal, padding: EdgeInsets.only( bottom: ScreenAdaper.height(20), top: defaultPadding), diff --git a/lib/screens/inventory_inout/inventory_inout_controller.dart b/lib/screens/inventory_inout/inventory_inout_controller.dart index 4ea9ef2..291de5b 100644 --- a/lib/screens/inventory_inout/inventory_inout_controller.dart +++ b/lib/screens/inventory_inout/inventory_inout_controller.dart @@ -7,6 +7,7 @@ import 'package:sk_base_mobile/util/date.util.dart'; import 'package:sk_base_mobile/util/modal.util.dart'; import 'package:sk_base_mobile/util/screen_adaper_util.dart'; import 'package:sk_base_mobile/apis/api.dart' as Api; +import '../../models/index.dart'; import 'components/responsive.dart'; class InventoryInoutController extends GetxController { @@ -15,18 +16,25 @@ class InventoryInoutController extends GetxController { final PageController pageController = PageController(); final DateTime dateTime = DateTime.now(); final DbHelper db = DbHelper(); - List list = [ - [].obs, - [].obs, - [].obs, - [].obs, - [].obs, - [].obs, - [].obs, + List> list = [ + [].obs, + [].obs, + [].obs, + [].obs, + [].obs, + [].obs, + [].obs, ].obs; RxInt barIndex = 0.obs; RxList model = [].obs; final ScrollController scrollController = ScrollController(); + final daysNum = 20; + @override + void onInit() { + super.onInit(); + getTasks(); + // getInoutHistory(); + } /// 打开出库还是入库选择框 Future showInOrOutPickerDialog() async { @@ -220,16 +228,22 @@ class InventoryInoutController extends GetxController { ); } - Future getInoutHistory() async { + Future> getInoutHistory() async { final res = await Api.getInventoryInout({}); - + printInfo(info: res.toString()); + if (res.data != null) { + return res.data!.items + .map((e) => InventoryInOutModel.fromJson(e)) + .toList(); + } + return []; // final List> queryResult = // await dbClient!.query('Tasks'); // return queryResult.map((e) => TaskModel.fromMap(e)).toList(); } getTasks() async { - db.getData().then((value) { + getInoutHistory().then((value) { model.value = value; getSepretLists(); }); @@ -242,22 +256,24 @@ class InventoryInoutController extends GetxController { } getDateAccordingTabs(int value) { - return '${DateUtil.addPrefix(dateTime.add(Duration(days: value)).day.toString())}/${DateUtil.addPrefix(dateTime.add(Duration(days: value)).month.toString())}/${DateUtil.addPrefix(dateTime.add(Duration(days: value)).year.toString())}'; + return '${DateUtil.addPrefix(dateTime.add(Duration(days: value)).year.toString())}-${DateUtil.addPrefix(dateTime.add(Duration(days: value)).month.toString())}-${DateUtil.addPrefix(dateTime.add(Duration(days: value)).day.toString())}'; } getSepretLists() { - List> tempList = []; + List> tempList = []; for (int i = 0; i < 7; i++) { - RxList tempList1 = [].obs; + RxList tempList1 = [].obs; tempList1.clear(); for (int j = 0; j < model.length; j++) { - if (model[j].date == getDateAccordingTabs(i)) { + final sourceDateStr = DateUtil.format(model[j].time); + final currentDateStr = getDateAccordingTabs(i); + if (sourceDateStr == currentDateStr) { tempList1.add(model[j]); } } tempList.add(tempList1); } - list = tempList; + list.assignAll(tempList); } onMoveNextPage() { @@ -276,15 +292,15 @@ class InventoryInoutController extends GetxController { int value, int index, int ind, String key, BuildContext context) { switch (value) { case 3: - { - ModalUtil.showWarningDialog('Complete Task', - 'This task will be marked as completed', 'Confirm', () { - list[ind][index].status = 'complete'; - list[ind].add(''); - list[ind].remove(''); - db.update(key, 'status', 'complete'); - }); - } + // { + // ModalUtil.showWarningDialog('Complete Task', + // 'This task will be marked as completed', 'Confirm', () { + // list[ind][index].status = 'complete'; + // list[ind].add(''); + // list[ind].remove(''); + // db.update(key, 'status', 'complete'); + // }); + // } case 2: { ModalUtil.showWarningDialog( diff --git a/lib/screens/new_inventory_inout/new_inventory_inout_controller.dart b/lib/screens/new_inventory_inout/new_inventory_inout_controller.dart index ac17d05..7ab8271 100644 --- a/lib/screens/new_inventory_inout/new_inventory_inout_controller.dart +++ b/lib/screens/new_inventory_inout/new_inventory_inout_controller.dart @@ -233,31 +233,31 @@ class NewInventoryInoutController extends GetxController { } loading.value = true; - db - .insert(TaskModel( - key: DateTime.now().microsecondsSinceEpoch.toString(), - startTime: startTime.value, - endTime: endTime.value, - date: selectedDate.value, - periority: lowPeriority.value ? 'Low' : 'High', - description: description.value.text.toString(), - category: category.value.text.toString(), - title: label.value.text.toString(), - image: selectedImage.value.toString(), - show: 'yes', - status: 'unComplete')) - .then((value) { - Duration dif = pickedDate!.difference(DateTime( - DateTime.now().year, DateTime.now().month, DateTime.now().day)); - inventoryInoutController.list[dif.inDays].add(value); - Timer(const Duration(seconds: 1), () { - loading.value = false; - Get.back(); - SnackBarUtil().success( - 'Successful', - message: 'Task is created', - ); - }); - }); + // db + // .insert(TaskModel( + // key: DateTime.now().microsecondsSinceEpoch.toString(), + // startTime: startTime.value, + // endTime: endTime.value, + // date: selectedDate.value, + // periority: lowPeriority.value ? 'Low' : 'High', + // description: description.value.text.toString(), + // category: category.value.text.toString(), + // title: label.value.text.toString(), + // image: selectedImage.value.toString(), + // show: 'yes', + // status: 'unComplete')) + // .then((value) { + // Duration dif = pickedDate!.difference(DateTime( + // DateTime.now().year, DateTime.now().month, DateTime.now().day)); + // inventoryInoutController.list[dif.inDays].add(value); + // Timer(const Duration(seconds: 1), () { + // loading.value = false; + // Get.back(); + // SnackBarUtil().success( + // 'Successful', + // message: 'Task is created', + // ); + // }); + // }); } } diff --git a/lib/services/dio.service.dart b/lib/services/dio.service.dart index 409f049..4e2d0c2 100644 --- a/lib/services/dio.service.dart +++ b/lib/services/dio.service.dart @@ -136,7 +136,7 @@ class DioService extends Get.GetxService { if (response.data != null) { try { if (response.data['code'] == 200) { - if (GloablConfig.DEBUG) print(response.data['data']); + if (GloablConfig.DEBUG) LoggerUtil().info(response.data['data']); response.data = response.data['data']; // 分页数据处理