patrol_job_edit.dart 11 KB

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