import 'dart:convert'; import 'dart:math' as math; import 'package:bbyyy/beans/flow_bean_entity.dart'; import 'package:bbyyy/beans/store_bean_entity.dart'; import 'package:bbyyy/beans/user_balance_entity.dart'; import 'package:bbyyy/https/MyDio.dart'; import 'package:bbyyy/https/url.dart'; import 'package:bbyyy/my_tools/const.dart'; import 'package:bbyyy/my_tools/dims.dart'; import 'package:bbyyy/my_tools/my_colors.dart'; import 'package:bbyyy/my_tools/my_cookie.dart'; import 'package:bbyyy/my_tools/my_tools.dart'; import 'package:bbyyy/my_tools/my_views.dart'; import 'package:bbyyy/pay/pay_tools.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; class WalletPage extends StatefulWidget { @override _WalletPageState createState() => _WalletPageState(); } class _WalletPageState extends State { int sTab = 0; List flow = []; int page = 1; RefreshController controller = RefreshController(initialRefresh: true); int total = 0; double totalAmount = 0.0; @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return Scaffold( body: Column( children: [ Stack( children: [ Container( decoration: BoxDecoration( gradient: LinearGradient(colors: MyColors.lg), ), height: 200, ), Column( children: [ SafeArea( bottom: false, child: Container( height: 45, width: double.infinity, color: Colors.transparent, child: Stack( children: [ Text( '资金流水', style: TextStyle(color: Colors.white, fontSize: 16), ), Positioned( left: 0, child: GestureDetector( onTap: () { Navigator.pop(context); }, behavior: HitTestBehavior.translucent, child: Transform.rotate( angle: math.pi, child: Padding( padding: EdgeInsets.only( left: 16, right: 16, top: 8, bottom: 8), child: SvgPicture.asset( 'images/svg/箭头.svg', color: Colors.white, height: 14, ), ), ), ), ), Row( children: [ GestureDetector( onTap: () { showSelect(); }, behavior: HitTestBehavior.translucent, child: Container( padding: EdgeInsets.symmetric( vertical: 8, horizontal: 16), child: Text( '筛选', style: TextStyle( color: Colors.white, fontSize: 16), ), ), ), ], mainAxisAlignment: MainAxisAlignment.end, ) ], alignment: Alignment.center, ), ), ), // Container( // decoration: BoxDecoration( // border: Border.all(color: Colors.white, width: 1), // borderRadius: BorderRadius.all(Radius.circular(20))), // height: 40, // width: double.infinity, // margin: EdgeInsets.symmetric(horizontal: 33, vertical: 7), // child: Row( // children: [ // Expanded( // child: GestureDetector( // onTap: () { // setState(() { // sTab = 0; // controller.requestRefresh(); // }); // }, // behavior: HitTestBehavior.translucent, // child: Container( // height: 40, // decoration: BoxDecoration( // borderRadius: BorderRadius.only( // topLeft: Radius.circular(20), // bottomLeft: Radius.circular(20), // ), // color: sTab == 0 // ? Colors.white // : Colors.transparent), // child: Text( // '我的收入', // style: TextStyle( // color: sTab == 0 // ? MyColors.cFF4233 // : Colors.white), // ), // alignment: Alignment.center, // ), // ), // ), // Expanded( // child: GestureDetector( // onTap: () { // setState(() { // sTab = 1; // controller.requestRefresh(); // }); // }, // behavior: HitTestBehavior.translucent, // child: Container( // height: 40, // decoration: BoxDecoration( // borderRadius: BorderRadius.only( // topRight: Radius.circular(20), // bottomRight: Radius.circular(20), // ), // color: sTab == 1 // ? Colors.white // : Colors.transparent), // child: Text( // '我的支出', // style: TextStyle( // color: sTab == 1 // ? MyColors.cFF4233 // : Colors.white), // ), // alignment: Alignment.center, // ), // ), // ) // ], // ), // ), Container( margin: EdgeInsets.only(top: 10), child: Row( children: [ ClipRRect( child: MyViews() .netImg(imgURL(MyCookie().getPic()), 36, 36), borderRadius: BorderRadius.circular(18), ), Container( margin: EdgeInsets.only(left: 10), child: Text( '${MyCookie().getName()}(${MyCookie().getUID()})', style: TextStyle(color: Colors.white, fontSize: 15), ), ), ], mainAxisAlignment: MainAxisAlignment.center, ), alignment: Alignment.center, ), Container( margin: EdgeInsets.only(top: 25), child: Center( child: Text( '共$total笔', style: TextStyle(color: Colors.white, fontSize: 20), ), ), ), // Container( // height: 22, // child: Row( // children: [ // Text( // '$total笔数', // style: TextStyle(color: Colors.white, fontSize: 14), // ), // // Visibility( // // visible: sTab == 0, // // child: GestureDetector( // // onTap: () { // // if (MyCookie().userBean.aliPayAccount.isEmpty) { // // MyTools().toPage(context, SetAlipayPage(), // // (then) { // // if (MyCookie() // // .userBean // // .aliPayAccount // // .isNotEmpty) { // // MyTools().toPage(context, WithdrawPage(), // // (then) { // // controller.requestRefresh(); // // }); // // } // // }); // // } else { // // MyTools().toPage(context, WithdrawPage(), // // (then) { // // controller.requestRefresh(); // // }); // // } // // }, // // behavior: HitTestBehavior.translucent, // // child: Container( // // decoration: BoxDecoration( // // color: MyColors.cFFCD00, // // borderRadius: // // BorderRadius.all(Radius.circular(15)), // // ), // // height: 30, // // width: 70, // // child: Text( // // '申请提现', // // style: TextStyle( // // color: Colors.white, fontSize: 13), // // ), // // alignment: Alignment.center, // // padding: EdgeInsets.only(bottom: 1), // // ), // // ), // // ) // ], // mainAxisAlignment: MainAxisAlignment.spaceBetween, // ), // alignment: Alignment.centerLeft, // margin: EdgeInsets.only(top: 25, left: 15, right: 17), // ), // Container( // child: Text( // '¥${NumUtil.multiply(totalAmount, 1)}', // style: TextStyle(color: Colors.white, fontSize: 24), // ), // alignment: Alignment.center, // margin: EdgeInsets.only(top: 2), // ), ], ) ], ), Expanded( child: SmartRefresher( controller: controller, onRefresh: onRefresh, onLoading: onLoading, enablePullDown: true, enablePullUp: true, child: flow.length == 0 ? SingleChildScrollView(child: noData()) : ListView.builder( itemBuilder: (c, index) { return MyViews().getWalletItem(flow[index], context); }, padding: EdgeInsets.only(top: 13), itemCount: flow.length, ), ), ), ], ), ); } StateSetter ss; List types = ['全部', '订单', '佣金','提现']; int typeIndex = 0; // List times = ['全部', '今天', '昨天', '本周', '上周', '本月']; List times = ['昨天', '本周', '上周']; int timeIndex = -1; void showSelect() { showModalBottomSheet( backgroundColor: Colors.transparent, context: context, builder: (context) { return StatefulBuilder(builder: (c, s) { ss = s; return Container( color: Colors.transparent, height: 240 + (MediaQuery.of(context).size.width / 3 / 2.5) * ((types.length / 3).ceil()), child: Column( children: [ Container( padding: EdgeInsets.only(left: 10, right: 10, top: 3, bottom: 0), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only( topLeft: Radius.circular(8), topRight: Radius.circular(8))), child: Row( children: [ GestureDetector( onTap: () { Navigator.pop(context); }, behavior: HitTestBehavior.translucent, child: Padding( padding: const EdgeInsets.all(8.0), child: Text( '取消', style: TextStyle( color: MyColors.cFF4233, fontSize: 14), ), ), ), Text( '类型筛选', style: TextStyle(color: MyColors.c333333, fontSize: 16), ), GestureDetector( child: Padding( padding: const EdgeInsets.all(8.0), child: Text( '确定', style: TextStyle( color: MyColors.cFF4233, fontSize: 14), ), ), behavior: HitTestBehavior.translucent, onTap: () { Navigator.pop(context); controller.requestRefresh(); }, ), ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), height: 39.5, ), Container( height: 0.5, color: MyColors.cF5F5F5, ), Expanded( child: Container( color: Colors.white, child: SingleChildScrollView( child: Column( children: [ Visibility( visible: types.length > 1, child: Container( height: 20 + (MediaQuery.of(context).size.width / 3 / 2.5) * ((types.length / 3).ceil()), color: Colors.white, child: Column( children: [ Container( child: Text( '类型筛选', style: TextStyle( color: MyColors.c333333, fontSize: 15), ), margin: EdgeInsets.only( left: 18, top: 5, bottom: 5), height: 20, ), Expanded( child: GridView( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 3, childAspectRatio: 3), children: getTypeItems(), physics: NeverScrollableScrollPhysics(), ), ) ], crossAxisAlignment: CrossAxisAlignment.start, ), ), ), Visibility( visible: times.length > 1, child: Container( height: 20 + (MediaQuery.of(context).size.width / 3 / 2.5) * ((times.length / 3).ceil()), color: Colors.white, child: Column( children: [ Container( child: Text( '时间筛选', style: TextStyle( color: MyColors.c333333, fontSize: 15), ), margin: EdgeInsets.only( left: 18, top: 5, bottom: 5), height: 20, ), Expanded( child: GridView( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 3, childAspectRatio: 3), children: getTimeItems(), physics: NeverScrollableScrollPhysics(), ), ) ], crossAxisAlignment: CrossAxisAlignment.start, ), ), ), ], crossAxisAlignment: CrossAxisAlignment.start, ), ), ), ) ], ), ); }); }); } getTypeItems() { List item = []; for (int i = 0; i < types.length; i++) { item.add(GestureDetector( onTap: () { ss(() { if (typeIndex == i) { typeIndex = -1; } else { typeIndex = i; } }); // getTime(timeIndex); }, behavior: HitTestBehavior.translucent, child: Container( alignment: Alignment.center, child: Container( decoration: BoxDecoration( color: i == typeIndex ? MyColors.cFFECEB : MyColors.cEDEDED, borderRadius: BorderRadius.all(Radius.circular(4))), height: 34, width: 100, child: Text( types[i], style: TextStyle( color: i == typeIndex ? MyColors.cFF4233 : MyColors.c666666, fontSize: 14), ), alignment: Alignment.center, ), ), )); } return item; } getTimeItems() { List item = []; for (int i = 0; i < times.length; i++) { item.add(GestureDetector( onTap: () { ss(() { if (timeIndex == i) { timeIndex = -1; } else { timeIndex = i; } }); if (timeIndex != -1) { getTime(timeIndex +1); } }, behavior: HitTestBehavior.translucent, child: Container( alignment: Alignment.center, child: Container( decoration: BoxDecoration( color: i == timeIndex ? MyColors.cFFECEB : MyColors.cEDEDED, borderRadius: BorderRadius.all(Radius.circular(4))), height: 34, width: 100, child: Text( times[i], style: TextStyle( color: i == timeIndex ? MyColors.cFF4233 : MyColors.c666666, fontSize: 14), ), alignment: Alignment.center, ), ), )); } return item; } void myFlow() { getUserWalletBalance((re, hE) { if (!hE) { UserBalanceEntity balance = UserBalanceEntity().fromJson(json.decode(re.data.toString())); MyCookie().userBean.balance = balance.data; setState(() {}); } }, (e) {}, context); var conditions = [ "user_uid==${MyCookie().getUID()}", // "paid_amount ${sTab == 0 ? '>' : '<'} 0" ]; if (typeIndex != 0 && typeIndex != -1) { switch(typeIndex){ case 1: conditions.add('type IN ${[ flowTypeOrderCommodity, flowTypeOrderAnnualFee, flowTypeOrderVirtualProduct, flowTypeOrderThirdPlatform, flowTypeOrderOfflineTransfer, flowTypeScancodeAilyPay ]}'); break; case 2: conditions.add('type IN ${[ flowTypeShopCommission ]}'); break; case 3: conditions.add('type IN ${[ flowTypeWithdraw ]}'); break; } // conditions.add("type IN ${typeIndex == 1 ? [ // flowTypeOrderCommodity, // flowTypeOrderAnnualFee, // flowTypeOrderVirtualProduct, // flowTypeOrderThirdPlatform, // flowTypeOrderOfflineTransfer, // flowTypeScancodeAilyPay // ] : [flowTypeShopCommission]}"); } if (timeIndex != -1) { conditions.add("pay_time between ${getTime(timeIndex +1)}"); }else{ conditions.add("pay_time between ${getTime(6)}"); } MyDio().query({ "key": "flow", "filters": {"conditions": conditions}, "dims": flowDims, "order_by": ["id,DESC"], "paging": [page, 50] }, (response, hasError) { if (!hasError) { FlowBeanEntity entity = FlowBeanEntity().fromJson(json.decode(response.data.toString())); total = entity.data.total; totalAmount = entity.data.data.totalAmount; if (page == 1) { flow.clear(); } try { flow.addAll(entity.data.data.records); } catch (e) {} setState(() {}); } endRe(controller); }, (error) {}); } void onRefresh() { page = 1; checkIfYouAreTheOwner(); myFlow(); } void onLoading() { page++; myFlow(); } void checkIfYouAreTheOwner() { MyDio().query({ "key": "shop", "filters": { "conditions": ["owner_uid == ${MyCookie().getUID()}"] }, "dims": shopDims, "paging": [1, 5000] }, (response, hasError) { if (!hasError) { StoreBeanEntity entity = StoreBeanEntity().fromJson(json.decode(response.data.toString())); if (entity.data.data.length == 0) { types.remove('佣金'); } setState(() {}); } endRe(controller); }, (error) {}); } }