index.dart 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. import 'package:farmer_client/pages/orderInfo/widgets/star.dart';
  2. import 'package:farmer_client/widgets/DefaultButton.dart';
  3. import 'package:ff_stars/ff_stars.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_screenutil/flutter_screenutil.dart';
  6. import 'package:fluttertoast/fluttertoast.dart';
  7. import 'package:get/get.dart';
  8. import 'package:farmer_client/widgets/Modal.dart' as modal;
  9. import '../../models/entities/OrderInfoModel.dart';
  10. import '../../services/orderAPI.dart';
  11. import '../../widgets/OrderInfoCard.dart';
  12. import '../../widgets/layout/BasicPage.dart';
  13. // class OrderContentInfo {
  14. // String title;
  15. // Color styleColor;
  16. // StyleObj ({ required this.title, required this.styleColor});
  17. // }
  18. class OrderPageInfo extends BasicPage {
  19. final id = Rx<String>('');
  20. final orderStateText = Rx<String>('待支付');
  21. final orderStateColor = Rx<Color>(Colors.black);
  22. final orderInfoContent = Rx<OrderInfoModel>(OrderInfoModel());
  23. final evalText=Rx<String>('');
  24. final evalStars=Rx<num>(-1);
  25. // orderStates
  26. @override
  27. void beforeShow() {
  28. // TODO: implement beforeShow
  29. super.beforeShow();
  30. if (Get.arguments['id'] != null) {
  31. id(Get.arguments['id']);
  32. orderStateText(Get.arguments['title']);
  33. orderStateColor(Get.arguments['styleColor']);
  34. orderInfo(id()).then((value) {
  35. orderInfoContent(OrderInfoModel.fromJson(value));
  36. });
  37. }
  38. }
  39. @override
  40. Widget builder(BuildContext context) {
  41. naviTitle = '订单详情';
  42. return Column(
  43. children: [
  44. Obx(
  45. () => OrderInfoCard(
  46. item: orderInfoContent(),
  47. orderStateText: orderStateText(),
  48. orderStateColor: orderStateColor()),
  49. ),
  50. // Obx(() => _BottomWidget(id: id())),
  51. Obx(
  52. () => Container(
  53. padding: EdgeInsets.fromLTRB(15, 50.w, 15, 0),
  54. child: _bottomJudgment(id.value)),
  55. ),
  56. ],
  57. );
  58. }
  59. Widget _bottomJudgment(String id) {
  60. return orderStateText.value == '已完成'
  61. ? Text('')
  62. : orderStateText.value == '进行中'
  63. ? Text('')
  64. : orderStateText.value == '待评价'
  65. ? DefaultButton(
  66. color: const Color(0xffffffff),
  67. backColor: const Color(0xFFFF703B),
  68. width: 300.w,
  69. height: 49.h,
  70. text: '评价',
  71. onPressed: () {
  72. modal.showDialog(
  73. title: '评价此订单',
  74. content: Container(
  75. alignment: Alignment.center,
  76. child:Container(
  77. margin: const EdgeInsets.fromLTRB(15, 20, 15, 20),
  78. child: Column(
  79. children: [
  80. Container(
  81. padding: const EdgeInsets.fromLTRB(0, 0, 0, 10),
  82. decoration: const BoxDecoration(
  83. border: Border(
  84. bottom: BorderSide(
  85. width: 0.8, color: Color(0x20000000)
  86. // 0x17000000
  87. ))),
  88. child: Row(
  89. children: [
  90. Text('满意度:',style: TextStyle(fontSize: 17.sp,fontWeight: FontWeight.bold),),
  91. FFStars(
  92. //https://pub.dev/packages/ff_stars
  93. normalStar:Image.asset('images/icons/starOff.png'),
  94. selectedStar:Image.asset('images/icons/starOn.png'),
  95. starsChanged: (realStars, selectedStars) {
  96. evalStars(realStars);
  97. print("real: $selectedStars, final: $realStars");
  98. },
  99. step: 1,
  100. defaultStars: 0,
  101. ),
  102. ],
  103. ),
  104. ),
  105. Container(
  106. margin: const EdgeInsets.fromLTRB(0, 20, 0, 0),
  107. width: 300.w,
  108. height: 100.w,
  109. decoration: BoxDecoration(
  110. border: Border.all(
  111. color: Color(0x20000000),
  112. width: 0.8,
  113. ),
  114. ),
  115. child: TextField(
  116. minLines: 6,
  117. maxLines: 6,
  118. style: TextStyle(fontSize: 17.sp, height: 1.5),
  119. decoration: const InputDecoration(
  120. isCollapsed: true,
  121. border: InputBorder.none,
  122. counterText: '',
  123. hintText: '请输入评价内容',
  124. floatingLabelBehavior: FloatingLabelBehavior.never,
  125. ),
  126. onChanged: (e) {
  127. evalText(e);
  128. },
  129. ),
  130. )
  131. ],
  132. )
  133. ,
  134. )
  135. ),
  136. onCancel: () => true,
  137. onConfirm:() {
  138. if(evalStars.value!=-1&&evalText.value!=''){
  139. orderEvaluation(id,evalStars.value,evalText.value).then((value) {
  140. Fluttertoast.showToast(msg: '评价成功!');
  141. Get.offNamed('/order');
  142. });
  143. }else{
  144. Fluttertoast.showToast(msg: '请完整选择评分或输入评价内容');
  145. return false;
  146. }
  147. }
  148. );
  149. },
  150. margin: const EdgeInsets.all(0),
  151. fontSize: 20.sp,
  152. radius: 24.5.w,
  153. )
  154. : orderStateText.value == '待作业'
  155. ? DefaultButton(
  156. color: const Color(0xffffffff),
  157. backColor: const Color(0xFFFF703B),
  158. width: 300.w,
  159. height: 49.h,
  160. text: '退单',
  161. onPressed: () {
  162. modal.showDialog(
  163. title: '提示',
  164. content: Container(
  165. alignment: Alignment.center,
  166. child: Text('确定要申请退单吗?'),
  167. ),
  168. onCancel: () => true,
  169. onConfirm: () => {
  170. orderRefund(id).then((value) {
  171. Fluttertoast.showToast(msg: '退单成功!');
  172. Get.offNamed('/order');
  173. }),
  174. });
  175. },
  176. margin: const EdgeInsets.all(0),
  177. fontSize: 20.sp,
  178. radius: 24.5.w,
  179. )
  180. : orderStateText.value == '已付款'
  181. ? DefaultButton(
  182. color: const Color(0xffffffff),
  183. backColor: const Color(0xFFFF703B),
  184. width: 300.w,
  185. height: 49.h,
  186. text: '退单',
  187. onPressed: () {
  188. modal.showDialog(
  189. title: '提示',
  190. content: Container(
  191. alignment: Alignment.center,
  192. child: Text('确定要申请退单吗?'),
  193. ),
  194. onCancel: () => true,
  195. onConfirm: () => {
  196. orderRefund(id).then((value) {
  197. Fluttertoast.showToast(msg: '退单成功!');
  198. Get.offNamed('/order');
  199. }),
  200. });
  201. },
  202. margin: const EdgeInsets.all(0),
  203. fontSize: 20.sp,
  204. radius: 24.5.w,
  205. )
  206. : orderStateText.value == '待付款'
  207. ? _BottomWidget(
  208. id: id,
  209. )
  210. : orderStateText.value == '已退单'
  211. ? Text('')
  212. : orderStateText.value == '退单申请中'
  213. ? Text(orderStateText.value)
  214. : Text('');
  215. }
  216. }
  217. class _BottomWidget extends StatelessWidget {
  218. final id;
  219. final resultMessage = Rx<String>('---');
  220. _BottomWidget({Key? key, required this.id}) : super(key: key);
  221. void _orderDeletels() {
  222. modal.showDialog(
  223. title: '提示',
  224. content: Container(
  225. alignment: Alignment.center,
  226. child: Text('确定要取消此订单吗?'),
  227. ),
  228. onCancel: () => true,
  229. onConfirm: () => {
  230. orderDelete(id).then((value) {
  231. Fluttertoast.showToast(msg: '订单取消成功!');
  232. Get.offNamed('/order');
  233. })
  234. });
  235. }
  236. //显示底部弹框的功能
  237. void showBottomSheet(context) {
  238. //用于在底部打开弹框的效果
  239. showModalBottomSheet(
  240. context: context,
  241. isScrollControlled: false,
  242. backgroundColor: Colors.white,
  243. shape: RoundedRectangleBorder(
  244. borderRadius: BorderRadius.all(Radius.circular(10))),
  245. builder: (BuildContext context) {
  246. return Container(
  247. height: 200.w, //对话框高度就是此高度
  248. child: Center(
  249. child: Column(
  250. children: [
  251. Padding(
  252. padding: EdgeInsets.fromLTRB(0, 25.w, 0, 34.w),
  253. child: Text(
  254. "支付方式",
  255. style:
  256. TextStyle(fontSize: 17.sp, fontWeight: FontWeight.bold),
  257. ),
  258. ),
  259. Padding(
  260. padding: EdgeInsets.fromLTRB(15.w, 0, 15.w, 0),
  261. child: ListTile(
  262. contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
  263. // 这边使用了contentPadding
  264. leading: Image(
  265. image: AssetImage('images/alipay.png'),
  266. width: 30.w,
  267. height: 30.w,
  268. ),
  269. title: Transform(
  270. transform: Matrix4.translationValues(-15, 0.0, 0.0),
  271. child: Text("支付宝",
  272. style: TextStyle(
  273. fontSize: 18.sp, color: Color(0xff333333))),
  274. ),
  275. trailing: Image(
  276. image: AssetImage('images/userRight.png'),
  277. width: 10.w,
  278. height: 18.w,
  279. ),
  280. ),
  281. ),
  282. Padding(
  283. padding: EdgeInsets.fromLTRB(15.w, 0, 15.w, 0),
  284. child: ListTile(
  285. onTap: (){
  286. },
  287. contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
  288. // 这边使用了contentPadding
  289. leading: Image(
  290. image: AssetImage('images/weChatPay.png'),
  291. width: 30.w,
  292. height: 30.w,
  293. ),
  294. title: Transform(
  295. transform: Matrix4.translationValues(-15, 0.0, 0.0),
  296. child: Text("微信",
  297. style: TextStyle(
  298. fontSize: 18.sp, color: Color(0xff333333))),
  299. ),
  300. trailing: Image(
  301. image: AssetImage('images/userRight.png'),
  302. width: 10.w,
  303. height: 18.w,
  304. ),
  305. ),
  306. ),
  307. ],
  308. )),
  309. );
  310. });
  311. }
  312. @override
  313. Widget build(BuildContext context) {
  314. return Container(
  315. alignment: Alignment.bottomCenter,
  316. child: Row(
  317. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  318. children: [
  319. SizedBox(
  320. width: 150.w,
  321. height: 49.h,
  322. child: ElevatedButton(
  323. onPressed: () {
  324. _orderDeletels();
  325. },
  326. child: const Text(
  327. "取消",
  328. style: TextStyle(
  329. fontSize: 18,
  330. color: Color(0xFFFF703B),
  331. fontWeight: FontWeight.bold),
  332. ),
  333. style: ButtonStyle(
  334. side: MaterialStateProperty.all(
  335. BorderSide(width: 1, color: Color(0xFFFF703B))), //边框
  336. elevation: MaterialStateProperty.all(0),
  337. backgroundColor: MaterialStateProperty.all(Colors.white),
  338. shape: MaterialStateProperty.all(
  339. RoundedRectangleBorder(
  340. borderRadius: BorderRadius.all(Radius.circular(24.4))),
  341. ),
  342. ),
  343. ),
  344. ),
  345. SizedBox(
  346. child: DefaultButton(
  347. color: const Color(0xffffffff),
  348. backColor: const Color(0xFFFF703B),
  349. width: 150.w,
  350. height: 49.h,
  351. text: '支付',
  352. onPressed: () {
  353. showBottomSheet(context);
  354. // Fluttertoast.showToast(msg: '支付成功!');
  355. // Get.offAllNamed('/');
  356. },
  357. margin: const EdgeInsets.all(0),
  358. fontSize: 20.sp,
  359. radius: 24.5.w,
  360. ),
  361. ),
  362. ],
  363. ),
  364. );
  365. }
  366. }