From d32bba352158c60111ad3fbe8a5753e65702e5b1 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Mon, 22 Feb 2021 19:15:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=80=9F=E8=BF=98=E7=AE=A1=E7=90=86=E7=89=A9?= =?UTF-8?q?=E5=93=81=E8=AF=A6=E6=83=85=E9=A1=B5=E9=9D=A2=E7=BB=86=E8=8A=82?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/const/api.dart | 3 + .../borrow/borrow_detail_item_model.dart | 2 +- .../borrow/borrow_item_detail_model.dart | 60 +++++++ .../borrow_item_detail_page.dart | 161 ++++++++++-------- .../borrow_manager/borrow_items_page.dart | 8 +- 5 files changed, 155 insertions(+), 79 deletions(-) create mode 100644 lib/models/manager/borrow/borrow_item_detail_model.dart diff --git a/lib/const/api.dart b/lib/const/api.dart index 7c787fc..d94c624 100644 --- a/lib/const/api.dart +++ b/lib/const/api.dart @@ -65,4 +65,7 @@ class _Manage { ///借还管理:根据物品主键id查询所有的物品明细信息 String get borrowDetailList => '/user/borrow/articleDetailList'; + + ///借还管理:根据物品明细id 查询物品信息 + String get borrowItemDetail => '/user/borrow/findById'; } diff --git a/lib/models/manager/borrow/borrow_detail_item_model.dart b/lib/models/manager/borrow/borrow_detail_item_model.dart index 892b40e..9ebee2e 100644 --- a/lib/models/manager/borrow/borrow_detail_item_model.dart +++ b/lib/models/manager/borrow/borrow_detail_item_model.dart @@ -7,7 +7,7 @@ class BorrowDetailItemModel { int borrowStatus; List imgUrls; ImgModel get firstImg => imgUrls.isEmpty ? null : imgUrls.first; - + bool get borrowed => borrowStatus == 2; BorrowDetailItemModel( {this.id, this.name, this.code, this.borrowStatus, this.imgUrls}); diff --git a/lib/models/manager/borrow/borrow_item_detail_model.dart b/lib/models/manager/borrow/borrow_item_detail_model.dart new file mode 100644 index 0000000..0c5db33 --- /dev/null +++ b/lib/models/manager/borrow/borrow_item_detail_model.dart @@ -0,0 +1,60 @@ +import 'package:aku_community_manager/models/common/img_model.dart'; + +class BorrowItemDetailModel { + int id; + String name; + String code; + int borrowStatus; + int status; + List imgUrls; + ImgModel get firstImg => imgUrls.isEmpty ? null : imgUrls.first; + bool get borrowed => borrowStatus == 2; + String get statusValue { + switch (status) { + case 1: + return '正常'; + case 2: + return '破损'; + case 3: + return '丢失'; + default: + return '未知'; + } + } + + BorrowItemDetailModel( + {this.id, + this.name, + this.code, + this.borrowStatus, + this.status, + this.imgUrls}); + + BorrowItemDetailModel.fromJson(Map json) { + id = json['id']; + name = json['name']; + code = json['code']; + borrowStatus = json['borrowStatus']; + status = json['status']; + 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['name'] = this.name; + data['code'] = this.code; + data['borrowStatus'] = this.borrowStatus; + data['status'] = this.status; + 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_item_detail_page.dart b/lib/ui/sub_pages/borrow_manager/borrow_item_detail_page.dart index 12f40fd..53b796b 100644 --- a/lib/ui/sub_pages/borrow_manager/borrow_item_detail_page.dart +++ b/lib/ui/sub_pages/borrow_manager/borrow_item_detail_page.dart @@ -1,8 +1,13 @@ // Flutter imports: +import 'package:aku_community_manager/const/api.dart'; +import 'package:aku_community_manager/models/manager/borrow/borrow_item_detail_model.dart'; +import 'package:aku_community_manager/utils/network/base_model.dart'; +import 'package:aku_community_manager/utils/network/net_util.dart'; import 'package:flutter/material.dart'; // Package imports: import 'package:aku_ui/common_widgets/aku_material_button.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:provider/provider.dart'; // Project imports: @@ -14,8 +19,8 @@ import 'package:aku_community_manager/tools/widget_tool.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; class BorrowItemDetailPage extends StatefulWidget { - final SingleBorrowGoods item; - BorrowItemDetailPage({Key key, this.item}) : super(key: key); + final int id; + BorrowItemDetailPage({Key key, this.id}) : super(key: key); @override _BorrowItemDetailPageState createState() => _BorrowItemDetailPageState(); @@ -24,10 +29,11 @@ class BorrowItemDetailPage extends StatefulWidget { class _BorrowItemDetailPageState extends State { bool _isEditing = false; TextEditingController _textEditingController; + BorrowItemDetailModel _detailModel; @override void initState() { super.initState(); - _textEditingController = TextEditingController(text: widget.item.name); + _textEditingController = TextEditingController(text: ''); } @override @@ -60,77 +66,86 @@ class _BorrowItemDetailPageState extends State { ) : SizedBox(), ], - body: ListView( - padding: EdgeInsets.symmetric(vertical: 16.w), - children: [ - Container( - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 32.w), - child: Column( - children: [ - _buildRow( - '物品名称', - TextField( - style: TextStyle( - color: AppStyle.primaryTextColor, - fontSize: 28.sp, - fontWeight: FontWeight.bold, - ), - controller: _textEditingController, - enabled: _isEditing, - onChanged: (text) { - widget.item.name = text; - }, - decoration: InputDecoration( - border: InputBorder.none, - ), - )), - Divider(height: 1.w), - _buildRow( - '物品单号', - Text( - widget.item.code, - style: TextStyle( - color: _isEditing - ? AppStyle.minorTextColor - : AppStyle.primaryTextColor, - fontSize: 28.sp, - fontWeight: FontWeight.bold, - ), - )), - _buildRow( - '出借状态', - Text( - '未出借', - style: TextStyle( - color: _isEditing - ? AppStyle.minorTextColor - : AppStyle.primaryTextColor, - fontSize: 28.sp, - fontWeight: FontWeight.bold, - ), - )), - _buildRow( - '物品图片', - (widget.item.assetpath is String) - ? Image.asset( - widget.item.assetpath, - height: 184.w, - width: 184.w, - fit: BoxFit.cover, - ) - : Image.file( - widget.item.assetpath, - height: 184.w, - width: 184.w, - fit: BoxFit.cover, + body: EasyRefresh( + firstRefresh: true, + header: MaterialHeader(), + onRefresh: () async { + BaseModel model = await NetUtil().get( + API.manage.borrowItemDetail, + params: {'articleDetailId': widget.id}, + ); + _detailModel = BorrowItemDetailModel.fromJson(model.data); + _textEditingController.text = _detailModel.name; + setState(() {}); + }, + child: _detailModel == null + ? SizedBox() + : ListView( + padding: EdgeInsets.symmetric(vertical: 16.w), + children: [ + Container( + color: Colors.white, + padding: EdgeInsets.symmetric(horizontal: 32.w), + child: Column( + children: [ + _buildRow( + '物品名称', + TextField( + style: TextStyle( + color: AppStyle.primaryTextColor, + fontSize: 28.sp, + fontWeight: FontWeight.bold, + ), + controller: _textEditingController, + enabled: _isEditing, + onChanged: (text) { + //TODO edit + // widget.item.name = text; + }, + decoration: InputDecoration( + border: InputBorder.none, + ), + )), + Divider(height: 1.w), + _buildRow( + '物品单号', + Text( + _detailModel.code, + style: TextStyle( + color: _isEditing + ? AppStyle.minorTextColor + : AppStyle.primaryTextColor, + fontSize: 28.sp, + fontWeight: FontWeight.bold, + ), + )), + _buildRow( + '出借状态', + Text( + '未出借', + style: TextStyle( + color: _isEditing + ? AppStyle.minorTextColor + : AppStyle.primaryTextColor, + fontSize: 28.sp, + fontWeight: FontWeight.bold, + ), + )), + _buildRow( + '物品图片', + FadeInImage.assetNetwork( + placeholder: R.ASSETS_PLACEHOLDER_WEBP, + image: API.image(_detailModel.firstImg?.url ?? ''), + height: 184.w, + width: 184.w, + ), ), - ), - AkuBox.h(28), - ], - ), - ), - ], + AkuBox.h(28), + ], + ), + ), + ], + ), ), ); } diff --git a/lib/ui/sub_pages/borrow_manager/borrow_items_page.dart b/lib/ui/sub_pages/borrow_manager/borrow_items_page.dart index ea0cc8b..efb31e9 100644 --- a/lib/ui/sub_pages/borrow_manager/borrow_items_page.dart +++ b/lib/ui/sub_pages/borrow_manager/borrow_items_page.dart @@ -1,6 +1,7 @@ // Flutter imports: import 'package:aku_community_manager/const/api.dart'; import 'package:aku_community_manager/models/manager/borrow/borrow_detail_item_model.dart'; +import 'package:aku_community_manager/ui/sub_pages/borrow_manager/borrow_item_detail_page.dart'; import 'package:aku_community_manager/ui/widgets/common/bee_list_view.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -12,13 +13,10 @@ import 'package:get/get.dart'; import 'package:provider/provider.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/add_borrow_item_page.dart'; -import 'package:aku_community_manager/ui/sub_pages/borrow_manager/borrow_item_detail_page.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; class BorrowItemPage extends StatefulWidget { @@ -77,7 +75,7 @@ class _BorrowItemPageState extends State { final userProvider = Provider.of(context); return GestureDetector( onTap: () { - // Get.to(BorrowItemDetailPage(item: item)); + Get.to(BorrowItemDetailPage(id: item.id)); }, child: Container( margin: EdgeInsets.only(top: 16.w), @@ -172,7 +170,7 @@ class _BorrowItemPageState extends State { _buildRow( R.ASSETS_MANAGE_BORROW_PNG, '出借状态', - '未借出', + item.borrowed ? '已出借' : '未借出', color: AppStyle.secondaryColor, ), ],