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.

718 lines
26 KiB

4 years ago
import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/coupon.dart';
import 'package:huixiang/utils/flutter_utils.dart';
3 years ago
import 'package:huixiang/utils/font_weight.dart';
4 years ago
import 'package:huixiang/view_widget/separator.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
class NewCouponWidget extends StatelessWidget {
4 years ago
final Function(int type) callback;
3 years ago
// final Function couponDialog;
4 years ago
final GestureTapCallback callbackEx;
final Coupon coupon;
3 years ago
final Function showCouponDetails;
4 years ago
final int type;
4 years ago
3 years ago
NewCouponWidget(this.coupon, this.callback,this.callbackEx,this.showCouponDetails, {this.type = 1});
4 years ago
@override
Widget build(BuildContext context) {
return buildCoupon(context);
4 years ago
}
String getCouponStoreName(){
String couponStoreName = coupon.tenantName;
if(coupon?.storeList != null && coupon.storeId != "0"){
coupon.storeList.forEach((element) {
if(element.id == coupon.storeId)
couponStoreName = element.storeName;
});
}
return couponStoreName;
}
3 years ago
///优惠券ui
4 years ago
Widget buildCoupon(BuildContext context) {
4 years ago
// if(coupon != null) {
// coupon.isEx = fa;
// }
3 years ago
// if (coupon != null) {
// print("object: ${coupon.toJson()}");
// }
4 years ago
return Container(
3 years ago
height: (coupon != null && coupon.isEx) ? 155.h : 135.h,
3 years ago
width: double.infinity,
margin: EdgeInsets.fromLTRB(14.w, 6.h, 14.w, 6.h),
padding: EdgeInsets.only(right: 5),
3 years ago
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(6),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 6.w,
height: double.infinity,
decoration: BoxDecoration(
borderRadius: new BorderRadius.only(
topLeft: Radius.circular(6),
bottomLeft: Radius.circular(6),
),
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3) :Color(0xFF32A060),
3 years ago
)
),
Expanded(
flex: 2,
child:Container(
3 years ago
margin: EdgeInsets.only(top: 14,left: 14,bottom: 14),
3 years ago
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"券名称:${coupon != null ? coupon.couponName ?? "" : ""}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 15.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF0D0D0D),
),
),
3 years ago
SizedBox(height:10,),
3 years ago
Expanded(child:
(coupon.useStartTime == null &&
coupon.useEndTime == null)?
Text(
S.of(context).quantian,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3) :Color(0xFF4D4D4D),
3 years ago
),
):Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"有效期: ",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3) :Color(0xFF4D4D4D),
3 years ago
),
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"${coupon?.useStartTime ??""} ~",
3 years ago
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3) :Color(0xFF4D4D4D),
3 years ago
),
),
3 years ago
SizedBox(height: 5,),
3 years ago
Text(
"${coupon?.useEndTime ?? ""}",
3 years ago
maxLines:1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3) :Color(0xFF4D4D4D),
3 years ago
),
)
],
)
],
),),
GestureDetector(
onTap: (){
3 years ago
showCouponDetails();
3 years ago
},
child: Row(
children: [
Text(
"使用详情",
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3):Color(0xFF4D4D4D),
3 years ago
),
),
Icon(
Icons.keyboard_arrow_right,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3) :Color(0xFF4D4D4D),
3 years ago
size: 20,
)
],
),
)
],
),
)),
Expanded(
flex: 1,
child:Container(
3 years ago
margin: EdgeInsets.only(top: 14,left: 12,bottom: 14,),
3 years ago
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(child: Container(
child: priceWidget(context),
)),
Container(
margin: EdgeInsets.only(right: 15.w),
3 years ago
child: rightBtn(context),
)
],
),
)),
],
),
);
Container(
3 years ago
height: (coupon != null && coupon.isEx) ? 168.h : 151.h,
4 years ago
width: double.infinity,
4 years ago
margin: EdgeInsets.fromLTRB(14.w, 6.h, 14.w, 6.h),
decoration: BoxDecoration(
3 years ago
color: Colors.white,
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
],
),
4 years ago
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
4 years ago
children: [
4 years ago
Expanded(
child: Container(
margin: EdgeInsets.only(top: 14.h, bottom: 8.h),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Container(
child: priceWidget(context),
4 years ago
),
4 years ago
flex: 1,
),
Expanded(
flex: 2,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
4 years ago
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
4 years ago
children: [
4 years ago
Container(
padding: EdgeInsets.fromLTRB(4, 2, 4, 2),
decoration: BoxDecoration(
borderRadius:
3 years ago
BorderRadius.circular(2),
4 years ago
border: Border.all(
width: 1,
color: Color(0xFFFF7A1A),
style: BorderStyle.solid,
4 years ago
),
4 years ago
),
child: Text(
S.of(context).shangjiaquan,
style: TextStyle(
4 years ago
fontSize: 10.sp,
3 years ago
fontWeight: MyFontWeight.medium,
4 years ago
color: Color(0xFFFF7A1A),
4 years ago
),
4 years ago
),
),
SizedBox(
4 years ago
width: 8.w,
4 years ago
),
4 years ago
Expanded(
child: Text(getCouponStoreName(),
4 years ago
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 16.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
4 years ago
color: Color(0xff353535),
),
4 years ago
),
4 years ago
flex: 1,
)
4 years ago
],
),
Text(
3 years ago
coupon != null ? coupon.couponName ?? "" : "",
4 years ago
overflow: TextOverflow.ellipsis,
4 years ago
style: TextStyle(
4 years ago
fontSize: 14.sp,
4 years ago
color: Color(0xff727272),
),
),
Row(
4 years ago
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
4 years ago
children: [
4 years ago
Visibility(
child: Text(
3 years ago
// S.of(context).quanchangtongyong,
(coupon?.allProduct ?? false) ? S.of(context).quanchangtongyong :"",
4 years ago
style: TextStyle(
color: Color(0xFF353535),
fontSize: 12.sp,
4 years ago
),
4 years ago
),
visible:
4 years ago
(coupon != null && (coupon.bizType == 1)) ??
false,
4 years ago
),
Container(
margin: EdgeInsets.only(right: 23.w),
child: rightBtn(context),
)
4 years ago
],
4 years ago
),
],
4 years ago
),
),
],
4 years ago
),
4 years ago
),
4 years ago
flex: (coupon != null && coupon.isEx) ? 97 : 97,
4 years ago
),
Container(
padding: EdgeInsets.symmetric(horizontal: 23.w),
child: MySeparator(
width: 5.w,
height: 1.h,
color: Color(0xFF353535),
),
),
Expanded(
flex: (coupon != null && coupon.isEx) ? 56 : 42,
child: Container(
3 years ago
margin: EdgeInsets.symmetric(horizontal: 23.w, vertical: 7.h),
4 years ago
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
4 years ago
children: [
4 years ago
Text(
S.of(context).xiangqing,
style: TextStyle(
color: Color(0xFF353535),
fontSize: 10.sp,
),
4 years ago
),
4 years ago
GestureDetector(
child: Icon(
(coupon != null && !coupon.isEx)
? Icons.keyboard_arrow_down
: Icons.keyboard_arrow_up,
color: Colors.black,
size: 18,
), //点击按钮布局
onTap: callbackEx,
4 years ago
),
4 years ago
],
),
4 years ago
if (coupon != null && coupon.isEx)
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
4 years ago
S.of(context).shiyongriqi,
4 years ago
style: TextStyle(
color: Color(0xFF353535),
fontSize: 10.sp,
),
),
Text(
(coupon.useStartTime == null &&
4 years ago
coupon.useEndTime == null)
3 years ago
? S.of(context).quantian
3 years ago
: "${coupon.useStartTime} - ${coupon.useEndTime}",
4 years ago
style: TextStyle(
color: Color(0xFF353535),
fontSize: 10.sp,
),
),
],
),
],
4 years ago
),
4 years ago
),
4 years ago
),
],
4 years ago
),
);
}
4 years ago
Widget priceWidget(BuildContext context) {
if (coupon.bizType == 1) {
return Column(
3 years ago
mainAxisAlignment: MainAxisAlignment.start,
4 years ago
crossAxisAlignment: CrossAxisAlignment.center,
children: [
3 years ago
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Text(
"¥",
style: TextStyle(
fontSize: 22.sp,
fontWeight: MyFontWeight.medium,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3):Color(0xff32A060),
4 years ago
),
3 years ago
),
SizedBox(
height: 4.h,
),
Text(
coupon != null
? double.tryParse("${coupon.discountAmount}" ?? "0")
.toInt()
.toString()
: "",
style: TextStyle(
fontSize: 35.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3):Color(0xff32A060),
4 years ago
),
3 years ago
),
],
4 years ago
),
Text(
S.of(context).manyuankeyong(coupon != null
? ("${coupon.fullAmount}" ?? "0")
4 years ago
.toString()
4 years ago
: ""),
style: TextStyle(
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3):Color(0xff32A060),
4 years ago
),
),
],
);
3 years ago
} else if (coupon.bizType == 3) {
return Column(
3 years ago
mainAxisAlignment: MainAxisAlignment.start,
3 years ago
crossAxisAlignment: CrossAxisAlignment.center,
children: [
3 years ago
Container(
padding: EdgeInsets.only(bottom:10,top: 7),
3 years ago
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
S.of(context).duihuanquan,
style: TextStyle(
3 years ago
fontSize: 26.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3):Color(0xff32A060),
3 years ago
),
),
],
),
),
Text(
S.of(context).xianshangshiyong,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.semi_bold,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3):Color(0xff32A060),
3 years ago
),
),
],
);
4 years ago
} else if (coupon.bizType == 5) {
return Column(
3 years ago
mainAxisAlignment: MainAxisAlignment.start,
4 years ago
crossAxisAlignment: CrossAxisAlignment.center,
children: [
3 years ago
Container(
padding: EdgeInsets.only(bottom:10,top: 7),
4 years ago
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
S.of(context).duihuanquan,
style: TextStyle(
3 years ago
fontSize: 26.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3):Color(0xff32A060),
4 years ago
),
),
],
),
),
Text(
S.of(context).xianxiashiyong,
style: TextStyle(
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3):Color(0xff32A060),
4 years ago
),
),
],
);
3 years ago
} else if (coupon.bizType == 6) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if(coupon?.limitAmount != "0.00")
3 years ago
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Text(
"¥",
style: TextStyle(
fontSize: 22.sp,
fontWeight: MyFontWeight.medium,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3):Color(0xff32A060),
3 years ago
),
),
SizedBox(
height: 4.h,
),
Text(
coupon != null
? "${AppUtils.calculateDouble(double.tryParse(coupon.limitAmount) ?? 0)}"
3 years ago
: "",
style: TextStyle(
fontSize: 35.sp,
fontWeight: MyFontWeight.semi_bold,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3):Color(0xff32A060),
3 years ago
),
),
],
),
],
);
}else {
4 years ago
return Column(
3 years ago
mainAxisAlignment: MainAxisAlignment.start,
4 years ago
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// if(coupon.discountPercent != 0)
3 years ago
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Text(
coupon.discountPercent != 0?( coupon != null
3 years ago
? "${(coupon.discountPercent / 10.0 >= 10) ? 10 : coupon.discountPercent / 10.0}" ??
"0"
: ""):"",
3 years ago
style: TextStyle(
fontSize: 37.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3):Color(0xff32A060),
4 years ago
),
3 years ago
),
SizedBox(
height: 4.h,
),
Text(
"${coupon.discountPercent != 0 ? "":""}",
3 years ago
style: TextStyle(
fontSize: 20.sp,
fontWeight: MyFontWeight.semi_bold,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3):Color(0xff32A060),
4 years ago
),
3 years ago
),
],
4 years ago
),
Text(
S.of(context).quanchangtongyong,
style: TextStyle(
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
color: (coupon.status ==2 || coupon.status == 3) ? Color(0xFFB3B3B3):Color(0xff32A060),
4 years ago
),
),
],
);
}
}
Widget rightBtn(context) {
4 years ago
if (type == 1) {
if (coupon != null && coupon.status == 0) {
return Align(
4 years ago
alignment: Alignment.centerRight,
child: InkWell(
onTap: () {
4 years ago
callback(type);
4 years ago
},
child: Container(
padding: EdgeInsets.fromLTRB(16.w, 2.h, 16.w, 2.h),
decoration: BoxDecoration(
3 years ago
borderRadius: BorderRadius.circular(10.5),
4 years ago
color: Color(0xFF32A060),
),
child: Text(
4 years ago
S.of(context).lingqu,
4 years ago
style: TextStyle(
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.medium,
4 years ago
color: Colors.white,
),
),
),
),
4 years ago
);
} else {
return Align(
alignment: Alignment.centerRight,
child: Container(
padding: EdgeInsets.fromLTRB(16.w, 2.h, 16.w, 2.h),
decoration: BoxDecoration(
3 years ago
borderRadius: BorderRadius.circular(10.5),
4 years ago
color: Colors.grey,
),
child: Text(
S.of(context).yilingqu,
style: TextStyle(
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.medium,
4 years ago
color: Colors.white,
),
4 years ago
),
),
4 years ago
);
}
4 years ago
} else {
4 years ago
if (coupon != null && coupon.status == 1) {
return Align(
4 years ago
alignment: Alignment.centerRight,
child: InkWell(
onTap: () {
callback(type);
},
child: Container(
3 years ago
width: 64.w,
height: 19.h,
4 years ago
decoration: BoxDecoration(
color: Color(0xFF32A060),
3 years ago
borderRadius: BorderRadius.circular(10),
4 years ago
),
3 years ago
alignment: Alignment.center,
child:Text(
"立即使用",
maxLines: 1,
overflow: TextOverflow.ellipsis,
4 years ago
style: TextStyle(
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.regular,
color: Color(0xFFFFFFFF),
4 years ago
),
),
4 years ago
),
3 years ago
// Container(
// padding: EdgeInsets.fromLTRB(16.w, 2.h, 16.w, 2.h),
// decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(10.5),
// color: Color(0xFF32A060),
// ),
// child: Text(
// (coupon.bizType == 5 || coupon.bizType == 3)
// ? S.of(context).quhexiao
// : S.of(context).qushiyong,
// style: TextStyle(
// fontSize: 12.sp,
// fontWeight: MyFontWeight.medium,
// color: Colors.white,
// ),
// ),
// ),
4 years ago
),
);
4 years ago
} else if (coupon != null && coupon.status == 2) {
return Align(
alignment: Alignment.centerRight,
child: Container(
padding: EdgeInsets.fromLTRB(16.w, 2.h, 16.w, 2.h),
decoration: BoxDecoration(
4 years ago
borderRadius: BorderRadius.circular(10.5),
4 years ago
// border: Border.all(
// width: 1, color: Color(0xFFA0A0A0), style: BorderStyle.solid)
color: Color(0xFFA0A0A0),
),
child: Text(
S.of(context).yishiyong,
style: TextStyle(
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.medium,
4 years ago
color: Colors.white,
),
),
4 years ago
),
4 years ago
);
} else {
return Align(
alignment: Alignment.centerRight,
child: Container(
padding: EdgeInsets.fromLTRB(16.w, 2.h, 16.w, 2.h),
3 years ago
// decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(10.5),
// // border: Border.all(
// // width: 1, color: Color(0xFFA0A0A0), style: BorderStyle.solid)
// color: Color(0xFFA0A0A0),
// ),
4 years ago
child: Text(
S.of(context).yishixiao,
style: TextStyle(
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFFB3B3B3),
4 years ago
),
4 years ago
),
),
4 years ago
);
}
4 years ago
}
4 years ago
}
3 years ago
4 years ago
}