visit_page.dart 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/res/gaps.dart';
  3. import 'package:liftmanager/net/api_service.dart';
  4. import 'package:liftmanager/utils/toast.dart';
  5. import 'package:liftmanager/widgets/app_bar.dart';
  6. import 'package:liftmanager/internal/search/search_router.dart';
  7. import 'package:liftmanager/widgets/app_search_bar.dart';
  8. import 'package:liftmanager/res/resources.dart';
  9. import 'package:liftmanager/routers/fluro_navigator.dart';
  10. import 'package:liftmanager/widgets/load_image.dart';
  11. import 'package:liftmanager/widgets/selected_image_change.dart';
  12. import 'package:image_picker/image_picker.dart';
  13. import 'dart:io';
  14. import 'package:intl/intl.dart';
  15. // 时间戳工具类
  16. import 'package:liftmanager/utils/time_format.dart';
  17. import 'package:date_format/date_format.dart';
  18. import 'package:flutter_cupertino_date_picker/flutter_cupertino_date_picker.dart';
  19. // import 'package:amap_search_fluttify/amap_search_fluttify.dart';
  20. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  21. import 'package:flutter_screenutil/flutter_screenutil.dart';
  22. import 'package:shared_preferences/shared_preferences.dart';
  23. import 'package:liftmanager/utils/time_format.dart';
  24. import 'package:liftmanager/utils/fast_notification.dart';
  25. import 'package:liftmanager/common/common.dart';
  26. import 'package:flustars/flustars.dart' as flustars;
  27. import 'package:permission_handler/permission_handler.dart';
  28. // import 'package:amap_all_fluttify/amap_all_fluttify.dart';
  29. import 'package:liftmanager/utils/theme_utils.dart';
  30. class VisitPage extends StatefulWidget {
  31. VisitPage(this.brandName, this.brandId);
  32. final String brandName;
  33. final String brandId;
  34. @override
  35. State<StatefulWidget> createState() {
  36. return VisitPageState();
  37. }
  38. }
  39. class VisitPageState extends State<VisitPage> {
  40. // NewsDetailItem item = NewsDetailItem();
  41. ScrollController _scrollController = new ScrollController();
  42. String extAddress;
  43. List<String> imagesUrl = [];
  44. List<String> imagesUrlVideo = [];
  45. List<String> videoUrl = [];
  46. String addressName = "";
  47. // String addressName = "湖北省武汉市洪山区武大科技园豪迈大厦,30.46139,114.414463";
  48. @override
  49. void initState() {
  50. super.initState();
  51. print(widget.brandName);
  52. print(widget.brandId);
  53. print(65656);
  54. FastNotification.addListener("set_address", (setAddress) {
  55. setState(() {
  56. addressName = setAddress;
  57. print(addressName);
  58. print(222222224);
  59. });
  60. });
  61. // getLocation();
  62. }
  63. Future<bool> requestPermission() async {
  64. final permissions = await PermissionHandler()
  65. .requestPermissions([PermissionGroup.location]);
  66. if (permissions[PermissionGroup.location] == PermissionStatus.granted) {
  67. return true;
  68. } else {
  69. toasts('需要定位权限!');
  70. return false;
  71. }
  72. }
  73. // getLocation() async {
  74. // if (await requestPermission()) {
  75. // Location location = await AmapLocation.fetchLocation();
  76. // String address = location.province + location.city + location.district + location.street + location.aoiName;
  77. // print(address);
  78. // setState(() {
  79. // addressName = address;
  80. // });
  81. // }
  82. // }
  83. upLoadFileOnce(path) {
  84. showLoading(context, "正在上传...");
  85. NewApiService().upload(path, onSuccess: (res) {
  86. // imagesUrl.add(res.path);
  87. dismissLoading(context);
  88. setState(() {
  89. imagesUrl.add(res.pathUrl);
  90. });
  91. }, onError: (code, msg) {
  92. dismissLoading(context);
  93. toasts(msg);
  94. });
  95. }
  96. //视频
  97. upLoadFileOnceVideo(path) {
  98. showLoading(context, "正在上传...");
  99. NewApiService().upload(path, onSuccess: (res) {
  100. // imagesUrl.add(res.path);
  101. dismissLoading(context);
  102. setState(() {
  103. videoUrl.add(res.pathUrl);
  104. imagesUrlVideo.add(res.coverUrl);
  105. });
  106. }, onError: (code, msg) {
  107. dismissLoading(context);
  108. toasts(msg);
  109. });
  110. }
  111. ///选择图片
  112. void selectPicker(type) {
  113. showDialog(
  114. context: context,
  115. builder: (BuildContext context) {
  116. return SimpleDialog(
  117. title: Text("选择方式"),
  118. children: ["拍照", '从手机相册选择'].map((String value) {
  119. print("$value");
  120. return SimpleDialogOption(
  121. child: Text(
  122. "${value}",
  123. style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
  124. ),
  125. onPressed: () {
  126. if(type=="image"){
  127. _getImage(value == '拍照' ? 1 : 0);
  128. }else if (type=="video") {
  129. _getVideo(value == '拍照' ? 1 : 0);
  130. }
  131. Navigator.of(context).pop();
  132. },
  133. );
  134. }).toList());
  135. });
  136. }
  137. void _getImage(int key) async {
  138. try {
  139. var _imageFile = await ImagePicker.pickImage(
  140. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  141. maxWidth: 800,
  142. imageQuality: 95);
  143. print(_imageFile);
  144. print(3333);
  145. if (_imageFile != null) {
  146. // images.add(_imageFile);
  147. upLoadFileOnce(_imageFile.path);
  148. // setState(() {});
  149. }
  150. } catch (e) {
  151. toasts("没有权限,无法打开相册!");
  152. }
  153. }
  154. void _getVideo(int key) async {
  155. print(key);
  156. print(333);
  157. try {
  158. var _imageFile = await ImagePicker.pickVideo(
  159. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  160. );
  161. if (_imageFile != null) {
  162. // print(123);
  163. // print(_imageFile);
  164. // print(jsonEncode(_imageFile));
  165. print(123);
  166. upLoadFileOnceVideo(_imageFile.path);
  167. setState(() {});
  168. }
  169. } catch (e) {
  170. toasts("没有权限,无法打开相册!");
  171. }
  172. }
  173. FocusNode blankNode = FocusNode();
  174. // 文本编辑控制
  175. TextEditingController _textEditingController = new TextEditingController();
  176. // 焦点控制
  177. GlobalKey _formKey = new GlobalKey<FormState>();
  178. TextEditingController _questionController = new TextEditingController();
  179. TextEditingController _methodController = new TextEditingController();
  180. DateTime _nowDate = DateTime.now(); //当前日期
  181. DateTime _oldDate = DateTime.now(); //当前日期
  182. DateTime _nowDateTime = DateTime.parse(formatDate(DateTime.now(),
  183. [yyyy, "-", mm, "-", "dd", " ", HH, ":", nn, ":", ss])); //当前日期时间
  184. @override
  185. Widget build(BuildContext context) {
  186. double width = MediaQuery.of(context).size.width;
  187. var _datetime = formatDate(
  188. _nowDate, [yyyy, "-", mm, "-", dd, " ", HH, ":", nn]);
  189. // _nowDate, [yyyy, "-", mm, "-", dd, " ", HH, ":", nn, ":", ss]);
  190. // var _datetime = formatDate(_nowDate,[yyyy, "-", mm, "-", dd, " ", HH]);
  191. //调起datetime_picker_bottom选择器
  192. _cupertinoDateTimePicker() {
  193. DatePicker.showDatePicker(
  194. context,
  195. minDateTime: DateTime.parse('2010-05-12'), //起始日期
  196. maxDateTime: DateTime.parse('2021-11-25'), //终止日期
  197. //initialDateTime: DateTime.parse(formatDate(_selectedDateTime, [yyyy, "-", mm, "-", "dd", " ", HH, ":", nn, ":", ss])),
  198. initialDateTime: _nowDateTime, //当前日期时间
  199. // dateFormat: "yyyy年M月d日 EEE,H时", //显示格式
  200. dateFormat: "yyyy年M月d日 ,H时:m分", //显示格式
  201. // dateFormat: "yyyy年M月d日 ,H时:m分:s秒", //显示格式
  202. locale: DateTimePickerLocale.zh_cn, //语言
  203. pickerTheme: DateTimePickerTheme(
  204. showTitle: true,
  205. ),
  206. pickerMode: DateTimePickerMode.datetime, // show TimePicker
  207. onCancel: () {
  208. debugPrint('onCancel');
  209. },
  210. onChange: (dateTime, List<int> index) {
  211. setState(() {
  212. _nowDate = dateTime;
  213. });
  214. },
  215. onConfirm: (dateTime, List<int> index) {
  216. setState(() {
  217. _nowDate = dateTime;
  218. print(_nowDate);
  219. print(333333);
  220. });
  221. },
  222. );
  223. }
  224. return Scaffold(
  225. resizeToAvoidBottomPadding: false, //不让键盘弹上去
  226. appBar: MyAppBar(
  227. centerTitle: "我要提问",
  228. ),
  229. body: GestureDetector(
  230. onTap: () {
  231. // 点击空白页面关闭键盘
  232. FocusScope.of(context).requestFocus(blankNode);
  233. },
  234. child: Stack(children: <Widget>[
  235. Container(
  236. padding: EdgeInsets.only(bottom: ScreenUtil().setWidth(80)),
  237. child: ListView(children: <Widget>[
  238. Form(
  239. key: _formKey, //设置globalKey,用于后面获取FormState
  240. // autovalidate: true, //开启自动校验
  241. child: Column(
  242. children: <Widget>[
  243. Container(
  244. padding: EdgeInsets.only(
  245. left: ScreenUtil().setWidth(15),
  246. right: ScreenUtil().setWidth(15),
  247. top: ScreenUtil().setWidth(10),
  248. bottom: ScreenUtil().setWidth(10)),
  249. decoration: BoxDecoration(
  250. border: Border(
  251. bottom: BorderSide(width: 0.5, color: Colours.line),
  252. ),
  253. ),
  254. child: Row(
  255. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  256. children: <Widget>[
  257. Text(
  258. "电梯品牌",
  259. style: TextStyle(
  260. // fontSize:ScreenUtil().setSp(14)
  261. ),
  262. textAlign: TextAlign.start,
  263. ),
  264. Text(
  265. widget.brandName,
  266. style: TextStyle(
  267. color: Color(0xff999999),
  268. // fontSize:ScreenUtil().setSp(14)
  269. ),
  270. textAlign: TextAlign.start,
  271. ),
  272. ]),
  273. ),
  274. Container(
  275. padding: EdgeInsets.only(
  276. left: ScreenUtil().setWidth(15),
  277. right: ScreenUtil().setWidth(15),
  278. top: ScreenUtil().setWidth(10),
  279. bottom: ScreenUtil().setWidth(10)),
  280. decoration: BoxDecoration(
  281. border: Border(
  282. bottom: BorderSide(width: 0.5, color: Colours.line),
  283. ),
  284. ),
  285. child: Row(
  286. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  287. children: <Widget>[
  288. Text(
  289. "出诊时间",
  290. style: TextStyle(
  291. // fontSize:ScreenUtil().setSp(14)
  292. ),
  293. textAlign: TextAlign.start,
  294. ),
  295. _nowDate.millisecondsSinceEpoch ==
  296. _oldDate.millisecondsSinceEpoch
  297. ? InkWell(
  298. onTap: _cupertinoDateTimePicker,
  299. child: Text(
  300. "请选择时间",
  301. style: TextStyle(
  302. color: Color(0xff999999),
  303. // fontSize:ScreenUtil().setSp(14)
  304. ),
  305. textAlign: TextAlign.start,
  306. ))
  307. : Row(
  308. mainAxisAlignment:
  309. MainAxisAlignment.center,
  310. children: <Widget>[
  311. InkWell(
  312. onTap: _cupertinoDateTimePicker,
  313. child: Row(
  314. children: <Widget>[
  315. Text('$_datetime'),
  316. Icon(Icons.arrow_drop_down)
  317. ],
  318. ),
  319. )
  320. ],
  321. )
  322. ]),
  323. ),
  324. InkWell(
  325. onTap: () {
  326. NavigatorUtils.push(
  327. context, "${BbsRouter.mapChoicePoint}?type=1");
  328. },
  329. child: Container(
  330. padding: EdgeInsets.only(
  331. left: ScreenUtil().setWidth(15),
  332. right: ScreenUtil().setWidth(15),
  333. top: ScreenUtil().setWidth(10),
  334. bottom: ScreenUtil().setWidth(10)),
  335. decoration: BoxDecoration(
  336. border: Border(
  337. bottom:
  338. BorderSide(width: 0.5, color: Colours.line),
  339. ),
  340. ),
  341. child: Row(
  342. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  343. children: <Widget>[
  344. Text(
  345. "出诊地点 ",
  346. style: TextStyle(
  347. // fontSize:ScreenUtil().setSp(14)
  348. ),
  349. textAlign: TextAlign.start,
  350. ),
  351. Expanded(
  352. child: Text(
  353. addressName != null && addressName != ""
  354. ? addressName.split(",")[0]
  355. : "请选择",
  356. style: TextStyle(
  357. color: Color(0xff999999),
  358. // fontSize:ScreenUtil().setSp(14)
  359. ),
  360. textAlign: TextAlign.end,
  361. maxLines: 1,
  362. overflow: TextOverflow.ellipsis,
  363. ),
  364. )
  365. ]),
  366. ),
  367. ),
  368. Row(
  369. crossAxisAlignment: CrossAxisAlignment.start,
  370. mainAxisAlignment: MainAxisAlignment.start,
  371. children: <Widget>[
  372. Container(
  373. padding: EdgeInsets.only(
  374. left: ScreenUtil().setWidth(15),
  375. top: ScreenUtil().setWidth(5),
  376. bottom: ScreenUtil().setWidth(5)),
  377. child: Text(
  378. "问题描述",
  379. style: TextStyle(
  380. // fontSize:ScreenUtil().setSp(14),miaos
  381. ),
  382. textAlign: TextAlign.left,
  383. ),
  384. ),
  385. ],
  386. ),
  387. Container(
  388. height: 100,
  389. padding: EdgeInsets.only(
  390. left: ScreenUtil().setWidth(15),
  391. right: ScreenUtil().setWidth(15),
  392. bottom: ScreenUtil().setWidth(20)),
  393. child: TextFormField(
  394. // autofocus: true,
  395. maxLength: 50,
  396. cursorColor: Color(0xffcccccc),
  397. controller: _questionController,
  398. maxLines: 5,
  399. decoration: InputDecoration(
  400. contentPadding: EdgeInsets.all(0),
  401. hintText: '请详细描述事故问题和现场情况',
  402. hintStyle: TextStyle(
  403. color: Color(0xffcccccc),
  404. // fontSize: ScreenUtil().setSp(14)
  405. ),
  406. focusedBorder: InputBorder.none,
  407. border: InputBorder.none,
  408. // filled: true, // 背景色
  409. // fillColor: Colors.cyan.withAlpha(35),
  410. // icon: Icon(Icons.person)
  411. ),
  412. // 校验
  413. validator: (val) {
  414. return val.trim().length > 0 ? null : "不能为空";
  415. }),
  416. ),
  417. SizedBox(
  418. height: 6,
  419. child: Container(color: ThemeUtils.getDialogTextFieldColor(context)),
  420. ),
  421. Row(
  422. crossAxisAlignment: CrossAxisAlignment.start,
  423. mainAxisAlignment: MainAxisAlignment.start,
  424. children: <Widget>[
  425. Container(
  426. padding: EdgeInsets.only(
  427. left: ScreenUtil().setWidth(15),
  428. top: ScreenUtil().setWidth(5),
  429. bottom: ScreenUtil().setWidth(5)),
  430. child: Text(
  431. "已尝试方法",
  432. style: TextStyle(
  433. // fontSize:ScreenUtil().setSp(14),
  434. ),
  435. textAlign: TextAlign.left,
  436. ),
  437. ),
  438. ],
  439. ),
  440. Container(
  441. height: 100,
  442. padding:
  443. EdgeInsets.only(left: 15, right: 15, bottom: 20),
  444. child: TextFormField(
  445. // autofocus: true,
  446. maxLength: 50,
  447. cursorColor: Color(0xffcccccc),
  448. controller: _methodController,
  449. maxLines: 5,
  450. decoration: InputDecoration(
  451. contentPadding: EdgeInsets.all(0),
  452. hintText: '请详细描述已尝试方法以及结果',
  453. hintStyle: TextStyle(
  454. color: Color(0xffcccccc),
  455. // fontSize: ScreenUtil().setSp(14)
  456. ),
  457. focusedBorder: InputBorder.none,
  458. border: InputBorder.none,
  459. // filled: true, // 背景色
  460. // fillColor: Colors.cyan.withAlpha(35),
  461. // icon: Icon(Icons.person)
  462. ),
  463. // 校验
  464. validator: (val) {
  465. return val.trim().length > 0 ? null : "不能为空";
  466. }),
  467. ),
  468. SizedBox(
  469. height: 6,
  470. child: Container(color: ThemeUtils.getDialogTextFieldColor(context)),
  471. ),
  472. Container(
  473. width: width,
  474. padding: EdgeInsets.only(left:15,top:15),
  475. child: Text(
  476. "上传图片:",
  477. style: TextStyle(
  478. fontSize:
  479. ScreenUtil()
  480. .setSp(14),
  481. ),
  482. textAlign: TextAlign.left,
  483. ),
  484. ),
  485. Container(
  486. color: ThemeUtils.getTabsBg(context),
  487. child: GridView.builder(
  488. shrinkWrap: true,
  489. padding:
  490. const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
  491. physics: NeverScrollableScrollPhysics(),
  492. gridDelegate:
  493. SliverGridDelegateWithFixedCrossAxisCount(
  494. crossAxisCount: 3, childAspectRatio: 1.18),
  495. itemCount: imagesUrl.length >= 9
  496. ? 9
  497. : imagesUrl.length + 1,
  498. itemBuilder: (_, index) {
  499. return Stack(
  500. children: <Widget>[
  501. Center(
  502. child: SelectedImage(
  503. image: index < imagesUrl.length
  504. ? imagesUrl[index]
  505. : null,
  506. index: index,
  507. onTap: () {
  508. if (index >= imagesUrl.length) {
  509. selectPicker("image");
  510. }
  511. FocusScope.of(context)
  512. .requestFocus(FocusNode());
  513. print(index);
  514. print(imagesUrl);
  515. }),
  516. ),
  517. index < imagesUrl.length
  518. ? Positioned(
  519. top: 0,
  520. right: 0,
  521. child: GestureDetector(
  522. onTap: () {
  523. print(index);
  524. imagesUrl
  525. .remove(imagesUrl[index]);
  526. setState(() {});
  527. },
  528. child: Icon(
  529. IconData(0xe62a,
  530. fontFamily: "myfont"),
  531. size: 24.0,
  532. color: Color(0xff999999),
  533. ),
  534. ))
  535. : Container(
  536. child: null,
  537. )
  538. ],
  539. );
  540. },
  541. )),
  542. SizedBox(
  543. height:6,
  544. child: Container(
  545. color:ThemeUtils.getDialogTextFieldColor(context)
  546. ),
  547. ),
  548. Container(
  549. width: width,
  550. padding: EdgeInsets.only(left:15,top:15),
  551. child: Text(
  552. "上传视频:",
  553. style: TextStyle(
  554. fontSize:
  555. ScreenUtil()
  556. .setSp(14),
  557. ),
  558. textAlign: TextAlign.left,
  559. ),
  560. ),
  561. Container(
  562. width: width,
  563. padding: EdgeInsets.only(left:15),
  564. child: Text(
  565. "(建议时长3分钟,建议大小50M)",
  566. style: TextStyle(
  567. color: Colors.red,
  568. fontSize:
  569. ScreenUtil()
  570. .setSp(14),
  571. ),
  572. textAlign: TextAlign.left,
  573. ),
  574. ),
  575. Container(
  576. color: ThemeUtils.getTabsBg(context),
  577. child: GridView.builder(
  578. shrinkWrap: true,
  579. padding: const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
  580. physics: NeverScrollableScrollPhysics(),
  581. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  582. crossAxisCount: 3, childAspectRatio: 1.18),
  583. itemCount: videoUrl.length >= 1 ? 1 : videoUrl.length + 1,
  584. itemBuilder: (_, index) {
  585. return Stack(
  586. children: <Widget>[
  587. Center(
  588. child: SelectedImage(
  589. image: index < videoUrl.length ? imagesUrlVideo[index] : null,
  590. index:index,
  591. onTap: () {
  592. if(index >= videoUrl.length){
  593. selectPicker("video");
  594. }
  595. FocusScope.of(context).requestFocus(FocusNode());
  596. print(index);
  597. print(videoUrl);
  598. }),
  599. ),
  600. index < videoUrl.length?Positioned(
  601. top:0,
  602. right:0,
  603. child:GestureDetector(
  604. onTap: (){
  605. print(index);
  606. videoUrl.remove(videoUrl[index]);
  607. imagesUrlVideo.remove(imagesUrlVideo[index]);
  608. setState(() {
  609. });
  610. },
  611. child:Icon(
  612. IconData(
  613. 0xe62a,
  614. fontFamily:"myfont"
  615. ),
  616. size: 24.0,
  617. color:Color(0xff999999),
  618. ),
  619. )
  620. ):Container(child: null,)
  621. ],
  622. );
  623. },
  624. )
  625. ),
  626. ],
  627. ),
  628. )
  629. ])),
  630. Positioned(
  631. bottom: 0,
  632. left: 0,
  633. child: Container(
  634. color:ThemeUtils.getDialogTextFieldColor(context),
  635. width: width,
  636. padding: EdgeInsets.only(
  637. top: ScreenUtil().setWidth(15),
  638. bottom: ScreenUtil().setWidth(15),
  639. left: ScreenUtil().setWidth(25),
  640. right: ScreenUtil().setWidth(25)),
  641. child: Container(
  642. height: ScreenUtil().setWidth(44),
  643. decoration: BoxDecoration(
  644. borderRadius: BorderRadius.circular(22.0),
  645. gradient: const LinearGradient(
  646. colors: [Color(0xFF00D9FF), Color(0xFF0287FF)]),
  647. ),
  648. child: FlatButton(
  649. // padding: EdgeInsets.all(15.0),
  650. child: Text("提交"),
  651. textColor: Colors.white,
  652. // textColor: Colors.white,
  653. onPressed: () {
  654. // getExtAddress();
  655. print(_nowDate);
  656. print(_nowDate.toString().split(" ")[0] + " " + _nowDate.toString().split(" ")[1].substring(0, 5)+":00");
  657. String time = _nowDate.toString().split(" ")[0] + " " + _nowDate.toString().split(" ")[1].substring(0, 5)+":00";
  658. print(999994);
  659. if (DateUtils.instance
  660. .getTimeStap(formartData: _nowDate.toString()) <=
  661. DateUtils.instance
  662. .getTimeStap(formartData: _oldDate.toString())) {
  663. toasts("请选择正确的出诊时间");
  664. return;
  665. }
  666. if (addressName == null || addressName == "") {
  667. toasts("请选择出诊地点");
  668. return;
  669. }
  670. // if (imagesUrl.length < 1) {
  671. // toasts("请上传图片");
  672. // return;
  673. // }
  674. String imgs = "";
  675. if(imagesUrl.length > 0){
  676. imgs = imagesUrl.join(",");
  677. }
  678. String videoImgs = "";
  679. if(videoUrl.length > 0){
  680. videoImgs = videoUrl.join(",");
  681. }
  682. if ((_formKey.currentState as FormState).validate()) {
  683. dynamic obj = {
  684. "dataTable": "2",
  685. "brandId": widget.brandId,
  686. "expression": _questionController.text,
  687. "usedMethods": _methodController.text,
  688. "imgs": imgs,
  689. "videoUrl":videoImgs,
  690. "createUserId": int.parse(
  691. flustars.SpUtil.getString(Constant.userId)),
  692. "chargerId": 1,
  693. "arrivedTime":DateUtils.instance.getTimeStap(formartData: time.toString()),
  694. // _nowDate.toString().split(" ")[0] +"T" +_nowDate.toString().split(" ")[1],
  695. // "arrivedTime":_nowDate.toString().split(" ")[0]+"T"+_nowDate.toString().split(" ")[1].substring(0, 2)+":00:00.000",
  696. "address": addressName.split(",")[0],
  697. "lat": addressName.split(",")[1],
  698. "lng": addressName.split(",")[2],
  699. };
  700. showLoading(context, "正在提交...");
  701. NewApiService().createCase(obj, onSuccess: (res) {
  702. dismissLoading(context);
  703. toasts("提交成功");
  704. FocusScope.of(context).requestFocus(FocusNode());
  705. print(res);
  706. print(999999);
  707. setDataId(res);
  708. setType("2");
  709. NavigatorUtils.push(context,
  710. "${BbsRouter.expertList}?id=${widget.brandId}");
  711. }, onError: (code, msg) {
  712. dismissLoading(context);
  713. toasts(msg);
  714. });
  715. }
  716. },
  717. ),
  718. ),
  719. ))
  720. ]),
  721. ),
  722. );
  723. }
  724. void setDataId(int id) async {
  725. SharedPreferences prefs = await SharedPreferences.getInstance();
  726. prefs.setInt("dataId", id);
  727. }
  728. void setType(String type) async {
  729. SharedPreferences prefs = await SharedPreferences.getInstance();
  730. prefs.setString("questionType", type);
  731. }
  732. // void getExtAddress ()async{
  733. // SharedPreferences prefs = await SharedPreferences.getInstance();
  734. // extAddress = prefs.getString("extAddress");
  735. // }
  736. }