import 'dart:io'; import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:path_provider/path_provider.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:ysairplane2/base/YSBase.dart'; import 'package:ysairplane2/code/YSUnionOrderDetail.dart'; import 'package:ysairplane2/tools/YSNetWorking.dart'; import 'package:ysairplane2/tools/YSTools.dart'; class YSUnionOrder extends StatefulWidget { final userId; final shopId; const YSUnionOrder({Key key, this.userId, this.shopId}) : super(key: key); @override _YSUnionOrderState createState() => _YSUnionOrderState(); } class _YSUnionOrderState extends State { String _timeSrt = ''; List _dataArray = []; int _page = 1; @override void initState() { Future.delayed(Duration(seconds: 0)).then((value){ _refreshData(); }); super.initState(); } @override Widget build(BuildContext context) { return YSBase( ystitle: '收入明细', yscolor: Color(0xFFF5F6F8), ysright: GestureDetector( onTap: () async{ Map request = {}; if(widget.userId!=null){ request['userId'] = widget.userId; }else if(widget.shopId!=null){ request['partnerId'] = widget.shopId; } Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/servants/export',parameter: request,isLoading: false,isToken: true); if(dict!=null) { if (await Permission.storage .request() .isGranted) { } else { Map statuses = await [ Permission.storage, ].request(); if (statuses[Permission.storage].isDenied) { return; } print('==============C ${statuses[Permission.location]}'); } Directory directory = await getExternalStorageDirectory(); if(Platform.isIOS==true){ directory = await getApplicationSupportDirectory(); } String url = '${dict['data']}'; String name = '${DateTime.now().microsecondsSinceEpoch}'; List array = url.split('.'); if(array.length>1){ name+='.${array[array.length-1]}'; } print('${directory.path}/$name'); Response response = await Dio().download(url, '${directory.path}/$name'); print(response.statusCode); if(response.statusCode==200){ ysFlutterToast(context, '文件已导出到${directory.path}/$name'); } } }, child: Text('导出',style: TextStyle(fontSize: zsp(32),color: Color(0xFF141418)),), ), yschild: Container( width: MediaQuery.of(context).size.width, child: Column( children: [ Container( height: hsp(80), padding: EdgeInsets.only(left: hsp(20),right: hsp(20)), child: GestureDetector( onTap: (){ showModalBottomSheet( context: context, builder: (context){ return YSDatePicker(isDate: true,choose: (value){ print(value); _timeSrt = value.substring(0,7); _refreshData(); },); } ); }, child: Row( children: [ Text(_timeSrt.isEmpty?'全部':_timeSrt,style: TextStyle(fontSize: zsp(30),color: Colors.black),), Icon(Icons.keyboard_arrow_down,size: hsp(40),color: Color(0xFFCCCCCC),) ], ), ) ), Container( height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44-hsp(80), color: Colors.white, child: EasyRefresh( onRefresh: _refreshData, onLoad: _loadMoreData, header: TaurusHeader( ), footer: TaurusFooter( ), child: ListView.separated( padding: EdgeInsets.only(left: hsp(20),right: hsp(20)), itemBuilder: (context,index){ Map item = _dataArray[index]; return GestureDetector( onTap: (){ Navigator.of(context).push( CupertinoPageRoute( builder: (context){ return YSUnionOrderDetail(order: item,); } ) ); }, child: Container( padding: EdgeInsets.all(hsp(20)), color: Colors.white, child: LayoutBuilder( builder: (context,listSize){ return Column( children: [ Row( children: [ Container( width: listSize.maxWidth-hsp(200), child: RichText( text: TextSpan( text: '订单编号:', style: TextStyle(fontSize: zsp(24),color: Color(0xFF999999)), children: [ TextSpan( text: '${item['orderSn']}', style: TextStyle(color: Colors.black) ) ] ), ), ), Container( width: hsp(200), child: Text(item['orderStatus']==0?'已下单':item['orderStatus']==1?'已核验':'已退款',style: TextStyle(fontSize: zsp(24),color: Color(0xFF999999)),), alignment: Alignment.centerRight, ) ], ), Container( margin: EdgeInsets.only(top: hsp(20),bottom: hsp(20)), child: Row( children: [ Container( width: listSize.maxWidth*0.7, child: Text('${item['typeName']}',style: TextStyle(fontSize: zsp(34),color: Color(0xFF5F5F5F)),), ), Container( width: listSize.maxWidth*0.3, alignment: Alignment.centerRight, child: RichText( text: TextSpan( text: '${item['orderPrice']}', style: TextStyle(fontSize: zsp(40),color: Colors.black), children: [ TextSpan( text: '元', style: TextStyle(fontSize: zsp(24)) ) ] ), ), ) ], ), ), Row( children: [ Container( width: listSize.maxWidth*0.2, child: RichText( text: TextSpan( text: '佣金:', style: TextStyle(fontSize: zsp(22),color: Color(0xFF999999)), children: [ TextSpan( text: '${item['servantsPrice']}', style: TextStyle(color: Colors.black) ) ] ), ), ), Container( width: listSize.maxWidth*0.3, child: RichText( text: TextSpan( text: '用户:', style: TextStyle(fontSize: zsp(22),color: Color(0xFF999999)), children: [ TextSpan( text: '${item['nickName']}', style: TextStyle(color: Colors.black) ) ] ), ), alignment: Alignment.center, ), Container( width: listSize.maxWidth*0.5, child: RichText( text: TextSpan( text: '支付时间:', style: TextStyle(fontSize: zsp(22),color: Color(0xFF999999)), children: [ TextSpan( text: '${item['payTime']}', style: TextStyle(color: Colors.black) ) ] ), ), alignment: Alignment.centerRight, ) ], ) ], ); }, ), ), ); }, separatorBuilder: (context,index){ return Divider(height: hsp(1),thickness: hsp(1),color: Color(0xFFF5F6F8),); }, itemCount: _dataArray.length, ), ), ) ], ), ), ); } Future _refreshData() async{ _page = 1; if(_timeSrt.isEmpty)_timeSrt = '${DateTime.now().year}-'+'${DateTime.now().month}'.padLeft(2,'0'); Map request = {}; request['pageNum'] = _page; request['date'] = _timeSrt; if(widget.userId!=null)request['userId'] = widget.userId; if(widget.shopId!=null)request['partnerId'] = widget.shopId; Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/servants/orderList',parameter: request,isLoading: false,isToken: true); if(dict!=null){ setState(() { _dataArray = dict['data']['resultList']; }); } } Future _loadMoreData() async{ _page++; Map request = {}; request['pageNum'] = _page; request['date'] = _timeSrt; if(widget.userId!=null)request['userId'] = widget.userId; if(widget.shopId!=null)request['partnerId'] = widget.shopId; Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/servants/orderList',parameter: request, isLoading: false,isToken: true); if(dict!=null){ setState(() { _dataArray.addAll(dict['data']['resultList']); }); } } }