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.
 
 
 
 
 
 

524 lines
18 KiB

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/data/base_data.dart';
import 'package:huixiang/data/logistics.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/utils/shared_preference.dart';
import 'package:huixiang/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/custom_image.dart';
import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/view_widget/my_footer.dart';
import 'package:huixiang/view_widget/no_data_view.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
class LogisticsInformationPage extends StatefulWidget {
final arguments;
LogisticsInformationPage({this.arguments});
@override
State<StatefulWidget> createState() {
return _LogisticsInformationPage();
}
}
class _LogisticsInformationPage extends State<LogisticsInformationPage> {
ApiService? apiService;
late RefreshController _refreshController;
@override
void initState() {
super.initState();
_refreshController = RefreshController();
apiService = ApiService(Dio(), context: context, token: SharedInstance.instance.token);
if ((widget.arguments["shipperCode"] ?? "") != "" && (widget.arguments["logisticsNum"] ?? "") != "") {
getShippingTrace(widget.arguments["shipperCode"] ?? "", widget.arguments["logisticsNum"] ?? "");
} else {
queryAppShippingTrace(widget.arguments["orderId"]);
}
}
List<Traces> logistics = [];
String shipStatus = "";
getShippingTrace(String shipperCode, String logisticCode) async {
BaseData<Logistics>? baseData = await apiService?.shippingTrace(shipperCode, logisticCode)
.catchError((error) {
_refreshController.refreshFailed();
_refreshController.loadFailed();
return BaseData<Logistics>()..isSuccess = false;
});
if (baseData?.isSuccess ?? false) {
Logistics? lgs = baseData!.data;
logistics.clear();
//lgs.traces.reversed:列表倒叙
logistics.addAll(lgs?.traces ?? []);
setState(() {
shipStatus = logisticsStatus(lgs?.state);
if (logistics.length > 0) {
String acceptStation = logistics[0].acceptStation ?? "";
logistics[0].acceptStation = acceptStation + shipStatus;
}
_refreshController.refreshCompleted();
_refreshController.loadComplete();
});
} else {
_refreshController.refreshFailed();
_refreshController.loadFailed();
}
}
queryAppShippingTrace(orderId) async {
BaseData<Logistics>? baseData =
await apiService?.getAppShippingTrace(orderId).catchError((error) {
_refreshController.refreshFailed();
_refreshController.loadFailed();
});
if (baseData?.isSuccess ?? false) {
Logistics? lgs = baseData!.data;
logistics.clear();
//lgs.traces.reversed:列表倒叙
logistics.addAll(lgs?.traces ?? []);
setState(() {
shipStatus = logisticsStatus(lgs?.state);
widget.arguments["logisticsName"] = lgs?.shipperCode;
widget.arguments["logisticsNum"] = lgs?.logisticCode;
if (logistics.length > 0) {
String acceptStation = logistics[0].acceptStation ?? "";
logistics[0].acceptStation = acceptStation + shipStatus;
}
_refreshController.refreshCompleted();
_refreshController.loadComplete();
});
} else {
_refreshController.refreshFailed();
_refreshController.loadFailed();
}
}
_onRefresh() {
if ((widget.arguments["shipperCode"] ?? "") != "" &&
(widget.arguments["logisticsNum"] ?? "") != "")
getShippingTrace(widget.arguments["shipperCode"] ?? "",
widget.arguments["logisticsNum"] ?? "");
else
queryAppShippingTrace(widget.arguments["orderId"]);
}
@override
void dispose() {
super.dispose();
_refreshController.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppBar(
background: Color(0xFFF7F7F7),
title: S.of(context).wuliuxinxi,
titleColor: Colors.black,
leadingColor: Colors.black,
),
body: SmartRefresher(
controller: _refreshController,
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
},
),
onRefresh: () {
_onRefresh();
},
physics: BouncingScrollPhysics(),
scrollController: ScrollController(),
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
children: [
_orderInformation(),
SizedBox(
height: 16.h,
),
Container(
margin: EdgeInsets.symmetric(
vertical: 8.h,
horizontal: 16.w,
),
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.vertical(
top: Radius.circular(8.w),
bottom: Radius.circular(4.w),
),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 2),
blurRadius: 14,
spreadRadius: 0,
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(bottom: 32.h),
child: Text(
S.of(context).dingdangenzong,
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.bold,
color: Color(0xff353535),
),
),
),
Container(
child: (logistics.length > 0)
? ListView.builder(
itemCount: logistics.length ?? 0,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, position) {
return orderTrackItem(logistics[position],
position, logistics.length);
},
)
: NoDataView(
src: "assets/image/ding_dan.webp",
isShowBtn: false,
text: "暂无物流信息~",
fontSize: 16.sp,
margin: EdgeInsets.only(top: 120),
),
),
],
),
),
],
),
),
),
);
}
Widget _orderInformation() {
return Container(
margin: EdgeInsets.only(left: 16.w, right: 16.w),
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(4),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 2),
blurRadius: 14,
spreadRadius: 0,
),
],
),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
alignment: Alignment.bottomCenter,
children: [
MImage(
widget.arguments["skuImg"] != null
? widget.arguments["skuImg"]
: "",
width: 95,
height: 95,
fit: BoxFit.cover,
errorSrc: "assets/image/default_1.webp",
fadeSrc: "assets/image/default_1.webp",
),
Container(
padding: EdgeInsets.only(
left: 32.w,
right: 32.w,
top: 5.h,
bottom: 5.h,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(0),
bottomLeft: Radius.circular(4),
topRight: Radius.circular(0),
bottomRight: Radius.circular(4),
),
color: Color(0x53000000),
),
child: Text.rich(
TextSpan(
children: [
TextSpan(
text: S.of(context).gong,
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.w400,
color: Colors.white,
),
),
TextSpan(
text: widget.arguments["productNum"].toString() ?? "",
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.w400,
color: Colors.white,
),
),
TextSpan(
text: S.of(context).jian,
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.w400,
color: Colors.white,
),
),
],
),
),
),
],
),
SizedBox(
width: 12.w,
),
Expanded(
flex: 1,
child: Container(
height: 95.h,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
S.of(context).wuliuzhuangtai,
style: TextStyle(
color: Color(0xff353535),
fontSize: 14.sp,
fontWeight: FontWeight.w400,
),
),
Text(
shipStatus,
style: TextStyle(
color: Color(0xFF32A060),
fontSize: 14.sp,
fontWeight: FontWeight.bold,
),
)
],
),
SizedBox(
height: 8.h,
),
Row(
children: [
Text(
S.of(context).wuliugongsi,
style: TextStyle(
color: Color(0xff353535),
fontSize: 14.sp,
),
),
Text(
widget.arguments["logisticsName"] ?? "",
style: TextStyle(
color: Colors.black,
fontSize: 14.sp,
fontWeight: FontWeight.w400,
),
)
],
),
SizedBox(
height: 8.h,
),
Row(
children: [
Text(
S.of(context).wuliudanhao,
style: TextStyle(
color: Color(0xff353535),
fontSize: 14.sp,
fontWeight: FontWeight.w400,
),
),
Text(
widget.arguments["logisticsNum"] ?? "",
style: TextStyle(
color: Colors.black,
fontSize: 14.sp,
fontWeight: FontWeight.w400,
),
),
],
),
],
),
),
),
],
),
],
),
);
}
Widget orderTrackItem(Traces logistics, var position, var size) {
return IntrinsicHeight(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
children: [
Text(
logistics.acceptTime?.split(" ")[0] ?? "",
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.medium,
color: Color(0xff353535),
),
),
SizedBox(
height: 5.h,
),
Text(
logistics.acceptTime?.split(" ")[1] ?? "",
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.medium,
color: Color(0xff868686),
),
),
],
),
SizedBox(
width: 28.w,
),
Column(
children: [
Image.asset(
tripStatus(logistics.acceptStation ?? ""),
width: 24.w,
height: 24.h,
),
if (position != size - 1)
Container(
width: 1.w,
height: (logistics.acceptStation?.length ?? 0) > 100
? 118.h
: 75.h,
decoration: new BoxDecoration(
color: Color(0xffE1E1E1),
),
),
],
),
SizedBox(
width: 28.w,
),
Expanded(
flex: 1,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (logisticsTripStatus(logistics.acceptStation ?? "") != "")
Text(
logisticsTripStatus(logistics.acceptStation ?? ""),
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.medium,
color: Colors.black,
),
),
SizedBox(
height: 10.h,
),
Text(
logistics.acceptStation ?? "",
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: Color(0xff353535),
),
),
],
),
),
],
),
);
}
String logisticsStatus(state) {
String logisticsStatus = "";
switch (state) {
case 2:
logisticsStatus = "运输中";
break;
case 3:
logisticsStatus = "已签收";
break;
case 4:
logisticsStatus = "问题件";
break;
}
return logisticsStatus;
}
String tripStatus(String type) {
String tripStatus = "assets/image/icon_sign.webp";
if (type.contains("已签收")) {
tripStatus = "assets/image/icon_sign.webp";
} else if (type.contains("派送中") || type.contains("派件")) {
tripStatus = "assets/image/icon_delivery.webp";
} else if (type.contains("揽收") || type.contains("揽收")) {
tripStatus = "assets/image/icon_delivery.webp";
} else if (type.contains("运输中") || type.contains("发往")) {
tripStatus = "assets/image/icon_transport.webp";
} else if (type.contains("已发货") || type.contains("分配")) {
tripStatus = "assets/image/icon_deliver_goods.webp";
} else if (type.contains("已下单")) {
tripStatus = "assets/image/icon_place_ order.webp";
}
return tripStatus;
}
String logisticsTripStatus(String state) {
String logisticsTripStatus = "";
if (state.contains("已签收")) {
logisticsTripStatus = "已签收";
} else if (state.contains("揽收")) {
logisticsTripStatus = "已揽件";
} else if (state.contains("派送中") || state.contains("派件")) {
logisticsTripStatus = "派送中";
} else if (state.contains("运输中") || state.contains("发往")) {
logisticsTripStatus = "运输中";
} else if (state.contains("已发货") || state.contains("分配")) {
logisticsTripStatus = "已发货";
} else if (state.contains("已下单")) {
logisticsTripStatus = "已下单";
}
return logisticsTripStatus;
}
}