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.

296 lines
10 KiB

3 years ago
import 'package:dio/dio.dart';
3 years ago
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:huixiang/generated/l10n.dart';
3 years ago
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/coupon.dart';
import 'package:huixiang/retrofit/data/page.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
3 years ago
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/item_title.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
3 years ago
import 'package:huixiang/view_widget/receive_success.dart';
3 years ago
import 'package:huixiang/view_widget/round_button.dart';
3 years ago
import 'package:huixiang/view_widget/selector_store_dialog.dart';
3 years ago
import 'package:huixiang/view_widget/separator.dart';
3 years ago
import 'package:shared_preferences/shared_preferences.dart';
3 years ago
class CouponView extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _CouponView();
}
}
class _CouponView extends State<CouponView> {
3 years ago
ApiService apiService;
List<Coupon> coupons = [];
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) => {
apiService = ApiService(
Dio(),
context: context,
token: value.getString('token'),
),
queryCoupon(),
});
}
queryCoupon() async {
BaseData<PageInfo<Coupon>> baseData = await apiService.queryCoupon({
"centre": true,
3 years ago
"pageNum": 1,
3 years ago
"pageSize": 10,
"searchKey": "",
"state": 0
}).catchError((onError) {
});
3 years ago
coupons.clear();
3 years ago
if (baseData != null && baseData.isSuccess) {
coupons.addAll(baseData.data.list);
setState(() {});
}
}
3 years ago
@override
Widget build(BuildContext context) {
return Column(
children: [
SizedBox(
height: 20.h,
),
ItemTitle(
text: S.of(context).chaojiyouhuiquan,
imgPath: "assets/image/icon_points_mall.png",
),
Container(
height: 132,
margin: EdgeInsets.only(top: 10),
child: ListView.builder(
scrollDirection: Axis.horizontal,
physics: BouncingScrollPhysics(),
padding: EdgeInsets.symmetric(horizontal: 10),
itemBuilder: (context, position) {
3 years ago
return couponItem(coupons[position]);
3 years ago
},
3 years ago
itemCount:coupons == null ? 0 : coupons.length,
3 years ago
),
),
],
);
}
3 years ago
Widget couponItem(Coupon coupon) {
3 years ago
return Container(
width: 0.9.sw,
height: 122.h,
child: Stack(
children: [
Container(
width: 0.9.sw,
height: 122.h,
child: SvgPicture.asset(
"assets/svg/youhuiquan_bg.svg",
width: double.infinity,
height: 122.h,
fit: BoxFit.fill,
),
),
Container(
width: 0.9.sw,
height: 122.h,
child: Row(
children: [
Expanded(
child: Container(
alignment: Alignment.center,
child: Container(
width: 74,
height: 74,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color(0xFFACDD60),
Color(0xFF32A060),
],
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text.rich(
TextSpan(
children: [
TextSpan(
text: "¥",
style: TextStyle(
fontSize: 16.sp,
fontWeight: MyFontWeight.regular,
color: Colors.white,
),
),
TextSpan(
3 years ago
text: coupon != null
? double.tryParse("${coupon.discountAmount}" ?? "0")
.toInt()
.toString()
: "",
3 years ago
style: TextStyle(
fontSize: 25.sp,
fontWeight: MyFontWeight.regular,
color: Colors.white,
),
),
],
),
),
Text(
3 years ago
S.of(context).manyuankeyong(coupon != null
? double.tryParse("${coupon.fullAmount}" ?? "0")
.toInt()
.toString()
: ""),
3 years ago
style: TextStyle(
fontWeight: MyFontWeight.regular,
fontSize: 14.sp,
color: Colors.white,
),
),
],
),
),
),
flex: 37,
),
Container(
margin: EdgeInsets.only(
top: 24.h,
bottom: 24.h,
),
child: MySeparator(
height: 5.h,
width: 1,
color: Color(0xFFD8D8D8),
),
),
Expanded(
child: Container(
margin:
EdgeInsets.symmetric(vertical: 10.h, horizontal: 15.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
3 years ago
(coupon != null && coupon.storeList != null && coupon.storeList.length > 0) ? coupon.storeList[0].storeName ?? "" : "",
overflow: TextOverflow.ellipsis,
3 years ago
style: TextStyle(
color: Color(0xFF181818),
fontWeight: MyFontWeight.medium,
fontSize: 14.sp,
),
),
Row(
children: [
3 years ago
// Text(
// "1张",
// style: TextStyle(
// color: Color(0xFF868686),
// fontWeight: MyFontWeight.regular,
// fontSize: 12.sp,
// ),
// ),
// SizedBox(
// width: 4.w,
// ),
3 years ago
Text(
3 years ago
coupon != null ? coupon.couponName ?? "" : "",
3 years ago
style: TextStyle(
color: Color(0xFF868686),
fontWeight: MyFontWeight.regular,
fontSize: 12.sp,
),
),
],
),
SizedBox(
width: 12.w,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
3 years ago
(coupon.useStartTime == null &&
coupon.useEndTime == null)
? S.of(context).quantian
: "${coupon.useStartTime.replaceAll("-", ".").split(" ")[0]} - ${coupon.useEndTime.replaceAll("-", ".").split(" ")[0]}",
3 years ago
style: TextStyle(
color: Color(0xFF868686),
fontWeight: MyFontWeight.semi_bold,
fontSize: 10.sp,
),
),
Expanded(
child: Container(),
flex: 1,
),
3 years ago
GestureDetector(
onTap: (){
3 years ago
if((coupon?.status??0) == 0)
receiveCoupon(coupon?.id??"");
3 years ago
},
child:RoundButton(
3 years ago
text: ((coupon?.status??0) == 0) ? "领取" : "已领取",
3 years ago
textColor: Colors.white,
3 years ago
backgroup: ((coupon?.status??0) == 0)?Color(0xFF32A060):Colors.grey,
3 years ago
radius: 100,
padding: EdgeInsets.symmetric(vertical: 3.h, horizontal: 14.w),
),
3 years ago
),
SizedBox(
width: 10.w,
),
],
),
],
),
),
flex: 63,
),
],
),
),
],
),
);
}
3 years ago
3 years ago
receiveCoupon(couponId) async {
BaseData baseData = await apiService.receiveCoupon(couponId);
if (baseData != null && baseData.isSuccess) {
queryCoupon();
showAlertDialog();
}
}
3 years ago
3 years ago
showAlertDialog() {
//显示对话框
showDialog(
context: context,
builder: (BuildContext context) {
return ReceiveSuccess();
},
);
}
3 years ago
}