ShoppingMall.dart 9.0 KB

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