HeavyList.dart 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/common/common.dart';
  3. import 'package:liftmanager/common/user_db.dart';
  4. import 'package:liftmanager/internal/heavy/heavy_router.dart';
  5. import 'package:liftmanager/internal/heavy/model/heavy_list_entity.dart';
  6. import 'package:liftmanager/internal/maintenance/maintenance_router.dart';
  7. import 'package:liftmanager/internal/maintenance/model/maintenance_list_entity.dart';
  8. import 'package:liftmanager/net/api_service.dart';
  9. import 'package:liftmanager/res/resources.dart';
  10. import 'package:liftmanager/routers/fluro_navigator.dart';
  11. import 'package:liftmanager/utils/toast.dart';
  12. import 'package:liftmanager/widgets/my_button.dart';
  13. import 'package:liftmanager/widgets/my_refresh_list.dart';
  14. import 'package:liftmanager/widgets/state_layout.dart';
  15. import 'dart:convert' as convert;
  16. import 'package:oktoast/oktoast.dart';
  17. class HeavyList extends StatefulWidget {
  18. const HeavyList({Key key, @required this.index}) : super(key: key);
  19. final int index;
  20. @override
  21. _HeavyListState createState() => _HeavyListState();
  22. }
  23. class _HeavyListState extends State<HeavyList>
  24. with
  25. AutomaticKeepAliveClientMixin<HeavyList>,
  26. SingleTickerProviderStateMixin {
  27. List<HeavyListItem> _list = [];
  28. int _page = 1;
  29. int _maxPage = 999;
  30. StateType _stateType = StateType.loading;
  31. @override
  32. void initState() {
  33. super.initState();
  34. //Item数量
  35. // _maxPage = widget.index == 0 ? 1 : (widget.index == 1 ? 2 : 3);
  36. _onRefresh();
  37. getHasRole();
  38. }
  39. bool noRole = true;
  40. getHasRole() async {
  41. var role = await User().getCompanyRole();
  42. if(role == Constant.RoleAdmin || role == Constant.RoleRegion || role == Constant.RoleWork){
  43. noRole = false;
  44. setState(() {
  45. });
  46. }
  47. }
  48. Future _onRefresh() async {
  49. _stateType = StateType.loading;
  50. _page = 1;
  51. _maxPage = 999;
  52. ApiService(context: context).searchHeavyProject(_page, 10, widget.index,
  53. onSuccess: (HeavyListEntity data) {
  54. _stateType = StateType.empty;
  55. if (data != null) {
  56. if (_page == 1) {
  57. _list.clear();
  58. }
  59. if (data.rows.length < 10) {
  60. _maxPage = _page;
  61. }
  62. if (data != null) {
  63. _list.addAll(data.rows);
  64. }
  65. }
  66. setState(() {});
  67. }, onError: (code, msg) {
  68. showToast(msg);
  69. });
  70. }
  71. Future _loadMore() async {
  72. _stateType = StateType.loading;
  73. _page++;
  74. ApiService(context: context).searchHeavyProject(_page, 10, widget.index,
  75. onSuccess: (HeavyListEntity data) {
  76. _stateType = StateType.empty;
  77. if (data.rows.length < 10) {
  78. _maxPage = _page;
  79. }
  80. _list.addAll(data.rows);
  81. _page++;
  82. setState(() {});
  83. }, onError: (code, msg) {
  84. showToast(msg);
  85. });
  86. }
  87. ///电梯列表
  88. void _liftList(id) {
  89. NavigatorUtils.push(context, HeavyRouter.heavyLiftListPage + "?id=${id}");
  90. }
  91. ///项目详情
  92. void _projectDetail(id,projectStatus) {
  93. NavigatorUtils.push(context, "${HeavyRouter.heavyDetailPage}?id=${id}&status=${projectStatus}");
  94. }
  95. void _startProject(id) {
  96. showAlert(context, "提示", "现在开工?", "确定", (){
  97. NavigatorUtils.goBack(context);
  98. showLoading(context, "正在加载");
  99. ApiService(context: context).capitalBegin(id,onSuccess: (res){
  100. dismissLoading(context);
  101. _onRefresh();
  102. },onError: (code,msg){
  103. dismissLoading(context);
  104. toasts(msg);
  105. });
  106. },txt2: "取消",onPre2: (){
  107. NavigatorUtils.goBack(context);
  108. });
  109. }
  110. void _endProject(id) {
  111. showAlert(context, "提示", "现在开工?", "确定", (){
  112. ApiService(context: context).capitalBegin(id,onSuccess: (res){
  113. if(res !=null){
  114. _onRefresh();
  115. }
  116. },onError: (code,msg){
  117. toasts(msg);
  118. });
  119. },txt2: "取消",onPre2: (){
  120. NavigatorUtils.goBack(context);
  121. });
  122. }
  123. @override
  124. Widget build(BuildContext context) {
  125. super.build(context);
  126. return MyListView(
  127. itemCount: _list.length,
  128. stateType: _stateType,
  129. onRefresh: _onRefresh,
  130. loadMore: _loadMore,
  131. hasMore: _page < _maxPage,
  132. itemBuilder: (_, index) {
  133. return InkWell(
  134. onTap: () {
  135. _projectDetail(_list[index].projectId,_list[index].projectStatus);
  136. },
  137. child: Container(
  138. margin: EdgeInsets.fromLTRB(15, 5, 15, 5),
  139. decoration: BoxDecoration(
  140. color: Colors.white,
  141. borderRadius: BorderRadius.circular(6.0),
  142. ),
  143. padding: const EdgeInsets.only(bottom: 10),
  144. child: Column(
  145. children: <Widget>[
  146. Container(
  147. decoration: BoxDecoration(
  148. border: Border(
  149. bottom:
  150. BorderSide(width: 0.5, color: Colours.text_gray_c),
  151. )),
  152. padding: EdgeInsets.only(left: 12),
  153. child: Row(
  154. children: <Widget>[
  155. Expanded(
  156. flex: 1,
  157. child: Text(
  158. _list[index].projectName,
  159. style: TextStyles.text15,
  160. overflow: TextOverflow.ellipsis,
  161. softWrap: false, //单行显示
  162. )),
  163. Offstage(
  164. offstage: noRole || !(_list[index].projectStatus=="1" && _list[index].isMonitor=="1"),
  165. child: MyButton(
  166. key: const Key('lift_list'),
  167. onPressed: () {
  168. _startProject(_list[index].projectId);
  169. },
  170. height: 25,
  171. fontSize: 11,
  172. colors: [Colours.app_main, Colours.app_main],
  173. borderWidth: 0.5,
  174. borderColor: Colours.app_main,
  175. text: "开工",
  176. )
  177. ),
  178. // Offstage(
  179. // offstage: !(widget.projectStatus=="2"&&item.isMonitor=="1"),
  180. // child: FlatButton(
  181. // child: Text("竣工"),
  182. // textColor: Colours.dark_text,
  183. // highlightColor: Colors.transparent,
  184. // onPressed: () {
  185. // NavigatorUtils.push(context, "${HeavyRouter.heavyEndPage}?id="+widget.projectId);
  186. // },
  187. // )
  188. // ),
  189. Offstage(
  190. offstage:noRole || !(_list[index].projectStatus=="2"&&_list[index].isMonitor=="1"),
  191. child: MyButton(
  192. key: const Key('lift_list'),
  193. onPressed: () {
  194. NavigatorUtils.push(context, "${HeavyRouter.heavyEndPage}?id="+_list[index].projectId);
  195. },
  196. height: 25,
  197. fontSize: 11,
  198. colors: [Colours.app_main, Colours.app_main],
  199. borderWidth: 0.5,
  200. borderColor: Colours.app_main,
  201. text: "竣工",
  202. )
  203. ),
  204. MyButton(
  205. key: const Key('lift_list'),
  206. onPressed: () {
  207. _liftList(_list[index].projectId);
  208. },
  209. height: 25,
  210. fontSize: 11,
  211. colors: [Colours.app_main, Colours.app_main],
  212. borderWidth: 0.5,
  213. borderColor: Colours.app_main,
  214. text: "查看电梯",
  215. )
  216. ],
  217. ),
  218. ),
  219. lineTxt("大修单编号", "${_list[index].projectCode}"),
  220. lineTxt(
  221. "项目用途",
  222. "${Constant.projectUsageText[_list[index].projectUsage]}",
  223. ),
  224. lineTxt("台量", "${_list[index].actualNum}")
  225. ],
  226. ),
  227. ));
  228. });
  229. }
  230. Widget lineTxt(title, value) {
  231. return Container(
  232. padding: EdgeInsets.only(left: 12, top: 5, right: 12),
  233. child: Row(
  234. children: <Widget>[
  235. Text("${title}",
  236. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray)),
  237. Expanded(
  238. flex: 1,
  239. child: Text(
  240. "${value}",
  241. textAlign: TextAlign.right,
  242. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray),
  243. ),
  244. )
  245. ],
  246. ),
  247. );
  248. }
  249. @override
  250. bool get wantKeepAlive => true;
  251. }