order_detail_page.dart 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:flutter_picker/flutter_picker.dart';
  4. import '../../util/api.dart';
  5. import '../../util/models.dart';
  6. import '../../util/util.dart';
  7. import '../../showAlert.dart';
  8. import '../../showLineModal.dart';
  9. class OrderDetailPage extends StatefulWidget {
  10. final String orderNo;
  11. OrderDetailPage({
  12. Key key,
  13. @required this.orderNo
  14. }): super(key: key);
  15. _OrderDetailPageState createState() => _OrderDetailPageState();
  16. }
  17. class _OrderDetailPageState extends State < OrderDetailPage > {
  18. OrderDetailData orderDetailObj;
  19. @override
  20. void initState() {
  21. super.initState();
  22. getOrderDetail(widget.orderNo).then((resp){
  23. if(isNotError(context, resp) && this.mounted){
  24. OrderDetailObj tempObj = OrderDetailObj.fromJson(resp.data);
  25. setState(() {
  26. orderDetailObj =tempObj.data;
  27. });
  28. }
  29. });
  30. }
  31. @override
  32. Widget build(BuildContext context) {
  33. return Scaffold(
  34. appBar: AppBar(
  35. title: Text("订单详情", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36)), ),
  36. centerTitle: true,
  37. backgroundColor: Color.fromRGBO(64, 98, 254, 1),
  38. ),
  39. body: Container(
  40. padding: EdgeInsets.fromLTRB(0, ScreenUtil.getInstance().setHeight(20), 0, ScreenUtil.getInstance().setHeight(20)),
  41. color: Color.fromRGBO(246, 246, 254, 1),
  42. child:orderDetailObj==null?Center(
  43. child:_getMoreWidget(),
  44. ): ListView(
  45. children: < Widget > [
  46. _sendInfo(),
  47. _getInfo(),
  48. ItemInfoWidget(obj:orderDetailObj),
  49. ],
  50. )
  51. ),
  52. //resizeToAvoidBottomPadding: false //键盘弹出,页面不跟随向上滑动,防止出现溢出错误
  53. );
  54. }
  55. Widget _sendInfo() {
  56. return Container(
  57. color: Colors.white,
  58. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  59. child: Column(
  60. children: < Widget > [
  61. titleWidget('lib/images/icon_send.png', '发件信息'),
  62. underLine(),
  63. contentWiget('电话', orderDetailObj.senderPhone!=null?orderDetailObj.senderPhone:orderDetailObj.sendCompanyPhone),
  64. contentWiget('企业编码', orderDetailObj.sendCompanyCode),
  65. contentWiget('企业名称', orderDetailObj.sendCompanyName),
  66. contentWiget('城市/区域', '${orderDetailObj.sendCompanyProvinceName}'+' '+'${orderDetailObj.sendCompanyCityName}'+' '+ '${orderDetailObj.sendCompanyAreaName}'),
  67. lastContentWiget('详细地址', orderDetailObj.sendCompanyAddress)
  68. ],
  69. )
  70. );
  71. }
  72. Widget _getInfo() {
  73. return Container(
  74. color: Colors.white,
  75. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  76. child: Column(
  77. children: < Widget > [
  78. titleWidget('lib/images/icon_shoujian.png', '收件信息'),
  79. underLine(),
  80. contentWiget('企业名称', orderDetailObj.receiptCompanyName),
  81. contentWiget('电话', orderDetailObj.receiptCompanyPhone),
  82. contentWiget('城市/区域', '${orderDetailObj.receiptCompanyProvinceName}'+' '+ '${orderDetailObj.receiptCompanyCityName}'+' '+ '${orderDetailObj.receiptCompanyAreaName}'),
  83. lastContentWiget('详细地址', orderDetailObj.sendCompanyAddress)
  84. ],
  85. )
  86. );
  87. }
  88. }
  89. class ItemInfoWidget extends StatefulWidget {
  90. final OrderDetailData obj;
  91. ItemInfoWidget({
  92. Key key,
  93. @required this.obj
  94. }): super(key: key);
  95. _ItemInfoWidgetState createState() => _ItemInfoWidgetState();
  96. }
  97. class _ItemInfoWidgetState extends State < ItemInfoWidget > {
  98. double afterTransportFee=0.0;//运费
  99. int afterGoodsNumber=0;//数量
  100. double afterCollectingFee=0.0;//代收
  101. bool submitStatus = true;
  102. String lineId = '-1';
  103. List<CompanyOfLineList> lineList = [];
  104. String showTextPaymentMehod = '现付';
  105. int goodsPaymentMethod = 1;
  106. @override
  107. void initState() {
  108. super.initState();
  109. setState(() {
  110. afterTransportFee = widget.obj.goodsFreight/100;
  111. afterGoodsNumber =widget.obj.goodsQuantity;
  112. afterCollectingFee =widget.obj.goodsAgencyFund/100;
  113. });
  114. getLineOfCompanyId(widget.obj.sendCompanyId.toString()).then((resp){
  115. if(isNotError(context, resp) && this.mounted){
  116. CompanyOfLine obj = CompanyOfLine.fromJson(resp.data);
  117. setState(() {
  118. lineList = obj.data;
  119. });
  120. }
  121. });
  122. }
  123. @override
  124. Widget build(BuildContext context) {
  125. showTextPaymentMehod = widget.obj.goodsPaymentMethod==1?'现付':'到付';
  126. return Container(
  127. child: Container(
  128. color: Colors.white,
  129. child: Column(
  130. crossAxisAlignment: CrossAxisAlignment.start,
  131. children: < Widget > [
  132. titleWidget('lib/images/icon_huowu.png', "货物信息"),
  133. underLine(),
  134. contentWiget("货物名称",widget.obj.goods),
  135. _inputWidget("数量", widget.obj.goodsQuantity),
  136. _inputWidget("运费", widget.obj.goodsFreight/100),
  137. _inputWidget("代收", widget.obj.goodsAgencyFund/100),
  138. _packageType('付款方式'),
  139. contentWiget("保价", (widget.obj.goodsPriceProtection/100).toString()),
  140. contentWiget("重量", widget.obj.goodsWeight.toStringAsFixed(1)),
  141. contentWiget("包装类型", (widget.obj.goodsPackingName)),
  142. contentWiget("货物类型", (widget.obj.goodsCategoryName)),
  143. _descWidget(widget.obj.memo),
  144. submitBtn(widget.obj.orderNo)
  145. ],
  146. ),
  147. )
  148. );
  149. }
  150. Widget _inputWidget(String key, num value) {
  151. return Padding(
  152. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  153. child: Column(
  154. children: < Widget > [
  155. SizedBox(
  156. height: ScreenUtil.getInstance().setHeight(89),
  157. child: Center(
  158. child: Row(
  159. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  160. children: < Widget > [
  161. Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  162. Container(
  163. width: ScreenUtil.getInstance().setWidth(300),
  164. child: Row(
  165. mainAxisAlignment: MainAxisAlignment.end,
  166. children: < Widget > [
  167. Expanded(
  168. //padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(20)),
  169. //child: Text(value,style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  170. child: Center(
  171. child: TextField(
  172. keyboardType: TextInputType.number,
  173. textAlign: TextAlign.end,
  174. style: TextStyle(
  175. fontSize: ScreenUtil.getInstance().setSp(30),
  176. color: Colors.black
  177. ),
  178. decoration: InputDecoration(
  179. border: InputBorder.none,
  180. hintText: value.toString(),
  181. hintStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Colors.black),
  182. contentPadding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(20), 0, 0, 0),
  183. ),
  184. onChanged: (value){
  185. if(key=='数量'){
  186. afterGoodsNumber =int.parse(value);
  187. }else if(key=='运费'){
  188. afterTransportFee =double.parse(value);
  189. String temp = afterTransportFee.toStringAsFixed(1);
  190. afterTransportFee = double.parse(temp);
  191. }else if(key=='代收'){
  192. afterCollectingFee =double.parse(value);
  193. String temp = afterCollectingFee.toStringAsFixed(1);
  194. afterCollectingFee = double.parse(temp);
  195. }
  196. },
  197. ),
  198. )
  199. ),
  200. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  201. ],
  202. )
  203. )
  204. ],
  205. ),
  206. )
  207. ),
  208. Expanded(
  209. flex: 0,
  210. child: underLine()
  211. )
  212. ],
  213. )
  214. );
  215. }
  216. Widget _descWidget(String str) {
  217. return
  218. Container(
  219. padding: EdgeInsets.all(ScreenUtil.getInstance().setWidth(30)),
  220. child: Text(str, maxLines: 100, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  221. );
  222. }
  223. Widget submitBtn(String orderNo) {
  224. return GestureDetector(
  225. child: Container(
  226. margin: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(50), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(40)),
  227. height: ScreenUtil.getInstance().setHeight(88),
  228. decoration: BoxDecoration(
  229. borderRadius: BorderRadius.all(Radius.circular(4)),
  230. color: Color.fromRGBO(37, 102, 242, 1),
  231. ),
  232. child: Center(
  233. child:Row(
  234. mainAxisAlignment: MainAxisAlignment.center,
  235. children: <Widget>[
  236. Offstage(
  237. offstage: submitStatus,
  238. child: SizedBox(
  239. width: ScreenUtil.getInstance().setWidth(45),
  240. height: ScreenUtil.getInstance().setHeight(45),
  241. child: Image.asset('lib/images/loading.gif'),
  242. ),
  243. ),
  244. Text('提交', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36), color: Colors.white)),
  245. ],
  246. )
  247. ),
  248. ),
  249. onTap: () {
  250. if(!submitStatus) return;
  251. if(lineList.length==1){
  252. lineId = lineList[0].lineId.toString();
  253. }else if(lineList.length>1){
  254. showLineModal(lineList,orderNo);
  255. return;
  256. }
  257. submitOrder(orderNo);
  258. },
  259. );
  260. }
  261. showPickerModal(BuildContext context, String type) {
  262. List < dynamic > data = [];
  263. if (type == '付款方式') {
  264. data = ['现付', '到付'];
  265. }
  266. new Picker(
  267. adapter: PickerDataAdapter < String > (pickerdata: data),
  268. height: ScreenUtil.getInstance().setHeight(450),
  269. confirmText: '确定',
  270. confirmTextStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(64, 98, 254, 1)),
  271. cancelText: '取消',
  272. cancelTextStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(153, 153, 153, 1)),
  273. headercolor: Color.fromRGBO(245, 245, 245, 1),
  274. itemExtent: ScreenUtil.getInstance().setHeight(80),
  275. textStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(42, 42, 42, 1)),
  276. changeToFirst: true,
  277. hideHeader: false,
  278. onConfirm: (Picker picker, List value) {
  279. showTextPaymentMehod = data[value[0]];
  280. if (showTextPaymentMehod == '现付') {
  281. goodsPaymentMethod = 1;
  282. } else {
  283. goodsPaymentMethod = 2;
  284. }
  285. }
  286. ).showModal(this.context);
  287. }
  288. Widget _packageType(String key) {
  289. return Padding(
  290. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  291. child: Column(
  292. children: < Widget > [
  293. InkWell(
  294. child: SizedBox(
  295. height: ScreenUtil.getInstance().setHeight(89),
  296. child: Center(
  297. child: Row(
  298. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  299. children: < Widget > [
  300. Expanded(
  301. flex: 0,
  302. child: Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  303. ),
  304. Expanded(
  305. child: Row(
  306. mainAxisAlignment: MainAxisAlignment.end,
  307. children: < Widget > [
  308. //Text('${value}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  309. SizedBox(
  310. width: ScreenUtil.getInstance().setWidth(500),
  311. child: Text(showTextPaymentMehod, textAlign: TextAlign.end, )
  312. ),
  313. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  314. ],
  315. )
  316. )
  317. ],
  318. ),
  319. )
  320. ),
  321. onTap: () {
  322. showPickerModal(context, key);
  323. },
  324. ),
  325. Expanded(
  326. flex: 0,
  327. child: underLine()
  328. )
  329. ],
  330. )
  331. );
  332. }
  333. showLineModal(List<CompanyOfLineList> list,String orderNo){
  334. showDialog < Null > (
  335. context: context, //BuildContext对象
  336. barrierDismissible: false,
  337. builder: (BuildContext context) {
  338. return ShowLineModal(
  339. lineList: list, childCallback: (val) {
  340. lineId = val;
  341. submitOrder(orderNo);
  342. },
  343. );
  344. });
  345. }
  346. submitOrder(String orderNo){
  347. setState(() {
  348. submitStatus = false;
  349. });
  350. updataOrder(lineId,orderNo,afterTransportFee,afterCollectingFee,afterGoodsNumber).then((resp){
  351. if(isNotError(context, resp) && this.mounted){
  352. showDialog < Null > (
  353. context: context, //BuildContext对象
  354. barrierDismissible: false,
  355. builder: (BuildContext context) {
  356. return MyAlertDialog( //调用对话框
  357. text: '订单修改成功!', childCallback: (val) {
  358. if(val){
  359. Navigator.pop(context,true);
  360. }
  361. },
  362. );
  363. });
  364. }else{
  365. setState(() {
  366. submitStatus = true;
  367. });
  368. }
  369. });
  370. }
  371. }
  372. Widget titleWidget(String iconUrl, String str) {
  373. return Container(
  374. height: ScreenUtil.getInstance().setHeight(90),
  375. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  376. child: Center(
  377. child: Row(
  378. mainAxisAlignment: MainAxisAlignment.start,
  379. children: < Widget > [
  380. Padding(
  381. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setHeight(20)),
  382. child: Image.asset(
  383. iconUrl,
  384. width: ScreenUtil.getInstance().setWidth(40),
  385. height: ScreenUtil.getInstance().setHeight(40),
  386. )
  387. ),
  388. Text(str, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32)), )
  389. ],
  390. ),
  391. ),
  392. );
  393. }
  394. Widget underLine() {
  395. return Container(
  396. color: Color.fromRGBO(223, 223, 223, 1),
  397. height: ScreenUtil.getInstance().setHeight(1),
  398. );
  399. }
  400. Widget contentWiget(String key, String value) {
  401. return Padding(
  402. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  403. child: Column(
  404. children: < Widget > [
  405. Padding(
  406. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(30)),
  407. child: SizedBox(
  408. height: ScreenUtil.getInstance().setHeight(89),
  409. child: Center(
  410. child: Row(
  411. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  412. children: < Widget > [
  413. Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  414. Text(value, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  415. ],
  416. ),
  417. )
  418. )
  419. ),
  420. Expanded(
  421. flex: 0,
  422. child: underLine()
  423. )
  424. ],
  425. )
  426. );
  427. }
  428. Widget lastContentWiget(String key, String value) {
  429. return Padding(
  430. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  431. child:
  432. Padding(
  433. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(30)),
  434. child: SizedBox(
  435. height: ScreenUtil.getInstance().setHeight(89),
  436. child: Center(
  437. child: Row(
  438. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  439. children: < Widget > [
  440. Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  441. Text(value, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  442. ],
  443. ),
  444. )
  445. )
  446. ),
  447. );
  448. }
  449. Widget _getMoreWidget() {
  450. return Center(
  451. child: Padding(
  452. padding: EdgeInsets.all(10.0),
  453. child: Row(
  454. mainAxisAlignment: MainAxisAlignment.center,
  455. crossAxisAlignment: CrossAxisAlignment.center,
  456. children: < Widget > [
  457. Text(
  458. '加载中...',
  459. style: TextStyle(fontSize: 16.0),
  460. ),
  461. Container(
  462. width: ScreenUtil.getInstance().setWidth(50),
  463. height: ScreenUtil.getInstance().setHeight(50),
  464. child: CircularProgressIndicator()
  465. )
  466. ],
  467. ),
  468. ),
  469. );
  470. }