order_detail_page.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import '../order_management_page/order_detail_page.dart';
  4. import '../../showDialog.dart';
  5. import '../../util/api.dart';
  6. import '../../util/models.dart';
  7. import '../../util/util.dart';
  8. import '../../util/session.dart';
  9. import '../../util/bluetooth_utils.dart';
  10. import '../../showAlert.dart';
  11. class OrderDetail extends StatefulWidget {
  12. final String orderNo;
  13. OrderDetail({
  14. Key key,
  15. @required this.orderNo
  16. }): super(key: key);
  17. _OrderDetailState createState() => _OrderDetailState();
  18. }
  19. class _OrderDetailState extends State < OrderDetail > {
  20. OrderDetailData data;
  21. BluetoothUtils bluetooth = BluetoothUtils();
  22. @override
  23. void initState() {
  24. super.initState();
  25. getOrderDetail(widget.orderNo).then((resp) {
  26. if (isNotError(context, resp) && this.mounted) {
  27. OrderDetailObj orderDetailObj = OrderDetailObj.fromJson(resp.data);
  28. setState(() {
  29. data = orderDetailObj.data;
  30. });
  31. }
  32. });
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. return Container(
  37. child: Scaffold(
  38. appBar: AppBar(
  39. title: Text('订单'),
  40. centerTitle: true,
  41. backgroundColor: Color.fromRGBO(64, 98, 254, 1),
  42. ),
  43. body: Container(
  44. child: data==null?_getMoreWidget():_cardWiget()
  45. ),
  46. )
  47. );
  48. }
  49. Widget _cardWiget() {
  50. return InkWell(
  51. child: Card(
  52. color: Colors.white,
  53. child: Container(
  54. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(20)),
  55. child: Column(
  56. children: < Widget > [
  57. Padding(
  58. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(30)),
  59. child: Row(
  60. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  61. children: < Widget > [
  62. Text('订单号:${data.orderNo}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(102, 102, 102, 1)), ),
  63. Text("运输中", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(126, 211, 33, 1)), ),
  64. ],
  65. )
  66. ),
  67. Padding(
  68. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  69. child: Row(
  70. children: < Widget > [
  71. Text('${data.sendCompanyName} --> ${data.receiptCompanyName}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30)), ),
  72. ],
  73. )
  74. ),
  75. Padding(
  76. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(15)),
  77. child: Row(
  78. children: < Widget > [
  79. SizedBox(
  80. width: ScreenUtil.getInstance().setWidth(355),
  81. child: Text('货物名称:${data.goods}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(155, 155, 155, 1)), ),
  82. ),
  83. Text('代收款:${data.goodsAgencyFund/100}元', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(155, 155, 155, 1)), ),
  84. ],
  85. ),
  86. ),
  87. Padding(
  88. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(30)),
  89. child: Row(
  90. children: < Widget > [
  91. SizedBox(
  92. width: ScreenUtil.getInstance().setWidth(355),
  93. child: Text('货物件数:${data.goodsQuantity}件', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(155, 155, 155, 1)), ),
  94. ),
  95. Text('运费:${data.goodsFreight/100}元', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(155, 155, 155, 1)), ),
  96. ],
  97. ),
  98. ),
  99. Padding(
  100. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  101. child: Container(
  102. height: ScreenUtil.getInstance().setHeight(1),
  103. color: Color.fromRGBO(223, 223, 223, 1),
  104. ),
  105. ),
  106. Row(
  107. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  108. children: < Widget > [
  109. GestureDetector(
  110. child: Offstage(
  111. offstage: false,
  112. child: Container(
  113. width: ScreenUtil.getInstance().setWidth(94),
  114. height: ScreenUtil.getInstance().setHeight(48),
  115. decoration: BoxDecoration(
  116. color: Color.fromRGBO(239, 243, 249, 1),
  117. borderRadius: BorderRadius.all(Radius.circular(4.0))
  118. ),
  119. child: Center(
  120. child: Text('作废', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  121. ),
  122. ),
  123. ),
  124. onTap: () {
  125. showDialog < Null > (
  126. context: context, //BuildContext对象
  127. barrierDismissible: false,
  128. builder: (BuildContext context) {
  129. return new LoadingDialog( //调用对话框
  130. text: '是否确认作废', childCallback: (val) {
  131. if (val) {
  132. myUpdataOrder(5);
  133. } else {
  134. return;
  135. }
  136. },
  137. );
  138. });
  139. print("作废");
  140. },
  141. ),
  142. InkWell(
  143. child: Offstage(
  144. offstage: false,
  145. child: Container(
  146. width: ScreenUtil.getInstance().setWidth(94),
  147. height: ScreenUtil.getInstance().setHeight(48),
  148. decoration: BoxDecoration(
  149. color: Color.fromRGBO(239, 243, 249, 1),
  150. borderRadius: BorderRadius.all(Radius.circular(4.0))
  151. ),
  152. child: Center(
  153. child: Text('改单', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  154. ),
  155. ),
  156. ),
  157. onTap: () {
  158. showDialog < Null > (
  159. context: context, //BuildContext对象
  160. barrierDismissible: false,
  161. builder: (BuildContext context) {
  162. return new LoadingDialog( //调用对话框
  163. text: '是否确认改单', childCallback: (val) {
  164. if (val) {
  165. print(val);
  166. Navigator.push(context, MaterialPageRoute(builder: (context) {
  167. return OrderDetailPage(orderNo: '${data.orderNo}', );
  168. })).then((resp){
  169. if(resp==true){
  170. getOrderDetail(widget.orderNo).then((resp) {
  171. if (isNotError(context, resp) && this.mounted) {
  172. OrderDetailObj orderDetailObj = OrderDetailObj.fromJson(resp.data);
  173. setState(() {
  174. data = orderDetailObj.data;
  175. });
  176. }
  177. });
  178. }
  179. });
  180. } else {
  181. return;
  182. }
  183. },
  184. );
  185. });
  186. print("改单");
  187. },
  188. ),
  189. InkWell(
  190. child: Offstage(
  191. offstage: false,
  192. child: Container(
  193. width: ScreenUtil.getInstance().setWidth(94),
  194. height: ScreenUtil.getInstance().setHeight(48),
  195. decoration: BoxDecoration(
  196. color: Color.fromRGBO(239, 243, 249, 1),
  197. borderRadius: BorderRadius.all(Radius.circular(4.0))
  198. ),
  199. child: Center(
  200. child: Text('打印', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
  201. ),
  202. ),
  203. ),
  204. onTap: () {
  205. showDialog < Null > (
  206. context: context, //BuildContext对象
  207. barrierDismissible: false,
  208. builder: (BuildContext context) {
  209. return new LoadingDialog( //调用对话框
  210. text: '是否确认打印', childCallback: (val) {
  211. if (val) {
  212. checkBlueToothAndPrintOrder(widget);
  213. } else {
  214. return;
  215. }
  216. },
  217. );
  218. });
  219. print("打印");
  220. },
  221. ),
  222. ],
  223. )
  224. ],
  225. ),
  226. )
  227. ),
  228. onTap: () {
  229. },
  230. );
  231. }
  232. Widget _getMoreWidget() {
  233. return Center(
  234. child: Padding(
  235. padding: EdgeInsets.all(10.0),
  236. child: Row(
  237. mainAxisAlignment: MainAxisAlignment.center,
  238. crossAxisAlignment: CrossAxisAlignment.center,
  239. children: < Widget > [
  240. Text(
  241. '加载中...',
  242. style: TextStyle(fontSize: 16.0),
  243. ),
  244. Container(
  245. width: ScreenUtil.getInstance().setWidth(50),
  246. height: ScreenUtil.getInstance().setHeight(50),
  247. child: CircularProgressIndicator()
  248. )
  249. ],
  250. ),
  251. ),
  252. );
  253. }
  254. myUpdataOrder(int myOrderStatus) {
  255. updataOrderStatus(data.orderNo, myOrderStatus).then((resp) {
  256. if (isNotError(context, resp) && this.mounted) {
  257. }
  258. });
  259. }
  260. void checkBlueToothAndPrintOrder(var obj){
  261. bluetooth.isBTDevice().then((resp){
  262. if(resp){
  263. bluetooth.isEnableBluetooth().then((resp){
  264. if(resp){
  265. getOrderDetail(obj.orderNo).then((resp){
  266. if(isNotError(context, resp) && this.mounted){
  267. OrderDetailData data = OrderDetailObj.fromJson(resp.data).data;
  268. getKey('printType').then((printType){
  269. getKey('stationName').then((stationName){
  270. getKey('nickName').then((nickName){
  271. double goodsYs = (data.goodsFreight/100)+(data.goodsAgencyFund/100);
  272. String nowDate = fromatDate( DateTime.now().millisecondsSinceEpoch);//打印时间
  273. String createTime = fromatDate(data.createTime);
  274. double goodsAgencyFunds = data.goodsAgencyFund/100;
  275. double goodsDFreight = data.goodsPaymentMethod==1?data.goodsFreight/100:0;
  276. double goodsXFreight = data.goodsPaymentMethod==2?data.goodsFreight/100:0;
  277. String receiptAddress = data.receiptCompanyAddress.length>10?data.receiptCompanyAddress.substring(0,10):data.receiptCompanyAddress;
  278. Map<String, String> pum = {
  279. "[logisticsNo]": "${data.orderNo ?? ''}",
  280. "[createTime]": "$createTime",
  281. "[sendStationName]": "$stationName",
  282. "[dealerCode]": "${data.sendCompanyCode ?? ''}",
  283. "[dealerName]": "${data.sendCompanyName}",
  284. "[dealerTel]": "${data.sendCompanyPhone ?? ''}",
  285. "[repairName]": "${data.receiptCompanyName ?? ''}",
  286. "[repairTel]": "${data.receiptCompanyPhone ?? ''}",
  287. "[endStationName]": "${data.receiptStationName}",
  288. "[goodsLineCode]": "${data.lineCode ?? ''}",
  289. "[goodsLine]": "${data.lineName ?? ''}",
  290. "[repairAddress]": "${receiptAddress?? ''}",
  291. "[goodsQuantity]": "${data.goodsQuantity ?? ''}",
  292. "[goodsInsurance]": "${data.goodsInsurance ?? ''}",
  293. "[goodsFlatCost]": "${data.goodsFlatCost ?? ''}",
  294. // 到付 现付 金额
  295. "[goodsDFreight]": "$goodsDFreight",
  296. "[goodsXFreight]": "$goodsXFreight",
  297. "[goodsAgencyFund]": "$goodsAgencyFunds",
  298. "[goodsYs]": "$goodsYs",
  299. "[dealerBankAccount]": "${data.sendCompanyBankCard ?? ''}",
  300. "[goodsRemark]": "${data.memo ?? ''}",
  301. "[realName]": "${nickName?? ''}",
  302. "[currentTime]": "$nowDate",
  303. "[currentGoodNumber]": "1/1",
  304. };
  305. bluetooth.printOrder(pum, int.parse(printType));
  306. });
  307. });
  308. });
  309. }
  310. });
  311. }else{
  312. showDialog <Null> (
  313. context: context,
  314. barrierDismissible: false,
  315. builder: (BuildContext context) {
  316. return MyAlertDialog(text: '请打开蓝牙并连接打印机',childCallback:(val){});
  317. }
  318. );
  319. }
  320. });
  321. }else{
  322. showDialog <Null> (
  323. context: context,
  324. barrierDismissible: false,
  325. builder: (BuildContext context) {
  326. return MyAlertDialog(text: '当前设备不支持蓝牙',childCallback:(val){});
  327. }
  328. );
  329. }
  330. });
  331. }
  332. }