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.
 
 
 
 
 
 

985 lines
37 KiB

import 'package:dio/dio.dart';
import 'package:flutter/cupertino.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/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/my_footer.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:shimmer/shimmer.dart';
import '../../../generated/l10n.dart';
import '../../../retrofit/business_api.dart';
import '../../../retrofit/data/base_data.dart';
import '../../../retrofit/data/recharge_flow_list.dart';
import '../../../utils/business_instance.dart';
import '../../../utils/flutter_utils.dart';
import '../../../utils/font_weight.dart';
import '../../../view_widget/no_data_view.dart';
class VipRechargeFlow extends StatefulWidget {
final String storeId;
VipRechargeFlow(
Key key,
this.storeId,
) : super(key: key);
@override
State<StatefulWidget> createState() {
return _VipRechargeFlow();
}
}
class _VipRechargeFlow extends State<VipRechargeFlow> {
final RefreshController _refreshController = RefreshController();
BusinessApiService businessService;
List<Records> records = [];
int _current = 1;
String networkError = "";
int networkStatus = 0;
final TextEditingController editingController = TextEditingController();
FocusNode _focusNode = FocusNode();
bool isKeyBoardShow = false;
///离开页面记着销毁和清除
@override
void dispose() {
super.dispose();
_refreshController.dispose();
_focusNode.unfocus();
}
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
print("object: ${MediaQuery.of(context).viewInsets.bottom}");
if (MediaQuery.of(context).viewInsets.bottom == 0) {
if (isKeyBoardShow) {
isKeyBoardShow = false;
//关闭键盘 软键盘关闭了, 清除输入控件的焦点, 否则重新进入页面会导致软键盘再弹出问题
FocusScope.of(context).requestFocus(FocusNode());
}
} else {
isKeyBoardShow = true;
}
});
});
_onRefresh();
}
_onRefresh({bool isShowLoad = true}) async {
if (isShowLoad)
EasyLoading.show(
status: S.current.zhengzaijiazai,
maskType: EasyLoadingMaskType.black);
await queryRechargeFlow(isRefreshData: false);
EasyLoading.dismiss();
if (!mounted) return;
if (_refreshController.isRefresh) _refreshController.refreshCompleted();
setState(() {});
}
queryRechargeFlow({isRefreshData = true}) async {
try {
if (businessService == null) {
businessService = BusinessApiService(Dio(),
context: context,
token: BusinessInstance.instance.businessToken,
tenant: BusinessInstance.instance.businessTenant,
storeId: widget.storeId);
}
BaseData<RechargeFlowList> baseData = await businessService.rechargeFlow({
"size": 10,
"pageSize": 10,
"current": _current,
"currentPage": 1,
"sort": "id",
"order": "descending",
"model": {"id": editingController?.text ?? ""},
// "map": {"startDate": "", "endDate": ""},
"timeRange": null
}).catchError((error) {
networkError = AppUtils.dioErrorTypeToString(error.type);
networkStatus = -1;
setState(() {});
_refreshController.refreshFailed();
_refreshController.loadFailed();
});
if (!mounted) return;
if (baseData != null && baseData.isSuccess) {
records.addAll(baseData?.data?.records ?? []);
if ((baseData?.data?.records ?? []).isEmpty ||
records.length.toString() == baseData.data.total)
_refreshController.loadNoData();
else
_refreshController.loadComplete();
networkStatus = 1;
} else {
SmartDialog.showToast(baseData.msg, alignment: Alignment.center);
}
} finally {
if (isRefreshData) setState(() {});
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
Container(
width: double.infinity,
height: 1.h,
color: Color(0xFFD8D8D8),
),
rechargeFlowSearch(),
Expanded(
child:Container(
child:SmartRefresher(
controller: _refreshController,
enablePullDown: true,
enablePullUp: records.length == 0 ? false : true,
header: MyHeader(color: Color(0xFF30415B)),
physics: BouncingScrollPhysics(),
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
},
),
onRefresh: () {
_current = 1;
records.clear();
_onRefresh(isShowLoad: false);
},
onLoading: () {
_current++;
_onRefresh(isShowLoad: false);
},
child: SingleChildScrollView(
physics: NeverScrollableScrollPhysics(),
child: Column(
children: [
Padding(
padding: EdgeInsets.only(left: 20.w, top: 16.h,bottom: 16.h),
child: Row(
children: [
Container(
width: 4.w,
height: 16.h,
color: Color(0xFF30415B),
margin: EdgeInsets.only(right: 12.w),
),
Expanded(
child: Text(
"充值流水",
style: TextStyle(
fontSize: 15.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF0D0D0D),
),
),
),
],
),
),
networkStatus == -1
? noNetwork()
: ((networkStatus == 0)
? ListView.builder(
padding: EdgeInsets.zero,
itemCount: 10,
scrollDirection: Axis.vertical,
shrinkWrap: true,
physics: BouncingScrollPhysics(),
itemBuilder: (context, position) {
return rechargeFlowItemSm();
},
)
: ((records == null || records.length == 0)
? NoDataView(
src:
"assets/image/bs_no data_logo.webp",
isShowBtn: false,
text: "暂无数据",
fontSize: 16.sp,
iconHeight: 120.h,
margin: EdgeInsets.all(50.h),
)
: ListView.builder(
itemCount: records?.length ?? 0,
physics: BouncingScrollPhysics(),
shrinkWrap: true,
itemBuilder: (context, position) {
return GestureDetector(
behavior:
HitTestBehavior.opaque,
onTap: () {
if (isKeyBoardShow)
FocusScope.of(context)
.requestFocus(
FocusNode());
return;
},
child: rechargeFlowItem(
records[position],
position),
);
},
))),
],
))),
)),
],
);
}
/// 搜索框
Widget rechargeFlowSearch() {
return Container(
color: Colors.white,
child: Container(
height: 40.h,
margin:
EdgeInsets.only(left: 20.w, right: 17.w, top: 10.h, bottom: 15.h),
decoration: BoxDecoration(
color: Color(0xFFF7F8FA),
borderRadius: BorderRadius.circular(2),
),
child: TextField(
focusNode: _focusNode,
textInputAction: TextInputAction.search,
onEditingComplete: () {
FocusScope.of(context).requestFocus(FocusNode());
records.clear();
_onRefresh();
},
style: TextStyle(
fontSize: 15.sp,
fontWeight: MyFontWeight.regular,
color: Color(0xFF808080),
),
controller: editingController,
decoration: InputDecoration(
hintText: "订单编号",
hintStyle: TextStyle(
color: Color(0xFF808080),
fontSize: 15.sp,
fontWeight: MyFontWeight.regular),
contentPadding: EdgeInsets.symmetric(
vertical: 12.h,
),
prefixIcon: Image.asset(
"assets/image/bs_goods_search.webp",
width: 20,
height: 20,
),
border: InputBorder.none,
),
),
),
);
}
Widget rechargeFlowItem(Records records, index) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
),
margin: EdgeInsets.only(left: 16.w, right: 16.w, bottom: 12.h),
padding: EdgeInsets.only(
top: 13.h,
bottom: 16.h,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(
left: 12.h,
),
child: Text(
"订单编号: ${records?.id ?? ""}",
style: TextStyle(
fontSize: 14.sp,
color: Color(0xFF1A1A1A),
fontWeight: MyFontWeight.bold),
),
),
Container(
height: 1.h,
width: double.infinity,
color: Color(0xFFF4F6F7),
margin: EdgeInsets.symmetric(vertical: 13.h),
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Column(
children: [
Padding(
padding: EdgeInsets.only(
bottom: 12.h,
left: 12.w,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Text(
"充值用户: ",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF1A1A1A),
fontWeight: MyFontWeight.regular),
),
flex: 1,
),
Expanded(
child: Text(
records?.createPerson ?? "",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF1A1A1A),
fontWeight: MyFontWeight.regular),
),
flex: 2,
),
],
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12.h,
left: 12.w,
),
child: Row(
children: [
Expanded(
child: Text(
"手机号: ",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF1A1A1A),
fontWeight: MyFontWeight.regular),
),
flex: 1,
),
Expanded(
child: Text(
records?.phone ?? "",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF1A1A1A),
fontWeight: MyFontWeight.regular),
),
flex: 2,
),
],
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12.h,
left: 12.w,
),
child: Row(
children: [
Expanded(
child: Text(
"充值实付金额: ",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF1A1A1A),
fontWeight: MyFontWeight.regular),
),
flex: 1,
),
Expanded(
child: Text(
"${records?.rechargeMoney ?? ""}",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF1A1A1A),
fontWeight: MyFontWeight.regular),
),
flex: 2,
),
],
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12.h,
left: 12.w,
),
child: Row(
children: [
Expanded(
flex: 1,
child: Text(
"充值实赠金额: ",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF1A1A1A),
fontWeight: MyFontWeight.regular),
)),
Expanded(
flex: 2,
child: Text(
"${records?.giftdMoney ?? ""}",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF1A1A1A),
fontWeight: MyFontWeight.regular),
)),
],
),
),
if (records.isShow)
Padding(
padding: EdgeInsets.only(
bottom: 12.h,
left: 12.w,
),
child: Row(
children: [
Expanded(
flex: 1,
child: Text(
"充值门店: ",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF1A1A1A),
fontWeight: MyFontWeight.regular),
)),
Expanded(
flex: 2,
child: Text(
records?.storeName ?? "",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF1A1A1A),
fontWeight: MyFontWeight.regular),
)),
],
),
),
if (records.isShow)
Padding(
padding: EdgeInsets.only(
bottom: 12.h,
left: 12.w,
),
child: Row(
children: [
Expanded(
flex: 1,
child: Text(
"充值方式: ",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF1A1A1A),
fontWeight: MyFontWeight.regular),
)),
Expanded(
flex: 2,
child: Text(
records?.rechargeName ?? "",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF1A1A1A),
fontWeight: MyFontWeight.regular),
)),
],
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12.h,
left: 12.w,
),
child: Row(
children: [
Expanded(
flex: 1,
child: Text(
"入账时间: ",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF1A1A1A),
fontWeight: MyFontWeight.regular),
)),
Expanded(
flex: 2,
child: Text(
records?.createTime ?? "",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF1A1A1A),
fontWeight: MyFontWeight.regular),
)),
],
)),
],
)),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
setState(() {
records.isShow = !records.isShow;
});
},
child: Container(
padding:
EdgeInsets.symmetric(horizontal: 24.w, vertical: 6.h),
child: Icon(
records.isShow
? Icons.keyboard_arrow_up
: Icons.keyboard_arrow_down,
color: Color(0xFF0D0D0D),
size: 24,
)),
),
],
)
],
),
);
}
Widget rechargeFlowItemSm() {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
),
margin: EdgeInsets.only(left: 16.w, right: 16.w, bottom: 12.h),
padding: EdgeInsets.only(
top: 13.h,
bottom: 16.h,
),
child: Column(
children: [
Container(
padding: EdgeInsets.only(
left: 12.h,
),
child: Row(
children: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 60.w,
height: 18.h,
),
),
SizedBox(
width: 15.w,
),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 198.w,
height: 18.h,
),
),
],
),
),
Container(
height: 1.h,
width: double.infinity,
color: Color(0xFFF4F6F7),
margin: EdgeInsets.symmetric(vertical: 13.h),
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
flex: 1,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 12.h,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 60.w,
height: 18.h,
),
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 12.h,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 77.w,
height: 18.h,
),
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 12.h,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 52.w,
height: 18.h,
),
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 12.h,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 52.w,
height: 18.h,
),
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 12.h,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 52.w,
height: 18.h,
),
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 12.h,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 52.w,
height: 18.h,
),
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 12.h,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 52.w,
height: 18.h,
),
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 12.h,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 52.w,
height: 18.h,
),
),
),
],
)),
Expanded(
flex: 2,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 12.h,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 48.w,
height: 18.h,
),
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 12.h,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 77.w,
height: 18.h,
),
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 12.h,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 120.w,
height: 18.h,
),
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 12.h,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 44.w,
height: 18.h,
),
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 12.h,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 44.w,
height: 18.h,
),
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 12.h,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 44.w,
height: 18.h,
),
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 12.h,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 44.w,
height: 18.h,
),
),
),
Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 12.h,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 44.w,
height: 18.h,
),
),
),
],
)),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
margin: EdgeInsets.only(right: 24.w),
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(2),
),
width: 16.w,
height: 16.h,
),
),
],
)
],
),
);
}
Widget noNetwork() {
return Container(
margin: EdgeInsets.only(top: 120.h),
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),
)),
)
],
),
);
}
}