repair_page.dart 13 KB

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