order_detail.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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 OrderDetailsPage extends StatefulWidget {
  8. final String orderNo;
  9. OrderDetailsPage({
  10. Key key,
  11. @required this.orderNo
  12. }): super(key: key);
  13. _OrderDetailsPageState createState() => _OrderDetailsPageState();
  14. }
  15. class _OrderDetailsPageState extends State < OrderDetailsPage > {
  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. contentWiget("数量", (widget.obj.goodsQuantity).toString()),
  121. contentWiget("运费", (widget.obj.goodsFreight/100).toString()),
  122. contentWiget("代收", (widget.obj.goodsAgencyFund/100).toString()),
  123. contentWiget("保价", widget.obj.goodsPriceProtection.toString()),
  124. contentWiget("重量", widget.obj.goodsWeight.toStringAsFixed(1)),
  125. _descWidget(widget.obj.memo),
  126. ],
  127. ),
  128. )
  129. );
  130. }
  131. Widget _inputWidget(String key, num value) {
  132. return Padding(
  133. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  134. child: Column(
  135. children: < Widget > [
  136. SizedBox(
  137. height: ScreenUtil.getInstance().setHeight(89),
  138. child: Center(
  139. child: Row(
  140. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  141. children: < Widget > [
  142. Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  143. Container(
  144. width: ScreenUtil.getInstance().setWidth(300),
  145. child: Row(
  146. mainAxisAlignment: MainAxisAlignment.end,
  147. children: < Widget > [
  148. Expanded(
  149. //padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(20)),
  150. //child: Text(value,style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  151. child: Center(
  152. child: TextField(
  153. keyboardType: TextInputType.number,
  154. textAlign: TextAlign.end,
  155. style: TextStyle(
  156. fontSize: ScreenUtil.getInstance().setSp(30),
  157. color: Color.fromRGBO(136, 136, 136, 1)
  158. ),
  159. decoration: InputDecoration(
  160. border: InputBorder.none,
  161. hintText: value.toString(),
  162. hintStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)),
  163. contentPadding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(20), 0, 0, 0),
  164. ),
  165. onChanged: (value){
  166. if(key=='数量'){
  167. afterGoodsNumber =int.parse(value);
  168. }else if(key=='运费'){
  169. afterTransportFee =double.parse(value);
  170. String temp = afterTransportFee.toStringAsFixed(1);
  171. afterTransportFee = double.parse(temp);
  172. }else if(key=='代收'){
  173. afterCollectingFee =double.parse(value);
  174. String temp = afterCollectingFee.toStringAsFixed(1);
  175. afterCollectingFee = double.parse(temp);
  176. }
  177. },
  178. ),
  179. )
  180. ),
  181. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  182. ],
  183. )
  184. )
  185. ],
  186. ),
  187. )
  188. ),
  189. Expanded(
  190. flex: 0,
  191. child: underLine()
  192. )
  193. ],
  194. )
  195. );
  196. }
  197. Widget _descWidget(String str) {
  198. return
  199. Container(
  200. padding: EdgeInsets.all(ScreenUtil.getInstance().setWidth(30)),
  201. child: Text(str, maxLines: 100, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  202. );
  203. }
  204. Widget submitBtn(String orderNo) {
  205. return GestureDetector(
  206. child: Container(
  207. margin: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(50), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(40)),
  208. height: ScreenUtil.getInstance().setHeight(88),
  209. decoration: BoxDecoration(
  210. borderRadius: BorderRadius.all(Radius.circular(4)),
  211. color: Color.fromRGBO(37, 102, 242, 1),
  212. ),
  213. child: Center(
  214. child:Row(
  215. mainAxisAlignment: MainAxisAlignment.center,
  216. children: <Widget>[
  217. Offstage(
  218. offstage: submitStatus,
  219. child: SizedBox(
  220. width: ScreenUtil.getInstance().setWidth(45),
  221. height: ScreenUtil.getInstance().setHeight(45),
  222. child: Image.asset('lib/images/loading.gif'),
  223. ),
  224. ),
  225. Text('提交', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36), color: Colors.white)),
  226. ],
  227. )
  228. ),
  229. ),
  230. onTap: () {
  231. if(!submitStatus) return;
  232. setState(() {
  233. submitStatus = false;
  234. });
  235. updataOrder(orderNo,afterTransportFee,afterCollectingFee,afterGoodsNumber).then((resp){
  236. if(isNotError(context, resp)){
  237. showDialog < Null > (
  238. context: context, //BuildContext对象
  239. barrierDismissible: false,
  240. builder: (BuildContext context) {
  241. return MyAlertDialog( //调用对话框
  242. text: '订单修改成功!', childCallback: (val) {
  243. if(val){
  244. Navigator.pop(context,true);
  245. }
  246. },
  247. );
  248. });
  249. }else{
  250. setState(() {
  251. submitStatus = true;
  252. });
  253. }
  254. });
  255. },
  256. );
  257. }
  258. }
  259. Widget titleWidget(String iconUrl, String str) {
  260. return Container(
  261. height: ScreenUtil.getInstance().setHeight(90),
  262. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  263. child: Center(
  264. child: Row(
  265. mainAxisAlignment: MainAxisAlignment.start,
  266. children: < Widget > [
  267. Padding(
  268. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setHeight(20)),
  269. child: Image.asset(
  270. iconUrl,
  271. width: ScreenUtil.getInstance().setWidth(40),
  272. height: ScreenUtil.getInstance().setHeight(40),
  273. )
  274. ),
  275. Text(str, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32)), )
  276. ],
  277. ),
  278. ),
  279. );
  280. }
  281. Widget underLine() {
  282. return Container(
  283. color: Color.fromRGBO(223, 223, 223, 1),
  284. height: ScreenUtil.getInstance().setHeight(1),
  285. );
  286. }
  287. Widget contentWiget(String key, String value) {
  288. return Padding(
  289. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  290. child: Column(
  291. children: < Widget > [
  292. Padding(
  293. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(30)),
  294. child: SizedBox(
  295. height: ScreenUtil.getInstance().setHeight(89),
  296. child: Center(
  297. child: Row(
  298. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  299. children: < Widget > [
  300. Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  301. Text(value, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  302. ],
  303. ),
  304. )
  305. )
  306. ),
  307. Expanded(
  308. flex: 0,
  309. child: underLine()
  310. )
  311. ],
  312. )
  313. );
  314. }
  315. Widget lastContentWiget(String key, String value) {
  316. return Padding(
  317. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  318. child:
  319. Padding(
  320. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(30)),
  321. child: SizedBox(
  322. height: ScreenUtil.getInstance().setHeight(89),
  323. child: Center(
  324. child: Row(
  325. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  326. children: < Widget > [
  327. Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  328. Text(value, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  329. ],
  330. ),
  331. )
  332. )
  333. ),
  334. );
  335. }
  336. Widget _getMoreWidget() {
  337. return Center(
  338. child: Padding(
  339. padding: EdgeInsets.all(10.0),
  340. child: Row(
  341. mainAxisAlignment: MainAxisAlignment.center,
  342. crossAxisAlignment: CrossAxisAlignment.center,
  343. children: < Widget > [
  344. Text(
  345. '加载中...',
  346. style: TextStyle(fontSize: 16.0),
  347. ),
  348. Container(
  349. width: ScreenUtil.getInstance().setWidth(50),
  350. height: ScreenUtil.getInstance().setHeight(50),
  351. child: CircularProgressIndicator()
  352. )
  353. ],
  354. ),
  355. ),
  356. );
  357. }