172 lines
6.4 KiB
Dart
Raw Normal View History

2025-09-18 16:13:37 +08:00
// 钱包页面
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
2025-09-22 14:41:47 +08:00
import 'package:loopin/IM/controller/im_user_info_controller.dart';
2025-09-18 16:13:37 +08:00
import 'package:loopin/behavior/custom_scroll_behavior.dart';
2025-09-22 14:41:47 +08:00
import 'package:loopin/components/empty_tip.dart';
2025-09-18 16:13:37 +08:00
import 'package:loopin/pages/my/merchant/balance/controller.dart';
2025-09-22 14:41:47 +08:00
import 'package:loopin/utils/index.dart';
2025-09-18 16:13:37 +08:00
class Balance extends StatefulWidget {
const Balance({super.key});
@override
State<Balance> createState() => _BalanceState();
}
class _BalanceState extends State<Balance> {
2025-09-22 14:41:47 +08:00
final controller = Get.find<BalanceController>();
@override
void dispose() {
Get.delete<BalanceController>();
super.dispose();
}
2025-09-18 16:13:37 +08:00
@override
Widget build(BuildContext context) {
return Scaffold(
2025-09-22 14:41:47 +08:00
appBar: AppBar(title: Text("我的余额")),
2025-09-18 16:13:37 +08:00
body: ScrollConfiguration(
behavior: CustomScrollBehavior().copyWith(scrollbars: false),
child: Column(
children: [
// 上半部分:余额 + 充值
Container(
padding: const EdgeInsets.all(16),
color: Colors.blueAccent,
width: double.infinity,
child: Obx(() {
2025-09-22 14:41:47 +08:00
final ctl = Get.find<ImUserInfoController>();
final role = ctl.role.value;
final isLeader = Utils.hasRole(role, 5);
2025-09-18 16:13:37 +08:00
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"钱包余额",
style: TextStyle(color: Colors.white, fontSize: 16),
),
const SizedBox(height: 8),
Text(
"¥ ${controller.balance.value.toStringAsFixed(2)}",
style: const TextStyle(
color: Colors.white,
fontSize: 28,
fontWeight: FontWeight.bold,
),
),
2025-09-22 14:41:47 +08:00
// if (isLeader) const SizedBox(height: 12),
Row(
children: [
ElevatedButton(
onPressed: () {
// 加充值
controller.recharge(money: '0.1');
// http
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.orange,
),
child: const Text("充值"),
),
SizedBox(width: 20),
//
ElevatedButton(
onPressed: () {
// 提现
// controller.recharge(money: '0.1');
controller.withDraw(money: '1000');
// http
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.orange,
),
child: const Text("提现"),
),
],
2025-09-18 16:13:37 +08:00
),
],
);
}),
),
// 下半部分:流水记录分页列表
Expanded(
2025-09-22 14:41:47 +08:00
child: EasyRefresh.builder(
callLoadOverOffset: 20, //触底距离
callRefreshOverOffset: 20, // 下拉距离
header: ClassicHeader(
dragText: '下拉刷新',
armedText: '释放刷新',
readyText: '加载中...',
processingText: '加载中...',
processedText: '加载完成',
failedText: '加载失败,请重试',
messageText: '最后更新于 %T',
),
footer: ClassicFooter(
dragText: '加载更多',
armedText: '释放加载',
readyText: '加载中...',
processingText: '加载中...',
processedText: '加载完成',
noMoreText: '没有更多了~',
failedText: '加载失败,请重试',
messageText: '最后更新于 %T',
),
2025-09-18 16:13:37 +08:00
2025-09-22 14:41:47 +08:00
onRefresh: () async {
await controller.getData(reset: true);
},
onLoad: () async {
if (controller.hasMore.value) {
await controller.getData();
return controller.hasMore.value ? IndicatorResult.success : IndicatorResult.noMore;
}
},
childBuilder: (context, physics) {
return Obx(
() {
// 数据加载中
if (controller.isLoading.value && controller.data.isEmpty) {
return Center(
child: CircularProgressIndicator(),
2025-09-18 16:13:37 +08:00
);
2025-09-22 14:41:47 +08:00
}
//空
if (controller.data.isEmpty) {
return EmptyTip();
}
return ListView.builder(
physics: physics,
itemCount: controller.data.length,
itemBuilder: (context, index) {
final tx = controller.data[index];
return ListTile(
title: Text(tx.source),
subtitle: Text(tx.createTime),
trailing: Text(
"变动金额:${tx.changeType == 1 ? '+' : '-'}${tx.changeAmount}${tx.id}", // 变动金额
style: TextStyle(
fontWeight: FontWeight.bold,
color: tx.changeType == 1 ? Colors.green : Colors.red,
),
),
);
},
);
},
);
},
),
2025-09-18 16:13:37 +08:00
),
],
),
),
);
}
}