index.dart 18KB

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