patrol_job_add.dart 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import 'package:deus_app/common/event/RefreshPatrolEdit.dart';
  2. import 'package:deus_app/common/event/multiple_choice.dart';
  3. import 'package:deus_app/common/style/TitleBar.dart';
  4. import 'package:deus_app/common/style/gsy_style.dart';
  5. import 'package:deus_app/common/utils/CommonUtils.dart';
  6. import 'package:deus_app/common/utils/ConstantString.dart';
  7. import 'package:deus_app/common/utils/DioUtil.dart';
  8. import 'package:deus_app/common/utils/ToastUtils.dart';
  9. import 'package:deus_app/main.dart';
  10. import 'package:deus_app/model/patrol_job_select_entity_entity.dart';
  11. import 'package:flutter/material.dart';
  12. class PatrolJobAdd extends StatefulWidget {
  13. var id;
  14. final PatrolJobSelectEntityDataPatrolItemModelVOS responseData;
  15. PatrolJobAdd({super.key,required this.responseData,required this.id});
  16. @override
  17. State createState() {
  18. return new _PatrolJobAdd(responseData,id);
  19. }
  20. }
  21. class _PatrolJobAdd extends State<PatrolJobAdd> {
  22. PatrolJobSelectEntityDataPatrolItemModelVOS responseData;
  23. var id;
  24. _PatrolJobAdd(this.responseData,this.id);
  25. String groupValue = '';
  26. List<MultipleChoice>mList=[];
  27. @override
  28. void initState() {
  29. super.initState();
  30. if(responseData.type==2){
  31. groupValue=responseData.param[0];
  32. }else if(responseData.type==3){
  33. for (var element in responseData.param) {
  34. mList.add(MultipleChoice(element, false));
  35. }
  36. }
  37. }
  38. @override
  39. Widget build(BuildContext context) {
  40. return Scaffold(
  41. appBar: TitleBar().backAppbar("添加巡检项目"),
  42. // backgroundColor: const Color(0xfff2f2f2),
  43. body: Stack(
  44. children: [
  45. Column(
  46. children: [
  47. Container(
  48. padding: const EdgeInsets.fromLTRB(15.0, 15.0, 15.0, 15.0),
  49. child: Column(
  50. children: [
  51. Container(
  52. alignment: Alignment.centerLeft,
  53. child: Text(
  54. responseData.name,
  55. style: const TextStyle(
  56. fontSize: GSYConstant.TextSize15,
  57. color: Colors.black,
  58. ),
  59. ),
  60. ),
  61. Container(
  62. margin: const EdgeInsets.only(top: 10),
  63. // padding: const EdgeInsets.fromLTRB(30.0, 0.0, 0.0, 10.0),
  64. // alignment: Alignment.centerLeft,
  65. alignment: Alignment.centerLeft,
  66. child: Text(
  67. responseData.params,
  68. style: GSYConstant.textLight,
  69. textAlign: TextAlign.left,
  70. ),
  71. ),
  72. SizedBox(
  73. height: 10,
  74. ),
  75. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  76. Container(
  77. child: Text(
  78. '类型:',
  79. style: TextStyle(
  80. color: GSYColors.primaryLightValue,
  81. fontSize: GSYConstant.TextSize15,
  82. ),
  83. ),
  84. ),
  85. Container(
  86. child: Text(
  87. responseData.type == 0
  88. ? '数值'
  89. : responseData.type == 1
  90. ? '长文本'
  91. : responseData.type == 2
  92. ? '单选'
  93. : '多选',
  94. textAlign: TextAlign.right,
  95. style: TextStyle(
  96. color: GSYColors.primaryLightValue,
  97. fontSize: GSYConstant.TextSize15,
  98. ),
  99. ),
  100. ),
  101. ]),
  102. ],
  103. ),
  104. ),
  105. Divider(
  106. height: 0.8,
  107. color: Colors.grey,
  108. ),
  109. SizedBox(
  110. height: 10,
  111. ),
  112. Expanded(
  113. child:responseData.type==2||responseData.type==3? Container(
  114. child: ListView.builder(
  115. itemCount: responseData.param.length,
  116. itemBuilder: (context, index) {
  117. return Container(
  118. child: ListTile(
  119. title:responseData.type==2?Row(
  120. children: [
  121. Radio(
  122. value: responseData.param[index],
  123. groupValue: groupValue,
  124. onChanged: (value) {
  125. // groupValue = value;
  126. setState(() {
  127. groupValue = value!;
  128. });
  129. },
  130. // selected: groupValue == index,
  131. ),
  132. Text(responseData.param[index],style: TextStyle(
  133. color: GSYColors.primaryLightValue,
  134. fontSize: GSYConstant.TextSize15,
  135. ),)
  136. ],
  137. ):Row(
  138. children: [
  139. Checkbox(
  140. value: mList[index].isCheck,
  141. activeColor: Colors.blue,
  142. onChanged: (bool? value) {
  143. setState(() {
  144. mList[index].isCheck=value!;
  145. });
  146. },
  147. ),
  148. Text(responseData.param[index],style: TextStyle(
  149. color: GSYColors.primaryLightValue,
  150. fontSize: GSYConstant.TextSize15,
  151. )),
  152. ],
  153. )
  154. )
  155. );
  156. },
  157. ),
  158. ):Container(
  159. padding: EdgeInsets.only(left: 12,right: 12,bottom: 12),
  160. decoration: BoxDecoration(color: Colors.white),
  161. child: Column(
  162. children: [
  163. const SizedBox(
  164. height: 10,
  165. ),
  166. TextField(
  167. maxLines: 5,
  168. decoration: InputDecoration(border: OutlineInputBorder()),
  169. style: TextStyle(fontSize: 14),
  170. onChanged: (value) {
  171. groupValue = value;
  172. },
  173. )
  174. ],
  175. ),
  176. )
  177. ),
  178. ],
  179. ),
  180. Positioned(
  181. left: 0,
  182. right: 0,
  183. bottom:0,
  184. // flex: 7,
  185. child:SizedBox(
  186. height: 50,
  187. width: double.infinity,
  188. child: TextButton(
  189. onPressed: () {
  190. appAddItem();
  191. },
  192. style: ButtonStyle(
  193. backgroundColor: MaterialStateProperty.all<Color>(
  194. Color(0xFF4875EC)),
  195. shape: MaterialStateProperty.all(
  196. BeveledRectangleBorder(
  197. borderRadius: BorderRadius.circular(0))),
  198. foregroundColor:
  199. MaterialStateProperty.all<Color>(Colors.white),
  200. // padding: MaterialStateProperty.all(EdgeInsets.zero)
  201. ),
  202. child: const Text(ConstantString.complete),
  203. ),
  204. ),
  205. )
  206. ],
  207. ),
  208. );
  209. }
  210. appAddItem() async {
  211. // Navigator.pushAndRemoveUntil(context, MaterialPageRoute(
  212. // builder: (context) =>
  213. // PatrolJobEdit(id: responseData.id)), (route) => false);
  214. if(responseData.type==3){
  215. for (var element in mList) {
  216. if(element.isCheck){
  217. if(!CommonUtils.validationInput(groupValue)){
  218. groupValue=element.name;
  219. }else{
  220. groupValue='$groupValue,${element.name}';
  221. }
  222. }
  223. }
  224. }
  225. if(!CommonUtils.validationInput(groupValue)){
  226. showToast(ConstantString.patrolAddNull);
  227. return;
  228. }
  229. var result = await DioUtil().request("patrolItem/appAddItem",
  230. method: DioMethod.post,
  231. data: {'id': responseData.id,'patrolJobId':id,'result':groupValue});
  232. if (result['code'] == 0) {
  233. setState(() {
  234. eventBus.fire(RefreshPatrolEdit());
  235. Navigator.of(context)..pop()..pop();
  236. });
  237. } else {
  238. showToast(result['msg']);
  239. }
  240. }
  241. }