repair_add_page.dart 12 KB

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