对接缴费接口(暂未接入支付功能,直接跳过至成功页面

hmxc
张萌 4 years ago
parent e10f19ddd1
commit 53b7a883d9

@ -1,9 +1,11 @@
import 'package:aku_community/pages/life_pay/pay_finish_page.dart'; 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/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:get/get.dart'; import 'package:get/get.dart' hide Response;
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:velocity_x/velocity_x.dart'; import 'package:velocity_x/velocity_x.dart';
@ -29,18 +31,21 @@ class LifePayPage extends StatefulWidget {
} }
class SelectPay { class SelectPay {
double? payTotal; double payTotal; //
int? payCount; int payCount; //
SelectPay({this.payCount, this.payTotal}); List<int> ids; //id
SelectPay(
{required this.payCount, required this.payTotal, required this.ids});
} }
class _LifePayPageState extends State<LifePayPage> { class _LifePayPageState extends State<LifePayPage> {
EasyRefreshController? _controller; EasyRefreshController? _controller;
List<int> _selectYears = []; List<int> _selectYears = []; //
List<LifePayModel?> _models = []; List<LifePayModel?> _models = [];
List<SelectPay> _selectPay = []; List<SelectPay> _selectPay = []; //
double _totalCost = 0; double _totalCost = 0; //
int _count = 0; int _count = 0; //
List _ids = []; //id
bool get allSelect => bool get allSelect =>
((_models.length == _selectYears.length) && (_models.length != 0)); ((_models.length == _selectYears.length) && (_models.length != 0));
@ -130,8 +135,11 @@ class _LifePayPageState extends State<LifePayPage> {
setState(() { setState(() {
if (_selectYears.contains(index)) { if (_selectYears.contains(index)) {
_selectYears.remove(index); _selectYears.remove(index);
_totalCost -= (_selectPay[index].payTotal ?? 0.0); _totalCost -= (_selectPay[index].payTotal);
_count -= (_selectPay[index].payCount ?? 0); _count -= (_selectPay[index].payCount);
_selectPay[index].ids.forEach((element) {
_ids.remove(element);
});
if (_count < 0) { if (_count < 0) {
_count = 0; _count = 0;
} }
@ -140,8 +148,9 @@ class _LifePayPageState extends State<LifePayPage> {
} }
} else { } else {
_selectYears.add(index); _selectYears.add(index);
_totalCost += (_selectPay[index].payTotal ?? 0.0); _totalCost += (_selectPay[index].payTotal);
_count += (_selectPay[index].payCount ?? 0); _count += (_selectPay[index].payCount);
_ids.addAll(_selectPay[index].ids);
} }
}); });
}, },
@ -196,6 +205,7 @@ class _LifePayPageState extends State<LifePayPage> {
() => LifePayDetailPage(model: _models[index]))); () => LifePayDetailPage(model: _models[index])));
_selectPay[index].payCount = payMent[0]; _selectPay[index].payCount = payMent[0];
_selectPay[index].payTotal = payMent[1]; _selectPay[index].payTotal = payMent[1];
_selectPay[index].ids = payMent[2];
setState(() {}); setState(() {});
}, },
child: Container( child: Container(
@ -227,6 +237,26 @@ class _LifePayPageState extends State<LifePayPage> {
return total as double; return total as double;
} }
List<int> getIds(LifePayModel list) {
List<int> _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<int> _findIds(List<DetailsVoList> list) {
List<int> _list = [];
list.forEach((element) {
_list.add(element.id!);
});
return _list;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final appProvider = Provider.of<AppProvider>(context); final appProvider = Provider.of<AppProvider>(context);
@ -251,11 +281,12 @@ class _LifePayPageState extends State<LifePayPage> {
convert: (model) { convert: (model) {
List<LifePayModel> lifePayModels = List<LifePayModel> lifePayModels =
model.tableList!.map((e) => LifePayModel.fromJson(e)).toList(); model.tableList!.map((e) => LifePayModel.fromJson(e)).toList();
_selectPay.clear();
_selectPay.addAll(lifePayModels _selectPay.addAll(lifePayModels
.map((e) => SelectPay( .map((e) => SelectPay(
payCount: e.dailyPaymentTypeVos!.length, payCount: e.dailyPaymentTypeVos!.length,
payTotal: getPayTotal(e), payTotal: getPayTotal(e),
)) ids: getIds(e)))
.toList()); .toList());
return lifePayModels; return lifePayModels;
}, },
@ -291,8 +322,10 @@ class _LifePayPageState extends State<LifePayPage> {
children: [ children: [
GestureDetector( GestureDetector(
onTap: () { onTap: () {
//
if (_models.length == _selectYears.length) { if (_models.length == _selectYears.length) {
_selectYears.clear(); _selectYears.clear();
_ids.clear();
_totalCost = 0; _totalCost = 0;
_count = 0; _count = 0;
} else { } else {
@ -303,9 +336,11 @@ class _LifePayPageState extends State<LifePayPage> {
} }
_totalCost = 0; _totalCost = 0;
_count = 0; _count = 0;
_ids.clear();
for (var item in _selectPay) { for (var item in _selectPay) {
_totalCost += item.payTotal!; _totalCost += item.payTotal;
_count += item.payCount!; _count += item.payCount;
_ids.addAll(item.ids);
} }
} }
setState(() {}); setState(() {});
@ -360,8 +395,16 @@ class _LifePayPageState extends State<LifePayPage> {
borderRadius: BorderRadius.circular(37.w)), borderRadius: BorderRadius.circular(37.w)),
color: kPrimaryColor, color: kPrimaryColor,
padding: EdgeInsets.symmetric(horizontal: 50.w, vertical: 15.w), padding: EdgeInsets.symmetric(horizontal: 50.w, vertical: 15.w),
onPressed: () { onPressed: () async {
Get.off(() => PayFinishPage()); 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(), child: '去缴费'.text.black.size(32.sp).bold.make(),
), ),

@ -25,6 +25,7 @@ class LifePayDetailPage extends StatefulWidget {
class _LifePayDetailPageState extends State<LifePayDetailPage> { class _LifePayDetailPageState extends State<LifePayDetailPage> {
List<String> _selectItems = []; List<String> _selectItems = [];
List<int> _ids = [];
double _payTotal = 0; double _payTotal = 0;
int _payNum = 0; int _payNum = 0;
int get listLength { int get listLength {
@ -53,6 +54,9 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
.toString(); .toString();
if (!_selectItems.contains(id)) { if (!_selectItems.contains(id)) {
_selectItems.add(id); _selectItems.add(id);
_ids.addAll(_findIds(widget.model!.dailyPaymentTypeVos![i]
.detailedVoList![j].detailsVoList ??
[]));
_payNum += 1; _payNum += 1;
_payTotal += widget _payTotal += widget
.model!.dailyPaymentTypeVos![i].detailedVoList![j].paymentPrice! .model!.dailyPaymentTypeVos![i].detailedVoList![j].paymentPrice!
@ -62,7 +66,16 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
} }
} }
Widget _buildTile(int? groupId, int? id, int? years, double? price) { List<int> _findIds(List<DetailsVoList> list) {
List<int> _list = [];
list.forEach((element) {
_list.add(element.id!);
});
return _list;
}
Widget _buildTile(
int? groupId, int? id, int? years, double? price, List<int> list) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
String item = id.toString() + groupId.toString(); String item = id.toString() + groupId.toString();
@ -70,8 +83,12 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
_selectItems.remove(item); _selectItems.remove(item);
_payNum -= 1; _payNum -= 1;
_payTotal -= price!.toDouble(); _payTotal -= price!.toDouble();
list.forEach((element) {
_ids.remove(element);
});
} else { } else {
_selectItems.add(item); _selectItems.add(item);
_ids.addAll(list);
_payNum += 1; _payNum += 1;
_payTotal += price!.toDouble(); _payTotal += price!.toDouble();
} }
@ -119,9 +136,10 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
), ),
50.w.heightBox, 50.w.heightBox,
...model.detailedVoList! ...model.detailedVoList!
.map((e) => _buildTile( .map((e) => _buildTile(e.groupId, model.id, widget.model!.years,
e.groupId, model.id, widget.model!.years, e.paymentPrice)) e.paymentPrice, _findIds(e.detailsVoList ?? [])))
.toList().sepWidget(separate: 24.w.heightBox), .toList()
.sepWidget(separate: 24.w.heightBox),
], ],
), ),
); );
@ -149,6 +167,7 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
onTap: () { onTap: () {
if (isAllSelect) { if (isAllSelect) {
_selectItems.clear(); _selectItems.clear();
_ids.clear();
_payNum = 0; _payNum = 0;
_payTotal = 0; _payTotal = 0;
} else { } else {
@ -167,6 +186,12 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
.toString(); .toString();
if (!_selectItems.contains(id)) { if (!_selectItems.contains(id)) {
_selectItems.add(id); _selectItems.add(id);
_ids.addAll(_findIds(widget
.model!
.dailyPaymentTypeVos![i]
.detailedVoList![j]
.detailsVoList ??
[]));
_payNum += 1; _payNum += 1;
_payTotal += widget.model!.dailyPaymentTypeVos![i] _payTotal += widget.model!.dailyPaymentTypeVos![i]
.detailedVoList![j].paymentPrice! .detailedVoList![j].paymentPrice!
@ -228,7 +253,7 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
color: kPrimaryColor, color: kPrimaryColor,
padding: EdgeInsets.symmetric(horizontal: 50.w, vertical: 15.w), padding: EdgeInsets.symmetric(horizontal: 50.w, vertical: 15.w),
onPressed: () { onPressed: () {
Get.back(result: [_payNum, _payTotal]); Get.back(result: [_payNum, _payTotal,_ids]);
}, },
child: '选好了'.text.black.size(32.sp).bold.make(), child: '选好了'.text.black.size(32.sp).bold.make(),
), ),

Loading…
Cancel
Save