maint_job_page.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. //巡检任务列表
  2. import 'package:deus_app/common/event/RefreshMaintPage.dart';
  3. import 'package:deus_app/common/style/TitleBar.dart';
  4. import 'package:deus_app/common/utils/ToastUtils.dart';
  5. import 'package:deus_app/main.dart';
  6. import 'package:deus_app/model/maint_pesonse_entity.dart';
  7. import 'package:deus_app/page/maint/maint_job_detail.dart';
  8. import 'package:flutter/cupertino.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:pull_to_refresh/pull_to_refresh.dart';
  11. import '../../common/style/gsy_style.dart';
  12. import '../../common/utils/ConstantString.dart';
  13. import '../../common/utils/DioUtil.dart';
  14. import '../../widget/MaintJobDrawer.dart';
  15. class MaintJobPage extends StatefulWidget {
  16. const MaintJobPage({super.key});
  17. static var routeName = '/MaintJobPage';
  18. @override
  19. State createState() {
  20. return _MaintJobPage();
  21. }
  22. }
  23. List<MaintJobVO> maint_job_list = <MaintJobVO>[];
  24. int index = 1;
  25. class _MaintJobPage extends State<MaintJobPage> {
  26. final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
  27. final RefreshController _refreshController =
  28. RefreshController(initialRefresh: false);
  29. MaintJobList maintJobList = MaintJobList();
  30. String _device = '', _num = '';
  31. dynamic _stase;
  32. var _event;
  33. _load() async {
  34. var result = await DioUtil().request('maintJob/list',
  35. method: DioMethod.post,
  36. data: {'query': {'jobName':_device,'jobNum':_num,'status':_stase}, 'index': index, 'size': 20});
  37. _refreshController.loadComplete();
  38. _refreshController.refreshCompleted();
  39. MaintJobResponse maintJobResponse = MaintJobResponse.fromJson(result);
  40. if(maintJobResponse.code==0){
  41. maintJobList = maintJobResponse.data!;
  42. setState(() {
  43. if(index==1){
  44. maint_job_list.clear();
  45. }
  46. maint_job_list.addAll(maintJobList.list!);
  47. });
  48. }else{
  49. if(index>1){
  50. index--;
  51. }
  52. showToast(maintJobResponse.msg!);
  53. }
  54. }
  55. void _onRefresh() async {
  56. if (mounted) {
  57. setState(() {
  58. index = 1;
  59. _load();
  60. });
  61. }
  62. }
  63. void _onLoading() async {
  64. if (mounted) {
  65. setState(() {
  66. if (maintJobList.total! > maint_job_list.length) {
  67. index++;
  68. _load();
  69. } else {
  70. _refreshController.loadNoData();
  71. }
  72. });
  73. }
  74. }
  75. @override
  76. void initState() {
  77. super.initState();
  78. _load();
  79. _event = eventBus.on<RefreshMaintPage>().listen((event) {
  80. setState(() {
  81. index=1;
  82. _load();
  83. });
  84. });
  85. }
  86. @override
  87. Widget build(BuildContext context) {
  88. return Scaffold(
  89. key: _scaffoldKey,
  90. appBar: TitleBar().drawAppBar(ConstantString.maintJobText, () {
  91. _scaffoldKey.currentState?.openEndDrawer();
  92. }),
  93. endDrawer: MaintJobDrawer(
  94. callback: (String device, String num, dynamic stase) {
  95. _device = device;
  96. _num = num;
  97. _stase = stase;
  98. index = 1;
  99. _load();
  100. },
  101. ),
  102. //抽屉
  103. backgroundColor: const Color(0xfff2f2f2),
  104. body: Column(
  105. children: [
  106. const SizedBox(
  107. height: 10,
  108. ),
  109. Row(
  110. mainAxisAlignment: MainAxisAlignment.start,
  111. children: const [
  112. SizedBox(
  113. width: 15,
  114. ),
  115. Text(ConstantString.maintJobTitle,
  116. style: GSYConstant.smallActionLightText),
  117. ],
  118. ),
  119. Expanded(
  120. child: Container(
  121. child: SmartRefresher(
  122. enablePullDown: true,
  123. enablePullUp: true,
  124. header: WaterDropHeader(),
  125. footer: CustomFooter(
  126. builder: (BuildContext context, LoadStatus? mode) {
  127. Widget body;
  128. if (mode == LoadStatus.idle) {
  129. body = Text("上拉加载");
  130. } else if (mode == LoadStatus.loading) {
  131. body = CupertinoActivityIndicator();
  132. } else if (mode == LoadStatus.failed) {
  133. body = Text("加载失败!点击重试!");
  134. } else if (mode == LoadStatus.canLoading) {
  135. body = Text("松手,加载更多!");
  136. } else {
  137. body = Text("没有更多数据了!");
  138. }
  139. return Container(
  140. height: 55.0,
  141. child: Center(child: body),
  142. );
  143. },
  144. ),
  145. controller: _refreshController,
  146. onRefresh: _onRefresh,
  147. onLoading: _onLoading,
  148. // child:Expanded(
  149. // child: Container(
  150. child: ListView.builder(
  151. itemCount: maint_job_list.length,
  152. itemBuilder: (context, index) {
  153. MaintJobVO maintJobVO = maint_job_list[index];
  154. return _maint_job_list(maintJobVO);
  155. },
  156. ),
  157. )))
  158. ],
  159. ));
  160. }
  161. Widget _maint_job_list(MaintJobVO maintJobVO) {
  162. return Container(
  163. margin: EdgeInsets.only(top: 12, left: 10, right: 10),
  164. padding: EdgeInsets.only(top: 12, bottom: 10),
  165. color: Colors.white,
  166. child: ListTile(
  167. title: Column(
  168. children: [
  169. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  170. Container(
  171. child: Text(
  172. maintJobVO.jobName!,
  173. style: TextStyle(
  174. color: Colors.black,
  175. fontSize: GSYConstant.middleTextWhiteSize,
  176. fontWeight: FontWeight.bold,
  177. ),
  178. ),
  179. ),
  180. Container(
  181. padding:
  182. EdgeInsets.only(top: 3, bottom: 3, left: 5, right: 5),
  183. child: Text(
  184. maintJobVO.status == 0
  185. ? '已关闭'
  186. : maintJobVO.status == 1
  187. ? '执行中'
  188. : maintJobVO.status == 2
  189. ? '已完成'
  190. : maintJobVO.status == 3
  191. ? '待执行'
  192. : maintJobVO.status == 4
  193. ? '已逾期'
  194. : '未知',
  195. textAlign: TextAlign.right,
  196. style: TextStyle(
  197. color: maintJobVO.status == 0 || maintJobVO.status == 4
  198. ? Colors.red
  199. :maintJobVO.status == 1|| maintJobVO.status == 3
  200. ? Colors.orange
  201. : maintJobVO.status == 2
  202. ? Colors.blue
  203. : Colors.black, //边框颜色
  204. fontSize: GSYConstant.minTextSize,
  205. ),
  206. ),
  207. decoration: BoxDecoration(
  208. border: new Border.all(
  209. color: maintJobVO.status == 0 || maintJobVO.status == 4
  210. ? Colors.red
  211. :maintJobVO.status == 1|| maintJobVO.status == 3
  212. ? Colors.orange
  213. : maintJobVO.status == 2
  214. ? Colors.blue
  215. : Colors.black, //边框颜色
  216. width: 1.0, //边框粗细
  217. ),
  218. borderRadius: const BorderRadius.all(
  219. const Radius.circular(3.0)), //边框的弧度
  220. ),
  221. )
  222. ]),
  223. SizedBox(
  224. height: 12,
  225. ),
  226. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  227. Container(
  228. child: Text(
  229. '任务编号:',
  230. style: TextStyle(
  231. color: GSYColors.primaryLightValue,
  232. fontSize: GSYConstant.smallTextSize,
  233. ),
  234. ),
  235. ),
  236. Container(
  237. child: Text(
  238. maintJobVO.jobNum!,
  239. textAlign: TextAlign.right,
  240. style: TextStyle(
  241. color: GSYColors.primaryLightValue,
  242. fontSize: GSYConstant.smallTextSize,
  243. ),
  244. ),
  245. ),
  246. ]),
  247. SizedBox(
  248. height: 10,
  249. ),
  250. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  251. Container(
  252. child: Text(
  253. '任务开始时间:',
  254. style: TextStyle(
  255. color: GSYColors.primaryLightValue,
  256. fontSize: GSYConstant.smallTextSize,
  257. ),
  258. ),
  259. ),
  260. Container(
  261. child: Text(
  262. maintJobVO.startTime!,
  263. textAlign: TextAlign.right,
  264. style: TextStyle(
  265. color: GSYColors.primaryLightValue,
  266. fontSize: GSYConstant.smallTextSize,
  267. ),
  268. ),
  269. ),
  270. ]),
  271. SizedBox(
  272. height: 10,
  273. ),
  274. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  275. Container(
  276. child: Text(
  277. '任务结束时间:',
  278. style: TextStyle(
  279. color: GSYColors.primaryLightValue,
  280. fontSize: GSYConstant.smallTextSize,
  281. ),
  282. ),
  283. ),
  284. Container(
  285. child: Text(
  286. maintJobVO.endTime!,
  287. textAlign: TextAlign.right,
  288. style: TextStyle(
  289. color: GSYColors.primaryLightValue,
  290. fontSize: GSYConstant.smallTextSize,
  291. ),
  292. ),
  293. ),
  294. ]),
  295. SizedBox(
  296. height: 5,
  297. ),
  298. ],
  299. ),
  300. onTap: () {
  301. Navigator.push(
  302. context,
  303. MaterialPageRoute(
  304. builder: (context) =>
  305. new MaintJobDetail(id: maintJobVO.id)));
  306. },
  307. ));
  308. }
  309. @override
  310. void dispose() {
  311. super.dispose();
  312. _event.cancel();
  313. }
  314. }