重写多选逻辑

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

@ -1,11 +1,11 @@
class LifePayMolde { class LifePayModel {
int years; int years;
int paymentNum; int paymentNum;
List<DailyPaymentTypeVos> dailyPaymentTypeVos; 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']; years = json['years'];
paymentNum = json['paymentNum']; paymentNum = json['paymentNum'];
if (json['dailyPaymentTypeVos'] != null) { if (json['dailyPaymentTypeVos'] != null) {

@ -3,17 +3,17 @@ import 'package:akuCommunity/base/base_style.dart';
import 'package:akuCommunity/const/resource.dart'; import 'package:akuCommunity/const/resource.dart';
import 'package:akuCommunity/constants/api.dart'; import 'package:akuCommunity/constants/api.dart';
import 'package:akuCommunity/model/manager/life_pay_model.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/life_pay/widget/my_house_page.dart';
import 'package:akuCommunity/pages/things_page/widget/bee_list_view.dart'; import 'package:akuCommunity/pages/things_page/widget/bee_list_view.dart';
import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/provider/user_provider.dart';
import 'package:akuCommunity/utils/bee_parse.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/cupertino.dart';
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:provider/provider.dart'; import 'package:provider/provider.dart';
// Package imports: // Package imports:
import 'package:velocity_x/velocity_x.dart'; import 'package:velocity_x/velocity_x.dart';
@ -29,8 +29,29 @@ class LifePayPage extends StatefulWidget {
_LifePayPageState createState() => _LifePayPageState(); _LifePayPageState createState() => _LifePayPageState();
} }
class SelectList {
bool value;
List<String> selected;
SelectList();
}
class _LifePayPageState extends State<LifePayPage> { class _LifePayPageState extends State<LifePayPage> {
EasyRefreshController _controller; 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 @override
void initState() { void initState() {
super.initState(); super.initState();
@ -92,7 +113,7 @@ class _LifePayPageState extends State<LifePayPage> {
); );
} }
Widget _buildCard(LifePayMolde model) { Widget _buildCard(LifePayModel model, int index) {
return Container( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.w), color: kForeGroundColor), borderRadius: BorderRadius.circular(8.w), color: kForeGroundColor),
@ -102,8 +123,59 @@ class _LifePayPageState extends State<LifePayPage> {
Column( Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
BeeCheckBox.round( GestureDetector(
onChange: (value) {}, 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, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
GestureDetector( GestureDetector(
onTap: () {}, onTap: () {
LifePayDetailPage(
model: _models[index],
selectItems: selectItems[index].selected,
).to();
},
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Color(0xFF2A2A2A), color: Color(0xFF2A2A2A),
@ -185,10 +262,11 @@ class _LifePayPageState extends State<LifePayPage> {
controller: _controller, controller: _controller,
convert: (model) { convert: (model) {
return model.tableList return model.tableList
.map((e) => LifePayMolde.fromJson(e)) .map((e) => LifePayModel.fromJson(e))
.toList(); .toList();
}, },
builder: (items) { builder: (items) {
_models = items;
return Column( return Column(
children: [ children: [
_buildHouseCard( _buildHouseCard(
@ -207,8 +285,8 @@ class _LifePayPageState extends State<LifePayPage> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
'缴费账单'.text.color(ktextPrimary).size(28.sp).make(), '缴费账单'.text.color(ktextPrimary).size(28.sp).make(),
...List.generate( ...List.generate(items.length,
items.length, (index) => _buildCard(items[index])), (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), 32.w, 16.w, 32.w, 12.w + MediaQuery.of(context).padding.bottom),
child: Row( child: Row(
children: [ children: [
BeeCheckBox.round( // BeeCheckBox.round(
onChange: (value) {}, // onChange: (value) {
size: 40.w, // 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(), Spacer(),
Column( Column(
@ -247,6 +367,7 @@ class _LifePayPageState extends State<LifePayPage> {
'已选10项'.text.color(ktextSubColor).size(20.sp).make(), '已选10项'.text.color(ktextSubColor).size(20.sp).make(),
], ],
), ),
24.w.widthBox,
MaterialButton( MaterialButton(
elevation: 0, elevation: 0,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(

@ -1,17 +1,24 @@
import 'package:akuCommunity/base/base_style.dart'; import 'package:akuCommunity/base/base_style.dart';
import 'package:akuCommunity/model/manager/life_pay_model.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/utils/bee_parse.dart';
import 'package:akuCommunity/widget/bee_scaffold.dart'; import 'package:akuCommunity/widget/bee_scaffold.dart';
import 'package:akuCommunity/widget/buttons/bee_check_box.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/material.dart';
import 'package:akuCommunity/utils/headers.dart'; import 'package:akuCommunity/utils/headers.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:provider/provider.dart';
class LifePayDetailPage extends StatefulWidget { class LifePayDetailPage extends StatefulWidget {
final LifePayMolde model; final LifePayModel model;
final List<String> selectItems;
LifePayDetailPage({ LifePayDetailPage({
Key key, Key key,
this.model, this.model,
this.selectItems,
}) : super(key: key); }) : super(key: key);
@override @override
@ -19,6 +26,79 @@ class LifePayDetailPage extends StatefulWidget {
} }
class _LifePayDetailPageState extends State<LifePayDetailPage> { 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BeeScaffold( return BeeScaffold(
@ -27,7 +107,9 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
body: ListView( body: ListView(
padding: EdgeInsets.only(top: 16.w), padding: EdgeInsets.only(top: 16.w),
children: [ children: [
...widget.model.dailyPaymentTypeVos
.map((e) => _buildCard(e))
.toList(),
], ],
), ),
bottomNavi: Container( bottomNavi: Container(
@ -35,9 +117,51 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
32.w, 16.w, 32.w, 12.w + MediaQuery.of(context).padding.bottom), 32.w, 16.w, 32.w, 12.w + MediaQuery.of(context).padding.bottom),
child: Row( child: Row(
children: [ children: [
BeeCheckBox.round( GestureDetector(
onChange: (value) {}, onTap: () {
size: 40.w, 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(), Spacer(),
Column( Column(

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