index.dart 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. import 'package:farmer_client/widgets/DefaultButton.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:fluttertoast/fluttertoast.dart';
  5. import 'package:get/get.dart';
  6. import 'package:farmer_client/widgets/Modal.dart' as modal;
  7. import '../../models/entities/OrderInfoModel.dart';
  8. import '../../services/orderAPI.dart';
  9. import '../../widgets/OrderInfoCard.dart';
  10. import '../../widgets/layout/BasicPage.dart';
  11. // class OrderContentInfo {
  12. // String title;
  13. // Color styleColor;
  14. // StyleObj ({ required this.title, required this.styleColor});
  15. // }
  16. class OrderPageInfo extends BasicPage {
  17. final id = Rx<String>('');
  18. final orderStateText = Rx<String>('待支付');
  19. final orderStateColor = Rx<Color>(Colors.black);
  20. final orderInfoContent = Rx<OrderInfoModel>(OrderInfoModel());
  21. // orderStates
  22. @override
  23. void beforeShow() {
  24. // TODO: implement beforeShow
  25. super.beforeShow();
  26. if (Get.arguments['id'] != null) {
  27. id(Get.arguments['id']);
  28. orderStateText(Get.arguments['title']);
  29. orderStateColor(Get.arguments['styleColor']);
  30. orderInfo(id()).then((value) {
  31. orderInfoContent(OrderInfoModel.fromJson(value));
  32. });
  33. }
  34. }
  35. @override
  36. Widget builder(BuildContext context) {
  37. naviTitle = '订单详情';
  38. return Column(
  39. children: [
  40. Obx(
  41. () => OrderInfoCard(
  42. item: orderInfoContent(),
  43. orderStateText: orderStateText(),
  44. orderStateColor: orderStateColor()),
  45. ),
  46. // Obx(() => _BottomWidget(id: id())),
  47. Obx(
  48. () => Container(
  49. padding: EdgeInsets.fromLTRB(15, 50.w, 15, 0),
  50. child: _bottomJudgment(id.value)),
  51. ),
  52. ],
  53. );
  54. }
  55. Widget _bottomJudgment(String id) {
  56. return orderStateText.value == '已完成'
  57. ? Text('')
  58. : orderStateText.value == '进行中'
  59. ? Text('')
  60. : orderStateText.value == '待评价'
  61. ? DefaultButton(
  62. color: const Color(0xffffffff),
  63. backColor: const Color(0xFFFF703B),
  64. width: 300.w,
  65. height: 49.h,
  66. text: '评价',
  67. onPressed: () {
  68. Fluttertoast.showToast(msg: '评价成功!');
  69. Get.offNamed('/order');
  70. },
  71. margin: const EdgeInsets.all(0),
  72. fontSize: 20.sp,
  73. radius: 24.5.w,
  74. )
  75. : orderStateText.value == '待作业'
  76. ? DefaultButton(
  77. color: const Color(0xffffffff),
  78. backColor: const Color(0xFFFF703B),
  79. width: 300.w,
  80. height: 49.h,
  81. text: '退单',
  82. onPressed: () {
  83. modal.showDialog(
  84. title: '提示',
  85. content: Container(
  86. alignment: Alignment.center,
  87. child: Text('确定要申请退单吗?'),
  88. ),
  89. onCancel: () => true,
  90. onConfirm: () => {
  91. orderRefund(id).then((value) {
  92. Fluttertoast.showToast(msg: '退单成功!');
  93. Get.offNamed('/order');
  94. }),
  95. });
  96. },
  97. margin: const EdgeInsets.all(0),
  98. fontSize: 20.sp,
  99. radius: 24.5.w,
  100. )
  101. : orderStateText.value == '已付款'
  102. ? DefaultButton(
  103. color: const Color(0xffffffff),
  104. backColor: const Color(0xFFFF703B),
  105. width: 300.w,
  106. height: 49.h,
  107. text: '退单',
  108. onPressed: () {
  109. modal.showDialog(
  110. title: '提示',
  111. content: Container(
  112. alignment: Alignment.center,
  113. child: Text('确定要申请退单吗?'),
  114. ),
  115. onCancel: () => true,
  116. onConfirm: () => {
  117. orderRefund(id).then((value) {
  118. Fluttertoast.showToast(msg: '退单成功!');
  119. Get.offNamed('/order');
  120. }),
  121. });
  122. },
  123. margin: const EdgeInsets.all(0),
  124. fontSize: 20.sp,
  125. radius: 24.5.w,
  126. )
  127. : orderStateText.value == '待付款'
  128. ? _BottomWidget(
  129. id: id,
  130. )
  131. : orderStateText.value == '已退单'
  132. ? Text('')
  133. : orderStateText.value == '退单申请中'
  134. ? Text(orderStateText.value)
  135. : Text('');
  136. }
  137. }
  138. class _BottomWidget extends StatelessWidget {
  139. final id;
  140. final resultMessage = Rx<String>('---');
  141. _BottomWidget({Key? key, required this.id}) : super(key: key);
  142. void _orderDeletels() {
  143. modal.showDialog(
  144. title: '提示',
  145. content: Container(
  146. alignment: Alignment.center,
  147. child: Text('确定要取消此订单吗?'),
  148. ),
  149. onCancel: () => true,
  150. onConfirm: () => {
  151. orderDelete(id).then((value) {
  152. Fluttertoast.showToast(msg: '订单取消成功!');
  153. Get.offNamed('/order');
  154. })
  155. });
  156. }
  157. //显示底部弹框的功能
  158. void showBottomSheet(context) {
  159. //用于在底部打开弹框的效果
  160. showModalBottomSheet(
  161. context: context,
  162. isScrollControlled: false,
  163. backgroundColor: Colors.white,
  164. shape: RoundedRectangleBorder(
  165. borderRadius: BorderRadius.all(Radius.circular(10))),
  166. builder: (BuildContext context) {
  167. return Container(
  168. height: 200.w, //对话框高度就是此高度
  169. child: Center(
  170. child: Column(
  171. children: [
  172. Padding(
  173. padding: EdgeInsets.fromLTRB(0, 25.w, 0, 34.w),
  174. child: Text(
  175. "支付方式",
  176. style:
  177. TextStyle(fontSize: 17.sp, fontWeight: FontWeight.bold),
  178. ),
  179. ),
  180. Padding(
  181. padding: EdgeInsets.fromLTRB(15.w, 0, 15.w, 0),
  182. child: ListTile(
  183. contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
  184. // 这边使用了contentPadding
  185. leading: Image(
  186. image: AssetImage('images/alipay.png'),
  187. width: 30.w,
  188. height: 30.w,
  189. ),
  190. title: Transform(
  191. transform: Matrix4.translationValues(-15, 0.0, 0.0),
  192. child: Text("支付宝",
  193. style: TextStyle(
  194. fontSize: 18.sp, color: Color(0xff333333))),
  195. ),
  196. trailing: Image(
  197. image: AssetImage('images/userRight.png'),
  198. width: 10.w,
  199. height: 18.w,
  200. ),
  201. ),
  202. ),
  203. Padding(
  204. padding: EdgeInsets.fromLTRB(15.w, 0, 15.w, 0),
  205. child: ListTile(
  206. onTap: (){
  207. },
  208. contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
  209. // 这边使用了contentPadding
  210. leading: Image(
  211. image: AssetImage('images/weChatPay.png'),
  212. width: 30.w,
  213. height: 30.w,
  214. ),
  215. title: Transform(
  216. transform: Matrix4.translationValues(-15, 0.0, 0.0),
  217. child: Text("微信",
  218. style: TextStyle(
  219. fontSize: 18.sp, color: Color(0xff333333))),
  220. ),
  221. trailing: Image(
  222. image: AssetImage('images/userRight.png'),
  223. width: 10.w,
  224. height: 18.w,
  225. ),
  226. ),
  227. ),
  228. ],
  229. )),
  230. );
  231. });
  232. }
  233. @override
  234. Widget build(BuildContext context) {
  235. return Container(
  236. alignment: Alignment.bottomCenter,
  237. child: Row(
  238. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  239. children: [
  240. SizedBox(
  241. width: 150.w,
  242. height: 49.h,
  243. child: ElevatedButton(
  244. onPressed: () {
  245. _orderDeletels();
  246. },
  247. child: const Text(
  248. "取消",
  249. style: TextStyle(
  250. fontSize: 18,
  251. color: Color(0xFFFF703B),
  252. fontWeight: FontWeight.bold),
  253. ),
  254. style: ButtonStyle(
  255. side: MaterialStateProperty.all(
  256. BorderSide(width: 1, color: Color(0xFFFF703B))), //边框
  257. elevation: MaterialStateProperty.all(0),
  258. backgroundColor: MaterialStateProperty.all(Colors.white),
  259. shape: MaterialStateProperty.all(
  260. RoundedRectangleBorder(
  261. borderRadius: BorderRadius.all(Radius.circular(24.4))),
  262. ),
  263. ),
  264. ),
  265. ),
  266. SizedBox(
  267. child: DefaultButton(
  268. color: const Color(0xffffffff),
  269. backColor: const Color(0xFFFF703B),
  270. width: 150.w,
  271. height: 49.h,
  272. text: '支付',
  273. onPressed: () {
  274. showBottomSheet(context);
  275. // Fluttertoast.showToast(msg: '支付成功!');
  276. // Get.offAllNamed('/');
  277. },
  278. margin: const EdgeInsets.all(0),
  279. fontSize: 20.sp,
  280. radius: 24.5.w,
  281. ),
  282. ),
  283. ],
  284. ),
  285. );
  286. }
  287. }