balance_history.dart 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import 'package:fast/constants.dart';
  2. import 'package:fast/model/model.dart';
  3. import 'package:fast/utils/api.dart';
  4. import 'package:fast/utils/http_utils.dart';
  5. import 'package:fast/utils/size_fit.dart';
  6. import 'package:fast/view/component/navi_bar.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:get/get.dart';
  9. class BalanceHistory extends StatefulWidget {
  10. int type; //0 全部 1 充值
  11. BalanceHistory({Key? key, required this.type}) : super(key: key);
  12. @override
  13. State<BalanceHistory> createState() => _BalanceHistoryState();
  14. }
  15. class _BalanceHistoryState extends State<BalanceHistory> {
  16. List<HistoryBean> list = [];
  17. bool loaded = false;
  18. @override
  19. void initState() {
  20. getList();
  21. super.initState();
  22. }
  23. Future getList() async {
  24. Map<String, dynamic> data = await HttpUtils.get(Api.stoneRecords, params: {
  25. 'page_num': 1,
  26. 'page_size': 100,
  27. 'trans_type': widget.type == 1 ? 'RECHARGE' : 'ALL'
  28. });
  29. List<dynamic> datas = data['data'];
  30. List<HistoryBean> array = [];
  31. for (var item in datas) {
  32. array.add(HistoryBean.fromJson(item));
  33. }
  34. setState(() {
  35. loaded = true;
  36. list = array;
  37. });
  38. }
  39. @override
  40. Widget build(BuildContext context) {
  41. SizeFit.initialize(context);
  42. EdgeInsets safePadding = MediaQuery.of(context).padding;
  43. double screenHeight = MediaQuery.of(context).size.height;
  44. return Material(
  45. child: Container(
  46. padding: EdgeInsets.only(top: 0, bottom: safePadding.bottom),
  47. color: kBgColor,
  48. child: Stack(
  49. children: [
  50. if (loaded && list.isEmpty)
  51. Container(
  52. width: 375.px,
  53. height: screenHeight,
  54. alignment: Alignment.center,
  55. child: Column(
  56. mainAxisAlignment: MainAxisAlignment.center,
  57. children: [
  58. Image.asset('assets/images/no_content.png',width: 88.px,height: 80.px,),
  59. SizedBox(height: 16.px,),
  60. Text(widget.type==0?'您还没有逆龄石相关记录':'您还没有逆龄石充值记录',style: TextStyle(color:const Color(0x66C4CCDA),fontSize: 14.px,fontWeight: FontWeight.bold ),)
  61. ],
  62. ),
  63. ),
  64. SizedBox(
  65. height: screenHeight,
  66. child: SingleChildScrollView(
  67. child: Column(children: [
  68. SizedBox(
  69. height: 40.px + safePadding.top,
  70. ),
  71. ...List<Widget>.generate(list.length, (i) {
  72. return item(list[i]);
  73. })
  74. ]))),
  75. NaviBar(
  76. title: widget.type == 0 ? '逆龄石记录' : '充值记录',
  77. closeCallback: () {
  78. Get.back();
  79. })
  80. ],
  81. )));
  82. }
  83. Widget item(HistoryBean bean) {
  84. return Column(
  85. mainAxisAlignment: MainAxisAlignment.start,
  86. crossAxisAlignment: CrossAxisAlignment.start,
  87. children: [
  88. SizedBox(
  89. height: 12.px,
  90. ),
  91. Row(
  92. crossAxisAlignment: CrossAxisAlignment.center,
  93. children: [
  94. SizedBox(
  95. width: 24.px,
  96. ),
  97. Container(
  98. margin: EdgeInsets.only(bottom: 2.px),
  99. child: Text(
  100. bean.stone > 0
  101. ? '+' + bean.stone.toString()
  102. : bean.stone.toString(),
  103. style: TextStyle(
  104. color: kThemeColor,
  105. fontFamily: 'Exo2',
  106. fontWeight: FontWeight.w600,
  107. fontSize: 16.px),
  108. ),
  109. ),
  110. SizedBox(
  111. width: 6.px,
  112. ),
  113. Image.asset(
  114. 'assets/images/stone.png',
  115. width: 16.px,
  116. height: 16.px,
  117. ),
  118. SizedBox(
  119. width: 12.px,
  120. ),
  121. Text(
  122. formatTime(bean.dateTime!),
  123. style: TextStyle(color: const Color(0x80C4CCDA), fontSize: 12.px),
  124. )
  125. ],
  126. ),
  127. Container(
  128. margin: EdgeInsets.only(left: 24.px, top: 9.px),
  129. child: Text(
  130. bean.description,
  131. textAlign: TextAlign.left,
  132. style: TextStyle(
  133. color: Colors.white,
  134. fontSize: 14.px,
  135. ),
  136. ),
  137. ),
  138. Container(
  139. margin: EdgeInsets.only(top: 12.px, left: 24.px),
  140. height: 1.px,
  141. width: 328.px,
  142. color: const Color(0x1AC4CCDA),
  143. )
  144. ],
  145. );
  146. }
  147. formatTime(DateTime dateTime) {
  148. DateTime now = DateTime.now();
  149. int minutes = (now.millisecondsSinceEpoch ~/ 1000 -
  150. dateTime.millisecondsSinceEpoch ~/ 1000) ~/
  151. 60;
  152. if (minutes < 1) {
  153. return '刚刚';
  154. } else if (minutes <= 59) {
  155. return minutes.toString() + '分钟前';
  156. } else if (minutes <= 60 * 24 - 1) {
  157. return (minutes ~/ 60).toString() + '小时前';
  158. } else if (minutes <= 60 * 24 * 3 - 1) {
  159. return (minutes ~/ (60 * 24)).toString() + '天前';
  160. }
  161. return dateTime.year.toString() +
  162. '-' +
  163. dateTime.month.toString().padLeft(2, "0") +
  164. '-' +
  165. dateTime.day.toString().padLeft(2, "0");
  166. }
  167. }