order_detail_page.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import '../../util/api.dart';
  4. import '../../util/models.dart';
  5. import '../../util/util.dart';
  6. import '../../showAlert.dart';
  7. class OrderDetailPage extends StatefulWidget {
  8. final String orderNo;
  9. OrderDetailPage({
  10. Key key,
  11. @required this.orderNo
  12. }): super(key: key);
  13. _OrderDetailPageState createState() => _OrderDetailPageState();
  14. }
  15. class _OrderDetailPageState extends State < OrderDetailPage > {
  16. OrderDetailData orderDetailObj;
  17. @override
  18. void initState() {
  19. super.initState();
  20. getOrderDetail(widget.orderNo).then((resp){
  21. if(isNotError(context, resp)){
  22. OrderDetailObj tempObj = OrderDetailObj.fromJson(resp.data);
  23. setState(() {
  24. orderDetailObj =tempObj.data;
  25. });
  26. }
  27. });
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return Scaffold(
  32. appBar: AppBar(
  33. title: Text("订单详情", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36)), ),
  34. centerTitle: true,
  35. backgroundColor: Color.fromRGBO(64, 98, 254, 1),
  36. ),
  37. body: Container(
  38. padding: EdgeInsets.fromLTRB(0, ScreenUtil.getInstance().setHeight(20), 0, ScreenUtil.getInstance().setHeight(20)),
  39. color: Color.fromRGBO(246, 246, 254, 1),
  40. child:orderDetailObj==null?Center(
  41. child:_getMoreWidget(),
  42. ): ListView(
  43. children: < Widget > [
  44. _sendInfo(),
  45. _getInfo(),
  46. ItemInfoWidget(obj:orderDetailObj),
  47. ],
  48. )
  49. ),
  50. //resizeToAvoidBottomPadding: false //键盘弹出,页面不跟随向上滑动,防止出现溢出错误
  51. );
  52. }
  53. Widget _sendInfo() {
  54. return Container(
  55. color: Colors.white,
  56. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  57. child: Column(
  58. children: < Widget > [
  59. titleWidget('lib/images/icon_send.png', '发件信息'),
  60. underLine(),
  61. contentWiget('电话', orderDetailObj.senderPhone),
  62. contentWiget('企业编码', orderDetailObj.sendCompanyCode),
  63. contentWiget('企业名称', orderDetailObj.sendCompanyName),
  64. contentWiget('城市/区域', '${orderDetailObj.sendCompanyProvinceName}' '${orderDetailObj.sendCompanyCityName}' '${orderDetailObj.sendCompanyAreaName}'),
  65. lastContentWiget('详细地址', orderDetailObj.sendCompanyAddress)
  66. ],
  67. )
  68. );
  69. }
  70. Widget _getInfo() {
  71. return Container(
  72. color: Colors.white,
  73. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  74. child: Column(
  75. children: < Widget > [
  76. titleWidget('lib/images/icon_shoujian.png', '收件信息'),
  77. underLine(),
  78. contentWiget('企业名称', orderDetailObj.receiptCompanyName),
  79. contentWiget('电话', orderDetailObj.receiptCompanyPhone),
  80. contentWiget('城市/区域', '${orderDetailObj.receiptCompanyProvinceName}' '${orderDetailObj.receiptCompanyCityName}' '${orderDetailObj.receiptCompanyAreaName}'),
  81. lastContentWiget('详细地址', orderDetailObj.sendCompanyAddress)
  82. ],
  83. )
  84. );
  85. }
  86. }
  87. class ItemInfoWidget extends StatefulWidget {
  88. final OrderDetailData obj;
  89. ItemInfoWidget({
  90. Key key,
  91. @required this.obj
  92. }): super(key: key);
  93. _ItemInfoWidgetState createState() => _ItemInfoWidgetState();
  94. }
  95. class _ItemInfoWidgetState extends State < ItemInfoWidget > {
  96. double afterTransportFee=0.0;//运费
  97. int afterGoodsNumber=0;//数量
  98. double afterCollectingFee=0.0;//代收
  99. bool submitStatus = true;
  100. @override
  101. void initState() {
  102. super.initState();
  103. setState(() {
  104. afterTransportFee = widget.obj.goodsFreight/100;
  105. afterGoodsNumber =widget.obj.goodsQuantity;
  106. afterCollectingFee =widget.obj.goodsAgencyFund/100;
  107. });
  108. }
  109. @override
  110. Widget build(BuildContext context) {
  111. return Container(
  112. child: Container(
  113. color: Colors.white,
  114. child: Column(
  115. crossAxisAlignment: CrossAxisAlignment.start,
  116. children: < Widget > [
  117. titleWidget('lib/images/icon_huowu.png', "货物信息"),
  118. underLine(),
  119. contentWiget("货物名称",widget.obj.goods),
  120. _inputWidget("数量", widget.obj.goodsQuantity),
  121. _inputWidget("运费", widget.obj.goodsFreight/100),
  122. _inputWidget("代收", widget.obj.goodsAgencyFund/100),
  123. contentWiget("保价", widget.obj.goodsPriceProtection.toString()),
  124. contentWiget("重量", widget.obj.goodsWeight.toStringAsFixed(1)),
  125. _descWidget(widget.obj.memo),
  126. submitBtn(widget.obj.orderNo)
  127. ],
  128. ),
  129. )
  130. );
  131. }
  132. Widget _inputWidget(String key, num value) {
  133. return Padding(
  134. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  135. child: Column(
  136. children: < Widget > [
  137. SizedBox(
  138. height: ScreenUtil.getInstance().setHeight(89),
  139. child: Center(
  140. child: Row(
  141. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  142. children: < Widget > [
  143. Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  144. Container(
  145. width: ScreenUtil.getInstance().setWidth(300),
  146. child: Row(
  147. mainAxisAlignment: MainAxisAlignment.end,
  148. children: < Widget > [
  149. Expanded(
  150. //padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(20)),
  151. //child: Text(value,style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  152. child: Center(
  153. child: TextField(
  154. keyboardType: TextInputType.number,
  155. textAlign: TextAlign.end,
  156. style: TextStyle(
  157. fontSize: ScreenUtil.getInstance().setSp(30),
  158. color: Color.fromRGBO(136, 136, 136, 1)
  159. ),
  160. decoration: InputDecoration(
  161. border: InputBorder.none,
  162. hintText: value.toString(),
  163. hintStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)),
  164. contentPadding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(20), 0, 0, 0),
  165. ),
  166. onChanged: (value){
  167. if(key=='数量'){
  168. afterGoodsNumber =int.parse(value);
  169. }else if(key=='运费'){
  170. afterTransportFee =double.parse(value);
  171. }else if(key=='代收'){
  172. afterCollectingFee =double.parse(value);
  173. }
  174. },
  175. ),
  176. )
  177. ),
  178. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  179. ],
  180. )
  181. )
  182. ],
  183. ),
  184. )
  185. ),
  186. Expanded(
  187. flex: 0,
  188. child: underLine()
  189. )
  190. ],
  191. )
  192. );
  193. }
  194. Widget _descWidget(String str) {
  195. return
  196. Container(
  197. padding: EdgeInsets.all(ScreenUtil.getInstance().setWidth(30)),
  198. child: Text(str, maxLines: 100, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  199. );
  200. }
  201. Widget submitBtn(String orderNo) {
  202. return GestureDetector(
  203. child: Container(
  204. margin: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(50), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(40)),
  205. height: ScreenUtil.getInstance().setHeight(88),
  206. decoration: BoxDecoration(
  207. borderRadius: BorderRadius.all(Radius.circular(4)),
  208. color: Color.fromRGBO(37, 102, 242, 1),
  209. ),
  210. child: Center(
  211. child:Row(
  212. mainAxisAlignment: MainAxisAlignment.center,
  213. children: <Widget>[
  214. Offstage(
  215. offstage: submitStatus,
  216. child: SizedBox(
  217. width: ScreenUtil.getInstance().setWidth(45),
  218. height: ScreenUtil.getInstance().setHeight(45),
  219. child: Image.asset('lib/images/loading.gif'),
  220. ),
  221. ),
  222. Text('提交', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36), color: Colors.white)),
  223. ],
  224. )
  225. ),
  226. ),
  227. onTap: () {
  228. if(!submitStatus) return;
  229. setState(() {
  230. submitStatus = false;
  231. });
  232. updataOrder(orderNo,afterTransportFee,afterCollectingFee,afterGoodsNumber).then((resp){
  233. if(isNotError(context, resp)){
  234. showDialog < Null > (
  235. context: context, //BuildContext对象
  236. barrierDismissible: false,
  237. builder: (BuildContext context) {
  238. return MyAlertDialog( //调用对话框
  239. text: '订单修改成功!', childCallback: (val) {
  240. if(val){
  241. Navigator.pop(context);
  242. }
  243. },
  244. );
  245. });
  246. }else{
  247. setState(() {
  248. submitStatus = true;
  249. });
  250. }
  251. });
  252. },
  253. );
  254. }
  255. }
  256. Widget titleWidget(String iconUrl, String str) {
  257. return Container(
  258. height: ScreenUtil.getInstance().setHeight(90),
  259. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  260. child: Center(
  261. child: Row(
  262. mainAxisAlignment: MainAxisAlignment.start,
  263. children: < Widget > [
  264. Padding(
  265. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setHeight(20)),
  266. child: Image.asset(
  267. iconUrl,
  268. width: ScreenUtil.getInstance().setWidth(40),
  269. height: ScreenUtil.getInstance().setHeight(40),
  270. )
  271. ),
  272. Text(str, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32)), )
  273. ],
  274. ),
  275. ),
  276. );
  277. }
  278. Widget underLine() {
  279. return Container(
  280. color: Color.fromRGBO(223, 223, 223, 1),
  281. height: ScreenUtil.getInstance().setHeight(1),
  282. );
  283. }
  284. Widget contentWiget(String key, String value) {
  285. return Padding(
  286. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  287. child: Column(
  288. children: < Widget > [
  289. Padding(
  290. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(30)),
  291. child: SizedBox(
  292. height: ScreenUtil.getInstance().setHeight(89),
  293. child: Center(
  294. child: Row(
  295. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  296. children: < Widget > [
  297. Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  298. Text(value, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  299. ],
  300. ),
  301. )
  302. )
  303. ),
  304. Expanded(
  305. flex: 0,
  306. child: underLine()
  307. )
  308. ],
  309. )
  310. );
  311. }
  312. Widget lastContentWiget(String key, String value) {
  313. return Padding(
  314. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  315. child:
  316. Padding(
  317. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(30)),
  318. child: SizedBox(
  319. height: ScreenUtil.getInstance().setHeight(89),
  320. child: Center(
  321. child: Row(
  322. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  323. children: < Widget > [
  324. Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  325. Text(value, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  326. ],
  327. ),
  328. )
  329. )
  330. ),
  331. );
  332. }
  333. Widget _getMoreWidget() {
  334. return Center(
  335. child: Padding(
  336. padding: EdgeInsets.all(10.0),
  337. child: Row(
  338. mainAxisAlignment: MainAxisAlignment.center,
  339. crossAxisAlignment: CrossAxisAlignment.center,
  340. children: < Widget > [
  341. Text(
  342. '加载中...',
  343. style: TextStyle(fontSize: 16.0),
  344. ),
  345. Container(
  346. width: ScreenUtil.getInstance().setWidth(50),
  347. height: ScreenUtil.getInstance().setHeight(50),
  348. child: CircularProgressIndicator()
  349. )
  350. ],
  351. ),
  352. ),
  353. );
  354. }