HeavyList.dart 9.1 KB

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