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