解决物品归还 两页面交互时数值不正确的问题

hmxc
张萌 4 years ago
parent 14d427a068
commit 88f2271215

@ -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<int?>? receiveIds;
BorrowGoodsDetailPage({Key? key, this.articleId, this.receiveIds})
final int articleId;
final List<int>? receiveIds;
BorrowGoodsDetailPage(
{Key? key, required this.articleId, this.receiveIds})
: super(key: key);
@override
@ -30,14 +31,14 @@ class _BorrowGoodsDetailPageState extends State<BorrowGoodsDetailPage> {
EasyRefreshController? _easyRefreshController;
List<ArticleBorrowDetailModel> _models = [];
bool _onload = true;
List<int?>? _selectItems = [];
bool get allSelect => _selectItems!.length == _models.length;
List<int> _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<BorrowGoodsDetailPage> {
body: EasyRefresh(
firstRefresh: true,
header: MaterialHeader(),
controller: _easyRefreshController,
onRefresh: () async {
List<dynamic> models = await (getModels());
_models =
@ -64,7 +66,8 @@ class _BorrowGoodsDetailPageState extends State<BorrowGoodsDetailPage> {
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<BorrowGoodsDetailPage> {
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<BorrowGoodsDetailPage> {
'全选'.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<BorrowGoodsDetailPage> {
}
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<BorrowGoodsDetailPage> {
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(),
);
}
}

@ -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<int> selectIds;
BorrowGoodsSubmitModel(
this.selectIds,
);
BorrowGoodsSubmitModel.init({List<int>? 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<BorrowGoodsPage> {
EasyRefreshController? _easyRefreshController;
List<int>? _receiveIds = [];
List<int> _submitIds = [];
List<int> _counts = [];
List<BorrowGoodsSubmitModel> _receiveIds = [];
List<int> get _submitIds {
List<int> _list = [];
_receiveIds.forEach((element) {
_list.addAll(element.selectIds);
});
return _list;
}
@override
void initState() {
super.initState();
@ -45,27 +58,30 @@ class _BorrowGoodsPageState extends State<BorrowGoodsPage> {
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<ArticleBorrowModel>(
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<BorrowGoodsPage> {
),
],
),
_counts[index] == 0
_receiveIds[index].selectIds.length == 0
? SizedBox()
: Column(
crossAxisAlignment: CrossAxisAlignment.end,
@ -175,7 +191,7 @@ class _BorrowGoodsPageState extends State<BorrowGoodsPage> {
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<BorrowGoodsPage> {
.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(() {});
});
}

Loading…
Cancel
Save