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

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/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<int> ids; //id
SelectPay(
{required this.payCount, required this.payTotal, required this.ids});
}
class _LifePayPageState extends State<LifePayPage> {
EasyRefreshController? _controller;
List<int> _selectYears = [];
List<int> _selectYears = []; //
List<LifePayModel?> _models = [];
List<SelectPay> _selectPay = [];
double _totalCost = 0;
int _count = 0;
List<SelectPay> _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<LifePayPage> {
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<LifePayPage> {
}
} 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<LifePayPage> {
() => 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<LifePayPage> {
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
Widget build(BuildContext context) {
final appProvider = Provider.of<AppProvider>(context);
@ -251,11 +281,12 @@ class _LifePayPageState extends State<LifePayPage> {
convert: (model) {
List<LifePayModel> lifePayModels =
model.tableList!.map((e) => LifePayModel.fromJson(e)).toList();
_selectPay.clear();
_selectPay.addAll(lifePayModels
.map((e) => SelectPay(
payCount: e.dailyPaymentTypeVos!.length,
payTotal: getPayTotal(e),
))
ids: getIds(e)))
.toList());
return lifePayModels;
},
@ -291,8 +322,10 @@ class _LifePayPageState extends State<LifePayPage> {
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<LifePayPage> {
}
_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<LifePayPage> {
borderRadius: BorderRadius.circular(37.w)),
color: kPrimaryColor,
padding: EdgeInsets.symmetric(horizontal: 50.w, vertical: 15.w),
onPressed: () {
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(),
),

@ -25,6 +25,7 @@ class LifePayDetailPage extends StatefulWidget {
class _LifePayDetailPageState extends State<LifePayDetailPage> {
List<String> _selectItems = [];
List<int> _ids = [];
double _payTotal = 0;
int _payNum = 0;
int get listLength {
@ -53,6 +54,9 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
.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<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(
onTap: () {
String item = id.toString() + groupId.toString();
@ -70,8 +83,12 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
_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<LifePayDetailPage> {
),
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<LifePayDetailPage> {
onTap: () {
if (isAllSelect) {
_selectItems.clear();
_ids.clear();
_payNum = 0;
_payTotal = 0;
} else {
@ -167,6 +186,12 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
.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<LifePayDetailPage> {
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(),
),

Loading…
Cancel
Save