heavy_list_page.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/internal/heavy/model/heavy_count_item.dart';
  3. import 'package:liftmanager/internal/heavy/provider/heavy_page.dart';
  4. import 'package:liftmanager/internal/heavy/widgets/HeavyList.dart';
  5. import 'package:liftmanager/net/api_service.dart';
  6. import 'package:liftmanager/res/resources.dart';
  7. import 'package:liftmanager/utils/theme_utils.dart';
  8. import 'package:liftmanager/utils/toast.dart';
  9. import 'package:liftmanager/widgets/app_bar.dart';
  10. import 'package:provider/provider.dart' as p;
  11. class HeavyListPage extends StatefulWidget {
  12. HeavyListPage({this.topInto = false});
  13. final bool topInto;
  14. @override
  15. HeavyListPageState createState() => HeavyListPageState();
  16. }
  17. class HeavyListPageState extends State<HeavyListPage>
  18. with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  19. HeavyPageProvider provider = HeavyPageProvider();
  20. // List<Map> tabs = [{"id":0,"name":"未开始"},{"id":1,"name":"施工中"},{"id":2,"name":"待审核"},{"id":3,"name":"已完成"}];
  21. TabController _tabController;
  22. PageController _pageController = PageController(initialPage: 0);
  23. HeavyCountItem countItem = HeavyCountItem();
  24. @override
  25. void initState() {
  26. super.initState();
  27. _tabController = new TabController(vsync: this, length: 4);
  28. // if(widget.topInto){
  29. // _tabController.animateTo(1);
  30. // _pageController = PageController(initialPage: 1);
  31. // }else{
  32. _pageController = PageController(initialPage: 0);
  33. // }
  34. getCount();
  35. }
  36. getCount() {
  37. ApiService(context: context).heavyCount(onSuccess: (res) {
  38. if (res != null) {
  39. countItem = res;
  40. setState(() {});
  41. }
  42. }, onError: (code, msg) {
  43. toasts(msg);
  44. });
  45. }
  46. @override
  47. void dispose() {
  48. _tabController.dispose();
  49. super.dispose();
  50. }
  51. _onPageChange(int index) {
  52. _tabController.animateTo(index);
  53. provider.setIndex(index);
  54. }
  55. @override
  56. Widget build(BuildContext context) {
  57. return p.ChangeNotifierProvider<HeavyPageProvider>(
  58. create: (_) => provider,
  59. child: Scaffold(
  60. appBar: MyAppBar(
  61. centerTitle: "大修管理",
  62. ),
  63. body: Column(
  64. crossAxisAlignment: CrossAxisAlignment.start,
  65. children: <Widget>[
  66. Container(
  67. // 隐藏点击效果
  68. color:ThemeUtils.getTabsBg(context),
  69. child: TabBar(
  70. onTap: (index) {
  71. if (!mounted) {
  72. return;
  73. }
  74. _pageController.jumpToPage(index);
  75. },
  76. isScrollable: false,
  77. controller: _tabController,
  78. labelStyle: TextStyles.textBold18,
  79. indicatorSize: TabBarIndicatorSize.label,
  80. labelPadding: const EdgeInsets.all(0),
  81. unselectedLabelColor: Colours.text_gray,
  82. labelColor: Theme.of(context).primaryColor,
  83. indicatorPadding:
  84. const EdgeInsets.only(left: 5.0, right: 5.0),
  85. tabs: <Widget>[
  86. _TabView("未开始", "(${countItem.noStart})", 0),
  87. _TabView("施工中", "(${countItem.abuilding})", 1),
  88. _TabView("待审核", "(${countItem.checkPending})", 2),
  89. _TabView("已完成", "(${countItem.complete})", 3),
  90. ],
  91. ),
  92. ),
  93. Gaps.line,
  94. Expanded(
  95. child: PageView.builder(
  96. key: const Key('pageView'),
  97. itemCount: 4,
  98. onPageChanged: _onPageChange,
  99. controller: _pageController,
  100. itemBuilder: (BuildContext context, int index) {
  101. return Container(
  102. color: ThemeUtils.getBackgroundColor(context),
  103. child: HeavyList(index: index+1));
  104. },
  105. ),
  106. )
  107. ],
  108. ),
  109. ),
  110. );
  111. }
  112. @override
  113. bool get wantKeepAlive => true;
  114. }
  115. class _TabView extends StatelessWidget {
  116. const _TabView(this.tabName, this.tabSub, this.index);
  117. final String tabName;
  118. final String tabSub;
  119. final int index;
  120. @override
  121. Widget build(BuildContext context) {
  122. return p.Consumer<HeavyPageProvider>(
  123. builder: (_, provider, child) {
  124. return Tab(
  125. child: SizedBox(
  126. child: Row(
  127. crossAxisAlignment: CrossAxisAlignment.center,
  128. mainAxisAlignment: MainAxisAlignment.center,
  129. children: <Widget>[
  130. Text(
  131. tabName,
  132. style: TextStyle(fontSize: 15),
  133. ),
  134. Padding(
  135. padding: const EdgeInsets.only(top: 1.0),
  136. child: Text(tabSub,
  137. style: TextStyle(fontSize: Dimens.font_sp12)),
  138. ),
  139. ],
  140. ),
  141. ));
  142. },
  143. );
  144. }
  145. }
  146. //class HeavyListPage extends StatefulWidget {
  147. // @override
  148. // HeavyListPageState createState() => HeavyListPageState();
  149. //}
  150. //
  151. //class HeavyListPageState
  152. // extends BasePageState<HeavyListPage, HeavyListProvider>
  153. // with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  154. // BaseListProvider<ProjectListItem> provider =
  155. // BaseListProvider<ProjectListItem>();
  156. //
  157. // String _keyword = "";
  158. // int _page = 1;
  159. //
  160. // @override
  161. // void initState() {
  162. // /// 默认为加载中状态,本页面场景默认为空
  163. // provider.setStateTypeNotNotify(StateType.loading);
  164. // super.initState();
  165. // _onRefresh();
  166. // }
  167. //
  168. // ///电梯列表
  169. // void _liftList(id) {
  170. // NavigatorUtils.push(context, HeavyRouter.heavyLiftListPage + "?id=${id}");
  171. // }
  172. //
  173. // ///项目详情
  174. // void _projectDetail(id) {
  175. // NavigatorUtils.push(context, "${HeavyRouter.heavyDetailPage}?id=${id}");
  176. // }
  177. //
  178. // @override
  179. // Widget build(BuildContext context) {
  180. // return ChangeNotifierProvider<BaseListProvider<ProjectListItem>>(
  181. // create: (_) => provider,
  182. // child: Scaffold(
  183. // appBar: MyAppBar(
  184. // centerTitle: "大修模块",
  185. //// actions: <Widget>[
  186. //// FlatButton(
  187. //// child: Text("创建", key: const Key('actionName')),
  188. //// textColor: Colours.dark_text,
  189. //// highlightColor: Colors.transparent,
  190. //// onPressed: () {
  191. //// NavigatorUtils.push(context, HeavyRouter.heavyCreatePage);
  192. //// },
  193. //// )
  194. //// ],
  195. // ),
  196. // body: Container(
  197. // color: ThemeUtils.getBackgroundColor(context),
  198. // child: Column(
  199. // crossAxisAlignment: CrossAxisAlignment.start,
  200. // children: <Widget>[
  201. // Container(
  202. // color: ThemeUtils.getBackgroundColor(context),
  203. // padding:
  204. // EdgeInsets.only(top: 10, bottom: 10, left: 15, right: 15),
  205. // child: SearchBar(
  206. // hintText: "搜索大修项目",
  207. // autofocus: false,
  208. // onPressed: (text) {
  209. // _keyword = text;
  210. // provider.setStateType(StateType.loading);
  211. // _page = 1;
  212. // presenter.searchProject(context,_keyword, _page, true);
  213. // },
  214. // ),
  215. // ),
  216. // Expanded(
  217. // flex: 1,
  218. // child: Consumer<BaseListProvider<ProjectListItem>>(
  219. // builder: (_, provider, __) {
  220. // return MyListView(
  221. // key: Key('project_list'),
  222. // itemCount: provider.list.length,
  223. // stateType: provider.stateType,
  224. // onRefresh: _onRefresh,
  225. // loadMore: _loadMore,
  226. // hasMore: provider.hasMore,
  227. // itemBuilder: (_, index) {
  228. // return InkWell(
  229. // onTap: () {
  230. // _projectDetail(provider.list[index].projectId);
  231. // },
  232. // child: Container(
  233. // margin: EdgeInsets.fromLTRB(15, 5, 15, 5),
  234. // decoration: BoxDecoration(
  235. // color: Colors.white,
  236. // borderRadius: BorderRadius.circular(6.0),
  237. // ),
  238. // padding: const EdgeInsets.only(bottom: 10),
  239. // child: Column(
  240. // children: <Widget>[
  241. // Container(
  242. // decoration: BoxDecoration(
  243. // border: Border(
  244. // bottom: BorderSide(
  245. // width: 0.5,
  246. // color: Colours.text_gray_c),
  247. // )),
  248. // padding: EdgeInsets.only(left: 12),
  249. // child: Row(
  250. // children: <Widget>[
  251. // Expanded(
  252. // flex: 1,
  253. // child: Text(
  254. // provider
  255. // .list[index].projectName,
  256. // style: TextStyles.text15,
  257. // overflow: TextOverflow.ellipsis,
  258. // softWrap: false, //单行显示
  259. // )),
  260. // MyButton(
  261. // key: const Key('lift_list'),
  262. // onPressed: () {
  263. // _liftList(provider
  264. // .list[index].projectId);
  265. // },
  266. // height: 25,
  267. // fontSize: 11,
  268. // colors: [
  269. // Colours.app_main,
  270. // Colours.app_main
  271. // ],
  272. // borderWidth: 0.5,
  273. // borderColor: Colours.app_main,
  274. // text: "查看电梯",
  275. // )
  276. // ],
  277. // ),
  278. // ),
  279. // lineTxt("大修单编号",
  280. // "${provider.list[index].projectCode}"),
  281. // lineTxt(
  282. // "项目用途",
  283. // "${Constant.projectUsageText[int.parse(provider.list[index].projectUsage)]}",
  284. // ),
  285. // lineTxt("台量",
  286. // "${provider.list[index].actualNum}")
  287. // ],
  288. // ),
  289. // ));
  290. // },
  291. // );
  292. // }))
  293. // ],
  294. // ),
  295. // ),
  296. // ));
  297. // }
  298. //
  299. // Widget lineTxt(title, value) {
  300. // return Container(
  301. // padding: EdgeInsets.only(left: 12, top: 5, right: 12),
  302. // child: Row(
  303. // children: <Widget>[
  304. // Text("${title}",
  305. // style: TextStyle(fontSize: 13, color: Colours.dark_text_gray)),
  306. // Expanded(
  307. // flex: 1,
  308. // child: Text(
  309. // "${value}",
  310. // textAlign: TextAlign.right,
  311. // style: TextStyle(fontSize: 13, color: Colours.dark_text_gray),
  312. // ),
  313. // )
  314. // ],
  315. // ),
  316. // );
  317. // }
  318. //
  319. // Future _onRefresh() async {
  320. // _page = 1;
  321. // await presenter.searchProject(context,_keyword, _page, false);
  322. // }
  323. //
  324. // Future _loadMore() async {
  325. // _page++;
  326. // await presenter.searchProject(context,_keyword, _page, false);
  327. // }
  328. //
  329. // @override
  330. // HeavyListProvider createPresenter() {
  331. // return HeavyListProvider();
  332. // }
  333. //
  334. // @override
  335. // bool get wantKeepAlive => true;
  336. //}