maint_job_edit.dart 11 KB

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