order_management_page.dart 40 KB

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