patrol_job_list.dart 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import 'package:deus_app/common/event/RefreshPatrolEdit.dart';
  2. import 'package:deus_app/common/style/TitleBar.dart';
  3. import 'package:deus_app/common/style/gsy_style.dart';
  4. import 'package:deus_app/common/utils/ConstantString.dart';
  5. import 'package:deus_app/common/utils/DioUtil.dart';
  6. import 'package:deus_app/common/utils/ToastUtils.dart';
  7. import 'package:deus_app/main.dart';
  8. import 'package:deus_app/model/patrol_job_detail_response_entity.dart';
  9. import 'package:deus_app/page/patrol/patrol_job_edit.dart';
  10. import 'package:flutter/material.dart';
  11. class PatrolJobList extends StatefulWidget {
  12. final PatrolJobDetailResponseData responseData;
  13. const PatrolJobList({super.key, required this.responseData});
  14. @override
  15. State createState() {
  16. return _PatrolJobList(responseData);
  17. }
  18. }
  19. class _PatrolJobList extends State<PatrolJobList> {
  20. PatrolJobDetailResponseData responseData;
  21. _PatrolJobList(this.responseData);
  22. @override
  23. Widget build(BuildContext context) {
  24. return WillPopScope(
  25. child: Scaffold(
  26. appBar: TitleBar().backAppbar("巡检设备详情"),
  27. backgroundColor: const Color(0xfff2f2f2),
  28. body: Stack(
  29. children: [
  30. Column(
  31. children: [
  32. SizedBox(
  33. height: 10,
  34. ),
  35. Row(
  36. mainAxisAlignment: MainAxisAlignment.start,
  37. children: [
  38. SizedBox(
  39. width: 15,
  40. ),
  41. Text(ConstantString.patrolJobTitle,
  42. style: GSYConstant.smallActionLightText),
  43. ],
  44. ),
  45. Expanded(
  46. child: Container(
  47. margin: EdgeInsets.only(bottom: 50),
  48. child: ListView.builder(
  49. itemCount: responseData.equipmentVOS.length,
  50. itemBuilder: (context, index) {
  51. return Container(
  52. margin: EdgeInsets.only(
  53. top: 12, left: 10, right: 10),
  54. padding: EdgeInsets.only(top: 12, bottom: 10),
  55. color: Colors.white,
  56. child: ListTile(
  57. title: Column(
  58. children: [
  59. Container(
  60. // padding: const EdgeInsets.fromLTRB(30.0, 0.0, 0.0, 0.0),
  61. alignment: Alignment.centerLeft,
  62. child: Row(
  63. mainAxisAlignment:
  64. MainAxisAlignment
  65. .spaceBetween,
  66. children: [
  67. Text(
  68. responseData
  69. .equipmentVOS[index]
  70. .showName,
  71. style: GSYConstant
  72. .smallTextBold),
  73. Text(
  74. responseData
  75. .equipmentVOS[
  76. index]
  77. .isComplete ==
  78. 0
  79. ? '未完成'
  80. : '已完成',
  81. style: TextStyle(
  82. fontSize: GSYConstant
  83. .smallTextSize,
  84. color: responseData
  85. .equipmentVOS[
  86. index]
  87. .isComplete ==
  88. 0
  89. ? Colors.red
  90. : Colors.blue),
  91. ),
  92. ]),
  93. ),
  94. Container(
  95. margin:
  96. const EdgeInsets.only(top: 10),
  97. // padding: const EdgeInsets.fromLTRB(30.0, 0.0, 0.0, 10.0),
  98. // alignment: Alignment.centerLeft,
  99. child: Row(
  100. mainAxisAlignment:
  101. MainAxisAlignment
  102. .spaceBetween,
  103. children: [
  104. new Text(
  105. '完成时间:',
  106. style: GSYConstant
  107. .smallTextLight,
  108. ),
  109. Container(
  110. child: Text(
  111. responseData
  112. .equipmentVOS[index]
  113. .itemCompleteTime,
  114. style: GSYConstant
  115. .smallTextLight,
  116. textAlign: TextAlign.right,
  117. ),
  118. ),
  119. ]),
  120. ),
  121. SizedBox(
  122. height: 5,
  123. ),
  124. ],
  125. ),
  126. onTap: () {
  127. completeEquipment(index);
  128. },
  129. ));
  130. },
  131. )),
  132. )
  133. ],
  134. ),
  135. Positioned(
  136. left: 0,
  137. right: 0,
  138. bottom: 0,
  139. // flex: 7,
  140. child: SizedBox(
  141. height: 50,
  142. width: double.infinity,
  143. child: TextButton(
  144. onPressed: () {
  145. if (next()) {
  146. Navigator.push(
  147. context,
  148. MaterialPageRoute(
  149. builder: (context) =>
  150. PatrolJobEdit(id: responseData.id)));
  151. }
  152. },
  153. style: ButtonStyle(
  154. backgroundColor:
  155. MaterialStateProperty.all<Color>(Color(0xFF4875EC)),
  156. shape: MaterialStateProperty.all(BeveledRectangleBorder(
  157. borderRadius: BorderRadius.circular(0))),
  158. foregroundColor:
  159. MaterialStateProperty.all<Color>(Colors.white),
  160. // padding: MaterialStateProperty.all(EdgeInsets.zero)
  161. ),
  162. child: const Text(ConstantString.next),
  163. ),
  164. ),
  165. )
  166. ],
  167. )),
  168. onWillPop: () async {
  169. eventBus.fire(RefreshPatrolEdit());
  170. return true;
  171. });
  172. }
  173. completeEquipment(int index) async {
  174. if (responseData.equipmentVOS[index].isComplete == 0) {
  175. var result = await DioUtil().request("patrolJob/completeEquipment",
  176. method: DioMethod.post,
  177. data: {'id': responseData.equipmentVOS[index].id});
  178. if (result['code'] == 0) {
  179. setState(() {
  180. responseData.equipmentVOS[index].isComplete = 1;
  181. responseData.equipmentVOS[index].itemCompleteTime = result['data'];
  182. });
  183. } else {
  184. showToast(result['msg']);
  185. }
  186. }
  187. }
  188. bool next() {
  189. bool isNext = true;
  190. for (var element in responseData.equipmentVOS) {
  191. if (element.isComplete == 0) {
  192. isNext = false;
  193. break;
  194. }
  195. }
  196. return isNext;
  197. }
  198. }