patrol_job_edit.dart 11 KB

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