patrol_job_edit.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. import 'dart:io';
  2. import 'package:deus_app/PhotoTool.dart';
  3. import 'package:deus_app/common/dialog/CloseTaskDialog.dart';
  4. import 'package:deus_app/common/event/RefreshPatrol.dart';
  5. import 'package:deus_app/common/event/RefreshPatrolEdit.dart';
  6. import 'package:deus_app/common/style/TitleBar.dart';
  7. import 'package:deus_app/common/style/gsy_style.dart';
  8. import 'package:deus_app/common/utils/ConstantString.dart';
  9. import 'package:deus_app/common/utils/DioUtil.dart';
  10. import 'package:deus_app/common/utils/ToastUtils.dart';
  11. import 'package:deus_app/generated/json/patrol_job_edit_emtity_entity_helper.dart';
  12. import 'package:deus_app/generated/json/upload_list_entity_entity_helper.dart';
  13. import 'package:deus_app/main.dart';
  14. import 'package:deus_app/model/patrol_job_edit_emtity_entity.dart';
  15. import 'package:deus_app/model/upload_list_entity_entity.dart';
  16. import 'package:deus_app/page/patrol/patrol_job_select.dart';
  17. import 'package:dio/dio.dart';
  18. import 'package:flutter/cupertino.dart';
  19. import 'package:flutter/material.dart';
  20. import 'package:wechat_assets_picker/wechat_assets_picker.dart';
  21. class PatrolJobEdit extends StatefulWidget {
  22. static var routeName = "/PatrolJobEdit";
  23. var id;
  24. @override
  25. State createState() {
  26. return _PatrolJobEdit(id);
  27. }
  28. PatrolJobEdit({super.key, @required this.id});
  29. }
  30. class _PatrolJobEdit extends State<PatrolJobEdit> with WidgetsBindingObserver {
  31. List<PatrolJobEditEmtityData> patrolItemVOS = <PatrolJobEditEmtityData>[];
  32. List<AssetEntity> imageFiles = [];
  33. List<int> mList = [];
  34. var id;
  35. var _event;
  36. String note = '';
  37. FocusNode focusNode = FocusNode();
  38. _PatrolJobEdit(this.id);
  39. @override
  40. Widget build(BuildContext context) {
  41. return Scaffold(
  42. resizeToAvoidBottomInset: false,
  43. appBar: TitleBar().backAppbar("巡检设备详情"),
  44. backgroundColor: const Color(0xfff2f2f2),
  45. body: Column(
  46. children: [
  47. Expanded(
  48. // flex: 7,
  49. child: ListView(
  50. children: _Ws(),
  51. ),
  52. ),
  53. Container(
  54. height: 50,
  55. // flex: 7,
  56. child: Row(
  57. children: [
  58. Expanded(
  59. child: SizedBox(
  60. height: 50,
  61. child: TextButton(
  62. onPressed: () {
  63. Navigator.pop(context);
  64. },
  65. child: Text(ConstantString.back),
  66. style: ButtonStyle(
  67. backgroundColor: MaterialStateProperty.all<Color>(
  68. Color(0xFF4875EC)),
  69. shape: MaterialStateProperty.all(
  70. BeveledRectangleBorder(
  71. borderRadius: BorderRadius.circular(0))),
  72. foregroundColor:
  73. MaterialStateProperty.all<Color>(Colors.white),
  74. // padding: MaterialStateProperty.all(EdgeInsets.zero)
  75. ),
  76. ),
  77. ),
  78. ),
  79. Expanded(
  80. child: SizedBox(
  81. height: 50,
  82. child: TextButton(
  83. onPressed: () {
  84. CloseTaskDialog.showAlertDialog(context, () {
  85. if (imageFiles.isNotEmpty) {
  86. uploadList();
  87. } else {
  88. patrolJobRemark();
  89. }
  90. }, '您确认完成当前巡检?');
  91. },
  92. child: Text(ConstantString.complete),
  93. style: ButtonStyle(
  94. backgroundColor:
  95. MaterialStateProperty.all<Color>(Colors.blue),
  96. foregroundColor:
  97. MaterialStateProperty.all<Color>(Colors.white),
  98. shape: MaterialStateProperty.all(BeveledRectangleBorder(
  99. borderRadius: BorderRadius.circular(0))),
  100. // padding: MaterialStateProperty.all(EdgeInsets.zero)
  101. ),
  102. ),
  103. )),
  104. ],
  105. ),
  106. )
  107. ],
  108. ));
  109. }
  110. List<Widget> _Ws() {
  111. List<Widget> ws = [];
  112. ws.add(_mainPatrolAdd());
  113. ws.addAll(_item());
  114. ws.add(_notes());
  115. ws.add(_picture());
  116. // ws.add(_url());
  117. return ws;
  118. }
  119. Widget _picture() {
  120. return Container(
  121. child: Column(
  122. children: [
  123. Container(
  124. height: 50,
  125. padding: EdgeInsets.only(left: 12),
  126. alignment: Alignment.centerLeft,
  127. child: Text('巡检图片',
  128. style: TextStyle(
  129. color: Colors.black,
  130. fontSize: GSYConstant.TextSize15,
  131. )),
  132. ),
  133. Container(
  134. // padding: EdgeInsets.only(left: 12,right: 12),
  135. decoration: BoxDecoration(color: Colors.white),
  136. child: PhotoTool(
  137. imageCount: 5,
  138. lineCount: 5,
  139. addCall: (List<AssetEntity> _imageFiles) {
  140. imageFiles.clear();
  141. imageFiles.addAll(_imageFiles);
  142. },
  143. removeCall: (int index) {
  144. imageFiles.removeAt(index);
  145. },focusNode:focusNode,),
  146. )
  147. ],
  148. ));
  149. }
  150. Widget _notes() {
  151. return Container(
  152. child: Column(
  153. children: <Widget>[
  154. Container(
  155. height: 50,
  156. padding: EdgeInsets.only(left: 12),
  157. alignment: Alignment.centerLeft,
  158. child: Text('任务结果备注',
  159. style: TextStyle(
  160. color: Colors.black,
  161. fontSize: GSYConstant.TextSize15,
  162. )),
  163. ),
  164. Container(
  165. padding: EdgeInsets.only(left: 12, right: 12, bottom: 12),
  166. decoration: BoxDecoration(color: Colors.white),
  167. child: Column(
  168. children: [
  169. const SizedBox(
  170. height: 10,
  171. ),
  172. TextField(
  173. maxLines: 5,
  174. focusNode: focusNode,
  175. decoration: InputDecoration(border: OutlineInputBorder()),
  176. style: TextStyle(fontSize: 14),
  177. onChanged: (value) {
  178. note = value;
  179. },
  180. )
  181. ],
  182. ),
  183. )
  184. ],
  185. ),
  186. );
  187. }
  188. Widget _mainPatrolAdd() {
  189. return Column(
  190. children: [
  191. Container(
  192. padding: EdgeInsets.fromLTRB(12, 0, 12, 0),
  193. height: 50,
  194. child: Row(
  195. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  196. children: [
  197. const Text(
  198. '巡检项目:',
  199. style: TextStyle(
  200. color: Colors.black,
  201. fontSize: GSYConstant.TextSize15,
  202. ),
  203. ),
  204. Container(
  205. child: TextButton(
  206. onPressed: () {
  207. focusNode.unfocus();
  208. Navigator.push(
  209. context,
  210. MaterialPageRoute(
  211. builder: (context) => PatrolJobSelect(
  212. id: id,
  213. )));
  214. },
  215. child: Row(
  216. children: [
  217. new Icon(Icons.add),
  218. new Text(
  219. '添加项目',
  220. style: TextStyle(
  221. color: Colors.blue,
  222. fontSize: GSYConstant.TextSize15,
  223. ),
  224. textAlign: TextAlign.right,
  225. )
  226. ],
  227. ),
  228. ),
  229. ),
  230. ],
  231. ),
  232. )
  233. ],
  234. );
  235. }
  236. List<Widget> _item() {
  237. return patrolItemVOS.map((e) => _buildItem(e)).toList();
  238. }
  239. Widget _buildItem(PatrolJobEditEmtityData item) {
  240. return FractionallySizedBox(
  241. widthFactor: 1,
  242. child: Container(
  243. padding: const EdgeInsets.fromLTRB(12, 0, 15, 5),
  244. decoration: BoxDecoration(color: Colors.white),
  245. child: Column(
  246. children: [
  247. Container(
  248. child: Row(
  249. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  250. children: [
  251. Text(item.name,
  252. style: TextStyle(
  253. fontSize: GSYConstant.middleTextWhiteSize,
  254. fontWeight: FontWeight.bold)),
  255. IconButton(
  256. onPressed: () {
  257. deletePatrolItem(item.id);
  258. },
  259. icon: new Icon(Icons.delete))
  260. ],
  261. ),
  262. ),
  263. Container(
  264. margin: const EdgeInsets.fromLTRB(0, 10.0, 0, 0),
  265. alignment: Alignment.centerLeft,
  266. child: Text(
  267. item.result,
  268. style: GSYConstant.smallTextLight,
  269. ),
  270. ),
  271. const SizedBox(
  272. height: 5,
  273. ),
  274. Divider(
  275. height: 0.8,
  276. color: Colors.grey,
  277. ),
  278. ],
  279. ),
  280. ));
  281. }
  282. patrolItem() async {
  283. var result = await DioUtil().request('patrolItem/list',
  284. method: DioMethod.post, data: {'patrolJobId': id});
  285. if (0 == result['code']) {
  286. PatrolJobEditEmtityEntity jobEdit = patrolJobEditEmtityEntityFromJson(
  287. PatrolJobEditEmtityEntity(), result);
  288. setState(() {
  289. patrolItemVOS.clear();
  290. patrolItemVOS.addAll(jobEdit.data);
  291. });
  292. } else {
  293. showToast(result['msg']);
  294. }
  295. }
  296. @override
  297. void initState() {
  298. super.initState();
  299. patrolItem();
  300. _event = eventBus.on<RefreshPatrolEdit>().listen((event) {
  301. setState(() {
  302. patrolItem();
  303. });
  304. });
  305. }
  306. deletePatrolItem(String id) async {
  307. var result = await DioUtil().request('patrolItem/deletePatrolItem',
  308. method: DioMethod.post, data: {'id': id});
  309. if (result['code'] == 0) {
  310. setState(() {
  311. patrolItem();
  312. });
  313. } else {
  314. showToast(result['msg']);
  315. }
  316. }
  317. @override
  318. void dispose() {
  319. super.dispose();
  320. _event.cancel();
  321. }
  322. uploadList() async {
  323. List<MultipartFile> files = [];
  324. for (var element in imageFiles) {
  325. File? imgFile = await element.file;
  326. String? s = imgFile?.path;
  327. MultipartFile file = MultipartFile.fromFileSync(s!);
  328. files.add(file);
  329. }
  330. var formData = FormData.fromMap({'files': files});
  331. var result = await DioUtil().request('uploadImg/uploadList',
  332. method: DioMethod.post, data: formData);
  333. if (result['code'] == 0) {
  334. UploadListEntityEntity data =
  335. uploadListEntityEntityFromJson(UploadListEntityEntity(), result);
  336. setState(() {
  337. mList.clear();
  338. mList.addAll(data.data);
  339. patrolJobRemark();
  340. });
  341. } else {
  342. showToast(result['msg']);
  343. }
  344. }
  345. patrolJobRemark() async {
  346. var result = await DioUtil().request('patrolJob/patrolJobRemark',
  347. method: DioMethod.post,
  348. data: {'id': id, 'fileIds': mList, 'remarks': note});
  349. if (result['code'] == 0) {
  350. setState(() {
  351. eventBus.fire(RefreshPatrolEdit());
  352. eventBus.fire(RefreshPatrol());
  353. Navigator.of(context)
  354. ..pop()
  355. ..pop();
  356. });
  357. } else {
  358. showToast(result['msg']);
  359. }
  360. }
  361. }