From d9de27a01fc2285b227886ce0d84ae36c718fb71 Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Fri, 16 Apr 2021 13:28:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=89=A9=E5=93=81=E5=BD=92?= =?UTF-8?q?=E8=BF=98=E9=A1=B5=E9=9D=A2=20=E5=AF=B9=E6=8E=A5=EF=BC=9A?= =?UTF-8?q?=E5=80=9F=E8=BF=98=E7=AE=A1=E7=90=86=EF=BC=9A=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=BB=E9=94=AEid=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E5=BD=92=E8=BF=98=E7=89=A9=E5=93=81=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=88=E5=BD=92=E8=BF=98=E7=95=8C=E9=9D=A2=EF=BC=89?= =?UTF-8?q?=20=E5=AF=B9=E6=8E=A5=EF=BC=9A=E5=80=9F=E8=BF=98=E7=AE=A1?= =?UTF-8?q?=E7=90=86=EF=BC=9A=E5=BD=92=E8=BF=98=E7=89=A9=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/constants/api.dart | 3 + .../manager/article_return_list_model.dart | 80 ++++++ .../goods_manage_page/goods_manage_page.dart | 5 +- .../retrun/return_goods_detail_page.dart | 255 ++++++++++++++++++ 4 files changed, 342 insertions(+), 1 deletion(-) create mode 100644 lib/model/manager/article_return_list_model.dart create mode 100644 lib/pages/goods_manage_page/retrun/return_goods_detail_page.dart diff --git a/lib/constants/api.dart b/lib/constants/api.dart index e6b26687..127be2ec 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -166,6 +166,9 @@ class _Manager { ///借还管理:借取物品 String get articleBorrowGoods => '/user/articleBorrow/borrow'; + ///借还管理:归还物品 + String get articleReturnGoods => '/user/articleBorrow/articleReturn'; + ///借还管理:根据用户主键id查询需要归还物品信息(归还界面) String get articleReturnList => '/articleBorrow/findBorrowByUserId'; diff --git a/lib/model/manager/article_return_list_model.dart b/lib/model/manager/article_return_list_model.dart new file mode 100644 index 00000000..09bd393b --- /dev/null +++ b/lib/model/manager/article_return_list_model.dart @@ -0,0 +1,80 @@ +import 'package:akuCommunity/model/common/img_model.dart'; + +class ArticleReturnListModel { + int id; + String name; + String code; + String beginDate; + int borrowTime; + List imgList; + String get paraseBorrowTime { + if (this.borrowTime > 24) { + return '${this.borrowTime ~/ 24}天${this.borrowTime % 24}小时'; + } else { + return '${this.borrowTime}小时'; + } + } + + ArticleReturnListModel( + {this.id, + this.name, + this.code, + this.beginDate, + this.borrowTime, + this.imgList}); + + ArticleReturnListModel.fromJson(Map json) { + id = json['id']; + name = json['name']; + code = json['code']; + beginDate = json['beginDate']; + borrowTime = json['borrowTime']; + if (json['imgList'] != null) { + imgList = new List(); + json['imgList'].forEach((v) { + imgList.add(new ImgModel.fromJson(v)); + }); + } + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['name'] = this.name; + data['code'] = this.code; + data['beginDate'] = this.beginDate; + data['borrowTime'] = this.borrowTime; + if (this.imgList != null) { + data['imgList'] = this.imgList.map((v) => v.toJson()).toList(); + } + return data; + } +} + +class ImgList { + String url; + String size; + int longs; + int paragraph; + int sort; + + ImgList({this.url, this.size, this.longs, this.paragraph, this.sort}); + + ImgList.fromJson(Map json) { + url = json['url']; + size = json['size']; + longs = json['longs']; + paragraph = json['paragraph']; + sort = json['sort']; + } + + Map toJson() { + final Map data = new Map(); + data['url'] = this.url; + data['size'] = this.size; + data['longs'] = this.longs; + data['paragraph'] = this.paragraph; + data['sort'] = this.sort; + return data; + } +} diff --git a/lib/pages/goods_manage_page/goods_manage_page.dart b/lib/pages/goods_manage_page/goods_manage_page.dart index 61cdf558..ae7f4d24 100644 --- a/lib/pages/goods_manage_page/goods_manage_page.dart +++ b/lib/pages/goods_manage_page/goods_manage_page.dart @@ -1,4 +1,5 @@ import 'package:akuCommunity/pages/goods_manage_page/borrow/borrow_goods_page.dart'; +import 'package:akuCommunity/pages/goods_manage_page/retrun/return_goods_detail_page.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -122,7 +123,9 @@ class _GoodsManagePageState extends State { ? () { Get.to(() => BorrowGoodsPage()); } - : () {}, + : () { + Get.to(() => ReturnGoodsDetailPage()); + }, ), ); } diff --git a/lib/pages/goods_manage_page/retrun/return_goods_detail_page.dart b/lib/pages/goods_manage_page/retrun/return_goods_detail_page.dart new file mode 100644 index 00000000..a1fc0ef7 --- /dev/null +++ b/lib/pages/goods_manage_page/retrun/return_goods_detail_page.dart @@ -0,0 +1,255 @@ +import 'package:akuCommunity/base/base_style.dart'; +import 'package:akuCommunity/constants/api.dart'; +import 'package:akuCommunity/model/common/img_model.dart'; +import 'package:akuCommunity/model/manager/article_return_list_model.dart'; +import 'package:akuCommunity/utils/network/base_model.dart'; +import 'package:akuCommunity/utils/network/net_util.dart'; +import 'package:akuCommunity/widget/animated/animated_scale.dart'; +import 'package:akuCommunity/widget/bee_scaffold.dart'; +import 'package:akuCommunity/widget/buttons/radio_button.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; +import 'package:get/get.dart'; +import 'package:velocity_x/velocity_x.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:akuCommunity/const/resource.dart'; + +class ReturnGoodsDetailPage extends StatefulWidget { + ReturnGoodsDetailPage({Key key}) : super(key: key); + + @override + _ReturnGoodsDetailPageState createState() => _ReturnGoodsDetailPageState(); +} + +class _ReturnGoodsDetailPageState extends State { + EasyRefreshController _easyRefreshController; + List _models; + bool _onload = true; + List _selectItems = []; + bool get allSelect => _selectItems.length == _models.length; + @override + void initState() { + super.initState(); + _easyRefreshController = EasyRefreshController(); + } + + @override + void dispose() { + _easyRefreshController?.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return BeeScaffold( + title: '选择物品', + body: EasyRefresh( + firstRefresh: true, + header: MaterialHeader(), + onRefresh: () async { + List models = await getModels(); + _models = + models.map((e) => ArticleReturnListModel.fromJson(e)).toList(); + _onload = false; + setState(() {}); + }, + child: _onload + ? _empty() + : ListView( + children: [..._models.map((e) => _goodsCard(e)).toList()], + ), + ), + bottomNavi: _onload ? _empty() : _bottomButton(), + ); + } + + Widget _allSelectButton() { + return GestureDetector( + onTap: () { + if (allSelect) { + _selectItems.clear(); + } else { + _selectItems.clear(); + _models.forEach((element) { + _selectItems.add(element.id); + }); + } + setState(() {}); + }, + child: AnimatedContainer( + height: 40.w, + width: 40.w, + decoration: BoxDecoration( + border: Border.all( + color: allSelect ? kPrimaryColor : Color(0xFF979797), + width: 3.w, + ), + borderRadius: BorderRadius.circular(20.w), + ), + duration: Duration(milliseconds: 300), + curve: Curves.easeInOutCubic, + alignment: Alignment.center, + child: AnimatedOpacity( + duration: Duration(milliseconds: 300), + curve: Curves.easeInOutCubic, + opacity: allSelect ? 1 : 0, + child: AnimatedScale( + scale: allSelect ? 1 : 0, + child: Container( + height: 24.w, + width: 24.w, + decoration: BoxDecoration( + color: kPrimaryColor, + borderRadius: BorderRadius.circular(12.w), + ), + ), + ), + ), + ), + ); + } + + Widget _bottomButton() { + return Row( + children: [ + _allSelectButton(), + 16.w.widthBox, + '全选'.text.color(ktextSubColor).size(24.sp).make(), + Spacer(), + '已选择 '.richText.color(ktextPrimary).size(24.sp).withTextSpanChildren([ + '${_selectItems.length}' + .textSpan + .size(32.sp) + .color(ktextPrimary) + .make(), + ' 项'.textSpan.size(24.sp).color(ktextPrimary).make(), + ]).make(), + 32.w.widthBox, + MaterialButton( + elevation: 0, + shape: + RoundedRectangleBorder(borderRadius: BorderRadius.circular(37.w)), + color: kPrimaryColor, + padding: EdgeInsets.symmetric(horizontal: 50.w, vertical: 15.w), + onPressed: () async { + BaseModel baseModel = + await NetUtil().post(API.manager.articleReturnGoods, + params: { + 'ids': _selectItems, + }, + showMessage: true); + if (baseModel.status) { + Get.back(); + } + }, + child: '归还'.text.black.size(32.sp).bold.make(), + ), + ], + ) + .pSymmetric(v: 22.w, h: 32.w) + .box + .color(Colors.white) + .width(double.infinity) + .padding(EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom)) + .make(); + } + + Widget _empty() { + return Container(); + } + + Future getModels() async { + BaseModel baseModel = await NetUtil().get(API.manager.articleReturnList); + return baseModel.data as List; + } + + Widget _goodsCard(ArticleReturnListModel model) { + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + GestureDetector( + onTap: () { + if (_selectItems.contains(model.id)) { + _selectItems.remove(model.id); + } else { + _selectItems.add(model.id); + } + setState(() {}); + }, + child: Container( + height: 232.w - 48.w, + alignment: Alignment.center, + child: BeeRadio( + value: model.id, + groupValues: _selectItems, + ), + ), + ).material(color: Colors.transparent), + 24.w.widthBox, + SizedBox( + width: 184.w, + height: 184.w, + child: ClipRRect( + child: FadeInImage.assetNetwork( + placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, + image: API.image(ImgModel.first(model.imgList)), + ), + ), + ), + 24.w.widthBox, + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Image.asset( + R.ASSETS_ICONS_ARTICLE_NAME_PNG, + width: 40.w, + height: 40.w, + ), + 4.w.widthBox, + '物品名称:'.text.color(ktextSubColor).size(28.sp).make(), + '${model.name}'.text.color(ktextPrimary).size(28.sp).make(), + ], + ), + 12.w.heightBox, + Row( + children: [ + Image.asset( + R.ASSETS_ICONS_ARTICLE_COUNT_PNG, + width: 40.w, + height: 40.w, + ), + 4.w.widthBox, + '物品单号:'.text.color(ktextSubColor).size(28.sp).make(), + '${model.code}'.text.color(ktextPrimary).size(28.sp).make(), + ], + ), + 12.w.heightBox, + Row( + children: [ + Image.asset( + R.ASSETS_ICONS_BORROW_STATUS_PNG, + width: 40.w, + height: 40.w, + ), + 4.w.widthBox, + '出借时间'.text.color(ktextSubColor).size(28.sp).make(), + '${model.paraseBorrowTime}' + .text + .color(ktextPrimary) + .size(28.sp) + .make(), + ], + ), + ], + ) + ], + ) + .box + .color(Colors.white) + .padding(EdgeInsets.symmetric(vertical: 24.w, horizontal: 24.w)) + .withRounded(value: 6.w) + .make(); + } +}