import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:intl/intl.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:shimmer/shimmer.dart'; import '../../generated/l10n.dart'; import '../../retrofit/business_api.dart'; import '../../retrofit/data/base_data.dart'; import '../../retrofit/data/day_flow_list.dart'; import '../../utils/business_instance.dart'; import '../../utils/flutter_utils.dart'; import '../../view_widget/classic_header.dart'; import '../../view_widget/my_footer.dart'; import '../../view_widget/no_data_view.dart'; import '../date_select/date_picker.dart'; class FlowPage extends StatefulWidget { final arguments; FlowPage({this.arguments}); @override State createState() { return _FlowPage(); } } class _FlowPage extends State { final RefreshController refreshController = RefreshController(); String storeId; BusinessApiService businessService; List dayFlowList = []; int _loadCount = 0; String _datetime; String networkError = ""; int networkStatus = 0; @override void initState() { super.initState(); storeId = widget.arguments["storeId"]; _onRefresh(); } _onRefresh() async { EasyLoading.show( status: S.current.zhengzaijiazai, maskType: EasyLoadingMaskType.black); SharedPreferences.getInstance().then((value) { businessService = BusinessApiService(Dio(), context: context, token: BusinessInstance.instance.businessToken, tenant: BusinessInstance.instance.businessTenant, storeId: storeId); queryDayFlow( _datetime == null ? DateFormat("yyyy-MM-dd").format(DateTime.now()) : (_datetime + "-01"), "0", isSing: false); }); } addLoadCount() { _loadCount += 1; if (_loadCount == 1) { _loadCount = 0; EasyLoading.dismiss(); if (refreshController.isRefresh) refreshController.refreshCompleted(); if (mounted) setState(() {}); } } ///今日流水/isMonth=0(当月数据),isMonth=1(当日数据) queryDayFlow(yearMonth, isMonth, {isSing = true}) async { if (isSing) EasyLoading.show( status: S.current.zhengzaijiazai, maskType: EasyLoadingMaskType.black); try { BaseData> baseData = await businessService.dayFlow(yearMonth, isMonth).catchError((error) { networkStatus = -1; networkError = AppUtils.dioErrorTypeToString(error.type); }); if (baseData != null && baseData.isSuccess) { if (isMonth == "0") { dayFlowList = baseData.data; } else { dayFlowList .firstWhere((element) => element.localDate == yearMonth) .detailList = baseData.data; } networkStatus = 1; } } finally { if (isSing) { setState(() {}); EasyLoading.dismiss(); } else { addLoadCount(); } } } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Color(0xFFF8F8FA), appBar: MyAppBar( title: widget.arguments["storeName"], titleColor: Colors.black, background: Colors.white, leadingColor: Colors.black, brightness: Brightness.dark, ), body: networkStatus == -1 ? noNetwork():SmartRefresher( controller: refreshController, enablePullDown: true, enablePullUp: false, header: MyHeader( color: Color(0xFF30415B), ), footer: CustomFooter( builder: (context, mode) { return MyFooter(mode); }, ), onRefresh: _onRefresh, physics: BouncingScrollPhysics(), scrollController: ScrollController(), child: SingleChildScrollView( physics: BouncingScrollPhysics(), child: Container( margin: EdgeInsets.only(top: 24.h, left: 16.w, right: 16.w), child: Column( children: [ GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { showDateSelector(); }, child: Row( children: [ Text( _datetime == null ? DateFormat("yyyy年MM月").format(DateTime.now()) : "${_datetime.replaceAll("-", "年")}月", style: TextStyle( fontSize: 15.sp, fontWeight: MyFontWeight.semi_bold, color: Color(0xFF0D0D0D), ), ), Icon( Icons.keyboard_arrow_down, color: Color(0xFF0D0D0D), size: 24, ), ], ), ), SizedBox( height: 16.h, ), if(networkStatus == 1) (dayFlowList == null || dayFlowList.length == 0) ? NoDataView( src: "assets/image/bs_no data_logo.webp", isShowBtn: false, text: "暂无数据", fontSize: 16.sp, margin: EdgeInsets.all(20.h), ) : ListView.builder( padding: EdgeInsets.zero, itemCount: dayFlowList?.length ?? 0, scrollDirection: Axis.vertical, shrinkWrap: true, physics: BouncingScrollPhysics(), itemBuilder: (context, position) { return GestureDetector( onTap: () {}, child: billItem(dayFlowList[position]), ); }, ), if(networkStatus == 0) ListView.builder( padding: EdgeInsets.zero, itemCount: 10, scrollDirection: Axis.vertical, shrinkWrap: true, physics: BouncingScrollPhysics(), itemBuilder: (context, position) { return billItemSm(); }, ) ], ), ), ), ), ); } ///月份账单大概 Widget billItem(DayFlowList dayFlowList) { return Container( padding: EdgeInsets.all(12.h), margin: EdgeInsets.only(bottom: 12.h), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(8.w), ), child: Column( children: [ GestureDetector( onTap: () { if (dayFlowList.detailList != null) { setState(() { dayFlowList.detailList = null; }); } else { queryDayFlow(dayFlowList?.localDate ?? "", "1"); } }, child: Row( children: [ Expanded( child: Text( dayFlowList?.localDate ?? "", style: TextStyle( fontSize: 18.sp, fontWeight: MyFontWeight.medium, color: Color(0xFF0D0D0D), ), )), Icon( dayFlowList.detailList == null ? Icons.keyboard_arrow_up : Icons.keyboard_arrow_down, color: Color(0xFF0D0D0D), size: 24, ), ], ), ), SizedBox( height: 15.h, ), Row( children: [ Expanded( child: Text( "交易金额 ${dayFlowList?.amount ?? ""}元", style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.regular, color: Color(0xFF1A1A1A), ), )), Text( "共${(dayFlowList?.count ?? 0).toString()}笔", style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.regular, color: Color(0xFF1A1A1A), ), ) ], ), SizedBox( height: 20.h, ), if (dayFlowList.detailList != null) Column( children: dayFlowList.detailList.map((e) { return billIDetailsItem(e); }).toList(), ) ], ), ); } Widget billItemSm() { return Container( margin: EdgeInsets.only(bottom: 12.h), padding: EdgeInsets.all(12), width: double.infinity, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(6), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Shimmer.fromColors( baseColor: Color(0XFFD8D8D8), highlightColor: Color(0XFFD8D8D8), child: Container( decoration: BoxDecoration( color: Color(0XFFD8D8D8), borderRadius: BorderRadius.circular(2), ), width: 50.w, height: 20.h, ), ), Spacer(), Icon( Icons.keyboard_arrow_down, color: Color(0xFF0D0D0D), size: 24, ), ], ), Padding( padding: EdgeInsets.only( top: 16.h, ), child: Row( children: [ Shimmer.fromColors( baseColor: Color(0XFFD8D8D8), highlightColor: Color(0XFFD8D8D8), child: Container( decoration: BoxDecoration( color: Color(0XFFD8D8D8), borderRadius: BorderRadius.circular(2), ), width: 114.w, height: 20.h, ), ), Spacer(), Shimmer.fromColors( baseColor: Color(0XFFD8D8D8), highlightColor: Color(0XFFD8D8D8), child: Container( decoration: BoxDecoration( color: Color(0XFFD8D8D8), borderRadius: BorderRadius.circular(2), ), width: 38.w, height: 20.h, ), ), ], )) ], ), ); } ///月份账单明细 Widget billIDetailsItem(DayFlowList detailList) { return Container( margin: EdgeInsets.only(bottom: 20.h), child: Row( children: [ Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: EdgeInsets.only(bottom: 15.h), child: Text( detailList?.localDateTime ?? "", style: TextStyle( fontSize: 14.sp, fontWeight: MyFontWeight.regular, color: Color(0xFF1A1A1A), ), ), ), Text( detailList?.nickname ?? AppUtils.phoneEncode(detailList?.phone) ?? detailList?.storeName ?? "", style: TextStyle( fontSize: 14.sp, fontWeight: MyFontWeight.regular, color: Color(0xFF1A1A1A), ), ), ], ), ), Text.rich( TextSpan( children: [ TextSpan( text: (detailList?.amount != "0.00") ? "+" : "-", style: TextStyle( fontSize: 18.sp, fontWeight: MyFontWeight.medium, color: Color(0xFF0D0D0D), ), ), TextSpan( text: (detailList?.amount != "0.00") ? (detailList?.amount ?? "") : (detailList?.refundAmount ?? ""), style: TextStyle( fontSize: 18.sp, fontWeight: MyFontWeight.medium, color: Color(0xFF0D0D0D), ), ), ], ), ), ], )); } showDateSelector() async { String dateTime = await showModalBottomSheet( backgroundColor: Colors.transparent, context: context, builder: (_) { return DatePickerWidget(); }); if (dateTime != null) { _datetime = dateTime; queryDayFlow(_datetime + "-01", "0"); } } Widget noNetwork() { return Container( color: Colors.white, width: double.infinity, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( networkError.substring(0, networkError.indexOf(",")), style: TextStyle( fontSize: 14.sp, color: Color(0xFF0D0D0D), fontWeight: MyFontWeight.bold), ), Padding( padding: EdgeInsets.symmetric(vertical: 10.h), child: Text( "请检查网络设置或稍后重试", style: TextStyle( fontSize: 12.sp, color: Color(0xFF7A797F), fontWeight: MyFontWeight.regular), ), ), GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { _onRefresh(); }, child: Container( decoration: BoxDecoration( color: Color(0xFF30415B), borderRadius: BorderRadius.circular(15), ), padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 3.h), child: Text( "重试", style: TextStyle( fontSize: 14.sp, color: Colors.white, fontWeight: MyFontWeight.regular), )), ) ], ), ); } }