import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:ysairplane/code/YSChooseLocation.dart'; import 'package:ysairplane/code/YSChoosePlane.dart'; import 'package:ysairplane/code/YSOrderOne.dart'; import 'package:ysairplane/code/YSOrderTwo.dart'; import 'package:ysairplane/code/YSPay.dart'; import 'package:ysairplane/tools/YSNetWorking.dart'; import 'package:ysairplane/tools/YSTools.dart'; import 'YSCity.dart'; class YSTravelling extends StatefulWidget { @override _YSTravellingState createState() => _YSTravellingState(); } class _YSTravellingState extends State { int _type = 1; int _typeSub = 1; Map _msgDict; List _travellings1 = [{'startCity':{},'endCity':{},'startTime':'','endTime':''}]; List _travellings2 = [{'startCity':{},'endCity':{},'startTime':'','endTime':''}]; List _travellings3 = [{'startCity':{},'endCity':{},'startTime':'','endTime':''}]; String _numStr; Map _planeType; @override void initState() { Future.delayed(Duration(seconds: 0)).then((value){ _getBackImageData(); }); super.initState(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Color(0xFFF1F2F4), body: SingleChildScrollView( child: Stack( children: [ Container( height: MediaQuery.of(context).padding.top+hsp(380), width: MediaQuery.of(context).size.width, child: Image( image: _msgDict==null?AssetImage('lib/images/home3.png'):NetworkImage('${_msgDict['background']}'), fit: BoxFit.fill, ), ), GestureDetector( onTap: (){Navigator.pop(context);}, child: Container( margin: EdgeInsets.only(left: wsp(32),top: MediaQuery.of(context).padding.top+hsp(30)), child: Icon(Icons.arrow_back_ios,size: hsp(40),color: Colors.white,), ), ), if(_msgDict!=null)Container( margin: EdgeInsets.only(left: wsp(32),top: MediaQuery.of(context).padding.top+hsp(130),right: wsp(32)), width: MediaQuery.of(context).size.width-wsp(64), alignment: Alignment.center, child: Text('${_msgDict['name']}',style: TextStyle(fontSize: zsp(40),color: Colors.white,fontWeight: FontWeight.bold),) ), if(_msgDict!=null)Container( margin: EdgeInsets.only(left: wsp(32),top: MediaQuery.of(context).padding.top+hsp(200),right: wsp(32)), width: MediaQuery.of(context).size.width-wsp(64), alignment: Alignment.center, child: Text('${_msgDict['subtitle']}',style: TextStyle(fontSize: zsp(28),color: Colors.white.withOpacity(0.6)),) ), Container( width: MediaQuery.of(context).size.width-wsp(60), margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+hsp(300),left: wsp(30),bottom: hsp(40)), decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(10)), color: Colors.white, ), child: Column( children: [ Row( children: [ GestureDetector( onTap: (){ _travellings1 = [{'startCity':{},'endCity':{},'startTime':'','endTime':''}]; _travellings2 = [{'startCity':{},'endCity':{},'startTime':'','endTime':''}]; _travellings3 = [{'startCity':{},'endCity':{},'startTime':'','endTime':''}]; setState(() { _type = 1; }); }, child: Container( height: hsp(100), width: (MediaQuery.of(context).size.width-wsp(64))/2, padding: EdgeInsets.only(top: hsp(30)), decoration: BoxDecoration( color: _type==1?Colors.white:Color(0xFFF1F2F3), borderRadius: BorderRadius.only(topLeft: Radius.circular(10)) ), child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text('商旅机',style: TextStyle(fontSize: zsp(34),color: Colors.black,fontWeight: FontWeight.bold),), Container( height: hsp(6), width: wsp(66), color: _type==1?Color(0xFF007EFF):Colors.transparent, ) ], ), ), ), GestureDetector( onTap: (){ _travellings1 = [{'startCity':{},'endCity':{},'startTime':'','endTime':''}]; _travellings2 = [{'startCity':{},'endCity':{},'startTime':'','endTime':''}]; _travellings3 = [{'startCity':{},'endCity':{},'startTime':'','endTime':''}]; setState(() { _type = 2; }); }, child: Container( height: hsp(100), width: (MediaQuery.of(context).size.width-wsp(64))/2, padding: EdgeInsets.only(top: hsp(30)), decoration: BoxDecoration( color: _type==2?Colors.white:Color(0xFFF1F2F3), borderRadius: BorderRadius.only(topRight: Radius.circular(10)) ), child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text('直升机',style: TextStyle(fontSize: zsp(34),color: Colors.black,fontWeight: FontWeight.bold),), Container( height: hsp(6), width: wsp(66), color: _type==2?Color(0xFF007EFF):Colors.transparent, ) ], ), ), ) ], ), Container( margin: EdgeInsets.only(left: wsp(40),right: wsp(40),top: hsp(40),bottom: hsp(10)), padding: EdgeInsets.only(left: wsp(2),right: wsp(2)), height: hsp(80), decoration: BoxDecoration( color: Color(0xFFF1F2F3), borderRadius: BorderRadius.all(Radius.circular(5)) ), child: Row( children: [ GestureDetector( onTap: (){ setState(() { _typeSub = 1; }); }, child: Container( height: hsp(74), width: (MediaQuery.of(context).size.width-wsp(144))/3, decoration: BoxDecoration( color: _typeSub==1?Colors.white:Colors.transparent, borderRadius: BorderRadius.all(Radius.circular(5)) ), alignment: Alignment.center, child: Text('单程',style: TextStyle(fontSize: zsp(30),fontWeight: _typeSub==1?FontWeight.bold:FontWeight.normal,color: Colors.black),), ), ), GestureDetector( onTap: (){ setState(() { _typeSub = 2; }); }, child: Container( height: hsp(74), width: (MediaQuery.of(context).size.width-wsp(144))/3, decoration: BoxDecoration( color: _typeSub==2?Colors.white:Colors.transparent, borderRadius: BorderRadius.all(Radius.circular(5)) ), alignment: Alignment.center, child: Text('往返',style: TextStyle(fontSize: zsp(30),fontWeight: _typeSub==2?FontWeight.bold:FontWeight.normal,color: Colors.black),), ), ), GestureDetector( onTap: (){ setState(() { _typeSub = 3; }); }, child: Container( height: hsp(74), width: (MediaQuery.of(context).size.width-wsp(144))/3, decoration: BoxDecoration( color: _typeSub==3?Colors.white:Colors.transparent, borderRadius: BorderRadius.all(Radius.circular(5)) ), alignment: Alignment.center, child: Text('多程',style: TextStyle(fontSize: zsp(30),fontWeight: _typeSub==3?FontWeight.bold:FontWeight.normal,color: Colors.black),), ), ), ], ), ), ListView.separated( shrinkWrap: true, itemBuilder: (context,index){ return Container( child: Column( children: [ if(_typeSub==3)Container( padding: EdgeInsets.only(right: wsp(32),top: wsp(30),bottom: wsp(10)), child: Row( children: [ Container( height: hsp(40), alignment: Alignment.center, child: Text('${index+1}',style: TextStyle(fontSize: zsp(20),color: Colors.white),), padding: EdgeInsets.only(left: wsp(20),right: wsp(20)), margin: EdgeInsets.only(right: wsp(30)), decoration: BoxDecoration( color: Color(0xFF007EFF), borderRadius: BorderRadius.only(topRight: Radius.circular(3),bottomRight: Radius.circular(8)) ), ), ], ), ), Container( padding: EdgeInsets.only(left: wsp(32),right: wsp(32),top: hsp(20),bottom: hsp(20)), child: _type==1?Column( children: [ Row( children: [ GestureDetector( child: Container( child: Text('${(_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['startCity'].isNotEmpty? (_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['startCity']['display']:'请选择出发地'}', style: TextStyle(fontSize: zsp(40),fontWeight: FontWeight.bold,color: Colors.black),), width: (MediaQuery.of(context).size.width-hsp(210))/2, alignment: Alignment.centerLeft, ), onTap: (){ Navigator.of(context,rootNavigator: true).push( CupertinoPageRoute( builder: (context){ return _type==1?YSCity():YSChooseLocation(); } ) ).then((value){ if(value!=null){ setState(() { (_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['startCity'] = value; }); // _getFeatureDisplayListData(); } }); }, ), Image(height: hsp(60),width: hsp(60),image: AssetImage('lib/images/plane.png'),), GestureDetector( child: Container( child: Text('${(_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['endCity'].isNotEmpty? (_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['endCity']['display']:'请选择目的地'}', style: TextStyle(fontSize: zsp(40),fontWeight: FontWeight.bold,color: Colors.black),), width: (MediaQuery.of(context).size.width-hsp(210))/2, alignment: Alignment.centerRight, ), onTap: (){ Navigator.of(context,rootNavigator: true).push( CupertinoPageRoute( builder: (context){ return YSCity(); } ) ).then((value){ if(value!=null){ setState(() { (_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['endCity'] = value; }); // _getFeatureDisplayListData(); } }); }, ), ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text('${(_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['startCity'].isNotEmpty? (_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['startCity']['airplanename']:''}',style: TextStyle(fontSize: zsp(24),color: Color(0xFF999999)),), Text('${(_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['endCity'].isNotEmpty? (_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['endCity']['airplanename']:''}',style: TextStyle(fontSize: zsp(24),color: Color(0xFF999999)),), ], ) ], ): Container( width: MediaQuery.of(context).size.width-hsp(100), child: ListView.builder( itemBuilder: (context,indexSub){ return GestureDetector( onTap: (){ Navigator.of(context,rootNavigator: true).push( CupertinoPageRoute( builder: (context){ return YSChooseLocation(); } ) ).then((value){ if(value!=null){ print(value); setState(() { (_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index][indexSub==0?'startCity':'endCity'] = value; }); // _getFeatureDisplayListData(); } }); }, child: Row( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Column( children: [ Container( height: hsp(30), width: hsp(30), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(50)), border: Border.all(color: indexSub%2==0?Color(0xFF02C094):Color(0xFFFB9658),width: wsp(6)) ), margin: EdgeInsets.only(top: hsp(10),bottom: hsp(7)), ), if(indexSub<1)Container( height: hsp(30), width: hsp(5), color: Color(0xFFCACAD4), ) ], ), Container( child: RichText( text: TextSpan( text: '${(_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index][indexSub==0?'startCity':'endCity'].isNotEmpty? (_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index][indexSub==0?'startCity':'endCity']['display']:'${indexSub==0?'请选择出发地':'请选择目的地'}'}', style: TextStyle(color: Color(0xFF000000),fontSize: hsp(30),fontWeight: FontWeight.bold), children: [ ] ), ), margin: EdgeInsets.only(left: wsp(10),top: hsp(5)), ) ], ), Icon(Icons.keyboard_arrow_right,size: hsp(50),color: Color(0xFFC1C1C1),) ], ), ); }, itemCount: 2, shrinkWrap: true, physics: NeverScrollableScrollPhysics(), padding: EdgeInsets.all(0), ), ), ), Divider(height: 0.5,thickness: 0.5,color: Color(0xFFE9E9E9),indent: wsp(32),endIndent: wsp(32),), Container( padding: EdgeInsets.only(left: wsp(32),right: wsp(32),top: hsp(20),bottom: hsp(20)), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Column( children: [ Text('出发',style: TextStyle(fontSize: zsp(24),color: Color(0xFF666666)),), GestureDetector( onTap: (){ if((_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['startCity'].isEmpty){ ysFlutterToast(context, '请选择出发地'); return; } if((_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['endCity'].isEmpty){ ysFlutterToast(context, '请选择目的地'); return; } showModalBottomSheet( context: context, builder: (context){ return YSDatePicker( choose: (value){ (_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['startTime'] = value; _getDate(index); }, ); } ); }, behavior: HitTestBehavior.opaque, child: RichText( text: TextSpan( text: (_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['startTime'].isNotEmpty? '${(_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['startTime']}':'请选择出发时间', style: TextStyle(fontSize: zsp(28),fontWeight: FontWeight.bold,color: Colors.black), children: [ // TextSpan( // text: '今天', // style: TextStyle(fontSize: zsp(24),fontWeight: FontWeight.normal), // ) ] ), ), ) ], crossAxisAlignment: CrossAxisAlignment.start, ), Column( children: [ Text((_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['endTime'].isNotEmpty?'到达':'',style: TextStyle(fontSize: zsp(24),color: Color(0xFF666666)),), RichText( text: TextSpan( text: (_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['endTime'].isNotEmpty? '${(_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['endTime']}':'', style: TextStyle(fontSize: zsp(28),fontWeight: FontWeight.bold,color: Colors.black), children: [ // TextSpan( // text: '今天', // style: TextStyle(fontSize: zsp(24),fontWeight: FontWeight.normal), // ) ] ), ) ], crossAxisAlignment: CrossAxisAlignment.start, ), Icon(Icons.keyboard_arrow_right,size: hsp(50),color: Color(0xFFC1C1C1),) ], ), ), ], ), ); }, separatorBuilder: (context,index){ return Divider(height: 0.5,thickness: 0.5,color: Color(0xFFE9E9E9),indent: wsp(32),endIndent: wsp(32),); }, itemCount: (_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3).length, padding: EdgeInsets.all(0), physics: NeverScrollableScrollPhysics(), ), if(_typeSub==3)Divider(height: 0.5,thickness: 0.5,color: Color(0xFFE9E9E9),indent: wsp(32),endIndent: wsp(32),), if(_typeSub==3)GestureDetector( onTap: (){ for(int i = 0;i<(_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3).length;i++){ if((_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[i]['startCity'].length==0){ ysFlutterToast(context, '请完善出发地'); return; } if((_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[i]['endCity'].length==0){ ysFlutterToast(context, '请完善目的地'); return; } if((_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[i]['startTime'].length==0){ ysFlutterToast(context, '请完善出发时间'); return; } if((_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[i]['endTime'].length==0){ ysFlutterToast(context, '请完善到达时间'); return; } } setState(() { (_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3) .add({'startCity':(_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[(_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3).length-1]['endCity'],'endCity':{},'startTime':'','endTime':''}); }); }, behavior: HitTestBehavior.opaque, child: Container( padding: EdgeInsets.only(right: wsp(32),top: wsp(32),bottom: wsp(32)), child: Row( children: [ Container( height: hsp(40), alignment: Alignment.center, child: Text('添加',style: TextStyle(fontSize: zsp(20),color: Colors.white),), padding: EdgeInsets.only(left: wsp(10),right: wsp(10)), margin: EdgeInsets.only(right: wsp(30)), decoration: BoxDecoration( color: Color(0xFF007EFF), borderRadius: BorderRadius.only(topRight: Radius.circular(3),bottomRight: Radius.circular(8)) ), ), Text('增加行程',style: TextStyle(fontSize: zsp(28),color: Color(0xFF999999)),), ], ), ), ), Divider(height: 0.5,thickness: 0.5,color: Color(0xFFE9E9E9),indent: wsp(32),endIndent: wsp(32),), GestureDetector( onTap: (){ showModalBottomSheet( context: context, builder: (context){ return YSPicker( dataArray: [for(int i=0;i<30;i++){'title':'${i+1}'}], title: 'title', choose: (value){ setState(() { _numStr = value['title']; }); }, ); } ); }, behavior: HitTestBehavior.opaque, child: Container( padding: EdgeInsets.all(wsp(32)), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(_numStr==null?'请选择出行人数':'$_numStr人出行',style: TextStyle(fontSize: zsp(36),color: Colors.black),), Icon(Icons.keyboard_arrow_right,size: hsp(50),color: Color(0xFFC1C1C1),) ], ), ), ), Divider(height: 0.5,thickness: 0.5,color: Color(0xFFE9E9E9),indent: wsp(32),endIndent: wsp(32),), GestureDetector( onTap: (){ Navigator.of(context).push( CupertinoPageRoute( builder: (context){ return YSChoosePlane(type: _type,); } ) ).then((value){ if(value!=null){ setState(() { _planeType = value; }); } }); }, behavior: HitTestBehavior.opaque, child: Container( padding: EdgeInsets.all(wsp(32)), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(_planeType==null?'飞机类型':'${_planeType['partnerName']}',style: TextStyle(fontSize: zsp(36),color: Colors.black),), Icon(Icons.keyboard_arrow_right,size: hsp(50),color: Color(0xFFC1C1C1),) ], ), ), ), Divider(height: 0.5,thickness: 0.5,color: Color(0xFFE9E9E9),indent: wsp(32),endIndent: wsp(32),), GestureDetector( onTap: (){ if(_planeType==null){ ysFlutterToast(context, '请选择飞机类型'); return; } if(_numStr==null){ ysFlutterToast(context, '请选择出行人数'); return; } for(int i = 0;i<(_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3).length;i++){ if((_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[i]['startCity'].length==0){ ysFlutterToast(context, '请完善出发地'); return; } if((_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[i]['endCity'].length==0){ ysFlutterToast(context, '请完善目的地'); return; } if((_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[i]['startTime'].length==0){ ysFlutterToast(context, '请完善出发时间'); return; } if((_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[i]['endTime'].length==0){ ysFlutterToast(context, '请完善到达时间'); return; } } _postPlaneOrderData(); }, child: Container( width: MediaQuery.of(context).size.width-wsp(64)-hsp(64), margin: EdgeInsets.all(hsp(32)), height: hsp(100), decoration: BoxDecoration( color: Color(0xFF007EFF), borderRadius: BorderRadius.all(Radius.circular(5)) ), alignment: Alignment.center, child: Text('一键召唤公务机',style: TextStyle(fontWeight: FontWeight.bold,color: Colors.white,fontSize: zsp(36)),), ), ) ], ), ) ], ), ), ); } _getBackImageData() async{ Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/wallconfigure/get',parameter: {'type':7},isLoading: false,isToken: false); if(dict!=null){ setState(() { _msgDict = dict['data']; }); } } _getDate(int index) async{ Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/preferential/caculationHour',parameter: {'timeSetout':(_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['startTime'], 'airportidSetout':(_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['startCity']['id'], 'airportidArrive':(_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['endCity']['id']},isLoading: false,isToken: false); if(dict!=null){ setState(() { (_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)[index]['endTime'] = dict['data']; }); } } _postPlaneOrderData() async{ print((_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3)); Map requestDict = {}; requestDict['type'] = 7; requestDict['airplaneid'] = _planeType['id']; requestDict['Itinerary'] = _typeSub; requestDict['travelersNumber'] = _numStr; requestDict['charterType'] = _type; List array = []; int i = 0; (_typeSub==1?_travellings1:_typeSub==2?_travellings2:_travellings3).forEach((element) { i++; Map itineraries = {}; if(_type==1){ itineraries['airportidSetout'] = element['startCity']['id']; itineraries['airportidArrive'] = element['endCity']['id']; }else{ itineraries['locationSetout'] = element['startCity']['location']; itineraries['locationArrive'] = element['endCity']['location']; itineraries['setout'] = element['startCity']['display']; itineraries['arrive'] = element['endCity']['display']; } itineraries['timeSetout'] = '${element['startTime']}:00'; itineraries['timeArrive'] = '${element['endTime']}:00'; itineraries['queue'] = i; array.add(itineraries); }); requestDict['itineraries'] = array; Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/applets/preferential/Grayson',parameter: requestDict,isLoading: true,isToken: true); if(dict!=null){ Navigator.of(context).push( CupertinoPageRoute( builder: (context){ return YSOrderOne(msgDict: _msgDict,orderDict: requestDict,confirmDict: dict['data']); } ) ); } } }