order_management_page.dart 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'dart:async';
  4. import 'order_management_page/order_detail_page.dart';
  5. import 'order_detail/order_detail.dart';
  6. import '../util/bluetooth_utils.dart';
  7. import '../util/session.dart';
  8. import '../showDialog.dart';
  9. import '../showAlert.dart';
  10. import '../util/models.dart';
  11. import '../util/api.dart';
  12. import '../util/util.dart';
  13. class OrderManagementPage extends StatefulWidget {
  14. final Widget child;
  15. OrderManagementPage({
  16. Key key,
  17. this.child
  18. }): super(key: key);
  19. _OrderManagementPageState createState() => _OrderManagementPageState();
  20. }
  21. class _OrderManagementPageState extends State < OrderManagementPage > with AutomaticKeepAliveClientMixin {
  22. @override
  23. Widget build(BuildContext context) {
  24. return Container(
  25. child: Scaffold(
  26. appBar: AppBar(
  27. title: Text('订单管理', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36)), ),
  28. centerTitle: true,
  29. backgroundColor: Color.fromRGBO(64, 98, 254, 1),
  30. ),
  31. body: Container(
  32. decoration: BoxDecoration(
  33. color: Color.fromRGBO(246, 246, 254, 1)
  34. ),
  35. child: QueryWidget()
  36. ),
  37. resizeToAvoidBottomPadding: false //键盘弹出,页面不跟随向上滑动,防止出现溢出错误
  38. )
  39. );
  40. }
  41. @override
  42. bool get wantKeepAlive => true;
  43. }
  44. class QueryWidget extends StatefulWidget { //搜索栏
  45. final Widget child;
  46. QueryWidget({
  47. Key key,
  48. this.child
  49. }): super(key: key);
  50. _QueryWidgetState createState() => _QueryWidgetState();
  51. }
  52. class _QueryWidgetState extends State < QueryWidget > {
  53. //单号的输入框控制器
  54. TextEditingController _orderController = TextEditingController();
  55. ScrollController _scrollController = ScrollController();
  56. GlobalKey _globalKey = GlobalKey(); //搜索栏key
  57. List < bool > statusList = [true, false, false];
  58. double inputPostX = 0;
  59. double inputPostY = 0;
  60. double inputWidth = 0;
  61. double inputHeight = 0;
  62. bool showStatus = true; //提示层显示状态
  63. String _orderNo = "";
  64. int orderStatus = 1; //0:代收单,1:待取件,2:运途中:已完成
  65. int page = 1;
  66. bool hasNextPage = true;
  67. BluetoothUtils bluetooth = BluetoothUtils();
  68. List < FromStatusGetOrderList > orderList = [];
  69. List likeOrderNoList = [];
  70. var timer;
  71. bool loadMoreStatus = true;
  72. @override
  73. void initState() {
  74. super.initState();
  75. switchOrderFromStatus(orderStatus, page);
  76. _scrollController.addListener(() {
  77. if (_scrollController.position.pixels == _scrollController.position.maxScrollExtent) {
  78. if (loadMoreStatus) {
  79. page = ++page;
  80. getMoreOrder(orderStatus, page);
  81. }
  82. }
  83. });
  84. }
  85. @override
  86. Widget build(BuildContext context) {
  87. return Stack(
  88. children: < Widget > [
  89. Container(
  90. child: Column(
  91. children: < Widget > [
  92. Container(
  93. color: Colors.white,
  94. height: ScreenUtil.getInstance().setHeight(222),
  95. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(20), ScreenUtil.getInstance().setWidth(20), ScreenUtil.getInstance().setWidth(20), 0),
  96. child: Column(
  97. children: < Widget > [
  98. Container(
  99. key: _globalKey,
  100. height: ScreenUtil.getInstance().setHeight(100),
  101. decoration: BoxDecoration(
  102. border: Border.all(color: Color.fromRGBO(204, 204, 204, 1), width: 1),
  103. borderRadius: BorderRadius.all(Radius.circular(5))
  104. ),
  105. child: Row(
  106. children: < Widget > [
  107. Expanded(
  108. child: TextField(
  109. controller: _orderController,
  110. keyboardType: TextInputType.number,
  111. autocorrect: true,
  112. decoration: InputDecoration(
  113. border: InputBorder.none,
  114. hintText: "输入运单号后6位查询物流",
  115. hintStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(26), color: Color.fromRGBO(155, 155, 155, 1)),
  116. contentPadding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), 0, ScreenUtil.getInstance().setWidth(30), 0)
  117. ),
  118. onTap: () {
  119. RenderObject inputObj = _globalKey.currentContext.findRenderObject();
  120. setState(() {
  121. inputWidth = inputObj.paintBounds.size.width;
  122. inputHeight = inputObj.paintBounds.size.height;
  123. inputPostX = inputObj.getTransformTo(null).getTranslation().x;
  124. inputPostY = ScreenUtil.getInstance().setWidth(20) + inputHeight;
  125. });
  126. },
  127. onChanged: ((value) {
  128. setState(() {
  129. _orderNo = value;
  130. });
  131. if (timer != null) {
  132. timer.cancel();
  133. }
  134. timer = Timer(Duration(milliseconds: 500), () {
  135. if (_orderNo.length >= 6) {
  136. orderNoLike(_orderNo, orderStatus).then((resp) {
  137. if (isNotError(context, resp) && this.mounted) {
  138. LikeOrderNo tempObj = LikeOrderNo.fromJson(resp.data);
  139. if (tempObj.data.length > 0) {
  140. setState(() {
  141. likeOrderNoList = tempObj.data;
  142. showStatus = false;
  143. });
  144. }
  145. }
  146. });
  147. } else {
  148. setState(() {
  149. showStatus = true;
  150. });
  151. }
  152. });
  153. }),
  154. onEditingComplete: () {
  155. FocusScope.of(context).requestFocus(FocusNode());
  156. setState(() {
  157. showStatus = true;
  158. });
  159. },
  160. ),
  161. ),
  162. IconButton(
  163. icon: Image.asset('lib/images/icon_saoyisao.png',
  164. width: ScreenUtil.getInstance().setWidth(38),
  165. height: ScreenUtil.getInstance().setHeight(36),
  166. ),
  167. onPressed: () {},
  168. ),
  169. GestureDetector(
  170. child: Container(
  171. width: ScreenUtil.getInstance().setWidth(120),
  172. decoration: BoxDecoration(
  173. border: Border(left: BorderSide.merge(BorderSide(color: Color.fromRGBO(204, 204, 204, 1), width: 1), BorderSide(color: Color.fromRGBO(204, 204, 204, 1), width: 0)), )
  174. ),
  175. child: Center(
  176. child: Text("查询", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(26), color: Color.fromRGBO(64, 98, 254, 1)), ),
  177. ),
  178. ),
  179. onTap: () {
  180. print("查询");
  181. }
  182. ),
  183. ],
  184. ),
  185. ),
  186. Container(
  187. height: ScreenUtil.getInstance().setHeight(100),
  188. child: Container(
  189. padding: EdgeInsets.only(top: ScreenUtil.getInstance().setHeight(25)),
  190. child: Row(
  191. mainAxisAlignment: MainAxisAlignment.spaceAround,
  192. children: < Widget > [
  193. GestureDetector(
  194. child: Container(
  195. height: ScreenUtil.getInstance().setHeight(80),
  196. decoration: BoxDecoration(
  197. border: statusList[0] ? Border(bottom: BorderSide.merge(BorderSide(color: Colors.black, width: 1), BorderSide(color: Colors.black, width: 0)), ) : Border()
  198. ),
  199. child: Center(
  200. child: Text("待取件", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: statusList[0] ? Colors.black : Color.fromRGBO(155, 155, 155, 1)), ),
  201. )
  202. ),
  203. onTap: () {
  204. if (statusList[0]) {
  205. return;
  206. } else {
  207. setState(() {
  208. statusList = [true, false, false];
  209. orderStatus = 1;
  210. });
  211. switchOrderFromStatus(orderStatus, page);
  212. }
  213. },
  214. ),
  215. GestureDetector(
  216. child: Container(
  217. height: ScreenUtil.getInstance().setHeight(80),
  218. decoration: BoxDecoration(
  219. border: statusList[1] ? Border(bottom: BorderSide.merge(BorderSide(color: Colors.black, width: 1), BorderSide(color: Colors.black, width: 0)), ) : Border()
  220. ),
  221. child: Center(
  222. child: Text("运途中", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: statusList[1] ? Colors.black : Color.fromRGBO(155, 155, 155, 1)), ),
  223. )
  224. ),
  225. onTap: () {
  226. if (statusList[1]) {
  227. return;
  228. } else {
  229. setState(() {
  230. statusList = [false, true, false];
  231. orderStatus = 2;
  232. });
  233. switchOrderFromStatus(orderStatus, page);
  234. }
  235. },
  236. ),
  237. GestureDetector(
  238. child: Container(
  239. height: ScreenUtil.getInstance().setHeight(80),
  240. decoration: BoxDecoration(
  241. border: statusList[2] ? Border(bottom: BorderSide.merge(BorderSide(color: Colors.black, width: 1), BorderSide(color: Colors.black, width: 0)), ) : Border()
  242. ),
  243. child: Center(
  244. child: Text("已完成", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: statusList[2] ? Colors.black : Color.fromRGBO(155, 155, 155, 1)), ),
  245. )
  246. ),
  247. onTap: () {
  248. if (statusList[2]) {
  249. return;
  250. } else {
  251. setState(() {
  252. statusList = [false, false, true];
  253. orderStatus = 3;
  254. });
  255. switchOrderFromStatus(orderStatus, page);
  256. }
  257. },
  258. ),
  259. ],
  260. )
  261. )
  262. ),
  263. ],
  264. )
  265. ),
  266. Expanded(
  267. child: Container(
  268. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(20), ScreenUtil.getInstance().setWidth(20), ScreenUtil.getInstance().setWidth(20), 0),
  269. child: orderList == null ? Center(
  270. child: _getMoreWidget()
  271. ) : orderList.length == 0 ?
  272. Center(
  273. child: Text('暂无订单'),
  274. ) :
  275. RefreshIndicator(
  276. onRefresh: refreshOrder,
  277. child: ListView.builder(
  278. physics: AlwaysScrollableScrollPhysics(),
  279. controller: _scrollController,
  280. itemCount: orderList.length + 1,
  281. itemBuilder: (BuildContext context, int index) {
  282. if (index < orderList.length) {
  283. return _cardWiget(orderList[index], index);
  284. }
  285. if (hasNextPage) {
  286. return _getMoreWidget();
  287. } else {
  288. return _noMoreWidegt();
  289. }
  290. },
  291. )
  292. )
  293. ),
  294. )
  295. ],
  296. )
  297. ),
  298. Positioned(
  299. left: inputPostX,
  300. top: inputPostY,
  301. child: Offstage(
  302. offstage: showStatus,
  303. child:
  304. Container(
  305. width: inputWidth,
  306. height: ScreenUtil.getInstance().setHeight(320),
  307. margin: EdgeInsets.only(top: ScreenUtil.getInstance().setHeight(1)),
  308. decoration: BoxDecoration(
  309. color: Color.fromRGBO(244, 248, 251, 1),
  310. border: Border.all(color: Color.fromRGBO(204, 204, 204, 1), width: 1),
  311. borderRadius: BorderRadius.all(Radius.circular(5))
  312. ),
  313. child: ListView.builder(
  314. itemCount: likeOrderNoList.length,
  315. itemBuilder: (BuildContext context, int index) {
  316. return InkWell(
  317. child: Padding(
  318. padding: EdgeInsets.all(10),
  319. child: Text(likeOrderNoList[index]),
  320. ),
  321. onTap: () {
  322. setState(() {
  323. page = 1;
  324. _orderNo = likeOrderNoList[index];
  325. });
  326. fromStatusGetOrderList(orderStatus, page, likeOrderNoList[index]).then((resp) {
  327. if (isNotError(context, resp) && this.mounted) {
  328. FromStatusGetOrderObj tempObj = FromStatusGetOrderObj.fromJson(resp.data);
  329. setState(() {
  330. orderList = tempObj.data.items;
  331. hasNextPage = tempObj.data.hasNextPage;
  332. });
  333. }
  334. });
  335. setState(() {
  336. _orderController.text = likeOrderNoList[index];
  337. showStatus = true;
  338. FocusScope.of(context).requestFocus(FocusNode());
  339. });
  340. },
  341. );
  342. },
  343. ),
  344. ),
  345. )
  346. )
  347. ],
  348. );
  349. }
  350. Widget _cardWiget(FromStatusGetOrderList obj, int index) {
  351. Map < int, String > statusMap = {
  352. 1: '待取货',
  353. 2: '运途中',
  354. 3: '已签收',
  355. 4: '已拒收',
  356. 5: '已作废',
  357. 6: '已取消'
  358. };
  359. return InkWell(
  360. child: Card(
  361. color: Colors.white,
  362. child: Container(
  363. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(20)),
  364. child: Column(
  365. children: < Widget > [
  366. Padding(
  367. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(30)),
  368. child: Row(
  369. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  370. children: < Widget > [
  371. Text('订单号:${obj.orderNo}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(102, 102, 102, 1)), ),
  372. Text('${statusMap[obj.orderStatus]}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(126, 211, 33, 1)), ),
  373. ],
  374. )
  375. ),
  376. Padding(
  377. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  378. child: Row(
  379. children: < Widget > [
  380. Text('${obj.sendCompanyName} --> ${obj.receiptCompanyName}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30)), ),
  381. ],
  382. )
  383. ),
  384. Padding(
  385. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(15)),
  386. child: Row(
  387. children: < Widget > [
  388. SizedBox(
  389. width: ScreenUtil.getInstance().setWidth(355),
  390. child: Text('货物名称:${obj.goods}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(155, 155, 155, 1)), ),
  391. ),
  392. Text('代收款:${obj.goodsAgencyFund/100}元', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(155, 155, 155, 1)), ),
  393. ],
  394. ),
  395. ),
  396. Padding(
  397. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(30)),
  398. child: Row(
  399. children: < Widget > [
  400. SizedBox(
  401. width: ScreenUtil.getInstance().setWidth(355),
  402. child: Text('货物件数:${obj.goodsQuantity}件', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(155, 155, 155, 1)), ),
  403. ),
  404. Text('运费:${obj.goodsFreight/100}元', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(155, 155, 155, 1)), ),
  405. ],
  406. ),
  407. ),
  408. Padding(
  409. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  410. child: Container(
  411. height: ScreenUtil.getInstance().setHeight(1),
  412. color: Color.fromRGBO(223, 223, 223, 1),
  413. ),
  414. ),
  415. orderStatus == 1 ? _status1Fun(obj, index) : orderStatus == 2 ? _status2Fun(obj, index) : _status3Fun(obj, index)
  416. ],
  417. ),
  418. )
  419. ),
  420. onTap: () {
  421. Navigator.push(
  422. context,
  423. MaterialPageRoute(
  424. builder: (BuildContext context) {
  425. return OrderDetailsPage(orderNo: obj.orderNo);
  426. })
  427. );
  428. },
  429. );
  430. }
  431. Widget _status1Fun(FromStatusGetOrderList obj, int index) {
  432. return Row(
  433. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  434. children: < Widget > [
  435. InkWell(
  436. child: Container(
  437. width: ScreenUtil.getInstance().setWidth(94),
  438. height: ScreenUtil.getInstance().setHeight(48),
  439. decoration: BoxDecoration(
  440. color: Color.fromRGBO(239, 243, 249, 1),
  441. borderRadius: BorderRadius.all(Radius.circular(4.0))
  442. ),
  443. child: Center(
  444. child: Text('作废', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  445. ),
  446. ),
  447. onTap: () {
  448. showDialog < Null > (
  449. context: context, //BuildContext对象
  450. barrierDismissible: false,
  451. builder: (BuildContext context) {
  452. return new LoadingDialog( //调用对话框
  453. text: '是否确认作废', childCallback: (val) {
  454. if (val) {
  455. myUpdataOrder(obj.orderNo, 5, index);
  456. } else {
  457. return;
  458. }
  459. },
  460. );
  461. });
  462. print("作废");
  463. },
  464. ),
  465. InkWell(
  466. child: Container(
  467. width: ScreenUtil.getInstance().setWidth(94),
  468. height: ScreenUtil.getInstance().setHeight(48),
  469. decoration: BoxDecoration(
  470. color: Color.fromRGBO(239, 243, 249, 1),
  471. borderRadius: BorderRadius.all(Radius.circular(4.0))
  472. ),
  473. child: Center(
  474. child: Text('寄件', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  475. ),
  476. ),
  477. onTap: () {
  478. showDialog < Null > (
  479. context: context, //BuildContext对象
  480. barrierDismissible: false,
  481. builder: (BuildContext context) {
  482. return new LoadingDialog( //调用对话框
  483. text: '是否确认寄件', childCallback: (val) {
  484. if (val) {
  485. Navigator.push(
  486. context,
  487. MaterialPageRoute(
  488. builder: (BuildContext context) {
  489. return OrderDetailPage(orderNo: obj.orderNo);
  490. })
  491. ).then((resp) {
  492. if (resp == true) {
  493. deleteOrder(index);
  494. }
  495. });
  496. } else {
  497. return;
  498. }
  499. },
  500. );
  501. });
  502. print("寄件");
  503. },
  504. ),
  505. ],
  506. );
  507. }
  508. Widget _status2Fun(FromStatusGetOrderList obj, int index) {
  509. return Row(
  510. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  511. children: < Widget > [
  512. InkWell(
  513. child: Container(
  514. width: ScreenUtil.getInstance().setWidth(94),
  515. height: ScreenUtil.getInstance().setHeight(48),
  516. decoration: BoxDecoration(
  517. color: Color.fromRGBO(239, 243, 249, 1),
  518. borderRadius: BorderRadius.all(Radius.circular(4.0))
  519. ),
  520. child: Center(
  521. child: Text('作废', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  522. ),
  523. ),
  524. onTap: () {
  525. showDialog < Null > (
  526. context: context, //BuildContext对象
  527. barrierDismissible: false,
  528. builder: (BuildContext context) {
  529. return new LoadingDialog( //调用对话框
  530. text: '是否确认作废', childCallback: (val) {
  531. if (val) {
  532. myUpdataOrder(obj.orderNo, 5, index);
  533. } else {
  534. return;
  535. }
  536. },
  537. );
  538. });
  539. print("作废");
  540. },
  541. ),
  542. InkWell(
  543. child: Container(
  544. width: ScreenUtil.getInstance().setWidth(94),
  545. height: ScreenUtil.getInstance().setHeight(48),
  546. decoration: BoxDecoration(
  547. color: Color.fromRGBO(239, 243, 249, 1),
  548. borderRadius: BorderRadius.all(Radius.circular(4.0))
  549. ),
  550. child: Center(
  551. child: Text('拒收', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  552. ),
  553. ),
  554. onTap: () {
  555. showDialog < Null > (
  556. context: context, //BuildContext对象
  557. barrierDismissible: false,
  558. builder: (BuildContext context) {
  559. return new LoadingDialog( //调用对话框
  560. text: '是否确认拒收', childCallback: (val) {
  561. if (val) {
  562. myUpdataOrder(obj.orderNo, 4, index);
  563. } else {
  564. return;
  565. }
  566. },
  567. );
  568. });
  569. print("拒收");
  570. },
  571. ),
  572. InkWell(
  573. child: Container(
  574. width: ScreenUtil.getInstance().setWidth(94),
  575. height: ScreenUtil.getInstance().setHeight(48),
  576. decoration: BoxDecoration(
  577. color: Color.fromRGBO(239, 243, 249, 1),
  578. borderRadius: BorderRadius.all(Radius.circular(4.0))
  579. ),
  580. child: Center(
  581. child: Text('签收', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  582. ),
  583. ),
  584. onTap: () {
  585. showDialog < Null > (
  586. context: context, //BuildContext对象
  587. barrierDismissible: false,
  588. builder: (BuildContext context) {
  589. return new LoadingDialog( //调用对话框
  590. text: '是否确认签收', childCallback: (val) {
  591. if (val) {
  592. myUpdataOrder(obj.orderNo, 3, index);
  593. } else {
  594. return;
  595. }
  596. },
  597. );
  598. });
  599. print("签收");
  600. },
  601. ),
  602. InkWell(
  603. child: Container(
  604. width: ScreenUtil.getInstance().setWidth(94),
  605. height: ScreenUtil.getInstance().setHeight(48),
  606. decoration: BoxDecoration(
  607. color: Color.fromRGBO(239, 243, 249, 1),
  608. borderRadius: BorderRadius.all(Radius.circular(4.0))
  609. ),
  610. child: Center(
  611. child: Text('改单', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  612. ),
  613. ),
  614. onTap: () {
  615. showDialog < Null > (
  616. context: context, //BuildContext对象
  617. barrierDismissible: false,
  618. builder: (BuildContext context) {
  619. return new LoadingDialog( //调用对话框
  620. text: '是否确认改单', childCallback: (val) {
  621. if (val) {
  622. Navigator.push(
  623. context,
  624. MaterialPageRoute(
  625. builder: (BuildContext context) {
  626. return OrderDetailPage(orderNo: obj.orderNo);
  627. })
  628. ).then((resp) {
  629. if (resp == true) {
  630. switchOrderFromStatus(orderStatus, page);
  631. }
  632. });
  633. } else {
  634. return;
  635. }
  636. },
  637. );
  638. });
  639. print("改单");
  640. },
  641. ),
  642. InkWell(
  643. child: Container(
  644. width: ScreenUtil.getInstance().setWidth(94),
  645. height: ScreenUtil.getInstance().setHeight(48),
  646. decoration: BoxDecoration(
  647. color: Color.fromRGBO(239, 243, 249, 1),
  648. borderRadius: BorderRadius.all(Radius.circular(4.0))
  649. ),
  650. child: Center(
  651. child: Text('打印', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  652. ),
  653. ),
  654. onTap: () {
  655. showDialog < Null > (
  656. context: context, //BuildContext对象
  657. barrierDismissible: false,
  658. builder: (BuildContext context) {
  659. return new LoadingDialog( //调用对话框
  660. text: '是否确认打印', childCallback: (val) {
  661. if (val) {
  662. checkBlueToothAndPrintOrder(obj);
  663. } else {
  664. return;
  665. }
  666. },
  667. );
  668. });
  669. print("打印");
  670. },
  671. ),
  672. ],
  673. );
  674. }
  675. Widget _status3Fun(FromStatusGetOrderList obj, int index) {
  676. return Row(
  677. mainAxisAlignment: MainAxisAlignment.end,
  678. children: < Widget > [
  679. InkWell(
  680. child: Container(
  681. width: ScreenUtil.getInstance().setWidth(94),
  682. height: ScreenUtil.getInstance().setHeight(48),
  683. decoration: BoxDecoration(
  684. color: Color.fromRGBO(239, 243, 249, 1),
  685. borderRadius: BorderRadius.all(Radius.circular(4.0))
  686. ),
  687. child: Center(
  688. child: Text('打印', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  689. ),
  690. ),
  691. onTap: () {
  692. showDialog < Null > (
  693. context: context, //BuildContext对象
  694. barrierDismissible: false,
  695. builder: (BuildContext context) {
  696. return new LoadingDialog( //调用对话框
  697. text: '是否确认打印', childCallback: (val) {
  698. if (val) {
  699. checkBlueToothAndPrintOrder(obj);
  700. } else {
  701. return;
  702. }
  703. },
  704. );
  705. });
  706. print("打印");
  707. },
  708. ),
  709. ],
  710. );
  711. }
  712. Widget _getMoreWidget() {
  713. return Center(
  714. child: Padding(
  715. padding: EdgeInsets.all(10.0),
  716. child: Row(
  717. mainAxisAlignment: MainAxisAlignment.center,
  718. crossAxisAlignment: CrossAxisAlignment.center,
  719. children: < Widget > [
  720. Text(
  721. '加载中...',
  722. style: TextStyle(fontSize: 16.0),
  723. ),
  724. Container(
  725. width: ScreenUtil.getInstance().setWidth(50),
  726. height: ScreenUtil.getInstance().setHeight(50),
  727. child: CircularProgressIndicator()
  728. )
  729. ],
  730. ),
  731. ),
  732. );
  733. }
  734. Widget _noMoreWidegt() {
  735. return Center(
  736. child: Padding(
  737. padding: EdgeInsets.all(10.0),
  738. child: Text(
  739. '没有更多数据了...',
  740. style: TextStyle(fontSize: 16.0),
  741. ),
  742. ),
  743. );
  744. }
  745. switchOrderFromStatus(int orderStatus, int page) {
  746. setState(() {
  747. orderList = null;
  748. });
  749. page = 1;
  750. fromStatusGetOrderList(orderStatus, page, _orderNo).then((resp) {
  751. if (isNotError(context, resp) && this.mounted) {
  752. FromStatusGetOrderObj tempObj = FromStatusGetOrderObj.fromJson(resp.data);
  753. setState(() {
  754. orderList = tempObj.data.items;
  755. hasNextPage = tempObj.data.hasNextPage;
  756. });
  757. }
  758. });
  759. }
  760. getMoreOrder(int orderStatus, int page) {
  761. if (!hasNextPage) {
  762. return;
  763. }
  764. loadMoreStatus = false;
  765. fromStatusGetOrderList(orderStatus, page, _orderNo).then((resp) {
  766. if (isNotError(context, resp) && this.mounted) {
  767. FromStatusGetOrderObj tempObj = FromStatusGetOrderObj.fromJson(resp.data);
  768. setState(() {
  769. orderList.addAll(tempObj.data.items);
  770. hasNextPage = tempObj.data.hasNextPage;
  771. });
  772. loadMoreStatus = true;
  773. } else {
  774. loadMoreStatus = true;
  775. }
  776. });
  777. }
  778. deleteOrder(int index) {
  779. setState(() {
  780. orderList.removeAt(index);
  781. });
  782. if (orderList.length < 4) {
  783. if (hasNextPage) {
  784. setState(() {
  785. page = ++page;
  786. });
  787. getMoreOrder(orderStatus, page);
  788. }
  789. }
  790. }
  791. myUpdataOrder(String myOrderNo, int myOrderStatus, int index) {
  792. updataOrderStatus(myOrderNo, myOrderStatus).then((resp) {
  793. if (isNotError(context, resp) && this.mounted) {
  794. deleteOrder(index);
  795. }
  796. });
  797. }
  798. Future refreshOrder() async {
  799. page = 1;
  800. await fromStatusGetOrderList(orderStatus, page, _orderNo).then((resp) {
  801. if (isNotError(context, resp) && this.mounted) {
  802. FromStatusGetOrderObj tempObj = FromStatusGetOrderObj.fromJson(resp.data);
  803. setState(() {
  804. orderList = tempObj.data.items;
  805. hasNextPage = tempObj.data.hasNextPage;
  806. });
  807. }
  808. });
  809. }
  810. void checkBlueToothAndPrintOrder(FromStatusGetOrderList obj){
  811. bluetooth.isBTDevice().then((resp){
  812. if(resp){
  813. bluetooth.isEnableBluetooth().then((resp){
  814. if(resp){
  815. getOrderDetail(obj.orderNo).then((resp){
  816. if(isNotError(context, resp) && this.mounted){
  817. OrderDetailData data = OrderDetailObj.fromJson(resp.data).data;
  818. getKey('printType').then((printType){
  819. getKey('stationName').then((stationName){
  820. getKey('nickName').then((nickName){
  821. double goodsYs = (data.goodsFreight/100)+(data.goodsAgencyFund/100);
  822. String nowDate = fromatDate( DateTime.now().millisecondsSinceEpoch);//打印时间
  823. String createTime = fromatDate(data.createTime);
  824. double goodsAgencyFunds = data.goodsAgencyFund/100;
  825. double goodsDFreight = data.goodsPaymentMethod==1?data.goodsFreight/100:0;
  826. double goodsXFreight = data.goodsPaymentMethod==2?data.goodsFreight/100:0;
  827. String receiptAddress = data.receiptCompanyAddress.length>10?data.receiptCompanyAddress.substring(0,10):data.receiptCompanyAddress;
  828. Map<String, String> pum = {
  829. "[logisticsNo]": "${data.orderNo ?? ''}",
  830. "[createTime]": "$createTime",
  831. "[sendStationName]": "$stationName",
  832. "[dealerCode]": "${data.sendCompanyCode ?? ''}",
  833. "[dealerName]": "${data.sendCompanyName}",
  834. "[dealerTel]": "${data.sendCompanyPhone ?? ''}",
  835. "[repairName]": "${data.receiptCompanyName ?? ''}",
  836. "[repairTel]": "${data.receiptCompanyPhone ?? ''}",
  837. "[endStationName]": "${data.receiptStationName}",
  838. "[goodsLineCode]": "${data.lineCode ?? ''}",
  839. "[goodsLine]": "${data.lineName ?? ''}",
  840. "[repairAddress]": "${receiptAddress?? ''}",
  841. "[goodsQuantity]": "${data.goodsQuantity ?? ''}",
  842. "[goodsInsurance]": "${data.goodsInsurance ?? ''}",
  843. "[goodsFlatCost]": "${data.goodsFlatCost ?? ''}",
  844. // 到付 现付 金额
  845. "[goodsDFreight]": "$goodsDFreight",
  846. "[goodsXFreight]": "$goodsXFreight",
  847. "[goodsAgencyFund]": "$goodsAgencyFunds",
  848. "[goodsYs]": "$goodsYs",
  849. "[dealerBankAccount]": "${data.sendCompanyBankCard ?? ''}",
  850. "[goodsRemark]": "${data.memo ?? ''}",
  851. "[realName]": "${nickName?? ''}",
  852. "[currentTime]": "$nowDate",
  853. "[currentGoodNumber]": "1/1",
  854. };
  855. bluetooth.printOrder(pum, int.parse(printType)).then((value){
  856. if(value==null){
  857. showDialog <Null> (
  858. context: context,
  859. barrierDismissible: false,
  860. builder: (BuildContext context) {
  861. return MyAlertDialog(text: '未连接打印机',childCallback:(val){});
  862. }
  863. );
  864. }
  865. });
  866. });
  867. });
  868. });
  869. }
  870. });
  871. }else{
  872. showDialog <Null> (
  873. context: context,
  874. barrierDismissible: false,
  875. builder: (BuildContext context) {
  876. return MyAlertDialog(text: '请打开蓝牙并连接打印机',childCallback:(val){});
  877. }
  878. );
  879. }
  880. });
  881. }else{
  882. showDialog <Null> (
  883. context: context,
  884. barrierDismissible: false,
  885. builder: (BuildContext context) {
  886. return MyAlertDialog(text: '当前设备不支持蓝牙',childCallback:(val){});
  887. }
  888. );
  889. }
  890. });
  891. }
  892. }