重写多选逻辑

hmxc
张萌 4 years ago
parent 82766835da
commit 0e408e08ce

@ -1,11 +1,11 @@
class LifePayMolde {
class LifePayModel {
int years;
int paymentNum;
List<DailyPaymentTypeVos> dailyPaymentTypeVos;
LifePayMolde({this.years, this.paymentNum, this.dailyPaymentTypeVos});
LifePayModel({this.years, this.paymentNum, this.dailyPaymentTypeVos});
LifePayMolde.fromJson(Map<String, dynamic> json) {
LifePayModel.fromJson(Map<String, dynamic> json) {
years = json['years'];
paymentNum = json['paymentNum'];
if (json['dailyPaymentTypeVos'] != null) {

@ -3,17 +3,17 @@ import 'package:akuCommunity/base/base_style.dart';
import 'package:akuCommunity/const/resource.dart';
import 'package:akuCommunity/constants/api.dart';
import 'package:akuCommunity/model/manager/life_pay_model.dart';
import 'package:akuCommunity/pages/life_pay/widget/life_pay_detail_page.dart';
import 'package:akuCommunity/pages/life_pay/widget/my_house_page.dart';
import 'package:akuCommunity/pages/things_page/widget/bee_list_view.dart';
import 'package:akuCommunity/provider/user_provider.dart';
import 'package:akuCommunity/utils/bee_parse.dart';
import 'package:akuCommunity/widget/buttons/bee_check_box.dart';
import 'package:akuCommunity/widget/buttons/bee_check_radio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:provider/provider.dart';
// Package imports:
import 'package:velocity_x/velocity_x.dart';
@ -29,8 +29,29 @@ class LifePayPage extends StatefulWidget {
_LifePayPageState createState() => _LifePayPageState();
}
class SelectList {
bool value;
List<String> selected;
SelectList();
}
class _LifePayPageState extends State<LifePayPage> {
EasyRefreshController _controller;
List<SelectList> selectItems = [];
List<int> _selectYears = [];
List<LifePayModel> _models;
bool get isAllSelect => _models.length == _selectYears.length;
int _getLength(LifePayModel model) {
int count = 0;
model.dailyPaymentTypeVos.forEach((element) {
element.detailedVoList.forEach((element) {
count++;
});
});
return count;
}
@override
void initState() {
super.initState();
@ -92,7 +113,7 @@ class _LifePayPageState extends State<LifePayPage> {
);
}
Widget _buildCard(LifePayMolde model) {
Widget _buildCard(LifePayModel model, int index) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.w), color: kForeGroundColor),
@ -102,8 +123,59 @@ class _LifePayPageState extends State<LifePayPage> {
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
BeeCheckBox.round(
onChange: (value) {},
GestureDetector(
onTap: () {
if (selectItems[index].selected.length ==
_getLength(model)) {
selectItems[index].value = false;
selectItems[index].selected.clear();
_selectYears.remove(index);
} else {
selectItems[index].value = true;
_selectYears.add(index);
for (var i = 0; i < model.dailyPaymentTypeVos.length; i++) {
for (var j = 0;
i <
model
.dailyPaymentTypeVos[i].detailedVoList.length;
i++) {
String id = model.dailyPaymentTypeVos[i].id.toString() +
model.dailyPaymentTypeVos[i].detailedVoList[j]
.groupId
.toString();
if (!selectItems[index].selected.contains(id)) {
selectItems[index].selected.add(id);
}
}
}
}
setState(() {});
},
child: BeeCheckRadio(
value: index,
groupValue: _selectYears,
// onChange: (value) {
// if (value) {
// selectItems[index].value=false;
// selectItems[index].selected.clear();
// } else {
// selectItems[index].value=true;
// for (var i = 0; i < model.dailyPaymentTypeVos.length; i++) {
// for (var j = 0;
// i <
// model
// .dailyPaymentTypeVos[i].detailedVoList.length;
// i++) {
// selectItems[index].selected.add(
// model.dailyPaymentTypeVos[i].id.toString() +
// model.dailyPaymentTypeVos[i].detailedVoList[j]
// .groupId
// .toString());
// }
// }
// }
// },
),
),
],
),
@ -145,7 +217,12 @@ class _LifePayPageState extends State<LifePayPage> {
mainAxisAlignment: MainAxisAlignment.start,
children: [
GestureDetector(
onTap: () {},
onTap: () {
LifePayDetailPage(
model: _models[index],
selectItems: selectItems[index].selected,
).to();
},
child: Container(
decoration: BoxDecoration(
color: Color(0xFF2A2A2A),
@ -185,10 +262,11 @@ class _LifePayPageState extends State<LifePayPage> {
controller: _controller,
convert: (model) {
return model.tableList
.map((e) => LifePayMolde.fromJson(e))
.map((e) => LifePayModel.fromJson(e))
.toList();
},
builder: (items) {
_models = items;
return Column(
children: [
_buildHouseCard(
@ -207,8 +285,8 @@ class _LifePayPageState extends State<LifePayPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
'缴费账单'.text.color(ktextPrimary).size(28.sp).make(),
...List.generate(
items.length, (index) => _buildCard(items[index])),
...List.generate(items.length,
(index) => _buildCard(items[index], index)),
],
),
),
@ -220,9 +298,51 @@ class _LifePayPageState extends State<LifePayPage> {
32.w, 16.w, 32.w, 12.w + MediaQuery.of(context).padding.bottom),
child: Row(
children: [
BeeCheckBox.round(
onChange: (value) {},
size: 40.w,
// BeeCheckBox.round(
// onChange: (value) {
// if (value) {
// _selectYears.clear();
// } else {
// for (var i = 0; i < _models.length; i++) {
// _selectYears.add(i);
// }
// }
// setState(() {});
// },
// size: 40.w,
// ),
GestureDetector(
onTap: () {
if (isAllSelect) {
_selectYears.clear();
} else {
for (var i = 0; i < _models.length; i++) {
if (!_selectYears.contains(i)) {
_selectYears.add(i);
}
}
}
setState(() {});
},
child: AnimatedContainer(
duration: Duration(milliseconds: 300),
decoration: BoxDecoration(
border: Border.all(
width: 1.w,
color: isAllSelect ? kPrimaryColor : kDarkSubColor),
color: isAllSelect ? kPrimaryColor : Colors.transparent,
borderRadius: BorderRadius.circular(20.w)),
curve: Curves.easeInOutCubic,
width: 40.w,
height: 40.w,
child: isAllSelect
? Icon(
CupertinoIcons.check_mark,
size: 25.w,
color: Colors.white,
)
: SizedBox(),
),
),
Spacer(),
Column(
@ -247,6 +367,7 @@ class _LifePayPageState extends State<LifePayPage> {
'已选10项'.text.color(ktextSubColor).size(20.sp).make(),
],
),
24.w.widthBox,
MaterialButton(
elevation: 0,
shape: RoundedRectangleBorder(

@ -1,17 +1,24 @@
import 'package:akuCommunity/base/base_style.dart';
import 'package:akuCommunity/model/manager/life_pay_model.dart';
import 'package:akuCommunity/pages/life_pay/life_pay_page.dart';
import 'package:akuCommunity/provider/user_provider.dart';
import 'package:akuCommunity/utils/bee_parse.dart';
import 'package:akuCommunity/widget/bee_scaffold.dart';
import 'package:akuCommunity/widget/buttons/bee_check_box.dart';
import 'package:akuCommunity/widget/buttons/bee_check_radio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:akuCommunity/utils/headers.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
class LifePayDetailPage extends StatefulWidget {
final LifePayMolde model;
final LifePayModel model;
final List<String> selectItems;
LifePayDetailPage({
Key key,
this.model,
this.selectItems,
}) : super(key: key);
@override
@ -19,25 +26,142 @@ class LifePayDetailPage extends StatefulWidget {
}
class _LifePayDetailPageState extends State<LifePayDetailPage> {
int get listLength {
int count = 0;
widget.model.dailyPaymentTypeVos.forEach((element) {
element.detailedVoList.forEach((element) {
count++;
});
});
return count;
}
bool get isAllSelect {
return listLength == widget.selectItems.length;
}
Widget _buildTile(int groupId, int id, int years, int price) {
return Row(
children: [
GestureDetector(
onTap: () {
String item = id.toString() + groupId.toString();
if (widget.selectItems.contains(item)) {
widget.selectItems.remove(item);
} else {
widget.selectItems.add(item);
}
setState(() {});
},
child: BeeCheckRadio(
value: id.toString() + groupId.toString(),
groupValue: widget.selectItems)),
24.w.widthBox,
groupId == 1
? '$years上半年'.text.black.size(28.sp).make()
: '$years下半年'.text.black.size(28.sp).make(),
Spacer(),
'¥${price.toString()}'.text.color(kDangerColor).size(28.sp).bold.make(),
24.w.widthBox,
Icon(
CupertinoIcons.chevron_forward,
size: 40.w,
),
],
);
}
Widget _buildCard(DailyPaymentTypeVos model) {
UserProvider userProvider = Provider.of<UserProvider>(context);
return Container(
padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 20.w),
child: Column(
children: [
Row(
children: [
model.name.text.black.size(30.sp).bold.make(),
Spacer(),
'$kEstateName ${BeeParse.getEstateName(userProvider.currentHouse)}'
.text
.color(ktextSubColor)
.size(24.sp)
.make(),
],
),
50.w.heightBox,
...model.detailedVoList
.map((e) => _buildTile(
e.groupId, model.id, widget.model.years, e.paymentPrice))
.toList(),
],
),
);
}
@override
Widget build(BuildContext context) {
return BeeScaffold(
title:
'${BeeParse.getCustomYears(widget.model.years)}-${widget.model.years}年明细',
body: ListView(
padding: EdgeInsets.only(top: 16.w),
children: [
],
),
bottomNavi: Container(
title:
'${BeeParse.getCustomYears(widget.model.years)}-${widget.model.years}年明细',
body: ListView(
padding: EdgeInsets.only(top: 16.w),
children: [
...widget.model.dailyPaymentTypeVos
.map((e) => _buildCard(e))
.toList(),
],
),
bottomNavi: Container(
padding: EdgeInsets.fromLTRB(
32.w, 16.w, 32.w, 12.w + MediaQuery.of(context).padding.bottom),
child: Row(
children: [
BeeCheckBox.round(
onChange: (value) {},
size: 40.w,
GestureDetector(
onTap: () {
if (isAllSelect) {
widget.selectItems.clear();
} else {
for (var i = 0;
i < widget.model.dailyPaymentTypeVos.length;
i++) {
for (var j = 0;
i <
widget.model.dailyPaymentTypeVos[i].detailedVoList
.length;
i++) {
String id =
widget.model.dailyPaymentTypeVos[i].id.toString() +
widget.model.dailyPaymentTypeVos[i]
.detailedVoList[j].groupId
.toString();
if (!widget.selectItems.contains(id)) {
widget.selectItems.add(id);
}
}
}
}
setState(() {});
},
child: AnimatedContainer(
duration: Duration(milliseconds: 300),
decoration: BoxDecoration(
border: Border.all(
width: 1.w,
color: isAllSelect ? kPrimaryColor : kDarkSubColor),
color: isAllSelect ? kPrimaryColor : Colors.transparent,
borderRadius: BorderRadius.circular(20.w)),
curve: Curves.easeInOutCubic,
width: 40.w,
height: 40.w,
child: isAllSelect
? Icon(
CupertinoIcons.check_mark,
size: 25.w,
color: Colors.white,
)
: SizedBox(),
),
),
Spacer(),
Column(
@ -76,6 +200,6 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
],
),
),
);
);
}
}

@ -92,7 +92,7 @@ class _AddFixedSubmitPageState extends State<AddFixedSubmitPage> {
size: 40.w,
),
],
),
).material(color: Colors.transparent),
),
24.w.heightBox,
BeeDivider.horizontal(),

@ -0,0 +1,47 @@
import 'package:akuCommunity/base/base_style.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:akuCommunity/utils/headers.dart';
class BeeCheckRadio<T> extends StatefulWidget {
final T value;
final List<T> groupValue;
BeeCheckRadio({Key key, this.value, this.groupValue}) : super(key: key);
@override
_BeeCheckRadioState createState() => _BeeCheckRadioState();
}
class _BeeCheckRadioState extends State<BeeCheckRadio> {
bool get _selected {
if (widget.groupValue.contains(widget.value)) return true;
return false;
}
@override
Widget build(BuildContext context) {
return AnimatedContainer(
height: 40.w,
width: 40.w,
decoration: BoxDecoration(
border: Border.all(
color: _selected ? 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: _selected ? 1 : 0,
child: Icon(
CupertinoIcons.chevron_forward,
size: 24.w,
),
),
);
}
}
Loading…
Cancel
Save