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.
 
 
 
 
 
 

479 lines
16 KiB

import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/activity.dart';
import 'package:huixiang/retrofit/data/activity_order_list.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/store_info.dart';
import 'package:huixiang/retrofit/min_api.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/font_weight.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:huixiang/view_widget/my_footer.dart';
import 'package:huixiang/view_widget/my_tab.dart';
import 'package:huixiang/view_widget/no_data_view.dart';
import 'package:huixiang/view_widget/round_button.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:shared_preferences/shared_preferences.dart';
class BargainGroupOrder extends StatefulWidget {
final Map<String, dynamic> arguments;
BargainGroupOrder({this.arguments});
@override
State<StatefulWidget> createState() {
return _BargainGroupOrder();
}
}
class _BargainGroupOrder extends State<BargainGroupOrder>
with SingleTickerProviderStateMixin {
List<Widget> tabs;
List<Widget> _pages;
TabController tabcontroller;
int type = 0;
@override
void initState() {
super.initState();
type = widget.arguments["type"];
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (tabcontroller == null)
tabcontroller = TabController(length: 4, vsync: this);
tabs = [
MyTab(
text: S.of(context).quanbu,
),
MyTab(
text: "进行中",
),
MyTab(
text: "成功",
),
MyTab(
text: "失败",
)
];
_pages = [
ExchangeHistoryList(0,type),
ExchangeHistoryList(2,type),
ExchangeHistoryList(3,type),
ExchangeHistoryList(4,type)
];
}
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 4,
child: Scaffold(
appBar: MyAppBar(
title:type == 1 ? S.of(context).wodepintuan :S.of(context).wodekanjia,
titleColor: Colors.black,
titleSize: 18.sp,
background: Color(0xFFFFFFFF),
leadingColor: Colors.black,
toolbarHeight: kToolbarHeight + MediaQuery.of(context).padding.top,
bottom: PreferredSize(
preferredSize: Size(double.infinity, 38.h),
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,
),
),
),
body: TabBarView(
children: _pages,
controller: tabcontroller,
),
),
);
}
}
class ExchangeHistoryList extends StatefulWidget {
final int orderStatus;
final int type;
ExchangeHistoryList(this.orderStatus,this.type);
@override
State<StatefulWidget> createState() {
return _ExchangeHistoryList();
}
}
class _ExchangeHistoryList extends State<ExchangeHistoryList> with AutomaticKeepAliveClientMixin{
MinApiService minService;
List<ActivityOrderList> activityOrderList = [];
RefreshController _refreshController = RefreshController(initialRefresh: false);
ApiService apiService;
StoreInfo storeInfo;
List<Activity> activitys;
String storeId;
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) {
String minToken = value.getString("minToken");
String tenant = value.getString("tenant");
String storeId = value.getString("storeId");
minService = MinApiService(
Dio(),
context: context,
token: minToken,
tenant: tenant,
storeId: storeId,
showLoading: true
);
queryShowMyActList();
});
}
///查看我的拼团、砍价、列表
queryShowMyActList() async {
BaseData<List<ActivityOrderList>> baseData =
await minService.showMyActList({
"state":widget.orderStatus,
"type" :widget.type,
}).catchError((error) {
_refreshController.loadFailed();
_refreshController.refreshFailed();
});
if (baseData != null && baseData.isSuccess) {
_refreshController.refreshCompleted();
setState(() {
activityOrderList.clear();
if(baseData.data.length > 0)
activityOrderList.addAll(baseData.data);
queryStoreInfo();
});
} else {
_refreshController.refreshFailed();
_refreshController.loadFailed();
}
}
/// 查询店铺信息
queryStoreInfo() async {
if (apiService == null) {
SharedPreferences value = await SharedPreferences.getInstance();
apiService = ApiService(
Dio(),
context: context,
token: value.getString("token"),
);
}
BaseData baseData =
await apiService.queryStoreInfo(activityOrderList[0].storeId).catchError((error) {
debugPrint(error.toString());
});
if (baseData != null && baseData.isSuccess) {
storeInfo = StoreInfo.fromJson(baseData.data);
activitys = storeInfo.informationVOPageVO.list
.map((e) => Activity.fromJson(e))
.toList();
if (mounted) {
setState(() {});
}
}
EasyLoading.dismiss();
}
_refresh() {
queryShowMyActList();
}
@override
Widget build(BuildContext context) {
return Container(
child: SmartRefresher(
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
footer: CustomFooter(
builder: (BuildContext context, LoadStatus mode) {
return MyFooter(mode);
},
),
controller: _refreshController,
physics: BouncingScrollPhysics(),
// onLoading: _refresh,
onRefresh: _refresh,
child: (activityOrderList != null && activityOrderList.length > 0)
?
ListView.builder(
itemCount: activityOrderList?.length ?? 0,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, position) {
return bargainOrder(activityOrderList[position]);
},
):NoDataView(
src: "assets/image/ding_dan.webp",
isShowBtn: false,
text: "还没有订单,快去下一单吧~",
fontSize: 16.sp,
margin: EdgeInsets.only(top: 120.h),
),
),
);
}
Widget bargainOrder(ActivityOrderList activityOrderList) {
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:21.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(
activityOrderList?.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(
(widget.type == 1)?(widget.orderStatus == 4 ? "拼团失败" :(activityOrderList.howManyMore != 0 ? "还差${activityOrderList?.howManyMore ?? 0}人拼团成功" : "拼团成功"))
:(activityOrderList.actRecordState == 1 ? "待支付" :(widget.orderStatus == 4 ? "砍价失败" : (activityOrderList.howManyMoney != "0.00" ? "还差¥${activityOrderList?.howManyMoney ?? 0}砍价成功" : "砍价成功"))),
style: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.bold,
color: widget.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_(activityOrderList?.joinTime ?? ""),
style: TextStyle(
fontSize: 10.sp,
color: Color(0xFF727272),
),
),
SizedBox(
height: 8.h,
),
Container(
height: 81.h,
margin: EdgeInsets.only(right: 12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MImage(
activityOrderList?.productImg ?? "",
width: 81.w,
height: 81.h,
fit: BoxFit.cover,
errorSrc: "assets/image/default_1.webp",
fadeSrc: "assets/image/default_1.webp",
),
SizedBox(
width: 10,
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
activityOrderList?.storeName ?? "",
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.medium,
color: Color(0xFF353535),
),
),
Text(
activityOrderList?.productSkuName ?? "",
style: TextStyle(
fontSize: 10.sp,
fontWeight: MyFontWeight.medium,
color: Color(0xFF727272),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"x1",
style: TextStyle(
fontSize: 10.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF727272),
),
),
Text.rich(
TextSpan(
children: [
TextSpan(
// text: "已砍至:",
text: S.of(context).heji,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: Color(0xFF868686),
),
),
TextSpan(
text:activityOrderList?.orderSum ?? "0",
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF32A060),
),
),
TextSpan(
text: "",
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: Color(0xFF868686),
),
),
],
),
),
],
),
],
)),
],
),
),
],
),
),
SizedBox(
height: 12.h,
),
Container(
margin: EdgeInsets.only(right: 12.w, bottom: 16.h),
child: Directionality(
textDirection: TextDirection.rtl,
child: Row(
children: [
GestureDetector(
onTap: () {
if(widget.type == 1) {
Navigator.of(context)
.pushNamed('/router/group_details', arguments: {
"actRecordId": activityOrderList.actRecordId,
"limitNumber":activityOrderList.successNumber,
});
}else{
Navigator.of(context)
.pushNamed('/router/bargain_details',arguments: {
"actRecordId": activityOrderList.actRecordId,
"limitNumber":activityOrderList.successNumber,
"storeInfo":storeInfo,
}).then((value) {
_refresh();
setState(() {});
});
}
},
child: RoundButton(
height: 25.h,
text: "查看详情",
textColor: Colors.white,
fontSize: 12.sp,
backgroup: Color(0xFF32A060),
radius: 2,
padding: EdgeInsets.fromLTRB(17.w,0, 17.w,0),
),
),
],
),
),
),
],
),
);
}
@override
bool get wantKeepAlive => true;
}