| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- import 'package:fast/constants.dart';
- import 'package:fast/model/model.dart';
- import 'package:fast/utils/api.dart';
- import 'package:fast/utils/http_utils.dart';
- import 'package:fast/utils/size_fit.dart';
- import 'package:fast/view/component/navi_bar.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- class BalanceHistory extends StatefulWidget {
- int type; //0 全部 1 充值
- BalanceHistory({Key? key, required this.type}) : super(key: key);
- @override
- State<BalanceHistory> createState() => _BalanceHistoryState();
- }
- class _BalanceHistoryState extends State<BalanceHistory> {
- List<HistoryBean> list = [];
- bool loaded = false;
- @override
- void initState() {
- getList();
- super.initState();
- }
- Future getList() async {
- Map<String, dynamic> data = await HttpUtils.get(Api.stoneRecords, params: {
- 'page_num': 1,
- 'page_size': 100,
- 'trans_type': widget.type == 1 ? 'RECHARGE' : 'ALL'
- });
- List<dynamic> datas = data['data'];
- List<HistoryBean> array = [];
- for (var item in datas) {
- array.add(HistoryBean.fromJson(item));
- }
- setState(() {
- loaded = true;
- list = array;
- });
- }
- @override
- Widget build(BuildContext context) {
- SizeFit.initialize(context);
- EdgeInsets safePadding = MediaQuery.of(context).padding;
- double screenHeight = MediaQuery.of(context).size.height;
- return Material(
- child: Container(
- padding: EdgeInsets.only(top: 0, bottom: safePadding.bottom),
- color: kBgColor,
- child: Stack(
- children: [
- if (loaded && list.isEmpty)
- Container(
- width: 375.px,
- height: screenHeight,
- alignment: Alignment.center,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Image.asset('assets/images/no_content.png',width: 88.px,height: 80.px,),
- SizedBox(height: 16.px,),
- Text(widget.type==0?'您还没有逆龄石相关记录':'您还没有逆龄石充值记录',style: TextStyle(color:const Color(0x66C4CCDA),fontSize: 14.px,fontWeight: FontWeight.bold ),)
- ],
- ),
- ),
- SizedBox(
- height: screenHeight,
- child: SingleChildScrollView(
- child: Column(children: [
- SizedBox(
- height: 40.px + safePadding.top,
- ),
- ...List<Widget>.generate(list.length, (i) {
- return item(list[i]);
- })
- ]))),
- NaviBar(
- title: widget.type == 0 ? '逆龄石记录' : '充值记录',
- closeCallback: () {
- Get.back();
- })
- ],
- )));
- }
- Widget item(HistoryBean bean) {
- return Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- SizedBox(
- height: 12.px,
- ),
- Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- SizedBox(
- width: 24.px,
- ),
- Container(
- margin: EdgeInsets.only(bottom: 2.px),
- child: Text(
- bean.stone > 0
- ? '+' + bean.stone.toString()
- : bean.stone.toString(),
- style: TextStyle(
- color: kThemeColor,
- fontFamily: 'Exo2',
- fontWeight: FontWeight.w600,
- fontSize: 16.px),
- ),
- ),
- SizedBox(
- width: 6.px,
- ),
- Image.asset(
- 'assets/images/stone.png',
- width: 16.px,
- height: 16.px,
- ),
- SizedBox(
- width: 12.px,
- ),
- Text(
- formatTime(bean.dateTime!),
- style: TextStyle(color: const Color(0x80C4CCDA), fontSize: 12.px),
- )
- ],
- ),
- Container(
- margin: EdgeInsets.only(left: 24.px, top: 9.px),
- child: Text(
- bean.description,
- textAlign: TextAlign.left,
- style: TextStyle(
- color: Colors.white,
- fontSize: 14.px,
- ),
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 12.px, left: 24.px),
- height: 1.px,
- width: 328.px,
- color: const Color(0x1AC4CCDA),
- )
- ],
- );
- }
- formatTime(DateTime dateTime) {
- DateTime now = DateTime.now();
- int minutes = (now.millisecondsSinceEpoch ~/ 1000 -
- dateTime.millisecondsSinceEpoch ~/ 1000) ~/
- 60;
- if (minutes < 1) {
- return '刚刚';
- } else if (minutes <= 59) {
- return minutes.toString() + '分钟前';
- } else if (minutes <= 60 * 24 - 1) {
- return (minutes ~/ 60).toString() + '小时前';
- } else if (minutes <= 60 * 24 * 3 - 1) {
- return (minutes ~/ (60 * 24)).toString() + '天前';
- }
- return dateTime.year.toString() +
- '-' +
- dateTime.month.toString().padLeft(2, "0") +
- '-' +
- dateTime.day.toString().padLeft(2, "0");
- }
- }
|