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.
 
 
 
 
 
 

684 lines
21 KiB

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/order_info.dart';
import 'package:huixiang/retrofit/data/page.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/custom_image.dart';
import 'package:huixiang/view_widget/my_footer.dart';
import 'package:huixiang/view_widget/my_tab.dart';
import 'package:huixiang/view_widget/round_button.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class OrderHistoryPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _OrderHistoryPage();
}
}
class _OrderHistoryPage extends State<OrderHistoryPage>
with SingleTickerProviderStateMixin {
List<Widget> _pages;
TabController tabcontroller;
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (tabcontroller == null)
tabcontroller = TabController(length: 4, vsync: this);
_pages = [
OrderHistoryList(0),
OrderHistoryList(1),
OrderHistoryList(2),
OrderHistoryList(3)
];
}
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: Text(
S.of(context).dingdan,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
centerTitle: false,
backgroundColor: Color(0xFFFFFFFF),
elevation: 0,
leading: GestureDetector(
onTap: () {
Navigator.of(context).pop();
},
child: Container(
alignment: Alignment.centerRight,
margin: EdgeInsets.only(left: 10),
padding: EdgeInsets.all(6),
child: Icon(
Icons.arrow_back_ios,
color: Colors.black,
size: 24,
),
),
),
titleSpacing: 2,
leadingWidth: 56,
bottom: PreferredSize(
preferredSize: Size(double.infinity, 38),
child: TabBar(
controller: tabcontroller,
isScrollable: false,
indicatorWeight: 2,
indicatorSize: TabBarIndicatorSize.label,
indicatorColor: Color(0xFF39B54A),
indicatorPadding: EdgeInsets.only(top: 3),
unselectedLabelStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.normal,
),
labelStyle: TextStyle(
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.bold,
),
labelColor: Colors.black,
tabs: [
MyTab(
text: S.of(context).quanbu,
),
MyTab(
text: S.of(context).daifukuan,
),
MyTab(
text: S.of(context).weiwancheng,
),
MyTab(
text: S.of(context).yiwancheng,
)
],
),
),
),
body: TabBarView(
children: _pages,
controller: tabcontroller,
),
),
);
}
}
class OrderHistoryList extends StatefulWidget {
final int orderStatus;
OrderHistoryList(this.orderStatus);
@override
State<StatefulWidget> createState() {
return _OrderHistoryList();
}
}
class _OrderHistoryList extends State<OrderHistoryList>
with AutomaticKeepAliveClientMixin {
final RefreshController refreshController = RefreshController();
@override
Widget build(BuildContext context) {
super.build(context);
return SmartRefresher(
controller: refreshController,
enablePullDown: true,
enablePullUp: true,
physics: BouncingScrollPhysics(),
header: MyHeader(),
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
},
),
onRefresh: _onRefresh,
onLoading: queryOrder,
child: ListView.builder(
itemCount: orderInfos != null ? orderInfos.length : 0,
itemBuilder: (context, position) {
return InkWell(
onTap: () {
Navigator.of(context).pushNamed('/router/order_details',
arguments: {"id": orderInfos[position].id});
},
child: orderItem(orderInfos[position]),
);
}),
);
}
bool isRemake = true;
ApiService apiService;
int current = 1;
_onRefresh() {
current = 1;
queryOrder();
}
List<OrderInfo> orderInfos = [];
queryOrder() async {
BaseData baseData = await apiService.orderList({
"current": current,
"model": {"status": widget.orderStatus},
"order": "descending",
"size": 10,
"sort": "id"
}).catchError((onError) {
refreshController.refreshFailed();
refreshController.loadFailed();
});
if (baseData != null && baseData.isSuccess) {
PageInfo pageInfo = PageInfo.fromJson(baseData.data);
if (current == 1) {
orderInfos.clear();
}
orderInfos
.addAll(pageInfo.records.map((e) => OrderInfo.fromJson(e)).toList());
refreshController.refreshCompleted();
refreshController.loadComplete();
if (current * 10 > int.tryParse(pageInfo.total)) {
refreshController.loadNoData();
} else {
current += 1;
}
setState(() {});
} else {
refreshController.refreshFailed();
refreshController.loadFailed();
Fluttertoast.showToast(msg: baseData.msg);
}
}
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) => {
apiService = ApiService(Dio(), token: value.getString("token")),
queryOrder(),
});
}
Widget orderItem(OrderInfo orderInfo) {
return Container(
margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w, 8.h),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(4),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(25),
offset: Offset(0, 1),
blurRadius: 12,
spreadRadius: 0,
)
]),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 19.w,
height: 19.h,
margin: EdgeInsets.only(left: 12.w, top: 12.h),
alignment: Alignment.center,
decoration: BoxDecoration(
color: Color(0xff32A060),
borderRadius: BorderRadius.circular(2),
),
child: Text(
(orderInfo != null && orderInfo.isTakeOut == 0) ? "" : "",
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
Expanded(
child: Container(
width: double.infinity,
margin: EdgeInsets.only(left: 6.w, top: 12.h),
alignment: Alignment.centerLeft,
child: Text(
(orderInfo != null) ? orderInfo.storeName : "",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.sp,
color: Color(0xFF353535),
),
),
),
flex: 1,
),
Padding(
padding: EdgeInsets.only(top: 12.h, right: 12.w),
child: Text(
(orderInfo != null &&
orderInfo.storeVO != null &&
orderInfo.storeVO.posType != null)
? statusText(
orderInfo.refundStatus,
orderInfo.orderStatus,
orderInfo.payStatus,
orderInfo.sendStatus,
orderInfo.isTakeOut)
: "",
style: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.bold,
color: (orderInfo != null && orderInfo.orderStatus == 4)
? Color(0xFF32A060)
: Color(0xffFE951E),
),
),
),
],
),
Container(
margin: EdgeInsets.only(left: 37.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
S.of(context).xiadanshijian_(
(orderInfo != null) ? orderInfo.createTime : ""),
style: TextStyle(
fontSize: 10.sp,
color: Color(0xFF727272),
),
),
SizedBox(
height: 8.h,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Container(
child: Row(
children: [
Expanded(
flex: 1,
child: Row(
children: goodsItem((orderInfo != null &&
orderInfo.productList !=
null)
? orderInfo.productList
: null),
),
),
],
),
),
flex: 1,
),
Padding(
padding: EdgeInsets.all(22.w),
child: Image.asset(
"assets/image/icon_order_more.png",
width: 24.w,
height: 24.h,
),
)
],
),
],
),
),
SizedBox(
height: 12.h,
),
Container(
margin: EdgeInsets.only(right: 12.w, bottom: 12.h),
child: Directionality(
textDirection: TextDirection.rtl,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text.rich(
TextSpan(
children: [
TextSpan(
text: "",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF868686),
),
),
TextSpan(
text: (orderInfo != null &&
orderInfo.productList !=
null)
? "${orderInfo.productList.length}"
: "0",
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
TextSpan(
text: "",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF868686),
),
),
],
),
),
SizedBox(
width: 4.w,
),
Text.rich(
TextSpan(
children: [
TextSpan(
text: "合计:",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF868686),
),
),
TextSpan(
text: S.of(context).yuan(orderInfo != null
? orderInfo.finalPayPrice
: "0"),
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
TextSpan(
text: "",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF868686),
),
),
],
),
),
],
),
SizedBox(
height: 8.h,
),
Row(
children: statusBtn(
orderInfo != null ? orderInfo.orderStatus : 0),
),
],
),
),
),
],
),
);
}
String statusText(refundStatus, orderStatus, payStatus, sendStatus, isTakeOut) {
String statusText = "";
if(isTakeOut == 0) {
if(payStatus == 0) {
statusText = S.of(context).daizhifu;
} else {
statusText = S.of(context).yizhifu;
switch(orderStatus) {
case 2:
statusText = S.of(context).shangjiazhengzaipeican;
break;
case 3:
statusText = S.of(context).daiqucan;
break;
case 4:
statusText = S.of(context).yiwancheng;
break;
}
if(refundStatus == 1) {
statusText = S.of(context).yituikuan;
}
}
} else if(isTakeOut == 1) {
if(payStatus == 0) {
statusText = S.of(context).daizhifu;
} else {
statusText = S.of(context).yizhifu;
switch(sendStatus) {
case 1:
statusText = S.of(context).zhengzaihujiaoqishou;
break;
case 2:
statusText = S.of(context).quhuozhong;
break;
case 3:
statusText = S.of(context).peisongzhong;
break;
case 4:
statusText = S.of(context).yisongda;
switch(orderStatus) {
case 4:
statusText = S.of(context).yiwancheng;
break;
}
break;
}
if(refundStatus == 1) {
statusText = S.of(context).yituikuan;
}
}
} else if(isTakeOut == 2) {
if(payStatus == 0) {
statusText = S.of(context).daizhifu;
} else {
statusText = S.of(context).yizhifu;
switch(sendStatus) {
case 1:
statusText = S.of(context).yifahuo;
break;
case 4:
statusText = S.of(context).yisongda;
switch(orderStatus) {
case 4:
statusText = S.of(context).yiwancheng;
break;
}
break;
}
if(refundStatus == 1) {
statusText = S.of(context).yituikuan;
}
}
}
return statusText;
}
List<Widget> statusBtn(orderStatus) {
return [
if (orderStatus == 2)
RoundButton(
text: S.of(context).querenshouhuo,
textColor: Colors.white,
fontSize: 12.sp,
backgroup: Color(0xFF32A060),
radius: 2,
padding: EdgeInsets.fromLTRB(17.w, 4.h, 17.w, 4.h),
),
if (orderStatus == 2)
Container(
width: 72.w,
height: 24.h,
margin: EdgeInsets.only(right: 10.w),
child: TextButton(
onPressed: () {
Navigator.of(context)
.pushNamed('/router/logistics_information_page');
},
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
side: MaterialStateProperty.all(
BorderSide(color: Color(0xff32A060), width: 0.5),
),
),
child: Text(
S.of(context).chakanwuliu,
style: TextStyle(color: Color(0xff32A060), fontSize: 12.sp),
),
),
),
if (orderStatus == 3)
RoundButton(
text: S.of(context).zailaiyidan,
textColor: Colors.white,
fontSize: 12.sp,
backgroup: Color(0xFF32A060),
radius: 2,
padding: EdgeInsets.fromLTRB(17.w, 4.h, 17.w, 4.h),
),
if (orderStatus == 3)
Container(
width: 72.w,
height: 24.h,
margin: EdgeInsets.only(right: 10.w),
child: TextButton(
onPressed: () {},
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
side: MaterialStateProperty.all(
BorderSide(
color: Color(0xff32A060),
width: 0.5,
),
),
),
child: Text(
S.of(context).shanchudingdan,
style: TextStyle(
color: Color(0xff32A060),
fontSize: 12.sp,
),
),
),
),
if (orderStatus == 0 || orderStatus == 1)
RoundButton(
text: S.of(context).quzhifu,
textColor: Colors.white,
fontSize: 12.sp,
backgroup: Color(0xFF32A060),
radius: 2,
padding: EdgeInsets.fromLTRB(17.w, 4.h, 17.w, 4.h),
),
SizedBox(
width: 10.w,
),
if (orderStatus == 0 || orderStatus == 1)
Container(
width: 72.w,
height: 24.h,
child: TextButton(
onPressed: () {},
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
side: MaterialStateProperty.all(
BorderSide(
color: Color(0xff32A060),
width: 0.5,
),
),
),
child: Text(
S.of(context).quxiaozhifu,
style: TextStyle(
color: Color(0xff32A060),
fontSize: 12.sp,
),
),
),
),
if (orderStatus == 3)
Expanded(
flex: 1,
child: Container(
margin: EdgeInsets.only(left: 37.w),
alignment: Alignment.centerLeft,
child: Text(
S.of(context).qudanhao("123"),
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
),
];
}
List<Widget> goodsItem(List<ProductList> products) {
if (products == null) return [];
return products
.map((e) => Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
MImage(
e.skuImg,
width: 75.w,
height: 75.h,
fit: BoxFit.contain,
errorSrc: "assets/image/default_1.png",
fadeSrc: "assets/image/default_1.png",
),
SizedBox(
height: 4.h,
),
if (isRemake)
Text(
e.productName,
style: TextStyle(
fontSize: 10.sp,
color: Color(0xFF353535),
),
),
],
))
.toList();
}
@override
bool get wantKeepAlive => true;
}