repair_job_edit.dart 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. import 'dart:io';
  2. import 'package:deus_app/PhotoTool.dart';
  3. import 'package:deus_app/common/event/RefreshRepairDetail.dart';
  4. import 'package:deus_app/common/event/RefreshRepairPage.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/upload_list_entity_entity_helper.dart';
  11. import 'package:deus_app/main.dart';
  12. import 'package:deus_app/model/maint_job_items_list_response_entity.dart';
  13. import 'package:deus_app/model/repair_detail_response_entity.dart';
  14. import 'package:deus_app/model/upload_list_entity_entity.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 RepairJobEdit extends StatefulWidget {
  20. static var routeName = "/PatrolJobEdit";
  21. RepairDetailResponseData responseData;
  22. @override
  23. State createState() {
  24. return _RepairJobEdit(responseData);
  25. }
  26. RepairJobEdit({super.key, required this.responseData});
  27. }
  28. class _RepairJobEdit extends State<RepairJobEdit> {
  29. List<MaintJobItemsListResponseData> patrolItemVOS = <MaintJobItemsListResponseData>[];
  30. List<AssetEntity> imageFiles = [];
  31. List<int>mList=[];
  32. RepairDetailResponseData responseData;
  33. var _event;
  34. String note='';
  35. FocusNode focusNode = FocusNode();
  36. _RepairJobEdit(this.responseData);
  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. if(imageFiles.isNotEmpty){
  62. uploadList();
  63. }else{
  64. patrolJobRemark();
  65. }
  66. },
  67. child: Text(ConstantString.completeRepair),
  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. ],
  82. ),
  83. )
  84. ],
  85. ));
  86. }
  87. List<Widget> _Ws() {
  88. List<Widget> ws = [];
  89. ws.add(_mainPatrolAdd());
  90. ws.add(_notes());
  91. ws.add(_picture());
  92. // ws.add(_url());
  93. return ws;
  94. }
  95. Widget _picture(){
  96. return Container(
  97. child: Column(
  98. children: [
  99. Container(
  100. height: 50,
  101. padding: EdgeInsets.only(left: 12),
  102. alignment: Alignment.centerLeft,
  103. child: Text('巡检图片',style: TextStyle(
  104. color: Colors.black,
  105. fontSize: GSYConstant.TextSize15,
  106. )),
  107. ),
  108. Container(
  109. // padding: EdgeInsets.only(left: 12,right: 12),
  110. decoration: BoxDecoration(color: Colors.white),
  111. child: PhotoTool(imageCount: 5, lineCount: 5, addCall: (List<AssetEntity> _imageFiles){
  112. imageFiles.addAll(_imageFiles);
  113. }, removeCall:(int index){
  114. imageFiles.remove(index);
  115. }, focusNode: focusNode),
  116. )
  117. ],
  118. )
  119. );
  120. }
  121. Widget _notes(){
  122. return Container(
  123. child: Column(
  124. children: <Widget>[
  125. Container(
  126. height: 50,
  127. padding: EdgeInsets.only(left: 12),
  128. alignment: Alignment.centerLeft,
  129. child: Text('任务结果备注',style: TextStyle(
  130. color: Colors.black,
  131. fontSize: GSYConstant.TextSize15,
  132. )),
  133. ),
  134. Container(
  135. padding: EdgeInsets.only(left: 12,right: 12,bottom: 12),
  136. decoration: BoxDecoration(color: Colors.white),
  137. child: Column(
  138. children: [
  139. const SizedBox(
  140. height: 10,
  141. ),
  142. TextField(
  143. maxLines: 5,
  144. decoration: InputDecoration(border: OutlineInputBorder()),
  145. style: TextStyle(fontSize: 14),
  146. focusNode: focusNode,
  147. onChanged: (value) {
  148. note = value;
  149. },
  150. )
  151. ],
  152. ),
  153. )
  154. ],
  155. ),
  156. );
  157. }
  158. Widget _mainPatrolAdd(){
  159. return Column(
  160. children: [
  161. Container(
  162. padding: EdgeInsets.fromLTRB(12,0, 12, 0),
  163. alignment: Alignment.centerLeft,
  164. height: 50,
  165. child: Text(
  166. '设备信息:',
  167. style: TextStyle(
  168. color: Colors.black,
  169. fontSize: GSYConstant.TextSize15,
  170. ),
  171. ),
  172. ),
  173. Container(
  174. // padding: const EdgeInsets.fromLTRB(30.0, 0.0, 0.0, 0.0),
  175. alignment: Alignment.centerLeft,
  176. color: Colors.white,
  177. padding: EdgeInsets.fromLTRB(12,15, 12, 15),
  178. child: Row(
  179. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  180. children: [
  181. Text(responseData.deviceName!,
  182. style: GSYConstant.smallTextBold),
  183. Text(
  184. '未维修',
  185. style: TextStyle(
  186. fontSize: GSYConstant.smallTextSize,
  187. color: Colors.red),
  188. ),
  189. ]),
  190. ),
  191. ],
  192. );
  193. }
  194. @override
  195. void initState() {
  196. super.initState();
  197. // patrolItem();
  198. // _event = eventBus.on<RefreshMaintEdit>().listen((event) {
  199. // setState(() {
  200. // patrolItem();
  201. // });
  202. // });
  203. }
  204. @override
  205. void dispose() {
  206. super.dispose();
  207. _event.cancel();
  208. }
  209. uploadList() async {
  210. List<MultipartFile> files = [];
  211. for (var element in imageFiles) {
  212. File? imgFile = await element.file;
  213. String? s=imgFile?.path;
  214. MultipartFile file =MultipartFile.fromFileSync(s!);
  215. files.add(file);
  216. }
  217. var formData =FormData.fromMap({
  218. 'files': files
  219. });
  220. var result = await DioUtil().request('uploadImg/uploadList',
  221. method: DioMethod.post, data: formData);
  222. if (result['code'] == 0) {
  223. UploadListEntityEntity data=uploadListEntityEntityFromJson(UploadListEntityEntity(), result);
  224. setState(() {
  225. mList.clear();
  226. mList.addAll(data.data);
  227. patrolJobRemark();
  228. });
  229. } else {
  230. showToast(result['msg']);
  231. }
  232. }
  233. patrolJobRemark() async {
  234. var result = await DioUtil().request('repair-bill/app-complete',
  235. method: DioMethod.post, data: {'id': responseData.id,'repairResIds':mList,'remarks':note});
  236. if (result['code'] == 0) {
  237. setState(() {
  238. eventBus.fire(RefreshRepairDetail());
  239. eventBus.fire(RefreshRepairPage());
  240. Navigator.of(context).pop();
  241. });
  242. } else {
  243. showToast(result['msg']);
  244. }
  245. }
  246. }