order_detail.dart 14 KB

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