recommend_ask.dart 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. import 'dart:convert';
  2. import 'package:chewie/chewie.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/services.dart';
  5. import 'package:flutter_screenutil/flutter_screenutil.dart';
  6. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  7. import 'package:liftmanager/net/api_service.dart';
  8. import 'package:liftmanager/res/resources.dart';
  9. import 'package:liftmanager/routers/fluro_navigator.dart';
  10. import 'package:liftmanager/utils/theme_utils.dart';
  11. import 'package:liftmanager/utils/time_format.dart';
  12. import 'package:liftmanager/utils/toast.dart';
  13. import 'package:liftmanager/utils/utils.dart';
  14. import 'package:liftmanager/widgets/app_bar.dart';
  15. import 'package:liftmanager/widgets/load_image.dart';
  16. import 'package:liftmanager/widgets/preview_images.dart';
  17. import 'package:orientation/orientation.dart';
  18. import 'package:video_player/video_player.dart';
  19. class RecommendAsk extends StatefulWidget {
  20. RecommendAsk(this.id, this.type);
  21. final String id;
  22. final String type;
  23. @override
  24. State<StatefulWidget> createState() {
  25. return RecommendAskState();
  26. }
  27. }
  28. class RecommendAskState extends State<RecommendAsk> {
  29. // NewsDetailItem item = NewsDetailItem();
  30. ScrollController _scrollController = new ScrollController();
  31. VideoPlayerController _controller;
  32. @override
  33. void initState() {
  34. super.initState();
  35. // getDetail();
  36. Future.delayed(Duration(milliseconds: 100), () {
  37. getDetail();
  38. });
  39. }
  40. bool _hasData = false;
  41. List<String> listPreview = [];
  42. var detailObj;
  43. getDetail() {
  44. NewApiService().getLiftcaseDetail(int.parse(widget.id), onSuccess: (res) {
  45. detailObj = res;
  46. if (_controller == null && detailObj.videoUrl != null) {
  47. _controller =
  48. VideoPlayerController.network(Utils.getImagePath(detailObj.videoUrl)
  49. // imgFontUrl + detailObj.url
  50. );
  51. }
  52. listPreview = [];
  53. detailObj.imgs.split(",").forEach((element) {
  54. listPreview.add(Utils.getImagePath(element, isWater: true));
  55. });
  56. print("获取详情成功");
  57. print(JsonEncoder().convert(res));
  58. _hasData = true;
  59. setState(() {});
  60. }, onError: (code, msg) {
  61. toasts(msg);
  62. });
  63. }
  64. orderReceiving() {
  65. var obj = {"acceptStatus": 1, "id": detailObj.id};
  66. NewApiService().orderReceiving(obj, onSuccess: (res) {
  67. toasts("操作成功");
  68. if (_controller != null) {
  69. _controller.pause();
  70. }
  71. NavigatorUtils.push(context,
  72. "${BbsRouter.chatRoom}?id=${detailObj.sessionId}&type=someToOne&toUserId=''");
  73. _hasData = true;
  74. setState(() {});
  75. }, onError: (code, msg) {
  76. toasts(msg);
  77. });
  78. }
  79. orderRefuze() {
  80. NewApiService().orderRefuze(detailObj.id, onSuccess: (res) {
  81. toasts("操作成功");
  82. if (_controller != null) {
  83. _controller.pause();
  84. }
  85. NavigatorUtils.push(context, BbsRouter.workPlace);
  86. _hasData = true;
  87. setState(() {});
  88. }, onError: (code, msg) {
  89. toasts(msg);
  90. });
  91. }
  92. getTitle() {
  93. String str;
  94. if (widget.type == "1") {
  95. str = "问诊推荐";
  96. } else if (widget.type == "2") {
  97. str = "出诊推荐";
  98. } else if (widget.type == "3") {
  99. str = "诊单详情";
  100. }
  101. return str;
  102. }
  103. @override
  104. void dispose() {
  105. if (_controller != null) {
  106. _controller?.pause();
  107. _controller?.dispose();
  108. }
  109. // SystemChrome.setPreferredOrientations([
  110. // DeviceOrientation.portraitUp,
  111. // ]);
  112. OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp);
  113. super.dispose();
  114. }
  115. @override
  116. Widget build(BuildContext context) {
  117. double width = MediaQuery.of(context).size.width;
  118. double height = MediaQuery.of(context).size.height;
  119. if (width > height) {
  120. // SystemChrome.setPreferredOrientations([
  121. // DeviceOrientation.portraitUp,
  122. // ]);
  123. OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp);
  124. }
  125. return Scaffold(
  126. resizeToAvoidBottomPadding: false, //不让键盘弹上去
  127. appBar: MyAppBar(
  128. centerTitle: getTitle(),
  129. ),
  130. body: _hasData
  131. ? Stack(children: <Widget>[
  132. Container(
  133. padding: EdgeInsets.only(
  134. bottom: widget.type != "3"
  135. ? ScreenUtil().setWidth(70)
  136. : ScreenUtil().setWidth(10)),
  137. child: ListView(children: <Widget>[
  138. Column(
  139. crossAxisAlignment: CrossAxisAlignment.start,
  140. children: <Widget>[
  141. Container(
  142. padding: EdgeInsets.only(
  143. left: ScreenUtil().setWidth(15),
  144. right: ScreenUtil().setWidth(15),
  145. top: ScreenUtil().setWidth(10),
  146. bottom: ScreenUtil().setWidth(10)),
  147. decoration: BoxDecoration(
  148. border: Border(
  149. bottom:
  150. BorderSide(width: 0.5, color: Colours.line),
  151. ),
  152. ),
  153. child: Row(
  154. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  155. children: <Widget>[
  156. Text(
  157. "提问人",
  158. style: TextStyle(
  159. fontSize: ScreenUtil().setSp(17)),
  160. textAlign: TextAlign.start,
  161. ),
  162. Row(
  163. children: <Widget>[
  164. Text(
  165. detailObj.name ?? "",
  166. style: TextStyle(
  167. color: Color(0xff666666),
  168. fontSize: ScreenUtil().setSp(15)),
  169. textAlign: TextAlign.start,
  170. ),
  171. Container(
  172. margin: EdgeInsets.only(
  173. left: ScreenUtil().setWidth(10),
  174. right: ScreenUtil().setWidth(10),
  175. top: ScreenUtil().setWidth(5)),
  176. decoration: BoxDecoration(
  177. borderRadius: BorderRadius.circular(
  178. ScreenUtil().setWidth(25)),
  179. ),
  180. child: ClipRRect(
  181. borderRadius: BorderRadius.circular(
  182. ScreenUtil().setWidth(22)),
  183. child: LoadNetworkImage(
  184. detailObj.avatarUrl,
  185. width: ScreenUtil().setWidth(37),
  186. height: ScreenUtil().setWidth(37),
  187. // alignment: Alignment.centerLeft,
  188. ),
  189. ),
  190. ),
  191. ],
  192. )
  193. ]),
  194. ),
  195. Container(
  196. padding: EdgeInsets.only(
  197. left: ScreenUtil().setWidth(15),
  198. right: ScreenUtil().setWidth(15),
  199. top: ScreenUtil().setWidth(10),
  200. bottom: ScreenUtil().setWidth(10)),
  201. decoration: BoxDecoration(
  202. border: Border(
  203. bottom:
  204. BorderSide(width: 0.5, color: Colours.line),
  205. ),
  206. ),
  207. child: Row(
  208. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  209. children: <Widget>[
  210. Text(
  211. "电梯品牌",
  212. style: TextStyle(
  213. fontSize: ScreenUtil().setSp(17)),
  214. textAlign: TextAlign.start,
  215. ),
  216. Text(
  217. detailObj.brandName ?? "",
  218. style: TextStyle(
  219. color: Color(0xff666666),
  220. fontSize: ScreenUtil().setSp(15)),
  221. textAlign: TextAlign.start,
  222. ),
  223. ]),
  224. ),
  225. Container(
  226. padding: EdgeInsets.only(
  227. left: ScreenUtil().setWidth(15),
  228. right: ScreenUtil().setWidth(15),
  229. top: ScreenUtil().setWidth(10),
  230. bottom: ScreenUtil().setWidth(10)),
  231. decoration: BoxDecoration(
  232. border: Border(
  233. bottom:
  234. BorderSide(width: 0.5, color: Colours.line),
  235. ),
  236. ),
  237. child: Row(
  238. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  239. children: <Widget>[
  240. Text(
  241. "出厂时间",
  242. style: TextStyle(
  243. fontSize: ScreenUtil().setSp(17)),
  244. textAlign: TextAlign.start,
  245. ),
  246. Text(
  247. detailObj.productionDate ?? "",
  248. style: TextStyle(
  249. color: Color(0xff666666),
  250. fontSize: ScreenUtil().setSp(15)),
  251. textAlign: TextAlign.start,
  252. ),
  253. ]),
  254. ),
  255. detailObj.dataTable == 2
  256. ? Container(
  257. padding: EdgeInsets.only(
  258. left: ScreenUtil().setWidth(15),
  259. right: ScreenUtil().setWidth(15),
  260. top: ScreenUtil().setWidth(10),
  261. bottom: ScreenUtil().setWidth(10)),
  262. decoration: BoxDecoration(
  263. border: Border(
  264. bottom: BorderSide(
  265. width: 0.5, color: Colours.line),
  266. ),
  267. ),
  268. child: Row(
  269. mainAxisAlignment:
  270. MainAxisAlignment.spaceBetween,
  271. children: <Widget>[
  272. Text(
  273. "出诊时间",
  274. style: TextStyle(
  275. fontSize: ScreenUtil().setSp(17)),
  276. textAlign: TextAlign.start,
  277. ),
  278. Text(
  279. detailObj.arrivedTime != null
  280. ? DateUtils.instance.getFormartData(
  281. timeSamp: detailObj.arrivedTime,
  282. format: "yyyy-MM-dd HH:mm")
  283. : "",
  284. style: TextStyle(
  285. color: Color(0xff666666),
  286. fontSize: ScreenUtil().setSp(15)),
  287. textAlign: TextAlign.start,
  288. ),
  289. ]),
  290. )
  291. : Container(child: null),
  292. detailObj.dataTable == 2
  293. ? Container(
  294. padding: EdgeInsets.only(
  295. left: ScreenUtil().setWidth(15),
  296. right: ScreenUtil().setWidth(15),
  297. top: ScreenUtil().setWidth(10),
  298. bottom: ScreenUtil().setWidth(10)),
  299. decoration: BoxDecoration(
  300. border: Border(
  301. bottom: BorderSide(
  302. width: 0.5, color: Colours.line),
  303. ),
  304. ),
  305. child: Row(
  306. mainAxisAlignment:
  307. MainAxisAlignment.spaceBetween,
  308. crossAxisAlignment:
  309. CrossAxisAlignment.start,
  310. children: <Widget>[
  311. Text(
  312. "出诊地点",
  313. style: TextStyle(
  314. fontSize: ScreenUtil().setSp(17)),
  315. textAlign: TextAlign.start,
  316. ),
  317. Container(
  318. width: width * 0.7,
  319. child: Text(
  320. detailObj.address != null
  321. ? detailObj.address.split(",")[0]
  322. : "",
  323. style: TextStyle(
  324. color: Color(0xff666666),
  325. fontSize: ScreenUtil().setSp(18)),
  326. textAlign: TextAlign.end,
  327. ),
  328. )
  329. ]),
  330. )
  331. : Container(child: null),
  332. Column(
  333. crossAxisAlignment: CrossAxisAlignment.start,
  334. mainAxisAlignment: MainAxisAlignment.start,
  335. children: <Widget>[
  336. Container(
  337. padding: EdgeInsets.only(
  338. left: ScreenUtil().setWidth(15),
  339. top: ScreenUtil().setWidth(10),
  340. bottom: ScreenUtil().setWidth(5)),
  341. child: Text(
  342. "问题描述",
  343. style: TextStyle(
  344. fontSize: ScreenUtil().setSp(17),
  345. ),
  346. textAlign: TextAlign.left,
  347. ),
  348. ),
  349. Container(
  350. padding: EdgeInsets.only(
  351. left: ScreenUtil().setWidth(15),
  352. right: ScreenUtil().setWidth(15),
  353. bottom: ScreenUtil().setWidth(50)),
  354. child: Text(
  355. detailObj.expression ?? "",
  356. style: TextStyle(
  357. color: Color(0xff666666),
  358. fontSize: ScreenUtil().setSp(15),
  359. ),
  360. textAlign: TextAlign.left,
  361. ),
  362. ),
  363. ],
  364. ),
  365. SizedBox(
  366. height: 6,
  367. child: Container(
  368. color:
  369. ThemeUtils.getDialogTextFieldColor(context)),
  370. ),
  371. Column(
  372. crossAxisAlignment: CrossAxisAlignment.start,
  373. mainAxisAlignment: MainAxisAlignment.start,
  374. children: <Widget>[
  375. Container(
  376. padding: EdgeInsets.only(
  377. left: ScreenUtil().setWidth(15),
  378. top: ScreenUtil().setWidth(10),
  379. bottom: ScreenUtil().setWidth(5)),
  380. child: Text(
  381. "已尝试方法",
  382. style: TextStyle(
  383. fontSize: ScreenUtil().setSp(17),
  384. ),
  385. textAlign: TextAlign.left,
  386. ),
  387. ),
  388. Container(
  389. padding: EdgeInsets.only(
  390. left: ScreenUtil().setWidth(15),
  391. right: ScreenUtil().setWidth(15),
  392. bottom: ScreenUtil().setWidth(50)),
  393. child: Text(
  394. detailObj.usedMethods ?? "",
  395. style: TextStyle(
  396. color: Color(0xff666666),
  397. fontSize: ScreenUtil().setSp(15),
  398. ),
  399. textAlign: TextAlign.left,
  400. ),
  401. ),
  402. ],
  403. ),
  404. detailObj.imgs != null && detailObj.imgs != ""
  405. ? SizedBox(
  406. height: 6,
  407. child: Container(
  408. color: ThemeUtils.getDialogTextFieldColor(
  409. context)),
  410. )
  411. : Container(child: null),
  412. detailObj.imgs != null && detailObj.imgs != ""
  413. ? Container(
  414. padding: EdgeInsets.all(15),
  415. color: ThemeUtils.getTabsBg(context),
  416. child: Wrap(
  417. spacing: 20,
  418. runSpacing: 15,
  419. children: List<Widget>.from(detailObj.imgs
  420. .split(",")
  421. .asMap()
  422. .keys
  423. .map((index) {
  424. return GestureDetector(
  425. onTap: () {
  426. Navigator.of(context).push(
  427. new FadeRoute(
  428. page: PhotoViewGalleryScreen(
  429. images: listPreview, //传入图片list
  430. index: index, //传入当前点击的图片的index
  431. // heroTag: img,//传入当前点击的图片的hero tag (可选)
  432. ),
  433. ),
  434. );
  435. },
  436. child: LoadNetworkImage(
  437. detailObj.imgs.split(",")[index],
  438. width: ScreenUtil().setWidth(100),
  439. height: ScreenUtil().setWidth(100),
  440. isWater: true,
  441. // alignment: Alignment.centerLeft,
  442. ),
  443. );
  444. }).toList())))
  445. : Container(child: null),
  446. detailObj.videoUrl != null && detailObj.videoUrl != ""
  447. ? SizedBox(
  448. height: 6,
  449. child: Container(
  450. color: ThemeUtils.getDialogTextFieldColor(
  451. context)),
  452. )
  453. : Container(child: null),
  454. detailObj.videoUrl != null && detailObj.videoUrl != ""
  455. ? Container(
  456. padding: EdgeInsets.only(
  457. left: ScreenUtil().setWidth(15),
  458. right: ScreenUtil().setWidth(15),
  459. top: ScreenUtil().setWidth(15)),
  460. child: ClipRRect(
  461. borderRadius: BorderRadius.circular(5),
  462. child: new Chewie(
  463. controller: ChewieController(
  464. videoPlayerController:
  465. // VideoPlayerController.network(
  466. // imgFontUrl + detailObj.url
  467. // ),
  468. _controller,
  469. aspectRatio: 3 / 2,
  470. autoPlay: false,
  471. looping: true,
  472. showControls: true,
  473. deviceOrientationsAfterFullScreen: [
  474. DeviceOrientation.portraitUp,
  475. ],
  476. // 占位图
  477. // placeholder: Image.network(
  478. // imgFontUrl+detailObj.cover,
  479. // fit: BoxFit.contain,
  480. // ),
  481. // 是否在 UI 构建的时候就加载视频
  482. autoInitialize: true,
  483. // 拖动条样式颜色
  484. materialProgressColors:
  485. new ChewieProgressColors(
  486. playedColor: Colors.red,
  487. handleColor: Colors.blue,
  488. backgroundColor: Colors.grey,
  489. bufferedColor: Colors.lightGreen,
  490. ),
  491. ),
  492. ),
  493. ))
  494. : Container(child: null),
  495. ],
  496. ),
  497. ])),
  498. Positioned(
  499. bottom: 0,
  500. left: 0,
  501. child: widget.type != "3"
  502. ? Container(
  503. width: width,
  504. child: Row(children: <Widget>[
  505. Container(
  506. height: ScreenUtil().setWidth(70),
  507. width: width / 2,
  508. color: Colors.white,
  509. child: FlatButton(
  510. // padding: EdgeInsets.all(15.0),
  511. child: Text(
  512. "拒绝",
  513. style: TextStyle(
  514. fontSize: ScreenUtil().setSp(16)),
  515. ),
  516. textColor: Color(0xff222222),
  517. onPressed: () {
  518. // NavigatorUtils.push(context, BbsRouter.questionPay);
  519. orderRefuze();
  520. },
  521. ),
  522. ),
  523. Container(
  524. height: ScreenUtil().setWidth(70),
  525. width: width / 2,
  526. color: Color(0xff0388FD),
  527. child: FlatButton(
  528. // padding: EdgeInsets.all(15.0),
  529. child: Text(
  530. "接单",
  531. style: TextStyle(
  532. fontSize: ScreenUtil().setSp(16)),
  533. ),
  534. textColor: Colors.white,
  535. onPressed: () {
  536. // NavigatorUtils.push(context, BbsRouter.questionPay);
  537. orderReceiving();
  538. },
  539. ),
  540. ),
  541. ]))
  542. : Container(child: null))
  543. ])
  544. : Center(
  545. child: Text("正在加载..."),
  546. ),
  547. );
  548. }
  549. }
  550. class FadeRoute extends PageRouteBuilder {
  551. final Widget page;
  552. FadeRoute({this.page})
  553. : super(
  554. pageBuilder: (
  555. BuildContext context,
  556. Animation<double> animation,
  557. Animation<double> secondaryAnimation,
  558. ) =>
  559. page,
  560. transitionsBuilder: (
  561. BuildContext context,
  562. Animation<double> animation,
  563. Animation<double> secondaryAnimation,
  564. Widget child,
  565. ) =>
  566. FadeTransition(
  567. opacity: animation,
  568. child: child,
  569. ),
  570. );
  571. }