YSUnionOrder.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. import 'dart:io';
  2. import 'package:dio/dio.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_easyrefresh/easy_refresh.dart';
  6. import 'package:path_provider/path_provider.dart';
  7. import 'package:permission_handler/permission_handler.dart';
  8. import 'package:ysairplane2/base/YSBase.dart';
  9. import 'package:ysairplane2/code/YSUnionOrderDetail.dart';
  10. import 'package:ysairplane2/tools/YSNetWorking.dart';
  11. import 'package:ysairplane2/tools/YSTools.dart';
  12. class YSUnionOrder extends StatefulWidget {
  13. final userId;
  14. final shopId;
  15. const YSUnionOrder({Key key, this.userId, this.shopId}) : super(key: key);
  16. @override
  17. _YSUnionOrderState createState() => _YSUnionOrderState();
  18. }
  19. class _YSUnionOrderState extends State<YSUnionOrder> {
  20. String _timeSrt = '';
  21. List _dataArray = [];
  22. int _page = 1;
  23. @override
  24. void initState() {
  25. Future.delayed(Duration(seconds: 0)).then((value){
  26. _refreshData();
  27. });
  28. super.initState();
  29. }
  30. @override
  31. Widget build(BuildContext context) {
  32. return YSBase(
  33. ystitle: '收入明细',
  34. yscolor: Color(0xFFF5F6F8),
  35. ysright: GestureDetector(
  36. onTap: () async{
  37. Map request = {};
  38. if(widget.userId!=null){
  39. request['userId'] = widget.userId;
  40. }else if(widget.shopId!=null){
  41. request['partnerId'] = widget.shopId;
  42. }
  43. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/servants/export',parameter: request,isLoading: false,isToken: true);
  44. if(dict!=null) {
  45. if (await Permission.storage
  46. .request()
  47. .isGranted) {
  48. } else {
  49. Map<Permission, PermissionStatus> statuses = await [
  50. Permission.storage,
  51. ].request();
  52. if (statuses[Permission.storage].isDenied) {
  53. return;
  54. }
  55. print('==============C ${statuses[Permission.location]}');
  56. }
  57. Directory directory = await getExternalStorageDirectory();
  58. if(Platform.isIOS==true){
  59. directory = await getApplicationSupportDirectory();
  60. }
  61. String url = '${dict['data']}';
  62. String name = '${DateTime.now().microsecondsSinceEpoch}';
  63. List array = url.split('.');
  64. if(array.length>1){
  65. name+='.${array[array.length-1]}';
  66. }
  67. print('${directory.path}/$name');
  68. Response response = await Dio().download(url, '${directory.path}/$name');
  69. print(response.statusCode);
  70. if(response.statusCode==200){
  71. ysFlutterToast(context, '文件已导出到${directory.path}/$name');
  72. }
  73. }
  74. },
  75. child: Text('导出',style: TextStyle(fontSize: zsp(32),color: Color(0xFF141418)),),
  76. ),
  77. yschild: Container(
  78. width: MediaQuery.of(context).size.width,
  79. child: Column(
  80. children: [
  81. Container(
  82. height: hsp(80),
  83. padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
  84. child: GestureDetector(
  85. onTap: (){
  86. showModalBottomSheet(
  87. context: context,
  88. builder: (context){
  89. return YSDatePicker(isDate: true,choose: (value){
  90. print(value);
  91. _timeSrt = value.substring(0,7);
  92. _refreshData();
  93. },);
  94. }
  95. );
  96. },
  97. child: Row(
  98. children: [
  99. Text(_timeSrt.isEmpty?'全部':_timeSrt,style: TextStyle(fontSize: zsp(30),color: Colors.black),),
  100. Icon(Icons.keyboard_arrow_down,size: hsp(40),color: Color(0xFFCCCCCC),)
  101. ],
  102. ),
  103. )
  104. ),
  105. Container(
  106. height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44-hsp(80),
  107. color: Colors.white,
  108. child: EasyRefresh(
  109. onRefresh: _refreshData,
  110. onLoad: _loadMoreData,
  111. header: TaurusHeader(
  112. ),
  113. footer: TaurusFooter(
  114. ),
  115. child: ListView.separated(
  116. padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
  117. itemBuilder: (context,index){
  118. Map item = _dataArray[index];
  119. return GestureDetector(
  120. onTap: (){
  121. Navigator.of(context).push(
  122. CupertinoPageRoute(
  123. builder: (context){
  124. return YSUnionOrderDetail(order: item,);
  125. }
  126. )
  127. );
  128. },
  129. child: Container(
  130. padding: EdgeInsets.all(hsp(20)),
  131. color: Colors.white,
  132. child: LayoutBuilder(
  133. builder: (context,listSize){
  134. return Column(
  135. children: [
  136. Row(
  137. children: [
  138. Container(
  139. width: listSize.maxWidth-hsp(200),
  140. child: RichText(
  141. text: TextSpan(
  142. text: '订单编号:',
  143. style: TextStyle(fontSize: zsp(24),color: Color(0xFF999999)),
  144. children: [
  145. TextSpan(
  146. text: '${item['orderSn']}',
  147. style: TextStyle(color: Colors.black)
  148. )
  149. ]
  150. ),
  151. ),
  152. ),
  153. Container(
  154. width: hsp(200),
  155. child: Text(item['orderStatus']==0?'已下单':item['orderStatus']==1?'已核验':'已退款',style: TextStyle(fontSize: zsp(24),color: Color(0xFF999999)),),
  156. alignment: Alignment.centerRight,
  157. )
  158. ],
  159. ),
  160. Container(
  161. margin: EdgeInsets.only(top: hsp(20),bottom: hsp(20)),
  162. child: Row(
  163. children: [
  164. Container(
  165. width: listSize.maxWidth*0.7,
  166. child: Text('${item['typeName']}',style: TextStyle(fontSize: zsp(34),color: Color(0xFF5F5F5F)),),
  167. ),
  168. Container(
  169. width: listSize.maxWidth*0.3,
  170. alignment: Alignment.centerRight,
  171. child: RichText(
  172. text: TextSpan(
  173. text: '${item['orderPrice']}',
  174. style: TextStyle(fontSize: zsp(40),color: Colors.black),
  175. children: [
  176. TextSpan(
  177. text: '元',
  178. style: TextStyle(fontSize: zsp(24))
  179. )
  180. ]
  181. ),
  182. ),
  183. )
  184. ],
  185. ),
  186. ),
  187. Row(
  188. children: [
  189. Container(
  190. width: listSize.maxWidth*0.2,
  191. child: RichText(
  192. text: TextSpan(
  193. text: '佣金:',
  194. style: TextStyle(fontSize: zsp(22),color: Color(0xFF999999)),
  195. children: [
  196. TextSpan(
  197. text: '${item['servantsPrice']}',
  198. style: TextStyle(color: Colors.black)
  199. )
  200. ]
  201. ),
  202. ),
  203. ),
  204. Container(
  205. width: listSize.maxWidth*0.3,
  206. child: RichText(
  207. text: TextSpan(
  208. text: '用户:',
  209. style: TextStyle(fontSize: zsp(22),color: Color(0xFF999999)),
  210. children: [
  211. TextSpan(
  212. text: '${item['nickName']}',
  213. style: TextStyle(color: Colors.black)
  214. )
  215. ]
  216. ),
  217. ),
  218. alignment: Alignment.center,
  219. ),
  220. Container(
  221. width: listSize.maxWidth*0.5,
  222. child: RichText(
  223. text: TextSpan(
  224. text: '支付时间:',
  225. style: TextStyle(fontSize: zsp(22),color: Color(0xFF999999)),
  226. children: [
  227. TextSpan(
  228. text: '${item['payTime']}',
  229. style: TextStyle(color: Colors.black)
  230. )
  231. ]
  232. ),
  233. ),
  234. alignment: Alignment.centerRight,
  235. )
  236. ],
  237. )
  238. ],
  239. );
  240. },
  241. ),
  242. ),
  243. );
  244. },
  245. separatorBuilder: (context,index){
  246. return Divider(height: hsp(1),thickness: hsp(1),color: Color(0xFFF5F6F8),);
  247. },
  248. itemCount: _dataArray.length,
  249. ),
  250. ),
  251. )
  252. ],
  253. ),
  254. ),
  255. );
  256. }
  257. Future<void> _refreshData() async{
  258. _page = 1;
  259. if(_timeSrt.isEmpty)_timeSrt = '${DateTime.now().year}-'+'${DateTime.now().month}'.padLeft(2,'0');
  260. Map request = {};
  261. request['pageNum'] = _page;
  262. request['date'] = _timeSrt;
  263. if(widget.userId!=null)request['userId'] = widget.userId;
  264. if(widget.shopId!=null)request['partnerId'] = widget.shopId;
  265. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/servants/orderList',parameter: request,isLoading: false,isToken: true);
  266. if(dict!=null){
  267. setState(() {
  268. _dataArray = dict['data']['resultList'];
  269. });
  270. }
  271. }
  272. Future<void> _loadMoreData() async{
  273. _page++;
  274. Map request = {};
  275. request['pageNum'] = _page;
  276. request['date'] = _timeSrt;
  277. if(widget.userId!=null)request['userId'] = widget.userId;
  278. if(widget.shopId!=null)request['partnerId'] = widget.shopId;
  279. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/servants/orderList',parameter: request, isLoading: false,isToken: true);
  280. if(dict!=null){
  281. setState(() {
  282. _dataArray.addAll(dict['data']['resultList']);
  283. });
  284. }
  285. }
  286. }