MyTeam.dart 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. import 'package:flutter/material.dart';
  2. import 'package:redux/redux.dart';
  3. import 'package:flutter_redux/flutter_redux.dart';
  4. import '../redux/AppState.dart';
  5. import '../model/UserInfo.dart';
  6. import '../net/HttpManager.dart';
  7. import '../model/UserInfo.dart';
  8. import '../styles/totast.dart';
  9. import '../net/Result.dart';
  10. import '../model/UserLevel.dart';
  11. class MyTeam extends StatefulWidget {
  12. @override
  13. MyTeamState createState() => MyTeamState();
  14. }
  15. class MyTeamState extends State<MyTeam> {
  16. List<UserInfo> teamList = [];
  17. bool isShow = false;
  18. num _topHeight;
  19. int currentPage = 1;
  20. bool canNext = true;
  21. List<UserLevel> levelList = [];
  22. ScrollController _controller;
  23. UserInfo higherLevel = UserInfo.empty();
  24. Future<void> getHigh() async {
  25. Result res = await HttpManager.get('userInfo/getUserInfo', data: {
  26. "id": StoreProvider.of<AppState>(context).state.userInfo.recommender
  27. });
  28. if (res.success) {
  29. setState(() {
  30. higherLevel = UserInfo.fromJson(res.data);
  31. });
  32. }
  33. }
  34. Future<void> getLevel() async {
  35. Result res = await HttpManager.get('userLevel/all', data: {});
  36. if (res.success) {
  37. setState(() {
  38. for (var item in res.data) {
  39. UserLevel _l = UserLevel.fromJson(item);
  40. levelList.add(_l);
  41. }
  42. });
  43. }
  44. }
  45. Future<void> getLevelList() async {
  46. Toast.show(context, '加载中', -1, 'loading');
  47. canNext = false;
  48. Result res = await HttpManager.get('userInfo/page', data: {
  49. 'recommender': StoreProvider.of<AppState>(context).state.userInfo.id,
  50. 'currentPage': currentPage,
  51. 'pageNumber': 20,
  52. 'adminFlag': "N",
  53. });
  54. Toast.hide();
  55. if (res.success) {
  56. if (currentPage == 1) {
  57. teamList = [];
  58. }
  59. setState(() {
  60. for (var item in res.data['pp']) {
  61. UserInfo _u = UserInfo.fromJson(item);
  62. teamList.add(_u);
  63. }
  64. });
  65. if (res.data['page']['totalNumber'] > currentPage) {
  66. canNext = true;
  67. }
  68. } else {}
  69. }
  70. @override
  71. void initState() {
  72. super.initState();
  73. Future.delayed(Duration.zero, () {
  74. if (StoreProvider.of<AppState>(context).state.userInfo.recommender !=
  75. null) {
  76. getHigh();
  77. }
  78. getLevelList();
  79. getLevel();
  80. });
  81. _controller = ScrollController();
  82. _controller.addListener(() {
  83. if (_controller.position.pixels == _controller.position.maxScrollExtent &&
  84. canNext) {
  85. currentPage++;
  86. getLevelList();
  87. }
  88. });
  89. }
  90. @override
  91. void dispose() {
  92. super.dispose();
  93. _controller.dispose();
  94. }
  95. @override
  96. Widget build(BuildContext context) {
  97. return StoreConnector<AppState, UserInfo>(
  98. converter: (Store store) => store.state.userInfo,
  99. builder: (context, userInfo) {
  100. return Scaffold(
  101. appBar: AppBar(
  102. title: Text('我的团队'),
  103. centerTitle: true,
  104. ),
  105. body: Container(
  106. color: Color(0xFF2B2B42),
  107. height: double.infinity,
  108. child: SingleChildScrollView(
  109. controller: _controller,
  110. child: Column(
  111. children: <Widget>[
  112. Container(
  113. height: 128,
  114. decoration: BoxDecoration(
  115. image: DecorationImage(
  116. image: AssetImage('images/img_tuandui.png'),
  117. fit: BoxFit.cover)),
  118. child: Center(
  119. child: Image.asset('images/text_01.png'),
  120. ),
  121. ),
  122. higherLevel.id != null
  123. ? Container(
  124. padding: EdgeInsets.symmetric(vertical: 10),
  125. color: Color(0xFF27273B),
  126. child: Container(
  127. padding: EdgeInsets.symmetric(
  128. vertical: 12, horizontal: 15),
  129. color: Color(0xFF2B2B42),
  130. child: Row(
  131. children: <Widget>[
  132. Text(
  133. '我的上级',
  134. style: TextStyle(
  135. color: Theme.of(context).primaryColor,
  136. fontSize: 14,
  137. fontWeight: FontWeight.w500),
  138. ),
  139. Expanded(
  140. flex: 1,
  141. child: Container(),
  142. ),
  143. CircleAvatar(
  144. backgroundImage:
  145. NetworkImage(higherLevel.icon),
  146. ),
  147. Container(
  148. width: 12,
  149. ),
  150. Text(higherLevel.nickname,
  151. style: TextStyle(
  152. color: Colors.white,
  153. fontSize: 14,
  154. fontWeight: FontWeight.w500))
  155. ],
  156. ),
  157. ),
  158. )
  159. : Container(
  160. color: Color(0xFF27273B),
  161. height: 10,
  162. ),
  163. Container(
  164. padding:
  165. EdgeInsets.symmetric(horizontal: 15, vertical: 20),
  166. decoration: BoxDecoration(
  167. border: Border(
  168. bottom: BorderSide(
  169. width: 1,
  170. color: Color(0xFF27273B),
  171. ))),
  172. child: Row(
  173. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  174. children: <Widget>[
  175. Text(
  176. '我的下级',
  177. style: TextStyle(
  178. color:Theme.of(context).primaryColor,
  179. fontSize: 14,
  180. fontWeight: FontWeight.w500),
  181. ),
  182. Text(
  183. teamList.length.toString() + '位',
  184. style: TextStyle(
  185. color: Color(0xFF727785), fontSize: 13),
  186. )
  187. ],
  188. ),
  189. ),
  190. Padding(
  191. padding: EdgeInsets.symmetric(horizontal: 15),
  192. child: ListView(
  193. shrinkWrap: true,
  194. children: _widgetList(),
  195. ),
  196. )
  197. ],
  198. ),
  199. ),
  200. ),
  201. );
  202. });
  203. }
  204. List<Widget> _widgetList() {
  205. List<Widget> list = [];
  206. if (teamList.isEmpty) {
  207. list.add(Padding(
  208. child: Center(
  209. child: Text('暂无数据', style: TextStyle(color: Colors.white24)),
  210. ),
  211. padding: EdgeInsets.symmetric(vertical: 10),
  212. ));
  213. } else {
  214. for (var item in teamList) {
  215. var _widget = Container(
  216. height: 60,
  217. decoration: BoxDecoration(
  218. border: Border(
  219. bottom: BorderSide(
  220. width: 1,
  221. color: Color(0xFF27273B),
  222. ))),
  223. child: Row(
  224. children: <Widget>[
  225. CircleAvatar(
  226. backgroundImage: NetworkImage(item.icon),
  227. ),
  228. Container(
  229. width: 12,
  230. ),
  231. Expanded(
  232. flex: 1,
  233. child: Text(
  234. item.nickname,
  235. style: TextStyle(
  236. color: Colors.white,
  237. fontSize: 14,
  238. ),
  239. )),
  240. backLevel(item.levelId)
  241. ],
  242. ),
  243. );
  244. list.add(_widget);
  245. }
  246. }
  247. return list;
  248. }
  249. Widget backLevel(int id) {
  250. Widget _w = Container();
  251. String name = '';
  252. for (var item in levelList) {
  253. if (id == item.id && id > 1) {
  254. name = item.name;
  255. }
  256. }
  257. if (name != '') {
  258. _w = Container(
  259. child: Text(
  260. name,
  261. style: TextStyle(fontSize: 12, color: Theme.of(context).primaryColor),
  262. ),
  263. padding: EdgeInsets.symmetric(vertical: 4, horizontal: 5),
  264. decoration: BoxDecoration(
  265. border: Border.all(width: 1, color: Theme.of(context).primaryColor)),
  266. );
  267. }
  268. return _w;
  269. }
  270. }