order_detail.dart 15 KB

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