375 lines
13 KiB
Dart
375 lines
13 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
import 'package:aslan/chatvibe_ui/components/text/at_text.dart';
|
|
import 'package:aslan/chatvibe_core/utilities/at_loading_manager.dart';
|
|
import 'package:aslan/chatvibe_data/sources/repositories/user_repository_impl.dart';
|
|
|
|
import 'package:aslan/app_localizations.dart';
|
|
import 'package:aslan/chatvibe_ui/components/at_compontent.dart';
|
|
import 'package:aslan/chatvibe_ui/components/at_page_list.dart';
|
|
import 'package:aslan/chatvibe_ui/components/at_tts.dart';
|
|
import 'package:aslan/chatvibe_core/constants/at_screen.dart';
|
|
import 'package:aslan/chatvibe_core/routes/at_fluro_navigator.dart';
|
|
import 'package:aslan/chatvibe_domain/models/res/at_prop_coupon_list_res.dart';
|
|
import 'package:aslan/chatvibe_ui/widgets/countdown_timer.dart';
|
|
import 'package:aslan/chatvibe_features/home/coupon/coupon_route.dart';
|
|
|
|
class CouponTabPage extends ATPageList {
|
|
int? type;
|
|
|
|
CouponTabPage({this.type});
|
|
|
|
@override
|
|
_CouponTabPageState createState() => _CouponTabPageState(type: type);
|
|
}
|
|
|
|
class _CouponTabPageState extends ATPageListState<Records, CouponTabPage> {
|
|
int? type;
|
|
|
|
_CouponTabPageState({this.type});
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
enablePullUp = false;
|
|
isGridView = true;
|
|
gridViewCount = 2;
|
|
padding = EdgeInsets.symmetric(horizontal: 5.w, vertical: 5.w);
|
|
backgroundColor = Colors.transparent;
|
|
gridDelegate = SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: gridViewCount,
|
|
mainAxisSpacing: 8.w,
|
|
crossAxisSpacing: 8.w,
|
|
childAspectRatio: 1.5,
|
|
);
|
|
loadData(1);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.transparent,
|
|
body: Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: buildList(context),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget buildItem(Records res) {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage(
|
|
res.couponType == 1
|
|
? "atu_images/coupon/at_icon_coupon_headdress_item_bg.png"
|
|
: (res.couponType == 2
|
|
? "atu_images/coupon/at_icon_coupon_mountains_item_bg.png"
|
|
: "atu_images/coupon/at_icon_coupon_vip_item_bg.png"),
|
|
),
|
|
fit: BoxFit.contain,
|
|
),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
SizedBox(height: 12.w),
|
|
Row(
|
|
children: [
|
|
SizedBox(width: 6.w),
|
|
netImage(url: res.propIcon ?? "", width: 52.w, height: 52.w),
|
|
SizedBox(width: 5.w),
|
|
Expanded(
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: text(
|
|
"${res.propName}*${res.propDays??0}${(res.propDays??0)>1?ATAppLocalizations.of(context)!.days:ATAppLocalizations.of(context)!.day}",
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 12.sp,
|
|
textColor:
|
|
res.couponType == 1
|
|
? Color(0xff002F89)
|
|
: (res.couponType == 2
|
|
? Color(0xff890000)
|
|
: Color(0xff893200)),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
CountdownTimer(
|
|
expiryDate: DateTime.fromMillisecondsSinceEpoch(
|
|
res.expireTime ?? 0,
|
|
),
|
|
color:
|
|
res.couponType == 3 ? Colors.red : Colors.white,
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
SizedBox(width: 10.w),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 22.w),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
SizedBox(width: 15.w),
|
|
GestureDetector(
|
|
child: Container(
|
|
alignment: AlignmentDirectional.center,
|
|
width: 55.w,
|
|
height: 25.w,
|
|
decoration: BoxDecoration(
|
|
color: Color(0xffF7D882),
|
|
borderRadius: BorderRadius.all(Radius.circular(22.w)),
|
|
),
|
|
child: text(
|
|
ATAppLocalizations.of(context)!.use,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 12.sp,
|
|
textColor:
|
|
res.couponType == 1
|
|
? Color(0xff002F89)
|
|
: (res.couponType == 2
|
|
? Color(0xff890000)
|
|
: Color(0xff893200)),
|
|
),
|
|
),
|
|
onTap: () {
|
|
_showUseConfirm(res);
|
|
},
|
|
),
|
|
SizedBox(width: 15.w),
|
|
GestureDetector(
|
|
child: Container(
|
|
alignment: AlignmentDirectional.center,
|
|
width: 55.w,
|
|
height: 25.w,
|
|
decoration: BoxDecoration(
|
|
color: Color(0xffF7D882),
|
|
borderRadius: BorderRadius.all(Radius.circular(22.w)),
|
|
),
|
|
child: text(
|
|
ATAppLocalizations.of(context)!.send,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 12.sp,
|
|
textColor:
|
|
res.couponType == 1
|
|
? Color(0xff002F89)
|
|
: (res.couponType == 2
|
|
? Color(0xff890000)
|
|
: Color(0xff893200)),
|
|
),
|
|
),
|
|
onTap: () {
|
|
ATNavigatorUtils.push(
|
|
context,
|
|
"${CouponRoute.couponSend}?couponJson=${Uri.encodeComponent(jsonEncode(res.toJson()))}",
|
|
).then((result) {
|
|
loadData(1);
|
|
});
|
|
},
|
|
),
|
|
SizedBox(width: 15.w),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void _showUseConfirm(Records res) {
|
|
SmartDialog.show(
|
|
tag: "showUseConfirm",
|
|
alignment: Alignment.center,
|
|
animationType: SmartAnimationType.fade,
|
|
builder: (_) {
|
|
return Container(
|
|
margin: EdgeInsets.symmetric(horizontal: 25.w),
|
|
padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 15.w),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(15.w),
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
SizedBox(height: 8.w),
|
|
text(
|
|
ATAppLocalizations.of(context)!.tips,
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.bold,
|
|
textColor: Colors.black,
|
|
),
|
|
SizedBox(height: 10.w),
|
|
netImage(url: res.propIcon ?? "", width: 78.w, height: 78.w),
|
|
SizedBox(height: 15.w),
|
|
text(
|
|
"${res.propName}*${res.propDays}${ATAppLocalizations.of(context)!.days}",
|
|
fontSize: 15.sp,
|
|
fontWeight: FontWeight.w600,
|
|
textColor: Colors.black,
|
|
),
|
|
SizedBox(height: 10.w),
|
|
text(
|
|
maxLines: 3,
|
|
ATAppLocalizations.of(context)!.useCoupontips,
|
|
fontSize: 15.sp,
|
|
fontWeight: FontWeight.w600,
|
|
textColor: Colors.black54,
|
|
),
|
|
SizedBox(height: 15.w),
|
|
Container(
|
|
margin: EdgeInsets.symmetric(horizontal: 15.w),
|
|
height: height(43),
|
|
alignment: Alignment.center,
|
|
child: Row(
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: GestureDetector(
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(12),
|
|
color: Colors.white,
|
|
border: Border.all(
|
|
color: Color(0xffE6E6E6),
|
|
width: 1.w,
|
|
),
|
|
),
|
|
alignment: Alignment.center,
|
|
child: text(
|
|
ATAppLocalizations.of(context)!.cancel,
|
|
fontSize: 14.sp,
|
|
textColor: Colors.black54,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
onTap: () {
|
|
SmartDialog.dismiss(tag: "showUseConfirm");
|
|
},
|
|
),
|
|
),
|
|
SizedBox(width: 15.w),
|
|
Expanded(
|
|
child: GestureDetector(
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(12),
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [
|
|
Color(0xffC670FF).withOpacity(0.6),
|
|
Color(0xff7726FF).withOpacity(0.6),
|
|
],
|
|
),
|
|
),
|
|
alignment: Alignment.center,
|
|
child: text(
|
|
ATAppLocalizations.of(context)!.confirm,
|
|
fontSize: 14.sp,
|
|
textColor: Colors.white,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
onTap: () {
|
|
ATLoadingManager.exhibitOperation();
|
|
AccountRepository()
|
|
.couponUse(res.couponNo ?? "")
|
|
.then((result) {
|
|
loadData(1);
|
|
ATLoadingManager.veilRoutine();
|
|
ATTts.show(
|
|
ATAppLocalizations.of(
|
|
context,
|
|
)!.operationSuccessful,
|
|
);
|
|
SmartDialog.dismiss(tag: "_showUseConfirm");
|
|
})
|
|
.catchError((e) {
|
|
ATLoadingManager.veilRoutine();
|
|
SmartDialog.dismiss(tag: "_showUseConfirm");
|
|
});
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(height: 15.w),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
empty() {
|
|
List<Widget> list = [];
|
|
list.add(SizedBox(height: height(100)));
|
|
list.add(
|
|
Image.asset('atu_images/room/icon_room_music_empty.png', width: 120.w),
|
|
);
|
|
list.add(SizedBox(height: height(15)));
|
|
list.add(
|
|
Text(
|
|
ATAppLocalizations.of(context)!.youDontHaveAnyCouponsYet,
|
|
style: TextStyle(
|
|
fontSize: sp(14),
|
|
color: Color(0xff999999),
|
|
fontWeight: FontWeight.w400,
|
|
decoration: TextDecoration.none,
|
|
height: 1,
|
|
),
|
|
),
|
|
);
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.max,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: list,
|
|
);
|
|
}
|
|
|
|
///加载数据
|
|
@override
|
|
loadPage({
|
|
required int page,
|
|
required Function(List<Records>) onSuccess,
|
|
Function? onErr,
|
|
}) async {
|
|
try {
|
|
var result = await AccountRepository().propCouponList(
|
|
pageCount,
|
|
page,
|
|
couponType: type,
|
|
);
|
|
List<Records> list = [];
|
|
result.records?.forEach((rd) {
|
|
if (rd.status != 1) {
|
|
list.add(rd);
|
|
}
|
|
});
|
|
onSuccess(list);
|
|
} catch (e) {
|
|
if (onErr != null) {
|
|
onErr();
|
|
}
|
|
}
|
|
}
|
|
}
|