maint_job_page.dart 10 KB

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