repair_job_edit.dart 7.8 KB

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