From 53b7a883d9b3e865f0bf75894bc34f5e6194cb2a Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Wed, 26 May 2021 20:14:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E7=BC=B4=E8=B4=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=88=E6=9A=82=E6=9C=AA=E6=8E=A5=E5=85=A5=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=8A=9F=E8=83=BD=EF=BC=8C=E7=9B=B4=E6=8E=A5=E8=B7=B3?= =?UTF-8?q?=E8=BF=87=E8=87=B3=E6=88=90=E5=8A=9F=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/life_pay/life_pay_page.dart | 81 ++++++++++++++----- .../life_pay/widget/life_pay_detail_page.dart | 35 ++++++-- 2 files changed, 92 insertions(+), 24 deletions(-) diff --git a/lib/pages/life_pay/life_pay_page.dart b/lib/pages/life_pay/life_pay_page.dart index 49f0ad0e..5ae2300c 100644 --- a/lib/pages/life_pay/life_pay_page.dart +++ b/lib/pages/life_pay/life_pay_page.dart @@ -1,9 +1,11 @@ import 'package:aku_community/pages/life_pay/pay_finish_page.dart'; +import 'package:aku_community/utils/network/base_model.dart'; +import 'package:aku_community/utils/network/net_util.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; -import 'package:get/get.dart'; +import 'package:get/get.dart' hide Response; import 'package:provider/provider.dart'; import 'package:velocity_x/velocity_x.dart'; @@ -29,18 +31,21 @@ class LifePayPage extends StatefulWidget { } class SelectPay { - double? payTotal; - int? payCount; - SelectPay({this.payCount, this.payTotal}); + double payTotal; //费用 + int payCount; //项数 + List ids; //存储选中的主键id数组 + SelectPay( + {required this.payCount, required this.payTotal, required this.ids}); } class _LifePayPageState extends State { EasyRefreshController? _controller; - List _selectYears = []; + List _selectYears = []; //选择的年份,存储其数组下标 List _models = []; - List _selectPay = []; - double _totalCost = 0; - int _count = 0; + List _selectPay = []; //辅助计算总费用数组 储存下级页面传递出来的已选费用参数 + double _totalCost = 0; //总费用 + int _count = 0; //费用项数 + List _ids = []; //存储选中的主键id数组 bool get allSelect => ((_models.length == _selectYears.length) && (_models.length != 0)); @@ -130,8 +135,11 @@ class _LifePayPageState extends State { setState(() { if (_selectYears.contains(index)) { _selectYears.remove(index); - _totalCost -= (_selectPay[index].payTotal ?? 0.0); - _count -= (_selectPay[index].payCount ?? 0); + _totalCost -= (_selectPay[index].payTotal); + _count -= (_selectPay[index].payCount); + _selectPay[index].ids.forEach((element) { + _ids.remove(element); + }); if (_count < 0) { _count = 0; } @@ -140,8 +148,9 @@ class _LifePayPageState extends State { } } else { _selectYears.add(index); - _totalCost += (_selectPay[index].payTotal ?? 0.0); - _count += (_selectPay[index].payCount ?? 0); + _totalCost += (_selectPay[index].payTotal); + _count += (_selectPay[index].payCount); + _ids.addAll(_selectPay[index].ids); } }); }, @@ -196,6 +205,7 @@ class _LifePayPageState extends State { () => LifePayDetailPage(model: _models[index]))); _selectPay[index].payCount = payMent[0]; _selectPay[index].payTotal = payMent[1]; + _selectPay[index].ids = payMent[2]; setState(() {}); }, child: Container( @@ -227,6 +237,26 @@ class _LifePayPageState extends State { return total as double; } + List getIds(LifePayModel list) { + List _list = []; + if (list.dailyPaymentTypeVos != null) { + for (var item in list.dailyPaymentTypeVos!) { + for (var v in item.detailedVoList!) { + _list.addAll(_findIds(v.detailsVoList ?? [])); + } + } + } + return _list; + } + + List _findIds(List list) { + List _list = []; + list.forEach((element) { + _list.add(element.id!); + }); + return _list; + } + @override Widget build(BuildContext context) { final appProvider = Provider.of(context); @@ -251,11 +281,12 @@ class _LifePayPageState extends State { convert: (model) { List lifePayModels = model.tableList!.map((e) => LifePayModel.fromJson(e)).toList(); + _selectPay.clear(); _selectPay.addAll(lifePayModels .map((e) => SelectPay( - payCount: e.dailyPaymentTypeVos!.length, - payTotal: getPayTotal(e), - )) + payCount: e.dailyPaymentTypeVos!.length, + payTotal: getPayTotal(e), + ids: getIds(e))) .toList()); return lifePayModels; }, @@ -291,8 +322,10 @@ class _LifePayPageState extends State { children: [ GestureDetector( onTap: () { + //若已全选则清空已选年份数组 if (_models.length == _selectYears.length) { _selectYears.clear(); + _ids.clear(); _totalCost = 0; _count = 0; } else { @@ -303,9 +336,11 @@ class _LifePayPageState extends State { } _totalCost = 0; _count = 0; + _ids.clear(); for (var item in _selectPay) { - _totalCost += item.payTotal!; - _count += item.payCount!; + _totalCost += item.payTotal; + _count += item.payCount; + _ids.addAll(item.ids); } } setState(() {}); @@ -360,8 +395,16 @@ class _LifePayPageState extends State { borderRadius: BorderRadius.circular(37.w)), color: kPrimaryColor, padding: EdgeInsets.symmetric(horizontal: 50.w, vertical: 15.w), - onPressed: () { - Get.off(() => PayFinishPage()); + onPressed: () async { + BaseModel baseModel = await NetUtil() + .post('/user/dailyPayment/pay', params: { + "ids": _ids, + "payType":1, //暂时写死 等待后续补充 + "payPrice":_totalCost + }); + if (baseModel.status ?? false) { + Get.off(() => PayFinishPage()); + } }, child: '去缴费'.text.black.size(32.sp).bold.make(), ), diff --git a/lib/pages/life_pay/widget/life_pay_detail_page.dart b/lib/pages/life_pay/widget/life_pay_detail_page.dart index 89849937..d3ba8232 100644 --- a/lib/pages/life_pay/widget/life_pay_detail_page.dart +++ b/lib/pages/life_pay/widget/life_pay_detail_page.dart @@ -25,6 +25,7 @@ class LifePayDetailPage extends StatefulWidget { class _LifePayDetailPageState extends State { List _selectItems = []; + List _ids = []; double _payTotal = 0; int _payNum = 0; int get listLength { @@ -53,6 +54,9 @@ class _LifePayDetailPageState extends State { .toString(); if (!_selectItems.contains(id)) { _selectItems.add(id); + _ids.addAll(_findIds(widget.model!.dailyPaymentTypeVos![i] + .detailedVoList![j].detailsVoList ?? + [])); _payNum += 1; _payTotal += widget .model!.dailyPaymentTypeVos![i].detailedVoList![j].paymentPrice! @@ -62,7 +66,16 @@ class _LifePayDetailPageState extends State { } } - Widget _buildTile(int? groupId, int? id, int? years, double? price) { + List _findIds(List list) { + List _list = []; + list.forEach((element) { + _list.add(element.id!); + }); + return _list; + } + + Widget _buildTile( + int? groupId, int? id, int? years, double? price, List list) { return GestureDetector( onTap: () { String item = id.toString() + groupId.toString(); @@ -70,8 +83,12 @@ class _LifePayDetailPageState extends State { _selectItems.remove(item); _payNum -= 1; _payTotal -= price!.toDouble(); + list.forEach((element) { + _ids.remove(element); + }); } else { _selectItems.add(item); + _ids.addAll(list); _payNum += 1; _payTotal += price!.toDouble(); } @@ -119,9 +136,10 @@ class _LifePayDetailPageState extends State { ), 50.w.heightBox, ...model.detailedVoList! - .map((e) => _buildTile( - e.groupId, model.id, widget.model!.years, e.paymentPrice)) - .toList().sepWidget(separate: 24.w.heightBox), + .map((e) => _buildTile(e.groupId, model.id, widget.model!.years, + e.paymentPrice, _findIds(e.detailsVoList ?? []))) + .toList() + .sepWidget(separate: 24.w.heightBox), ], ), ); @@ -149,6 +167,7 @@ class _LifePayDetailPageState extends State { onTap: () { if (isAllSelect) { _selectItems.clear(); + _ids.clear(); _payNum = 0; _payTotal = 0; } else { @@ -167,6 +186,12 @@ class _LifePayDetailPageState extends State { .toString(); if (!_selectItems.contains(id)) { _selectItems.add(id); + _ids.addAll(_findIds(widget + .model! + .dailyPaymentTypeVos![i] + .detailedVoList![j] + .detailsVoList ?? + [])); _payNum += 1; _payTotal += widget.model!.dailyPaymentTypeVos![i] .detailedVoList![j].paymentPrice! @@ -228,7 +253,7 @@ class _LifePayDetailPageState extends State { color: kPrimaryColor, padding: EdgeInsets.symmetric(horizontal: 50.w, vertical: 15.w), onPressed: () { - Get.back(result: [_payNum, _payTotal]); + Get.back(result: [_payNum, _payTotal,_ids]); }, child: '选好了'.text.black.size(32.sp).bold.make(), ),