repair_page.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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: Stack(
  99. children: [
  100. Column(children: [
  101. SizedBox(
  102. height: 10,
  103. ),
  104. Row(
  105. mainAxisAlignment: MainAxisAlignment.start,
  106. children: [
  107. SizedBox(
  108. width: 15,
  109. ),
  110. Text(ConstantString.repairJobTitle,
  111. style: GSYConstant.smallActionLightText),
  112. ],
  113. ),
  114. Expanded(
  115. child: Container(
  116. margin: EdgeInsets.only(bottom: 50),
  117. child: SmartRefresher(
  118. enablePullDown: true,
  119. enablePullUp: true,
  120. header: WaterDropHeader(),
  121. footer: CustomFooter(
  122. builder: (BuildContext context, LoadStatus? mode) {
  123. Widget body;
  124. if (mode == LoadStatus.idle) {
  125. body = Text("上拉加载");
  126. } else if (mode == LoadStatus.loading) {
  127. body = CupertinoActivityIndicator();
  128. } else if (mode == LoadStatus.failed) {
  129. body = Text("加载失败!点击重试!");
  130. } else if (mode == LoadStatus.canLoading) {
  131. body = Text("松手,加载更多!");
  132. } else {
  133. body = Text("没有更多数据了!");
  134. }
  135. return Container(
  136. height: 55.0,
  137. child: Center(child: body),
  138. );
  139. },
  140. ),
  141. controller: _refreshController,
  142. onRefresh: _onRefresh,
  143. onLoading: _onLoading,
  144. child: ListView.builder(
  145. itemCount: patrol_job_list.length,
  146. itemBuilder: (context, index) {
  147. RepairBillListResponseDataList patrolJobData =
  148. patrol_job_list[index];
  149. return _patrol_job_list(patrolJobData);
  150. },
  151. ),
  152. ))),
  153. ]),
  154. Positioned(
  155. left: 0,
  156. right: 0,
  157. bottom: 0,
  158. // flex: 7,
  159. child: SizedBox(
  160. height: 50,
  161. width: double.infinity,
  162. child: TextButton(
  163. onPressed: () {
  164. Navigator.push(
  165. context,
  166. MaterialPageRoute(
  167. builder: (context) =>
  168. new RepairAddPage()));
  169. },
  170. style: ButtonStyle(
  171. backgroundColor:
  172. MaterialStateProperty.all<Color>(Color(0xFF4875EC)),
  173. shape: MaterialStateProperty.all(BeveledRectangleBorder(
  174. borderRadius: BorderRadius.circular(0))),
  175. foregroundColor:
  176. MaterialStateProperty.all<Color>(Colors.white),
  177. // padding: MaterialStateProperty.all(EdgeInsets.zero)
  178. ),
  179. child: const Text(ConstantString.newRepair),
  180. ),
  181. ),
  182. )
  183. ],
  184. ));
  185. }
  186. Widget _patrol_job_list(RepairBillListResponseDataList patrolJobData) {
  187. return Container(
  188. margin: EdgeInsets.only(top: 12, left: 10, right: 10),
  189. padding: EdgeInsets.only(top: 12, bottom: 10),
  190. color: Colors.white,
  191. child: ListTile(
  192. title: Column(
  193. children: [
  194. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  195. Container(
  196. child: Text(
  197. patrolJobData.theme,
  198. style: TextStyle(
  199. color: Colors.black,
  200. fontSize: GSYConstant.middleTextWhiteSize,
  201. fontWeight: FontWeight.bold,
  202. ),
  203. ),
  204. ),
  205. Container(
  206. padding:
  207. EdgeInsets.only(top: 3, bottom: 3, left: 5, right: 5),
  208. child: Text(
  209. patrolJobData.status == 1
  210. ? '待接单'
  211. : patrolJobData.status == 2
  212. ? '待执行'
  213. : patrolJobData.status == 3
  214. ? '维修中'
  215. : patrolJobData.status == 4
  216. ? '已关闭'
  217. : patrolJobData.status == 5
  218. ? '已完成'
  219. : '未知',
  220. textAlign: TextAlign.right,
  221. style: TextStyle(
  222. color:
  223. patrolJobData.status == 1 || patrolJobData.status == 2
  224. ? Colors.red
  225. : patrolJobData.status == 3
  226. ? Colors.orange
  227. : patrolJobData.status == 4 ||
  228. patrolJobData.status == 5
  229. ? Colors.blue
  230. : Colors.black, //边框颜色
  231. fontSize: GSYConstant.minTextSize,
  232. ),
  233. ),
  234. decoration: BoxDecoration(
  235. border: new Border.all(
  236. color:
  237. patrolJobData.status == 1 || patrolJobData.status == 2
  238. ? Colors.red
  239. : patrolJobData.status == 3
  240. ? Colors.orange
  241. : patrolJobData.status == 4 ||
  242. patrolJobData.status == 5
  243. ? Colors.blue
  244. : Colors.black, //边框颜色
  245. width: 1.0, //边框粗细
  246. ),
  247. borderRadius: const BorderRadius.all(
  248. const Radius.circular(3.0)), //边框的弧度
  249. ),
  250. )
  251. ]),
  252. SizedBox(
  253. height: 12,
  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.repNum,
  268. textAlign: TextAlign.right,
  269. style: TextStyle(
  270. color: GSYColors.primaryLightValue,
  271. fontSize: GSYConstant.smallTextSize,
  272. ),
  273. ),
  274. ),
  275. ]),
  276. SizedBox(
  277. height: 10,
  278. ),
  279. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  280. Container(
  281. child: Text(
  282. '报修设备:',
  283. style: TextStyle(
  284. color: GSYColors.primaryLightValue,
  285. fontSize: GSYConstant.smallTextSize,
  286. ),
  287. ),
  288. ),
  289. Container(
  290. child: Text(
  291. patrolJobData.deviceName,
  292. textAlign: TextAlign.right,
  293. style: TextStyle(
  294. color: GSYColors.primaryLightValue,
  295. fontSize: GSYConstant.smallTextSize,
  296. ),
  297. ),
  298. ),
  299. ]),
  300. SizedBox(
  301. height: 10,
  302. ),
  303. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  304. Container(
  305. child: Text(
  306. '申请时间:',
  307. style: TextStyle(
  308. color: GSYColors.primaryLightValue,
  309. fontSize: GSYConstant.smallTextSize,
  310. ),
  311. ),
  312. ),
  313. Container(
  314. child: Text(
  315. patrolJobData.applicationTime,
  316. textAlign: TextAlign.right,
  317. style: TextStyle(
  318. color: GSYColors.primaryLightValue,
  319. fontSize: GSYConstant.smallTextSize,
  320. ),
  321. ),
  322. ),
  323. ]),
  324. SizedBox(
  325. height: 10,
  326. ),
  327. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  328. Container(
  329. child: Text(
  330. '申请人:',
  331. style: TextStyle(
  332. color: GSYColors.primaryLightValue,
  333. fontSize: GSYConstant.smallTextSize,
  334. ),
  335. ),
  336. ),
  337. Container(
  338. child: Text(
  339. patrolJobData.applicant,
  340. textAlign: TextAlign.right,
  341. style: TextStyle(
  342. color: GSYColors.primaryLightValue,
  343. fontSize: GSYConstant.smallTextSize,
  344. ),
  345. ),
  346. ),
  347. ]),
  348. SizedBox(
  349. height: 5,
  350. ),
  351. ],
  352. ),
  353. onTap: () {
  354. Navigator.push(
  355. context,
  356. MaterialPageRoute(
  357. builder: (context) =>
  358. new RepairDetail(id: patrolJobData.id)));
  359. },
  360. ));
  361. }
  362. void _onRefresh() async {
  363. if (mounted) {
  364. setState(() {
  365. index = 1;
  366. _load();
  367. });
  368. }
  369. }
  370. void _onLoading() async {
  371. if (mounted) {
  372. setState(() {
  373. if (patrolJobResponse.data!.total! > patrol_job_list.length) {
  374. index++;
  375. _load();
  376. } else {
  377. _refreshController.loadNoData();
  378. }
  379. });
  380. }
  381. }
  382. }