diff --git a/lib/const/api.dart b/lib/const/api.dart index d94c624..4ebf479 100644 --- a/lib/const/api.dart +++ b/lib/const/api.dart @@ -68,4 +68,6 @@ class _Manage { ///借还管理:根据物品明细id 查询物品信息 String get borrowItemDetail => '/user/borrow/findById'; + + String get borrowStatusList => '/user/borrow/list'; } diff --git a/lib/models/manager/borrow/borrow_status_item_model.dart b/lib/models/manager/borrow/borrow_status_item_model.dart new file mode 100644 index 0000000..78ae7a7 --- /dev/null +++ b/lib/models/manager/borrow/borrow_status_item_model.dart @@ -0,0 +1,119 @@ +import 'package:aku_community_manager/models/common/img_model.dart'; +import 'package:aku_community_manager/style/app_style.dart'; +import 'package:common_utils/common_utils.dart'; +import 'package:flutter/material.dart'; + +class BorrowStatusItemModel { + int id; + int articleDetailId; + String articleName; + + ///借取状态(1.出借中,2.已还,3.待检查) + int borrowStatus; + + ///物品状态(1.正常,2.损坏,3.丢失) + int status; + int borrowTime; + String beginDate; + String endDate; + String borrowName; + String borrowTel; + String createDate; + List imgUrls; + ImgModel get firstImg => imgUrls.isEmpty ? null : imgUrls.first; + DateTime get create => DateUtil.getDateTime(createDate); + DateTime get begin => DateUtil.getDateTime(beginDate); + DateTime get end => DateUtil.getDateTime(endDate); + + ///借取状态(1.出借中,2.已还,3.待检查) + String get borrowStatusValue { + switch (borrowStatus) { + case 1: + return '出借中'; + case 2: + return '已还'; + case 3: + return '待检查'; + default: + return '未知'; + } + } + + ///物品状态(1.正常,2.损坏,3.丢失) + String get statusValue { + switch (status) { + case 1: + return '正常'; + case 2: + return '损坏'; + case 3: + return '丢失'; + default: + return '未知'; + } + } + + ///物品状态(1.正常,2.损坏,3.丢失) + Color get statusColor { + switch (status) { + case 1: + return AppStyle.primaryTextColor; + default: + return AppStyle.failColor; + } + } + + BorrowStatusItemModel( + {this.id, + this.articleDetailId, + this.articleName, + this.borrowStatus, + this.status, + this.borrowTime, + this.beginDate, + this.endDate, + this.borrowName, + this.borrowTel, + this.createDate, + this.imgUrls}); + + BorrowStatusItemModel.fromJson(Map json) { + id = json['id']; + articleDetailId = json['articleDetailId']; + articleName = json['articleName']; + borrowStatus = json['borrowStatus']; + status = json['status']; + borrowTime = json['borrowTime']; + beginDate = json['beginDate']; + endDate = json['endDate']; + borrowName = json['borrowName']; + borrowTel = json['borrowTel']; + createDate = json['createDate']; + if (json['imgUrls'] != null) { + imgUrls = new List(); + json['imgUrls'].forEach((v) { + imgUrls.add(new ImgModel.fromJson(v)); + }); + } else + imgUrls = []; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['articleDetailId'] = this.articleDetailId; + data['articleName'] = this.articleName; + data['borrowStatus'] = this.borrowStatus; + data['status'] = this.status; + data['borrowTime'] = this.borrowTime; + data['beginDate'] = this.beginDate; + data['endDate'] = this.endDate; + data['borrowName'] = this.borrowName; + data['borrowTel'] = this.borrowTel; + data['createDate'] = this.createDate; + if (this.imgUrls != null) { + data['imgUrls'] = this.imgUrls.map((v) => v.toJson()).toList(); + } + return data; + } +} diff --git a/lib/ui/sub_pages/borrow_manager/borrow_manager_card.dart b/lib/ui/sub_pages/borrow_manager/borrow_manager_card.dart index 5bdcf95..4e07b88 100644 --- a/lib/ui/sub_pages/borrow_manager/borrow_manager_card.dart +++ b/lib/ui/sub_pages/borrow_manager/borrow_manager_card.dart @@ -1,25 +1,23 @@ // Flutter imports: +import 'package:aku_community_manager/const/api.dart'; +import 'package:aku_community_manager/models/manager/borrow/borrow_status_item_model.dart'; import 'package:flutter/material.dart'; // Package imports: import 'package:aku_ui/common_widgets/aku_material_button.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:common_utils/common_utils.dart'; -import 'package:get/get.dart'; import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; -// Project imports: -import 'package:aku_community_manager/mock_models/borrow/borrow_model.dart'; import 'package:aku_community_manager/mock_models/users/user_info_model.dart'; import 'package:aku_community_manager/provider/user_provider.dart'; import 'package:aku_community_manager/style/app_style.dart'; import 'package:aku_community_manager/tools/widget_tool.dart'; -import 'package:aku_community_manager/ui/sub_pages/borrow_manager/borrow_manager_check_page.dart'; import 'package:aku_community_manager/ui/widgets/inner/aku_chip_box.dart'; class BorrowManagerCard extends StatefulWidget { - final BorrowModel model; + final BorrowStatusItemModel model; BorrowManagerCard({Key key, this.model}) : super(key: key); @override @@ -46,12 +44,12 @@ class _BorrowManagerCardState extends State { AkuChipBox(title: '借还管理'), AkuBox.w(24), Text( - DateUtil.formatDate(widget.model.date), + DateUtil.formatDate(widget.model.create), style: TextStyle(), ), Spacer(), Text( - widget.model.borrowGoods.borrowValue, + widget.model.borrowStatusValue, style: TextStyle( color: AppStyle.failColor, fontWeight: FontWeight.bold, @@ -62,7 +60,7 @@ class _BorrowManagerCardState extends State { ), AkuBox.h(24), Text( - widget.model.title, + widget.model.articleName, style: TextStyle( color: AppStyle.primaryTextColor, fontSize: 32.sp, @@ -73,40 +71,27 @@ class _BorrowManagerCardState extends State { Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - (widget.model.borrowGoods.assetpath is String) - ? Image.asset( - widget.model.borrowGoods.assetpath, - height: 184.w, - width: 183.w, - fit: BoxFit.cover, - ) - : Image.file( - widget.model.borrowGoods.assetpath, - height: 184.w, - width: 183.w, - fit: BoxFit.cover, - ), + FadeInImage.assetNetwork( + placeholder: R.ASSETS_PLACEHOLDER_WEBP, + image: API.image(widget.model.firstImg?.url ?? ''), + height: 184.w, + width: 184.w, + ), AkuBox.w(24), Expanded( child: Column( children: [ _buildRow(R.ASSETS_MESSAGE_IC_PEOPLE_PNG, '借用人员', - widget.model.borrowPerson), + widget.model.borrowName), _buildRow(R.ASSETS_MESSAGE_IC_PHONE_PNG, '联系电话', - widget.model.phone), + widget.model.borrowTel), _buildRow(R.ASSETS_MANAGE_IC_TIME_PNG, '借用时常', - '${widget.model.borrowTime}天'), + '${(widget.model.borrowTime / 24).toStringAsFixed(0)}天'), _buildRow( R.ASSETS_MANAGE_INFO_PNG, '物品状态', - widget.model.goodsStatus == GOODS_STATUS.BROKEN - ? '损坏' - : widget.model.goodsStatus == GOODS_STATUS.LOST - ? '丢失' - : '正常', - color: widget.model.goodsStatus == GOODS_STATUS.NORMAL - ? AppStyle.primaryTextColor - : AppStyle.failColor, + widget.model.statusValue, + color: widget.model.statusColor, ), ], ), @@ -120,9 +105,10 @@ class _BorrowManagerCardState extends State { } List _buildCard() { - if (role != USER_ROLE.MANAGER) + final userProvider = Provider.of(context); + if (!userProvider.infoModel.canOperation) return []; - else if (widget.model.borrowGoods.status == BORROW_STATUS.DONE) { + else if (widget.model.borrowStatus == 2) { return []; } else return [ @@ -142,7 +128,7 @@ class _BorrowManagerCardState extends State { ), ), onPressed: () { - launch('tel:${widget.model.phone}'); + launch('tel:${widget.model.borrowTel}'); }, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(4.w), @@ -150,7 +136,7 @@ class _BorrowManagerCardState extends State { ), ), AkuBox.w(24), - widget.model.borrowGoods.status == BORROW_STATUS.BORROWING + widget.model.borrowStatus == 1 ? AkuMaterialButton( minWidth: 160.w, height: 64.w, @@ -169,14 +155,15 @@ class _BorrowManagerCardState extends State { ), ) : SizedBox(), - widget.model.borrowGoods.status == BORROW_STATUS.WAIT_CHECK + widget.model.borrowStatus == 3 ? AkuMaterialButton( minWidth: 160.w, height: 64.w, color: AppStyle.primaryColor, radius: 4.w, onPressed: () { - Get.to(BorrowManagerCheckPage(model: widget.model)); + //TODO + // Get.to(BorrowManagerCheckPage(model: widget.model)); }, child: Text( '检查信息', diff --git a/lib/ui/sub_pages/borrow_manager/borrow_manager_page.dart b/lib/ui/sub_pages/borrow_manager/borrow_manager_page.dart index 56be063..1c0d9a9 100644 --- a/lib/ui/sub_pages/borrow_manager/borrow_manager_page.dart +++ b/lib/ui/sub_pages/borrow_manager/borrow_manager_page.dart @@ -1,4 +1,5 @@ // Flutter imports: +import 'package:aku_community_manager/ui/sub_pages/borrow_manager/borrow_manager_view.dart'; import 'package:flutter/material.dart'; // Package imports: @@ -30,12 +31,13 @@ class _BorrowManagerPageState extends State Provider.of(context, listen: false).userInfoModel.role; TabController _tabController; List get _tabs { - switch (role) { - case USER_ROLE.MANAGER: - return ['全部', '出借中', '待检查', '已归还']; - default: - return ['全部', '出借中', '已归还']; - } + final userProvider = Provider.of(context, listen: false); + return [ + '全部', + '出借中', + ...userProvider.infoModel.canOperation ? ['待检查'] : [], + '已归还' + ]; } @override @@ -77,32 +79,14 @@ class _BorrowManagerPageState extends State } List _getChildren() { - switch (role) { - case USER_ROLE.MANAGER: - return [ - getView(BorrowData.models), - getView(BorrowData.borrowModels), - getView(BorrowData.checkModels), - getView(BorrowData.doneModels), - ]; - break; - default: - return [ - getView(BorrowData.models), - getView(BorrowData.borrowModels), - getView(BorrowData.doneModels), - ]; - } + final userProvider = Provider.of(context); + return [ + BorrowManagerView(), + BorrowManagerView(status: 1), + ...userProvider.infoModel.canOperation + ? [BorrowManagerView(status: 3)] + : [], + BorrowManagerView(status: 2), + ]; } } - -Widget getView(List models) { - return ListView.builder( - itemBuilder: (context, index) { - return BorrowManagerCard( - model: models[index], - ); - }, - itemCount: models.length, - ); -} diff --git a/lib/ui/sub_pages/borrow_manager/borrow_manager_view.dart b/lib/ui/sub_pages/borrow_manager/borrow_manager_view.dart new file mode 100644 index 0000000..c420636 --- /dev/null +++ b/lib/ui/sub_pages/borrow_manager/borrow_manager_view.dart @@ -0,0 +1,42 @@ +import 'package:aku_community_manager/const/api.dart'; +import 'package:aku_community_manager/models/manager/borrow/borrow_status_item_model.dart'; +import 'package:aku_community_manager/ui/sub_pages/borrow_manager/borrow_manager_card.dart'; +import 'package:aku_community_manager/ui/widgets/common/bee_list_view.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; + +class BorrowManagerView extends StatefulWidget { + final int status; + BorrowManagerView({Key key, this.status}) : super(key: key); + + @override + _BorrowManagerViewState createState() => _BorrowManagerViewState(); +} + +class _BorrowManagerViewState extends State + with AutomaticKeepAliveClientMixin { + EasyRefreshController _refreshController = EasyRefreshController(); + @override + Widget build(BuildContext context) { + super.build(context); + return BeeListView( + path: API.manage.borrowStatusList, + extraParams: {'borrowStatus': widget.status}, + controller: _refreshController, + convert: (model) => model.tableList + .map((e) => BorrowStatusItemModel.fromJson(e)) + .toList(), + builder: (items) { + return ListView.builder( + itemBuilder: (context, index) { + return BorrowManagerCard(model: items[index]); + }, + itemCount: items.length, + ); + }, + ); + } + + @override + bool get wantKeepAlive => true; +}