From c9a3763093d8b1c9f4cde7be9e9408e5686248c4 Mon Sep 17 00:00:00 2001 From: w-R <953969641@qq.com> Date: Tue, 26 Oct 2021 14:17:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/home/home_view/coupon.dart | 32 +++++++---- lib/mine/fans_page.dart | 92 ++++++++++-------------------- lib/retrofit/data/follow_list.dart | 12 +++- 3 files changed, 63 insertions(+), 73 deletions(-) diff --git a/lib/home/home_view/coupon.dart b/lib/home/home_view/coupon.dart index 61551b19..26376d19 100644 --- a/lib/home/home_view/coupon.dart +++ b/lib/home/home_view/coupon.dart @@ -24,7 +24,6 @@ class CouponView extends StatefulWidget { class _CouponView extends State { ApiService apiService; - int pageNum = 1; List coupons = []; @@ -45,21 +44,16 @@ class _CouponView extends State { queryCoupon() async { BaseData> baseData = await apiService.queryCoupon({ "centre": true, - "pageNum": pageNum, + "pageNum": 1, "pageSize": 10, "searchKey": "", "state": 0 }).catchError((onError) { }); - if (pageNum == 1) coupons.clear(); + coupons.clear(); if (baseData != null && baseData.isSuccess) { coupons.addAll(baseData.data.list); - if (baseData.data.pageNum == baseData.data.pages) { - } else { - pageNum += 1; - } setState(() {}); - } else { } } @@ -252,11 +246,13 @@ class _CouponView extends State { ), GestureDetector( onTap: (){ + if((coupon?.status??0) == 0) + receiveCoupon(coupon?.id??""); }, child:RoundButton( - text: "领取", + text: ((coupon?.status??0) == 0) ? "领取" : "已领取", textColor: Colors.white, - backgroup: Color(0xFF32A060), + backgroup: ((coupon?.status??0) == 0)?Color(0xFF32A060):Colors.grey, radius: 100, padding: EdgeInsets.symmetric(vertical: 3.h, horizontal: 14.w), ), @@ -279,5 +275,21 @@ class _CouponView extends State { ); } + receiveCoupon(couponId) async { + BaseData baseData = await apiService.receiveCoupon(couponId); + if (baseData != null && baseData.isSuccess) { + queryCoupon(); + showAlertDialog(); + } + } + showAlertDialog() { + //显示对话框 + showDialog( + context: context, + builder: (BuildContext context) { + return ReceiveSuccess(); + }, + ); + } } diff --git a/lib/mine/fans_page.dart b/lib/mine/fans_page.dart index d819ab69..6a25e159 100644 --- a/lib/mine/fans_page.dart +++ b/lib/mine/fans_page.dart @@ -82,11 +82,12 @@ class _FansPage extends State { } //关注/取关会员 - _vipFollow(followId) async { + _vipFollow(followId,isFollow) async { BaseData baseData = await apiService.follow(followId); if (baseData != null && baseData.isSuccess) { widget.refresh(); - SmartDialog.showToast("关注成功", alignment: Alignment.center); + _queryFollowList(); + SmartDialog.showToast(isFollow?"取关成功":"关注成功", alignment: Alignment.center); } else { SmartDialog.showToast(baseData.msg, alignment: Alignment.center); } @@ -170,68 +171,35 @@ class _FansPage extends State { borderRadius: BorderRadius.circular(11.w), color: Color(0xFF32A060), ), - child: - // GestureDetector( - // onTap: () { - // setState(() { - // if (widget.commentType == 0) { - // comment?.selfFollow = - // !(comment?.selfFollow ?? false); - // _vipFollow(list.mid); - // } - // }); - // }, - // child: (widget.commentType == 0) - // ? RoundButton( - // padding: EdgeInsets.symmetric( - // horizontal: 8, - // vertical: 3, - // ), - // backgroup: (comment?.selfFollow ?? false) - // ? Color(0xFFE6E6E6) - // : Color(0xFF32A060), - // textColor: (comment?.selfFollow ?? false) - // ? Color(0xFF808080) - // : Colors.white, - // text: (comment?.selfFollow ?? false) ? "已关注" : "关注", - // radius: 20, - // icons: Icon( - // (comment?.selfFollow ?? false) - // ? Icons.check - // : Icons.add, - // color: (comment?.selfFollow ?? false) - // ? Color(0xFF808080) - // : Colors.white, - // size: 14, - // ), - // ) - // : Icon( - // Icons.close, - // color: Colors.black, - // size: 16, - // ), - // ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment:CrossAxisAlignment.center, - children: [ - Icon( - Icons.add, - color: Colors.white, - size: 14, - ), - SizedBox( - width:4, + child: GestureDetector( + onTap: () { + setState(() { + _vipFollow(list.mid,list?.isFollow ?? false); + }); + }, + child: RoundButton( + padding: EdgeInsets.symmetric( + horizontal: 8, + vertical: 3, ), - Text( - "关注", - style: TextStyle( - color: Colors.white, - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, - ), + backgroup: (list?.isFollow ?? false) + ? Color(0xFFE6E6E6) + : Color(0xFF32A060), + textColor: (list?.isFollow ?? false) + ? Color(0xFF808080) + : Colors.white, + text: (list?.isFollow ?? false) ? "已关注" : "关注", + radius: 20, + icons: Icon( + (list?.isFollow ?? false) + ? Icons.check + : Icons.add, + color: (list?.isFollow ?? false) + ? Color(0xFF808080) + : Colors.white, + size: 14, ), - ], + ), ), ), ], diff --git a/lib/retrofit/data/follow_list.dart b/lib/retrofit/data/follow_list.dart index 27691608..d7177de7 100644 --- a/lib/retrofit/data/follow_list.dart +++ b/lib/retrofit/data/follow_list.dart @@ -115,25 +115,30 @@ class FollowList { class ListData { ListData({ - String mid, + String mid, + bool isFollow, String nickname, String avatar,}){ _mid = mid; _nickname = nickname; + _isFollow = isFollow; _avatar = avatar; } ListData.fromJson(dynamic json) { _mid = json['mid']; _nickname = json['nickname']; + _isFollow = json['isFollow']; _avatar = json['avatar']; } String _mid; String _nickname; String _avatar; + bool _isFollow; String get mid => _mid; String get nickname => _nickname; + bool get isFollow => _isFollow; String get avatar => _avatar; @@ -141,10 +146,15 @@ class ListData { _mid = value; } + set isFollow(bool value) { + _isFollow = value; + } + Map toJson() { final map = {}; map['mid'] = _mid; map['nickname'] = _nickname; + map['isFollow'] = _isFollow; map['avatar'] = _avatar; return map; }