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