patrol_job_page.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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: patrol_job_list.isNotEmpty?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. ):Container(
  138. alignment: Alignment.center,
  139. child: const Text(
  140. '暂无数据',
  141. textAlign: TextAlign.center,
  142. style: TextStyle(
  143. color: GSYColors.primaryLightValue,
  144. fontSize: GSYConstant.middleTextWhiteSize,
  145. ),
  146. ),
  147. )
  148. );
  149. }
  150. Widget _patrol_job_list(PatrolJobData patrolJobData) {
  151. return Container(
  152. margin: EdgeInsets.only(top: 12, left: 10, right: 10),
  153. padding: EdgeInsets.only(top: 12, bottom: 10),
  154. color: Colors.white,
  155. child: ListTile(
  156. title: Column(
  157. children: [
  158. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  159. Container(
  160. child: Text(
  161. patrolJobData.name!,
  162. style: TextStyle(
  163. color: Colors.black,
  164. fontSize: GSYConstant.middleTextWhiteSize,
  165. fontWeight: FontWeight.bold,
  166. ),
  167. ),
  168. ),
  169. Container(
  170. padding:
  171. EdgeInsets.only(top: 3, bottom: 3, left: 5, right: 5),
  172. child: Text(
  173. patrolJobData.status == 0
  174. ? '已关闭'
  175. : patrolJobData.status == 1
  176. ? '执行中'
  177. : patrolJobData.status == 2
  178. ? '已完成'
  179. : patrolJobData.status == 3
  180. ? '待执行'
  181. : patrolJobData.status == 4
  182. ? '已逾期'
  183. : '未知',
  184. textAlign: TextAlign.right,
  185. style: TextStyle(
  186. color:
  187. patrolJobData.status == 0 || patrolJobData.status == 4
  188. ? Colors.red
  189. : patrolJobData.status == 1||patrolJobData.status == 3
  190. ? Colors.orange
  191. : patrolJobData.status == 2
  192. ? Colors.blue
  193. : Colors.black, //边框颜色
  194. fontSize: GSYConstant.minTextSize,
  195. ),
  196. ),
  197. decoration: BoxDecoration(
  198. border: new Border.all(
  199. color:
  200. patrolJobData.status == 0 || patrolJobData.status == 4
  201. ? Colors.red
  202. : patrolJobData.status == 1 ||patrolJobData.status == 3
  203. ? Colors.orange
  204. : patrolJobData.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. patrolJobData.number!,
  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. patrolJobData.startDate!,
  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. patrolJobData.endDate!,
  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 PatrolJobDetail(id: patrolJobData.id)));
  297. },
  298. ));
  299. }
  300. void _onRefresh() async {
  301. // monitor network fetch
  302. // await Future.delayed(Duration(milliseconds: 1000));
  303. // if failed,use refreshFailed()
  304. if (mounted) {
  305. setState(() {
  306. index = 1;
  307. _load();
  308. });
  309. }
  310. }
  311. void _onLoading() async {
  312. // monitor network fetch
  313. // await Future.delayed(Duration(milliseconds: 1000));
  314. // if failed,use loadFailed(),if no data return,use LoadNodata()
  315. // items.add((items.length+1).toString());
  316. if (mounted) {
  317. setState(() {
  318. if (patrolJobResponse.data!.total! > patrol_job_list.length) {
  319. index++;
  320. _load();
  321. } else {
  322. _refreshController.loadNoData();
  323. }
  324. });
  325. }
  326. }
  327. @override
  328. void dispose() {
  329. super.dispose();
  330. _event.cancel();
  331. }
  332. }