patrol_job_page.dart 11 KB

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