repair_page.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. //巡检任务列表
  2. import 'package:deus_app/common/event/RefreshRepairPage.dart';
  3. import 'package:deus_app/common/style/TitleBar.dart';
  4. import 'package:deus_app/generated/json/repair_bill_list_response_entity_helper.dart';
  5. import 'package:deus_app/main.dart';
  6. import 'package:deus_app/model/repair_bill_list_response_entity.dart';
  7. import 'package:deus_app/page/repair/repair_add_page.dart';
  8. import 'package:deus_app/page/repair/repair_detail.dart';
  9. import 'package:deus_app/widget/RepairJobDrawer.dart';
  10. import 'package:flutter/cupertino.dart';
  11. import 'package:flutter/material.dart';
  12. import 'package:pull_to_refresh/pull_to_refresh.dart';
  13. import '../../common/style/gsy_style.dart';
  14. import '../../common/utils/ConstantString.dart';
  15. import '../../common/utils/DioUtil.dart';
  16. import '../../common/utils/ToastUtils.dart';
  17. class RepairPage extends StatefulWidget {
  18. const RepairPage({super.key});
  19. static var routeName = '/RepairPage';
  20. @override
  21. State createState() {
  22. return _RepairPage();
  23. }
  24. }
  25. List<RepairBillListResponseDataList> patrol_job_list =
  26. <RepairBillListResponseDataList>[];
  27. class _RepairPage extends State<RepairPage> {
  28. final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
  29. final RefreshController _refreshController =
  30. RefreshController(initialRefresh: false);
  31. int index = 1;
  32. RepairBillListResponseEntity patrolJobResponse =
  33. RepairBillListResponseEntity();
  34. dynamic _status;
  35. String _theme = '';
  36. String _repNum = '';
  37. var _event;
  38. _load() async {
  39. var result = await DioUtil()
  40. .request('repair-bill/list', method: DioMethod.post, data: {
  41. 'query': {'theme': _theme, 'repNum': _repNum, 'status': _status},
  42. 'index': index,
  43. 'size': 20
  44. });
  45. _refreshController.loadComplete();
  46. _refreshController.refreshCompleted();
  47. patrolJobResponse = repairBillListResponseEntityFromJson(
  48. RepairBillListResponseEntity(), result);
  49. if (patrolJobResponse.code == 0) {
  50. setState(() {
  51. if (index == 1) {
  52. patrol_job_list.clear();
  53. }
  54. patrol_job_list.addAll(patrolJobResponse.data.xList);
  55. });
  56. } else {
  57. if (index > 1) {
  58. index--;
  59. }
  60. showToast(patrolJobResponse.msg!);
  61. }
  62. }
  63. @override
  64. void dispose() {
  65. super.dispose();
  66. _event.cancel();
  67. }
  68. @override
  69. void initState() {
  70. super.initState();
  71. _load();
  72. _event = eventBus.on<RefreshRepairPage>().listen((event) {
  73. setState(() {
  74. index=1;
  75. _load();
  76. });
  77. });
  78. }
  79. @override
  80. Widget build(BuildContext context) {
  81. return Scaffold(
  82. key: _scaffoldKey,
  83. appBar: TitleBar().drawAppBar(ConstantString.repairJobText, () {
  84. _scaffoldKey.currentState?.openEndDrawer();
  85. }),
  86. endDrawer: RepairJobDrawer(
  87. callback: (String theme, String repNum, dynamic status) {
  88. setState(() {
  89. _theme = theme;
  90. _repNum = repNum;
  91. _status = status;
  92. index=1;
  93. _load();
  94. });
  95. }),
  96. //抽屉
  97. backgroundColor: const Color(0xfff2f2f2),
  98. body: patrol_job_list.isNotEmpty?Stack(
  99. children: [
  100. Column(children: [
  101. Expanded(
  102. child: Container(
  103. margin: EdgeInsets.only(bottom: 50),
  104. child: SmartRefresher(
  105. enablePullDown: true,
  106. enablePullUp: true,
  107. header: WaterDropHeader(),
  108. footer: CustomFooter(
  109. builder: (BuildContext context, LoadStatus? mode) {
  110. Widget body;
  111. if (mode == LoadStatus.idle) {
  112. body = Text("上拉加载");
  113. } else if (mode == LoadStatus.loading) {
  114. body = CupertinoActivityIndicator();
  115. } else if (mode == LoadStatus.failed) {
  116. body = Text("加载失败!点击重试!");
  117. } else if (mode == LoadStatus.canLoading) {
  118. body = Text("松手,加载更多!");
  119. } else {
  120. body = Text("没有更多数据了!");
  121. }
  122. return Container(
  123. height: 55.0,
  124. child: Center(child: body),
  125. );
  126. },
  127. ),
  128. controller: _refreshController,
  129. onRefresh: _onRefresh,
  130. onLoading: _onLoading,
  131. child: ListView.builder(
  132. itemCount: patrol_job_list.length,
  133. itemBuilder: (context, index) {
  134. RepairBillListResponseDataList patrolJobData =
  135. patrol_job_list[index];
  136. return _patrol_job_list(patrolJobData);
  137. },
  138. ),
  139. ))),
  140. ]),
  141. Positioned(
  142. left: 0,
  143. right: 0,
  144. bottom: 0,
  145. // flex: 7,
  146. child: SizedBox(
  147. height: 50,
  148. width: double.infinity,
  149. child: TextButton(
  150. onPressed: () {
  151. Navigator.push(
  152. context,
  153. MaterialPageRoute(
  154. builder: (context) =>
  155. new RepairAddPage()));
  156. },
  157. style: ButtonStyle(
  158. backgroundColor:
  159. MaterialStateProperty.all<Color>(Color(0xFF4875EC)),
  160. shape: MaterialStateProperty.all(BeveledRectangleBorder(
  161. borderRadius: BorderRadius.circular(0))),
  162. foregroundColor:
  163. MaterialStateProperty.all<Color>(Colors.white),
  164. // padding: MaterialStateProperty.all(EdgeInsets.zero)
  165. ),
  166. child: const Text(ConstantString.newRepair),
  167. ),
  168. ),
  169. )
  170. ],
  171. ): Container(
  172. alignment: Alignment.center,
  173. child: const Text(
  174. '暂无数据',
  175. textAlign: TextAlign.center,
  176. style: TextStyle(
  177. color: GSYColors.primaryLightValue,
  178. fontSize: GSYConstant.middleTextWhiteSize,
  179. ),
  180. ),
  181. )
  182. );
  183. }
  184. Widget _patrol_job_list(RepairBillListResponseDataList patrolJobData) {
  185. return Container(
  186. margin: EdgeInsets.only(top: 12, left: 10, right: 10),
  187. padding: EdgeInsets.only(top: 12, bottom: 10),
  188. color: Colors.white,
  189. child: ListTile(
  190. title: Column(
  191. children: [
  192. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  193. Container(
  194. child: Text(
  195. patrolJobData.theme,
  196. style: TextStyle(
  197. color: Colors.black,
  198. fontSize: GSYConstant.middleTextWhiteSize,
  199. fontWeight: FontWeight.bold,
  200. ),
  201. ),
  202. ),
  203. Container(
  204. padding:
  205. EdgeInsets.only(top: 3, bottom: 3, left: 5, right: 5),
  206. child: Text(
  207. patrolJobData.status == 1
  208. ? '待接单'
  209. : patrolJobData.status == 2
  210. ? '待执行'
  211. : patrolJobData.status == 3
  212. ? '维修中'
  213. : patrolJobData.status == 4
  214. ? '已关闭'
  215. : patrolJobData.status == 5
  216. ? '已完成'
  217. : '未知',
  218. textAlign: TextAlign.right,
  219. style: TextStyle(
  220. color:
  221. patrolJobData.status == 1 || patrolJobData.status == 2
  222. ? Colors.red
  223. : patrolJobData.status == 3
  224. ? Colors.orange
  225. : patrolJobData.status == 4 ||
  226. patrolJobData.status == 5
  227. ? Colors.blue
  228. : Colors.black, //边框颜色
  229. fontSize: GSYConstant.minTextSize,
  230. ),
  231. ),
  232. decoration: BoxDecoration(
  233. border: new Border.all(
  234. color:
  235. patrolJobData.status == 1 || patrolJobData.status == 2
  236. ? Colors.red
  237. : patrolJobData.status == 3
  238. ? Colors.orange
  239. : patrolJobData.status == 4 ||
  240. patrolJobData.status == 5
  241. ? Colors.blue
  242. : Colors.black, //边框颜色
  243. width: 1.0, //边框粗细
  244. ),
  245. borderRadius: const BorderRadius.all(
  246. const Radius.circular(3.0)), //边框的弧度
  247. ),
  248. )
  249. ]),
  250. SizedBox(
  251. height: 12,
  252. ),
  253. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  254. Container(
  255. child: Text(
  256. '报修单号:',
  257. style: TextStyle(
  258. color: GSYColors.primaryLightValue,
  259. fontSize: GSYConstant.smallTextSize,
  260. ),
  261. ),
  262. ),
  263. Container(
  264. child: Text(
  265. patrolJobData.repNum,
  266. textAlign: TextAlign.right,
  267. style: TextStyle(
  268. color: GSYColors.primaryLightValue,
  269. fontSize: GSYConstant.smallTextSize,
  270. ),
  271. ),
  272. ),
  273. ]),
  274. SizedBox(
  275. height: 10,
  276. ),
  277. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  278. Container(
  279. child: Text(
  280. '报修设备:',
  281. style: TextStyle(
  282. color: GSYColors.primaryLightValue,
  283. fontSize: GSYConstant.smallTextSize,
  284. ),
  285. ),
  286. ),
  287. Container(
  288. child: Text(
  289. patrolJobData.deviceName,
  290. textAlign: TextAlign.right,
  291. style: TextStyle(
  292. color: GSYColors.primaryLightValue,
  293. fontSize: GSYConstant.smallTextSize,
  294. ),
  295. ),
  296. ),
  297. ]),
  298. SizedBox(
  299. height: 10,
  300. ),
  301. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  302. Container(
  303. child: Text(
  304. '申请时间:',
  305. style: TextStyle(
  306. color: GSYColors.primaryLightValue,
  307. fontSize: GSYConstant.smallTextSize,
  308. ),
  309. ),
  310. ),
  311. Container(
  312. child: Text(
  313. patrolJobData.applicationTime,
  314. textAlign: TextAlign.right,
  315. style: TextStyle(
  316. color: GSYColors.primaryLightValue,
  317. fontSize: GSYConstant.smallTextSize,
  318. ),
  319. ),
  320. ),
  321. ]),
  322. SizedBox(
  323. height: 10,
  324. ),
  325. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  326. Container(
  327. child: Text(
  328. '申请人:',
  329. style: TextStyle(
  330. color: GSYColors.primaryLightValue,
  331. fontSize: GSYConstant.smallTextSize,
  332. ),
  333. ),
  334. ),
  335. Container(
  336. child: Text(
  337. patrolJobData.applicant,
  338. textAlign: TextAlign.right,
  339. style: TextStyle(
  340. color: GSYColors.primaryLightValue,
  341. fontSize: GSYConstant.smallTextSize,
  342. ),
  343. ),
  344. ),
  345. ]),
  346. SizedBox(
  347. height: 5,
  348. ),
  349. ],
  350. ),
  351. onTap: () {
  352. Navigator.push(
  353. context,
  354. MaterialPageRoute(
  355. builder: (context) =>
  356. new RepairDetail(id: patrolJobData.id)));
  357. },
  358. ));
  359. }
  360. void _onRefresh() async {
  361. if (mounted) {
  362. setState(() {
  363. index = 1;
  364. _load();
  365. });
  366. }
  367. }
  368. void _onLoading() async {
  369. if (mounted) {
  370. setState(() {
  371. if (patrolJobResponse.data!.total! > patrol_job_list.length) {
  372. index++;
  373. _load();
  374. } else {
  375. _refreshController.loadNoData();
  376. }
  377. });
  378. }
  379. }
  380. }