index.dart 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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,'title':'待付款','styleColor':Color(0xFF51D4FF)});
  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:
  75. Column(
  76. children: [
  77. Container(
  78. margin: EdgeInsets.fromLTRB(15, 20, 0, 0),
  79. alignment: Alignment.topLeft,
  80. child: Text(
  81. '作业面积/公顷',
  82. style: TextStyle(
  83. color: Color(0xff222222),
  84. fontSize: 17.sp,
  85. fontWeight: FontWeight.bold),
  86. ),
  87. ),
  88. TextFormField(
  89. autofocus: false,
  90. keyboardType: TextInputType.number,
  91. controller: _unameController,
  92. decoration: const InputDecoration(
  93. isCollapsed: true,
  94. contentPadding:
  95. EdgeInsets.symmetric(vertical: 8, horizontal: 16),
  96. counterText: '', //去掉计数
  97. /// UnderlineInputBorder 只有下边框 默认使用的就是下边框
  98. border: UnderlineInputBorder(
  99. borderRadius: BorderRadius.all(Radius.circular(10)),
  100. borderSide: BorderSide(
  101. color: Color(0x30000000),
  102. width: 2.0,
  103. ),
  104. ),
  105. floatingLabelBehavior: FloatingLabelBehavior.never,
  106. hintText: "请输入具体面积(公顷)",
  107. ),
  108. onChanged: (e) {
  109. workingArea(int.parse(e));
  110. },
  111. // 校验用户名
  112. validator: (v) {
  113. return v!.trim().isNotEmpty ? null : "作业面积/公顷不能为空";
  114. },
  115. ),
  116. Container(
  117. margin: EdgeInsets.fromLTRB(15, 20, 0, 0),
  118. alignment: Alignment.topLeft,
  119. child: Text(
  120. '作业时间:',
  121. style: TextStyle(
  122. color: Color(0xff222222),
  123. fontSize: 17.sp,
  124. fontWeight: FontWeight.bold),
  125. ),
  126. ),
  127. Container(
  128. width: 345.w,
  129. padding: EdgeInsets.fromLTRB(0, 15, 0, 15),
  130. decoration: const BoxDecoration(
  131. border: Border(
  132. bottom: BorderSide(width: 1, color: Color(0x20000000)
  133. // 0x17000000
  134. )),
  135. ),
  136. child: Row(
  137. children: [
  138. Image(
  139. image: AssetImage('images/icons/timeImage.png'),
  140. fit: BoxFit.cover,
  141. width: 18.w,
  142. height: 18.w,
  143. ),
  144. Padding(
  145. padding: EdgeInsets.fromLTRB(10, 0, 0, 0),
  146. child: GestureDetector(
  147. onTap: () async {
  148. var handleChnage = await showDatePicker(
  149. context: context,
  150. helpText: '请选择作业开始时间',
  151. cancelText: '取消',
  152. confirmText: '确定',
  153. initialDate: selectDate() == null
  154. ? DateTime.now()
  155. : selectDate(),
  156. firstDate: DateTime.now(),
  157. lastDate: DateTime(2030),
  158. );
  159. selectDate(handleChnage!);
  160. print('${selectDate}+');
  161. },
  162. child: Obx(
  163. () => Text(selectDate == null
  164. ? '请选择日期'
  165. : '${DateFormat("yyyy-MM-dd").format(selectDate())}'),
  166. )),
  167. )
  168. ],
  169. )),
  170. Container(
  171. margin: EdgeInsets.fromLTRB(15, 20, 0, 0),
  172. alignment: Alignment.topLeft,
  173. child: Text(
  174. '作业位置:',
  175. style: TextStyle(
  176. color: Color(0xff222222),
  177. fontSize: 17.sp,
  178. fontWeight: FontWeight.bold),
  179. ),
  180. ),
  181. Container(
  182. width: 345.w,
  183. padding: EdgeInsets.fromLTRB(0, 15, 0, 15),
  184. decoration: BoxDecoration(
  185. border: Border(
  186. bottom: BorderSide(width: 1, color: Color(0x20000000)
  187. // 0x17000000
  188. )),
  189. ),
  190. child: Row(
  191. mainAxisAlignment: MainAxisAlignment.start,
  192. children: [
  193. Image(
  194. image: AssetImage('images/gpsImgae.png'),
  195. fit: BoxFit.cover,
  196. width: 14.w,
  197. height: 17.h,
  198. ),
  199. Padding(
  200. padding: EdgeInsets.fromLTRB(10, 0, 0, 0),
  201. child: GestureDetector(
  202. onTap: () {
  203. Get.toNamed('/addressList',
  204. arguments: {'isBack': true});
  205. },
  206. child: Container(
  207. width: 290.w,
  208. child: Obx(() => Text(
  209. addressController.address.value.address
  210. .toString(),
  211. softWrap: true,
  212. maxLines: 1,
  213. textAlign: TextAlign.left,
  214. overflow: TextOverflow.ellipsis,
  215. )),
  216. ),
  217. ))
  218. ],
  219. ),
  220. ),
  221. Spacer(),
  222. Container(
  223. alignment: Alignment.bottomCenter,
  224. child: SizedBox(
  225. width: 315.w,
  226. height: 49.h,
  227. child: ElevatedButton(
  228. onPressed: () {
  229. _orderSubmit();
  230. },
  231. child: const Text(
  232. "确定",
  233. style: TextStyle(
  234. fontSize: 18,
  235. color: Colors.white,
  236. fontWeight: FontWeight.bold),
  237. ),
  238. style: ButtonStyle(
  239. elevation: MaterialStateProperty.all(0),
  240. backgroundColor:
  241. MaterialStateProperty.all(const Color(0xFFFF703B)),
  242. shape: MaterialStateProperty.all(
  243. const RoundedRectangleBorder(
  244. borderRadius:
  245. BorderRadius.all(Radius.circular(24.4)))),
  246. ),
  247. ),
  248. ),
  249. ),
  250. Container(
  251. margin: EdgeInsets.fromLTRB(0, 30.w, 0, 30.w),
  252. alignment: Alignment.bottomCenter,
  253. child: SizedBox(
  254. width: 315.w,
  255. height: 49.h,
  256. child: ElevatedButton(
  257. onPressed: () {
  258. Get.back();
  259. },
  260. child: const Text(
  261. "取消",
  262. style: TextStyle(
  263. fontSize: 18,
  264. color: Color(0xFFFF703B),
  265. fontWeight: FontWeight.bold),
  266. ),
  267. style: ButtonStyle(
  268. side: MaterialStateProperty.all(
  269. BorderSide(width: 1, color: Color(0xFFFF703B))), //边框
  270. elevation: MaterialStateProperty.all(0),
  271. backgroundColor: MaterialStateProperty.all(Colors.white),
  272. shape: MaterialStateProperty.all(
  273. RoundedRectangleBorder(
  274. borderRadius:
  275. BorderRadius.all(Radius.circular(24.4))),
  276. ),
  277. ),
  278. ),
  279. ),
  280. ),
  281. ],
  282. ),
  283. ),
  284. );
  285. }
  286. }