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.

858 lines
29 KiB

4 years ago
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
4 years ago
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
4 years ago
import 'package:huixiang/generated/l10n.dart';
4 years ago
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/exchange_order.dart';
import 'package:huixiang/retrofit/data/page.dart';
4 years ago
import 'package:huixiang/retrofit/retrofit_api.dart';
3 years ago
import 'package:huixiang/utils/font_weight.dart';
4 years ago
import 'package:huixiang/view_widget/classic_header.dart';
3 years ago
import 'package:huixiang/view_widget/custom_image.dart';
4 years ago
import 'package:huixiang/view_widget/icon_text.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:huixiang/view_widget/round_button.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
import 'package:shared_preferences/shared_preferences.dart';
import 'package:shimmer/shimmer.dart';
4 years ago
class ExchangeHistoryPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _ExchangeHistoryPage();
}
}
class _ExchangeHistoryPage extends State<ExchangeHistoryPage>
with SingleTickerProviderStateMixin {
List<Widget> tabs;
List<Widget> _pages;
TabController tabcontroller;
@override
void initState() {
super.initState();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (tabcontroller == null)
tabcontroller = TabController(length: 3, vsync: this);
4 years ago
tabs = [
MyTab(
text: S.of(context).quanbuduihuan,
),
MyTab(
text: S.of(context).weiwancheng,
4 years ago
),
// MyTab(
// text: S.of(context).keshiyong,
// ),
4 years ago
MyTab(
text: S.of(context).yiwancheng,
4 years ago
)
];
_pages = [
ExchangeHistoryList(0),
ExchangeHistoryList(1),
ExchangeHistoryList(2),
// ExchangeHistoryList(3)
4 years ago
];
}
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
4 years ago
appBar: MyAppBar(
title: S.of(context).duihuanlishi,
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),
child: Theme(
data: ThemeData(
splashColor: Colors.transparent, // 点击时的水波纹颜色设置为透明
highlightColor: Colors.transparent, // 点击时的背景高亮颜色设置为透明
),
child: TabBar(
controller: tabcontroller,
indicatorWeight: 2,
indicatorColor: Color(0xFF39B54A),
indicatorSize: TabBarIndicatorSize.label,
indicatorPadding: EdgeInsets.only(top: 3),
unselectedLabelStyle: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.normal,
),
labelStyle: TextStyle(
color: Colors.black,
fontSize: 16.sp,
fontWeight: MyFontWeight.semi_bold),
labelColor: Colors.black,
tabs: tabs,
)),
4 years ago
),
),
body: TabBarView(
children: _pages,
controller: tabcontroller,
),
),
);
}
}
class ExchangeHistoryList extends StatefulWidget {
final int orderStatus;
ExchangeHistoryList(this.orderStatus);
@override
State<StatefulWidget> createState() {
return _ExchangeHistoryList();
}
}
class _ExchangeHistoryList extends State<ExchangeHistoryList>
with AutomaticKeepAliveClientMixin {
4 years ago
ApiService apiService;
RefreshController _refreshController =
RefreshController(initialRefresh: false);
int pageNum = 1;
List<ExchangeOrder> orders = [];
int networkStatus = 0;
4 years ago
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) => {
4 years ago
apiService = ApiService(Dio(),
showLoading: false,
context: context,
token: value.getString('token')),
queryHistory(),
});
4 years ago
}
queryHistory({bool isLoading = true}) async {
try {
if (isLoading)
EasyLoading.show(
status: S.current.zhengzaijiazai,
maskType: EasyLoadingMaskType.black);
var map = {
"pageNum": pageNum,
"pageSize": 10,
// "state": widget.orderStatus
};
if (widget.orderStatus != 0) {
map["state"] = widget.orderStatus;
}
BaseData<PageInfo<ExchangeOrder>> baseData =
await apiService.creditOrderList(map).catchError((error) {
networkStatus = -1;
_refreshController.loadFailed();
_refreshController.refreshFailed();
});
if (baseData != null && baseData.isSuccess) {
if (pageNum == 1) {
orders.clear();
}
orders.addAll(baseData.data.list);
_refreshController.loadComplete();
_refreshController.refreshCompleted();
3 years ago
if (baseData.data.pages == baseData.data.pageNum) {
_refreshController.loadNoData();
} else {
pageNum += 1;
}
networkStatus = 1;
} else {
_refreshController.refreshFailed();
_refreshController.loadFailed();
}
} finally {
EasyLoading.dismiss();
setState(() {});
4 years ago
}
}
4 years ago
_refresh() {
pageNum = 1;
queryHistory(isLoading: false);
4 years ago
}
4 years ago
@override
Widget build(BuildContext context) {
return SmartRefresher(
enablePullDown: true,
enablePullUp: true,
4 years ago
header: MyHeader(),
footer: CustomFooter(
builder: (BuildContext context, LoadStatus mode) {
4 years ago
return MyFooter(mode);
},
),
controller: _refreshController,
onRefresh: _refresh,
onLoading: () {
queryHistory(isLoading: false);
},
child: networkStatus == 0
? ListView.builder(
itemCount: 10,
physics: BouncingScrollPhysics(),
shrinkWrap: true,
4 years ago
itemBuilder: (context, position) {
return buildOrderSm();
4 years ago
},
)
: (orders == null || orders.length == 0
? NoDataView(
src: "assets/image/ding_dan.webp",
isShowBtn: false,
text: "目前暂无记录,手上那么多积分要赶紧用掉哦~",
fontSize: 16.sp,
margin: EdgeInsets.only(top: 120.h, left: 72, right: 72),
)
: ListView.builder(
itemCount: orders == null ? 0 : orders.length,
itemBuilder: (context, position) {
return buildOrder(orders[position]);
},
)),
);
}
String orderStatus(state) {
String orderStatus = "";
switch (state) {
case 1:
orderStatus = S.of(context).weiwancheng;
break;
case 2:
orderStatus = S.of(context).yiwancheng;
break;
case 9:
orderStatus = S.of(context).yiquxiao;
break;
}
return orderStatus;
}
Widget buildOrder(ExchangeOrder exchangeOrder) {
return Container(
4 years ago
margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w, 8.h),
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
4 years ago
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
]),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"创建时间 : ${exchangeOrder.createTime}",
style: TextStyle(
color: Colors.black,
3 years ago
fontWeight: MyFontWeight.semi_bold,
4 years ago
fontSize: 14.sp,
4 years ago
),
),
Text(
exchangeOrder.payStatus != 1
? "未支付"
: ((exchangeOrder.useTyped == 1)
? ((exchangeOrder.sendStatus == 3 ||
exchangeOrder.sendStatus == 9)
? "已自提"
: "待提货")
: (exchangeOrder.useTyped == 2
? ((exchangeOrder.sendStatus == 1) ? "待发货" : "已发货")
: orderStatus(exchangeOrder.state))),
style: TextStyle(
color: Color(0xFFFE951E),
3 years ago
fontWeight: MyFontWeight.semi_bold,
4 years ago
fontSize: 14.sp,
4 years ago
),
)
],
),
SizedBox(
4 years ago
height: 16.h,
),
exchangeOrder.useTyped == 1
? Container(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"自提门店" + " :",
style: TextStyle(
color: Color(0xFF353535),
fontWeight: MyFontWeight.regular,
fontSize: 12.sp,
),
),
SizedBox(
width: 8.w,
),
Expanded(
child: Text(
exchangeOrder.storeName ?? "",
style: TextStyle(
color: Colors.black,
fontWeight: MyFontWeight.regular,
fontSize: 12.sp,
),
),
)
],
),
SizedBox(
height: 8.h,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
S.of(context).zitidizhi + " :",
style: TextStyle(
color: Color(0xFF353535),
fontWeight: MyFontWeight.regular,
fontSize: 12.sp,
),
),
SizedBox(
width: 8.w,
),
Expanded(
child: Text(
exchangeOrder.address ?? "",
style: TextStyle(
color: Colors.black,
fontWeight: MyFontWeight.regular,
fontSize: 12.sp,
),
),
)
],
),
SizedBox(
height: 8.h,
),
Row(
children: [
Text(
S.of(context).zitishijian + " :",
style: TextStyle(
color: Color(0xFF353535),
fontWeight: MyFontWeight.regular,
fontSize: 12.sp,
),
),
SizedBox(
width: 8.h,
),
Expanded(
child: Text(
S.of(context).duihuanhouwugegongzuori,
style: TextStyle(
color: Colors.black,
fontWeight: MyFontWeight.regular,
fontSize: 12.sp,
),
),
)
],
),
],
),
)
: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (exchangeOrder.useTyped != 3)
Text(
S.of(context).shouhuodi + " :",
style: TextStyle(
color: Color(0xFF353535),
fontWeight: MyFontWeight.regular,
fontSize: 12.sp,
),
),
SizedBox(
width: 8.w,
),
Expanded(
child: Text(
exchangeOrder.recAddress ?? "",
style: TextStyle(
color: Colors.black,
fontWeight: MyFontWeight.regular,
fontSize: 12.sp,
),
),
)
],
),
SizedBox(
4 years ago
height: 16.h,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
3 years ago
MImage(
(exchangeOrder != null &&
exchangeOrder.creditOrderDetailList != null)
? exchangeOrder.creditOrderDetailList[0].goodsMainImg
: "",
errorSrc: "assets/image/default_1.webp",
fadeSrc: "assets/image/default_1.webp",
3 years ago
width: 66,
height: 66,
fit: BoxFit.cover,
),
SizedBox(
4 years ago
width: 12.w,
),
Expanded(
child: SizedBox(
4 years ago
height: 66.h,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
exchangeOrder.creditOrderDetailList[0].name,
4 years ago
overflow: TextOverflow.ellipsis,
style: TextStyle(
4 years ago
fontSize: 14.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF353535)),
4 years ago
),
SizedBox(
3 years ago
height: 5.h,
4 years ago
),
Text(
exchangeOrder.useTyped == 3
? S.of(context).feishiwuduihuanma
: exchangeOrder
.creditOrderDetailList[0].description,
4 years ago
maxLines: 2,
style: TextStyle(
fontSize: 10.sp,
3 years ago
fontWeight: MyFontWeight.regular,
4 years ago
color: Color(0xFF727272),
),
4 years ago
),
],
),
4 years ago
),
flex: 1,
),
Text(
"x${(exchangeOrder.creditOrderDetailList[0].goodsNumber).toString()}",
style: TextStyle(
4 years ago
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.regular,
color: Color(0xFF353535),
4 years ago
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
// Text(
// S.of(context).shangpinjifen(90),
// style: TextStyle(
// fontSize: 12,
// color: Color(0xFFA0A0A0),
// ),
// ),
// SizedBox(
// width: 4,
// ),
Text(
exchangeOrder?.amount == null || exchangeOrder.amount == "0"
? ""
: exchangeOrder.payType == 2
? "实付印章 ${exchangeOrder.amount}印章"
: (S.of(context).shifujifen(exchangeOrder.amount) +
(exchangeOrder?.creditOrderDetailList[0]?.money ==
null ||
exchangeOrder
?.creditOrderDetailList[0]?.money ==
"0.00"
? ""
: " + ${double.parse(exchangeOrder?.creditOrderDetailList[0]?.money.toString()) * exchangeOrder?.creditOrderDetailList[0].goodsNumber}")),
style: TextStyle(
4 years ago
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
color: Colors.black,
),
),
],
),
SizedBox(
4 years ago
height: 12.h,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
IconText(
"${S.of(context).dingdanbianhao}: ${exchangeOrder.orderCode}",
leftImage: "assets/image/bianhao.webp",
iconSize: 16,
textStyle: TextStyle(
4 years ago
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.regular,
color: Color(0xFF353535),
),
),
if (exchangeOrder.useTyped != 3)
(exchangeOrder.useTyped == 1
? GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
// if (exchangeOrder.state == 1) {
// receive2Card(exchangeOrder.id);
// } else {
// Navigator.of(context)
// .pushNamed('/router/write_off_page', arguments: {});
// }
Navigator.of(context).pushNamed(
'/router/exchange_write_offPage',
arguments: {
"exchangeOrder": exchangeOrder.toJson(),
});
},
child: buildBtnStatus(exchangeOrder.state),
)
: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).pushNamed(
'/router/logistics_information_page',
arguments: {
"orderId": exchangeOrder
.creditOrderDetailList[0].orderId,
"logisticsNum": "",
"logisticsName": "",
"productNum": exchangeOrder
.creditOrderDetailList[0].goodsNumber,
"skuImg": exchangeOrder
.creditOrderDetailList[0].goodsMainImg
});
},
child: buildBtnStatusTow(exchangeOrder.sendStatus),
))
],
)
],
),
);
4 years ago
}
Widget buildOrderSm() {
return Container(
margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w, 8.h),
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
]),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 153.w,
height: 20.h,
),
),
Spacer(),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 44.w,
height: 20.h,
),
)
],
),
SizedBox(
height: 16.h,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 50.w,
height: 17.h,
),
),
SizedBox(
width: 9.w,
),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 225.w,
height: 17.h,
),
)
],
),
SizedBox(
height: 10.h,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 50.w,
height: 17.h,
),
),
SizedBox(
width: 10.w,
),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 164.w,
height: 17.h,
),
)
],
),
SizedBox(
height: 16.h,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 66.h,
height: 66.h,
),
),
SizedBox(
width: 12.w,
),
Expanded(
child: Container(
height: 66.h,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 44.w,
height: 20.h,
),
),
SizedBox(
height: 5.h,
),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 213.w,
height: 20.h,
),
),
],
),
),
flex: 1,
),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 17.w,
height: 20.h,
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 91.w,
height: 20.h,
),
),
],
),
SizedBox(
height: 12.h,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 135.w,
height: 17.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,
),
)
],
)
],
),
);
}
4 years ago
receive2Card(id) async {
BaseData baseData = await apiService.creditOrderReceive(id);
4 years ago
if (baseData != null && baseData.isSuccess) {
_refresh();
4 years ago
}
}
Widget buildBtnStatus(state) {
if (state == 1) {
4 years ago
return RoundButton(
padding: EdgeInsets.fromLTRB(8, 4, 8, 4),
text: S.of(context).chakanhexiaoma,
textColor: Colors.white,
fontSize: 12,
backgroup: Color(0xFF32A060),
radius: 2,
);
} else {
return Container();
// return BorderText(
// text: S.of(context).shanchudingdan,
// textColor: Color(0xFF32A060),
// borderWidth: 1,
// borderColor: Color(0xFF32A060),
// fontSize: 12,
// padding: EdgeInsets.fromLTRB(14, 4, 14, 4),
// );
}
}
Widget buildBtnStatusTow(state) {
if (state == 2) {
return RoundButton(
padding: EdgeInsets.fromLTRB(8, 4, 8, 4),
text: S.of(context).chakanwuliu,
4 years ago
textColor: Colors.white,
fontSize: 12,
backgroup: Color(0xFF32A060),
radius: 2,
);
} else {
return Container();
// return BorderText(
// text: S.of(context).shanchudingdan,
// textColor: Color(0xFF32A060),
// borderWidth: 1,
// borderColor: Color(0xFF32A060),
// fontSize: 12,
// padding: EdgeInsets.fromLTRB(14, 4, 14, 4),
// );
4 years ago
}
}
@override
bool get wantKeepAlive => true;
4 years ago
}