index.dart 16KB

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