patrol_job_edit.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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.addAll(_imageFiles);
  141. },
  142. removeCall: (int index) {
  143. imageFiles.remove(index);
  144. },focusNode:focusNode),
  145. )
  146. ],
  147. ));
  148. }
  149. Widget _notes() {
  150. return Container(
  151. child: Column(
  152. children: <Widget>[
  153. Container(
  154. height: 50,
  155. padding: EdgeInsets.only(left: 12),
  156. alignment: Alignment.centerLeft,
  157. child: Text('任务结果备注',
  158. style: TextStyle(
  159. color: Colors.black,
  160. fontSize: GSYConstant.TextSize15,
  161. )),
  162. ),
  163. Container(
  164. padding: EdgeInsets.only(left: 12, right: 12, bottom: 12),
  165. decoration: BoxDecoration(color: Colors.white),
  166. child: Column(
  167. children: [
  168. const SizedBox(
  169. height: 10,
  170. ),
  171. TextField(
  172. maxLines: 5,
  173. focusNode: focusNode,
  174. decoration: InputDecoration(border: OutlineInputBorder()),
  175. style: TextStyle(fontSize: 14),
  176. onChanged: (value) {
  177. note = value;
  178. },
  179. )
  180. ],
  181. ),
  182. )
  183. ],
  184. ),
  185. );
  186. }
  187. Widget _mainPatrolAdd() {
  188. return Column(
  189. children: [
  190. Container(
  191. padding: EdgeInsets.fromLTRB(12, 0, 12, 0),
  192. height: 50,
  193. child: Row(
  194. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  195. children: [
  196. const Text(
  197. '巡检项目:',
  198. style: TextStyle(
  199. color: Colors.black,
  200. fontSize: GSYConstant.TextSize15,
  201. ),
  202. ),
  203. Container(
  204. child: TextButton(
  205. onPressed: () {
  206. focusNode.unfocus();
  207. Navigator.push(
  208. context,
  209. MaterialPageRoute(
  210. builder: (context) => PatrolJobSelect(
  211. id: id,
  212. )));
  213. },
  214. child: Row(
  215. children: [
  216. new Icon(Icons.add),
  217. new Text(
  218. '添加项目',
  219. style: TextStyle(
  220. color: Colors.blue,
  221. fontSize: GSYConstant.TextSize15,
  222. ),
  223. textAlign: TextAlign.right,
  224. )
  225. ],
  226. ),
  227. ),
  228. ),
  229. ],
  230. ),
  231. )
  232. ],
  233. );
  234. }
  235. List<Widget> _item() {
  236. return patrolItemVOS.map((e) => _buildItem(e)).toList();
  237. }
  238. Widget _buildItem(PatrolJobEditEmtityData item) {
  239. return FractionallySizedBox(
  240. widthFactor: 1,
  241. child: Container(
  242. padding: const EdgeInsets.fromLTRB(12, 0, 15, 5),
  243. decoration: BoxDecoration(color: Colors.white),
  244. child: Column(
  245. children: [
  246. Container(
  247. child: Row(
  248. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  249. children: [
  250. Text(item.name,
  251. style: TextStyle(
  252. fontSize: GSYConstant.middleTextWhiteSize,
  253. fontWeight: FontWeight.bold)),
  254. IconButton(
  255. onPressed: () {
  256. deletePatrolItem(item.id);
  257. },
  258. icon: new Icon(Icons.delete))
  259. ],
  260. ),
  261. ),
  262. Container(
  263. margin: const EdgeInsets.fromLTRB(0, 10.0, 0, 0),
  264. alignment: Alignment.centerLeft,
  265. child: Text(
  266. item.result,
  267. style: GSYConstant.smallTextLight,
  268. ),
  269. ),
  270. const SizedBox(
  271. height: 5,
  272. ),
  273. Divider(
  274. height: 0.8,
  275. color: Colors.grey,
  276. ),
  277. ],
  278. ),
  279. ));
  280. }
  281. patrolItem() async {
  282. var result = await DioUtil().request('patrolItem/list',
  283. method: DioMethod.post, data: {'patrolJobId': id});
  284. if (0 == result['code']) {
  285. PatrolJobEditEmtityEntity jobEdit = patrolJobEditEmtityEntityFromJson(
  286. PatrolJobEditEmtityEntity(), result);
  287. setState(() {
  288. patrolItemVOS.clear();
  289. patrolItemVOS.addAll(jobEdit.data);
  290. });
  291. } else {
  292. showToast(result['msg']);
  293. }
  294. }
  295. @override
  296. void initState() {
  297. super.initState();
  298. patrolItem();
  299. _event = eventBus.on<RefreshPatrolEdit>().listen((event) {
  300. setState(() {
  301. patrolItem();
  302. });
  303. });
  304. }
  305. deletePatrolItem(String id) async {
  306. var result = await DioUtil().request('patrolItem/deletePatrolItem',
  307. method: DioMethod.post, data: {'id': id});
  308. if (result['code'] == 0) {
  309. setState(() {
  310. patrolItem();
  311. });
  312. } else {
  313. showToast(result['msg']);
  314. }
  315. }
  316. @override
  317. void dispose() {
  318. super.dispose();
  319. _event.cancel();
  320. }
  321. uploadList() async {
  322. List<MultipartFile> files = [];
  323. for (var element in imageFiles) {
  324. File? imgFile = await element.file;
  325. String? s = imgFile?.path;
  326. MultipartFile file = MultipartFile.fromFileSync(s!);
  327. files.add(file);
  328. }
  329. var formData = FormData.fromMap({'files': files});
  330. var result = await DioUtil().request('uploadImg/uploadList',
  331. method: DioMethod.post, data: formData);
  332. if (result['code'] == 0) {
  333. UploadListEntityEntity data =
  334. uploadListEntityEntityFromJson(UploadListEntityEntity(), result);
  335. setState(() {
  336. mList.clear();
  337. mList.addAll(data.data);
  338. patrolJobRemark();
  339. });
  340. } else {
  341. showToast(result['msg']);
  342. }
  343. }
  344. patrolJobRemark() async {
  345. var result = await DioUtil().request('patrolJob/patrolJobRemark',
  346. method: DioMethod.post,
  347. data: {'id': id, 'fileIds': mList, 'remarks': note});
  348. if (result['code'] == 0) {
  349. setState(() {
  350. eventBus.fire(RefreshPatrolEdit());
  351. eventBus.fire(RefreshPatrol());
  352. Navigator.of(context)
  353. ..pop()
  354. ..pop();
  355. });
  356. } else {
  357. showToast(result['msg']);
  358. }
  359. }
  360. }