maint_job_page.dart 11 KB

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