maint_job_page.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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: maint_job_list.isNotEmpty?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. ):Container(
  160. alignment: Alignment.center,
  161. child: const Text(
  162. '暂无数据',
  163. textAlign: TextAlign.center,
  164. style: TextStyle(
  165. color: GSYColors.primaryLightValue,
  166. fontSize: GSYConstant.middleTextWhiteSize,
  167. ),
  168. ),
  169. )
  170. );
  171. }
  172. Widget _maint_job_list(MaintJobVO maintJobVO) {
  173. return Container(
  174. margin: EdgeInsets.only(top: 12, left: 10, right: 10),
  175. padding: EdgeInsets.only(top: 12, bottom: 10),
  176. color: Colors.white,
  177. child: ListTile(
  178. title: Column(
  179. children: [
  180. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  181. Container(
  182. child: Text(
  183. maintJobVO.jobName!,
  184. style: TextStyle(
  185. color: Colors.black,
  186. fontSize: GSYConstant.middleTextWhiteSize,
  187. fontWeight: FontWeight.bold,
  188. ),
  189. ),
  190. ),
  191. Container(
  192. padding:
  193. EdgeInsets.only(top: 3, bottom: 3, left: 5, right: 5),
  194. child: Text(
  195. maintJobVO.status == 0
  196. ? '已关闭'
  197. : maintJobVO.status == 1
  198. ? '执行中'
  199. : maintJobVO.status == 2
  200. ? '已完成'
  201. : maintJobVO.status == 3
  202. ? '待执行'
  203. : maintJobVO.status == 4
  204. ? '已逾期'
  205. : '未知',
  206. textAlign: TextAlign.right,
  207. style: TextStyle(
  208. color: maintJobVO.status == 0 || maintJobVO.status == 4
  209. ? Colors.red
  210. :maintJobVO.status == 1|| maintJobVO.status == 3
  211. ? Colors.orange
  212. : maintJobVO.status == 2
  213. ? Colors.blue
  214. : Colors.black, //边框颜色
  215. fontSize: GSYConstant.minTextSize,
  216. ),
  217. ),
  218. decoration: BoxDecoration(
  219. border: new Border.all(
  220. color: maintJobVO.status == 0 || maintJobVO.status == 4
  221. ? Colors.red
  222. :maintJobVO.status == 1|| maintJobVO.status == 3
  223. ? Colors.orange
  224. : maintJobVO.status == 2
  225. ? Colors.blue
  226. : Colors.black, //边框颜色
  227. width: 1.0, //边框粗细
  228. ),
  229. borderRadius: const BorderRadius.all(
  230. const Radius.circular(3.0)), //边框的弧度
  231. ),
  232. )
  233. ]),
  234. SizedBox(
  235. height: 12,
  236. ),
  237. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  238. Container(
  239. child: Text(
  240. '任务编号:',
  241. style: TextStyle(
  242. color: GSYColors.primaryLightValue,
  243. fontSize: GSYConstant.smallTextSize,
  244. ),
  245. ),
  246. ),
  247. Container(
  248. child: Text(
  249. maintJobVO.jobNum!,
  250. textAlign: TextAlign.right,
  251. style: TextStyle(
  252. color: GSYColors.primaryLightValue,
  253. fontSize: GSYConstant.smallTextSize,
  254. ),
  255. ),
  256. ),
  257. ]),
  258. SizedBox(
  259. height: 10,
  260. ),
  261. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  262. Container(
  263. child: Text(
  264. '任务开始时间:',
  265. style: TextStyle(
  266. color: GSYColors.primaryLightValue,
  267. fontSize: GSYConstant.smallTextSize,
  268. ),
  269. ),
  270. ),
  271. Container(
  272. child: Text(
  273. maintJobVO.startTime!,
  274. textAlign: TextAlign.right,
  275. style: TextStyle(
  276. color: GSYColors.primaryLightValue,
  277. fontSize: GSYConstant.smallTextSize,
  278. ),
  279. ),
  280. ),
  281. ]),
  282. SizedBox(
  283. height: 10,
  284. ),
  285. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  286. Container(
  287. child: Text(
  288. '任务结束时间:',
  289. style: TextStyle(
  290. color: GSYColors.primaryLightValue,
  291. fontSize: GSYConstant.smallTextSize,
  292. ),
  293. ),
  294. ),
  295. Container(
  296. child: Text(
  297. maintJobVO.endTime!,
  298. textAlign: TextAlign.right,
  299. style: TextStyle(
  300. color: GSYColors.primaryLightValue,
  301. fontSize: GSYConstant.smallTextSize,
  302. ),
  303. ),
  304. ),
  305. ]),
  306. SizedBox(
  307. height: 5,
  308. ),
  309. ],
  310. ),
  311. onTap: () {
  312. Navigator.push(
  313. context,
  314. MaterialPageRoute(
  315. builder: (context) =>
  316. new MaintJobDetail(id: maintJobVO.id)));
  317. },
  318. ));
  319. }
  320. @override
  321. void dispose() {
  322. super.dispose();
  323. _event.cancel();
  324. }
  325. }