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.
1027 lines
32 KiB
1027 lines
32 KiB
import 'package:dio/dio.dart'; |
|
import 'package:flutter/cupertino.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:flutter_easyloading/flutter_easyloading.dart'; |
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
|
import 'package:flutter_swiper/flutter_swiper.dart'; |
|
import 'package:huixiang/generated/l10n.dart'; |
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
import 'package:huixiang/retrofit/data/coupon.dart'; |
|
import 'package:huixiang/retrofit/data/goods.dart'; |
|
import 'package:huixiang/retrofit/data/page.dart'; |
|
import 'package:huixiang/retrofit/retrofit_api.dart'; |
|
import 'package:huixiang/utils/flutter_utils.dart'; |
|
import 'package:huixiang/utils/font_weight.dart'; |
|
import 'package:huixiang/view_widget/classic_header.dart'; |
|
import 'package:huixiang/view_widget/custom_image.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
import 'package:huixiang/view_widget/my_appbar.dart'; |
|
import 'package:huixiang/view_widget/my_footer.dart'; |
|
import 'package:huixiang/view_widget/new_coupon_widget.dart'; |
|
import 'package:huixiang/view_widget/no_data_view.dart'; |
|
import 'package:huixiang/view_widget/receive_success.dart'; |
|
import 'package:huixiang/view_widget/selector_store_dialog.dart'; |
|
import 'package:pull_to_refresh/pull_to_refresh.dart'; |
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
class WelfarePage extends StatefulWidget { |
|
@override |
|
State<StatefulWidget> createState() { |
|
return _WelfarePage(); |
|
} |
|
} |
|
|
|
class _WelfarePage extends State<WelfarePage> { |
|
ApiService apiService; |
|
final RefreshController refreshController = RefreshController(); |
|
List<Goods> goods = []; |
|
Goods goodsPrice; |
|
List<Coupon> coupons = []; |
|
List<List<Coupon>> coupon=[]; |
|
String categoryId; |
|
bool orderDesc = true; |
|
int orderType = 1; |
|
int type = 1; |
|
int couponIndex = 0; |
|
int swiperIndex = 0; |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
SharedPreferences.getInstance().then((value) => { |
|
apiService = ApiService(Dio(), context: context, token: value.getString("token")), |
|
queryGoods(), |
|
queryCoupon(), |
|
|
|
}); |
|
} |
|
|
|
queryGoods() async { |
|
if (apiService == null) { |
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
apiService = ApiService( |
|
Dio(), |
|
context: context, |
|
token: value.getString("token"), |
|
); |
|
} |
|
var param = { |
|
"categoryId": categoryId ?? "", |
|
"orderDesc": orderDesc, |
|
"orderType": orderType, |
|
"pageNum": 1, |
|
"pageSize": 100, |
|
"state": 1 |
|
}; |
|
BaseData<PageInfo<Goods>> pageGoods = |
|
await apiService.creditGoods(param).catchError((onError) { |
|
refreshController.loadFailed(); |
|
refreshController.refreshFailed(); |
|
}); |
|
EasyLoading.dismiss(); |
|
if (pageGoods != null && pageGoods.isSuccess) { |
|
setState(() { |
|
goods.clear(); |
|
goods.addAll(pageGoods.data.list); |
|
}); |
|
refreshController.refreshCompleted(); |
|
refreshController.loadComplete(); |
|
} else { |
|
refreshController.loadFailed(); |
|
refreshController.refreshFailed(); |
|
} |
|
} |
|
|
|
queryCoupon() async { |
|
if (apiService == null) { |
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
apiService = ApiService( |
|
Dio(), |
|
context: context, |
|
token: value.getString("token"), |
|
); |
|
} |
|
BaseData<PageInfo<Coupon>> baseData = await apiService.queryCoupon({ |
|
"centre": true, |
|
"pageNum": 1, |
|
"pageSize": 100, |
|
"searchKey": "", |
|
"state": 0 |
|
}).catchError((onError) { |
|
refreshController.refreshFailed(); |
|
refreshController.loadFailed(); |
|
}); |
|
coupons.clear(); |
|
coupon.clear(); |
|
if (baseData != null && baseData.isSuccess) { |
|
coupons.addAll(baseData.data.list); |
|
for(var i = 0;i < coupons.length~/3+1;i++){ |
|
List<Coupon> con = []; |
|
con = coupons.skip(i*3).take((i*3<coupons.length)?3:(coupons.length - (i*3))).toList(); |
|
coupon.add(con); |
|
} |
|
if(coupon.length > 0 && coupon[coupon.length - 1].isEmpty) |
|
coupon.removeAt(coupon.length-1); |
|
refreshController.refreshCompleted(); |
|
refreshController.loadComplete(); |
|
setState(() {}); |
|
} else { |
|
refreshController.refreshFailed(); |
|
refreshController.loadFailed(); |
|
} |
|
} |
|
|
|
|
|
_onRefresh(){ |
|
queryGoods(); |
|
// queryCoupon(); |
|
} |
|
|
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Stack( |
|
children: [ |
|
Container( |
|
decoration: BoxDecoration( |
|
image: DecorationImage( |
|
fit: BoxFit.fill, |
|
image: AssetImage("assets/image/welfare_zx.webp"), |
|
), |
|
), |
|
width: double.infinity, |
|
height: 236.h, |
|
), |
|
Scaffold( |
|
backgroundColor: Colors.transparent, |
|
appBar: MyAppBar( |
|
background: Colors.transparent, |
|
leadingColor: Colors.white, |
|
title: "福利中心", |
|
titleColor: Colors.white, |
|
titleSize: 18.sp, |
|
brightness: Brightness.dark, |
|
), |
|
body:SmartRefresher( |
|
controller: refreshController, |
|
enablePullDown: true, |
|
enablePullUp: false, |
|
header: MyHeader(), |
|
footer: CustomFooter( |
|
builder: (context, mode) { |
|
return MyFooter(mode); |
|
}, |
|
), |
|
onRefresh:(){ |
|
setState(() { |
|
_onRefresh(); |
|
}); |
|
}, |
|
physics: BouncingScrollPhysics(), |
|
scrollController: ScrollController(), |
|
child: Container( |
|
// margin: EdgeInsets.only(top:30.h,left: 14,right: 14), |
|
child: SingleChildScrollView( |
|
physics: BouncingScrollPhysics(), |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
weekCoupons(), |
|
|
|
Container( |
|
color: Colors.white, |
|
padding: EdgeInsets.only(left: 14,right: 14), |
|
child:Column( |
|
children: [ |
|
|
|
inviteFriends(), |
|
|
|
benefitExchange(), |
|
], |
|
), |
|
) |
|
|
|
// activityTask(), |
|
], |
|
), |
|
), |
|
), |
|
), |
|
), |
|
], |
|
); |
|
} |
|
|
|
/// 周券包推荐 |
|
Widget weekCoupons() { |
|
return Container( |
|
width: double.infinity, |
|
margin: EdgeInsets.only(top: 95), |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.circular(6), |
|
color: Colors.white, |
|
boxShadow: [ |
|
BoxShadow( |
|
color: Color(0x08213303).withAlpha(12), |
|
offset: Offset(0, 2), |
|
blurRadius: 3, |
|
spreadRadius: 0, |
|
), |
|
], |
|
), |
|
// margin: EdgeInsets.only(top: 139.h), |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Padding( |
|
padding: EdgeInsets.symmetric(horizontal: 17.w,vertical: 16.h), |
|
child: |
|
Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Text( |
|
S.of(context).lingquanzhongxin, |
|
style: TextStyle( |
|
color: Color(0xFF0D0D0D), |
|
fontSize: 15.sp, |
|
fontWeight: MyFontWeight.bold, |
|
), |
|
), |
|
Text( |
|
"每周三上新 ", |
|
style: TextStyle( |
|
color: Color(0xFF4D4D4D), |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
), |
|
], |
|
)), |
|
AspectRatio( |
|
aspectRatio: 1.10, |
|
child: Swiper( |
|
onIndexChanged: (it){ |
|
swiperIndex = it; |
|
}, |
|
index: couponIndex, |
|
viewportFraction: 0.9, |
|
scale: 0.7, |
|
key: UniqueKey(), |
|
pagination: SwiperPagination( |
|
alignment: Alignment.bottomCenter, |
|
builder: DotSwiperPaginationBuilder( |
|
size: 8, |
|
activeSize: 8, |
|
space: 5, |
|
activeColor: Colors.black, |
|
color: Colors.black.withAlpha(76), |
|
), |
|
), |
|
physics: BouncingScrollPhysics(), |
|
itemBuilder: (context, position) { |
|
return Column( |
|
children: [ |
|
Container( |
|
child: weekList(coupon[position]), |
|
// weekList(testList2[position]), |
|
), |
|
], |
|
); |
|
}, |
|
itemCount:coupon.length, |
|
), |
|
) |
|
], |
|
) |
|
); |
|
} |
|
|
|
Widget weekList(List<Coupon> cops){ |
|
return Expanded(child:(cops != null && cops.length > 0)?ListView.builder( |
|
padding: EdgeInsets.zero, |
|
itemCount: cops.length, |
|
scrollDirection: Axis.vertical, |
|
shrinkWrap: true, |
|
physics: BouncingScrollPhysics(), |
|
itemBuilder: (context, position) { |
|
return GestureDetector( |
|
onTap: () { |
|
}, |
|
child: weekCoupon(cops[position]), |
|
); |
|
}, |
|
):NoDataView( |
|
src: "assets/image/ka.webp", |
|
isShowBtn: false, |
|
text: S.of(context).haimeiyouyouhuiquankeyilingqu, |
|
fontSize: 16.sp, |
|
),); |
|
} |
|
|
|
Widget weekCoupon(Coupon cop) { |
|
return Container( |
|
height: 95.h, |
|
width: double.infinity, |
|
margin: EdgeInsets.only(bottom:10), |
|
padding:EdgeInsets.symmetric(horizontal: 12), |
|
decoration: BoxDecoration( |
|
image: DecorationImage( |
|
fit: BoxFit.fill, |
|
image: AssetImage("assets/image/week_coupons.webp"), |
|
), |
|
), |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Expanded(child: Container( |
|
margin: EdgeInsets.only(top: 12,bottom: 12), |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text( |
|
cop != null ? cop.couponName ?? "" : "", |
|
maxLines: 1, |
|
overflow: TextOverflow.ellipsis, |
|
style: TextStyle( |
|
fontSize: 14.sp, |
|
fontWeight: MyFontWeight.semi_bold, |
|
color: Color(0xFF0D0D0D), |
|
), |
|
), |
|
SizedBox(height: 12,), |
|
(cop.status == 0)? |
|
Text( |
|
"发放时间: ${cop?.publishStartTime ?? ""}", |
|
maxLines: 1, |
|
overflow: TextOverflow.ellipsis, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: cop.status == 3 ? Color(0xFFB3B3B3) :Color(0xFF4D4D4D), |
|
), |
|
):Text( |
|
"有效期至 ${cop?.publishEndTime ?? ""}", |
|
maxLines:1, |
|
overflow: TextOverflow.ellipsis, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: cop.status == 3 ? Color(0xFFB3B3B3) :Color(0xFF4D4D4D), |
|
), |
|
) |
|
], |
|
), |
|
)), |
|
|
|
Column( |
|
// mainAxisAlignment: MainAxisAlignment.start, |
|
// crossAxisAlignment: CrossAxisAlignment.end, |
|
children: [ |
|
Expanded(child: Container( |
|
child:weekWidget(cop), |
|
)), |
|
Container( |
|
margin: EdgeInsets.only(bottom: 12), |
|
child: weekBtn(cop), |
|
) |
|
], |
|
) |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget weekWidget(Coupon cop) { |
|
if (cop.bizType == 1) { |
|
return Column( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Row( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
crossAxisAlignment: CrossAxisAlignment.baseline, |
|
textBaseline: TextBaseline.alphabetic, |
|
children: [ |
|
Text( |
|
"¥", |
|
style: TextStyle( |
|
fontSize: 16.sp, |
|
fontWeight: MyFontWeight.medium, |
|
color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), |
|
), |
|
), |
|
SizedBox( |
|
height: 4.h, |
|
), |
|
Text( |
|
coupon != null |
|
? double.tryParse("${cop.discountAmount}" ?? "0") |
|
.toInt() |
|
.toString() |
|
: "", |
|
style: TextStyle( |
|
fontSize: 24.sp, |
|
fontWeight: MyFontWeight.semi_bold, |
|
color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), |
|
), |
|
), |
|
], |
|
), |
|
Text( |
|
S.of(context).manyuankeyong(coupon != null |
|
? ("${cop.fullAmount}" ?? "0") |
|
.toString() |
|
: ""), |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.semi_bold, |
|
color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), |
|
), |
|
), |
|
], |
|
); |
|
} else if (cop.bizType == 3) { |
|
return Column( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Container( |
|
// padding: EdgeInsets.only(bottom:10,top: 7), |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
children: [ |
|
Text( |
|
S.of(context).duihuanquan, |
|
style: TextStyle( |
|
fontSize: 22.sp, |
|
fontWeight: MyFontWeight.semi_bold, |
|
color:cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), |
|
), |
|
), |
|
], |
|
), |
|
), |
|
Text( |
|
S.of(context).xianshangshiyong, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.semi_bold, |
|
color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), |
|
), |
|
), |
|
], |
|
); |
|
} else if (cop.bizType == 5) { |
|
return Column( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Container( |
|
padding: EdgeInsets.only(bottom:10,top: 7), |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
children: [ |
|
Text( |
|
S.of(context).duihuanquan, |
|
style: TextStyle( |
|
fontSize: 26.sp, |
|
fontWeight: MyFontWeight.semi_bold, |
|
color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), |
|
), |
|
), |
|
], |
|
), |
|
), |
|
Text( |
|
S.of(context).xianxiashiyong, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.semi_bold, |
|
color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), |
|
), |
|
), |
|
], |
|
); |
|
} else if (cop.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: 16.sp, |
|
fontWeight: MyFontWeight.medium, |
|
color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), |
|
), |
|
), |
|
SizedBox( |
|
height: 4.h, |
|
), |
|
Text( |
|
coupon != null |
|
? "${AppUtils.calculateDouble(double.tryParse(cop.limitAmount) ?? 0)}" |
|
: "", |
|
style: TextStyle( |
|
fontSize: 24.sp, |
|
fontWeight: FontWeight.bold, |
|
color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), |
|
), |
|
), |
|
], |
|
), |
|
], |
|
); |
|
}else{ |
|
return Column( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Row( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
crossAxisAlignment: CrossAxisAlignment.baseline, |
|
textBaseline: TextBaseline.alphabetic, |
|
children: [ |
|
Text( |
|
coupon != null |
|
? "${(cop.discountPercent / 10.0 >= 10) ? 10 : cop.discountPercent / 10.0}" ?? |
|
"0" |
|
: "", |
|
style: TextStyle( |
|
fontSize: 30.sp, |
|
fontWeight: MyFontWeight.semi_bold, |
|
color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), |
|
), |
|
), |
|
SizedBox( |
|
height: 4.h, |
|
), |
|
Text( |
|
"折", |
|
style: TextStyle( |
|
fontSize: 16.sp, |
|
fontWeight: MyFontWeight.semi_bold, |
|
color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), |
|
), |
|
), |
|
], |
|
), |
|
], |
|
); |
|
} |
|
} |
|
|
|
Widget weekBtn(Coupon cop) { |
|
if(cop.status == 0) |
|
return Align( |
|
alignment: Alignment.centerRight, |
|
child: InkWell( |
|
onTap: () { |
|
receiveCoupon(cop.id); |
|
}, |
|
child: Container( |
|
padding: EdgeInsets.symmetric(horizontal: 12.w,vertical: 2.h), |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.circular(3), |
|
color: Color(0xFF32A060), |
|
), |
|
child: Text( |
|
S.of(context).lingqu, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.medium, |
|
color: Colors.white, |
|
), |
|
), |
|
), |
|
), |
|
); |
|
if(cop.status == 1 || cop.status == 2) |
|
return Align( |
|
alignment: Alignment.centerRight, |
|
child: InkWell( |
|
onTap: () { |
|
if (cop.bizType == 5 || cop.bizType == 3) { |
|
Navigator.of(context).pushNamed( |
|
'/router/write_off_page', |
|
arguments: { |
|
"couponId": cop.id, |
|
"coupon": cop.toJson() |
|
}); |
|
} else { |
|
showStoreSelector(cop.storeList); |
|
} |
|
}, |
|
child: Container( |
|
// height: 19.h, |
|
padding: EdgeInsets.symmetric(horizontal:8.w,vertical: 1.h), |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.circular(3), |
|
border: Border.all( |
|
width: 1, color: Color(0xFF32A060), style: BorderStyle.solid), |
|
color: Colors.transparent, |
|
), |
|
alignment: Alignment.center, |
|
child:Text( |
|
S.of(context).qushiyong, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFF32A060), |
|
), |
|
), |
|
), |
|
), |
|
); |
|
} |
|
|
|
receiveCoupon(couponId) async { |
|
couponIndex = swiperIndex; |
|
BaseData baseData = await apiService.receiveCoupon(couponId); |
|
if (baseData != null && baseData.isSuccess) { |
|
queryCoupon(); |
|
showAlertDialog(); |
|
}else{ |
|
SmartDialog.showToast(baseData?.msg,alignment: Alignment.center); |
|
} |
|
} |
|
|
|
showStoreSelector(storeList) { |
|
showModalBottomSheet( |
|
context: context, |
|
backgroundColor: Colors.transparent, |
|
builder: (context) { |
|
return SelectorStoreWidget(storeList); |
|
}, |
|
); |
|
} |
|
|
|
showAlertDialog() { |
|
//显示对话框 |
|
showDialog( |
|
context: context, |
|
builder: (BuildContext context) { |
|
return ReceiveSuccess(); |
|
}, |
|
); |
|
} |
|
|
|
///邀请好友 |
|
Widget inviteFriends() { |
|
return Container( |
|
margin: EdgeInsets.only(top:24.h,bottom:20.h), |
|
child:Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text( |
|
"邀请好友", |
|
style: TextStyle( |
|
fontSize: 15.sp, |
|
fontWeight: MyFontWeight.bold, |
|
color: Color(0xFF0D0D0D), |
|
), |
|
), |
|
SizedBox(height: 12,), |
|
GestureDetector( |
|
onTap: (){ |
|
Navigator.of(context).pushNamed('/router/invite_friends'); |
|
}, |
|
child:ClipRRect( |
|
child:Image.asset( |
|
"assets/image/welfare_spread.webp", |
|
width:double.infinity, |
|
fit: BoxFit.fill, |
|
height:100.h, |
|
), |
|
borderRadius: BorderRadius.circular(6.w), |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
///福利兑换 |
|
Widget benefitExchange() { |
|
return Container( |
|
width: double.infinity, |
|
margin: EdgeInsets.only(top:24.h,bottom:20.h), |
|
child:Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
GestureDetector( |
|
onTap: (){ |
|
Navigator.of(context).pushNamed('/router/welfare_exchange'); |
|
}, |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Expanded(child: |
|
Text( |
|
"福利兑换", |
|
style: TextStyle( |
|
fontSize: 15.sp, |
|
fontWeight: MyFontWeight.bold, |
|
color: Color(0xFF0D0D0D), |
|
), |
|
),), |
|
Text( |
|
S.of(context).gengduo, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFF4D4D4D), |
|
), |
|
), |
|
Icon( |
|
Icons.keyboard_arrow_right, |
|
color: Color(0xFF4D4D4D), |
|
size: 20, |
|
) |
|
], |
|
), |
|
), |
|
SizedBox(height: 12,), |
|
(goods == null || goods.length == 0)? NoDataView( |
|
src: "assets/image/xiao_fei.webp", |
|
isShowBtn: false, |
|
text: "暂无商品可兑换", |
|
fontSize: 16.sp, |
|
margin: EdgeInsets.all(60.h), |
|
) |
|
:GridView.builder( |
|
itemCount:goods.length>6?6:goods.length, |
|
padding: EdgeInsets.only( |
|
// left: 16.w, |
|
// right: 16.w, |
|
top: 18.h, |
|
bottom: 16.h, |
|
), |
|
shrinkWrap: true, |
|
physics: BouncingScrollPhysics(), |
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( |
|
//一行的Widget数量 |
|
crossAxisCount: 2, |
|
//水平子Widget之间间距 |
|
crossAxisSpacing: 11.w, |
|
//垂直子Widget之间间距 |
|
mainAxisSpacing: 16.w, |
|
//子Widget宽高比例 0.59 |
|
childAspectRatio: |
|
200 / (266 / 2 + (266 / 2) * AppUtils.textScale(context)), |
|
), |
|
itemBuilder: (context, index) { |
|
return GestureDetector( |
|
onTap: () { |
|
Navigator.of(context).pushNamed( |
|
'/router/integral_store_page', |
|
arguments: {"goodsId": goods[index].id}, |
|
); |
|
}, |
|
child: exchangeItem(goods[index]), |
|
); |
|
}, |
|
) |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget exchangeItem(Goods goods) { |
|
return Container( |
|
alignment: Alignment.center, |
|
decoration: BoxDecoration( |
|
color: Color(0xFFFFFFFF), |
|
borderRadius: BorderRadius.circular(4), |
|
boxShadow: [ |
|
BoxShadow( |
|
color: Colors.black.withAlpha(12), |
|
offset: Offset(0, 2), |
|
blurRadius: 4, |
|
spreadRadius: 0, |
|
) |
|
], |
|
), |
|
child: Stack( |
|
alignment: AlignmentDirectional.topEnd, |
|
fit: StackFit.loose, |
|
children: [ |
|
Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
mainAxisSize: MainAxisSize.max, |
|
children: [ |
|
MImage( |
|
goods.mainImgPath, |
|
aspectRatio: 1.1, |
|
fit: BoxFit.cover, |
|
radius: BorderRadius.only( |
|
topLeft: Radius.circular(4), |
|
topRight: Radius.circular(4), |
|
), |
|
errorSrc: "assets/image/default_1.webp", |
|
fadeSrc: "assets/image/default_1.webp", |
|
), |
|
Expanded( |
|
child: Container( |
|
margin: EdgeInsets.only( |
|
right: 12.w, |
|
top: 10.h, |
|
),padding: EdgeInsets.only( |
|
bottom: 8, |
|
left: 8 |
|
), |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text( |
|
goods.name, |
|
overflow: TextOverflow.ellipsis, |
|
maxLines: 1, |
|
style: TextStyle( |
|
color: Color(0xFF0D0D0D), |
|
height: 1.2, |
|
fontWeight: MyFontWeight.regular, |
|
fontSize: 14.sp, |
|
), |
|
), |
|
Spacer(), |
|
Text( |
|
pointPrice(goods), |
|
style: TextStyle( |
|
color: Color(0xFFE5600D), |
|
fontSize: 16.sp, |
|
fontWeight: MyFontWeight.semi_bold, |
|
), |
|
), |
|
], |
|
), |
|
), |
|
flex: 1, |
|
), |
|
], |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
|
|
String pointPrice(Goods goodsPrice){ |
|
if(goodsPrice == null) |
|
return ""; |
|
if(goodsPrice?.onePrice!=null && goodsPrice?.onePrice!="0"){ |
|
return S.of(context).jifen_(goodsPrice?.onePrice); |
|
}else if((goodsPrice?.onePrice == null || goodsPrice?.onePrice == "0") && ((goodsPrice?.price != null && goodsPrice?.price != "0") || (goodsPrice?.money != null && goodsPrice?.money != "0.00"))){ |
|
return (goodsPrice?.price== "0"|| goodsPrice?.price == null ? "" : S.of(context).jifen_(goodsPrice?.price)) + (goodsPrice?.money== "0"|| goodsPrice?.money == null ? "" : " + ${AppUtils.calculateDouble(double.tryParse(goodsPrice?.money) ?? 0)}元"); |
|
}else if(goodsPrice.oneMoney != null && goodsPrice.oneMoney != "0.00"){ |
|
return "${AppUtils.calculateDouble(double.tryParse(goodsPrice.oneMoney) ?? 0)}元"; |
|
} |
|
} |
|
|
|
///活动任务 |
|
Widget activityTask() { |
|
return Container( |
|
margin: EdgeInsets.only(bottom:20.h,), |
|
child:Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text( |
|
"活动任务", |
|
style: TextStyle( |
|
fontSize: 15.sp, |
|
fontWeight: MyFontWeight.bold, |
|
color: Color(0xFF0D0D0D), |
|
), |
|
), |
|
Text( |
|
"已完成0/3", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFF4D4D4D), |
|
), |
|
), |
|
], |
|
), |
|
SizedBox(height: 12.h,), |
|
ListView.builder( |
|
padding: EdgeInsets.zero, |
|
itemCount:6, |
|
scrollDirection: Axis.vertical, |
|
shrinkWrap: true, |
|
physics: NeverScrollableScrollPhysics(), |
|
itemBuilder: (context, position) { |
|
return GestureDetector( |
|
onTap: () { |
|
}, |
|
child: taskItem(), |
|
); |
|
}, |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget taskItem() { |
|
return Container( |
|
width:double.infinity, |
|
height:95.h, |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.circular(6), |
|
color: Colors.white, |
|
boxShadow: [ |
|
BoxShadow( |
|
color: Color(0x08213303).withAlpha(12), |
|
offset: Offset(0, 2), |
|
blurRadius: 3, |
|
spreadRadius: 0, |
|
), |
|
], |
|
), |
|
padding: EdgeInsets.symmetric(horizontal: 12.w,vertical: 12.h), |
|
margin: EdgeInsets.only(bottom: 10.h), |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
crossAxisAlignment: CrossAxisAlignment.end, |
|
children: [ |
|
Expanded(child:Column( |
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text( |
|
"海峡姐妹茶新品尝鲜(0/3)", |
|
style: TextStyle( |
|
fontSize: 14.sp, |
|
fontWeight: MyFontWeight.bold, |
|
color: Color(0xFF353535), |
|
), |
|
), |
|
Text( |
|
"可获得¥10代金券", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFF4D4D4D), |
|
), |
|
), Text( |
|
"购买任意3杯新品", |
|
style: TextStyle( |
|
fontSize: 10.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFFB3B3B3), |
|
), |
|
), |
|
], |
|
),), |
|
Container( |
|
width: 55.w, |
|
height: 21.h, |
|
decoration: BoxDecoration( |
|
gradient: new LinearGradient( |
|
begin: Alignment.centerLeft, |
|
end: Alignment.centerRight, |
|
colors: [ |
|
Color(0xFFFF2700), |
|
Color(0xFFFF4F00), |
|
],), |
|
// border: Border.all(color: Colors.white,width: 0.5), |
|
shape: BoxShape.rectangle, |
|
borderRadius: BorderRadius.circular(3), |
|
), |
|
alignment: Alignment.center, |
|
child:Text( |
|
"领取", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFFFFFFFF), |
|
), |
|
), |
|
) |
|
], |
|
), |
|
); |
|
} |
|
|
|
}
|
|
|