YSIssue.dart 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:ysairplane2/base/YSBase.dart';
  4. import 'package:ysairplane2/code/YSChooseLocation.dart';
  5. import 'package:ysairplane2/tools/YSNetWorking.dart';
  6. import 'package:ysairplane2/tools/YSTools.dart';
  7. class YSIssue extends StatefulWidget {
  8. @override
  9. _YSIssueState createState() => _YSIssueState();
  10. }
  11. class _YSIssueState extends State<YSIssue> {
  12. List _showArray = [{'title':'出发时间','content':'请选择时间'},{'title':'货物名称','content':'请输入货物名称'},
  13. {'title':'性质','content':'请选择性质'},{'title':'体积','content':'请输入'},{'title':'重量','content':'请输入'},{'title':'联系人','content':'请输入联系人'},{'title':'联系电话','content':'请输入联系电话'},
  14. {'title':'发货地点','content':'请选择发货地点'},{'title':'送货地点','content':'请选择送货地点'}];
  15. List _kinds = [];
  16. Map _kind,_startDict,_endDict;
  17. String _timeStr;
  18. TextEditingController _goodName = TextEditingController();
  19. TextEditingController _volume = TextEditingController();
  20. TextEditingController _weight = TextEditingController();
  21. TextEditingController _userName = TextEditingController();
  22. TextEditingController _phone = TextEditingController();
  23. @override
  24. void initState() {
  25. Future.delayed(Duration(seconds: 0)).then((value){
  26. _getTypeData();
  27. });
  28. super.initState();
  29. }
  30. @override
  31. Widget build(BuildContext context) {
  32. return YSBase(
  33. ystitle: '发布货源',
  34. yschild: Container(
  35. height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44,
  36. width: MediaQuery.of(context).size.width,
  37. color: Color(0xFFF1F2F3),
  38. child: Column(
  39. children: [
  40. ListView.separated(
  41. itemBuilder: (context,index){
  42. return GestureDetector(
  43. onTap: (){
  44. FocusScope.of(context).unfocus();
  45. if(index==0){
  46. dateChooseAlert(context,dateValue: (date){
  47. timeChooseAlert(context,timeValue: (time){
  48. setState(() {
  49. _timeStr = '$date $time';
  50. });
  51. });
  52. });
  53. }else if(index==2){
  54. showModalBottomSheet(context: context,builder: (context){
  55. return YSPicker(
  56. dataArray: _kinds,
  57. title: 'name',
  58. choose: (value){
  59. setState(() {
  60. _kind = value;
  61. });
  62. },
  63. );
  64. });
  65. }else if(index==7||index==8){
  66. Navigator.of(context).push(
  67. CupertinoPageRoute(
  68. builder: (context){
  69. return YSChooseLocation();
  70. }
  71. )
  72. ).then((value){
  73. if(value==null)return;
  74. if(index==7){
  75. setState(() {
  76. _startDict = value;
  77. });
  78. }else{
  79. setState(() {
  80. _endDict = value;
  81. });
  82. }
  83. });
  84. }
  85. },
  86. child: Container(
  87. color: Colors.white,
  88. padding: EdgeInsets.only(left: wsp(20),right: wsp(20)),
  89. height: hsp(100),
  90. child: Row(
  91. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  92. children: [
  93. Text('${_showArray[index]['title']}',style: TextStyle(fontSize: zsp(30),color: Colors.black,fontWeight: FontWeight.bold),),
  94. index==1||index==3||index==4||index==5||index==6?Container(
  95. width: MediaQuery.of(context).size.width*0.7,
  96. height: hsp(100),
  97. alignment: Alignment.centerRight,
  98. child: CupertinoTextField(
  99. placeholder: _showArray[index]['content'],
  100. placeholderStyle: TextStyle(fontSize: zsp(30),color: Color(0xFF999999)),
  101. style: TextStyle(fontSize: zsp(30),color: Color(0xFF999999)),
  102. decoration: BoxDecoration(),
  103. textAlign: TextAlign.right,
  104. suffix: Text(index==3?'立方米':index==4?'吨':'',style: TextStyle(fontSize: zsp(30),color: Colors.black)),
  105. controller: index==1?_goodName:index==3?_volume:index==4?_weight:index==5?_userName:_phone,
  106. keyboardType: index==1?TextInputType.text:index==3?TextInputType.number:
  107. index==4?TextInputType.number:index==5?TextInputType.text:TextInputType.phone,
  108. ),
  109. ):index==2||index==7||index==8?Row(
  110. children: [
  111. Text(index==2?(_kind==null?'${_showArray[index]['content']}':'${_kind['name']}'):
  112. index==7?(_startDict==null?'${_showArray[index]['content']}':'${_startDict['title']}')
  113. :(_endDict==null?'${_showArray[index]['content']}':'${_endDict['title']}'),style: TextStyle(fontSize: zsp(30),color: Color(0xFF999999)),),
  114. Icon(index==2?Icons.keyboard_arrow_down:Icons.location_on,color: Color(0xFF999999),size: hsp(40),)
  115. ],
  116. ):Text(index==0?(_timeStr==null?'${_showArray[index]['content']}':_timeStr):'${_showArray[index]['content']}',style: TextStyle(fontSize: zsp(30),color: Color(0xFF999999)),)
  117. ],
  118. ),
  119. ),
  120. );
  121. },
  122. separatorBuilder: (context,index){
  123. return Divider(height: index==0||index==4?hsp(10):0.5,thickness: index==0||index==4?hsp(10):0.5,color: Color(0xFFF1F2F3),);
  124. },
  125. itemCount: _showArray.length,
  126. padding: EdgeInsets.all(0),
  127. shrinkWrap: true,
  128. ),
  129. GestureDetector(
  130. onTap: (){
  131. FocusScope.of(context).unfocus();
  132. _postIssueData();
  133. },
  134. child: Container(
  135. margin: EdgeInsets.only(top: hsp(60)),
  136. height: hsp(88),
  137. width: MediaQuery.of(context).size.width-wsp(120),
  138. decoration: BoxDecoration(
  139. color: Color(0xFF007EFF),
  140. borderRadius: BorderRadius.all(Radius.circular(5))
  141. ),
  142. child: Text('确认发布',style: TextStyle(fontSize: zsp(30),color: Colors.white,fontWeight: FontWeight.bold),),
  143. alignment: Alignment.center,
  144. ),
  145. )
  146. ],
  147. ),
  148. ),
  149. );
  150. }
  151. _getTypeData() async{
  152. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/airplanegoods/type/get',parameter: {},isLoading: true,isToken: false);
  153. if(dict!=null){
  154. setState(() {
  155. _kinds = dict['data'];
  156. });
  157. }
  158. }
  159. _postIssueData() async{
  160. if(_timeStr==null){
  161. ysFlutterToast(context, '请选择出发时间');
  162. return;
  163. }
  164. if(_goodName.text.isEmpty){
  165. ysFlutterToast(context, '货物名称不能为空');
  166. return;
  167. }
  168. if(_kind==null){
  169. ysFlutterToast(context, '请选择货物性质');
  170. return;
  171. }
  172. if(_volume.text.isEmpty){
  173. ysFlutterToast(context, '货物体积不能为空');
  174. return;
  175. }
  176. if(_weight.text.isEmpty){
  177. ysFlutterToast(context, '货物重量不能为空');
  178. return;
  179. }
  180. if(_userName.text.isEmpty){
  181. ysFlutterToast(context, '联系人不能为空');
  182. return;
  183. }
  184. if(_phone.text.isEmpty){
  185. ysFlutterToast(context, '联系电话不能为空');
  186. return;
  187. }
  188. if(_startDict==null){
  189. ysFlutterToast(context, '请选择发货地点');
  190. return;
  191. }
  192. if(_endDict==null){
  193. ysFlutterToast(context, '请选择送货地点');
  194. return;
  195. }
  196. if(_endDict['title']==_startDict['title']){
  197. ysFlutterToast(context, '发货地点与送货地点不能相同');
  198. return;
  199. }
  200. Map request = {};
  201. request['goodsPlace'] = _startDict['title'];
  202. request['goodsUnloadingPlace'] = _endDict['title'];
  203. request['goodsLocation'] = '${_startDict['lat']},${_startDict['lng']}';
  204. request['goodsUnloadingLocation'] = '${_endDict['lat']},${_endDict['lng']}';
  205. request['setoffTime'] = '$_timeStr:00';
  206. request['goodsName'] = _goodName.text;
  207. request['goodsNatureId'] = _kind['id'];
  208. request['goodsVolume'] = _volume.text;
  209. request['goodsWeight'] = _weight.text;
  210. request['contactPerson'] = _userName.text;
  211. request['phone'] = _phone.text;
  212. Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/applets/airplanegoods/goodsInfo/create',parameter: request,isLoading: true,isToken: true);
  213. if(dict!=null){
  214. Navigator.of(context).pop('');
  215. }
  216. }
  217. }