order_management_page.dart 41 KB

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