index.dart 11KB

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