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.

686 lines
24 KiB

4 years ago
import 'package:barcode_widget/barcode_widget.dart';
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';
4 years ago
import 'package:huixiang/retrofit/data/order_info.dart';
import 'package:huixiang/retrofit/data/page.dart';
4 years ago
import 'package:huixiang/retrofit/data/vip_card.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/painter_bg.dart';
4 years ago
import 'package:huixiang/utils/status_utils.dart';
4 years ago
import 'package:huixiang/view_widget/custom_image.dart';
4 years ago
import 'package:huixiang/view_widget/my_footer.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
import 'package:pull_to_refresh/pull_to_refresh.dart';
4 years ago
import 'package:shared_preferences/shared_preferences.dart';
4 years ago
class VipDetailPage extends StatefulWidget {
4 years ago
final Map<String, dynamic> arguments;
VipDetailPage({this.arguments});
4 years ago
@override
State<StatefulWidget> createState() {
return _VipDetailPage();
}
}
class _VipDetailPage extends State<VipDetailPage> {
4 years ago
ApiService apiService;
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) {
apiService =
ApiService(Dio(), context: context, token: value.getString("token"));
vipDetail();
});
}
VipCard vipCard;
4 years ago
List<OrderInfo> orderInfos = [];
final RefreshController refreshController = RefreshController();
int current = 1;
4 years ago
vipDetail() async {
BaseData baseData = await apiService
.vipDetail(widget.arguments["id"])
.catchError((onError) {});
if (baseData != null && baseData.isSuccess) {
vipCard = VipCard.fromJson(baseData.data);
setState(() {});
}
4 years ago
BaseData order = await apiService.orderList({
"current": current,
"model": {"status": 0, "storeId": vipCard.storeId},
"order": "descending",
"size": 10,
"sort": "id"
});
if (order != null && order.isSuccess) {
PageInfo pageInfo = PageInfo.fromJson(order.data);
if (current == 1) {
orderInfos.clear();
}
orderInfos
.addAll(pageInfo.records.map((e) => OrderInfo.fromJson(e)).toList());
refreshController.loadComplete();
if (current * 10 > int.tryParse(pageInfo.total)) {
refreshController.loadNoData();
} else {
current += 1;
}
setState(() {});
} else {
refreshController.loadFailed();
}
4 years ago
}
4 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
S.of(context).huiyuankaxiangqing,
4 years ago
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
4 years ago
),
centerTitle: false,
backgroundColor: Color(0xFF3A405A),
brightness: Brightness.dark,
elevation: 0,
leading: GestureDetector(
onTap: () {
Navigator.of(context).pop();
},
child: Container(
alignment: Alignment.centerRight,
margin: EdgeInsets.only(left: 10),
padding: EdgeInsets.all(6),
child: Icon(
Icons.arrow_back_ios,
color: Colors.white,
size: 24,
),
),
),
titleSpacing: 2,
4 years ago
leadingWidth: 56.w,
4 years ago
),
4 years ago
body: Column(
children: [
Stack(
children: [
4 years ago
CustomPaint(
painter: BgPainter(
bgColor: Color(0xFF3A405A),
bezierHeight: 30.h,
),
child: Container(
height: 220.h,
),
4 years ago
),
4 years ago
buildVipCard(),
4 years ago
],
),
Padding(
4 years ago
padding: EdgeInsets.only(left: 16.w, top: 35.h, bottom: 16.h),
4 years ago
child: Row(
children: [
Text(
"历史订单",
overflow: TextOverflow.ellipsis,
style: TextStyle(
4 years ago
fontSize: 16.sp,
4 years ago
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
4 years ago
SizedBox(
4 years ago
width: 8.w,
4 years ago
),
4 years ago
Image.asset(
"assets/image/icon_history.png",
),
],
4 years ago
),
4 years ago
),
Expanded(
4 years ago
child: SmartRefresher(
controller: refreshController,
enablePullDown: false,
enablePullUp: true,
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
},
),
physics: BouncingScrollPhysics(),
child: ListView.builder(
itemBuilder: (context, position) {
return GestureDetector(
onTap: () {},
child: historyItem(orderInfos[position]),
);
},
itemCount: orderInfos != null ? orderInfos.length : 0,
),
4 years ago
),
4 years ago
),
4 years ago
],
4 years ago
),
);
}
4 years ago
Widget buildVipCard() {
4 years ago
return Container(
4 years ago
margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w, 8.h),
height: 220.h,
4 years ago
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.w),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
4 years ago
]),
4 years ago
child: Stack(
// alignment: Alignment.center,
children: [
Image.asset(
"assets/image/icon_vip_bj.png",
4 years ago
fit: BoxFit.fill, //填充剩余空间
4 years ago
height: 220.h,
4 years ago
),
Container(
4 years ago
padding: EdgeInsets.all(16.w),
4 years ago
child: Column(
4 years ago
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
4 years ago
MImage(
vipCard != null ? vipCard.storeLogo : "",
width: 40.w,
height: 40.h,
fit: BoxFit.cover,
errorSrc: "assets/image/default_1.png",
fadeSrc: "assets/image/default_1.png",
4 years ago
),
SizedBox(
4 years ago
width: 12.w,
4 years ago
),
Expanded(
child: Container(
4 years ago
height: 54.h,
4 years ago
child: Column(
4 years ago
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
4 years ago
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
4 years ago
Expanded(
child: Text(
vipCard != null ? vipCard.storeName : "",
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 20.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
),
4 years ago
),
4 years ago
flex: 1,
4 years ago
),
Image.asset(
"assets/image/icon_vip.png",
),
],
),
Text.rich(
4 years ago
TextSpan(
children: [
TextSpan(
text: "会员卡",
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
),
4 years ago
),
4 years ago
],
),
4 years ago
textDirection: TextDirection.ltr,
),
],
),
),
flex: 1,
)
],
),
4 years ago
Expanded(
child: Container(),
flex: 1,
4 years ago
),
4 years ago
Padding(
4 years ago
padding: EdgeInsets.only(left: 32.w, right: 32.w),
4 years ago
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
children: [
Text.rich(
4 years ago
TextSpan(
children: [
TextSpan(
text:
"¥${vipCard != null ? vipCard.balance : ""}",
style: TextStyle(
fontSize: 24.sp,
fontWeight: FontWeight.w500,
color: Colors.black,
),
4 years ago
),
4 years ago
],
),
4 years ago
),
GestureDetector(
4 years ago
onTap: () {
Navigator.of(context)
4 years ago
.pushNamed('/router/vip_balance', arguments: {"storeId":vipCard.id});
4 years ago
},
4 years ago
child: Row(
4 years ago
children: [
Text.rich(
4 years ago
TextSpan(
children: [
TextSpan(
text: S.of(context).yue,
style: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
),
4 years ago
),
4 years ago
],
),
4 years ago
),
Icon(
Icons.keyboard_arrow_right,
4 years ago
color: Colors.black,
4 years ago
size: 22.5,
),
],
),
),
],
),
Column(
children: [
Text.rich(
TextSpan(children: [
TextSpan(
text: "0",
4 years ago
style: TextStyle(
4 years ago
fontSize: 24.sp,
fontWeight: FontWeight.w500,
color: Colors.black,
),
4 years ago
),
]),
),
4 years ago
SizedBox(
4 years ago
height: 5.h,
4 years ago
),
4 years ago
Text.rich(
4 years ago
TextSpan(
children: [
TextSpan(
text: S.of(context).jifen,
style: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
),
4 years ago
),
4 years ago
],
),
4 years ago
),
],
),
],
4 years ago
),
),
Column(
children: [
Padding(
4 years ago
padding: EdgeInsets.only(top: 5.h, bottom: 5.h),
4 years ago
child: Text(
4 years ago
vipCard != null
? "${vipCard.id.substring(0, 4)} "
"${vipCard.id.substring(4, 8)} "
"${vipCard.id.substring(8, 12)} "
"${vipCard.id.substring(12, 16)} "
"${vipCard.id.substring(16, vipCard.id.length)}"
: "",
4 years ago
maxLines: 1,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.black,
fontSize: 14.sp,
4 years ago
wordSpacing: vipCard == null
? 10
: (MediaQuery.of(context).size.width - 64.w) /
(((vipCard.id.length) * 4)),
letterSpacing: vipCard == null
? 8
: (MediaQuery.of(context).size.width - 64.w) /
(((vipCard.id.length) * 4)),
4 years ago
),
4 years ago
),
),
BarcodeWidget(
barcode: Barcode.code128(),
data: '2673713263236786',
4 years ago
height: 30.h,
4 years ago
color: Colors.black,
drawText: false,
)
],
4 years ago
)
],
4 years ago
),
),
],
),
);
}
4 years ago
Widget historyItem(OrderInfo orderInfo) {
4 years ago
return Container(
4 years ago
margin: EdgeInsets.all(16.w),
4 years ago
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
4 years ago
width: 19.w,
height: 19.h,
4 years ago
margin: EdgeInsets.only(left: 12.w, top: 12.h),
4 years ago
alignment: Alignment.center,
decoration: new BoxDecoration(
color: Color(0xff32A060),
borderRadius: BorderRadius.circular(2),
),
4 years ago
child: Text(
4 years ago
(orderInfo != null && orderInfo.isTakeOut == 0) ? "" : "",
4 years ago
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),
),
),
),
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)
? StatusUtils.statusText(
context,
orderInfo.refundStatus,
orderInfo.orderStatus,
orderInfo.payStatus,
orderInfo.sendStatus,
orderInfo.isTakeOut)
: "",
4 years ago
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),
4 years ago
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
4 years ago
S.of(context).xiadanshijian_(
(orderInfo != null) ? orderInfo.createTime : ""),
4 years ago
style: TextStyle(
4 years ago
fontSize: 10.sp,
4 years ago
color: Color(0xFF727272),
),
),
SizedBox(
4 years ago
height: 8.h,
4 years ago
),
4 years ago
Row(
4 years ago
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
4 years ago
children: goodsItem(
(orderInfo != null && orderInfo.productList != null)
? orderInfo.productList
: null),
4 years ago
),
],
),
Padding(
4 years ago
padding: EdgeInsets.only(right: 22.w),
4 years ago
child: Image.asset(
"assets/image/icon_more.png",
fit: BoxFit.fill,
alignment: Alignment.centerRight,
4 years ago
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: [
4 years ago
Text.rich(
4 years ago
TextSpan(
4 years ago
children: [
TextSpan(
text: S.of(context).gong,
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF868686),
),
),
TextSpan(
text: (orderInfo != null &&
orderInfo.productList != null)
? "${orderInfo.productList.length}"
: "0",
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
TextSpan(
text: S.of(context).jian,
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF868686),
),
),
],
4 years ago
),
4 years ago
),
4 years ago
SizedBox(
width: 4.w,
),
4 years ago
Text.rich(
4 years ago
TextSpan(
4 years ago
children: [
TextSpan(
text: S.of(context).heji,
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF868686),
),
),
TextSpan(
text: totalPrice(orderInfo),
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
TextSpan(
text: S.of(context).yuan,
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF868686),
),
),
],
4 years ago
),
4 years ago
),
4 years ago
],
),
SizedBox(
height: 8.h,
),
Row(
4 years ago
children: (orderInfo != null)
? StatusUtils.statusBtn(
context,
orderInfo.payStatus,
orderInfo.orderStatus,
orderInfo.isTakeOut,
orderInfo.sendStatus,
orderInfo.refundStatus,
orderInfo.dayFlowCode)
: [],
4 years ago
),
],
),
),
4 years ago
),
],
),
);
}
4 years ago
bool isRemake = true;
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<ProductList> products) {
if (products == null) return [];
if (products.length > 3) {
products = products.sublist(0, 3);
}
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.h,
fit: BoxFit.contain,
errorSrc: "assets/image/default_1.png",
fadeSrc: "assets/image/default_1.png",
),
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
}