maint_job_edit.dart 12 KB

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