index.dart 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. import 'package:farmer_client/models/addressController.dart';
  2. import 'package:farmer_client/models/app.dart';
  3. import 'package:farmer_client/models/entities/CardInfo.dart';
  4. import 'package:farmer_client/widgets/layout/BasicPage.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:intl/intl.dart';
  11. import '../../models/entities/OrderInfoModel.dart';
  12. import '../../services/homeAPI.dart';
  13. import '../../services/orderAPI.dart';
  14. class OrderConfirmation extends BasicPage {
  15. TextEditingController _unameController = TextEditingController();
  16. GlobalKey _formKey = GlobalKey<FormState>();
  17. String markId = '';
  18. final selectDate = Rx<DateTime>(DateTime.now()); //选择的时间
  19. final workingArea = Rx<int>(0);
  20. AddressController addressController = AddressController.t;
  21. AppController appController = AppController.t;
  22. final item = Rx<CardInfo>(CardInfo()); //全部详情
  23. final orderInfo = Rx<OrderInfoModel>(OrderInfoModel()); //全部详情
  24. @override
  25. void beforeShow() {
  26. // TODO: implement beforeShow
  27. super.beforeShow();
  28. if (Get.arguments['item'] != null) {
  29. item(Get.arguments['item']);
  30. } else if (Get.arguments['id'] != null) {
  31. markId = Get.arguments['id'];
  32. EasyLoading.show(status: '数据加载中...');
  33. //苹果模拟器看不到定位所以加一个默认定位是邓州市中心位置
  34. getMachineryInfo(Get.arguments['id'],
  35. appController.locationStr ?? '112.091892,32.690712', true)
  36. .then((value) {
  37. item(CardInfo.fromJson(value));
  38. EasyLoading.dismiss();
  39. }).catchError((error) {
  40. EasyLoading.dismiss();
  41. Fluttertoast.showToast(msg: error.error['message']);
  42. });
  43. }
  44. }
  45. Map<String, dynamic> data = {};
  46. void _orderSubmit() {
  47. if ((_formKey.currentState as FormState).validate()) {
  48. data = {
  49. 'charges': item.value.price! * workingArea.value,
  50. 'price': item.value.price,
  51. 'amount': workingArea.value,
  52. 'machineryId': item.value.machineryId,
  53. 'machineryName': item.value.name,
  54. 'machineryType': item.value.typeId,
  55. 'typeName': item.value.typeName,
  56. 'address': addressController.address.value.address,
  57. 'orgId': item.value.orgId,
  58. 'appointmentDate':
  59. '${DateFormat("yyyy-MM-dd").format(selectDate.value)} 08:00:00',
  60. };
  61. generateOrder(data).then((value) {
  62. orderInfo(OrderInfoModel.fromJson(value));
  63. Fluttertoast.showToast(msg: '预约成功');
  64. Get.offNamed('/orderPageInfo', arguments: {
  65. 'orderId': value['orderId'],
  66. 'title': '待付款',
  67. 'styleColor': Color(0xFF51D4FF)
  68. });
  69. });
  70. //验证通过提交数据
  71. }
  72. }
  73. @override
  74. Widget builder(BuildContext context) {
  75. naviTitle = '预约';
  76. return SizedBox(
  77. height: 700.h,
  78. child: Form(
  79. key: _formKey, //设置globalKey,用于后面获取FormState
  80. autovalidateMode: AutovalidateMode.onUserInteraction,
  81. child: Column(
  82. children: [
  83. Container(
  84. margin: EdgeInsets.fromLTRB(15, 20, 0, 0),
  85. alignment: Alignment.topLeft,
  86. child: Text(
  87. '作业面积/亩',
  88. style: TextStyle(
  89. color: Color(0xff222222),
  90. fontSize: 17.sp,
  91. fontWeight: FontWeight.bold),
  92. ),
  93. ),
  94. TextFormField(
  95. autofocus: false,
  96. keyboardType: TextInputType.number,
  97. controller: _unameController,
  98. decoration: const InputDecoration(
  99. isCollapsed: true,
  100. contentPadding:
  101. EdgeInsets.symmetric(vertical: 8, horizontal: 16),
  102. counterText: '', //去掉计数
  103. /// UnderlineInputBorder 只有下边框 默认使用的就是下边框
  104. border: UnderlineInputBorder(
  105. borderRadius: BorderRadius.all(Radius.circular(10)),
  106. borderSide: BorderSide(
  107. color: Color(0x30000000),
  108. width: 2.0,
  109. ),
  110. ),
  111. floatingLabelBehavior: FloatingLabelBehavior.never,
  112. hintText: "请输入具体面积(亩)",
  113. ),
  114. onChanged: (e) {
  115. workingArea(int.parse(e));
  116. },
  117. // 校验用户名
  118. validator: (v) {
  119. return v!.trim().isNotEmpty ? null : "作业面积/亩不能为空";
  120. },
  121. ),
  122. Container(
  123. margin: const EdgeInsets.fromLTRB(15, 20, 0, 0),
  124. alignment: Alignment.topLeft,
  125. child: Text(
  126. '作业时间:',
  127. style: TextStyle(
  128. color: Color(0xff222222),
  129. fontSize: 17.sp,
  130. fontWeight: FontWeight.bold),
  131. ),
  132. ),
  133. Container(
  134. width: 345.w,
  135. padding: const EdgeInsets.fromLTRB(0, 15, 0, 15),
  136. decoration: const BoxDecoration(
  137. border: Border(
  138. bottom: BorderSide(width: 1, color: Color(0x20000000)
  139. // 0x17000000
  140. )),
  141. ),
  142. child: Row(
  143. children: [
  144. Image(
  145. image: const AssetImage('images/icons/timeImage.png'),
  146. fit: BoxFit.cover,
  147. width: 18.w,
  148. height: 18.w,
  149. ),
  150. Padding(
  151. padding: const EdgeInsets.fromLTRB(10, 0, 0, 0),
  152. child: GestureDetector(
  153. onTap: () async {
  154. var handleChnage = await showDatePicker(
  155. context: context,
  156. helpText: '请选择作业开始时间',
  157. cancelText: '取消',
  158. confirmText: '确定',
  159. initialDate: selectDate(),
  160. firstDate: DateTime.now(),
  161. lastDate: DateTime(2030),
  162. );
  163. selectDate(handleChnage!);
  164. print('${selectDate}+');
  165. },
  166. child: Obx(
  167. () => Text(selectDate == null
  168. ? '请选择日期'
  169. : DateFormat("yyyy-MM-dd")
  170. .format(selectDate())),
  171. )),
  172. )
  173. ],
  174. )),
  175. Container(
  176. margin: const EdgeInsets.fromLTRB(15, 20, 0, 0),
  177. alignment: Alignment.topLeft,
  178. child: Text(
  179. '作业位置:',
  180. style: TextStyle(
  181. color: Color(0xff222222),
  182. fontSize: 17.sp,
  183. fontWeight: FontWeight.bold),
  184. ),
  185. ),
  186. Container(
  187. width: 345.w,
  188. padding: const EdgeInsets.fromLTRB(0, 15, 0, 15),
  189. decoration: const BoxDecoration(
  190. border: Border(
  191. bottom: BorderSide(width: 1, color: Color(0x20000000)
  192. // 0x17000000
  193. )),
  194. ),
  195. child: Row(
  196. mainAxisAlignment: MainAxisAlignment.start,
  197. children: [
  198. Image(
  199. image: const AssetImage('images/gpsImgae.png'),
  200. fit: BoxFit.cover,
  201. width: 14.w,
  202. height: 17.h,
  203. ),
  204. Padding(
  205. padding: const EdgeInsets.fromLTRB(10, 0, 0, 0),
  206. child: GestureDetector(
  207. onTap: () {
  208. Get.toNamed('/addressList', arguments: {
  209. 'isBack': true,
  210. });
  211. },
  212. child: SizedBox(
  213. width: 290.w,
  214. child: Obx(() => Text(
  215. addressController.address.value.address
  216. .toString(),
  217. softWrap: true,
  218. maxLines: 1,
  219. textAlign: TextAlign.left,
  220. overflow: TextOverflow.ellipsis,
  221. )),
  222. ),
  223. ))
  224. ],
  225. ),
  226. ),
  227. const Spacer(),
  228. Container(
  229. alignment: Alignment.bottomCenter,
  230. child: SizedBox(
  231. width: 315.w,
  232. height: 49.h,
  233. child: ElevatedButton(
  234. onPressed: () {
  235. _orderSubmit();
  236. },
  237. child: const Text(
  238. "确定",
  239. style: TextStyle(
  240. fontSize: 18,
  241. color: Colors.white,
  242. fontWeight: FontWeight.bold),
  243. ),
  244. style: ButtonStyle(
  245. elevation: MaterialStateProperty.all(0),
  246. backgroundColor:
  247. MaterialStateProperty.all(const Color(0xFFFF703B)),
  248. shape: MaterialStateProperty.all(
  249. const RoundedRectangleBorder(
  250. borderRadius:
  251. BorderRadius.all(Radius.circular(24.4)))),
  252. ),
  253. ),
  254. ),
  255. ),
  256. Container(
  257. margin: EdgeInsets.fromLTRB(0, 30.w, 0, 30.w),
  258. alignment: Alignment.bottomCenter,
  259. child: SizedBox(
  260. width: 315.w,
  261. height: 49.h,
  262. child: ElevatedButton(
  263. onPressed: () {
  264. Get.back();
  265. },
  266. child: const Text(
  267. "取消",
  268. style: TextStyle(
  269. fontSize: 18,
  270. color: Color(0xFFFF703B),
  271. fontWeight: FontWeight.bold),
  272. ),
  273. style: ButtonStyle(
  274. side: MaterialStateProperty.all(const BorderSide(
  275. width: 1, color: Color(0xFFFF703B))), //边框
  276. elevation: MaterialStateProperty.all(0),
  277. backgroundColor: MaterialStateProperty.all(Colors.white),
  278. shape: MaterialStateProperty.all(
  279. const RoundedRectangleBorder(
  280. borderRadius:
  281. BorderRadius.all(Radius.circular(24.4))),
  282. ),
  283. ),
  284. ),
  285. ),
  286. ),
  287. ],
  288. ),
  289. ),
  290. );
  291. }
  292. }