提交 b855e8d1 authored 作者: yueweilu's avatar yueweilu

紫荆币充值界面及接口

上级 0bfcbbe5
......@@ -309,4 +309,22 @@ abstract class MineAPI {
}
return false;
}
/// 19、紫荆币充值列表
///
static Future<List<CoinModel>> coinsRechargeList(
{
required String type,
}) async {
final result = await HttpService.to.post(
'/v1/orders/Orders/getRechargeConfig',
params: {
'config_type': type,
},
);
if (result.data is! Map && result.data['list'] is! List) return [];
return List.generate(result.data['list'].length, (index) {
return CoinModel.fromJson(result.data['list'][index]);
});
}
}
......@@ -612,3 +612,51 @@ class HelpCenterContentModel {
return map;
}
}
/// 紫荆币模型
class CoinModel {
CoinModel({
this.beanName,
this.beanValue,
this.priceName,
this.priceValue,
this.identifying,
this.selected = false,
});
CoinModel.fromJson(dynamic json) {
beanName = json['bean_name'];
beanValue = json['bean_value'];
priceName = json['price_name'];
priceValue = json['price_value'];
identifying = json['identifying'];
selected = false;
}
String? beanName;
String? beanValue;
String? priceName;
String? priceValue;
String? identifying;
late bool selected;
CoinModel copyWith({ String? beanName,
String? beanValue,
String? priceName,
String? priceValue,
String? identifying,
}) => CoinModel( beanName: beanName ?? this.beanName,
beanValue: beanValue ?? this.beanValue,
priceName: priceName ?? this.priceName,
priceValue: priceValue ?? this.priceValue,
identifying: identifying ?? this.identifying,
);
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['bean_name'] = beanName;
map['bean_value'] = beanValue;
map['price_name'] = priceName;
map['price_value'] = priceValue;
map['identifying'] = identifying;
return map;
}
}
......@@ -7,12 +7,22 @@ class CoinRechargeController extends GetxController {
PayModel(type: 1, name: '微信', icon: 'assets/images/pay_wechat.png', selected: true),
PayModel(type: 2, name: '支付宝', icon: 'assets/images/pay_ali.png', selected: false),
];
List<CoinModel> data = [];
late CoinModel rechargeModel = CoinModel();
// 支付方式
late PayModel _payModel = pays.first;
PayModel get payModel => _payModel;
@override
void onReady() {
_getlist();
super.onReady();
}
void setPayModel(PayModel payModel){
for (PayModel model in pays) {
if (model.type == payModel.type){
......@@ -25,4 +35,29 @@ class CoinRechargeController extends GetxController {
}
update();
}
void choose(CoinModel coinModel){
for (CoinModel model in data) {
model.selected = (model == coinModel);
}
rechargeModel = coinModel;
update();
}
void _getlist()async{
String type = '';
if(Platform.isIOS){
type = 'ios';
}
if(Platform.isAndroid){
type = 'android';
}
final result = await MineAPI.coinsRechargeList(type: type);
data = result;
update();
}
}
\ No newline at end of file
......@@ -2,9 +2,13 @@ library recharge;
import 'package:flutter/material.dart';
import 'package:flutter_book/apis/index.dart';
import 'package:flutter_book/models/index.dart';
import 'package:flutter_book/theme.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_state_manager/src/simple/get_controllers.dart';
import 'package:go_router/go_router.dart';
import '../../models/shop.dart';
import '../../utils/index.dart';
......
......@@ -14,74 +14,76 @@ class _CoinRechargePageState extends State<CoinRechargePage> {
Widget build(BuildContext context) {
return GetBuilder<CoinRechargeController>(
init: CoinRechargeController(),
builder:(controller) => Container(
// height: 100,
// color: Colors.amberAccent,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: EdgeInsets.symmetric(vertical: 17),
width: double.infinity,
margin: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Container(
color: Colors.red,
child:Stack(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('紫荆币充值',textAlign:TextAlign.center),
],
),
Positioned(
right: 0,
top: 0,
child: Container(
width: 20,
height: 20,
color: Colors.green,
builder:(controller) => Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
color: Colors.white,
padding: EdgeInsets.symmetric(vertical: 17.w),
width: double.infinity,
margin: EdgeInsets.fromLTRB(10.w, 0.w, 10.w, 0.w),
child: Container(
// color: Colors.red,
child:Stack(
children: [
const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('紫荆币充值',textAlign:TextAlign.center),
],
),
Positioned(
right: 0.w,
top: 0.w,
child: GestureDetector(
onTap: (){
context.pop();
},
child: SizedBox(
width: 20.w,
height: 20.w,
child: Image.asset('assets/images/close.png'),
),
)
],
)
),
),
Container(
margin: EdgeInsets.symmetric(horizontal: 20),
child: _buildAudioGridView()
),
)
],
)
),
Gaps.vGaps15,
_buildListView(controller),
Gaps.vGaps15,
Container(
margin: EdgeInsets.symmetric(horizontal:15),
child: CustomGradientButton(
text: '立即充值',
isEnabled: true,
onPressed: () {
// context.goNamed(Routes.login);
},
),
),
Container(
margin: EdgeInsets.symmetric(horizontal: 20.w),
child: _buildAudioGridView(controller)
),
Gaps.vGaps15,
_buildListView(controller),
Gaps.vGaps15,
Container(
margin: EdgeInsets.symmetric(horizontal:15.w),
child: CustomGradientButton(
text: '立即充值${controller.rechargeModel.priceName??''}',
isEnabled: true,
onPressed: () {
// context.goNamed(Routes.login);
},
),
Gaps.vGaps15,
RichText(text: TextSpan(
children: [
TextSpan(text: '充值即代表同意',style: TextStyle(fontSize: 13.w,height: 1.5,color: Colours.c9)),
TextSpan(text: '《用户充值协议》',style: TextStyle(fontSize: 13.w,height: 1.5,color: Color(0xFF2A82D9))),
]
)),
Gaps.vGaps15
],
),
),
Gaps.vGaps15,
RichText(text: TextSpan(
children: [
TextSpan(text: '充值即代表同意',style: TextStyle(fontSize: 13.w,height: 1.5,color: Colours.c9)),
TextSpan(text: '《用户充值协议》',style: TextStyle(fontSize: 13.w,height: 1.5,color: Color(0xFF2A82D9))),
]
)),
Gaps.vGaps15
],
),
);
}
Widget _buildAudioGridView(){
Widget _buildAudioGridView(CoinRechargeController controller){
return GridView.builder(
// padding: const EdgeInsets.only(left: 13,top: 10),
physics: NeverScrollableScrollPhysics(),
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
......@@ -90,23 +92,29 @@ class _CoinRechargePageState extends State<CoinRechargePage> {
childAspectRatio: 2
),
itemBuilder: (BuildContext context, int index) {
return Container(
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(8.w),
border: Border.all(width: 0.5.w,color: Color(0xFFDADADA))
),
CoinModel model = controller.data[index];
return GestureDetector(
onTap: (){
controller.choose(model);
},
child: Container(
decoration: BoxDecoration(
color: model.selected?AppTheme.primary.withOpacity(0.1):Colors.white,
borderRadius: BorderRadius.circular(8.w),
border: Border.all(width: 0.5.w,color: model.selected?AppTheme.primary:const Color(0xFFDADADA))
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('42紫荆币',style: TextStyle(color: Colours.c3,fontSize: 14,height: 1.5),),
Text('6元',style: TextStyle(color: Colours.c9,fontSize: 11,height: 1.5),),
],
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(model.beanName??'',style: TextStyle(color: model.selected?AppTheme.primary:Colours.c3,fontSize: 14.w,height: 1.5),),
Text(model.priceName??'',style: TextStyle(color: model.selected?AppTheme.primary:Colours.c9,fontSize: 11.w,height: 1.5),),
],
),
),
);
},
itemCount: 6,
itemCount: controller.data.length,
);
}
Widget _buildListView(CoinRechargeController controller){
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论