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.

876 lines
28 KiB

4 years ago
import 'package:dio/dio.dart';
4 years ago
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
3 years ago
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:huixiang/data/base_data.dart';
import 'package:huixiang/data/order_info.dart';
import 'package:huixiang/data/order_product_vo.dart';
import 'package:huixiang/data/page.dart';
2 weeks ago
import 'package:huixiang/data/user_info.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/order/order_utils.dart';
import 'package:huixiang/order/order_view/order_pay_selected.dart';
3 years ago
import 'package:huixiang/retrofit/min_api.dart';
4 years ago
import 'package:huixiang/retrofit/retrofit_api.dart';
3 years ago
import 'package:huixiang/store/scan.dart';
import 'package:huixiang/utils/app_util.dart';
import 'package:huixiang/utils/shared_preference.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';
3 years ago
import 'package:huixiang/view_widget/tips_dialog.dart';
4 years ago
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:retrofit/retrofit.dart';
import 'package:shimmer/shimmer.dart';
4 years ago
class OrderHistoryPage extends StatefulWidget {
final Map? arguments;
3 years ago
OrderHistoryPage({this.arguments});
4 years ago
@override
State<StatefulWidget> createState() {
return _OrderHistoryPage();
}
}
class _OrderHistoryPage extends State<OrderHistoryPage>
with SingleTickerProviderStateMixin {
List<Widget> _pages = [];
TabController? tabController;
4 years ago
@override
void didChangeDependencies() {
super.didChangeDependencies();
4 years ago
4 years ago
_pages = [
OrderHistoryList(0),
OrderHistoryList(1),
OrderHistoryList(2),
OrderHistoryList(3)
];
}
@override
Widget build(BuildContext context) {
return DefaultTabController(
3 years ago
length: 4,
4 years ago
child: Scaffold(
4 years ago
appBar: MyAppBar(
title: S.of(context).dingdan,
titleColor: Colors.black,
titleSize: 18.sp,
background: Color(0xFFFFFFFF),
leadingColor: Colors.black,
2 weeks ago
toolbarHeight: kToolbarHeight,
4 years ago
bottom: PreferredSize(
4 years ago
preferredSize: Size(double.infinity, 38.h),
child: Theme(
data: ThemeData(
splashColor: Colors.transparent, // 点击时的水波纹颜色设置为透明
highlightColor: Colors.transparent, // 点击时的背景高亮颜色设置为透明
4 years ago
),
child: TabBar(
controller: tabController,
isScrollable: false,
indicatorWeight: 2.w,
indicatorSize: TabBarIndicatorSize.label,
indicatorColor: Color(0xFF39B54A),
indicatorPadding: EdgeInsets.only(top: 3.h),
unselectedLabelStyle: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.normal,
),
2 weeks ago
dividerHeight: 0,
dividerColor: Colors.transparent,
labelStyle: TextStyle(
color: Colors.black,
fontSize: 16.sp,
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,
)
],
)),
4 years ago
),
),
body: TabBarView(
children: _pages,
3 years ago
controller: tabController,
4 years ago
),
),
);
}
}
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, ParseErrorLogger {
4 years ago
final RefreshController refreshController = RefreshController();
4 years ago
bool isRemake = true;
ApiService? apiService;
4 years ago
int current = 1;
List<OrderInfo> orderInfos = [];
UserInfo? userInfo;
int networkStatus = 0;
@override
void initState() {
super.initState();
apiService = ApiService(
Dio(),
// showLoading: true,
context: context,
token: SharedInstance.instance.token,
errorLogger: this,
);
queryOrder();
queryUserBalance();
}
4 years ago
_onRefresh() {
current = 1;
queryOrder();
}
queryOrder({bool isLoading = true}) async {
try {
if (isLoading)
SmartDialog.showLoading(
msg: S.current.zhengzaijiazai,
);
BaseData<PageInfo<OrderInfo>>? baseData = await apiService?.orderList({
"current": current,
"model": {"status": widget.orderStatus},
"order": "descending",
"size": 10,
"sort": "id"
}).catchError((onError) {
networkStatus = -1;
refreshController.refreshFailed();
refreshController.loadFailed();
2 weeks ago
return BaseData<PageInfo<OrderInfo>>()..isSuccess = false;
});
if (baseData?.isSuccess ?? false) {
if (baseData!.data != null &&
(baseData.data!.records?.isNotEmpty ?? false)) {
if (current == 1) {
orderInfos.clear();
}
orderInfos.addAll(baseData.data!.records!);
}
refreshController.refreshCompleted();
refreshController.loadComplete();
if (current * 10 > (int.tryParse("${baseData.data?.total}") ?? 0)) {
refreshController.loadNoData();
} else {
current += 1;
}
setState(() {});
networkStatus = 1;
4 years ago
} else {
if (baseData?.msg?.isNotEmpty ?? false)
2 weeks ago
SmartDialog.showToast(
"${baseData!.msg}",
alignment: Alignment.center,
);
refreshController.refreshFailed();
refreshController.loadFailed();
4 years ago
}
} finally {
4 years ago
}
}
4 years ago
minLogin(OrderInfo orderInfo) {
apiService?.minLogin(orderInfo.storeId ?? "").catchError((onError) {
debugPrint("${onError}");
}).then((baseData) {
2 weeks ago
if (baseData.isSuccess ?? false) {
Map<String, dynamic> minStoreInfo = baseData.data;
String minToken = minStoreInfo["token"];
String tenant = orderInfo.tenantCode ?? "";
String storeId = orderInfo.storeId ?? "";
SharedInstance.instance.saveMini(minToken, tenant, storeId);
paySelected(
2 weeks ago
orderInfo,
MinApiService(
Dio(),
context: context,
token: minToken,
tenant: tenant,
storeId: storeId,
errorLogger: this,
),
);
}
});
}
queryDetails(id) async {
BaseData<OrderInfo>? baseData = await apiService?.orderDetail(id).catchError((error) {
2 weeks ago
return BaseData<OrderInfo>()..isSuccess = false;
});
if (baseData?.isSuccess ?? false) {
return baseData!.data;
}
}
queryUserBalance() async {
BaseData<UserInfo>? baseData = await apiService?.queryInfo().catchError((onError) {
2 weeks ago
return BaseData<UserInfo>()..isSuccess = false;
});
if (baseData?.isSuccess ?? false) {
userInfo = baseData!.data;
if (mounted) setState(() {});
}
}
paySelected(OrderInfo orderInfo, MinApiService minService) async {
if (userInfo == null) {
return;
}
var payChannel = await showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder: (context) {
return OrderPaySelected(userInfo!);
},
);
if (payChannel != null && payChannel > 0) {
orderInfo = await queryDetails(orderInfo.id);
OrderUtils.carryOnPay(
payChannel,
minService,
orderInfo,
(BaseData baseData) {
SmartDialog.showToast(
baseData.msg == "ok" ? "订单支付成功" : "${baseData.msg}",
alignment: Alignment.center,
);
Future.delayed(Duration(seconds: 3), () {
_onRefresh();
});
},
);
}
}
payResult(BaseData baseData) {}
orderCancel(String orderId) async {
BaseData? baseData = await apiService?.orderCancel(orderId).catchError((onError) {
2 weeks ago
return BaseData()..isSuccess = false;
});
if (baseData?.isSuccess ?? false) {
SmartDialog.showToast("订单取消成功");
_onRefresh();
}
}
aginOrder(OrderInfo orderInfo) {
if (orderInfo.storeVO?.posType?.code == "NORMALSTORE") {
Scan.toScan(
context,
orderInfo.storeVO?.id,
orderInfo.tenantCode,
orderInfo.storeVO?.storeName,
apiService!,
);
} else {
String storeId = orderInfo.storeVO?.id ?? "";
miniLogin(apiService!, storeId, (token) {
Navigator.of(context).pushNamed(
'/router/store_order',
arguments: {
"id": orderInfo.storeVO?.id,
"tenant": orderInfo.tenantCode,
"storeName": orderInfo.storeVO?.storeName,
"miniToken": token,
},
);
});
}
}
@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(isLoading: false);
},
child: networkStatus == 0
? ListView.builder(
itemCount: 10,
physics: BouncingScrollPhysics(),
shrinkWrap: true,
itemBuilder: (context, position) {
return orderItemSm();
},
)
: ((orderInfos.length > 0)
? ListView.builder(
itemCount: orderInfos.length ?? 0,
padding: EdgeInsets.symmetric(
vertical: 8,
),
itemBuilder: (context, position) {
return InkWell(
onTap: () {
2 weeks ago
Navigator.of(context).pushNamed(
'/router/order_details',
arguments: {
"id": orderInfos[position].id,
"jumpState": 2
},
);
},
child: orderItem(orderInfos[position]),
);
2 weeks ago
},
)
: NoDataView(
src: "assets/image/ding_dan.webp",
isShowBtn: false,
text: "目前暂无订单,快去下一单吧~",
fontSize: 16.sp,
margin: EdgeInsets.only(top: 120),
)),
);
4 years ago
}
String orderAllGoods(OrderInfo orderInfo) {
3 years ago
int count = 0;
orderInfo.productList?.forEach((element) {
count += (element.buyNum ?? 0);
});
3 years ago
return count.toString();
}
4 years ago
Widget orderItem(OrderInfo orderInfo) {
4 years ago
return Container(
margin: EdgeInsets.fromLTRB(
12, 8, 12, 8,
),
4 years ago
decoration: BoxDecoration(
3 years ago
color: Colors.white,
borderRadius: BorderRadius.circular(4),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(25),
offset: Offset(0, 1),
blurRadius: 12,
spreadRadius: 0,
3 years ago
),
3 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: [
Expanded(
child: Container(
width: double.infinity,
margin: EdgeInsets.only(left: 12.w, top: 12.h),
4 years ago
alignment: Alignment.centerLeft,
child: Text(
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(
(orderInfo.storeVO != null)
4 years ago
? StatusUtils.statusText(
context,
orderInfo.refundStatus,
4 years ago
orderInfo.orderStatus,
orderInfo.payStatus,
orderInfo.sendStatus,
orderInfo.isTakeOut)
4 years ago
: "",
style: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.bold,
color: (orderInfo.refundStatus == 1 ||
orderInfo.orderStatus == -1 ||
(orderInfo.orderStatus ?? 0) >= 5)
4 years ago
? Colors.grey
: (orderInfo.orderStatus == 4)
? Color(0xFF32A060)
: Color(0xffFE951E),
4 years ago
),
),
4 years ago
),
],
),
Container(
margin: EdgeInsets.only(left: 12.w, top: 3.h),
4 years ago
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
4 years ago
children: [
4 years ago
Text(
S.of(context).xiadanshijian_(orderInfo.createTime ?? ""),
4 years ago
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: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: goodsItem(orderInfo.productList),
4 years ago
),
flex: 1,
4 years ago
),
4 years ago
Padding(
padding: EdgeInsets.all(22.w),
child: Image.asset(
3 years ago
"assets/image/icon_order_more.webp",
3 years ago
width: 24,
height: 24,
4 years ago
),
)
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(
3 years ago
text: orderAllGoods(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).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(
3 years ago
// text: totalPrice(orderInfo),
3 years ago
text: orderInfo.finalPayPrice,
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,
4 years ago
),
Row(
children: StatusUtils.statusBtn(
context,
orderInfo.payStatus,
orderInfo.payChannel,
orderInfo.orderStatus,
orderInfo.isTakeOut,
orderInfo.sendStatus,
orderInfo.refundStatus,
orderInfo.dayFlowCode, (type) {
if (type == 0) {
aginOrder(orderInfo);
} else if (type == 1) {
SmartDialog.show(
builder: (ctx) => Tips(
() {
1 week ago
SmartDialog.dismiss(status: SmartStatus.dialog);
},
text: "暂不支持此功能",
));
} else if (type == 2) {
orderCancel(orderInfo.id ?? "");
} else if (type == 3) {
minLogin(orderInfo);
} else if (type == 4) {
Navigator.of(context).pushNamed(
'/router/logistics_information_page',
arguments: {
"logisticsNum": orderInfo.logisticsNum,
"logisticsName": orderInfo.logisticsName,
"shipperCode": orderInfo.shipperCode,
"productNum":
orderInfo.productList?.length ?? 0,
"skuImg":
orderInfo.productList?[0].skuImg ?? ""
},
);
}
}),
4 years ago
),
],
),
),
4 years ago
),
4 years ago
],
),
);
}
4 years ago
// String totalPrice(orderInfo) {
// if (orderInfo == null) return "";
// double totalPrice = (double.tryParse(orderInfo.orderSum) + double.tryParse(orderInfo.postFee));
// if (orderInfo.orderDetail != null && orderInfo.orderDetail.couponDTO != null) {
// totalPrice -= double.tryParse(orderInfo.orderDetail.couponDTO.money);
// }
// return "$totalPrice";
// }
List<Widget> goodsItem(List<OrderProductVO>? products) {
if ((products?.length ?? 0) > 3) {
products = products?.sublist(0, 3);
4 years ago
}
return products
?.map(
(e) => Container(
margin: EdgeInsets.symmetric(horizontal: 2.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
MImage(
e.skuImg ?? "",
width: 75.w,
height: 75.w,
fit: BoxFit.cover,
errorSrc: "assets/image/default_1.webp",
fadeSrc: "assets/image/default_1.webp",
4 years ago
),
SizedBox(
height: 4.h,
),
if (isRemake)
Container(
width: 75.w,
child: Text(
e.productName ?? "",
maxLines: 1,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 10.sp,
color: Color(0xFF353535),
),
),
),
],
),
),
)
.toList() ??
[];
4 years ago
}
Widget orderItemSm() {
return Container(
margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w, 8.h),
padding: EdgeInsets.only(top: 12, bottom: 13.h, left: 13.w),
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: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 213.w,
height: 20.h,
),
),
Padding(
padding: EdgeInsets.only(right: 12.w),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 44.w,
height: 20.h,
),
),
),
],
),
Container(
margin: EdgeInsets.only(top: 5.h),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 160.w,
height: 16.h,
),
),
SizedBox(
height: 8.h,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: goodsItemSm(),
flex: 1,
),
Padding(
padding: EdgeInsets.all(22.w),
child: Image.asset(
"assets/image/icon_order_more.webp",
width: 24,
height: 24,
),
)
],
),
],
),
),
SizedBox(
height: 12.h,
),
Container(
alignment: Alignment.centerRight,
margin: EdgeInsets.only(right: 12.w, bottom: 12.h),
child: Directionality(
textDirection: TextDirection.rtl,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 75.w,
height: 20.h,
),
),
SizedBox(
width: 4.w,
),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 33.w,
height: 17.h,
),
),
],
),
SizedBox(
height: 8.h,
),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
decoration: BoxDecoration(
color: Color(0XFFD8D8D8),
borderRadius: BorderRadius.circular(10),
),
width: 72.w,
height: 25.h,
),
)
],
),
),
),
],
),
);
}
Widget goodsItemSm() {
return Container(
child: Row(
children: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 75.w,
height: 75.h,
),
),
SizedBox(width: 8.w),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 75.w,
height: 75.h,
),
),
SizedBox(width: 8.w),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 75.w,
height: 75.h,
),
),
],
));
}
4 years ago
@override
bool get wantKeepAlive => true;
@override
void logError(Object error, StackTrace stackTrace, RequestOptions options) {
debugPrint(
"logError: $error ${stackTrace.toString()} ${options.path}");
}
4 years ago
}