order_management_page.dart 40 KB

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