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.

280 lines
13 KiB

3 years ago
import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/store_info.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/item_title.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/view_widget/round_button.dart';
import 'package:huixiang/view_widget/separator.dart';
class UnionCoupon extends StatefulWidget {
final StoreInfo storeInfo;
3 years ago
final bool coupon;
3 years ago
final Function(String id) receiveCoupon;
3 years ago
UnionCoupon(this.storeInfo, this.receiveCoupon, {this.coupon = false});
3 years ago
@override
State<StatefulWidget> createState() {
return _UnionCoupon();
}
}
class _UnionCoupon extends State<UnionCoupon> {
@override
Widget build(BuildContext context) {
3 years ago
return (widget.coupon != null &&
widget.coupon &&
(widget.storeInfo != null && widget.storeInfo.couponVOList != null))
? buildCoupon()
: Column(
children: [
Container(
margin: EdgeInsets.only(top: 10.h, bottom: 10.h),
child: ItemTitle(
text: S.of(context).youhuiquan,
imgPath: "assets/image/icon_union_coupons.png",
),
),
(widget.storeInfo != null &&
widget.storeInfo.couponVOList != null)
? buildCoupon()
: Container(
width: double.infinity,
height: 50.h,
alignment: Alignment.center,
child: Text(
S.of(context).zanwuyouhuiquankelingqu,
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFFA0A0A0),
),
),
),
],
);
3 years ago
}
Widget buildCoupon() {
return Container(
height: 109.h,
child: ListView.builder(
3 years ago
itemCount:
(widget.storeInfo != null && widget.storeInfo.couponVOList != null)
? widget.storeInfo.couponVOList.length
: 0,
3 years ago
physics: BouncingScrollPhysics(parent: PageScrollPhysics()),
scrollDirection: Axis.horizontal,
itemBuilder: (context, position) {
return Container(
width: MediaQuery.of(context).size.width * 0.784,
margin: EdgeInsets.only(left: 6.w),
child: AspectRatio(
aspectRatio: 2.86,
child: Stack(
children: [
Image.asset(
"assets/image/icon_union_coupons_bg.png",
fit: BoxFit.fill,
width: double.infinity,
height: double.infinity,
),
Container(
padding: EdgeInsets.only(
left: 24.w,
right: 24.w,
bottom: 17.h,
top: 11.h,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
margin: EdgeInsets.only(left: 5),
child: Text.rich(TextSpan(children: [
TextSpan(
text: (widget.storeInfo != null &&
3 years ago
widget.storeInfo.couponVOList != null &&
widget.storeInfo.couponVOList[position]
.bizType ==
1)
3 years ago
? "¥"
: "",
style: TextStyle(
fontSize: 22.sp,
color: Color(0xFFFF7A1A),
fontWeight: MyFontWeight.semi_bold,
),
),
TextSpan(
text: (widget.storeInfo != null &&
3 years ago
widget.storeInfo.couponVOList != null &&
widget.storeInfo.couponVOList[position]
.bizType ==
1)
3 years ago
? "${double.tryParse(widget.storeInfo.couponVOList[position].discountAmount).toInt()}"
: (widget.storeInfo != null &&
3 years ago
widget.storeInfo.couponVOList !=
null &&
widget
.storeInfo
.couponVOList[position]
.bizType ==
5)
? S.of(context).duihuanquan
: "${widget.storeInfo.couponVOList[position].discountPercent ~/ 10}",
3 years ago
style: TextStyle(
fontSize: 36.sp,
color: Color(0xFFFF7A1A),
fontWeight: MyFontWeight.semi_bold,
),
),
])),
alignment: Alignment.center,
),
Container(
margin: EdgeInsets.only(
top: 12.h,
bottom: 12.h,
left: 15.w,
right: 24.w,
),
child: MySeparator(
width: 1.w,
height: 5.h,
color: Color(0xFF979797),
),
),
Expanded(
child: Container(
margin: EdgeInsets.only(
bottom: 12.h,
top: 12.h,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
(widget.storeInfo != null &&
3 years ago
widget.storeInfo.couponVOList != null)
? widget.storeInfo.couponVOList[position]
.couponName
3 years ago
: "",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 10.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF727272),
),
),
Text(
(widget.storeInfo != null &&
3 years ago
widget.storeInfo.couponVOList != null)
3 years ago
? (widget.storeInfo.couponVOList[position]
3 years ago
.bizType ==
1
? S.of(context).manlijiandaijinquan(
double.tryParse(widget
.storeInfo
.couponVOList[position]
.fullAmount)
.toInt(),
double.tryParse(widget
.storeInfo
.couponVOList[position]
.discountAmount)
.toInt())
: S.of(context).quanchangzhe(widget
.storeInfo
.couponVOList[position]
.discountPercent))
3 years ago
: "",
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFFFF7A1A),
),
),
Text(
S.of(context).youxiaoqizhi(
3 years ago
(widget.storeInfo != null &&
widget.storeInfo.couponVOList !=
null &&
// widget.storeInfo.couponVOList[position].useStartTime != null &&
widget
.storeInfo
.couponVOList[position]
.useEndTime !=
null)
// ? "${widget.storeInfo.couponVOList[position].useStartTime.replaceAll("-", ".").split(" ")[0]}-${widget.storeInfo.couponVOList[position].useEndTime.replaceAll("-", ".").split(" ")[0]}"
? "${widget.storeInfo.couponVOList[position].useEndTime.replaceAll("-", ".").split(" ")[0]}"
: "",
),
3 years ago
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: TextStyle(
fontSize: 8.sp,
color: Color(0xFFA29E9E),
),
),
],
),
),
),
InkWell(
onTap: () {
if (widget.storeInfo != null &&
widget.storeInfo.couponVOList != null &&
3 years ago
widget.storeInfo.couponVOList[position]
.status ==
0) {
3 years ago
widget.receiveCoupon(
widget.storeInfo.couponVOList[position].id);
}
},
child: Container(
height: 25.h,
child: RoundButton(
text: (widget.storeInfo != null &&
3 years ago
widget.storeInfo.couponVOList != null &&
widget.storeInfo.couponVOList[position]
.status >
0)
3 years ago
? S.of(context).yilingqu
: S.of(context).lingqu,
textColor: Colors.white,
backgroup: (widget.storeInfo != null &&
3 years ago
widget.storeInfo.couponVOList != null &&
widget.storeInfo.couponVOList[position]
.status >
0)
3 years ago
? Colors.grey
: Color(0xFF32A060),
padding: EdgeInsets.symmetric(
horizontal: 8.w, vertical: 4.h),
fontSize: 12.sp,
),
),
),
],
),
),
],
),
),
);
},
),
);
}
3 years ago
}