FondleTalk/lib/tools/shop/account_page.dart
2024-09-02 14:11:51 +08:00

332 lines
11 KiB
Dart

import 'dart:async';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:talk/common/EventBusUtil.dart';
import 'package:talk/tools/shop/shop_model.dart';
import 'package:talk/tools/shop/transaction_page.dart';
import '../../beans/account_bean.dart';
import '../../beans/create_order_bean.dart';
import '../../beans/transaction_records_bean.dart';
import '../../common/Global.dart';
import '../../common/func.dart';
import '../../dialog/payment_method_dialog.dart';
import '../me/agreement_page.dart';
///货币
class AccountPage extends StatefulWidget {
const AccountPage({super.key});
@override
State<AccountPage> createState() => _AccountPageState();
}
class _AccountPageState extends State<AccountPage> {
List dataList = [1, 2, 3, 4, 5, 6];
late StreamSubscription subscription;
final ShopModel _viewmodel = ShopModel();
late AccountBean accountBean;
List<TransactionRecordsBean> recordList = [];
StreamSubscription<PaySuccess>? _paySuccess;
@override
void initState() {
// TODO: implement initState
super.initState();
//支付完成
_paySuccess = EventBusUtil.listen((event) {
_viewmodel.getOrderRewardsInfo();
});
subscription = _viewmodel.streamController.stream.listen((newData) {
String code = newData['code'];
if (code.isNotEmpty) {
switch (code) {
case "getMyAccount":
accountBean = newData['data'];
// EasyLoading.dismiss();
break;
case "getTransactionRecords":
recordList = newData['data'];
break;
case "createOrderWx": //微信支付
CreateOrderBean createOrderBean = newData['data'];
Map<String, dynamic> map = {
"orderInfoWx": createOrderBean.payment,
};
invokeNativeMethod("WxPay", map);
break;
case "createOrderZfb": //支付宝支付
CreateOrderBean createOrderBean = newData['data'];
Map<String, dynamic> map = {
"orderInfoZfb": createOrderBean.payment,
};
invokeNativeMethod("Alipay", map);
break;
case "getOrderRewardsInfo": //获取订单状态
loadData();
EasyLoading.showToast(newData['data']);
break;
default:
EasyLoading.dismiss();
EasyLoading.showToast(newData['data']);
break;
}
setState(() {});
}
});
// EasyLoading.show(status: 'loading...');
loadData();
}
loadData() {
_viewmodel.getMyAccount();
_viewmodel.getTransactionRecords();
}
@override
void dispose() {
// TODO: implement dispose
subscription.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
final w45 = size.width / 8;
final t39 = size.width / 9.230769230769231;
final h35 = size.width / 10.28571428571429;
return Scaffold(
backgroundColor: Color(0xFF121213),
appBar: AppBar(
backgroundColor: Color(0xFF121213),
scrolledUnderElevation: 0.0,
title: Text(
'我的账户',
style: TextStyle(fontSize: 16, color: Colors.white),
),
centerTitle: true,
leading: IconButton(
iconSize: 18,
icon: Icon(Icons.arrow_back_ios_sharp),
color: Colors.white,
onPressed: () {
// 处理返回操作
Navigator.pop(context);
},
),
),
body: SingleChildScrollView(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Image(
width: w45,
image: AssetImage('assets/images/ic_pearl.png'),
),
Container(
alignment: Alignment.center,
margin: EdgeInsets.only(top: 13),
child: Text(
'${accountBean.currency}',
style: TextStyle(fontSize: 24, color: Color(0xFFE1E1E1)),
),
),
Container(
alignment: Alignment.centerLeft,
margin: EdgeInsets.only(top: t39),
child: Text(
'账户充值',
style: TextStyle(fontSize: 13, color: Color(0xFFACACAC)),
),
),
Container(
margin: EdgeInsets.only(top: 16),
child: GridView.count(
shrinkWrap: true,
//水平子Widget之间间距
crossAxisSpacing: 17.0,
//垂直子Widget之间间距
mainAxisSpacing: 16.0,
//GridView内边距
padding: EdgeInsets.zero,
//一行的Widget数量
crossAxisCount: 2,
//子Widget宽高比例
childAspectRatio: 2.67,
//子Widget列表
children: _item(),
physics: NeverScrollableScrollPhysics(),
//类似 cellForRow 函数
scrollDirection: Axis.vertical),
),
Container(
margin: EdgeInsets.only(top: 14),
decoration: BoxDecoration(color: Color(0xFF2A2A2A), borderRadius: BorderRadius.all(Radius.circular(7))),
child: Column(
children: [
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
// Navigator.pushNamed(context, '/TransactionPage');
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TransactionPage(
recordList: recordList,
)));
},
child: SizedBox(
height: h35,
child: const Stack(
alignment: Alignment.center,
children: [
Positioned(
left: 21,
child: Text(
'交易记录',
style: TextStyle(color: Color(0xFF8E8E8E), fontSize: 12),
)),
Positioned(
right: 21,
child: Icon(
size: 10,
Icons.arrow_forward_ios_sharp,
color: Color(0xFF6E6E6E),
))
],
),
),
),
Container(
width: double.infinity,
height: 0.33,
margin: EdgeInsets.symmetric(horizontal: 21),
color: Color(0xFF3A3A3A),
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
// Navigator.pushNamed(context, '/ProblemPage');
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AgreementPage(
title: "常见问题",
url: "https://shhuanmeng.com/shangcheng.html",
)),
);
},
child: SizedBox(
height: h35,
child: const Stack(
alignment: Alignment.center,
children: [
Positioned(
left: 21,
child: Text(
'常见问题',
style: TextStyle(color: Color(0xFF8E8E8E), fontSize: 12),
)),
Positioned(
right: 35,
child: Text(
'充值须知、充值异常与帮助',
style: TextStyle(color: Color(0xFF8E8E8E), fontSize: 12),
)),
Positioned(
right: 21,
child: Icon(
size: 10,
Icons.arrow_forward_ios_sharp,
color: Color(0xFF6E6E6E),
)),
],
),
),
),
],
),
),
Container(
margin: EdgeInsets.only(top: 22),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"充值代表已阅读并同意",
style: TextStyle(fontSize: 10, color: Color(0xFF686868)),
),
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AgreementPage(
title: "常见问题",
url: "https://shhuanmeng.com/shangcheng.html",
)),
);
},
child: Text(
"《充值协议》",
style: TextStyle(fontSize: 10, color: Color(0xFF969696)),
),
),
],
),
),
],
),
),
),
);
}
_item() {
return accountBean.currencyRechargeList!.map((res) {
return Stack(
children: [
GestureDetector(
onTap: () {
FunctionUtil.bottomSheetDialog(context, PaymentMethodDialog(
onTap: (isWX) {
_viewmodel.createOrder(res.productId.toString(), isWX ? "wx" : "zfb");
},
));
},
child: CachedNetworkImage(
fit: BoxFit.cover,
imageUrl: res.imgUrl!,
errorWidget: (context, url, error) => const Icon(Icons.error),
),
),
],
);
}).toList();
}
// 获取原生的值
invokeNativeMethod(String method, Map<String, dynamic> map) async {
dynamic args;
try {
args = await Global.method.invokeMethod(method, map);
} on PlatformException catch (e) {}
}
}