patrol_job_page.dart 11 KB

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