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.
 
 
 
 
 
 

183 lines
5.9 KiB

import 'package:flutter/material.dart';
import 'package:huixiang/data/min_order_info.dart';
import 'package:huixiang/data/settle_order_info.dart';
import 'package:huixiang/data/store_info.dart';
import 'package:huixiang/settlement/settlement_view/coupon.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class SettlementCoupon extends StatefulWidget {
final StoreInfo? storeInfo;
final MinOrderInfo? minOrderInfo;
final int tableId;
final SettleOrderInfo? settleOrderInfo;
final CouponListBean? couponBean;
SettlementCoupon(
this.settleOrderInfo,
this.minOrderInfo,
this.tableId,
this.storeInfo, {
this.couponBean,
});
@override
State<StatefulWidget> createState() {
return _SettlementCoupon();
}
}
class _SettlementCoupon extends State<SettlementCoupon> {
List<CouponListBean> couponCan = [];
List<CouponListBean> couponNo = [];
@override
void initState() {
super.initState();
couponCan.clear();
couponNo.clear();
if (widget.tableId > 0) {
if (widget.minOrderInfo?.orderInfoVo?.couponList != null &&
widget.minOrderInfo!.orderInfoVo?.couponList?.isNotEmpty) {
widget.minOrderInfo!.orderInfoVo?.couponList.forEach((element) {
if (element["usable"]) {
couponCan.add(CouponListBean.fromJson(element));
} else {
couponNo.add(CouponListBean.fromJson(element));
}
});
setState(() {});
}
} else {
if ((widget.settleOrderInfo?.couponList?.isNotEmpty ?? false)) {
widget.settleOrderInfo!.couponList?.forEach((element) {
if (element.usable ?? false) {
couponCan.add(element);
} else {
couponNo.add(element);
}
});
setState(() {});
}
}
}
@override
Widget build(BuildContext context) {
return StatefulBuilder(
builder: (context1, state) {
return Container(
alignment: Alignment.topCenter,
width: double.infinity,
height: MediaQuery.of(context).size.height / 3 * 2,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8),
topRight: Radius.circular(8),
),
),
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.only(
top: 16,
left: 16,
right: 16,
bottom: 8,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Text(
"可用优惠券(${couponCan.length})",
style: TextStyle(
color: Color(0xFF000000),
fontSize: 14.sp,
fontWeight: MyFontWeight.medium,
),
),
),
InkWell(
onTap: () {
Navigator.of(context).pop();
},
child: Image.asset(
"assets/image/cancel.webp",
width: 24,
height: 24,
),
),
],
),
),
Container(
padding: EdgeInsets.only(
top: 8,
left: 16,
right: 16,
),
child: ListView.builder(
itemCount: couponCan == null ? 0 : couponCan.length,
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemBuilder: (context, position) {
return CouponWidget(
couponCan[position],
widget.storeInfo,
selected: widget.couponBean?.id == couponCan[position].id,
);
},
),
),
if (couponNo.isNotEmpty)
Container(
padding: EdgeInsets.only(
top: 16,
left: 16,
right: 16,
bottom: 8,
),
child: Text(
"不可用优惠券",
style: TextStyle(
color: Color(0xFF000000),
fontSize: 14.sp,
fontWeight: MyFontWeight.medium,
),
),
),
if (couponNo.isNotEmpty)
Container(
padding: EdgeInsets.only(
top: 8,
left: 16,
right: 16,
),
child: ListView.builder(
itemCount: couponNo == null ? 0 : couponNo.length,
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemBuilder: (context, position) {
return CouponWidget(
couponNo[position],
widget.storeInfo,
);
},
),
),
],
),
),
);
},
);
}
}