order_management_page.dart 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  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 = null;
  770. });
  771. page = 1;
  772. scanSearchOrderList(_orderNo,page).then((resp) {
  773. if (isNotError(context, resp) && this.mounted) {
  774. FromStatusGetOrderObj tempObj = FromStatusGetOrderObj.fromJson(resp.data);
  775. if(tempObj.data.items[0].orderStatus==2){
  776. setState(() {
  777. statusList = [false, true, false];
  778. orderStatus = 2;
  779. });
  780. }else if(tempObj.data.items[0].orderStatus>=3){
  781. setState(() {
  782. statusList = [false, false, true];
  783. orderStatus = 3;
  784. });
  785. }
  786. print(tempObj.data.items[0].orderStatus);
  787. print(orderStatus);
  788. setState(() {
  789. orderList = tempObj.data.items;
  790. hasNextPage = tempObj.data.hasNextPage;
  791. });
  792. }
  793. });
  794. }
  795. getMoreOrder(int orderStatus, int page) {
  796. if (!hasNextPage) {
  797. return;
  798. }
  799. loadMoreStatus = false;
  800. fromStatusGetOrderList(orderStatus, page, _orderNo).then((resp) {
  801. if (isNotError(context, resp) && this.mounted) {
  802. FromStatusGetOrderObj tempObj = FromStatusGetOrderObj.fromJson(resp.data);
  803. setState(() {
  804. orderList.addAll(tempObj.data.items);
  805. hasNextPage = tempObj.data.hasNextPage;
  806. });
  807. loadMoreStatus = true;
  808. } else {
  809. loadMoreStatus = true;
  810. }
  811. });
  812. }
  813. deleteOrder(int index) {
  814. setState(() {
  815. orderList.removeAt(index);
  816. });
  817. if (orderList.length < 4) {
  818. if (hasNextPage) {
  819. setState(() {
  820. page = ++page;
  821. });
  822. getMoreOrder(orderStatus, page);
  823. }
  824. }
  825. }
  826. myUpdataOrder(String myOrderNo, int myOrderStatus, int index) {
  827. updataOrderStatus(myOrderNo, myOrderStatus).then((resp) {
  828. if (isNotError(context, resp) && this.mounted) {
  829. deleteOrder(index);
  830. }else{
  831. OrderReception obj = OrderReception.fromJson(resp.data);
  832. showDialog < Null > (
  833. context: context, //BuildContext对象
  834. barrierDismissible: false,
  835. builder: (BuildContext context) {
  836. return new LoadingDialog( //调用对话框
  837. text: obj.msg, childCallback: (val) {
  838. },
  839. );
  840. });
  841. }
  842. });
  843. }
  844. Future refreshOrder() async {
  845. page = 1;
  846. await fromStatusGetOrderList(orderStatus, page, _orderNo).then((resp) {
  847. if (isNotError(context, resp) && this.mounted) {
  848. FromStatusGetOrderObj tempObj = FromStatusGetOrderObj.fromJson(resp.data);
  849. setState(() {
  850. orderList = tempObj.data.items;
  851. hasNextPage = tempObj.data.hasNextPage;
  852. });
  853. }
  854. });
  855. }
  856. void checkBlueToothAndPrintOrder(FromStatusGetOrderList obj){
  857. bluetooth.isBTDevice().then((resp){
  858. if(resp){
  859. bluetooth.isEnableBluetooth().then((resp){
  860. if(resp){
  861. getOrderDetail(obj.orderNo).then((resp){
  862. if(isNotError(context, resp) && this.mounted){
  863. OrderDetailData data = OrderDetailObj.fromJson(resp.data).data;
  864. getKey('printType').then((printType){
  865. getKey('stationName').then((stationName){
  866. getKey('nickName').then((nickName){
  867. getKey('companyName').then((companyName){
  868. getKey('companyCustomerPhone').then((companyCustomerPhone){
  869. double goodsYs = data.goodsPaymentMethod==2?(data.goodsFreight/100)+(data.goodsAgencyFund/100):data.goodsAgencyFund/100;
  870. String nowDate = fromatDate( DateTime.now().millisecondsSinceEpoch);//打印时间
  871. String createTime = fromatDate(data.createTime);
  872. double goodsAgencyFunds = data.goodsAgencyFund/100;
  873. double goodsDFreight = data.goodsPaymentMethod==2?data.goodsFreight/100:0;
  874. double goodsXFreight = data.goodsPaymentMethod==1?data.goodsFreight/100:0;
  875. String receiptAddress = data.receiptCompanyAddress.length>10?data.receiptCompanyAddress.substring(0,10):data.receiptCompanyAddress;
  876. Map<String, String> pum = {
  877. "[logisticsNo]": "${data.orderNo ?? ''}",
  878. "[createTime]": "$createTime",
  879. "[sendStationName]": "$stationName",
  880. "[dealerCode]": "${data.sendCompanyCode ?? ''}",
  881. "[dealerName]": "${data.sendCompanyName}",
  882. "[dealerTel]": "${data.sendCompanyPhone ?? ''}",
  883. "[repairName]": "${data.receiptCompanyName ?? ''}",
  884. "[repairTel]": "${data.receiptCompanyPhone ?? ''}",
  885. "[endStationName]": "${data.receiptStationName}",
  886. "[goodsLineCode]": "${data.lineCode ?? ''}",
  887. "[goodsLine]": "${data.lineName ?? ''}",
  888. "[repairAddress]": "${receiptAddress?? ''}",
  889. "[goodsQuantity]": "${data.goodsQuantity ?? ''}",
  890. "[goodsInsurance]": "${data.goodsInsurance ?? ''}",
  891. "[goodsFlatCost]": "${data.goodsFlatCost ?? ''}",
  892. // 到付 现付 金额
  893. "[goodsDFreight]": "$goodsDFreight",
  894. "[goodsXFreight]": "$goodsXFreight",
  895. "[goodsAgencyFund]": "$goodsAgencyFunds",
  896. "[goodsYs]": "$goodsYs",
  897. "[dealerBankAccount]": "${data.sendCompanyBankCard ?? ''}",
  898. "[goodsRemark]": "${data.memo ?? ''}",
  899. "[realName]": "${nickName?? ''}",
  900. "[currentTime]": "$nowDate",
  901. "[currentGoodNumber]": "1/1",
  902. "[companyCustomerPhone]":"$companyCustomerPhone",
  903. "[companyName]":"$companyName"
  904. };
  905. bluetooth.printOrder(pum, int.parse(printType)).then((value){
  906. if(value==null){
  907. showDialog <Null> (
  908. context: context,
  909. barrierDismissible: false,
  910. builder: (BuildContext context) {
  911. return MyAlertDialog(text: '未连接打印机',childCallback:(val){});
  912. }
  913. );
  914. }
  915. });
  916. });
  917. });
  918. });
  919. });
  920. });
  921. }
  922. });
  923. }else{
  924. showDialog <Null> (
  925. context: context,
  926. barrierDismissible: false,
  927. builder: (BuildContext context) {
  928. return MyAlertDialog(text: '请打开蓝牙并连接打印机',childCallback:(val){});
  929. }
  930. );
  931. }
  932. });
  933. }else{
  934. showDialog <Null> (
  935. context: context,
  936. barrierDismissible: false,
  937. builder: (BuildContext context) {
  938. return MyAlertDialog(text: '当前设备不支持蓝牙',childCallback:(val){});
  939. }
  940. );
  941. }
  942. });
  943. }
  944. Future scan() async {
  945. try {
  946. String barcode = await BarcodeScanner.scan();
  947. setState(() {
  948. page=1;
  949. _orderNo = barcode;
  950. _orderController.text = barcode;
  951. });
  952. scanSearchOrder();
  953. } on PlatformException catch (e) {
  954. if (e.code == BarcodeScanner.CameraAccessDenied) {
  955. setState(() {
  956. return this.barcode = 'The user did not grant the camera permission!';
  957. });
  958. } else {
  959. setState(() {
  960. return this.barcode = 'Unknown error: $e';
  961. });
  962. }
  963. } on FormatException{
  964. setState(() => this.barcode = 'null (User returned using the "back"-button before scanning anything. Result)');
  965. } catch (e) {
  966. setState(() => this.barcode = 'Unknown error: $e');
  967. }
  968. }
  969. }