ShoppingMall.dart 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_redux/flutter_redux.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:intl/intl.dart';
  5. import '../redux/AppState.dart';
  6. import '../model/ProductInfo.dart';
  7. import '../widget/Dialog.dart';
  8. import '../redux/UserRedux.dart';
  9. import '../model/UserInfo.dart';
  10. import '../styles/colors.dart';
  11. import '../net/HttpManager.dart';
  12. import '../net/Result.dart';
  13. import '../styles/totast.dart';
  14. import 'ChoosePay.dart';
  15. import 'dart:io';
  16. class ShoppingMall extends StatefulWidget {
  17. @override
  18. ShoppingMallState createState() => ShoppingMallState();
  19. }
  20. class ShoppingMallState extends State<ShoppingMall> {
  21. // final List<Tab> myTabs = <Tab>[Tab(text: '门票购买'), Tab(text: '会员充值')];
  22. @override
  23. Widget build(BuildContext context) {
  24. return Scaffold(
  25. appBar: AppBar(
  26. // backgroundColor: PRIMARY_COLOR,
  27. title: Text('充值参赛券'),
  28. centerTitle: true,
  29. ),
  30. body: Recharge(type: 0),
  31. );
  32. }
  33. }
  34. class Recharge extends StatefulWidget {
  35. Recharge({Key key, this.type}) : super(key: key);
  36. final int type; //类型 0 金币 1 会员
  37. @override
  38. RechargeState createState() => RechargeState();
  39. }
  40. class RechargeState extends State<Recharge> {
  41. Future<void> getUserInfo() async {
  42. Result res = await HttpManager.get('userInfo/getUserInfo');
  43. if (res.success) {
  44. print(res.data);
  45. StoreProvider.of<AppState>(context).dispatch(UpdateUserAction(UserInfo.fromJson(res.data)));
  46. } else {}
  47. }
  48. List moneyList = [100, 300, 500, 1000, 2000, 5000];
  49. List vipList = [
  50. {'name': 'VIP1', 'value': 100},
  51. {'name': 'VIP2', 'value': 300},
  52. {'name': 'VIP3', 'value': 500},
  53. {'name': 'VIP4', 'value': 1000},
  54. {'name': 'VIP5', 'value': 2000},
  55. {'name': 'VIP6', 'value': 5000}
  56. ];
  57. List<ProductInfo> productInfoList = [];
  58. int chooseMoney = 0;
  59. ProductInfo chooseProduct;
  60. int payWay = 1; // 类型 1普通 2微信支付宝
  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. final Result res2 = await HttpManager.get('payCodeStock/allUsedMoney', data: {'typeFlag': widget.type});
  80. if (res2.success) {
  81. for (var item in productInfoList) {
  82. for (var k in res2.data) {
  83. if (item.money == k['money']) {
  84. item.canUse = true;
  85. }
  86. }
  87. }
  88. }
  89. Result res3 = await HttpManager.get('systemVariable/get', data: {'name': "pay_channel"});
  90. if (res3.success) {
  91. print(res3.data);
  92. setState(() {
  93. payWay = int.parse(res3.data);
  94. });
  95. }
  96. for (var item in productInfoList) {
  97. if (item.canUse) {
  98. setState(() {
  99. chooseProduct = item;
  100. });
  101. break;
  102. }
  103. }
  104. }
  105. Future<void> showDialog(id) async {
  106. Toast.show(context, '加载中', -1, 'loading');
  107. Result res = await HttpManager.get('alertMessage/getOne', data: {'id': id});
  108. Toast.hide();
  109. if (res.success) {
  110. MyDialog.showDialog(context, res.data['remark']);
  111. }
  112. }
  113. @override
  114. void initState() {
  115. super.initState();
  116. getInfoList();
  117. }
  118. @override
  119. Widget build(BuildContext context) {
  120. return Scaffold(
  121. body: Container(
  122. color: BG_COLOR,
  123. child: ListView.builder(
  124. itemCount: productInfoList.length + 1,
  125. itemBuilder: (BuildContext context, int index) {
  126. if (index == productInfoList.length) {
  127. return Container(
  128. height: 80,
  129. child: Center(
  130. child: Text('0点至8点到账缓慢,请提前充值', style: TextStyle(color: Color(0xFF727785), fontSize: 14)),
  131. ),
  132. );
  133. }
  134. bool isChoose = false;
  135. if (chooseProduct != null && productInfoList[index].id == chooseProduct.id) {
  136. isChoose = true;
  137. }
  138. return Container(
  139. padding: EdgeInsets.symmetric(horizontal: 15),
  140. margin: EdgeInsets.only(top: 10),
  141. height: 60,
  142. child: FlatButton(
  143. color: Color(0xFF24263A),
  144. padding: EdgeInsets.all(0),
  145. shape: RoundedRectangleBorder(
  146. borderRadius: BorderRadius.circular(4.0),
  147. side: BorderSide(color: isChoose ? Theme.of(context).primaryColor : Colors.transparent, width: 1)),
  148. disabledColor: Color(0xFF24263A).withOpacity(0.8),
  149. child: Container(
  150. child: Stack(
  151. children: <Widget>[
  152. Center(
  153. child: Row(
  154. mainAxisAlignment: MainAxisAlignment.center,
  155. children: <Widget>[
  156. Text(productInfoList[index].productName,
  157. style: TextStyle(
  158. color: productInfoList[index].canUse || payWay == 2 ? Color(0xFFFFFFFF) : Color(0xFF666666),
  159. fontWeight: FontWeight.w500,
  160. fontSize: 15)),
  161. Container(
  162. width: 10,
  163. ),
  164. Text(
  165. '¥' + productInfoList[index].money.toString(),
  166. style: TextStyle(
  167. color: productInfoList[index].canUse || payWay == 2 ? Color(0xFF727785) : Color(0xFF666666),
  168. fontWeight: FontWeight.w400,
  169. fontSize: 14),
  170. )
  171. ],
  172. ),
  173. ),
  174. Positioned(
  175. right: 0,
  176. bottom: 0,
  177. child: isChoose ? Image.asset('images/icon_xuanzhong.png') : Container(),
  178. )
  179. ],
  180. ),
  181. ),
  182. onPressed: productInfoList[index].canUse || payWay == 2
  183. ? () {
  184. if (!isChoose) {
  185. setState(() {
  186. chooseProduct = productInfoList[index];
  187. });
  188. }
  189. }
  190. : null,
  191. ),
  192. );
  193. }),
  194. ),
  195. floatingActionButton: Container(
  196. width: double.infinity,
  197. padding: EdgeInsets.symmetric(horizontal: 15),
  198. height: 48,
  199. child: FlatButton(
  200. color: PRIMARY_COLOR,
  201. textColor: Colors.white,
  202. child: Text('立即充值'),
  203. onPressed: () async {
  204. if (chooseProduct == null) {
  205. Toast.show(context, '请选择充值的门票', 1500, 'info');
  206. return;
  207. }
  208. Result res = await HttpManager.get('systemVariable/get', data: {'name': "iosPayHide"});
  209. if (res.success && res.data != null && res.data == 'true' && Platform.isIOS) {
  210. MyDialog.showDialog(context, 'ios充值暂未开放');
  211. } else {
  212. Navigator.push(context, CupertinoPageRoute(builder: (context) => ChoosePay(widget.type, chooseProduct, payWay)));
  213. }
  214. // Toast.show(context, '加载中', -1, 'loading');
  215. // final Result res = await HttpManager.post('productInfo/buy', data: {
  216. // 'userId': StoreProvider.of<AppState>(context).state.userInfo.id,
  217. // 'typeFlag': widget.type,
  218. // 'money': chooseProduct.money,
  219. // 'id': chooseProduct.id
  220. // });
  221. // Toast.hide();
  222. // if (res.success) {
  223. // Toast.show(context, '购买成功', 1500, 'success');
  224. // getUserInfo();
  225. // } else {
  226. // Toast.show(context, res.error, 1500, 'info');
  227. // }
  228. },
  229. ),
  230. ),
  231. floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
  232. );
  233. }
  234. }
  235. typedef void OnTapMenu();
  236. class ShoopingBtn extends StatelessWidget {
  237. final String icon;
  238. final String title;
  239. final OnTapMenu onTapHomeMenu;
  240. ShoopingBtn(
  241. this.icon,
  242. this.title, {
  243. this.onTapHomeMenu,
  244. });
  245. @override
  246. Widget build(BuildContext context) {
  247. return Container(
  248. height: 70,
  249. decoration: BoxDecoration(
  250. // gradient: LinearGradient(begin: Alignment.topCenter, end: Alignment.bottomCenter, stops: [0.0, 0.5], colors: [Color(0xFF464B6A), Color(0xFF35395E)])
  251. color: Color(0xFF3A3E61),
  252. borderRadius: BorderRadius.all(Radius.circular(4)),
  253. ),
  254. child: Material(
  255. color: Colors.transparent,
  256. child: InkWell(
  257. onTap: onTapHomeMenu,
  258. child: Column(
  259. mainAxisAlignment: MainAxisAlignment.center,
  260. children: <Widget>[
  261. Image.asset(
  262. icon,
  263. width: 20,
  264. height: 20,
  265. ),
  266. Container(
  267. height: 5,
  268. ),
  269. Text(
  270. title,
  271. style: TextStyle(
  272. fontSize: 13,
  273. fontWeight: FontWeight.w600,
  274. color: Theme.of(context).primaryColor,
  275. ),
  276. )
  277. ],
  278. ),
  279. )),
  280. );
  281. }
  282. }