Recharge.dart 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import 'package:flutter/material.dart';
  2. import '../styles/colors.dart';
  3. import '../net/HttpManager.dart';
  4. import '../net/Result.dart';
  5. import '../styles/totast.dart';
  6. import 'package:flutter_redux/flutter_redux.dart';
  7. import '../redux/AppState.dart';
  8. import '../model/ProductInfo.dart';
  9. import '../widget/Dialog.dart';
  10. class Recharge extends StatefulWidget {
  11. @override
  12. RechargeState createState() => RechargeState();
  13. }
  14. class RechargeState extends State<Recharge> {
  15. final List<Tab> myTabs = <Tab>[Tab(text: '金币充值'), Tab(text: '会员充值')];
  16. @override
  17. Widget build(BuildContext context) {
  18. return DefaultTabController(
  19. length: myTabs.length,
  20. child: Scaffold(
  21. appBar: AppBar(
  22. title: Padding(
  23. padding: EdgeInsets.only(right: 56),
  24. child: TabBar(
  25. tabs: myTabs,
  26. indicatorColor: Colors.white,
  27. labelColor: Colors.white,
  28. indicatorSize: TabBarIndicatorSize.label,
  29. ),
  30. ),
  31. ),
  32. body: TabBarView(
  33. children: <Widget>[
  34. RechargePage(type: 0),
  35. RechargePage(type: 1),
  36. ],
  37. ),
  38. ),
  39. );
  40. }
  41. }
  42. class RechargePage extends StatefulWidget {
  43. RechargePage({Key key, this.type}) : super(key: key);
  44. final int type; //类型 0 金币 1 会员
  45. @override
  46. RechargePageState createState() => RechargePageState();
  47. }
  48. class RechargePageState extends State<RechargePage> {
  49. List moneyList = [100, 300, 500, 1000, 2000, 5000];
  50. List vipList = [
  51. {'name': 'VIP1', 'value': 100},
  52. {'name': 'VIP2', 'value': 300},
  53. {'name': 'VIP3', 'value': 500},
  54. {'name': 'VIP4', 'value': 1000},
  55. {'name': 'VIP5', 'value': 2000},
  56. {'name': 'VIP6', 'value': 5000}
  57. ];
  58. List<ProductInfo> productInfoList = [];
  59. int chooseMoney = 0;
  60. ProductInfo chooseProduct;
  61. Future<void> getInfoList() async {
  62. Toast.show(context, '加载中', -1, 'loading');
  63. final Result res = await HttpManager.get('productInfo/all', data: {'typeFlag': widget.type});
  64. Toast.hide();
  65. if (res.success) {
  66. for (var item in res.data) {
  67. ProductInfo product;
  68. product = ProductInfo.fromJson(item);
  69. setState(() {
  70. productInfoList.add(product);
  71. });
  72. }
  73. if (productInfoList.isNotEmpty) {
  74. setState(() {
  75. chooseProduct = productInfoList[0];
  76. });
  77. }
  78. }
  79. }
  80. Future<void> showDialog(id) async {
  81. Toast.show(context, '加载中', -1, 'loading');
  82. Result res = await HttpManager.get('alertMessage/getOne', data: {'id': id});
  83. Toast.hide();
  84. if (res.success) {
  85. showCustomDialog(context, res.data['remark']);
  86. }
  87. }
  88. @override
  89. void initState() {
  90. super.initState();
  91. getInfoList();
  92. }
  93. @override
  94. Widget build(BuildContext context) {
  95. return Scaffold(
  96. body: Container(
  97. color: BG_COLOR,
  98. child: ListView.builder(
  99. itemCount: productInfoList.length + 1,
  100. itemBuilder: (BuildContext context, int index) {
  101. if (index == 0) {
  102. return Padding(
  103. padding: EdgeInsets.fromLTRB(15, 15, 15, 10),
  104. child: Row(
  105. crossAxisAlignment: CrossAxisAlignment.center,
  106. mainAxisAlignment: MainAxisAlignment.center,
  107. children: <Widget>[
  108. Expanded(
  109. flex: 1,
  110. child: ShoopingBtn('images/icon_haoli.png', '更多好礼', onTapHomeMenu: () {
  111. showDialog(2);
  112. }),
  113. ),
  114. Container(
  115. width: 15,
  116. ),
  117. Expanded(
  118. flex: 1,
  119. child: ShoopingBtn('images/icon_shangwu.png', '商务合作', onTapHomeMenu: () {
  120. showDialog(3);
  121. }),
  122. ),
  123. ],
  124. ),
  125. );
  126. }
  127. bool isChoose = false;
  128. if (productInfoList[index - 1].id == chooseProduct.id) {
  129. isChoose = true;
  130. }
  131. return Container(
  132. padding: EdgeInsets.symmetric(horizontal: 15),
  133. margin: EdgeInsets.only(top: 10),
  134. height: 60,
  135. child: FlatButton(
  136. color: Color(0xFF222335),
  137. padding: EdgeInsets.all(0),
  138. shape: Border.all(color: isChoose ? Color(0xFFC2524D) : Colors.transparent, width: 1),
  139. disabledColor: Color(0xFF222335),
  140. child: Container(
  141. child: Stack(
  142. children: <Widget>[
  143. Center(
  144. child: Row(
  145. mainAxisAlignment: MainAxisAlignment.center,
  146. children: <Widget>[
  147. Text(productInfoList[index - 1].productName,
  148. style: TextStyle(color: Color(0xFFFFFFFF), fontWeight: FontWeight.bold, fontSize: 15)),
  149. Container(
  150. width: 10,
  151. ),
  152. Text(
  153. '¥' + productInfoList[index - 1].money.toString(),
  154. style: TextStyle(color: Color(0xFF727785), fontWeight: FontWeight.normal, fontSize: 14),
  155. )
  156. ],
  157. ),
  158. ),
  159. Positioned(
  160. right: 0,
  161. bottom: 0,
  162. child: isChoose ? Image.asset('images/icon_xuanzhong.png', width: 36) : Container(),
  163. )
  164. ],
  165. ),
  166. ),
  167. onPressed: isChoose
  168. ? null
  169. : () {
  170. setState(() {
  171. chooseProduct = productInfoList[index - 1];
  172. });
  173. },
  174. ),
  175. );
  176. }),
  177. ),
  178. floatingActionButton: Container(
  179. width: double.infinity,
  180. padding: EdgeInsets.symmetric(horizontal: 15),
  181. height: 48,
  182. child: FlatButton(
  183. color: PRIMARY_COLOR,
  184. textColor: Colors.white,
  185. child: Text('立即充值'),
  186. onPressed: () async {
  187. Toast.show(context, '加载中', -1, 'loading');
  188. final Result res = await HttpManager.post('productInfo/buy', data: {
  189. 'userId': StoreProvider.of<AppState>(context).state.userInfo.id,
  190. 'typeFlag': widget.type,
  191. 'money': chooseProduct.money,
  192. 'id': chooseProduct.id
  193. });
  194. Toast.hide();
  195. if (res.success) {
  196. Toast.show(context, '购买成功', 1500, 'success');
  197. } else {
  198. Toast.show(context, res.error, 1500, 'info');
  199. }
  200. },
  201. ),
  202. ),
  203. floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
  204. );
  205. }
  206. }
  207. typedef void OnTapMenu();
  208. class ShoopingBtn extends StatelessWidget {
  209. final String icon;
  210. final String title;
  211. final OnTapMenu onTapHomeMenu;
  212. ShoopingBtn(
  213. this.icon,
  214. this.title, {
  215. this.onTapHomeMenu,
  216. });
  217. @override
  218. Widget build(BuildContext context) {
  219. return Container(
  220. height: 70,
  221. decoration: BoxDecoration(
  222. gradient: LinearGradient(begin: Alignment.topCenter, end: Alignment.bottomCenter, stops: [0.0, 0.5], colors: [Color(0xFF464B6A), Color(0xFF35395E)])),
  223. child: Material(
  224. color: Colors.transparent,
  225. child: InkWell(
  226. onTap: onTapHomeMenu,
  227. child: Column(
  228. mainAxisAlignment: MainAxisAlignment.center,
  229. children: <Widget>[
  230. Image.asset(
  231. icon,
  232. width: 20,
  233. height: 20,
  234. ),
  235. Container(
  236. height: 5,
  237. ),
  238. Text(
  239. title,
  240. style: TextStyle(
  241. fontSize: 13,
  242. fontWeight: FontWeight.bold,
  243. color: Color(0xFFC2524D),
  244. ),
  245. )
  246. ],
  247. ),
  248. )),
  249. );
  250. }
  251. }