123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- import 'package:flutter/material.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:ysairplane2/base/YSBase.dart';
- import 'package:ysairplane2/code/YSChooseLocation.dart';
- import 'package:ysairplane2/tools/YSNetWorking.dart';
- import 'package:ysairplane2/tools/YSTools.dart';
- class YSIssue extends StatefulWidget {
- @override
- _YSIssueState createState() => _YSIssueState();
- }
- class _YSIssueState extends State<YSIssue> {
- List _showArray = [{'title':'出发时间','content':'请选择时间'},{'title':'货物名称','content':'请输入货物名称'},
- {'title':'性质','content':'请选择性质'},{'title':'体积','content':'请输入'},{'title':'重量','content':'请输入'},{'title':'联系人','content':'请输入联系人'},{'title':'联系电话','content':'请输入联系电话'},
- {'title':'发货地点','content':'请选择发货地点'},{'title':'送货地点','content':'请选择送货地点'}];
- List _kinds = [];
- Map _kind,_startDict,_endDict;
- String _timeStr;
- TextEditingController _goodName = TextEditingController();
- TextEditingController _volume = TextEditingController();
- TextEditingController _weight = TextEditingController();
- TextEditingController _userName = TextEditingController();
- TextEditingController _phone = TextEditingController();
- @override
- void initState() {
- Future.delayed(Duration(seconds: 0)).then((value){
- _getTypeData();
- });
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return YSBase(
- ystitle: '发布货源',
- yschild: Container(
- height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44,
- width: MediaQuery.of(context).size.width,
- color: Color(0xFFF1F2F3),
- child: Column(
- children: [
- ListView.separated(
- itemBuilder: (context,index){
- return GestureDetector(
- onTap: (){
- FocusScope.of(context).unfocus();
- if(index==0){
- dateChooseAlert(context,dateValue: (date){
- timeChooseAlert(context,timeValue: (time){
- setState(() {
- _timeStr = '$date $time';
- });
- });
- });
- }else if(index==2){
- showModalBottomSheet(context: context,builder: (context){
- return YSPicker(
- dataArray: _kinds,
- title: 'name',
- choose: (value){
- setState(() {
- _kind = value;
- });
- },
- );
- });
- }else if(index==7||index==8){
- Navigator.of(context).push(
- CupertinoPageRoute(
- builder: (context){
- return YSChooseLocation();
- }
- )
- ).then((value){
- if(value==null)return;
- if(index==7){
- setState(() {
- _startDict = value;
- });
- }else{
- setState(() {
- _endDict = value;
- });
- }
- });
- }
- },
- child: Container(
- color: Colors.white,
- padding: EdgeInsets.only(left: wsp(20),right: wsp(20)),
- height: hsp(100),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text('${_showArray[index]['title']}',style: TextStyle(fontSize: zsp(30),color: Colors.black,fontWeight: FontWeight.bold),),
- index==1||index==3||index==4||index==5||index==6?Container(
- width: MediaQuery.of(context).size.width*0.7,
- height: hsp(100),
- alignment: Alignment.centerRight,
- child: CupertinoTextField(
- placeholder: _showArray[index]['content'],
- placeholderStyle: TextStyle(fontSize: zsp(30),color: Color(0xFF999999)),
- style: TextStyle(fontSize: zsp(30),color: Color(0xFF999999)),
- decoration: BoxDecoration(),
- textAlign: TextAlign.right,
- suffix: Text(index==3?'立方米':index==4?'吨':'',style: TextStyle(fontSize: zsp(30),color: Colors.black)),
- controller: index==1?_goodName:index==3?_volume:index==4?_weight:index==5?_userName:_phone,
- keyboardType: index==1?TextInputType.text:index==3?TextInputType.number:
- index==4?TextInputType.number:index==5?TextInputType.text:TextInputType.phone,
- ),
- ):index==2||index==7||index==8?Row(
- children: [
- Text(index==2?(_kind==null?'${_showArray[index]['content']}':'${_kind['name']}'):
- index==7?(_startDict==null?'${_showArray[index]['content']}':'${_startDict['title']}')
- :(_endDict==null?'${_showArray[index]['content']}':'${_endDict['title']}'),style: TextStyle(fontSize: zsp(30),color: Color(0xFF999999)),),
- Icon(index==2?Icons.keyboard_arrow_down:Icons.location_on,color: Color(0xFF999999),size: hsp(40),)
- ],
- ):Text(index==0?(_timeStr==null?'${_showArray[index]['content']}':_timeStr):'${_showArray[index]['content']}',style: TextStyle(fontSize: zsp(30),color: Color(0xFF999999)),)
- ],
- ),
- ),
- );
- },
- separatorBuilder: (context,index){
- return Divider(height: index==0||index==4?hsp(10):0.5,thickness: index==0||index==4?hsp(10):0.5,color: Color(0xFFF1F2F3),);
- },
- itemCount: _showArray.length,
- padding: EdgeInsets.all(0),
- shrinkWrap: true,
- ),
- GestureDetector(
- onTap: (){
- FocusScope.of(context).unfocus();
- _postIssueData();
- },
- child: Container(
- margin: EdgeInsets.only(top: hsp(60)),
- height: hsp(88),
- width: MediaQuery.of(context).size.width-wsp(120),
- decoration: BoxDecoration(
- color: Color(0xFF007EFF),
- borderRadius: BorderRadius.all(Radius.circular(5))
- ),
- child: Text('确认发布',style: TextStyle(fontSize: zsp(30),color: Colors.white,fontWeight: FontWeight.bold),),
- alignment: Alignment.center,
- ),
- )
- ],
- ),
- ),
- );
- }
- _getTypeData() async{
- Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/airplanegoods/type/get',parameter: {},isLoading: true,isToken: false);
- if(dict!=null){
- setState(() {
- _kinds = dict['data'];
- });
- }
- }
- _postIssueData() async{
- if(_timeStr==null){
- ysFlutterToast(context, '请选择出发时间');
- return;
- }
- if(_goodName.text.isEmpty){
- ysFlutterToast(context, '货物名称不能为空');
- return;
- }
- if(_kind==null){
- ysFlutterToast(context, '请选择货物性质');
- return;
- }
- if(_volume.text.isEmpty){
- ysFlutterToast(context, '货物体积不能为空');
- return;
- }
- if(_weight.text.isEmpty){
- ysFlutterToast(context, '货物重量不能为空');
- return;
- }
- if(_userName.text.isEmpty){
- ysFlutterToast(context, '联系人不能为空');
- return;
- }
- if(_phone.text.isEmpty){
- ysFlutterToast(context, '联系电话不能为空');
- return;
- }
- if(_startDict==null){
- ysFlutterToast(context, '请选择发货地点');
- return;
- }
- if(_endDict==null){
- ysFlutterToast(context, '请选择送货地点');
- return;
- }
- if(_endDict['title']==_startDict['title']){
- ysFlutterToast(context, '发货地点与送货地点不能相同');
- return;
- }
- Map request = {};
- request['goodsPlace'] = _startDict['title'];
- request['goodsUnloadingPlace'] = _endDict['title'];
- request['goodsLocation'] = '${_startDict['lat']},${_startDict['lng']}';
- request['goodsUnloadingLocation'] = '${_endDict['lat']},${_endDict['lng']}';
- request['setoffTime'] = '$_timeStr:00';
- request['goodsName'] = _goodName.text;
- request['goodsNatureId'] = _kind['id'];
- request['goodsVolume'] = _volume.text;
- request['goodsWeight'] = _weight.text;
- request['contactPerson'] = _userName.text;
- request['phone'] = _phone.text;
- Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/applets/airplanegoods/goodsInfo/create',parameter: request,isLoading: true,isToken: true);
- if(dict!=null){
- Navigator.of(context).pop('');
- }
- }
- }
|