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

紫荆币充值界面及接口

上级 0bfcbbe5
...@@ -309,4 +309,22 @@ abstract class MineAPI { ...@@ -309,4 +309,22 @@ abstract class MineAPI {
} }
return false; 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 { ...@@ -612,3 +612,51 @@ class HelpCenterContentModel {
return map; 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 { ...@@ -7,12 +7,22 @@ class CoinRechargeController extends GetxController {
PayModel(type: 1, name: '微信', icon: 'assets/images/pay_wechat.png', selected: true), PayModel(type: 1, name: '微信', icon: 'assets/images/pay_wechat.png', selected: true),
PayModel(type: 2, name: '支付宝', icon: 'assets/images/pay_ali.png', selected: false), PayModel(type: 2, name: '支付宝', icon: 'assets/images/pay_ali.png', selected: false),
]; ];
List<CoinModel> data = [];
late CoinModel rechargeModel = CoinModel();
// 支付方式 // 支付方式
late PayModel _payModel = pays.first; late PayModel _payModel = pays.first;
PayModel get payModel => _payModel; PayModel get payModel => _payModel;
@override
void onReady() {
_getlist();
super.onReady();
}
void setPayModel(PayModel payModel){ void setPayModel(PayModel payModel){
for (PayModel model in pays) { for (PayModel model in pays) {
if (model.type == payModel.type){ if (model.type == payModel.type){
...@@ -25,4 +35,29 @@ class CoinRechargeController extends GetxController { ...@@ -25,4 +35,29 @@ class CoinRechargeController extends GetxController {
} }
update(); 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; ...@@ -2,9 +2,13 @@ library recharge;
import 'package:flutter/material.dart'; 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:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:get/get_state_manager/src/simple/get_controllers.dart'; import 'package:get/get_state_manager/src/simple/get_controllers.dart';
import 'package:go_router/go_router.dart';
import '../../models/shop.dart'; import '../../models/shop.dart';
import '../../utils/index.dart'; import '../../utils/index.dart';
......
...@@ -14,33 +14,36 @@ class _CoinRechargePageState extends State<CoinRechargePage> { ...@@ -14,33 +14,36 @@ class _CoinRechargePageState extends State<CoinRechargePage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GetBuilder<CoinRechargeController>( return GetBuilder<CoinRechargeController>(
init: CoinRechargeController(), init: CoinRechargeController(),
builder:(controller) => Container( builder:(controller) => Column(
// height: 100,
// color: Colors.amberAccent,
child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Container( Container(
padding: EdgeInsets.symmetric(vertical: 17), color: Colors.white,
padding: EdgeInsets.symmetric(vertical: 17.w),
width: double.infinity, width: double.infinity,
margin: EdgeInsets.fromLTRB(10, 10, 10, 0), margin: EdgeInsets.fromLTRB(10.w, 0.w, 10.w, 0.w),
child: Container( child: Container(
color: Colors.red, // color: Colors.red,
child:Stack( child:Stack(
children: [ children: [
Row( const Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Text('紫荆币充值',textAlign:TextAlign.center), Text('紫荆币充值',textAlign:TextAlign.center),
], ],
), ),
Positioned( Positioned(
right: 0, right: 0.w,
top: 0, top: 0.w,
child: Container( child: GestureDetector(
width: 20, onTap: (){
height: 20, context.pop();
color: Colors.green, },
child: SizedBox(
width: 20.w,
height: 20.w,
child: Image.asset('assets/images/close.png'),
),
), ),
) )
], ],
...@@ -48,16 +51,16 @@ class _CoinRechargePageState extends State<CoinRechargePage> { ...@@ -48,16 +51,16 @@ class _CoinRechargePageState extends State<CoinRechargePage> {
), ),
), ),
Container( Container(
margin: EdgeInsets.symmetric(horizontal: 20), margin: EdgeInsets.symmetric(horizontal: 20.w),
child: _buildAudioGridView() child: _buildAudioGridView(controller)
), ),
Gaps.vGaps15, Gaps.vGaps15,
_buildListView(controller), _buildListView(controller),
Gaps.vGaps15, Gaps.vGaps15,
Container( Container(
margin: EdgeInsets.symmetric(horizontal:15), margin: EdgeInsets.symmetric(horizontal:15.w),
child: CustomGradientButton( child: CustomGradientButton(
text: '立即充值', text: '立即充值${controller.rechargeModel.priceName??''}',
isEnabled: true, isEnabled: true,
onPressed: () { onPressed: () {
// context.goNamed(Routes.login); // context.goNamed(Routes.login);
...@@ -74,14 +77,13 @@ class _CoinRechargePageState extends State<CoinRechargePage> { ...@@ -74,14 +77,13 @@ class _CoinRechargePageState extends State<CoinRechargePage> {
Gaps.vGaps15 Gaps.vGaps15
], ],
), ),
),
); );
} }
Widget _buildAudioGridView(){ Widget _buildAudioGridView(CoinRechargeController controller){
return GridView.builder( return GridView.builder(
// padding: const EdgeInsets.only(left: 13,top: 10), // padding: const EdgeInsets.only(left: 13,top: 10),
physics: NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true, shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3, crossAxisCount: 3,
...@@ -90,23 +92,29 @@ class _CoinRechargePageState extends State<CoinRechargePage> { ...@@ -90,23 +92,29 @@ class _CoinRechargePageState extends State<CoinRechargePage> {
childAspectRatio: 2 childAspectRatio: 2
), ),
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return Container( CoinModel model = controller.data[index];
return GestureDetector(
onTap: (){
controller.choose(model);
},
child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.red, color: model.selected?AppTheme.primary.withOpacity(0.1):Colors.white,
borderRadius: BorderRadius.circular(8.w), borderRadius: BorderRadius.circular(8.w),
border: Border.all(width: 0.5.w,color: Color(0xFFDADADA)) border: Border.all(width: 0.5.w,color: model.selected?AppTheme.primary:const Color(0xFFDADADA))
), ),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Text('42紫荆币',style: TextStyle(color: Colours.c3,fontSize: 14,height: 1.5),), Text(model.beanName??'',style: TextStyle(color: model.selected?AppTheme.primary:Colours.c3,fontSize: 14.w,height: 1.5),),
Text('6元',style: TextStyle(color: Colours.c9,fontSize: 11,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){ Widget _buildListView(CoinRechargeController controller){
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论