maint_job_edit.dart 12 KB

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