maint_job_edit.dart 11 KB

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