重构借还管理 出借列表

hmxc
张萌 3 years ago
parent d7d6fdebae
commit 32258020e6

@ -1,10 +1,3 @@
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:velocity_x/velocity_x.dart';
import 'package:aku_community/base/base_style.dart'; import 'package:aku_community/base/base_style.dart';
import 'package:aku_community/const/resource.dart'; import 'package:aku_community/const/resource.dart';
import 'package:aku_community/constants/api.dart'; import 'package:aku_community/constants/api.dart';
@ -12,17 +5,25 @@ import 'package:aku_community/model/common/img_model.dart';
import 'package:aku_community/model/manager/article_borrow_model.dart'; import 'package:aku_community/model/manager/article_borrow_model.dart';
import 'package:aku_community/pages/goods_manage_page/borrow/borrow_finsh_page.dart'; import 'package:aku_community/pages/goods_manage_page/borrow/borrow_finsh_page.dart';
import 'package:aku_community/pages/goods_manage_page/borrow/borrow_goods_detail_page.dart'; import 'package:aku_community/pages/goods_manage_page/borrow/borrow_goods_detail_page.dart';
import 'package:aku_community/pages/things_page/widget/bee_list_view.dart'; import 'package:aku_community/utils/network/base_list_model.dart';
import 'package:aku_community/utils/network/base_model.dart'; import 'package:aku_community/utils/network/base_model.dart';
import 'package:aku_community/utils/network/net_util.dart'; import 'package:aku_community/utils/network/net_util.dart';
import 'package:aku_community/widget/bee_scaffold.dart'; import 'package:aku_community/widget/bee_scaffold.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:power_logger/power_logger.dart';
import 'package:velocity_x/velocity_x.dart';
class BorrowGoodsSubmitModel { class BorrowGoodsSubmitModel {
List<int> selectIds; List<int> selectIds;
static BorrowGoodsSubmitModel init() => BorrowGoodsSubmitModel([]);
BorrowGoodsSubmitModel( BorrowGoodsSubmitModel(
this.selectIds, this.selectIds,
); );
BorrowGoodsSubmitModel.init({List<int>? selectIds}) : this(selectIds = []);
} }
class BorrowGoodsPage extends StatefulWidget { class BorrowGoodsPage extends StatefulWidget {
@ -35,6 +36,10 @@ class BorrowGoodsPage extends StatefulWidget {
class _BorrowGoodsPageState extends State<BorrowGoodsPage> { class _BorrowGoodsPageState extends State<BorrowGoodsPage> {
EasyRefreshController? _easyRefreshController; EasyRefreshController? _easyRefreshController;
List<BorrowGoodsSubmitModel> _receiveIds = []; List<BorrowGoodsSubmitModel> _receiveIds = [];
List<ArticleBorrowModel> _borrowModels = [];
int _page = 1;
int _size = 10;
List<int> get _submitIds { List<int> get _submitIds {
List<int> _list = []; List<int> _list = [];
_receiveIds.forEach((element) { _receiveIds.forEach((element) {
@ -68,29 +73,51 @@ class _BorrowGoodsPageState extends State<BorrowGoodsPage> {
// padding: EdgeInsets.symmetric(horizontal: 32.w), // padding: EdgeInsets.symmetric(horizontal: 32.w),
// ), // ),
// ], // ],
body: BeeListView<ArticleBorrowModel>( body: EasyRefresh(
path: API.manager.articleBorrow, firstRefresh: true,
controller: _easyRefreshController, header: MaterialHeader(),
convert: (models) { footer: MaterialFooter(),
_receiveIds = List.generate(models.tableList?.length ?? 0, controller: _easyRefreshController,
(index) => BorrowGoodsSubmitModel.init()); onRefresh: () async {
print(_submitIds); _page = 1;
setState(() {}); BaseListModel _listModel = await NetUtil().getList(
return models.tableList! API.manager.articleBorrow,
.map((e) => ArticleBorrowModel.fromJson(e)) params: {'pageNum': _page, 'size': _size});
.toList(); _borrowModels = _listModel.tableList
}, ?.map((e) => ArticleBorrowModel.fromJson(e))
builder: (items) { .toList() ??
return ListView.separated( [];
_receiveIds =
_borrowModels.map((e) => BorrowGoodsSubmitModel.init()).toList();
setState(() {});
},
onLoad: () async {
_page++;
BaseListModel _listModel = await NetUtil().getList(
API.manager.articleBorrow,
params: {'pageNum': _page, 'size': _size});
_borrowModels.addAll(_listModel.tableList
?.map((e) => ArticleBorrowModel.fromJson(e))
.toList() ??
[]);
_receiveIds.addAll(_listModel.tableList
?.map((e) => BorrowGoodsSubmitModel.init())
.toList() ??
[]);
setState(() {});
},
child: _borrowModels.isEmpty
? Container()
: ListView.separated(
padding: EdgeInsets.symmetric(vertical: 16.w, horizontal: 32.w), padding: EdgeInsets.symmetric(vertical: 16.w, horizontal: 32.w),
itemBuilder: (context, index) { itemBuilder: (context, index) {
return _goodsCard(items[index], index); return _goodsCard(_borrowModels[index], index);
}, },
separatorBuilder: (_, __) { separatorBuilder: (_, __) {
return 16.w.heightBox; return 16.w.heightBox;
}, },
itemCount: items.length); itemCount: _borrowModels.length),
}), ),
bottomNavi: Row( bottomNavi: Row(
children: [ children: [
'已选择 '.richText.color(ktextPrimary).size(24.sp).withTextSpanChildren([ '已选择 '.richText.color(ktextPrimary).size(24.sp).withTextSpanChildren([
@ -133,6 +160,7 @@ class _BorrowGoodsPageState extends State<BorrowGoodsPage> {
} }
Widget _goodsCard(ArticleBorrowModel model, int index) { Widget _goodsCard(ArticleBorrowModel model, int index) {
var selectCount = _receiveIds[index].selectIds.length;
return Row( return Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@ -177,7 +205,7 @@ class _BorrowGoodsPageState extends State<BorrowGoodsPage> {
), ),
], ],
), ),
_receiveIds[index].selectIds.length == 0 selectCount == 0
? SizedBox() ? SizedBox()
: Column( : Column(
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
@ -214,6 +242,7 @@ class _BorrowGoodsPageState extends State<BorrowGoodsPage> {
receiveIds: _receiveIds[index].selectIds, receiveIds: _receiveIds[index].selectIds,
)); ));
setState(() {}); setState(() {});
LoggerData.addData(_receiveIds.last.selectIds.length);
}); });
} }
} }

Loading…
Cancel
Save