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.

330 lines
11 KiB

3 years ago
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/coupon.dart';
3 years ago
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/flutter_utils.dart';
3 years ago
import 'package:huixiang/utils/font_weight.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/view_widget/classic_header.dart';
3 years ago
import 'package:huixiang/view_widget/item_title.dart';
import 'package:huixiang/view_widget/my_footer.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
3 years ago
class DiscountZone extends StatefulWidget {
final List<Coupon> coupon;
DiscountZone(this.coupon);
3 years ago
@override
State<StatefulWidget> createState() {
return _DiscountZone();
}
}
class _DiscountZone extends State<DiscountZone> {
ApiService apiService;
@override
void initState() {
super.initState();
3 years ago
}
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
3 years ago
margin: EdgeInsets.only(top: 24.h),
3 years ago
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Padding(padding:EdgeInsets.symmetric(horizontal: 14.w),
3 years ago
child: Text(
"特惠专区",
style: TextStyle(
color: Color(0xFF0D0D0D),
fontSize: 15.sp,
fontWeight: FontWeight.bold,
),
)),
if(widget.coupon.length != 0)
3 years ago
Container(
3 years ago
height: 100.h,
margin: EdgeInsets.only(top: 10.h),
3 years ago
child: ListView.builder(
scrollDirection: Axis.horizontal,
physics: BouncingScrollPhysics(),
3 years ago
padding: EdgeInsets.symmetric(horizontal: 10.w),
3 years ago
itemBuilder: (context, position) {
3 years ago
return GestureDetector(
onTap: (){
Navigator.of(context).pushNamed('/router/welfare_page');
},
child: discountItem(widget.coupon[position]),
);
3 years ago
},
3 years ago
itemCount:widget.coupon.length>5?5:widget.coupon.length,
3 years ago
),
),
],
),
);
}
Widget discountItem(Coupon coupon) {
3 years ago
return Container(
width: 290.w,
3 years ago
height: 100.h,
3 years ago
decoration: BoxDecoration(
image: DecorationImage(
3 years ago
fit: BoxFit.fill,
3 years ago
image: AssetImage("assets/image/discount.webp"),
),
),
margin: EdgeInsets.only(right: 10.w),
3 years ago
child: Row(
3 years ago
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
3 years ago
children: [
Expanded(
flex: 2,
child: Container(
3 years ago
margin: EdgeInsets.only(top: 12.h,bottom: 12.h,left: 20.w,right: 27.w),
child: Column(
3 years ago
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
3 years ago
(coupon != null ? coupon.couponName ?? "" : ""),
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 14.sp,
3 years ago
height: 1.5,
fontWeight: MyFontWeight.semi_bold,
3 years ago
color: Color(0xFFFFA607),
),
3 years ago
),
3 years ago
SizedBox(height:5.w),
(coupon.useStartTime == null &&
coupon.useEndTime == null)?
Text(
S.of(context).quantian,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
3 years ago
color: Color(0xFFFFA607),
),
):Text(
"有效期至 ${coupon.useEndTime.substring(0, coupon.useEndTime.indexOf(" "))}",
maxLines:1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
3 years ago
color: Color(0xFFFFA607),
),
3 years ago
),
],
),
)),
3 years ago
Expanded(
flex: 1,
child:Container(
3 years ago
margin: EdgeInsets.only(top: 12.h,bottom: 12.h),
3 years ago
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(child: Container(
3 years ago
padding: EdgeInsets.only(right: 5.w),
3 years ago
child:discountWidget(coupon),
)),
],
),
)),
],
)
);
}
Widget discountWidget(Coupon coupon) {
if (coupon.bizType == 1) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
3 years ago
Text(
"¥",
3 years ago
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.medium,
3 years ago
color: coupon.status == 3 ? Color(0xFFB3B3B3):Color(0xFFFFFFFF),
3 years ago
),
),
SizedBox(
height: 4.h,
),
3 years ago
Text(
coupon != null
? double.tryParse("${coupon.discountAmount}" ?? "0").toInt()
.toString()
: "",
3 years ago
style: TextStyle(
fontSize: 30.sp,
3 years ago
fontWeight: FontWeight.w900,
color: coupon.status == 3 ? Color(0xFFB3B3B3):Color(0xFFFFFFFF),
3 years ago
),
),
],
),
Text(
S.of(context).manyuankeyong(coupon != null
? ("${coupon.fullAmount}" ?? "0")
.toString()
: ""),
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.semi_bold,
3 years ago
color: coupon.status == 3 ? Color(0xFFB3B3B3):Color(0xFFFFFFFF),
),
),
],
);
} else if (coupon.bizType == 3) {
return Column(
3 years ago
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
3 years ago
padding: EdgeInsets.only(bottom:10,top: 7,left: 12),
child: Text(
S.of(context).duihuanquan,
style: TextStyle(
fontSize: 26.sp,
fontWeight: MyFontWeight.semi_bold,
3 years ago
color: coupon.status == 3 ? Color(0xFFB3B3B3):Color(0xFFFFFFFF),
3 years ago
),
),
),
Text(
S.of(context).xianshangshiyong,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.semi_bold,
3 years ago
color: coupon.status == 3 ? Color(0xFFB3B3B3):Color(0xFFFFFFFF),
),
),
],
);
} else if (coupon.bizType == 5) {
return Column(
3 years ago
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
3 years ago
padding: EdgeInsets.only(bottom:10,top: 7,left: 12),
child: Text(
S.of(context).duihuanquan,
style: TextStyle(
fontSize: 26.sp,
fontWeight: MyFontWeight.semi_bold,
3 years ago
color: coupon.status == 3 ? Color(0xFFB3B3B3):Color(0xFFFFFFFF),
3 years ago
),
),
),
Text(
S.of(context).xianxiashiyong,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.semi_bold,
3 years ago
color: coupon.status == 3 ? Color(0xFFB3B3B3):Color(0xFFFFFFFF),
),
),
],
);
3 years ago
} else if (coupon.bizType == 6) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Text(
"¥",
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.medium,
color: coupon.status == 3 ? Color(0xFFB3B3B3):Color(0xFFFFFFFF),
),
),
SizedBox(
height: 4.h,
),
Text(
coupon != null
? "${AppUtils.calculateDouble(double.tryParse(coupon.limitAmount) ?? 0)}"
3 years ago
: "",
style: TextStyle(
fontSize: 28.sp,
fontWeight: FontWeight.w900,
color: coupon.status == 3 ? Color(0xFFB3B3B3):Color(0xFFFFFFFF),
),
),
],
),
],
);
}else{
return Column(
3 years ago
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
3 years ago
Text(
coupon != null
? "${(coupon.discountPercent / 10.0 >= 10) ? 10 : coupon.discountPercent / 10.0}" ??
"0"
: "",
3 years ago
style: TextStyle(
fontSize: 30.sp,
fontWeight: FontWeight.w900,
3 years ago
color: coupon.status == 3 ? Color(0xFFB3B3B3):Color(0xFFFFFFFF),
3 years ago
),
),
SizedBox(
height: 4.h,
),
3 years ago
Text(
"",
3 years ago
style: TextStyle(
3 years ago
fontSize: 14.sp,
fontWeight: MyFontWeight.semi_bold,
3 years ago
color: coupon.status == 3 ? Color(0xFFB3B3B3):Color(0xFFFFFFFF),
3 years ago
),
),
],
),
3 years ago
],
);
}
3 years ago
}
3 years ago
}