From 88f227121546ff4dfa9757f53fb60a4cf93e0b7c Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Mon, 17 May 2021 15:25:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=89=A9=E5=93=81=E5=BD=92?= =?UTF-8?q?=E8=BF=98=20=E4=B8=A4=E9=A1=B5=E9=9D=A2=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=97=B6=E6=95=B0=E5=80=BC=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../borrow/borrow_goods_detail_page.dart | 181 +++++++++--------- .../borrow/borrow_goods_page.dart | 68 ++++--- 2 files changed, 130 insertions(+), 119 deletions(-) diff --git a/lib/pages/goods_manage_page/borrow/borrow_goods_detail_page.dart b/lib/pages/goods_manage_page/borrow/borrow_goods_detail_page.dart index 8ad0245e..96b4415a 100644 --- a/lib/pages/goods_manage_page/borrow/borrow_goods_detail_page.dart +++ b/lib/pages/goods_manage_page/borrow/borrow_goods_detail_page.dart @@ -17,9 +17,10 @@ import 'package:aku_community/widget/bee_scaffold.dart'; import 'package:aku_community/widget/buttons/radio_button.dart'; class BorrowGoodsDetailPage extends StatefulWidget { - final int? articleId; - final List? receiveIds; - BorrowGoodsDetailPage({Key? key, this.articleId, this.receiveIds}) + final int articleId; + final List? receiveIds; + BorrowGoodsDetailPage( + {Key? key, required this.articleId, this.receiveIds}) : super(key: key); @override @@ -30,14 +31,14 @@ class _BorrowGoodsDetailPageState extends State { EasyRefreshController? _easyRefreshController; List _models = []; bool _onload = true; - List? _selectItems = []; - bool get allSelect => _selectItems!.length == _models.length; + List _selectItems = []; + bool get allSelect => _selectItems.length == _models.length; @override void initState() { super.initState(); _easyRefreshController = EasyRefreshController(); if (widget.receiveIds != null && widget.receiveIds!.isNotEmpty) { - _selectItems = widget.receiveIds; + _selectItems = widget.receiveIds!; } } @@ -54,6 +55,7 @@ class _BorrowGoodsDetailPageState extends State { body: EasyRefresh( firstRefresh: true, header: MaterialHeader(), + controller: _easyRefreshController, onRefresh: () async { List models = await (getModels()); _models = @@ -64,7 +66,8 @@ class _BorrowGoodsDetailPageState extends State { child: _onload ? _empty() : ListView( - children: [..._models.map((e) => _goodsCard(e)).toList()], + padding: EdgeInsets.symmetric(vertical: 12.w), + children: [..._models.map((e) => _goodsCard(e)).toList()] ), ), bottomNavi: _onload ? _empty() : _bottomButton(), @@ -75,11 +78,11 @@ class _BorrowGoodsDetailPageState extends State { return GestureDetector( onTap: () { if (allSelect) { - _selectItems!.clear(); + _selectItems.clear(); } else { - _selectItems!.clear(); + _selectItems.clear(); _models.forEach((element) { - _selectItems!.add(element.id); + _selectItems.add(element.id!); }); } setState(() {}); @@ -125,7 +128,7 @@ class _BorrowGoodsDetailPageState extends State { '全选'.text.color(ktextSubColor).size(24.sp).make(), Spacer(), '已选择 '.richText.color(ktextPrimary).size(24.sp).withTextSpanChildren([ - '${_selectItems!.length}' + '${_selectItems.length}' .textSpan .size(32.sp) .color(ktextPrimary) @@ -167,19 +170,19 @@ class _BorrowGoodsDetailPageState extends State { } Widget _goodsCard(ArticleBorrowDetailModel 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( + return GestureDetector( + onTap: () { + if (_selectItems.contains(model.id)) { + _selectItems.remove(model.id); + } else { + _selectItems.add(model.id!); + } + setState(() {}); + }, + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( height: 232.w - 48.w, alignment: Alignment.center, child: BeeRadio( @@ -187,72 +190,72 @@ class _BorrowGoodsDetailPageState extends State { 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, + 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.borrowStatus}' - .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(); + 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.borrowStatus}' + .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(), + ); } } diff --git a/lib/pages/goods_manage_page/borrow/borrow_goods_page.dart b/lib/pages/goods_manage_page/borrow/borrow_goods_page.dart index 965db29c..9064db42 100644 --- a/lib/pages/goods_manage_page/borrow/borrow_goods_page.dart +++ b/lib/pages/goods_manage_page/borrow/borrow_goods_page.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; - import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; @@ -17,6 +16,14 @@ import 'package:aku_community/utils/network/base_model.dart'; import 'package:aku_community/utils/network/net_util.dart'; import 'package:aku_community/widget/bee_scaffold.dart'; +class BorrowGoodsSubmitModel { + List selectIds; + BorrowGoodsSubmitModel( + this.selectIds, + ); + BorrowGoodsSubmitModel.init({List? selectIds}) : this(selectIds = []); +} + class BorrowGoodsPage extends StatefulWidget { BorrowGoodsPage({Key? key}) : super(key: key); @@ -26,9 +33,15 @@ class BorrowGoodsPage extends StatefulWidget { class _BorrowGoodsPageState extends State { EasyRefreshController? _easyRefreshController; - List? _receiveIds = []; - List _submitIds = []; - List _counts = []; + List _receiveIds = []; + List get _submitIds { + List _list = []; + _receiveIds.forEach((element) { + _list.addAll(element.selectIds); + }); + return _list; + } + @override void initState() { super.initState(); @@ -45,27 +58,30 @@ class _BorrowGoodsPageState extends State { Widget build(BuildContext context) { return BeeScaffold( title: '全部物品', - actions: [ - MaterialButton( - onPressed: () { - // Get.to(() => MineGoodsPage()); - }, - child: '我的借还物品'.text.black.size(28.sp).make(), - padding: EdgeInsets.symmetric(horizontal: 32.w), - ), - ], + // actions: [ + // MaterialButton( + // onPressed: () { + // // Get.to(() => MineGoodsPage()); + // }, + // child: '我的借还物品'.text.black.size(28.sp).make(), + // padding: EdgeInsets.symmetric(horizontal: 32.w), + // ), + // ], body: BeeListView( path: API.manager.articleBorrow, controller: _easyRefreshController, convert: (models) { + _receiveIds = List.generate(models.tableList?.length ?? 0, + (index) => BorrowGoodsSubmitModel.init()); + print(_submitIds); + setState(() { + + }); return models.tableList! .map((e) => ArticleBorrowModel.fromJson(e)) .toList(); }, builder: (items) { - if (_counts.isEmpty) { - _counts = List.filled(items.length, 0); - } return ListView.separated( padding: EdgeInsets.symmetric(vertical: 16.w, horizontal: 32.w), itemBuilder: (context, index) { @@ -162,7 +178,7 @@ class _BorrowGoodsPageState extends State { ), ], ), - _counts[index] == 0 + _receiveIds[index].selectIds.length == 0 ? SizedBox() : Column( crossAxisAlignment: CrossAxisAlignment.end, @@ -175,7 +191,7 @@ class _BorrowGoodsPageState extends State { borderRadius: BorderRadius.circular(20.w), color: kPrimaryColor, ), - child: '${_counts[index]}' + child: '${_receiveIds[index].selectIds.length}' .text .color(ktextPrimary) .size(24.sp) @@ -194,18 +210,10 @@ class _BorrowGoodsPageState extends State { .withRounded(value: 6.w) .make() .onInkTap(() async { - _receiveIds?.forEach((element) { - _submitIds.remove(element); - }); - await Get.to(() => BorrowGoodsDetailPage( - articleId: model.id, - receiveIds: _receiveIds, - ))! - .then((value) { - _receiveIds = value; - }); - _counts[index] = _receiveIds?.length ?? 0; - _submitIds.addAll(_receiveIds ?? []); + _receiveIds[index].selectIds = await Get.to(() => BorrowGoodsDetailPage( + articleId: model.id!, + receiveIds: _receiveIds[index].selectIds, + )); setState(() {}); }); }