index.dart 19KB

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