添加购物车🛒页面,重构计算彩票注数算法

master
laiiihz 5 years ago
parent d324bffaae
commit 20202e3f02

@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:recook/pages/lottery/redeem_lottery_page.dart'; import 'package:recook/pages/lottery/redeem_lottery_page.dart';
import 'package:recook/utils/math/recook_math.dart';
class LotteryCartModel { class LotteryCartModel {
LotteryType type; LotteryType type;
@ -29,4 +30,36 @@ class LotteryCartStore {
break; break;
} }
} }
static int countLotteryBalls(
LotteryType type, {
@required List<int> redBalls,
@required List<int> blueBalls,
@required List<int> focusedRedBalls,
@required List<int> focusedBlueBalls,
}) {
switch (type) {
case LotteryType.DOUBLE_LOTTERY:
if (focusedRedBalls.length >= 1 && redBalls.length > 6)
return RecookMath.combination(6 - focusedRedBalls.length,
redBalls.length - focusedRedBalls.length) *
RecookMath.combination(1, blueBalls.length);
else
return RecookMath.combination(6, redBalls.length) *
RecookMath.combination(1, blueBalls.length);
break;
case LotteryType.BIG_LOTTERY:
if ((focusedRedBalls.length >= 1 || focusedBlueBalls.length >= 1) &&
redBalls.length > 5)
return RecookMath.combination(5 - focusedRedBalls.length,
redBalls.length - focusedRedBalls.length) *
RecookMath.combination(2 - focusedBlueBalls.length,
blueBalls.length - focusedBlueBalls.length);
else
return RecookMath.combination(5, redBalls.length) *
RecookMath.combination(2, blueBalls.length);
break;
}
return 0;
}
} }

@ -0,0 +1,20 @@
import 'package:flutter/material.dart';
import 'package:recook/pages/lottery/widget/lottery_scaffold.dart';
class LotteryCartPage extends StatefulWidget {
final dynamic arguments;
LotteryCartPage({Key key, this.arguments}) : super(key: key);
@override
_LotteryCartPageState createState() => _LotteryCartPageState();
}
class _LotteryCartPageState extends State<LotteryCartPage> {
@override
Widget build(BuildContext context) {
return LotteryScaffold(
title: '双色球',
body: SizedBox(),
);
}
}

@ -317,7 +317,21 @@ class _LotteryPickerPageState extends State<LotteryPickerPage> {
showToast(widget.arguments['type'] showToast(widget.arguments['type']
? '至少选6红球1蓝球' ? '至少选6红球1蓝球'
: '至少选5红球2蓝球'); : '至少选5红球2蓝球');
} else {} } else {
_clearAllSelect();
if (widget.arguments['type']) {
LotteryCartStore.add1Shot(
LotteryType.DOUBLE_LOTTERY,
LotteryCartModel(
type: LotteryType.DOUBLE_LOTTERY,
redBalls: _redBalls,
blueBalls: _blueBalls,
focusedRedBalls: _focusedRedBalls,
focusedBlueBalls: _focusedBlueBalls,
),
);
}
}
}, },
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.horizontal( borderRadius: BorderRadius.horizontal(
@ -388,25 +402,15 @@ class _LotteryPickerPageState extends State<LotteryPickerPage> {
} }
_countLotteryShot() { _countLotteryShot() {
if (widget.arguments['type']) { lotteryShots = LotteryCartStore.countLotteryBalls(
if (_focusedRedBalls.length >= 1 && _redBalls.length > 6) widget.arguments['type']
lotteryShots = RecookMath.combination(6 - _focusedRedBalls.length, ? LotteryType.DOUBLE_LOTTERY
_redBalls.length - _focusedRedBalls.length) * : LotteryType.BIG_LOTTERY,
RecookMath.combination(1, _blueBalls.length); redBalls: _redBalls,
else blueBalls: _blueBalls,
lotteryShots = RecookMath.combination(6, _redBalls.length) * focusedRedBalls: _focusedRedBalls,
RecookMath.combination(1, _blueBalls.length); focusedBlueBalls: _focusedBlueBalls,
} else { );
if ((_focusedRedBalls.length >= 1 || _focusedBlueBalls.length >= 1) &&
_redBalls.length > 5)
lotteryShots = RecookMath.combination(5 - _focusedRedBalls.length,
_redBalls.length - _focusedRedBalls.length) *
RecookMath.combination(2 - _focusedBlueBalls.length,
_blueBalls.length - _focusedBlueBalls.length);
else
lotteryShots = RecookMath.combination(5, _redBalls.length) *
RecookMath.combination(2, _blueBalls.length);
}
setState(() {}); setState(() {});
} }

@ -26,6 +26,7 @@ import 'package:recook/pages/home/widget/goods_hot_list_page.dart';
import 'package:recook/pages/home/widget/goods_list_temp_page.dart'; import 'package:recook/pages/home/widget/goods_list_temp_page.dart';
import 'package:recook/pages/login/wechat_bind_page.dart'; import 'package:recook/pages/login/wechat_bind_page.dart';
import 'package:recook/pages/login/wechat_input_invitecode_page.dart'; import 'package:recook/pages/login/wechat_input_invitecode_page.dart';
import 'package:recook/pages/lottery/lottery_cart_page.dart';
import 'package:recook/pages/lottery/lottery_help_page.dart'; import 'package:recook/pages/lottery/lottery_help_page.dart';
import 'package:recook/pages/lottery/lottery_history_page.dart'; import 'package:recook/pages/lottery/lottery_history_page.dart';
import 'package:recook/pages/lottery/lottery_order_detail_page.dart'; import 'package:recook/pages/lottery/lottery_order_detail_page.dart';
@ -320,6 +321,9 @@ class RouteName {
/// ///
static const String LOTTERY_ORDER_DETAIL_PAGE = "/LotteryOrderDetailPage"; static const String LOTTERY_ORDER_DETAIL_PAGE = "/LotteryOrderDetailPage";
///
static const String LOTTERY_CART_PAGE = "/LotteryCartPage";
} }
typedef RouteBuilder = Widget Function(BuildContext context, typedef RouteBuilder = Widget Function(BuildContext context,
@ -629,6 +633,9 @@ final Map<String, RouteBuilder> _routes = {
RouteName.LOTTERY_ORDER_PAGE: (context, {arguments}) => LotteryOrderPage(), RouteName.LOTTERY_ORDER_PAGE: (context, {arguments}) => LotteryOrderPage(),
RouteName.LOTTERY_ORDER_DETAIL_PAGE: (context, {arguments}) => RouteName.LOTTERY_ORDER_DETAIL_PAGE: (context, {arguments}) =>
LotteryOrderDetailPage(arguments: arguments), LotteryOrderDetailPage(arguments: arguments),
RouteName.LOTTERY_CART_PAGE:(context,{arguments})=> LotteryCartPage(
arguments:arguments
),
}; };
/// ///

Loading…
Cancel
Save