123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- 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<YSUnionOrder> {
- 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<Permission, PermissionStatus> 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<void> _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<void> _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']);
- });
- }
- }
- }
|