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.
655 lines
20 KiB
655 lines
20 KiB
import 'package:flutter/material.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
import 'package:huixiang/generated/l10n.dart'; |
|
import 'package:huixiang/retrofit/data/min_order_info.dart'; |
|
import 'package:huixiang/retrofit/data/order_product_vo.dart'; |
|
import 'package:huixiang/retrofit/data/settleOrderInfo.dart'; |
|
import 'package:huixiang/utils/flutter_utils.dart'; |
|
import 'package:huixiang/utils/font_weight.dart'; |
|
import 'package:huixiang/view_widget/custom_image.dart'; |
|
import 'package:huixiang/view_widget/separator.dart'; |
|
|
|
import '../../retrofit/data/shoppingCart.dart'; |
|
|
|
class SettlementOrderCommodity extends StatefulWidget { |
|
final int isTakeOut; |
|
final int diningStatus; |
|
final int tableId; |
|
|
|
final SettleOrderInfo settleOrderInfo; |
|
final MinOrderInfo minOrderInfo; |
|
final String pageType; |
|
final bool useVipPriceSelect; |
|
final bool showVipTips; |
|
final bool useBenefitSelect; |
|
final bool placeOrder; |
|
|
|
SettlementOrderCommodity( |
|
this.isTakeOut, |
|
this.diningStatus, |
|
this.settleOrderInfo, |
|
this.minOrderInfo, |
|
this.tableId, |
|
this.pageType, |
|
this.useVipPriceSelect, |
|
this.showVipTips, |
|
this.useBenefitSelect, |
|
this.placeOrder); |
|
|
|
@override |
|
State<StatefulWidget> createState() { |
|
return _SettlementOrderCommodity(); |
|
} |
|
} |
|
|
|
class _SettlementOrderCommodity extends State<SettlementOrderCommodity> { |
|
@override |
|
Widget build(BuildContext context) { |
|
return Stack( |
|
alignment: Alignment.centerRight, |
|
children: [ |
|
Container( |
|
margin: EdgeInsets.only( |
|
left: 16.w, |
|
right: 16.w, |
|
top: 16.h, |
|
bottom: 8.h, |
|
), |
|
padding: EdgeInsets.only( |
|
left: 20.w, |
|
right: 20.w, |
|
top: 12.h, |
|
bottom: 12.h, |
|
), |
|
decoration: BoxDecoration( |
|
color: Colors.white, |
|
boxShadow: [ |
|
BoxShadow( |
|
color: Colors.black.withAlpha(12), |
|
offset: Offset(0, 1), |
|
blurRadius: 12, |
|
spreadRadius: 0, |
|
), |
|
], |
|
borderRadius: BorderRadius.circular(8), |
|
), |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
children: commodityList(), |
|
), |
|
), |
|
Visibility( |
|
child: buildQrCode(), |
|
visible: false, |
|
), |
|
], |
|
); |
|
} |
|
|
|
List<Widget> commodityList() { |
|
if (widget.settleOrderInfo == null) return []; |
|
List<Widget> widgets = []; |
|
|
|
if (widget.minOrderInfo != null) { |
|
widgets.addAll(widget.minOrderInfo.orderProductVOList |
|
.map((e) => commodityItem(e)) |
|
.toList()); |
|
} else if (widget.settleOrderInfo != null) { |
|
widgets.addAll(widget.settleOrderInfo.orderProductList |
|
.map((e) => commodityItem(e)) |
|
.toList()); |
|
} |
|
widgets.add(SizedBox(height: 20.h)); |
|
|
|
if (widget.isTakeOut != 0) { |
|
// 配送费 |
|
widgets.add( |
|
discountItem( |
|
Color(0xFFFF7A1A), |
|
widget.isTakeOut == 1 |
|
? S.of(context).peisongfei |
|
: S.of(context).yunfei, |
|
"", |
|
(widget.minOrderInfo != null) |
|
? "+ ${widget.minOrderInfo?.postFee ?? "0"}" |
|
: "+ ${widget.settleOrderInfo?.postAge ?? "0"}", |
|
), |
|
); |
|
} |
|
|
|
if (widget.diningStatus == 3 && widget.isTakeOut != 2) { |
|
//打包费 |
|
widgets.add( |
|
discountItem( |
|
Color(0xFFFF7A1A), |
|
"打包费", |
|
"", |
|
(widget.minOrderInfo != null) |
|
? "+ ${widget.minOrderInfo?.totalPackagingFee ?? "0"}" |
|
: "+ ${widget.settleOrderInfo?.totalPackagingFee ?? "0"}", |
|
), |
|
); |
|
} |
|
|
|
if (widget.useVipPriceSelect && |
|
widget.settleOrderInfo.memberVO.isVip && |
|
(widget.tableId > 0 |
|
? !(widget?.minOrderInfo?.isRaise ?? false) |
|
: !(widget?.settleOrderInfo?.isRaise ?? false)) && |
|
(widget?.settleOrderInfo?.discountType == "VIP" && |
|
widget?.settleOrderInfo?.vipDiscountAmount != "0")) { |
|
widgets.add(vipItem( |
|
Color(0xFFFF7A1A), |
|
"VIP优惠", |
|
AppUtils.calculateDouble(double.tryParse( |
|
(widget.minOrderInfo != null && |
|
widget.minOrderInfo.orderProductVOList != null) |
|
? (widget.minOrderInfo?.discountAmount ?? "") |
|
: (widget?.settleOrderInfo?.vipDiscountAmount ?? ""))))); |
|
} |
|
|
|
if (widget.useBenefitSelect && |
|
(widget?.settleOrderInfo?.discountType == "SURPRISE" && |
|
widget?.settleOrderInfo?.vipDayDiscountAmount != "0") && |
|
((widget.tableId > 0 |
|
? !(widget?.minOrderInfo?.isRaise ?? false) |
|
: !(widget?.settleOrderInfo?.isRaise ?? false)))) { |
|
widgets.add(vipItem( |
|
Color(0xFFFF7A1A), |
|
"会员日优惠金额", |
|
AppUtils.calculateDouble(double.tryParse( |
|
(widget.minOrderInfo != null && |
|
widget.minOrderInfo.orderProductVOList != null) |
|
? (widget.minOrderInfo?.discountAmount ?? "") |
|
: (widget?.settleOrderInfo?.vipDayDiscountAmount ?? ""))))); |
|
} |
|
|
|
if (widget.useBenefitSelect && |
|
((widget?.settleOrderInfo?.discountType == "MEMBER_RANK") && |
|
widget?.settleOrderInfo?.benefitDiscountAmount != "0") && |
|
((widget.tableId > 0 |
|
? !(widget?.minOrderInfo?.isRaise ?? false) |
|
: !(widget?.settleOrderInfo?.isRaise ?? false)))) { |
|
widgets.add(vipItem( |
|
Color(0xFFFF7A1A), |
|
"会员优惠金额", |
|
AppUtils.calculateDouble(double.tryParse( |
|
(widget.minOrderInfo != null && |
|
widget.minOrderInfo.orderProductVOList != null) |
|
? (widget.minOrderInfo?.benefitDiscountAmount ?? "") |
|
: (widget?.settleOrderInfo?.benefitDiscountAmount ?? ""))))); |
|
} |
|
|
|
if (widget.showVipTips) { |
|
widgets.add(GestureDetector( |
|
child: Container( |
|
alignment: Alignment.centerLeft, |
|
child: Text.rich( |
|
TextSpan( |
|
children: [ |
|
TextSpan( |
|
text: "您未购买回乡VIP卡,无法享受优惠,", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Colors.black, |
|
), |
|
), |
|
TextSpan( |
|
text: "点击立即购买", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFFFF7A1A), |
|
), |
|
), |
|
], |
|
), |
|
), |
|
), |
|
onTap: () { |
|
Navigator.of(context).pushNamedAndRemoveUntil( |
|
'/router/main_page', (route) => false, |
|
arguments: {"index": 2}); |
|
}, |
|
)); |
|
} |
|
|
|
widgets.add(Container( |
|
margin: EdgeInsets.only( |
|
top: 24.h, |
|
bottom: 4.h, |
|
), |
|
child: MySeparator( |
|
height: 1, |
|
width: 5.w, |
|
color: Colors.grey, |
|
), |
|
)); |
|
widgets.add(buildTotalPrice()); |
|
return widgets; |
|
} |
|
|
|
Widget commodityItem(OrderProductVOList productList) { |
|
return Container( |
|
margin: EdgeInsets.only(top: 8.h, bottom: 8.h), |
|
child: Column( |
|
children: [ |
|
Row( |
|
children: [ |
|
MImage( |
|
productList.skuImg, |
|
width: 55, |
|
height: 55, |
|
fit: BoxFit.cover, |
|
radius: BorderRadius.circular(4), |
|
errorSrc: "assets/image/default_1.webp", |
|
fadeSrc: "assets/image/default_1.webp", |
|
), |
|
Expanded( |
|
flex: 1, |
|
child: Container( |
|
margin: EdgeInsets.only( |
|
left: 8.w, |
|
), |
|
// height: 44.h, |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text( |
|
productList.productName, |
|
maxLines: 1, |
|
overflow: TextOverflow.ellipsis, |
|
style: TextStyle( |
|
fontWeight: FontWeight.bold, |
|
fontSize: 14.sp, |
|
color: Color(0xFF353535), |
|
), |
|
), |
|
SizedBox( |
|
height: 4.h, |
|
), |
|
Text( |
|
productList.skuNameStr != null |
|
? "${productList.skuNameStr ?? ""}" |
|
: "", |
|
overflow: TextOverflow.ellipsis, |
|
style: TextStyle( |
|
fontSize: 10.sp, |
|
color: Color(0xFFA29E9E), |
|
), |
|
), |
|
Text( |
|
"x${productList.buyNum}", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
color: Color(0xFF727272), |
|
), |
|
), |
|
], |
|
), |
|
), |
|
), |
|
Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.end, |
|
children: [ |
|
Text( |
|
productList.buyNum > 1 |
|
? S.of(context).yuan_(AppUtils.calculateDouble( |
|
double.tryParse(productList.sellPrice ?? "0") - |
|
AppUtils.stringAsFixedDouble2((double.tryParse( |
|
productList.discountAmount ?? "0") / |
|
productList.buyNum)))) |
|
: S.of(context).yuan_(AppUtils.calculateDouble( |
|
double.tryParse(productList.sellPrice ?? "0") - |
|
double.tryParse( |
|
productList.discountAmount ?? "0"))), |
|
style: TextStyle( |
|
fontWeight: MyFontWeight.medium, |
|
fontSize: 14.sp, |
|
color: Color(0xFF4C4C4C), |
|
), |
|
), |
|
if (productList.discountAmount != null && |
|
productList.discountAmount != "0") |
|
Text( |
|
S.of(context).yuan_(productList.sellPrice), |
|
style: TextStyle( |
|
fontWeight: MyFontWeight.regular, |
|
fontSize: 12.sp, |
|
fontFamily: 'JDZhengHT', |
|
decoration: TextDecoration.lineThrough, |
|
color: Color(0xFFA29E9E), |
|
), |
|
) |
|
], |
|
), |
|
], |
|
), |
|
if (productList.setMealDataList.length != 0) |
|
ListView.builder( |
|
itemCount: productList.setMealDataList.length, |
|
scrollDirection: Axis.vertical, |
|
physics: BouncingScrollPhysics(), |
|
shrinkWrap: true, |
|
padding: EdgeInsets.zero, |
|
itemBuilder: (context, index) { |
|
return orderMealsItem(productList.setMealDataList[index]); |
|
}, |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget orderMealsItem(SetMealDataList setMealDataList) { |
|
return Column(children: setMealDataList.productInfoList.map((e) { |
|
return Container( |
|
margin: EdgeInsets.symmetric( |
|
vertical: 10.h, |
|
), |
|
child: Row( |
|
children: [ |
|
Expanded( |
|
flex: 2, |
|
child: Text( |
|
e.productName, |
|
overflow: TextOverflow.ellipsis, |
|
maxLines: 1, |
|
style: TextStyle( |
|
color: Color(0xffA29E9E), |
|
fontSize: 14.sp, |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
), |
|
), |
|
Expanded( |
|
flex: 3, |
|
child: Text( |
|
"${(e.skuName == "") ? "" : e.skuName}", |
|
overflow: TextOverflow.ellipsis, |
|
maxLines: 1, |
|
style: TextStyle( |
|
color: Color(0xffA29E9E), |
|
fontSize: 13.sp, |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
), |
|
), |
|
Text( |
|
"x${e.buyNumber.toString()}", |
|
overflow: TextOverflow.ellipsis, |
|
maxLines: 1, |
|
style: TextStyle( |
|
color: Color(0xffFF7A1A), |
|
fontSize: 13.sp, |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
), |
|
], |
|
), |
|
); |
|
}).toList(),); |
|
} |
|
|
|
Widget discountItem(Color color, textName, condition, amount) { |
|
return Container( |
|
margin: EdgeInsets.only(top: 9.h, bottom: 9.h), |
|
child: Row( |
|
children: [ |
|
Container( |
|
padding: EdgeInsets.fromLTRB(4.w, 2.h, 4.w, 2.h), |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.all(Radius.circular(2)), |
|
border: Border.all( |
|
width: 1, |
|
color: color, |
|
style: BorderStyle.solid, |
|
), |
|
), |
|
child: Text( |
|
textName, |
|
style: TextStyle( |
|
fontSize: 10.sp, |
|
color: color, |
|
), |
|
), |
|
), |
|
SizedBox( |
|
width: 27.w, |
|
), |
|
Expanded( |
|
child: Text( |
|
condition ?? "", |
|
style: TextStyle( |
|
fontSize: 10.sp, |
|
color: Color(0xFFA29E9E), |
|
), |
|
), |
|
flex: 1, |
|
), |
|
Text( |
|
S.of(context).yuan_("$amount"), |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
color: color, |
|
fontFamily: 'JDZhengHT', |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget vipItem(Color color, textName, vipDiscount) { |
|
return Container( |
|
margin: EdgeInsets.only(top: 9.h, bottom: 9.h), |
|
child: Row( |
|
children: [ |
|
Container( |
|
padding: EdgeInsets.fromLTRB(4.w, 2.h, 4.w, 2.h), |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.all(Radius.circular(2)), |
|
border: Border.all( |
|
width: 1, |
|
color: color, |
|
style: BorderStyle.solid, |
|
), |
|
), |
|
child: Text( |
|
textName, |
|
style: TextStyle( |
|
fontSize: 10.sp, |
|
color: color, |
|
), |
|
), |
|
), |
|
SizedBox( |
|
width: 27.w, |
|
), |
|
Spacer(), |
|
Text( |
|
S.of(context).yuan_("-¥$vipDiscount"), |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontFamily: 'JDZhengHT', |
|
color: color, |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget buildQrCode() { |
|
return Container( |
|
margin: EdgeInsets.only(right: 16.w), |
|
child: Stack( |
|
children: [ |
|
Container( |
|
width: 94.w, |
|
height: 33.h, |
|
margin: EdgeInsets.only(left: 12.w), |
|
padding: EdgeInsets.only(left: 16.w), |
|
decoration: BoxDecoration( |
|
color: Colors.white, |
|
boxShadow: [ |
|
BoxShadow( |
|
color: Colors.black.withAlpha(25), |
|
offset: Offset(0, 2), |
|
blurRadius: 3, |
|
spreadRadius: 0, |
|
) |
|
], |
|
borderRadius: BorderRadius.only( |
|
topLeft: Radius.circular(2), |
|
bottomLeft: Radius.circular(2), |
|
), |
|
), |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Text( |
|
S.of(context).qujianma, |
|
style: TextStyle( |
|
fontWeight: FontWeight.bold, |
|
fontSize: 12.sp, |
|
color: Colors.black, |
|
), |
|
), |
|
Icon( |
|
Icons.keyboard_arrow_right, |
|
color: Colors.black, |
|
size: 16, |
|
) |
|
], |
|
), |
|
), |
|
Container( |
|
margin: EdgeInsets.only(top: 6.h, bottom: 6.h), |
|
// padding: EdgeInsets.all(2), |
|
decoration: BoxDecoration( |
|
color: Colors.white, |
|
boxShadow: [ |
|
BoxShadow( |
|
color: Colors.black.withAlpha(25), |
|
offset: Offset(0, 1), |
|
blurRadius: 12, |
|
spreadRadius: 0, |
|
) |
|
], |
|
borderRadius: BorderRadius.circular(2), |
|
), |
|
child: Icon( |
|
Icons.qr_code, |
|
size: 20, |
|
color: Color(0xFF32A060), |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
String countAllGoods() { |
|
int count = 0; |
|
if (widget.minOrderInfo != null) { |
|
widget.minOrderInfo.orderProductVOList.forEach((element) { |
|
count += element.buyNum; |
|
}); |
|
} else if (widget.settleOrderInfo != null) { |
|
widget.settleOrderInfo.orderProductList.forEach((element) { |
|
count += element.buyNum; |
|
}); |
|
} |
|
return count.toString(); |
|
} |
|
|
|
Widget buildTotalPrice() { |
|
return Container( |
|
margin: EdgeInsets.only(top: 7.h, bottom: 11.h), |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.end, |
|
crossAxisAlignment: CrossAxisAlignment.baseline, |
|
textBaseline: TextBaseline.alphabetic, |
|
children: [ |
|
Expanded( |
|
child: Text( |
|
S.of(context).gongjijianshangpin(countAllGoods()), |
|
style: TextStyle( |
|
fontSize: 10.sp, |
|
color: Color(0xFFA29E9E), |
|
fontWeight: MyFontWeight.semi_bold, |
|
), |
|
), |
|
flex: 1, |
|
), |
|
Container( |
|
child: Text( |
|
"已优惠:¥${(widget.tableId > 0 ? (widget?.minOrderInfo?.isRaise ?? false) : (widget?.settleOrderInfo?.isRaise ?? false)) ? "0" : discountPrice()}", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontFamily: 'JDZhengHT', |
|
color: Color(0xFF7B7B7B), |
|
fontWeight: MyFontWeight.medium, |
|
), |
|
), |
|
), |
|
SizedBox( |
|
width: 15.w, |
|
), |
|
Container( |
|
child: Text( |
|
S.of(context).jiesuanjine, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
color: Color(0xFF353535), |
|
fontWeight: MyFontWeight.semi_bold, |
|
), |
|
), |
|
), |
|
SizedBox( |
|
width: 5.w, |
|
), |
|
Text( |
|
totalPrice(), |
|
textAlign: TextAlign.end, |
|
style: TextStyle( |
|
fontSize: 14.sp, |
|
color: Color(0xFF32A060), |
|
fontFamily: 'JDZhengHT', |
|
fontWeight: MyFontWeight.medium, |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
///已优惠金额 |
|
String discountPrice() { |
|
if (widget.minOrderInfo != null) { |
|
return AppUtils.calculateDouble( |
|
double.tryParse(widget.minOrderInfo?.totalDiscountPrice ?? "0")); |
|
} else if (widget.tableId < 0) { |
|
return "0"; |
|
} else { |
|
return AppUtils.calculateDouble( |
|
double.tryParse(widget?.settleOrderInfo?.totalDiscountAmount ?? "0")); |
|
} |
|
} |
|
|
|
String totalPrice() { |
|
if (widget.minOrderInfo != null && |
|
widget.minOrderInfo.orderProductVOList != null) { |
|
return "¥${AppUtils.calculateDouble( |
|
double.tryParse(widget.minOrderInfo.finalPayPrice))}"; |
|
} |
|
if (widget.settleOrderInfo.orderProductList == null) return ""; |
|
return "¥${AppUtils.calculateDouble( |
|
double.tryParse(widget.settleOrderInfo.price ?? ""))}"; |
|
} |
|
}
|
|
|