YSIssue.dart 7.7 KB

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