order_utils.dart 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import 'package:flutter/material.dart';
  2. import 'package:twong/router/base.dart';
  3. import 'package:twong/utils/index.dart';
  4. import 'package:twong/models/index.dart';
  5. import 'package:twong/config/style.dart';
  6. import 'package:twong/widgets/payment.dart';
  7. class OrderUtils {
  8. static Widget buildButtons({OrderData data, OrderDetails details}) {
  9. var orderId = data == null ? details.order_id : data.order_id;
  10. var orderStatus = data == null ? details.orderStatus : data.orderStatus;
  11. var cancel = Container(
  12. margin: EdgeInsets.only(left: 12.px),
  13. child: OutlineButton(
  14. onPressed: () => _cancelTab(orderId),
  15. shape: StadiumBorder(), child: Text("取消订单")),
  16. );
  17. var pay = Container(
  18. margin: EdgeInsets.only(left: 12.px),
  19. child: FlatButton(
  20. color: DColors.Main,
  21. shape: StadiumBorder(),
  22. onPressed: () => _payTab(orderId),
  23. child: Text("立即付款", style: TextStyle(color: Colors.white))),
  24. );
  25. var express = Container(
  26. margin: EdgeInsets.only(left: 12.px),
  27. child: FlatButton(
  28. color: DColors.Main,
  29. shape: StadiumBorder(),
  30. onPressed: () => _viewExpress(data: data, details: details),
  31. child: Text("查看物流", style: TextStyle(color: Colors.white))),
  32. );
  33. var del = Container(
  34. margin: EdgeInsets.only(left: 12.px),
  35. child: OutlineButton(
  36. color: DColors.Main,
  37. shape: StadiumBorder(),
  38. onPressed: () => _delOrder(orderId),
  39. child: Text("删除订单", style: TextStyle(color: Colors.grey))),
  40. );
  41. var confirm = Container(
  42. margin: EdgeInsets.only(left: 12.px),
  43. child: FlatButton(
  44. color: DColors.Main,
  45. shape: StadiumBorder(),
  46. onPressed: () => _confirm(orderId),
  47. child: Text("确认收货", style: TextStyle(color: Colors.white))),
  48. );
  49. var comment = Container(
  50. margin: EdgeInsets.only(left: 12.px),
  51. child: FlatButton(
  52. color: DColors.Main,
  53. shape: StadiumBorder(),
  54. onPressed: () => _comment(orderId),
  55. child: Text("立即评价", style: TextStyle(color: Colors.white))),
  56. );
  57. var more = Container(
  58. margin: EdgeInsets.only(left: 12.px),
  59. child: FlatButton(
  60. color: DColors.Main,
  61. shape: StadiumBorder(),
  62. onPressed: () => _moreBuy(data: data, details: details),
  63. child: Text("再次购买", style: TextStyle(color: Colors.white))),
  64. );
  65. var returned = Container(
  66. margin: EdgeInsets.only(left: 12.px),
  67. child: FlatButton(
  68. color: DColors.Main,
  69. shape: StadiumBorder(),
  70. onPressed: () => _returned(orderId),
  71. child: Text("申请退款", style: TextStyle(color: Colors.white))),
  72. );
  73. List<Widget> widgets = List<Widget>();
  74. if(orderStatus.type == 0) {
  75. widgets.add(cancel);
  76. widgets.add(pay);
  77. } else if(orderStatus.type == 1) {
  78. widgets.add(cancel);
  79. } else if(orderStatus.type == 2) {
  80. widgets.add(express);
  81. widgets.add(confirm);
  82. } else if(orderStatus.type == 3) {
  83. widgets.add(returned);
  84. if(details == null) {
  85. widgets.add(comment);
  86. }
  87. widgets.add(more);
  88. } else if(orderStatus.type == 4) {
  89. widgets.add(del);
  90. widgets.add(more);
  91. }
  92. return Row(
  93. mainAxisAlignment: MainAxisAlignment.end,
  94. children: widgets);
  95. }
  96. static void _cancelTab(String orderId) {
  97. Utils.showAlert(Cache.context, title: "确定取消订单么?", ok: () {
  98. });
  99. }
  100. static void _payTab(String orderId) {
  101. showModalBottomSheet(
  102. context: Cache.context,
  103. shape: RoundedRectangleBorder(borderRadius: BorderRadius.only(
  104. topLeft: Radius.circular(10.px), topRight: Radius.circular(10.px)
  105. )),
  106. builder: (BuildContext context) {
  107. return Payment(PaymentInfo.id(orderId));
  108. });
  109. }
  110. static void _viewExpress({OrderData data, OrderDetails details}) {
  111. Navigator.pushNamed(Cache.context, RouteNames.orderExpress,
  112. arguments: data == null ? details : data);
  113. }
  114. static void _confirm(String orderId) {
  115. }
  116. static void _delOrder(String orderId) {
  117. }
  118. static void _comment(String orderId) {
  119. Navigator.pushNamed(Cache.context, RouteNames.orderDetails, arguments: orderId);
  120. }
  121. static void _moreBuy({OrderData data, OrderDetails details}) {
  122. }
  123. static void _returned(String orderId) {
  124. }
  125. }