repair_add_page.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. import 'dart:io';
  2. import 'package:deus_app/PhotoTool.dart';
  3. import 'package:deus_app/common/event/RefreshRepairPage.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/upload_list_entity_entity_helper.dart';
  10. import 'package:deus_app/main.dart';
  11. import 'package:deus_app/model/repair_query_device_response_entity.dart';
  12. import 'package:deus_app/model/upload_list_entity_entity.dart';
  13. import 'package:deus_app/page/repair/repair_job_device_list.dart';
  14. import 'package:dio/dio.dart';
  15. import 'package:flutter/material.dart';
  16. import 'package:flutter/services.dart';
  17. import 'package:wechat_assets_picker/wechat_assets_picker.dart';
  18. class RepairAddPage extends StatefulWidget {
  19. const RepairAddPage({super.key});
  20. @override
  21. State<StatefulWidget> createState() {
  22. return _RepairAddPage();
  23. }
  24. }
  25. class _RepairAddPage extends State<RepairAddPage> {
  26. int groupValue = 1;
  27. String note='',theme='';
  28. List<AssetEntity> imageFiles = [];
  29. List<int>mList=[];
  30. var _event;
  31. RepairQueryDeviceResponseDataList _dataList=RepairQueryDeviceResponseDataList();
  32. @override
  33. Widget build(BuildContext context) {
  34. return Scaffold(
  35. appBar: TitleBar().backAppbar("新建报修"),
  36. backgroundColor: const Color(0xfff2f2f2),
  37. body: Stack(children: [
  38. Column(
  39. children: [
  40. Expanded(
  41. // flex: 7,
  42. child: ListView(
  43. children: _Ws(),
  44. ),
  45. ),
  46. ],
  47. ),
  48. Positioned(
  49. left: 0,
  50. right: 0,
  51. bottom:0,
  52. // flex: 7,
  53. child:SizedBox(
  54. height: 50,
  55. width: double.infinity,
  56. child: TextButton(
  57. onPressed: () {
  58. if(isAddDevice){
  59. if(imageFiles.isNotEmpty){
  60. uploadList();
  61. }else{
  62. patrolJobRemark();
  63. }
  64. }else{
  65. showToast('请选择设备');
  66. }
  67. },
  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. ),
  77. child: const Text(ConstantString.submit),
  78. ),
  79. ),
  80. )
  81. ]));
  82. }
  83. @override
  84. void initState() {
  85. super.initState();
  86. _event = eventBus.on<RepairQueryDeviceResponseDataList>().listen((event) {
  87. setState(() {
  88. _dataList=event;
  89. isAddDevice=true;
  90. });
  91. });
  92. }
  93. bool isAddDevice=false;
  94. List<Widget> _Ws() {
  95. List<Widget> ws = [];
  96. ws.add(_basicInformation());
  97. ws.add(_patrolAddTitle());
  98. if(isAddDevice){
  99. ws.add(_patrolAdd());
  100. }
  101. ws.add(_notes());
  102. return ws;
  103. }
  104. Widget _notes(){
  105. return Container(
  106. child: Column(
  107. children: <Widget>[
  108. Container(
  109. height: 50,
  110. padding: EdgeInsets.only(left: 12),
  111. alignment: Alignment.centerLeft,
  112. child: Text('报修说明',style: TextStyle(
  113. color: Colors.black,
  114. fontSize: GSYConstant.TextSize15,
  115. )),
  116. ),
  117. Container(
  118. padding: EdgeInsets.only(left: 12,right: 12,bottom: 12),
  119. decoration: BoxDecoration(color: Colors.white),
  120. child: Column(
  121. children: [
  122. const SizedBox(
  123. height: 10,
  124. ),
  125. TextField(
  126. maxLines: 5,
  127. decoration: InputDecoration(border: OutlineInputBorder()),
  128. style: TextStyle(fontSize: 14),
  129. onChanged: (value) {
  130. note = value;
  131. },
  132. )
  133. ],
  134. ),
  135. ),
  136. Container(
  137. // padding: EdgeInsets.only(left: 12,right: 12),
  138. decoration: BoxDecoration(color: Colors.white),
  139. child: PhotoTool(imageCount: 5, lineCount: 5, addCall: (List<AssetEntity> _imageFiles){
  140. imageFiles.addAll(_imageFiles);
  141. }, removeCall:(int index){
  142. imageFiles.remove(index);
  143. }),
  144. )
  145. ],
  146. ),
  147. );
  148. }
  149. Widget _basicInformation() {
  150. return Column(children: [
  151. Container(
  152. height: 50,
  153. padding: EdgeInsets.only(left: 12),
  154. alignment: Alignment.centerLeft,
  155. child: const Text(
  156. '基本信息:',
  157. style: TextStyle(
  158. color: Colors.black,
  159. fontSize: GSYConstant.TextSize15,
  160. ),
  161. ),
  162. ),
  163. Container(
  164. color: Colors.white,
  165. padding: EdgeInsets.only(left: 12, right: 12),
  166. child: Column(
  167. children: [
  168. Row(
  169. children: [
  170. Text(
  171. '紧急程度:',
  172. style: TextStyle(
  173. color: GSYColors.primaryLightValue,
  174. fontSize: GSYConstant.TextSize15,
  175. ),
  176. ),
  177. Radio(
  178. value: 1,
  179. groupValue: groupValue,
  180. onChanged: (value) {
  181. // groupValue = value;
  182. setState(() {
  183. groupValue = value!;
  184. });
  185. },
  186. ),
  187. Text("一般",
  188. style: TextStyle(
  189. color: GSYColors.primaryLightValue,
  190. fontSize: GSYConstant.TextSize15,
  191. )),
  192. Radio(
  193. value: 2,
  194. groupValue: groupValue,
  195. onChanged: (value) {
  196. // groupValue = value;
  197. setState(() {
  198. groupValue = value!;
  199. });
  200. },
  201. ),
  202. Text("紧急",
  203. style: TextStyle(
  204. color: GSYColors.primaryLightValue,
  205. fontSize: GSYConstant.smallTextSize,
  206. ))
  207. ],
  208. ),
  209. const SizedBox(
  210. height: 10,
  211. ),
  212. Row(children: [
  213. Text(
  214. '报修主题:',
  215. style: TextStyle(
  216. color: GSYColors.primaryLightValue,
  217. fontSize: GSYConstant.TextSize15,
  218. ),
  219. ),
  220. const SizedBox(
  221. width: 15,
  222. ),
  223. Container(
  224. height: 40,
  225. width: MediaQuery.of(context).size.width / 2 +
  226. MediaQuery.of(context).size.width / 8,
  227. child: TextField(
  228. decoration: InputDecoration(
  229. border: OutlineInputBorder(),
  230. hintText: '请输入报修主题',
  231. contentPadding: EdgeInsets.only(
  232. bottom: 20, left: 10 // HERE THE IMPORTANT PART
  233. )),
  234. style: TextStyle(fontSize: 14),
  235. textAlignVertical: TextAlignVertical.center,
  236. textAlign: TextAlign.left,
  237. onChanged: (value) {
  238. theme=value;
  239. },
  240. ),
  241. )
  242. ]),
  243. const SizedBox(
  244. height: 10,
  245. ),
  246. ],
  247. ),
  248. )
  249. ]);
  250. }
  251. Widget _patrolAddTitle() {
  252. return Container(
  253. padding: EdgeInsets.fromLTRB(12, 0, 12, 0),
  254. height: 50,
  255. child: Row(
  256. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  257. children: [
  258. const Text(
  259. '报修设备:',
  260. style: TextStyle(
  261. color: Colors.black,
  262. fontSize: GSYConstant.TextSize15,
  263. ),
  264. ),
  265. Container(
  266. child: TextButton(
  267. onPressed: () {
  268. Navigator.push(
  269. context,
  270. MaterialPageRoute(
  271. builder: (context) =>
  272. new RepairJobDeviceList()));
  273. },
  274. child: Row(
  275. children: [
  276. new Icon(Icons.add),
  277. new Text(
  278. '选择设备',
  279. style: TextStyle(
  280. color: Colors.blue,
  281. fontSize: GSYConstant.TextSize15,
  282. ),
  283. textAlign: TextAlign.right,
  284. )
  285. ],
  286. ),
  287. ),
  288. ),
  289. ],
  290. ),
  291. );
  292. }
  293. Widget _patrolAdd() {
  294. return Container(
  295. padding: EdgeInsets.only(top: 15, bottom: 15, left: 12, right: 12),
  296. color: Colors.white,
  297. child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  298. Container(
  299. child: Text(
  300. _dataList.showName,
  301. style: const TextStyle(
  302. color: Colors.black,
  303. fontSize: GSYConstant.middleTextWhiteSize,
  304. fontWeight: FontWeight.bold,
  305. ),
  306. ),
  307. ),
  308. Container(
  309. padding: EdgeInsets.only(top: 3, bottom: 3, left: 5, right: 5),
  310. child: Text(
  311. _dataList.status == 0
  312. ? '在线'
  313. : _dataList.status == 1
  314. ? '离线'
  315. : _dataList.status == 2
  316. ? '未激活'
  317. : '未知',
  318. textAlign: TextAlign.right,
  319. style: TextStyle(
  320. color: _dataList.status == 0
  321. ? Colors.blue
  322. : _dataList.status == 1
  323. ? Colors.orange
  324. : _dataList.status == 2
  325. ? Colors.red
  326. : Colors.black,
  327. fontSize: GSYConstant.minTextSize,
  328. ),
  329. ),
  330. decoration: BoxDecoration(
  331. border: new Border.all(
  332. color: _dataList.status == 0
  333. ? Colors.blue
  334. : _dataList.status == 1
  335. ? Colors.orange
  336. : _dataList.status == 2
  337. ? Colors.red
  338. : Colors.black, //边框颜色
  339. width: 1.0, //边框粗细
  340. ),
  341. borderRadius: const BorderRadius.all(
  342. const Radius.circular(3.0)), //边框的弧度
  343. ),
  344. )
  345. ]),
  346. );
  347. }
  348. @override
  349. void dispose() {
  350. super.dispose();
  351. _event.cancel();
  352. }
  353. patrolJobRemark() async {
  354. var result = await DioUtil().request('repair-bill/create',
  355. method: DioMethod.post, data: {'deviceId': _dataList.id,'repairImgIds':mList,'instructions':note,
  356. 'urg':groupValue,'theme':theme});
  357. if (result['code'] == 0) {
  358. setState(() {
  359. eventBus.fire(RefreshRepairPage());
  360. Navigator.pop(context);
  361. });
  362. } else {
  363. showToast(result['msg']);
  364. }
  365. }
  366. uploadList() async {
  367. List<MultipartFile> files = [];
  368. for (var element in imageFiles) {
  369. File? imgFile = await element.file;
  370. String? s=imgFile?.path;
  371. MultipartFile file =MultipartFile.fromFileSync(s!);
  372. files.add(file);
  373. }
  374. var formData =FormData.fromMap({
  375. 'files': files
  376. });
  377. var result = await DioUtil().request('uploadImg/uploadList',
  378. method: DioMethod.post, data: formData);
  379. if (result['code'] == 0) {
  380. UploadListEntityEntity data=uploadListEntityEntityFromJson(UploadListEntityEntity(), result);
  381. setState(() {
  382. mList.clear();
  383. mList.addAll(data.data);
  384. patrolJobRemark();
  385. });
  386. } else {
  387. showToast(result['msg']);
  388. }
  389. }
  390. }