ShoppingMall_old.dart 9.3 KB

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