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/services.dart';
  7. import 'package:flutter_easyloading/flutter_easyloading.dart';
  8. import 'package:flutter_screenutil/flutter_screenutil.dart';
  9. import 'package:fluttertoast/fluttertoast.dart';
  10. import 'package:get/get.dart';
  11. import 'package:intl/intl.dart';
  12. import '../../models/entities/CardListModel.dart';
  13. import '../../models/entities/OrderInfoModel.dart';
  14. import '../../services/homeAPI.dart';
  15. import '../../services/orderAPI.dart';
  16. class OrderConfirmation extends BasicPage {
  17. TextEditingController _unameController = TextEditingController();
  18. GlobalKey _formKey = GlobalKey<FormState>();
  19. String markId = '';
  20. final selectDate = Rx<DateTime>(DateTime.now()); //选择的时间
  21. final workingArea = Rx<int>(0);
  22. AddressController addressController = AddressController.t;
  23. AppController appController = AppController.t;
  24. final item = Rx<CardInfo>(CardInfo()); //全部详情
  25. final orderInfo = Rx<OrderInfoModel>(OrderInfoModel()); //全部详情
  26. @override
  27. void beforeShow() {
  28. // TODO: implement beforeShow
  29. super.beforeShow();
  30. if (Get.arguments['item'] != null) {
  31. item(Get.arguments['item']);
  32. } else {
  33. markId = Get.arguments['id'];
  34. EasyLoading.show(status: '数据加载中...');
  35. getMachineryInfo(markId, appController.locationStr, true)
  36. .then((value) {
  37. item(CardInfo.fromJson(value));
  38. EasyLoading.dismiss();
  39. });
  40. // item(CardInfo.fromJson(Get.arguments['item']));
  41. return;
  42. }
  43. }
  44. Map<String, dynamic> data = {};
  45. void _orderSubmit() {
  46. if ((_formKey.currentState as FormState).validate()) {
  47. data = {
  48. 'charges': item.value.price! * workingArea.value,
  49. 'price': item.value.price,
  50. 'amount': workingArea.value,
  51. 'machineryId': item.value.machineryId,
  52. 'machineryName': item.value.name,
  53. 'machineryType': item.value.typeId,
  54. 'typeName': item.value.typeName,
  55. 'address': addressController.address.value.address,
  56. 'orgId': item.value.orgId,
  57. 'appointmentDate':
  58. '${DateFormat("yyyy-MM-dd").format(selectDate.value)} 08:00:00',
  59. };
  60. generateOrder(data).then((value) {
  61. orderInfo(OrderInfoModel.fromJson(value));
  62. Fluttertoast.showToast(msg: '预约成功');
  63. Get.offNamed('/orderPageInfo', arguments: {
  64. 'id': orderInfo().orderId,
  65. 'title': '待付款',
  66. 'styleColor': Color(0xFF51D4FF)
  67. });
  68. });
  69. //验证通过提交数据
  70. }
  71. }
  72. @override
  73. Widget builder(BuildContext context) {
  74. naviTitle = '预约';
  75. return Container(
  76. height: 700.h,
  77. child: Form(
  78. key: _formKey, //设置globalKey,用于后面获取FormState
  79. autovalidateMode: AutovalidateMode.onUserInteraction,
  80. child: Column(
  81. children: [
  82. Container(
  83. margin: EdgeInsets.fromLTRB(15, 20, 0, 0),
  84. alignment: Alignment.topLeft,
  85. child: Text(
  86. '作业面积/亩',
  87. style: TextStyle(
  88. color: Color(0xff222222),
  89. fontSize: 17.sp,
  90. fontWeight: FontWeight.bold),
  91. ),
  92. ),
  93. TextFormField(
  94. autofocus: false,
  95. keyboardType: TextInputType.number,
  96. controller: _unameController,
  97. decoration: const InputDecoration(
  98. isCollapsed: true,
  99. contentPadding:
  100. EdgeInsets.symmetric(vertical: 8, horizontal: 16),
  101. counterText: '', //去掉计数
  102. /// UnderlineInputBorder 只有下边框 默认使用的就是下边框
  103. border: UnderlineInputBorder(
  104. borderRadius: BorderRadius.all(Radius.circular(10)),
  105. borderSide: BorderSide(
  106. color: Color(0x30000000),
  107. width: 2.0,
  108. ),
  109. ),
  110. floatingLabelBehavior: FloatingLabelBehavior.never,
  111. hintText: "请输入具体面积(亩)",
  112. ),
  113. onChanged: (e) {
  114. workingArea(int.parse(e));
  115. },
  116. // 校验用户名
  117. validator: (v) {
  118. return v!.trim().isNotEmpty ? null : "作业面积/亩不能为空";
  119. },
  120. ),
  121. Container(
  122. margin: const EdgeInsets.fromLTRB(15, 20, 0, 0),
  123. alignment: Alignment.topLeft,
  124. child: Text(
  125. '作业时间:',
  126. style: TextStyle(
  127. color: Color(0xff222222),
  128. fontSize: 17.sp,
  129. fontWeight: FontWeight.bold),
  130. ),
  131. ),
  132. Container(
  133. width: 345.w,
  134. padding: const EdgeInsets.fromLTRB(0, 15, 0, 15),
  135. decoration: const BoxDecoration(
  136. border: Border(
  137. bottom: BorderSide(width: 1, color: Color(0x20000000)
  138. // 0x17000000
  139. )),
  140. ),
  141. child: Row(
  142. children: [
  143. Image(
  144. image: const AssetImage('images/icons/timeImage.png'),
  145. fit: BoxFit.cover,
  146. width: 18.w,
  147. height: 18.w,
  148. ),
  149. Padding(
  150. padding: const EdgeInsets.fromLTRB(10, 0, 0, 0),
  151. child: GestureDetector(
  152. onTap: () async {
  153. var handleChnage = await showDatePicker(
  154. context: context,
  155. helpText: '请选择作业开始时间',
  156. cancelText: '取消',
  157. confirmText: '确定',
  158. initialDate: 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: const 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: const EdgeInsets.fromLTRB(0, 15, 0, 15),
  187. decoration: const 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: const AssetImage('images/gpsImgae.png'),
  198. fit: BoxFit.cover,
  199. width: 14.w,
  200. height: 17.h,
  201. ),
  202. Padding(
  203. padding: const EdgeInsets.fromLTRB(10, 0, 0, 0),
  204. child: GestureDetector(
  205. onTap: () {
  206. Get.toNamed('/addressList',
  207. arguments: {'isBack': true});
  208. },
  209. child: SizedBox(
  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. const 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. const BorderSide(width: 1, color: Color(0xFFFF703B))), //边框
  273. elevation: MaterialStateProperty.all(0),
  274. backgroundColor: MaterialStateProperty.all(Colors.white),
  275. shape: MaterialStateProperty.all(
  276. const RoundedRectangleBorder(
  277. borderRadius:
  278. BorderRadius.all(Radius.circular(24.4))),
  279. ),
  280. ),
  281. ),
  282. ),
  283. ),
  284. ],
  285. ),
  286. ),
  287. );
  288. }
  289. }