order_management_page.dart 39 KB

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