diff --git a/lib/home/home_page.dart b/lib/home/home_page.dart index 45085a23..2722bb5e 100644 --- a/lib/home/home_page.dart +++ b/lib/home/home_page.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -303,8 +305,7 @@ class _HomePage extends State with AutomaticKeepAliveClientMixin { child: GestureDetector( onTap: () { Navigator.of(context).pushNamed('/router/system_msg_page'); - ///活动优惠券赠送弹窗 - // activityShowAlertDialog(); + }, child: Container( height: 24, @@ -478,6 +479,11 @@ class _HomePage extends State with AutomaticKeepAliveClientMixin { } else if (await Permission.camera.isGranted) { // http://pos.app.gznl.top/placeorder/?tableId=1315903669597634560&tenantCode=1166&shopId=1300372027722432512 var result = await Navigator.of(context).pushNamed('/router/qr_scan'); + if(result.toString().contains("type\":\"coupon")){ + ///活动优惠券赠送弹窗 + activityShowAlertDialog(result.toString()); + return; + } // String result = await scanner.scan(); Uri uri = Uri.parse(result); String tableId = uri.queryParameters["tableId"]; @@ -526,12 +532,12 @@ class _HomePage extends State with AutomaticKeepAliveClientMixin { ); } - activityShowAlertDialog() { + activityShowAlertDialog(String result) { //显示对话框 showDialog( context: context, builder: (BuildContext context) { - return ActivityCoupons(); + return ActivityCoupons(result); }, ); } diff --git a/lib/retrofit/retrofit_api.dart b/lib/retrofit/retrofit_api.dart index b08fd3cd..24fa7fba 100644 --- a/lib/retrofit/retrofit_api.dart +++ b/lib/retrofit/retrofit_api.dart @@ -54,14 +54,14 @@ import 'data/wx_pay.dart'; part 'retrofit_api.g.dart'; -// const base_url = "https://pos.platform.lotus-wallet.com/app/"; ///正式 -// const baseUrl = "https://pos.platform.lotus-wallet.com/app/"; ///正式 +const base_url = "https://pos.platform.lotus-wallet.com/app/"; ///正式 +const baseUrl = "https://pos.platform.lotus-wallet.com/app/"; ///正式 // const base_url = "http://platform.prod.kunqi.lotus-wallet.com/app/"; ///222 // const baseUrl = "http://platform.prod.kunqi.lotus-wallet.com/app/"; ///222 -const base_url = "http://192.168.10.236:8766/app/"; ///费韬 -const baseUrl = "http://192.168.10.236:8766/app/"; ///费韬 +// const base_url = "http://192.168.10.236:8766/app/"; ///费韬 +// const baseUrl = "http://192.168.10.236:8766/app/"; ///费韬 // const base_url = "http://192.168.10.159:8766/app/"; ///费韬 // const baseUrl = "http://192.168.10.159:8766/app/"; ///费韬 diff --git a/lib/retrofit/retrofit_api.g.dart b/lib/retrofit/retrofit_api.g.dart index 71083690..5735110a 100644 --- a/lib/retrofit/retrofit_api.g.dart +++ b/lib/retrofit/retrofit_api.g.dart @@ -9,7 +9,7 @@ part of 'retrofit_api.dart'; class _ApiService implements ApiService { _ApiService(this._dio, {this.baseUrl}) { ArgumentError.checkNotNull(_dio, '_dio'); - baseUrl ??= 'http://192.168.10.236:8766/app/'; + baseUrl ??= 'https://pos.platform.lotus-wallet.com/app/'; } final Dio _dio; diff --git a/lib/view_widget/activity_coupons.dart b/lib/view_widget/activity_coupons.dart index 50c98c85..eeb6357b 100644 --- a/lib/view_widget/activity_coupons.dart +++ b/lib/view_widget/activity_coupons.dart @@ -1,18 +1,20 @@ +import 'dart:collection'; +import 'dart:convert'; + +import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; -import 'package:huixiang/generated/l10n.dart'; -import 'package:huixiang/retrofit/data/login_info.dart'; -import 'package:huixiang/utils/flutter_utils.dart'; +import 'package:huixiang/retrofit/data/base_data.dart'; +import 'package:huixiang/retrofit/data/coupon.dart'; +import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/utils/font_weight.dart'; -import 'package:huixiang/view_widget/receive_success.dart'; -import 'package:huixiang/view_widget/round_button.dart'; -import 'package:huixiang/view_widget/separator.dart'; +import 'package:shared_preferences/shared_preferences.dart'; class ActivityCoupons extends StatefulWidget { - // final List newUserCouponList; - // - // ActivityCoupons(this.newUserCouponList); + final String result; + + ActivityCoupons(this.result); @override State createState() { @@ -21,16 +23,53 @@ class ActivityCoupons extends StatefulWidget { } class _ActivityCoupons extends State { + var resultData; + int pageNum = 1; + List coupons = []; + ApiService apiService; + var receiveCou = new Queue(); + + @override + void initState() { + super.initState(); + resultData = jsonDecode(widget.result); + } + + receiveCoupon() async { + var id = receiveCou.removeFirst(); + if (apiService == null) { + SharedPreferences value = await SharedPreferences.getInstance(); + apiService = ApiService( + Dio(), + context: context, + token: value.getString("token"), + ); + } + BaseData baseData = await apiService.receiveCoupon(id).catchError((onError) {}); + if (baseData != null && baseData.isSuccess) { + if (receiveCou.length > 0) { + receiveCoupon(); + } else { + Navigator.of(context).pop(); + SmartDialog.showToast("领取成功", alignment: Alignment.center); + } + } + else{ + SmartDialog.showToast(baseData.msg, alignment: Alignment.center); + Navigator.of(context).pop(); + } + } + @override Widget build(BuildContext context) { return Container( - margin: EdgeInsets.only(top:150.h), + margin: EdgeInsets.only(top: 150.h), height: MediaQuery.of(context).size.height / 2, child: Column( children: [ Container( width: double.infinity, - height:MediaQuery.of(context).size.height / 2, + height: MediaQuery.of(context).size.height / 2, padding: EdgeInsets.only(top: 210.h), margin: EdgeInsets.only(top: 20.h, left: 20, right: 20), decoration: BoxDecoration( @@ -42,16 +81,18 @@ class _ActivityCoupons extends State { child: Column( children: [ Expanded( - child: reward(), + child: couponsActivity(), ), GestureDetector( onTap: () { - Navigator.of(context).pop(); - SmartDialog.showToast("领取成功",alignment: Alignment.center); + (resultData["list"] as List).forEach((element) { + receiveCou..add(element["id"]); + }); + receiveCoupon(); }, child: Container( margin: EdgeInsets.only( - left: 60.w, right: 60.w, top: 20.h, bottom:20.h), + left: 60.w, right: 60.w, top: 20.h, bottom: 20.h), decoration: BoxDecoration( gradient: new LinearGradient( begin: Alignment.centerLeft, @@ -96,23 +137,25 @@ class _ActivityCoupons extends State { ); } - Widget reward() { + Widget couponsActivity() { return ListView.builder( padding: EdgeInsets.zero, - itemCount: 4, + itemCount: (resultData == null || resultData["list"] == null) + ? 0 + : (resultData["list"] as List).length, scrollDirection: Axis.vertical, shrinkWrap: true, physics: BouncingScrollPhysics(), itemBuilder: (context, position) { return GestureDetector( onTap: () {}, - child: rewardItem(), + child: couponsItem(resultData["list"][position]), ); }, ); } - Widget rewardItem() { + Widget couponsItem(listData) { return Container( height: 69.h, width: double.infinity, @@ -123,79 +166,89 @@ class _ActivityCoupons extends State { ), ), margin: EdgeInsets.symmetric(horizontal: 60, vertical: 5), - padding: EdgeInsets.only(left: 16.w, right: 25.w), + padding: EdgeInsets.only(left: 16.w, right: 10.w), child: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text.rich( - TextSpan( - children: [ - TextSpan( - text: "¥", - style: TextStyle( - fontSize: 25.sp, - fontWeight: MyFontWeight.semi_bold, - color: Color(0xFFDE5F3B), + if (listData["type"] == 1) + Text.rich( + TextSpan( + children: [ + TextSpan( + text: "¥", + style: TextStyle( + fontSize: 14.sp, + fontWeight: MyFontWeight.semi_bold, + color: Color(0xFFDE5F3B), + ), ), - ), - TextSpan( - // text: double.tryParse( - // "${newUserCouponList.discountAmount}" ?? "0") - // .toInt() - // .toString() ?? - // "", - text: "10", - style: TextStyle( - fontSize: 35.sp, - fontWeight: MyFontWeight.semi_bold, - color: Color(0xFFDE5F3B), + TextSpan( + text: listData["discount"] ?? "", + style: TextStyle( + fontSize: 20.sp, + fontWeight: MyFontWeight.semi_bold, + color: Color(0xFFDE5F3B), + ), ), - ), - ], + ], + ), ), - ), - Expanded(child:Padding( - padding: EdgeInsets.only(top: 4, bottom: 4,left:10), - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "海峡姐妹茶吧", - overflow: TextOverflow.ellipsis, - maxLines: 2, - style: TextStyle( - fontSize: 14.sp, - fontWeight: MyFontWeight.semi_bold, - color: Color(0xFF181818), - ), + if (listData["type"] == 3) + Text( + "兑换券", + overflow: TextOverflow.ellipsis, + maxLines: 2, + style: TextStyle( + fontSize: 16.sp, + fontWeight: MyFontWeight.semi_bold, + color: Color(0xFFDE5F3B), + ), + ), + if (listData["type"] == 2) + Padding( + padding: EdgeInsets.only(right: 20), + child: Text.rich( + TextSpan( + children: [ + TextSpan( + text: (listData["percent"] / 10).toString() ?? "", + style: TextStyle( + fontSize: 25.sp, + fontWeight: MyFontWeight.semi_bold, + color: Color(0xFFDE5F3B), ), - Text( - "10元代金劵一张", - overflow: TextOverflow.ellipsis, - maxLines: 2, - style: TextStyle( - fontSize: 12.sp, - fontWeight: MyFontWeight.medium, - color: Color(0xFFD3623D), - ), + ), + TextSpan( + text: "折", + style: TextStyle( + fontSize: 14.sp, + fontWeight: MyFontWeight.semi_bold, + color: Color(0xFFDE5F3B), ), - Text( - // "有效期至:${(newUserCouponList.useEndTime != null && newUserCouponList.useEndTime != "") - // ? newUserCouponList.useEndTime.split(" ")[0] - // : "$newUserCouponList.useEndTime"}", - "有效期至:2021-07-30", - overflow: TextOverflow.ellipsis, - maxLines: 2, - style: TextStyle( - fontSize: 10.sp, - fontWeight: MyFontWeight.regular, - color: Color(0xFF727272), - ), - ) - ], - ))), + ), + ], + ), + )), + Expanded( + child: Padding( + padding: EdgeInsets.only(top: 4, bottom: 4, left: 10), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + listData["name"] ?? "", + overflow: TextOverflow.ellipsis, + maxLines: 2, + style: TextStyle( + fontSize: 16.sp, + fontWeight: MyFontWeight.semi_bold, + color: Color(0xFF181818), + ), + ), + ], + ))), ], ), ); diff --git a/lib/view_widget/login_tips.dart b/lib/view_widget/login_tips.dart index 694a350c..62aa0c07 100644 --- a/lib/view_widget/login_tips.dart +++ b/lib/view_widget/login_tips.dart @@ -23,7 +23,7 @@ class LoginTips extends StatelessWidget { // height: 0.7867.sw / (Platform.isAndroid ? 0.86 : 0.9), width:double.infinity, height:MediaQuery.of(context).size.width / 1, - margin: EdgeInsets.symmetric(horizontal:16.w), + margin: EdgeInsets.symmetric(horizontal:28.w), padding: EdgeInsets.symmetric(vertical: 20.h, horizontal: 24.w), decoration: BoxDecoration( color: Colors.white,