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

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'; import 'package:aku_community/widget/buttons/radio_button.dart';
class BorrowGoodsDetailPage extends StatefulWidget { class BorrowGoodsDetailPage extends StatefulWidget {
final int? articleId; final int articleId;
final List<int?>? receiveIds; final List<int>? receiveIds;
BorrowGoodsDetailPage({Key? key, this.articleId, this.receiveIds}) BorrowGoodsDetailPage(
{Key? key, required this.articleId, this.receiveIds})
: super(key: key); : super(key: key);
@override @override
@ -30,14 +31,14 @@ class _BorrowGoodsDetailPageState extends State<BorrowGoodsDetailPage> {
EasyRefreshController? _easyRefreshController; EasyRefreshController? _easyRefreshController;
List<ArticleBorrowDetailModel> _models = []; List<ArticleBorrowDetailModel> _models = [];
bool _onload = true; bool _onload = true;
List<int?>? _selectItems = []; List<int> _selectItems = [];
bool get allSelect => _selectItems!.length == _models.length; bool get allSelect => _selectItems.length == _models.length;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_easyRefreshController = EasyRefreshController(); _easyRefreshController = EasyRefreshController();
if (widget.receiveIds != null && widget.receiveIds!.isNotEmpty) { if (widget.receiveIds != null && widget.receiveIds!.isNotEmpty) {
_selectItems = widget.receiveIds; _selectItems = widget.receiveIds!;
} }
} }
@ -54,6 +55,7 @@ class _BorrowGoodsDetailPageState extends State<BorrowGoodsDetailPage> {
body: EasyRefresh( body: EasyRefresh(
firstRefresh: true, firstRefresh: true,
header: MaterialHeader(), header: MaterialHeader(),
controller: _easyRefreshController,
onRefresh: () async { onRefresh: () async {
List<dynamic> models = await (getModels()); List<dynamic> models = await (getModels());
_models = _models =
@ -64,7 +66,8 @@ class _BorrowGoodsDetailPageState extends State<BorrowGoodsDetailPage> {
child: _onload child: _onload
? _empty() ? _empty()
: ListView( : 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(), bottomNavi: _onload ? _empty() : _bottomButton(),
@ -75,11 +78,11 @@ class _BorrowGoodsDetailPageState extends State<BorrowGoodsDetailPage> {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
if (allSelect) { if (allSelect) {
_selectItems!.clear(); _selectItems.clear();
} else { } else {
_selectItems!.clear(); _selectItems.clear();
_models.forEach((element) { _models.forEach((element) {
_selectItems!.add(element.id); _selectItems.add(element.id!);
}); });
} }
setState(() {}); setState(() {});
@ -125,7 +128,7 @@ class _BorrowGoodsDetailPageState extends State<BorrowGoodsDetailPage> {
'全选'.text.color(ktextSubColor).size(24.sp).make(), '全选'.text.color(ktextSubColor).size(24.sp).make(),
Spacer(), Spacer(),
'已选择 '.richText.color(ktextPrimary).size(24.sp).withTextSpanChildren([ '已选择 '.richText.color(ktextPrimary).size(24.sp).withTextSpanChildren([
'${_selectItems!.length}' '${_selectItems.length}'
.textSpan .textSpan
.size(32.sp) .size(32.sp)
.color(ktextPrimary) .color(ktextPrimary)
@ -167,19 +170,19 @@ class _BorrowGoodsDetailPageState extends State<BorrowGoodsDetailPage> {
} }
Widget _goodsCard(ArticleBorrowDetailModel model) { Widget _goodsCard(ArticleBorrowDetailModel model) {
return Row( return GestureDetector(
crossAxisAlignment: CrossAxisAlignment.start, onTap: () {
children: [ if (_selectItems.contains(model.id)) {
GestureDetector( _selectItems.remove(model.id);
onTap: () { } else {
if (_selectItems!.contains(model.id)) { _selectItems.add(model.id!);
_selectItems!.remove(model.id); }
} else { setState(() {});
_selectItems!.add(model.id); },
} child: Row(
setState(() {}); crossAxisAlignment: CrossAxisAlignment.start,
}, children: [
child: Container( Container(
height: 232.w - 48.w, height: 232.w - 48.w,
alignment: Alignment.center, alignment: Alignment.center,
child: BeeRadio( child: BeeRadio(
@ -187,72 +190,72 @@ class _BorrowGoodsDetailPageState extends State<BorrowGoodsDetailPage> {
groupValues: _selectItems, groupValues: _selectItems,
), ),
), ),
).material(color: Colors.transparent), 24.w.widthBox,
24.w.widthBox, SizedBox(
SizedBox( width: 184.w,
width: 184.w, height: 184.w,
height: 184.w, child: ClipRRect(
child: ClipRRect( child: FadeInImage.assetNetwork(
child: FadeInImage.assetNetwork( placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, image: API.image(ImgModel.first(model.imgList)),
image: API.image(ImgModel.first(model.imgList)), ),
), ),
), ),
), 24.w.widthBox,
24.w.widthBox, Column(
Column( crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, children: [
children: [ Row(
Row( children: [
children: [ Image.asset(
Image.asset( R.ASSETS_ICONS_ARTICLE_NAME_PNG,
R.ASSETS_ICONS_ARTICLE_NAME_PNG, width: 40.w,
width: 40.w, height: 40.w,
height: 40.w, ),
), 4.w.widthBox,
4.w.widthBox, '物品名称:'.text.color(ktextSubColor).size(28.sp).make(),
'物品名称:'.text.color(ktextSubColor).size(28.sp).make(), '${model.name}'.text.color(ktextPrimary).size(28.sp).make(),
'${model.name}'.text.color(ktextPrimary).size(28.sp).make(), ],
], ),
), 12.w.heightBox,
12.w.heightBox, Row(
Row( children: [
children: [ Image.asset(
Image.asset( R.ASSETS_ICONS_ARTICLE_COUNT_PNG,
R.ASSETS_ICONS_ARTICLE_COUNT_PNG, width: 40.w,
width: 40.w, height: 40.w,
height: 40.w, ),
), 4.w.widthBox,
4.w.widthBox, '物品单号:'.text.color(ktextSubColor).size(28.sp).make(),
'物品单号:'.text.color(ktextSubColor).size(28.sp).make(), '${model.code}'.text.color(ktextPrimary).size(28.sp).make(),
'${model.code}'.text.color(ktextPrimary).size(28.sp).make(), ],
], ),
), 12.w.heightBox,
12.w.heightBox, Row(
Row( children: [
children: [ Image.asset(
Image.asset( R.ASSETS_ICONS_BORROW_STATUS_PNG,
R.ASSETS_ICONS_BORROW_STATUS_PNG, width: 40.w,
width: 40.w, height: 40.w,
height: 40.w, ),
), 4.w.widthBox,
4.w.widthBox, '出借状态:'.text.color(ktextSubColor).size(28.sp).make(),
'出借状态:'.text.color(ktextSubColor).size(28.sp).make(), '${model.borrowStatus}'
'${model.borrowStatus}' .text
.text .color(ktextPrimary)
.color(ktextPrimary) .size(28.sp)
.size(28.sp) .make(),
.make(), ],
], ),
), ],
], )
) ],
], )
) .box
.box .color(Colors.white)
.color(Colors.white) .padding(EdgeInsets.symmetric(vertical: 24.w, horizontal: 24.w))
.padding(EdgeInsets.symmetric(vertical: 24.w, horizontal: 24.w)) .withRounded(value: 6.w)
.withRounded(value: 6.w) .make(),
.make(); );
} }
} }

@ -1,5 +1,4 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.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/utils/network/net_util.dart';
import 'package:aku_community/widget/bee_scaffold.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 { class BorrowGoodsPage extends StatefulWidget {
BorrowGoodsPage({Key? key}) : super(key: key); BorrowGoodsPage({Key? key}) : super(key: key);
@ -26,9 +33,15 @@ class BorrowGoodsPage extends StatefulWidget {
class _BorrowGoodsPageState extends State<BorrowGoodsPage> { class _BorrowGoodsPageState extends State<BorrowGoodsPage> {
EasyRefreshController? _easyRefreshController; EasyRefreshController? _easyRefreshController;
List<int>? _receiveIds = []; List<BorrowGoodsSubmitModel> _receiveIds = [];
List<int> _submitIds = []; List<int> get _submitIds {
List<int> _counts = []; List<int> _list = [];
_receiveIds.forEach((element) {
_list.addAll(element.selectIds);
});
return _list;
}
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -45,27 +58,30 @@ class _BorrowGoodsPageState extends State<BorrowGoodsPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BeeScaffold( return BeeScaffold(
title: '全部物品', title: '全部物品',
actions: [ // actions: [
MaterialButton( // MaterialButton(
onPressed: () { // onPressed: () {
// Get.to(() => MineGoodsPage()); // // Get.to(() => MineGoodsPage());
}, // },
child: '我的借还物品'.text.black.size(28.sp).make(), // child: '我的借还物品'.text.black.size(28.sp).make(),
padding: EdgeInsets.symmetric(horizontal: 32.w), // padding: EdgeInsets.symmetric(horizontal: 32.w),
), // ),
], // ],
body: BeeListView<ArticleBorrowModel>( body: BeeListView<ArticleBorrowModel>(
path: API.manager.articleBorrow, path: API.manager.articleBorrow,
controller: _easyRefreshController, controller: _easyRefreshController,
convert: (models) { convert: (models) {
_receiveIds = List.generate(models.tableList?.length ?? 0,
(index) => BorrowGoodsSubmitModel.init());
print(_submitIds);
setState(() {
});
return models.tableList! return models.tableList!
.map((e) => ArticleBorrowModel.fromJson(e)) .map((e) => ArticleBorrowModel.fromJson(e))
.toList(); .toList();
}, },
builder: (items) { builder: (items) {
if (_counts.isEmpty) {
_counts = List.filled(items.length, 0);
}
return ListView.separated( return 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) {
@ -162,7 +178,7 @@ class _BorrowGoodsPageState extends State<BorrowGoodsPage> {
), ),
], ],
), ),
_counts[index] == 0 _receiveIds[index].selectIds.length == 0
? SizedBox() ? SizedBox()
: Column( : Column(
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
@ -175,7 +191,7 @@ class _BorrowGoodsPageState extends State<BorrowGoodsPage> {
borderRadius: BorderRadius.circular(20.w), borderRadius: BorderRadius.circular(20.w),
color: kPrimaryColor, color: kPrimaryColor,
), ),
child: '${_counts[index]}' child: '${_receiveIds[index].selectIds.length}'
.text .text
.color(ktextPrimary) .color(ktextPrimary)
.size(24.sp) .size(24.sp)
@ -194,18 +210,10 @@ class _BorrowGoodsPageState extends State<BorrowGoodsPage> {
.withRounded(value: 6.w) .withRounded(value: 6.w)
.make() .make()
.onInkTap(() async { .onInkTap(() async {
_receiveIds?.forEach((element) { _receiveIds[index].selectIds = await Get.to(() => BorrowGoodsDetailPage(
_submitIds.remove(element); articleId: model.id!,
}); receiveIds: _receiveIds[index].selectIds,
await Get.to(() => BorrowGoodsDetailPage( ));
articleId: model.id,
receiveIds: _receiveIds,
))!
.then((value) {
_receiveIds = value;
});
_counts[index] = _receiveIds?.length ?? 0;
_submitIds.addAll(_receiveIds ?? []);
setState(() {}); setState(() {});
}); });
} }

Loading…
Cancel
Save