patrol_job_page.dart 11 KB

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