order_management_page.dart 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  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. InkWell(
  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. InkWell(
  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. InkWell(
  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 Card(
  365. color: Colors.white,
  366. child: Container(
  367. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(20)),
  368. child: Column(
  369. children: < Widget > [
  370. InkWell(
  371. child: Column(
  372. children: <Widget>[
  373. Padding(
  374. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(30)),
  375. child: Row(
  376. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  377. children: < Widget > [
  378. Text('订单号:${obj.orderNo}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(102, 102, 102, 1)), ),
  379. Text('${statusMap[obj.orderStatus]}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color:obj.orderStatus==5?Colors.red:Color.fromRGBO(126, 211, 33, 1)), ),
  380. ],
  381. )
  382. ),
  383. Padding(
  384. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  385. child: Row(
  386. children: < Widget > [
  387. Text('${obj.sendCompanyName} --> ${obj.receiptCompanyName}',
  388. overflow: TextOverflow.ellipsis,style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30)), ),
  389. ],
  390. )
  391. ),
  392. Padding(
  393. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(15)),
  394. child: Row(
  395. children: < Widget > [
  396. SizedBox(
  397. width: ScreenUtil.getInstance().setWidth(355),
  398. child: Text('货物名称:${obj.goods}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(155, 155, 155, 1)), ),
  399. ),
  400. Text('代收款:${obj.goodsAgencyFund/100}元', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(155, 155, 155, 1)), ),
  401. ],
  402. ),
  403. ),
  404. Padding(
  405. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(30)),
  406. child: Row(
  407. children: < Widget > [
  408. SizedBox(
  409. width: ScreenUtil.getInstance().setWidth(355),
  410. child: Text('货物件数:${obj.goodsQuantity}件', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(155, 155, 155, 1)), ),
  411. ),
  412. Text('运费:${obj.goodsFreight/100}元', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(155, 155, 155, 1)), ),
  413. ],
  414. ),
  415. ),
  416. Padding(
  417. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  418. child: Container(
  419. height: ScreenUtil.getInstance().setHeight(1),
  420. color: Color.fromRGBO(223, 223, 223, 1),
  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. orderStatus == 1 ? _status1Fun(obj, index) : orderStatus == 2 ? _status2Fun(obj, index) : _status3Fun(obj, index)
  436. ],
  437. ),
  438. )
  439. );
  440. }
  441. Widget _status1Fun(FromStatusGetOrderList obj, int index) {
  442. return Row(
  443. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  444. children: < Widget > [
  445. InkWell(
  446. child: Container(
  447. width: ScreenUtil.getInstance().setWidth(94),
  448. height: ScreenUtil.getInstance().setHeight(48),
  449. decoration: BoxDecoration(
  450. color: Color.fromRGBO(239, 243, 249, 1),
  451. borderRadius: BorderRadius.all(Radius.circular(4.0))
  452. ),
  453. child: Center(
  454. child: Text('作废', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  455. ),
  456. ),
  457. onTap: () {
  458. showDialog < Null > (
  459. context: context, //BuildContext对象
  460. barrierDismissible: false,
  461. builder: (BuildContext context) {
  462. return new LoadingDialog( //调用对话框
  463. text: '是否确认作废', childCallback: (val) {
  464. if (val) {
  465. myUpdataOrder(obj.orderNo, 5, index);
  466. } else {
  467. return;
  468. }
  469. },
  470. );
  471. });
  472. print("作废");
  473. },
  474. ),
  475. InkWell(
  476. child: Container(
  477. width: ScreenUtil.getInstance().setWidth(94),
  478. height: ScreenUtil.getInstance().setHeight(48),
  479. decoration: BoxDecoration(
  480. color: Color.fromRGBO(239, 243, 249, 1),
  481. borderRadius: BorderRadius.all(Radius.circular(4.0))
  482. ),
  483. child: Center(
  484. child: Text('寄件', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  485. ),
  486. ),
  487. onTap: () {
  488. showDialog < Null > (
  489. context: context, //BuildContext对象
  490. barrierDismissible: false,
  491. builder: (BuildContext context) {
  492. return new LoadingDialog( //调用对话框
  493. text: '是否确认寄件', childCallback: (val) {
  494. if (val) {
  495. Navigator.push(
  496. context,
  497. MaterialPageRoute(
  498. builder: (BuildContext context) {
  499. return OrderDetailPage(orderNo: obj.orderNo,status: '寄件',);
  500. })
  501. ).then((resp) {
  502. if (resp == true) {
  503. deleteOrder(index);
  504. }
  505. });
  506. } else {
  507. return;
  508. }
  509. },
  510. );
  511. });
  512. print("寄件");
  513. },
  514. ),
  515. ],
  516. );
  517. }
  518. Widget _status2Fun(FromStatusGetOrderList obj, int index) {
  519. return Row(
  520. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  521. children: < Widget > [
  522. InkWell(
  523. child: Container(
  524. width: ScreenUtil.getInstance().setWidth(94),
  525. height: ScreenUtil.getInstance().setHeight(48),
  526. decoration: BoxDecoration(
  527. color: Color.fromRGBO(239, 243, 249, 1),
  528. borderRadius: BorderRadius.all(Radius.circular(4.0))
  529. ),
  530. child: Center(
  531. child: Text('作废', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  532. ),
  533. ),
  534. onTap: () {
  535. showDialog < Null > (
  536. context: context, //BuildContext对象
  537. barrierDismissible: false,
  538. builder: (BuildContext context) {
  539. return new LoadingDialog( //调用对话框
  540. text: '是否确认作废', childCallback: (val) {
  541. if (val) {
  542. myUpdataOrder(obj.orderNo, 5, index);
  543. } else {
  544. return;
  545. }
  546. },
  547. );
  548. });
  549. print("作废");
  550. },
  551. ),
  552. InkWell(
  553. child: Container(
  554. width: ScreenUtil.getInstance().setWidth(94),
  555. height: ScreenUtil.getInstance().setHeight(48),
  556. decoration: BoxDecoration(
  557. color: Color.fromRGBO(239, 243, 249, 1),
  558. borderRadius: BorderRadius.all(Radius.circular(4.0))
  559. ),
  560. child: Center(
  561. child: Text('拒收', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  562. ),
  563. ),
  564. onTap: () {
  565. showDialog < Null > (
  566. context: context, //BuildContext对象
  567. barrierDismissible: false,
  568. builder: (BuildContext context) {
  569. return new LoadingDialog( //调用对话框
  570. text: '是否确认拒收', childCallback: (val) {
  571. if (val) {
  572. myUpdataOrder(obj.orderNo, 4, index);
  573. } else {
  574. return;
  575. }
  576. },
  577. );
  578. });
  579. print("拒收");
  580. },
  581. ),
  582. InkWell(
  583. child: Container(
  584. width: ScreenUtil.getInstance().setWidth(94),
  585. height: ScreenUtil.getInstance().setHeight(48),
  586. decoration: BoxDecoration(
  587. color: Color.fromRGBO(239, 243, 249, 1),
  588. borderRadius: BorderRadius.all(Radius.circular(4.0))
  589. ),
  590. child: Center(
  591. child: Text('签收', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  592. ),
  593. ),
  594. onTap: () {
  595. showDialog < Null > (
  596. context: context, //BuildContext对象
  597. barrierDismissible: false,
  598. builder: (BuildContext context) {
  599. return new LoadingDialog( //调用对话框
  600. text: '是否确认签收', childCallback: (val) {
  601. if (val) {
  602. myUpdataOrder(obj.orderNo, 3, index);
  603. } else {
  604. return;
  605. }
  606. },
  607. );
  608. });
  609. print("签收");
  610. },
  611. ),
  612. InkWell(
  613. child: Container(
  614. width: ScreenUtil.getInstance().setWidth(94),
  615. height: ScreenUtil.getInstance().setHeight(48),
  616. decoration: BoxDecoration(
  617. color: Color.fromRGBO(239, 243, 249, 1),
  618. borderRadius: BorderRadius.all(Radius.circular(4.0))
  619. ),
  620. child: Center(
  621. child: Text('改单', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  622. ),
  623. ),
  624. onTap: () {
  625. showDialog < Null > (
  626. context: context, //BuildContext对象
  627. barrierDismissible: false,
  628. builder: (BuildContext context) {
  629. return new LoadingDialog( //调用对话框
  630. text: '是否确认改单', childCallback: (val) {
  631. if (val) {
  632. Navigator.push(
  633. context,
  634. MaterialPageRoute(
  635. builder: (BuildContext context) {
  636. return OrderDetailPage(orderNo: obj.orderNo,status: '改单',);
  637. })
  638. ).then((resp) {
  639. if (resp == true) {
  640. switchOrderFromStatus(orderStatus, page);
  641. }
  642. });
  643. } else {
  644. return;
  645. }
  646. },
  647. );
  648. });
  649. print("改单");
  650. },
  651. ),
  652. InkWell(
  653. child: Container(
  654. width: ScreenUtil.getInstance().setWidth(94),
  655. height: ScreenUtil.getInstance().setHeight(48),
  656. decoration: BoxDecoration(
  657. color: Color.fromRGBO(239, 243, 249, 1),
  658. borderRadius: BorderRadius.all(Radius.circular(4.0))
  659. ),
  660. child: Center(
  661. child: Text('打印', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  662. ),
  663. ),
  664. onTap: () {
  665. showDialog < Null > (
  666. context: context, //BuildContext对象
  667. barrierDismissible: false,
  668. builder: (BuildContext context) {
  669. return new LoadingDialog( //调用对话框
  670. text: '是否确认打印', childCallback: (val) {
  671. if (val) {
  672. checkBlueToothAndPrintOrder(obj);
  673. } else {
  674. return;
  675. }
  676. },
  677. );
  678. });
  679. print("打印");
  680. },
  681. ),
  682. ],
  683. );
  684. }
  685. Widget _status3Fun(FromStatusGetOrderList obj, int index) {
  686. return Row(
  687. mainAxisAlignment: MainAxisAlignment.end,
  688. children: < Widget > [
  689. InkWell(
  690. child: Container(
  691. width: ScreenUtil.getInstance().setWidth(94),
  692. height: ScreenUtil.getInstance().setHeight(48),
  693. decoration: BoxDecoration(
  694. color: Color.fromRGBO(239, 243, 249, 1),
  695. borderRadius: BorderRadius.all(Radius.circular(4.0))
  696. ),
  697. child: Center(
  698. child: Text('打印', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  699. ),
  700. ),
  701. onTap: () {
  702. showDialog < Null > (
  703. context: context, //BuildContext对象
  704. barrierDismissible: false,
  705. builder: (BuildContext context) {
  706. return new LoadingDialog( //调用对话框
  707. text: '是否确认打印', childCallback: (val) {
  708. if (val) {
  709. checkBlueToothAndPrintOrder(obj);
  710. } else {
  711. return;
  712. }
  713. },
  714. );
  715. });
  716. print("打印");
  717. },
  718. ),
  719. ],
  720. );
  721. }
  722. Widget _getMoreWidget() {
  723. return Center(
  724. child: Padding(
  725. padding: EdgeInsets.all(10.0),
  726. child: Row(
  727. mainAxisAlignment: MainAxisAlignment.center,
  728. crossAxisAlignment: CrossAxisAlignment.center,
  729. children: < Widget > [
  730. Text(
  731. '加载中...',
  732. style: TextStyle(fontSize: 16.0),
  733. ),
  734. Container(
  735. width: ScreenUtil.getInstance().setWidth(50),
  736. height: ScreenUtil.getInstance().setHeight(50),
  737. child: CircularProgressIndicator()
  738. )
  739. ],
  740. ),
  741. ),
  742. );
  743. }
  744. Widget _noMoreWidegt() {
  745. return Center(
  746. child: Padding(
  747. padding: EdgeInsets.all(10.0),
  748. child: Text(
  749. '没有更多数据了...',
  750. style: TextStyle(fontSize: 16.0),
  751. ),
  752. ),
  753. );
  754. }
  755. switchOrderFromStatus(int orderStatus, int page) {
  756. setState(() {
  757. orderList = null;
  758. });
  759. page = 1;
  760. fromStatusGetOrderList(orderStatus, page, _orderNo).then((resp) {
  761. if (isNotError(context, resp) && this.mounted) {
  762. FromStatusGetOrderObj tempObj = FromStatusGetOrderObj.fromJson(resp.data);
  763. setState(() {
  764. orderList = tempObj.data.items;
  765. hasNextPage = tempObj.data.hasNextPage;
  766. });
  767. }
  768. });
  769. }
  770. //扫描切换
  771. scanSearchOrder(){
  772. setState(() {
  773. orderList = [];
  774. });
  775. page = 1;
  776. getOrderDetail(_orderNo).then((resp) {
  777. if (isNotError(context, resp) && this.mounted) {
  778. OrderDetailData tempObj = OrderDetailObj.fromJson(resp.data).data;
  779. var tempJson = {
  780. "goods": tempObj.goods,
  781. "goodsAgencyFund": tempObj.goodsAgencyFund,
  782. "goodsFreight": tempObj.goodsFreight,
  783. "goodsQuantity": tempObj.goodsQuantity,
  784. "orderNo": tempObj.orderNo,
  785. "orderStatus": tempObj.orderStatus,
  786. "receiptCompanyName": tempObj.receiptCompanyName,
  787. "sendCompanyName": tempObj.sendCompanyName
  788. };
  789. FromStatusGetOrderList obj = FromStatusGetOrderList.fromJson(tempJson);
  790. if(obj.orderStatus==2){
  791. setState(() {
  792. statusList = [false, true, false];
  793. orderStatus = 2;
  794. });
  795. }else if(obj.orderStatus>=3){
  796. setState(() {
  797. statusList = [false, false, true];
  798. orderStatus = 3;
  799. });
  800. }
  801. setState(() {
  802. orderList.add(obj);
  803. hasNextPage = false;
  804. });
  805. }
  806. });
  807. }
  808. getMoreOrder(int orderStatus, int page) {
  809. if (!hasNextPage) {
  810. return;
  811. }
  812. loadMoreStatus = false;
  813. fromStatusGetOrderList(orderStatus, page, _orderNo).then((resp) {
  814. if (isNotError(context, resp) && this.mounted) {
  815. FromStatusGetOrderObj tempObj = FromStatusGetOrderObj.fromJson(resp.data);
  816. setState(() {
  817. orderList.addAll(tempObj.data.items);
  818. hasNextPage = tempObj.data.hasNextPage;
  819. });
  820. loadMoreStatus = true;
  821. } else {
  822. loadMoreStatus = true;
  823. }
  824. });
  825. }
  826. deleteOrder(int index) {
  827. setState(() {
  828. orderList.removeAt(index);
  829. });
  830. if (orderList.length < 4) {
  831. if (hasNextPage) {
  832. setState(() {
  833. page = ++page;
  834. });
  835. getMoreOrder(orderStatus, page);
  836. }
  837. }
  838. }
  839. myUpdataOrder(String myOrderNo, int myOrderStatus, int index) {
  840. updataOrderStatus(myOrderNo, myOrderStatus).then((resp) {
  841. if (isNotError(context, resp) && this.mounted) {
  842. deleteOrder(index);
  843. }else{
  844. OrderReception obj = OrderReception.fromJson(resp.data);
  845. showDialog < Null > (
  846. context: context, //BuildContext对象
  847. barrierDismissible: false,
  848. builder: (BuildContext context) {
  849. return new LoadingDialog( //调用对话框
  850. text: obj.msg, childCallback: (val) {
  851. },
  852. );
  853. });
  854. }
  855. });
  856. }
  857. Future refreshOrder() async {
  858. page = 1;
  859. await fromStatusGetOrderList(orderStatus, page, _orderNo).then((resp) {
  860. if (isNotError(context, resp) && this.mounted) {
  861. FromStatusGetOrderObj tempObj = FromStatusGetOrderObj.fromJson(resp.data);
  862. setState(() {
  863. orderList = tempObj.data.items;
  864. hasNextPage = tempObj.data.hasNextPage;
  865. });
  866. }
  867. });
  868. }
  869. void checkBlueToothAndPrintOrder(FromStatusGetOrderList obj){
  870. bluetooth.isBTDevice().then((resp){
  871. if(resp){
  872. bluetooth.isEnableBluetooth().then((resp){
  873. if(resp){
  874. getOrderDetail(obj.orderNo).then((resp){
  875. if(isNotError(context, resp) && this.mounted){
  876. OrderDetailData data = OrderDetailObj.fromJson(resp.data).data;
  877. getKey('printType').then((printType){
  878. getKey('stationName').then((stationName){
  879. getKey('nickName').then((nickName){
  880. getKey('companyName').then((companyName){
  881. getKey('companyCustomerPhone').then((companyCustomerPhone){
  882. double goodsYs = data.goodsPaymentMethod==2?(data.goodsFreight/100)+(data.goodsAgencyFund/100):data.goodsAgencyFund/100;
  883. String nowDate = fromatDate( DateTime.now().millisecondsSinceEpoch);//打印时间
  884. String createTime = fromatDate(data.createTime);
  885. double goodsAgencyFunds = data.goodsAgencyFund/100;
  886. double goodsDFreight = data.goodsPaymentMethod==2?data.goodsFreight/100:0;
  887. double goodsXFreight = data.goodsPaymentMethod==1?data.goodsFreight/100:0;
  888. String receiptAddress = data.receiptCompanyAddress.length>10?data.receiptCompanyAddress.substring(0,10):data.receiptCompanyAddress;
  889. Map<String, String> pum = {
  890. "[logisticsNo]": "${data.orderNo ?? ''}",
  891. "[createTime]": "$createTime",
  892. "[sendStationName]": "$stationName",
  893. "[dealerCode]": "${data.sendCompanyCode ?? ''}",
  894. "[dealerName]": "${data.sendCompanyName}",
  895. "[dealerTel]": "${data.sendCompanyPhone ?? ''}",
  896. "[repairName]": "${data.receiptCompanyName ?? ''}",
  897. "[repairTel]": "${data.receiptCompanyPhone ?? ''}",
  898. "[endStationName]": "${data.receiptStationName}",
  899. "[goodsLineCode]": "${data.lineCode ?? ''}",
  900. "[goodsLine]": "${data.lineName ?? ''}",
  901. "[repairAddress]": "${receiptAddress?? ''}",
  902. "[goodsQuantity]": "${data.goodsQuantity ?? ''}",
  903. "[goodsInsurance]": "${data.goodsInsurance ?? ''}",
  904. "[goodsFlatCost]": "${data.goodsFlatCost ?? ''}",
  905. // 到付 现付 金额
  906. "[goodsDFreight]": "$goodsDFreight",
  907. "[goodsXFreight]": "$goodsXFreight",
  908. "[goodsAgencyFund]": "$goodsAgencyFunds",
  909. "[goodsYs]": "$goodsYs",
  910. "[dealerBankAccount]": "${data.sendCompanyBankCard ?? ''}",
  911. "[goodsRemark]": "${data.memo ?? ''}",
  912. "[realName]": "${nickName?? ''}",
  913. "[currentTime]": "$nowDate",
  914. "[currentGoodNumber]": "1/1",
  915. "[companyCustomerPhone]":"$companyCustomerPhone",
  916. "[companyName]":"$companyName"
  917. };
  918. bluetooth.printOrder(pum, int.parse(printType)).then((value){
  919. if(value==null){
  920. showDialog <Null> (
  921. context: context,
  922. barrierDismissible: false,
  923. builder: (BuildContext context) {
  924. return MyAlertDialog(text: '未连接打印机',childCallback:(val){});
  925. }
  926. );
  927. }
  928. });
  929. });
  930. });
  931. });
  932. });
  933. });
  934. }
  935. });
  936. }else{
  937. showDialog <Null> (
  938. context: context,
  939. barrierDismissible: false,
  940. builder: (BuildContext context) {
  941. return MyAlertDialog(text: '请打开蓝牙并连接打印机',childCallback:(val){});
  942. }
  943. );
  944. }
  945. });
  946. }else{
  947. showDialog <Null> (
  948. context: context,
  949. barrierDismissible: false,
  950. builder: (BuildContext context) {
  951. return MyAlertDialog(text: '当前设备不支持蓝牙',childCallback:(val){});
  952. }
  953. );
  954. }
  955. });
  956. }
  957. Future scan() async {
  958. try {
  959. String barcode = await BarcodeScanner.scan();
  960. setState(() {
  961. page=1;
  962. _orderNo = barcode;
  963. _orderController.text = barcode;
  964. });
  965. scanSearchOrder();
  966. } on PlatformException catch (e) {
  967. if (e.code == BarcodeScanner.CameraAccessDenied) {
  968. setState(() {
  969. return this.barcode = 'The user did not grant the camera permission!';
  970. });
  971. } else {
  972. setState(() {
  973. return this.barcode = 'Unknown error: $e';
  974. });
  975. }
  976. } on FormatException{
  977. setState(() => this.barcode = 'null (User returned using the "back"-button before scanning anything. Result)');
  978. } catch (e) {
  979. setState(() => this.barcode = 'Unknown error: $e');
  980. }
  981. }
  982. }