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.

502 lines
16 KiB

4 years ago
import 'package:dio/dio.dart';
4 years ago
import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart';
4 years ago
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';
4 years ago
import 'package:huixiang/utils/status_utils.dart';
4 years ago
import 'package:huixiang/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/custom_image.dart';
4 years ago
import 'package:huixiang/view_widget/my_appbar.dart';
4 years ago
import 'package:huixiang/view_widget/my_footer.dart';
4 years ago
import 'package:huixiang/view_widget/my_tab.dart';
4 years ago
import 'package:huixiang/view_widget/no_data_view.dart';
4 years ago
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
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);
4 years ago
4 years ago
_pages = [
OrderHistoryList(0),
OrderHistoryList(1),
OrderHistoryList(2),
OrderHistoryList(3)
];
}
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
4 years ago
appBar: MyAppBar(
title: S.of(context).dingdan,
titleColor: Colors.black,
titleSize: 18.sp,
background: Color(0xFFFFFFFF),
leadingColor: Colors.black,
4 years ago
toolbarHeight: kToolbarHeight + MediaQuery.of(context).padding.top,
4 years ago
bottom: PreferredSize(
4 years ago
preferredSize: Size(double.infinity, 38.h),
4 years ago
child: TabBar(
controller: tabcontroller,
4 years ago
isScrollable: false,
4 years ago
indicatorWeight: 2.w,
4 years ago
indicatorSize: TabBarIndicatorSize.label,
indicatorColor: Color(0xFF39B54A),
4 years ago
indicatorPadding: EdgeInsets.only(top: 3.h),
4 years ago
unselectedLabelStyle: TextStyle(
4 years ago
fontSize: 16.sp,
4 years ago
fontWeight: FontWeight.normal,
),
4 years ago
labelStyle: TextStyle(
color: Colors.black,
4 years ago
fontSize: 16.sp,
4 years ago
fontWeight: FontWeight.bold,
),
labelColor: Colors.black,
4 years ago
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,
)
],
4 years ago
),
),
),
body: TabBarView(
children: _pages,
controller: tabcontroller,
),
),
);
}
}
class OrderHistoryList extends StatefulWidget {
final int orderStatus;
OrderHistoryList(this.orderStatus);
@override
State<StatefulWidget> createState() {
return _OrderHistoryList();
}
}
4 years ago
class _OrderHistoryList extends State<OrderHistoryList>
with AutomaticKeepAliveClientMixin {
final RefreshController refreshController = RefreshController();
4 years ago
@override
Widget build(BuildContext context) {
super.build(context);
4 years ago
return SmartRefresher(
controller: refreshController,
enablePullDown: true,
enablePullUp: true,
physics: BouncingScrollPhysics(),
header: MyHeader(),
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
},
),
onRefresh: _onRefresh,
onLoading: queryOrder,
4 years ago
child: (orderInfos != null && orderInfos.length > 0)
? 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]),
);
})
: NoDataView(
isShowBtn: false,
text: "还没有订单,快去下一单吧~",
fontSize: 16.sp,
margin: EdgeInsets.only(top: 120),
),
4 years ago
);
4 years ago
}
bool isRemake = true;
4 years ago
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();
}
}
4 years ago
@override
void initState() {
super.initState();
4 years ago
SharedPreferences.getInstance().then((value) => {
apiService = ApiService(Dio(), token: value.getString("token")),
queryOrder(),
});
4 years ago
}
4 years ago
Widget orderItem(OrderInfo orderInfo) {
4 years ago
return Container(
4 years ago
margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w, 8.h),
4 years ago
decoration: BoxDecoration(
color: Colors.white,
4 years ago
borderRadius: BorderRadius.circular(4),
4 years ago
boxShadow: [
BoxShadow(
4 years ago
color: Colors.black.withAlpha(25),
offset: Offset(0, 1),
blurRadius: 12,
spreadRadius: 0,
)
4 years ago
]),
4 years ago
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
4 years ago
children: [
4 years ago
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
4 years ago
width: 19.w,
height: 19.h,
margin: EdgeInsets.only(left: 12.w, top: 12.h),
4 years ago
alignment: Alignment.center,
4 years ago
decoration: BoxDecoration(
4 years ago
color: Color(0xff32A060),
borderRadius: BorderRadius.circular(2),
),
4 years ago
child: Text(
(orderInfo != null && orderInfo.isTakeOut == 0) ? "" : "",
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
4 years ago
),
Expanded(
child: Container(
width: double.infinity,
4 years ago
margin: EdgeInsets.only(left: 6.w, top: 12.h),
4 years ago
alignment: Alignment.centerLeft,
child: Text(
4 years ago
(orderInfo != null) ? orderInfo.storeName : "",
4 years ago
style: TextStyle(
fontWeight: FontWeight.bold,
4 years ago
fontSize: 14.sp,
4 years ago
color: Color(0xFF353535),
),
),
4 years ago
),
flex: 1,
),
Padding(
4 years ago
padding: EdgeInsets.only(top: 12.h, right: 12.w),
child: Text(
4 years ago
(orderInfo != null &&
orderInfo.storeVO != null &&
orderInfo.storeVO.posType != null)
4 years ago
? StatusUtils.statusText(
context,
orderInfo.refundStatus,
4 years ago
orderInfo.orderStatus,
orderInfo.payStatus,
orderInfo.sendStatus,
orderInfo.isTakeOut)
: "",
style: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.bold,
4 years ago
color: (orderInfo == null)
? Color(0xFF32A060)
: (orderInfo.refundStatus == 1 ||
orderInfo.orderStatus >= 5)
? Colors.grey
: (orderInfo.orderStatus == 4)
? Color(0xFF32A060)
: Color(0xffFE951E),
4 years ago
),
),
4 years ago
),
],
),
Container(
4 years ago
margin: EdgeInsets.only(left: 37.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
4 years ago
children: [
4 years ago
Text(
S.of(context).xiadanshijian_(
(orderInfo != null) ? orderInfo.createTime : ""),
style: TextStyle(
fontSize: 10.sp,
color: Color(0xFF727272),
),
),
SizedBox(
height: 8.h,
),
Row(
4 years ago
mainAxisAlignment: MainAxisAlignment.start,
4 years ago
crossAxisAlignment: CrossAxisAlignment.center,
4 years ago
children: [
4 years ago
Expanded(
child: Container(
child: Row(
4 years ago
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: goodsItem((orderInfo != null &&
orderInfo.productList != null)
? orderInfo.productList
: null),
4 years ago
),
),
flex: 1,
4 years ago
),
4 years ago
Padding(
padding: EdgeInsets.all(22.w),
child: Image.asset(
"assets/image/icon_order_more.png",
width: 24.w,
height: 24.h,
),
)
4 years ago
],
),
],
),
),
SizedBox(
4 years ago
height: 12.h,
4 years ago
),
Container(
4 years ago
margin: EdgeInsets.only(right: 12.w, bottom: 12.h),
4 years ago
child: Directionality(
4 years ago
textDirection: TextDirection.rtl,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text.rich(
TextSpan(
children: [
TextSpan(
4 years ago
text: S.of(context).gong,
4 years ago
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF868686),
4 years ago
),
4 years ago
),
TextSpan(
text: (orderInfo != null &&
4 years ago
orderInfo.productList != null)
? "${orderInfo.productList.length}"
4 years ago
: "0",
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
4 years ago
),
4 years ago
),
TextSpan(
4 years ago
text: S.of(context).jian,
4 years ago
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF868686),
4 years ago
),
4 years ago
),
],
4 years ago
),
4 years ago
),
SizedBox(
width: 4.w,
),
Text.rich(
TextSpan(
children: [
TextSpan(
4 years ago
text: S.of(context).heji,
4 years ago
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF868686),
4 years ago
),
4 years ago
),
TextSpan(
4 years ago
text: totalPrice(orderInfo),
4 years ago
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
4 years ago
),
4 years ago
),
TextSpan(
4 years ago
text: S.of(context).yuan,
4 years ago
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF868686),
4 years ago
),
4 years ago
),
],
4 years ago
),
4 years ago
),
],
),
SizedBox(
height: 8.h,
),
Row(
4 years ago
children: (orderInfo != null)
4 years ago
? StatusUtils.statusBtn(
context,
4 years ago
orderInfo.payStatus,
orderInfo.orderStatus,
orderInfo.isTakeOut,
orderInfo.sendStatus,
orderInfo.refundStatus,
4 years ago
orderInfo.dayFlowCode)
4 years ago
: [],
4 years ago
),
],
),
),
4 years ago
),
4 years ago
],
),
);
}
4 years ago
4 years ago
String totalPrice(orderInfo) {
4 years ago
if (orderInfo == null) return "";
double totalPrice = (double.tryParse(orderInfo.orderSum) +
double.tryParse(orderInfo.postFee));
if (orderInfo.orderDetail != null &&
orderInfo.orderDetail.couponDTO != null) {
4 years ago
totalPrice -= double.tryParse(orderInfo.orderDetail.couponDTO.money);
}
return "$totalPrice";
}
List<Widget> goodsItem(List<ProductList> products) {
4 years ago
if (products == null) return [];
4 years ago
if (products.length > 3) {
4 years ago
products = products.sublist(0, 3);
}
4 years ago
return products
4 years ago
.map(
(e) => Container(
margin: EdgeInsets.symmetric(horizontal: 2.w),
child: Column(
4 years ago
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)
4 years ago
Container(
width: 75.w,
child: Text(
e.productName,
maxLines: 1,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 10.sp,
color: Color(0xFF353535),
),
4 years ago
),
),
],
4 years ago
),
),
)
4 years ago
.toList();
}
@override
bool get wantKeepAlive => true;
4 years ago
}