order_detail_page.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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)){
  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)){
  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. return Container(
  126. child: Container(
  127. color: Colors.white,
  128. child: Column(
  129. crossAxisAlignment: CrossAxisAlignment.start,
  130. children: < Widget > [
  131. titleWidget('lib/images/icon_huowu.png', "货物信息"),
  132. underLine(),
  133. contentWiget("货物名称",widget.obj.goods),
  134. _inputWidget("数量", widget.obj.goodsQuantity),
  135. _inputWidget("运费", widget.obj.goodsFreight/100),
  136. _inputWidget("代收", widget.obj.goodsAgencyFund/100),
  137. _packageType('付款方式'),
  138. contentWiget("保价", widget.obj.goodsPriceProtection.toString()),
  139. contentWiget("重量", widget.obj.goodsWeight.toStringAsFixed(1)),
  140. _descWidget(widget.obj.memo),
  141. submitBtn(widget.obj.orderNo)
  142. ],
  143. ),
  144. )
  145. );
  146. }
  147. Widget _inputWidget(String key, num value) {
  148. return Padding(
  149. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  150. child: Column(
  151. children: < Widget > [
  152. SizedBox(
  153. height: ScreenUtil.getInstance().setHeight(89),
  154. child: Center(
  155. child: Row(
  156. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  157. children: < Widget > [
  158. Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  159. Container(
  160. width: ScreenUtil.getInstance().setWidth(300),
  161. child: Row(
  162. mainAxisAlignment: MainAxisAlignment.end,
  163. children: < Widget > [
  164. Expanded(
  165. //padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(20)),
  166. //child: Text(value,style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  167. child: Center(
  168. child: TextField(
  169. keyboardType: TextInputType.number,
  170. textAlign: TextAlign.end,
  171. style: TextStyle(
  172. fontSize: ScreenUtil.getInstance().setSp(30),
  173. color: Colors.black
  174. ),
  175. decoration: InputDecoration(
  176. border: InputBorder.none,
  177. hintText: value.toString(),
  178. hintStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Colors.black),
  179. contentPadding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(20), 0, 0, 0),
  180. ),
  181. onChanged: (value){
  182. if(key=='数量'){
  183. afterGoodsNumber =int.parse(value);
  184. }else if(key=='运费'){
  185. afterTransportFee =double.parse(value);
  186. String temp = afterTransportFee.toStringAsFixed(1);
  187. afterTransportFee = double.parse(temp);
  188. }else if(key=='代收'){
  189. afterCollectingFee =double.parse(value);
  190. String temp = afterCollectingFee.toStringAsFixed(1);
  191. afterCollectingFee = double.parse(temp);
  192. }
  193. },
  194. ),
  195. )
  196. ),
  197. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  198. ],
  199. )
  200. )
  201. ],
  202. ),
  203. )
  204. ),
  205. Expanded(
  206. flex: 0,
  207. child: underLine()
  208. )
  209. ],
  210. )
  211. );
  212. }
  213. Widget _descWidget(String str) {
  214. return
  215. Container(
  216. padding: EdgeInsets.all(ScreenUtil.getInstance().setWidth(30)),
  217. child: Text(str, maxLines: 100, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  218. );
  219. }
  220. Widget submitBtn(String orderNo) {
  221. return GestureDetector(
  222. child: Container(
  223. margin: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(50), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(40)),
  224. height: ScreenUtil.getInstance().setHeight(88),
  225. decoration: BoxDecoration(
  226. borderRadius: BorderRadius.all(Radius.circular(4)),
  227. color: Color.fromRGBO(37, 102, 242, 1),
  228. ),
  229. child: Center(
  230. child:Row(
  231. mainAxisAlignment: MainAxisAlignment.center,
  232. children: <Widget>[
  233. Offstage(
  234. offstage: submitStatus,
  235. child: SizedBox(
  236. width: ScreenUtil.getInstance().setWidth(45),
  237. height: ScreenUtil.getInstance().setHeight(45),
  238. child: Image.asset('lib/images/loading.gif'),
  239. ),
  240. ),
  241. Text('提交', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36), color: Colors.white)),
  242. ],
  243. )
  244. ),
  245. ),
  246. onTap: () {
  247. if(!submitStatus) return;
  248. if(lineList.length==1){
  249. lineId = lineList[0].lineId.toString();
  250. }else if(lineList.length>1){
  251. showLineModal(lineList,orderNo);
  252. return;
  253. }
  254. submitOrder(orderNo);
  255. },
  256. );
  257. }
  258. showPickerModal(BuildContext context, String type) {
  259. List < dynamic > data = [];
  260. if (type == '付款方式') {
  261. data = ['现付', '到付'];
  262. }
  263. new Picker(
  264. adapter: PickerDataAdapter < String > (pickerdata: data),
  265. height: ScreenUtil.getInstance().setHeight(450),
  266. confirmText: '确定',
  267. confirmTextStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(64, 98, 254, 1)),
  268. cancelText: '取消',
  269. cancelTextStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(153, 153, 153, 1)),
  270. headercolor: Color.fromRGBO(245, 245, 245, 1),
  271. itemExtent: ScreenUtil.getInstance().setHeight(80),
  272. textStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(42, 42, 42, 1)),
  273. changeToFirst: true,
  274. hideHeader: false,
  275. onConfirm: (Picker picker, List value) {
  276. showTextPaymentMehod = data[value[0]];
  277. if (showTextPaymentMehod == '现付') {
  278. goodsPaymentMethod = 1;
  279. } else {
  280. goodsPaymentMethod = 2;
  281. }
  282. }
  283. ).showModal(this.context);
  284. }
  285. Widget _packageType(String key) {
  286. return Padding(
  287. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  288. child: Column(
  289. children: < Widget > [
  290. InkWell(
  291. child: SizedBox(
  292. height: ScreenUtil.getInstance().setHeight(89),
  293. child: Center(
  294. child: Row(
  295. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  296. children: < Widget > [
  297. Expanded(
  298. flex: 0,
  299. child: Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  300. ),
  301. Expanded(
  302. child: Row(
  303. mainAxisAlignment: MainAxisAlignment.end,
  304. children: < Widget > [
  305. //Text('${value}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  306. SizedBox(
  307. width: ScreenUtil.getInstance().setWidth(500),
  308. child: Text(showTextPaymentMehod, textAlign: TextAlign.end, )
  309. ),
  310. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  311. ],
  312. )
  313. )
  314. ],
  315. ),
  316. )
  317. ),
  318. onTap: () {
  319. showPickerModal(context, key);
  320. },
  321. ),
  322. Expanded(
  323. flex: 0,
  324. child: underLine()
  325. )
  326. ],
  327. )
  328. );
  329. }
  330. showLineModal(List<CompanyOfLineList> list,String orderNo){
  331. showDialog < Null > (
  332. context: context, //BuildContext对象
  333. barrierDismissible: false,
  334. builder: (BuildContext context) {
  335. return ShowLineModal(
  336. lineList: list, childCallback: (val) {
  337. lineId = val;
  338. submitOrder(orderNo);
  339. },
  340. );
  341. });
  342. }
  343. submitOrder(String orderNo){
  344. setState(() {
  345. submitStatus = false;
  346. });
  347. updataOrder(lineId,orderNo,afterTransportFee,afterCollectingFee,afterGoodsNumber).then((resp){
  348. if(isNotError(context, resp)){
  349. showDialog < Null > (
  350. context: context, //BuildContext对象
  351. barrierDismissible: false,
  352. builder: (BuildContext context) {
  353. return MyAlertDialog( //调用对话框
  354. text: '订单修改成功!', childCallback: (val) {
  355. if(val){
  356. Navigator.pop(context,true);
  357. }
  358. },
  359. );
  360. });
  361. }else{
  362. setState(() {
  363. submitStatus = true;
  364. });
  365. }
  366. });
  367. }
  368. }
  369. Widget titleWidget(String iconUrl, String str) {
  370. return Container(
  371. height: ScreenUtil.getInstance().setHeight(90),
  372. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  373. child: Center(
  374. child: Row(
  375. mainAxisAlignment: MainAxisAlignment.start,
  376. children: < Widget > [
  377. Padding(
  378. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setHeight(20)),
  379. child: Image.asset(
  380. iconUrl,
  381. width: ScreenUtil.getInstance().setWidth(40),
  382. height: ScreenUtil.getInstance().setHeight(40),
  383. )
  384. ),
  385. Text(str, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32)), )
  386. ],
  387. ),
  388. ),
  389. );
  390. }
  391. Widget underLine() {
  392. return Container(
  393. color: Color.fromRGBO(223, 223, 223, 1),
  394. height: ScreenUtil.getInstance().setHeight(1),
  395. );
  396. }
  397. Widget contentWiget(String key, String value) {
  398. return Padding(
  399. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  400. child: Column(
  401. children: < Widget > [
  402. Padding(
  403. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(30)),
  404. child: SizedBox(
  405. height: ScreenUtil.getInstance().setHeight(89),
  406. child: Center(
  407. child: Row(
  408. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  409. children: < Widget > [
  410. Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  411. Text(value, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  412. ],
  413. ),
  414. )
  415. )
  416. ),
  417. Expanded(
  418. flex: 0,
  419. child: underLine()
  420. )
  421. ],
  422. )
  423. );
  424. }
  425. Widget lastContentWiget(String key, String value) {
  426. return Padding(
  427. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  428. child:
  429. Padding(
  430. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(30)),
  431. child: SizedBox(
  432. height: ScreenUtil.getInstance().setHeight(89),
  433. child: Center(
  434. child: Row(
  435. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  436. children: < Widget > [
  437. Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  438. Text(value, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  439. ],
  440. ),
  441. )
  442. )
  443. ),
  444. );
  445. }
  446. Widget _getMoreWidget() {
  447. return Center(
  448. child: Padding(
  449. padding: EdgeInsets.all(10.0),
  450. child: Row(
  451. mainAxisAlignment: MainAxisAlignment.center,
  452. crossAxisAlignment: CrossAxisAlignment.center,
  453. children: < Widget > [
  454. Text(
  455. '加载中...',
  456. style: TextStyle(fontSize: 16.0),
  457. ),
  458. Container(
  459. width: ScreenUtil.getInstance().setWidth(50),
  460. height: ScreenUtil.getInstance().setHeight(50),
  461. child: CircularProgressIndicator()
  462. )
  463. ],
  464. ),
  465. ),
  466. );
  467. }