You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

328 lines
10 KiB

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/my_appbar.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 '../../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 '../../view_widget/classic_header.dart';
import '../../view_widget/my_footer.dart';
class FlowPage extends StatefulWidget {
final arguments;
FlowPage({this.arguments});
@override
State<StatefulWidget> createState() {
return _FlowPage();
}
}
class _FlowPage extends State<FlowPage> {
final RefreshController refreshController = RefreshController();
String storeId;
BusinessApiService businessService;
List<DayFlowList> dayFlowList = [];
@override
void initState() {
super.initState();
storeId = widget.arguments["storeId"];
SharedPreferences.getInstance().then((value) {
businessService = BusinessApiService(Dio(),
context: context,
token: BusinessInstance.instance.businessToken,
tenant: BusinessInstance.instance.businessTenant,
storeId: storeId);
queryDayFlow("2023-09-04", "0");
});
}
///今日流水/isMonth=0(当月数据),isMonth=1(当日数据)
queryDayFlow(yearMonth, isMonth) async {
EasyLoading.show(
status: S.current.zhengzaijiazai, maskType: EasyLoadingMaskType.black);
try {
BaseData<List<DayFlowList>> baseData = await businessService
.dayFlow(
// "${DateFormat("yyyy-MM-dd").format(DateTime.now())}",
yearMonth,
isMonth)
.catchError((error) {});
if (baseData != null && baseData.isSuccess) {
if (isMonth == "0") {
dayFlowList = baseData.data;
} else {
dayFlowList
.firstWhere((element) => element.localDate == yearMonth)
.detailList = baseData.data.first.detailList;
}
setState(() {});
}
} finally {
EasyLoading.dismiss();
}
}
@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: SmartRefresher(
controller: refreshController,
enablePullDown: true,
enablePullUp: false,
header: MyHeader(
color: Colors.white,
),
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
},
),
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(
"2023年6月",
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,
),
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]),
);
},
)
],
),
),
),
),
);
}
///月份账单大概
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("2023-09-04", "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(),
)
// if (isShowMore)
// ListView.builder(
// padding: EdgeInsets.zero,
// itemCount: 5,
// scrollDirection: Axis.vertical,
// shrinkWrap: true,
// physics: BouncingScrollPhysics(),
// itemBuilder: (context, position) {
// return GestureDetector(
// onTap: () {},
// child: billIDetailsItem(),
// );
// },
// )
],
),
);
}
///月份账单明细
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?.phone ?? "",
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.regular,
color: Color(0xFF1A1A1A),
),
),
],
),
),
Text.rich(
TextSpan(
children: [
TextSpan(
text: "+",
style: TextStyle(
fontSize: 18.sp,
fontWeight: MyFontWeight.medium,
color: Color(0xFF0D0D0D),
),
),
TextSpan(
text: detailList?.amount ?? "",
style: TextStyle(
fontSize: 18.sp,
fontWeight: MyFontWeight.medium,
color: Color(0xFF0D0D0D),
),
),
],
),
),
],
));
}
showDateSelector() {
DatePicker.showDatePicker(context,
showTitleActions: true,
minTime: DateTime.now(),
maxTime: DateTime.now(),
theme: DatePickerTheme(
headerColor: Colors.white,
backgroundColor: Colors.white,
itemStyle: TextStyle(
color: Colors.black,
fontWeight: MyFontWeight.bold,
fontSize: 18),
doneStyle: TextStyle(color: Color(0xFF32A060), fontSize: 16.sp)),
onChanged: (date) {
print('change $date in time zone ' +
date.timeZoneOffset.inHours.toString());
}, onConfirm: (date) {
// "2023-09-04";
setState(() {});
}, currentTime: DateTime.now(), locale: LocaleType.zh);
}
}