maint_job_list.dart 7.3 KB

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