index.dart 10KB

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